Skip to content

fix(web-ui): prevent ACP session hydrate deadlock on re-switch - #2137

Open
xielixing wants to merge 1 commit into
GCWing:mainfrom
xielixing:fix/issue-1038
Open

fix(web-ui): prevent ACP session hydrate deadlock on re-switch#2137
xielixing wants to merge 1 commit into
GCWing:mainfrom
xielixing:fix/issue-1038

Conversation

@xielixing

Copy link
Copy Markdown

Problem

When switching back to a previously-loaded ACP session, the UI shows a permanent loading overlay and never displays content. The agent appears stuck.

Issue: #1038

Root Cause

A deadlock in switchChatSession (SessionModule.ts) for ACP sessions:

  1. shouldHydrateHistoricalSessionBeforeSwitch returns true for isHistorical sessions with no renderable content
  2. shouldActivateBeforeHydrate requires consumeRecentHistorySessionOpenIntent(sessionId) — but running ACP sessions never get an intent (they're filtered by isRunning in SessionsSection.tsx)
  3. With shouldActivateBeforeHydrate=false, the flow is hydrate-first-then-activate (lines 700-728)
  4. hydrateHistoricalSession defaults deferFullHistoryUntilActive=true (line 256)
  5. When hydrate completes, activeSessionId !== sessionId is still true (activation hasn't happened yet) → skipStaleLocalHydrateCommit in FlowChatStore.ts:7398-7401 fires and discards the loaded turns, resetting to metadata-only
  6. Then switchSession(sessionId) activates it (line 728) — but with empty turns and metadata-only state, the overlay is stuck forever

Fix

Pass deferFullHistoryUntilActive: false for ACP sessions in the hydrateHistoricalSession call within switchChatSession. This ensures the hydrate commit is not discarded even when activation happens after hydration. The subsequent switchSession call then activates a session that already has its loaded turns.

Changes:

  • Import isAcpFlowSession from ../../utils/acpSession
  • Pass deferFullHistoryUntilActive: !isAcpFlowSession(session) to the hydrate call

Non-ACP sessions retain the default true behavior (defer until active), so this change has no effect on existing session switching behavior.

Testing

  • TypeScript compilation passes (no new type errors)
  • Existing session switching behavior for non-ACP sessions is unchanged
  • ACP sessions now properly commit their loaded history even when activation follows hydration

When switching back to a previously-loaded ACP session, the UI showed
a permanent 'loading saved session' overlay. The root cause was a
deadlock in switchChatSession: ACP sessions never receive a history
session open intent (filtered by isRunning), so shouldActivateBeforeHydrate
was false. This meant hydration ran before activation, and with the
default deferFullHistoryUntilActive=true, the stale-commit guard in
FlowChatStore discarded the loaded turns (resetting to metadata-only).
Then activation happened on an empty session, leaving the overlay stuck.

Fix: pass deferFullHistoryUntilActive=false for ACP sessions so the
hydrate commit is preserved even when activation hasn't happened yet.
The subsequent switchSession call then activates a session that already
has its loaded turns.

Fixes GCWing#1038
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant