Skip to content

feat(context): carry the prior summary forward instead of re-summarizing it - #64

Merged
he-yufeng merged 2 commits into
mainfrom
feat/rolling-context-summary
Nov 16, 2026
Merged

he-yufeng merged 2 commits into
mainfrom
feat/rolling-context-summary

Conversation

@he-yufeng

Copy link
Copy Markdown
Owner

What this adds

Compression now carries the earlier summary forward instead of summarizing it again.

Every pass used to hand the whole old block to the summarizer, including the summary the previous pass had written. Each round therefore compressed a compression. Detail eroded a little at a time, and nothing looked wrong at any single step.

Measured on a seeded session with a fact in the first message (the deploy key lives in /etc/app/deploy.key), a summarizer that keeps what it is given, and four rounds of continued conversation:

round fact still present summary calls
0 yes 1
1 yes 2
2 yes 3
3 no 4

The fact survives three compressions and is gone on the fourth. On a long task that is exactly the early decision the rest of the work leans on.

How it works

_split_prior_summary recognizes the two markers this manager writes, lifts the prior summary out, and drops the acknowledgement turn that follows it. _summarize_old and _hard_collapse summarize only the turns that arrived since, then prepend the earlier summary verbatim. If nothing new aged out, layer 2 returns False rather than paying for a model call that would rewrite the same text.

The kept-tail boundary still goes through _safe_split, so a tool result is never severed from the tool_calls that produced it.

Tests

tests/test_context_rolling_summary.py, three cases:

  • the second pass summarizes the newly aged turns and never re-reads the summary the first pass wrote
  • three successive passes leave all three summaries present in the head, in order
  • the emergency collapse tier preserves the earlier summary too

Red-green verified twice: with context.py reverted all three fail; restored, all three pass.

tests/ (excluding test_live_smoke.py)   248 passed
ruff check corecoder tests              All checks passed
python -m compileall -q corecoder tests exit 0

test_live_smoke.py needs a real provider key and was not run.

Docs

Both READMEs describe the new behavior in the compression paragraph. The engine LoC badge and prose move 1483 → 1511 and the package totals 2989 → 3020 / 2442 → 2470, which is what test_readme_line_counts_are_current and test_doc_python_line_references_are_current pin; context.py references in article/ move 220 → 251. Those two guards were failing before this change touched the docs and pass now.

Note on formatting: ruff format --check reports pre-existing drift in context.py that predates this branch (the same warning fires on the unmodified file). CI runs ruff check, not ruff format, so I left the unrelated reformatting out of this diff.

…ing it

Each compression pass summarized the whole old block, including the
summary the previous pass wrote. Detail eroded a little at a time: a
fact stated in the first message survived three passes and was gone by
the fourth. Split the prior summary off, summarize only the turns that
arrived since, and prepend the earlier summary verbatim. Same for the
emergency collapse tier.
…summary

# Conflicts:
#	README.md
#	README_CN.md
#	article/00-index.md
#	article/00-index_EN.md
@he-yufeng
he-yufeng merged commit 7cf36f3 into main Nov 16, 2026
14 checks passed
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