Skip to content

refactor: extract context management and spill storage - #11

Merged
zhanghanduo merged 2 commits into
mainfrom
refactor/context-management-phase2
Sep 1, 2026
Merged

zhanghanduo merged 2 commits into
mainfrom
refactor/context-management-phase2

Conversation

@zhanghanduo

@zhanghanduo zhanghanduo commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • extract bounded LLM summary and calibrated tiered compaction into AgentCore
  • add projected-token triggers, budget consistency checks, retry/fallback policy, and compaction observability
  • add a session-isolated content-addressed SpillStore with atomic writes, read-only artifacts, recovery previews, aggregate result budgeting, scoped reads, and cleanup
  • keep product summary selection, sandbox mounts, path authorization, session identity, and workflow configuration behind explicit inputs

Validation

  • Ruff passed
  • strict Pyright passed with 0 errors and 0 warnings
  • 461 tests passed
  • source distribution and wheel build passed
  • CI passed on bc9b61b

Downstream

@zhanghanduo
zhanghanduo force-pushed the refactor/context-management-phase2 branch from ed24960 to b393fea Compare September 1, 2026 06:41
@zhanghanduo
zhanghanduo force-pushed the refactor/context-management-phase2 branch from b393fea to bc9b61b Compare September 1, 2026 06:46
…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>
@zhanghanduo
zhanghanduo merged commit 4869295 into main Sep 1, 2026
1 check passed
@zhanghanduo
zhanghanduo deleted the refactor/context-management-phase2 branch September 1, 2026 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant