[Bug] Failed session resume clears webview transcript while retaining previous session ID in client
Description
When resuming a session fails (e.g. session file corrupted, missing, or server throws), the webview has already executed postMessage({type: 'clear', isLoading: true}). Because the thrown error prevents this._sessionId = sessionId from executing in NanocoderAcpClient.resumeSession(), the client retains the original session ID. The webview's .finally() block then sends sessionLoaded, leaving the user looking at an empty transcript while any subsequent prompt continues the old conversation on the backend.
Environment
- OS: Linux (reviewed); macOS / Windows potentially affected
- Node version: >= 22.0.0
- Nanocoder version: 1.31.0
- Provider: Any
- Model: Any
Steps to Reproduce
- Have an active conversation in session A.
- Attempt to resume an invalid or missing session ID from History (or simulate a backend failure on
resumeSession). - Observe the
Failed to resume sessionerror notification. - Type a message in the empty chat input and press Send.
Expected Behavior
The UI should preserve the existing transcript while buffering target-session replay during resumeSession(). On successful resume, replace the transcript with the buffered history. On failure, retain the existing conversation and report the error without altering client session binding.
Actual Behavior
The visible transcript is cleared, but NanocoderAcpClient._sessionId still points to session A. The user's next message is appended to session A on the backend behind an empty UI transcript.
Logs/Screenshots
(Illustrative trace)
[Webview] User resumed session: invalid_id
resumeSession failed: Error: Session file not found
[Webview] postMessage: sessionLoaded
Additional Context
- [x] No matching open issue found in issue search performed on 2026-10-12
- [x] Client-state retention reproduced using a mocked ACP connection; UI clear verified in source
- [x] Relevant code paths inspected at commit
d5ff9c37
Implementation Notes (optional)
- Files:
plugins/vscode/src/acp-client.ts:473-493plugins/vscode/src/chat-webview-provider.ts:361-371
- Have
acpClient.resumeSession(sessionId)return a boolean or propagate errors rather than swallowing them. - In
ChatWebviewProvider, buffer incoming history replay duringresumeSession(). Replace the transcript with buffered history only on confirmed success; on failure, discard the buffer and retain the existing transcript.
Taking this will propose my plan
Hi @akramcodez, here is my proposal to fix this:
Root Cause
ChatWebviewProvidereagerly sendspostMessage({type: 'clear', isLoading: true})beforeacpClient.resumeSessionresolves, wipingmessagesContainer.innerHTML.NanocoderAcpClient.resumeSession()catches errors internally and returnsPromise<void>, keeping_sessionIdon session A without informing the caller.- The
.finally()block unconditionally sendssessionLoaded, leaving an empty transcript while subsequent messages continue session A on the backend.
Implementation Plan
-
Propagate Status in
NanocoderAcpClient(acp-client.ts):- Change
resumeSession(sessionId: string): Promise<boolean>. - Return
trueon success; catch backend rejection, display the error toast, keep_sessionIdintact, and returnfalse.
- Change
-
Buffer Replay & Atomic Switch in
ChatWebviewProvider(chat-webview-provider.ts):- Add
_resumingSessionIdand_resumeBuffer: any[]. - Buffer incoming
onSessionUpdatenotifications while resume is in flight instead of streaming them immediately to the UI/state controllers. - Show a non-destructive loading state without clearing the existing transcript.
- On Success (
true): Reset plan review/artifacts, sendpostMessage({type: 'clear'}), replay all buffered updates to rebuild transcript, and sendsessionLoaded. - On Failure (
false): Discard_resumeBuffer, retain existing transcript and session A state, and dismiss the loading indicator viasessionLoaded.
- Add
-
Webview Protocol (
webview-protocol.ts&chat-panel.js):- Add non-destructive loading handling (
sessionResuming) so existing DOM isn't wiped before resume succeeds.
- Add non-destructive loading handling (
-
Testing:
acp-client.spec.ts: VerifyresumeSessionreturnstrueon success,falseon failure, and retains existing_sessionId.chat-webview-provider.spec.ts: Test failed resume does NOT callclearand retains transcript; test successful resume buffers replay, clears old DOM, flushes buffered messages, and completes.
Could you please assign this issue to me?