refactor: extract context management and spill storage - #11
Merged
Merged
Conversation
zhanghanduo
force-pushed
the
refactor/context-management-phase2
branch
from
September 1, 2026 06:41
ed24960 to
b393fea
Compare
zhanghanduo
force-pushed
the
refactor/context-management-phase2
branch
from
September 1, 2026 06:46
b393fea to
bc9b61b
Compare
…ion guards Seven defects found reviewing PR #11, each with a regression test that was confirmed to fail against the original code: - `_partition` walked its split point forward with a `len(rest) - 1` bound, so a tail made only of tool results (a parallel tool-call turn emitting at least `keep_recent` of them) left the last result orphaned while the AIMessage carrying its `tool_call_id` was summarised away — the exact HTTP 400 the guard exists to prevent. Walk back to the assistant message instead and keep the turn whole; `keep_recent` is a floor, not a cap. - The unseen-result guard was dropped whenever a spill callback merely existed. `spill_compacted_body` writes with `require_visible=True` and so returns None for every body when the store has no `visible_root` — an allowed configuration — leaving the latest turn's results condensed with nothing recoverable. Test whether the callback can produce a ref, not whether it is set. - Bare "400"/"413"/"422" substrings classified a retriable 429 whose message named a retry delay ("try again in 400ms") as permanent, skipping its whole retry budget. Read the exception's status field first, then match codes on word boundaries with the transient set winning. - `budgeted_preview` could return more characters than its input: the `_MIN_PREVIEW_CHARS` floor overrides the cap and the footer lands on top. Return the body unchanged when no bounded rewrite is shorter — a footer pointing at a recovery file is pointless when nothing was elided. - The footer always claimed a marked gap, which head-only truncation (and the three middle-mode fallbacks) never writes. Report the shape actually produced. - `compaction_prompt` defaulted to `research` while documenting `auto`, so the measured handoff routing was unreachable for every in-repo caller. Behaviour is unchanged without a tool-category callback. - `budget_consistency` restated the trigger ratio it warns against disagreeing with, and was unreachable from the package API. Re-export the ratio from `tiered_compact`, accept an explicit `ratio`, and export the checker. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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
Validation
bc9b61bDownstream