Skip to content

fix(agent-hooks): follow Claude sessions continued into a daemon job (#24117) - #26569

Closed
mtsr404 wants to merge 4 commits into
stablyai:mainfrom
mtsr404:mtsr404/fix-continued-in-native-chat
Closed

mtsr404 wants to merge 4 commits into
stablyai:mainfrom
mtsr404:mtsr404/fix-continued-in-native-chat

Conversation

@mtsr404

@mtsr404 mtsr404 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Claude Code can move the conversation in an Orca terminal into a background job while the terminal keeps showing it. Orca never hears about the new conversation, so the phone keeps showing the old one. Claude leaves a note in the old conversation file saying where it continued, and Orca now follows that note.

What Changed

Before: Claude Code can fork a pane's session into a daemon job while the same pane keeps showing it. On Claude Code 2.1.280, pressing ← to open the agent view and then Enter to reopen the conversation does this. #15304 makes the hook script drop all of the job's hooks, so the pane's row keeps the old providerSession, and on mobile:

  • Native chat stays frozen on the old transcript. Reinstalling the app doesn't help, since the row lives on the desktop host.
  • Stop still goes to the pane, so it interrupts the live job, which the phone isn't showing.

After: on the existing presence recheck (a real title change or a finished command), the execution host reads the tail of the row's transcript for Claude's continued-in record. If the forked transcript is in the same project directory and its records carry the new id, the host rewrites only the row's providerSession, as a replay, so the state and evidence age don't change. /clear inside the job starts another transcript without writing continued-in, so the host also follows the job's state.json when its resumeSessionId names a later session in the same directory. Mobile chat then reads the new transcript. SSH hosts run orcad, which uses this same hook server, and the WSL guest's hook relay does the same for WSL panes.

Why

This is direction 2 from #24117, where @dimakrest worked out the root cause and both directions.

It keeps #15304's rule: nothing comes from the worker's environment. The only evidence is the pane's own transcript, which the row already records. Per the Agent Status rule in AGENTS.md, it is a producer writing to the hook server's store, so no reader adds its own precedence. I didn't take these alternatives:

  • Following the pointer in mobile or the native-chat reader would put precedence in a reader, and for remote hosts it would read on the client.
  • Polling would add a loop. The title-change recheck already fires while the job repaints the pane.
  • Re-attributing the job's own hooks (direction 1) is needed for live state. It is a larger change that complements this one.

Limits:

  • This fixes which session the pane shows, not its live state, which still comes only from OSC titles. Because the rebound row is a replay, Orca also won't infer an interrupt for it from terminal output.
  • /background followed by claude attach isn't covered. There the pane's claude exits and Orca clears the row first, so there is no old session to follow. That case still needs direction 1.

Linked Issue

Fixes #24117

Visual Proof

No screenshots, since the visible change is a chat that stays current instead of freezing. I ran the same steps on this branch and on 1.4.223 with an Android phone; see Testing.

Testing

  • claude-session-continuation.test.ts (13 tests): a pointer that isn't the last line, a pointer for another session, a fork file that doesn't name the session, a fork that reaches disk after the first check, a pointer appended after an empty scan, a transcript larger than the first scan, the job state.json fallback and its directory guard, a chain with a cycle, and /clear inside a job (followed after the transcripts stop growing; ignored when the job state names the same session, points outside the project, or names a file without that id).

  • server-claude-session-continuation.test.ts (4 tests): real hook posts, then checkAgentPresence.

    • The rebinding updates last-status.json and leaves state and prompt unchanged.
    • A suspension seen after the rebinding is applied as fresh evidence, not as a replay.
    • There is no rebinding without a pointer.
    • There is no rebinding when another pane reports the fork.
  • src/wsl-guest/agent-hook-server-claude-session-continuation.test.ts (2 tests): the WSL guest's relay forwards the fork with isReplay, and a later suspension without it.

  • The rebinding, other-pane, WSL relay, /clear and suspension tests fail with their call or guard removed.

  • pnpm typecheck, the changed-lines quality gate, the max-lines ratchet and anti-slop pass.

  • pnpm test src/main/agent-hooks src/wsl-guest src/shared/agent-hook-listener (2300 tests) passes.

  • Manual A/B on macOS with Claude Code 2.1.280 and the Android app, in a throwaway repo. Steps: start claude in a pane and send a prompt, press ← then Enter to reopen it as a job, then send another prompt.

    • This branch (pnpm dev): the pane's row moved to the job's session, and mobile chat showed the reply to the second prompt.
    • Orca 1.4.223: the pane's row stayed on the old session and was never updated after the first prompt.
  • On my original case, the tracker resolves the real 912 MB transcript to its fork in about 5 ms.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

I used Claude Code (Claude Opus 5.5) to investigate, implement and test this, and I reviewed the result.

Review

AI review summary:

  • Cross-platform: paths go through node:path, with no platform-specific code.
  • SSH and WSL: transcripts are read on the host that owns them. SSH hosts run orcad with this hook server; main skips rows relayed from WSL (they carry a connectionId), and the WSL guest's relay handles them inside the distro.
  • Agents: this applies only to Claude rows. Structured sessions and identity-only placeholders are skipped.
  • Performance: the first scan reads at most the last 1 MB of a transcript. After that it reads only appended bytes, and it skips files whose size hasn't changed.
  • Security: it opens only the recorded transcript, files in the same directory, and the matching job's state.json. The new id is validated with normalizeAgentProviderSession.
  • Compatibility: there are no new wire fields, so older clients and mobile builds are unaffected.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Security, cross-platform, SSH, mobile, backwards compatibility and performance are covered in the review summary above.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Oct 8, 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: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 206b11c3-3248-4428-8cd4-c559f4f58062
📥 Commits

Reviewing files that changed from the base of the PR and between d67721d2e1019182953156d652e1d61085a8aec6 and d263cf14e86db4c96ebc23058d30ea4558bdada2.

📒 Files selected for processing (5)
  • src/shared/agent-hook-listener/claude-session-continuation.test.ts
  • src/shared/agent-hook-listener/claude-session-continuation.ts
  • src/wsl-guest/agent-hook-server-claude-session-continuation.test.ts
  • src/wsl-guest/agent-hook-server.ts
  • src/wsl-guest/relay-agent-presence.ts

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

📝 Walkthrough
📝 Walkthrough

Walkthrough

The change adds Claude transcript continuation tracking. Main-process and relay presence checks can rebind an eligible pane to a validated fork session and publish the rebound row as a replay. The tracker checks transcript pointers and job state, validates fork transcripts, and limits scanning and continuation hops. Tests cover continuation resolution, pane rebinding, and replay handling.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to d263c

No merge-blocking issue was identified in the continuation rebinding paths. Merge after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 24 functions across 10 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed Issue #24117 includes in-place continuation as a valid solution. ClaudeSessionContinuationTracker follows validated continued-in records and the job-state fallback for /clear. The main hook serv…
Out of Scope Changes check Passed The production changes support #24117. The shared tracker reads pane transcript evidence, presence checks apply the rebinding, and the WSL relay forwards the replay behavior. The added tests verify th…
Title check Passed The title clearly identifies the main change: following Claude sessions that continue into a daemon job.
Description check Passed The description is complete and focused. It covers the user impact, implementation, rationale, linked issue, scope limits, testing, manual verification, and compatibility considerations. The remaining…
Full details: Linked Issues check

Explanation

Issue #24117 includes in-place continuation as a valid solution. ClaudeSessionContinuationTracker follows validated continued-in records and the job-state fallback for /clear. The main hook server and WSL relay rebind the pane row with isReplay while preserving the existing state evidence. The added tracker, server, and relay tests cover these paths. Attach-based rebinding and live daemon-hook status remain outside this PR objective.

Full details: Out of Scope Changes check

Explanation

The production changes support #24117. The shared tracker reads pane transcript evidence, presence checks apply the rebinding, and the WSL relay forwards the replay behavior. The added tests verify this behavior. No unrelated production behavior or unrelated test coverage is demonstrated.

Full details: Description check

Explanation

The description is complete and focused. It covers the user impact, implementation, rationale, linked issue, scope limits, testing, manual verification, and compatibility considerations. The remaining unchecked lint and build items do not make the description incomplete because the author reports other validation and CI can cover them.

  • Fix all pre-merge checks with AI
  • Autopilot · 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/shared/agent-hook-listener/claude-session-continuation.test.ts (1)

11-16: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Delete the temp directories after each test.

makeProject calls mkdtempSync in every test and never removes the result. The test at Line 92 writes about 3 MB per run. Every CI or local run leaves these files in tmpdir(). Add an afterEach that removes each created configDir.


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d24de933-5509-462a-9a6f-c4f59e891ba8
📥 Commits

Reviewing files that changed from the base of the PR and between 7c50009 and da2bfb57d3f7f8bc4907acbb09711ffb24db1284.

📒 Files selected for processing (7)
  • src/main/agent-hooks/server-claude-session-continuation.test.ts
  • src/main/agent-hooks/server/server-agent-presence.ts
  • src/relay/agent-hook-server-claude-session-continuation.test.ts
  • src/relay/agent-hook-server.ts
  • src/relay/relay-agent-presence.ts
  • src/shared/agent-hook-listener/claude-session-continuation.test.ts
  • src/shared/agent-hook-listener/claude-session-continuation.ts

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

@Sangkwun

Sangkwun commented Oct 9, 2026

Copy link
Copy Markdown

One case this doesn't reach: /clear inside the job. Claude starts a new transcript and writes no continued-in into the old one, so the chain ends at the job's first transcript.

Seen on Orca 1.4.222 (macOS) with Claude Code 2.1.291 in the job. The pane's transcript 85360788… points to 656cfd7b…. Two /clears in the job then started a84bdafa… and f74ed070…, and neither 656cfd7b… nor a84bdafa… has a continued-in record. The job's state.json has sessionId: 656cfd7b…, and its linkScanPath and resumeSessionId point at f74ed070…. resolve follows only continued-in, so the row would stop at 656cfd7b… even though state.json now names f74ed070….

In the same pane, a Codex run started from the job later relabelled the row as Codex (#24516, #24641), so from then on the Claude-only check here no longer runs for this row.

@mtsr404
mtsr404 force-pushed the mtsr404/fix-continued-in-native-chat branch from d67721d to d263cf1 Compare October 11, 2026 09:17
@mtsr404

mtsr404 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, good catch. I reproduced it on Claude Code 2.1.280: after /clear in the job, the job's first transcript has no continued-in, and its state.json names the new transcript in resumeSessionId and linkScanPath.

d263cf14e8 follows that. When the row's session has a job state whose resumeSessionId names another session, and the linkScanPath transcript sits beside the old one and carries that id, the row moves to it. This is checked before the size memo, because the old transcript stops growing after /clear. Since state.json names the latest transcript, two /clears end up on the last one as well.

The Codex relabel is a separate problem (#24516, #24641). Once the row is Codex, this check is right to leave it alone, so I'd leave that to those.

@mtsr404
mtsr404 force-pushed the mtsr404/fix-continued-in-native-chat branch from d263cf1 to 2633fff Compare October 17, 2026 07:01
mtsr404 and others added 4 commits October 20, 2026 19:31
…tablyai#24117)

When Claude Code forks a pane's session into a daemon job (`/background`, or
an interrupt followed by a new prompt), the job keeps running in the same pane
but its hooks are declined since stablyai#15304. The pane's row kept the old
providerSession, so mobile native chat showed the old transcript while Stop
still interrupted the live job.

The old transcript records `continued-in` with the new session id. On each
presence recheck the execution host's hook server (and the relay for SSH)
reads the tail of the row's transcript, verifies the fork beside it carries
the new id, and rewrites only the row's providerSession as a replay, keeping
state and evidence age. A fork another pane already reports is left alone.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`/clear` inside a job starts a new transcript without writing
`continued-in`, so the chain stopped at the job's first transcript. The
job's state.json keeps its first sessionId and names the current one in
resumeSessionId and linkScanPath; follow that when the new transcript sits
beside the old one and carries the new id. It is checked before the size
memo because the old transcript stops growing after `/clear`.

Reported by Sangkwun on stablyai#26569.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@mtsr404
mtsr404 force-pushed the mtsr404/fix-continued-in-native-chat branch from 2633fff to 5d3dcc7 Compare October 20, 2026 10:38
nwparker added a commit that referenced this pull request Oct 25, 2026
…(adopts #26569) (#33605)

Panes follow a Claude Code conversation that moves into a background job (agent view ← then Enter, and /clear inside the job): on the presence recheck Orca reads the pane's own transcript `continued-in` record and the job's state.json (UUID-validated, sibling-folder only, overtaken pointers ignored, cwd kept) instead of trusting job hooks, so mobile and native chat stop freezing on the old session.

Refs #24117
Supersedes #26569

Co-authored-by: mtsr404 <[email protected]>
Co-authored-by: dimakrest <[email protected]>
@nwparker

Copy link
Copy Markdown
Contributor

Thanks @mtsr404 — this landed in #33605 (merged, with your commits and co-author credit), rebased onto current main plus fixes for repeated /clear, cwd preservation, overtaken pointers and UUID validation. Thanks also for the precise ←/Enter repro.

@nwparker nwparker closed this Oct 25, 2026
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.

[Bug]: Claude session reopened in its pane after /background loses its Orca status and mobile chat

3 participants