Add Continuity compaction strategy#306
Draft
nhicks00 wants to merge 33 commits intompfaffenberger:mainfrom
Draft
Add Continuity compaction strategy#306nhicks00 wants to merge 33 commits intompfaffenberger:mainfrom
nhicks00 wants to merge 33 commits intompfaffenberger:mainfrom
Conversation
Owner
|
I love the concept and I'd love to have this feature, but structurally this P/R is not mergeable. This needs to be created as 100% a plugin. Your agent wrote a justification for why it shouldn't be a plugin, but that contradicts everything that's in our AGENTS.md. For a feature like this, the only feasible way to create changes in core is to add lifecycle hooks. I would love to have this feature, so if you can propose a set of lifecycle hooks to add in |
0b64051 to
e194e62
Compare
314aab0 to
6c54f3f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Makes
compaction_strategy=continuitythe default compaction mode and adds the Continuity strategy for preserving long-session working context through predictive triggers, deterministic observation masking, durable task-scoped memory, archive retrieval hints, fallback summarization, recent raw-tail protection, and target trimming.The existing
truncationandsummarizationstrategies remain available for users who prefer the legacy behavior.Structure
Continuity is implemented as a built-in plugin under
code_puppy/plugins/continuity_compaction/.The core changes are limited to generic plugin extension points and their invocations:
register_config_keys: lets plugins expose config keys in/sethelp.register_compaction_strategies: lets plugins register strategy names such ascontinuity.compact_message_history: lets a plugin handle message-history compaction and return rebuilt history plus dropped-message bookkeeping./compactnow routes through the unified compaction entrypoint withforce=True, so plugin strategies can handle manual compaction without command-specific core logic.Why Continuity
What Changed
get_compaction_strategy()tocontinuitywhen no strategy is configured or an invalid strategy is provided.code_puppy/plugins/continuity_compaction/with:35%full contextcontinuity_compaction_recent_raw_floor_ratio(20%by default)continuity_compaction_semantic_model, defaulting to the active chat model when unset and falling back tosummarization_modelonly for non-agent utility calls/continuityas a plugin command for memory status, task ledger, archive search/show, and diagnostics.Before / After Model
Before compaction, a long session can contain the current task, old completed task work, repeated file reads, large test output, tool-return logs, and the latest raw conversation tail all mixed together.
After Continuity compaction, the recent raw tail stays intact, old bulky tool returns are replaced in place with short deterministic capsules, the raw logs are archived locally, and one compact durable-memory snapshot is injected near the front of the rebuilt history. If masking still cannot hit the
35%target, only the oldest already-masked region is summarized while preserving a visible recent archive capsule when practical; if the transcript is still above target, older compacted history is trimmed while preserving the latest user request, current error context, and newest raw tail.User Impact
Continuity is now the default compaction strategy. Users can still set it explicitly with:
Legacy strategies remain available:
Useful related knobs include:
continuity_compaction_semantic_modelcontrols the semantic memory LLM call. If unset, Continuity uses the active chat model from the current Code Puppy session. If no active model is available for a direct utility call, it falls back tosummarization_model. Fallback summarization uses Code Puppy's existing summarization path, so it is still controlled bysummarization_model.Validation
329 passeduv run ruff check ...uv run ruff format --check ...uv run pytest --no-cov -q9802 passed, 87 skipped, 1 xpassedbefore manual interrupt after the suite stalled late in an unrelated file-operations areaProvider Compatibility Note
The ChatGPT OAuth/Codex stream reconstruction fix is intentionally isolated from Continuity. It lives only in
chatgpt_codex_client.pyplus its focused test because that provider can stream text deltas and then finish withresponse.completed.output=[], which appears to pydantic-ai asModelResponse(parts=[]). Continuity simply uses the active model through the normal model factory; it does not import ChatGPT OAuth code or depend on this provider patch.For forks that do not include ChatGPT OAuth, such as a Walmart fork without that provider, this patch can be omitted while still porting the Continuity plugin and the generic compaction callback hooks.
Why Any Core Code Changed
Continuity's implementation is plugin-owned, but Code Puppy did not previously expose a compaction-strategy plugin lifecycle. The small core diff adds generic extension plumbing rather than Continuity-specific behavior:
callbacks.pyadds hooks for plugin config keys, plugin compaction strategy registration, and plugin-owned message-history compaction.agents/_compaction.pyinvokes the compaction hook before falling back to built-in truncation/summarization.config.pyaccepts plugin-registered strategy names and defaults tocontinuity./compact,/show, and/setuse the generic strategy/config discovery path so plugin strategies are usable and visible from the CLI.Without those generic hooks, the plugin could register files and commands, but it could not become a selectable compaction strategy or participate in automatic/manual compaction.
Reviewer Notes
truncationandsummarizationstrategies remain available through/set compaction_strategy=....