fix(session): avoid repeated full-history summary loads during multi-step loops#21762
Open
sjawhar wants to merge 1 commit intoanomalyco:devfrom
Open
fix(session): avoid repeated full-history summary loads during multi-step loops#21762sjawhar wants to merge 1 commit intoanomalyco:devfrom
sjawhar wants to merge 1 commit intoanomalyco:devfrom
Conversation
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.
Issue for this PR
Closes #21761
Type of change
What does this PR do?
Fixes a high-impact session performance bug where tool-using sessions repeatedly reloaded the full session history during a single user prompt.
Root cause:
SessionProcessorcalledSessionSummary.summarize(...)inside thefinish-stephandlerfinish-stepruns once per assistant model turn, not once per overall user promptSessionSummary.summarize(...)loads the full session history withsessions.messages({ sessionID })Fix:
SessionSummary.summarize(...)call fromsession/processor.tssession/summary.tsto return early when the target user message already hassummary.diffsHow did you verify your code works?
cd packages/opencode && bun test test/session/prompt-effect.test.ts --test-name-pattern 'loop continues when finish is tool-calls|loop continues when finish is stop but assistant has tool parts|loop summarizes once across a multi-step tool run'cd packages/opencode && bun test test/session/processor-effect.test.tscd packages/opencode && bun typecheckRegression evidence
New regression test went red → green:
summaries = 3summaries = 1That reproduces the bug directly in a two-step tool loop and proves the processor-side summary call was the repeated trigger.
Live diagnostic evidence
Labeled diagnostic binary showed the bad sequence in a real frozen session:
prompt loop entry: 4summary start: 4summary loaded messages: 4prompt loop summary trigger: 1prune start: 0session messages full: 10message hydrate: 45This proved:
Notes
dev; unrelated to this changeChecklist