Repository navigation
feat(compaction): Request a background summary after each model call - #2743
Merged
Merged
Conversation
Co-Authored-By: Thomas Jiang <20501235+thomasjiangcy@users.noreply.github.com> Co-Authored-By: Thomas Jiang <thomas.jiang@sentry.io>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
1 screenshot change — 1 changed · 0 added · 0 removed Review screenshots in Frameshift
|
thomasjiangcy
approved these changes
Nov 5, 2026
This branch was successfully deployed
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.
A background summary was requested only after the agent loop ended, so a single long Turn that crossed the compaction threshold mid-run never had one ready. Since #2648 shipped, prod traces show no
over_targetdiscards. The inline compactions that remain areactiveones (~20s inside the Turn), and mid-Turn swaps almost never apply.The request now runs in
prepareNextTurnWithContext, after every model call. That covers the final reply too, so the Turn-end call is removed. Pi waits forturn_endlisteners before this hook, so the tool results are already committed when the mark is taken, and the mark lands on a safe cut after a tool result. The request is skipped when the hook just replaced history, because the last usage then counts the old history.The hook runs before every model call, so the check above the mark now reads only the newest
compaction_requested/compaction_preparedfact first. It loads the full history only when no request is pending and no summary became ready in this slice.loadLatestBackgroundCompactionmoves from the swap module intobackground-compaction.ts, so both use one copy.The mid-Turn swap stays at the threshold. Swapping as soon as a summary is ready would break the warm prompt cache in the middle of a Turn.
Test coverage gap: I verified the hook wiring with a real-agent integration test (Slack harness, scripted model stream). It fails on main and passes here. I did not commit it, because
test-architecture:checkdoes not allow tests inpackages/junior/teststo run the agent. An integration eval would have to tune the context window to real token counts, and I couldn't run evals in this environment. Only the request rule is covered: a pending request blocks another one. Decide whether you want an eval before merge.via @thomasjiangcy.
--
View Session [Sentry]