Skip to content

Fix OpenCode and Codex session resilience#338

Merged
danshapiro merged 20 commits into
mainfrom
fix/opencode-codex-session-resilience-20260511
May 18, 2026
Merged

Fix OpenCode and Codex session resilience#338
danshapiro merged 20 commits into
mainfrom
fix/opencode-codex-session-resilience-20260511

Conversation

@danshapiro
Copy link
Copy Markdown
Owner

Summary

  • Persist and restore durable provider session identity through sessionRef across terminal create, websocket inventory, sidebar state, and agent-chat restore flows.
  • Keep live coding terminals visible/running in the sidebar before provider binding, repair stale pane identity, and fresh-create panes that cannot be resumed after restore-unavailable errors.
  • Bind OpenCode sessions through root-session classification, targeted provider refreshes, and association metadata broadcasts.
  • Add server-side restore/error observability and suppress repeated websocket error logs with summaries.

Verification

  • npm run typecheck passed.
  • Focused restore/bootstrap/OpenCode coverage passed, including:
    • npm run test:vitest -- test/unit/client/components/App.ws-bootstrap.test.tsx --run
    • npm run test:vitest -- test/unit/server/coding-cli/opencode-activity-tracker.test.ts --run
    • npm run test:vitest -- test/server/ws-handshake-snapshot.test.ts test/server/session-association-broadcast.test.ts --run
    • npm run test:vitest -- test/e2e/terminal-restart-recovery.test.tsx test/unit/client/components/TerminalView.resumeSession.test.tsx test/e2e/agent-chat-resume-history-flow.test.tsx --run
  • git diff --check passed.
  • npm run verify still fails in existing broad-suite clusters outside the final review patch: agent tab write tests, legacy/noncanonical agent-chat restore expectations, and Codex registry/app-server recovery tests.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cb78417627

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread server/ws-handler.ts
Comment on lines +2567 to +2571
this.sendError(ws, {
code: 'INVALID_TERMINAL_ID',
message: 'Terminal not running',
requestId: m.attachRequestId,
terminalId: m.terminalId,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep INVALID_TERMINAL_ID attach errors requestless

terminal.attach now includes requestId: m.attachRequestId in INVALID_TERMINAL_ID errors, but the client’s recovery path in TerminalView only runs when msg.requestId is absent (msg.code === 'INVALID_TERMINAL_ID' && !msg.requestId). In attach-failure cases (for example, stale terminal IDs after reconnect), this change prevents the auto-recreate logic from running and leaves the pane stuck instead of recovering. Either keep attach errors requestless (as before) or update client-side handling to treat attach request IDs as recoverable invalid-terminal signals.

Useful? React with 👍 / 👎.

Comment on lines +163 to +165
forgetTerminal(terminalId: string): void {
pendingByTerminalId.delete(terminalId)
},
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Clear association caches when forgetting terminals

The new association publisher keeps publishedPairs and activeTerminalBySession entries forever, while forgetTerminal only removes pendingByTerminalId. On long-lived servers that cycle through many sessions/terminals, these sets/maps grow unbounded and retain stale dedupe state, creating a memory/perf regression introduced by this change. forgetTerminal should also evict keys tied to the terminal from the other caches.

Useful? React with 👍 / 👎.

@danshapiro danshapiro merged commit 47172ab into main May 18, 2026
1 check passed
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