nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] Failed session resume clears webview transcript while retaining previous session ID in client

Open akramcodez opened this issue 1 month ago • 2 comments

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

  1. Have an active conversation in session A.
  2. Attempt to resume an invalid or missing session ID from History (or simulate a backend failure on resumeSession).
  3. Observe the Failed to resume session error notification.
  4. 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-493
    • plugins/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 during resumeSession(). Replace the transcript with buffered history only on confirmed success; on failure, discard the buffer and retain the existing transcript.

akramcodez avatar Oct 12 '26 11:10 akramcodez

Taking this will propose my plan

rishu685 avatar Oct 12 '26 15:10 rishu685

Hi @akramcodez, here is my proposal to fix this:

Root Cause

  1. ChatWebviewProvider eagerly sends postMessage({type: 'clear', isLoading: true}) before acpClient.resumeSession resolves, wiping messagesContainer.innerHTML.
  2. NanocoderAcpClient.resumeSession() catches errors internally and returns Promise<void>, keeping _sessionId on session A without informing the caller.
  3. The .finally() block unconditionally sends sessionLoaded, leaving an empty transcript while subsequent messages continue session A on the backend.

Implementation Plan

  1. Propagate Status in NanocoderAcpClient (acp-client.ts):

    • Change resumeSession(sessionId: string): Promise<boolean>.
    • Return true on success; catch backend rejection, display the error toast, keep _sessionId intact, and return false.
  2. Buffer Replay & Atomic Switch in ChatWebviewProvider (chat-webview-provider.ts):

    • Add _resumingSessionId and _resumeBuffer: any[].
    • Buffer incoming onSessionUpdate notifications 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, send postMessage({type: 'clear'}), replay all buffered updates to rebuild transcript, and send sessionLoaded.
    • On Failure (false): Discard _resumeBuffer, retain existing transcript and session A state, and dismiss the loading indicator via sessionLoaded.
  3. Webview Protocol (webview-protocol.ts & chat-panel.js):

    • Add non-destructive loading handling (sessionResuming) so existing DOM isn't wiped before resume succeeds.
  4. Testing:

    • acp-client.spec.ts: Verify resumeSession returns true on success, false on failure, and retains existing _sessionId.
    • chat-webview-provider.spec.ts: Test failed resume does NOT call clear and retains transcript; test successful resume buffers replay, clears old DOM, flushes buffered messages, and completes.

Could you please assign this issue to me?

rishu685 avatar Oct 13 '26 06:10 rishu685