Skip to content

fix(chat): resume a background chat tab instead of opening a blank one - #8342

Merged
Kitenite merged 2 commits into
mainfrom
kiet/chat-resume-background-tab
Oct 9, 2026
Merged

Kitenite merged 2 commits into
mainfrom
kiet/chat-resume-background-tab

Conversation

@Kitenite

@Kitenite Kitenite commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Summary

  • The chat journal now stores each chat's agent session id (harnessSessionId) on the session row. Rows written before this get it from the journal the next time getSession reads them.
  • AcpChatPane recovers with the host's stored id when the pane has none, instead of starting a new agent session.
  • Every chat adapter now reports its session id. Before, only the ACP adapter did. The Claude SDK adapter reports the stream's session_id, and the Codex app-server adapter reports its thread id.

Why / Context

A chat that the app adopts into a background tab could open blank later, and switching it to the CLI then failed with "No conversation found with session ID".

listSessions and getSession always returned harnessSessionId: null, because nothing wrote it to the row (setHarnessSessionId had no callers). An adopted pane starts with agent: { id } and learns the agent session id only from the live stream, which runs while the tab is visible. If a background tab's agent stopped (host restart, agent exit), opening the tab ran recovery with no id. That is session/new: a chat with no history. The pane then saved the new session's id, which has no transcript because the session was never prompted, so the CLI could not resume it.

How It Works

  • ChatJournal keeps harnessSessionId in its session cache like title: it takes it from session events, writes it with the projection, and counts a change as a listing change. When it rebuilds a cache from the journal and the row disagrees, it writes the journal's value to the row.
  • getSession reads the journal cursor before the row, so a row that this read backfills comes back filled.
  • AcpChatPane uses agent.sessionId ?? stored.session.harnessSessionId. Recovery only runs after stored loads. The host change alone is not enough: adoption happens when the chat is created, before the agent reports its id.

Manual QA Checklist

Dev desktop over CDP, acp-chat on. A chat was created on the host and adopted into a background tab, then its agent was stopped (closeSession), and the tab was opened:

  • Before: blank chat; the pane pointed at a new session; CLI showed "No conversation found"
  • After: listSessions returns the agent session id; the tab shows the full history; the pane keeps the original id; CLI resumes the same conversation
  • Unchanged and still working: adopt into a visible tab, agent stop while the tab is visible, host-service restart, Chat→CLI→Chat

I ran the background-tab flow end to end for both Claude and Codex chats (claude-acp, codex-acp); both resume their own session in chat and in the CLI. The direct Claude SDK and Codex adapter changes are covered by unit tests only.

Testing

  • bun test in packages/chat-runtime (243 pass). The new projection, Claude adapter and Codex adapter tests fail on main.
  • bun run typecheck in packages/chat-runtime
  • bunx biome check on the changed files
  • bun run typecheck in apps/desktop reports 28 errors, all better-auth type inference in packages/auth and packages/trpc. None are in these files.

Known Limitations

  • A pane that already saved an empty session id is not repaired. Its original conversation can still be resumed from the CLI by the old id.
  • Not addressed here: after a resume the mode shows "Approve for me" instead of the mode the chat had, and a failing --resume leaks a terminal query reply into the prompt.

Summary by CodeRabbit

  • Bug Fixes
    • Chat sessions can resume using the saved session identifier when it isn’t available from the active agent.
    • Session identifiers reported by Claude and Codex are captured and preserved across journal updates, and restored when missing, helping existing sessions remain resumable after data is cleared or rebuilt.
    • Session details now report a cursor only when the session is available and cursor information could be retrieved.

Follow-ups (from review)

  • createSession with resume does not store the resumed id on the row until the agent reports it, so a host restart in that short window still recovers blank. Pass parsed.resume?.harnessSessionId to journal.open.
  • listSessions does not backfill old rows; they list null until getSession reads them. Desktop recovery uses getSession, but mobile's ended-chats list misses old chats until then. Mobile's resume list (NewSessionSheet) now shows entries it never showed before; not tested here.

The chat journal never stored the agent's session id on the session row,
so listSessions/getSession always returned harnessSessionId: null. A chat
adopted into a tab the user never opened had no agent session id. When its
agent stopped, opening the tab recovered with session/new: a blank chat,
and the pane then pointed at that empty session, so switching to the CLI
failed with "No conversation found".

- The journal projects harnessSessionId from session events, and backfills
  rows written before this from the journal.
- AcpChatPane recovers with the host's stored id when the pane has none.
@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3fdc9f2b-25aa-42be-a1ae-a65746683283
📥 Commits

Reviewing files that changed from the base of the PR and between 0740de5 and 60ca006.

📒 Files selected for processing (5)
  • packages/chat-runtime/src/harness/claude/claudeAdapter/claudeAdapter.test.ts
  • packages/chat-runtime/src/harness/claude/claudeAdapter/claudeAdapter.ts
  • packages/chat-runtime/src/harness/codex/codexAdapter/codexAdapter.test.ts
  • packages/chat-runtime/src/harness/codex/codexAdapter/codexAdapter.ts
  • packages/chat-runtime/src/projection/projection.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The chat runtime now captures harness session IDs from Claude and Codex events, retains them in the session projection and journal replay, and uses stored IDs for session lookup and pane resume when needed.

Changes

Harness Session ID Persistence and Resume

Layer / File(s) Summary
Emit harness session IDs
packages/chat-runtime/src/harness/claude/claudeAdapter/*, packages/chat-runtime/src/harness/codex/codexAdapter/*
Claude reports each new string session ID once. Codex includes its active thread ID in the idle session state. Tests cover both behaviors.
Store harness session IDs
packages/chat-runtime/src/projection/projection.ts, packages/chat-runtime/src/projection/index.ts
SessionProjection adds a nullable harnessSessionId. The exported setter updates the field without changing updatedAt, replacing the store method that changed the timestamp.
Retain and replay session IDs
packages/chat-runtime/src/journal/journal/journal.ts, packages/chat-runtime/src/projection/projection.test.ts
The journal preserves harness session IDs across events and restores them from replay. Tests cover retention after a later session update and restoration after the stored value is cleared.
Retrieve and use stored session IDs
packages/chat-runtime/src/commands/commands/commands.ts, apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatPane/components/AcpChatPane/AcpChatPane.tsx
getSession reads the cursor only when a session row exists, then rereads the row. AcpChatPane uses the stored harness session ID when agent.sessionId is absent.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant HarnessAdapter
  participant ChatJournal
  participant SessionProjection
  participant GetSession
  participant AcpChatPane
  HarnessAdapter->>ChatJournal: Emit session event with harnessSessionId
  ChatJournal->>SessionProjection: Write projected harnessSessionId
  GetSession->>ChatJournal: Read cursor and restore projection from replay
  GetSession->>AcpChatPane: Return session with harnessSessionId
  AcpChatPane->>AcpChatPane: Use stored ID when agent.sessionId is absent
Loading

Suggested reviewers: saddlepaddle, harshithmullapudi

Merge Risk: ⚪ Minimal · up to 60ca0

No confirmed new defect blocks merging. A restart before an adapter reports the resumed session ID can still leave that session without a recoverable ID, but that limitation predates this change.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 10 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title uses conventional commit format and clearly describes the primary fix: resuming a background chat tab instead of opening a blank one.
Description check Passed The description clearly explains the problem, implementation, testing, manual QA, limitations, and follow-ups. It does not reproduce the template headings or checklist, but it provides the required in…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ✅ Neon database branch

Thank you for your contribution! 🎉

@greptile-apps

greptile-apps Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

The PR preserves the agent’s session ID on the host and uses it to resume background chat tabs.

  • Chat session reads keep the agent ID used to find history.
  • Chat panes use the stored agent ID when they recover.

Diagram

sequenceDiagram
  participant Agent
  participant Journal as ChatJournal
  participant Row as Session row
  participant Pane as AcpChatPane
  Agent->>Journal: Session event with harnessSessionId
  Journal->>Row: Save harnessSessionId
  Pane->>Journal: getSession reads cursor
  Journal->>Row: Backfill ID from journal when needed
  Row-->>Pane: Stored session and native ID
  Pane->>Agent: Resume with pane ID or stored ID
Loading

Reviews (1) · Last reviewed commit: "fix(chat): resume a background chat tab ..." · Reviewed by Greptile

Copy link
Copy Markdown
Contributor

Review verdict: minor issues (non-blocking). The fix is correct and CI is green.

  • packages/chat-runtime/src/commands/commands/commands.ts:215: createSession opens the journal without harnessSessionId even when resume is set. The row stays empty until the agent reports its id, so a host restart in that window brings back the blank-chat recovery. Pass harnessSessionId: parsed.resume?.harnessSessionId ?? null to journal.open.
  • commands.ts:190-204: listSessions does not backfill. Old rows list null until getSession reads them (I confirmed this with a probe test). Desktop is fine. Mobile's ended-chats list misses old chats. Mention this in Known Limitations.
  • apps/mobile/.../NewSessionSheet.tsx:66-80: the mobile resume list was always empty before. It now appears. This is not in the description and was not tested.
  • Nit, commands.ts:362-366: getSession now writes (backfill), which a reader may not expect.

chat-runtime tests pass at 0740de5f (239 pass, 2 skip), and so does typecheck. The new projection tests fail on main. I could not verify the desktop end to end: the dev renderer came up on port 3007 and Local Admin sign-in failed with "Failed to fetch".

Full report: https://app.superset.sh/page/pr-8342-review-resume-background-chat-tab-pennbc

Only the ACP adapter reported harnessSessionId. The Claude SDK and Codex
app-server adapters accept a resume id but never reported one, so their
chats hit the same blank-chat recovery. Claude now reports the session_id
its stream carries, and Codex reports its thread id.
@Kitenite
Kitenite merged commit 097d239 into main Oct 9, 2026
18 checks passed
@Kitenite
Kitenite deleted the kiet/chat-resume-background-tab branch October 9, 2026 05:40
Kitenite added a commit that referenced this pull request Oct 13, 2026
Changes tab (not Code), drop in-pane review reply, #8326 is a file move,
#8243 and #8342 are acp-chat only, drop 'again' for first-time fixes,
inline the CLI commands instead of a non-runnable code block.
Kitenite added a commit that referenced this pull request Oct 13, 2026
* docs: generate weekly changelog 2026-10-11

* docs(changelog): add 2026-10-11 hero and screenshots

Replace the TODO markers with real captures from the dev desktop app:
the PR page (hero), the Track tasks in setting, and the Plugins page.

* docs(changelog): fix inaccurate 2026-10-11 copy from review

Changes tab (not Code), drop in-pane review reply, #8326 is a file move,
#8243 and #8342 are acp-chat only, drop 'again' for first-time fixes,
inline the CLI commands instead of a non-runnable code block.

This branch was previously deployed

1 inactive deployment
preview — 60ca0063 Deployed Oct 9, 2026 by Kitenite via Deploy Web #11565
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.

2 participants