Skip to content

feat(agent): keep every user turn verbatim across compaction + structured facts digest#4052

Merged
esengine merged 1 commit into
main-v2from
fix/compaction-keep-all-user-turns
Jun 11, 2026
Merged

feat(agent): keep every user turn verbatim across compaction + structured facts digest#4052
esengine merged 1 commit into
main-v2from
fix/compaction-keep-all-user-turns

Conversation

@esengine

Copy link
Copy Markdown
Owner

Follow-up to #4048. That PR pinned the first user turn; this adds the deterministic floor for facts stated at any point, plus a structured consolidation layer.

Base layer — the guarantee

Compaction now keeps every small user turn verbatim and folds only assistant/tool work (and oversized user pastes). A fact the user states mid-session — "always deploy to eu-west-3, never us-east-1" at turn 4 — is preserved in its own words regardless of how the summarizer behaves. This removes the model from the loop for user-stated facts: the only way to guarantee a fact stays in context is to never let a model re-generate it.

partitionFold splits the compaction region into kept (small user turns) and folded (the rest); the kept turns are spliced back verbatim before the digest.

Upper layer — the tidy view

The digest leads with a structured ## Standing facts & constraints section that consolidates what the user stated into one clean list. It's redundant with the verbatim turns by design — best-effort consolidation on top of a deterministic floor, so a weak summarizer dropping a fact there loses nothing.

Real-provider A/B

5-turn session, 14k window, 18 folds. Fact A stated turn 1, fact B ("eu-west-3") stated mid-session at turn 2; final turn asks for both.

mid-session fact B in the final request
this PR verbatim user turn present (deterministic) + also in the digest's facts section
#4048 only 0 verbatim user turns — survived only inside compaction summaries, i.e. by luck; one degenerate fold from loss

Both recalled the fact this run (the old summary happened to keep it), but the mechanism differs: the floor makes presence structural, not stochastic.

Tests

New TestCompactKeepsMidSessionUserTurns (a mid-session user fact survives a fold verbatim while the work folds). Existing compaction/prune tests unchanged and green; go test ./internal/agent/..., control, boot pass.

…digest

Builds on the first-turn pin (#4048): the deterministic floor now covers a fact
the user states at ANY point, not just the opening turn. Compaction keeps every
small user turn verbatim and folds only the assistant/tool work, so a mid-session
"always deploy to eu-west-3" survives regardless of how the summarizer behaves.

On top of that floor, the digest now leads with a structured "Standing facts &
constraints" section consolidating what the user stated into one tidy view —
redundant with the verbatim turns by design, so a weak summarizer dropping a fact
there loses nothing.
@esengine esengine requested a review from SivanCola as a code owner June 11, 2026 14:54
@github-actions github-actions Bot added v2 Go rewrite (1.x) — main-v2 branch, active development agent Core agent loop (internal/agent, internal/control) and removed v2 Go rewrite (1.x) — main-v2 branch, active development labels Jun 11, 2026
@esengine esengine merged commit d014949 into main-v2 Jun 11, 2026
14 checks passed
@esengine esengine deleted the fix/compaction-keep-all-user-turns branch June 11, 2026 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent Core agent loop (internal/agent, internal/control)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant