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
fairyhunter13
added a commit
to fairyhunter13/opencode
that referenced
this pull request
Apr 10, 2026
Port anomalyco/sst upstream dev's proven sync architecture to permanently
fix the flaky "blank subagent view" bug where ctrl+x down into a running
subagent showed an empty content area until completion.
sync.tsx:
- Remove `force` parameter from session.sync()
- Always mark fullSyncedSessions after fetch (drop time.completed gate)
- Remove redundant session.created handler (session.updated upserts)
- Match upstream/dev byte-for-byte in sync-relevant sections
routes/session/index.tsx:
- Task component: createEffect -> onMount with empty-messages guard
- Route-level sync: drop force=true argument
Preserved defensively (ahead of upstream):
- worker.ts + server/routes/event.ts still use GlobalBus.on("event", ...)
as defense-in-depth on top of InstanceState shared PubSub
- worker.ts WASM stdout/stderr capture to suppress Aborted() TUI corruption
- worker.ts per-directory filter in GlobalBus.on handler
provider.ts:
- Raise FLOOR_CEILINGS.critical from 4 to 10 for non-Anthropic providers
- Expand isAnthropicParent to also match parentModelID containing "claude"
(covers claude-via-proxy cases)
transform.ts:
- Preserve assistant messages with reasoning blocks verbatim to avoid
Anthropic 400 "thinking blocks cannot be modified" (ref upstream PR anomalyco#21370)
- Enable 4-BP cache strategy for GitHub Copilot Claude models
llm.ts:
- Use 5m TTL for short-lived subagent BP2 cache breakpoint; 1h for long-lived
processor.ts:
- Remove duplicate SessionSummary.summarize() call that triggered full-history
DB hydration on every LLM step in multi-step tool loops (ref upstream anomalyco#21762)
Tests:
- task-escalation.test.ts: update FLOOR_CEILINGS critical assertions to
match new ceiling (critical > opus, toBe(10)); expand coverage
- cache-max-efficiency-e2e.test.ts: new E2E test validating Anthropic prompt
cache hit rate across multi-turn conversations
Skill:
- Add opencode-prompt-cache-maximization skill (CLAUDE.md)
Submodule:
- Bump cmd/opencode-search-engine to include idle CPU perf improvements
Root cause: our prior fullSyncedSessions + time.completed guard raced
with Task.createEffect's fire-and-forget sync(id, force=false) -- first
fetch at T=0 returned 0 messages, session was never marked synced,
and no re-sync trigger existed, leaving the view blank until the
subagent finished.
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