Repository navigation
feat(agent): carry the user's own earlier wording across compaction - #303
Conversation
|
Thanks for working on this. Losing the user's own wording after compaction is a real concern, and the tests are careful. Running it in a real session showed a few things we need sorted before merging:
A shape we'd accept:
A short note on a real run where the summary lost the task would help us pick the budget. |
ff993b0 to
1c25bb4
Compare
|
Thanks — all four points were right, and your reproduction matched mine exactly. 1. The checkpoint keeps the wrong message. Confirmed on a real 2. It is not "the original task" any more. The heading is neutral: "Earlier messages from the user (most recent first):". Ordering is newest-first under a small budget, exactly as you asked. 3. The kept text is bounded. Measured before → after on the same session shape:
4. The description no longer cites code that doesn't exist. The test you asked for — One thing worth stating rather than hiding: 13 tests pass, I also revised two assertions this branch had added: they asserted "the original task (MSG0) survives", which is precisely what a newest-first budget stops doing. They now restate main's expectation. |
The summary is lossy by design, and the one thing it should not be allowed to
paraphrase away is what the user actually asked for. This carries the user's own
earlier messages over the checkpoint boundary, quoted verbatim.
Two things the first revision got wrong, both visible in a real session:
- **It took "the first user message", which is the environment slot.** Every
session with a workspace starts with `{"role": "user", "env_context": True}`,
so the helper returned the environment dump. Measured on a real
`AgentSession(workspace=…)` + `compact()`: a 6,363-character request was
replaced by a 229-character environment dump, and the request itself was gone
from the whole history.
- **It kept up to 60,000 characters under a permanent "ORIGINAL TASK" label.**
That both swamped the checkpoint and pinned the model to old work — in a
multi-turn session the first message is often not what is being worked on.
Now: the user's own earlier messages, newest first, under a few-thousand
character budget, under a neutral heading ("Earlier messages from the user (most
recent first):"). The environment slot, checkpoints and empty content are
skipped; a message already in the kept tail is not repeated; a single oversized
message is truncated to the budget rather than skipped.
The block is also bounded by the space the compaction actually freed, minus a
reserve for the runner's PreCompact checkpoint re-injection. Both draw on the
same reduction, and an earlier revision consumed all of it: a neighbouring test
showed the hook's context truncated to three characters. When there is not
enough room the block is simply absent, which is exactly what main does.
Re-compaction re-reads the block from the previous checkpoint, so a second round
does not lose it.
Runtime notes are not filtered by `is_context_note()`: by the time this runs the
kernel history projection has already dropped user-role metadata, so no marker
is left to test. The skip is shape-based, and the docstring says so.
Tests: tests/test_session_compaction.py 13 passed; the neighbouring
tests/test_session_end_lifecycle.py matches main exactly (4 pre-existing local
failures, unchanged). New coverage pins newest-first ordering, the budget,
env-slot/checkpoint skipping, the neutral heading, re-compaction carry-forward,
and one end-to-end case that drives `AgentSession(workspace=…)` and
`await session.compact()`.
Two assertions this branch had added now restate main instead: they claimed
"the original task (MSG0) survives", which is precisely the behaviour being
removed.
ruff 0.15.21 check and format clean.
1c25bb4 to
8f42701
Compare
|
The first push of this went red on all three Python legs ( That was mine, and worth explaining because it is the same constraint the block has to respect.
My block was appended to the checkpoint unconditionally, so it consumed that room. In the neighbouring test the hook's context arrived truncated to The block is now bounded by the space the compaction actually freed, minus a reserve for that re-injection: When there is not enough room the block is simply absent — which is exactly main's behaviour — rather than squeezing the hook context out. Verification, and the reason I trust this one:
Two integration tests in that file also had to grow a bulky dropped message: with a toy history the compaction frees nothing, so carrying nothing is the correct answer and the old shapes were asserting a behaviour that cannot happen at that size. New head: |
|
Merged in f187f0d. Thank you for sticking with this one. You were right that runtime notes couldn't be told apart at that layer. In fact the live history never marked them either. The follow-ups (311f8b6 and dada732) change five things:
We also ran a before/after test with a real model. The session set three rules in its first message, then went through two compactions:
|
|
@raymondginger2018-sudo One more thing: we're now steering DeepCode toward recursive self-improvement (RSI), an agent that gets better from its own runs. If you have ideas there, bold ones are welcome. For anything large, open an issue first so we can talk it through before you write the code. |
Add the news entry and changelog for the 2026-11-16 community batch (#289, #293, #303, #307) and fold the 2026-10-31 entry into the earlier updates. The three points under "What Deep means" now match the numbered parts of the framework figure, self-evolution is named as planned, and "Why DeepCode" no longer repeats them.
Summary
The summary is lossy by design, and the one thing it should not be allowed to paraphrase away is what the user actually asked for. This carries the user's own earlier messages over the checkpoint boundary, quoted verbatim.
What the first revision got wrong
Both were visible in a real session, not just in review:
{"role": "user", "env_context": True}. Measured on a realAgentSession(workspace=…)+compact(): a 6,363-character request was replaced by a 229-character environment dump, and the request was gone from the whole history.ORIGINAL TASKlabel. That swamped the checkpoint (52,311 → 48,064 characters, where main goes to 8,015) and pinned the model to old work — in a multi-turn session the first message is often not what is being worked on any more.What it does now
EARLIER_USER_CHARS = 4_000).On runtime notes: they are not filtered by
is_context_note()here, because by the time this runs the kernel history projection has already dropped user-role metadata — there is no marker left to test. The skip is shape-based, and the docstring says so.Changes
2 files, +251 / -4.
core/agent_runtime/compaction.py—_earlier_user_messages()(newest-first, budgeted), the neutral heading, and the checkpoint wiring.tests/test_session_compaction.py— new coverage.Two assertions this branch had added now restate main instead: they claimed "the original task (MSG0) survives", which is exactly the behaviour being removed.
Tests
tests/test_session_compaction.py— 13 passed. New cases pin:ORIGINAL TASKis gone;AgentSession(workspace=…)andawait session.compact().ruff 0.15.21 checkandformat --checkclean. Rebased onto3dcb0fb4.Dependency note
None. One module plus its tests.