Skip to content

fix(agent-status): keep a Claude pane spinning across a mid-turn Orca restart - #16538

Open
nwparker wants to merge 6 commits into
stablyai:mainfrom
nwparker:nwparker/restart-keep-agent-status
Open

nwparker wants to merge 6 commits into
stablyai:mainfrom
nwparker:nwparker/restart-keep-agent-status

Conversation

@nwparker

@nwparker nwparker commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

After an Orca update, a Claude process could keep running in its preserved terminal while every Orca status surface looked idle until Claude emitted another hook. Orca now confirms that restored status only when the same local pane still runs Claude and Claude's own transcript shows a recent open turn.

What Changed

  • Reuse the existing Claude transcript lifecycle decoder and foreground-process resolver to confirm hydrated working rows.
  • Run confirmation after daemon readiness and the existing restored-subagent reap, using the same pane/workspace ownership resolver.
  • Re-state confirmed rows through the normal status path while preserving the turn start, suppressing duplicate rename/plugin activity, and avoiding a wake-lock claim.
  • Fail closed for ended, interrupted, missing, stale, future-dated, remote/SSH, rebound, or unreadable evidence; WSL remains eligible only when workspace ownership is local.

Why

The failure source was persisted non-terminal status hydrating as restoredUnconfirmed; production renderers intentionally hide that row, and only a later hook could clear it. The reliability invariant is: a restored Claude row is visible as working only when current process identity and provider-authored turn lifecycle independently agree, under the current pane and execution-host authority.

The deterministic oracle covers restart hydration, current/persisted PTY identity, daemon foreground confirmation, transcript completion/interruption/age, local/WSL/SSH/folder ownership, retirement, replay side effects, and error isolation. No new wire field or opcode is introduced; mixed-version clients receive an ordinary existing status update.

Linked Issue

Fixes STA-5647

Visual Proof

Before: the Linear report shows Claude visibly running after an update while its worktree, tab, and agent row have no working state; deterministic baseline coverage reproduces the row as working + restoredUnconfirmed, which production summary logic hides.

After: a CDP-only Electron restart-shaped validation preserved the daemon PTY, restored a recent open Claude turn, and rendered Working simultaneously on the worktree, agent row, and terminal tab on the first mounted frame.

STA-5647 post-restart Claude working status

Backing proof from the same frame: intended branch identity nwparker/restart-keep-agent-status; foreground claude; main snapshot state=working with no restoredUnconfirmed; renderer snapshot state=working; observation origin process; original stateStartedAt preserved.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated

Commands and results:

  • pnpm tc — passed under Node 24.18.0.
  • pnpm run check:code-quality:changed — passed with zero new regular, type-aware, or React Doctor findings.
  • 13-file agent-hook, hydration, workspace-host, WSL transcript-path, daemon-router, foreground-identity, and startup-ordering matrix — 210/210 passed.
  • Final focused confirmation/hydration/ownership matrix — 85/85 passed.
  • Mutation proof: removing the nonnegative boundary-age fence made the future-boundary regression fail; restoring it returned green.
  • Electron/CDP: local macOS dev profile, real preserved daemon PTY, visible post-restart working state, and backing process/status snapshots passed.

Platform/provider coverage: deterministic contracts cover macOS/Linux/Windows-neutral orchestration, local worktrees, local folder workspaces, WSL relay provenance, SSH/remote fail-closed ownership, daemon incarnation routing, and current-versus-persisted PTY rebinds. Live Electron proof is macOS/local; live WSL, Windows, Linux, SSH, and paired-runtime UI journeys remain unrun.

Performance budget: the startup pass is one-shot after daemon readiness, filters irrelevant rows before provider/filesystem work, memoizes foreground scans per PTY, uses the existing two-slot transcript filesystem gate, and carries a 30-second pass deadline. A 4,097-row irrelevant snapshot performs zero foreground scans, path translations, transcript reads, or confirmations.

AI Disclosure

Review

Reviewed until clean for root cause, status/title ownership, daemon generation, PTY rebind races, update lifecycle, wake locks, plugin replay, remote/SSH/folder/WSL ownership, mixed-version behavior, bounded work, and Windows/Linux compatibility. The review found and fixed one fail-open edge: a future-dated transcript boundary previously had negative age and passed the maximum-age check.

Agent skill upstream boundary

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

Notes

Accepted residual gaps, each corrected by Claude's next real hook:

  • Foreground identity proves a Claude process owns the pane, not cryptographic equality with the persisted session; the 12-hour transcript bound limits abandoned-session reuse.
  • A permission prompt created while Orca was down can resemble an open tool turn and return as working.
  • A turn with no explicit boundary in the bounded tail stays unconfirmed rather than inventing evidence.
  • An offline-completed turn remains unconfirmed instead of being fabricated as done; completion notifications and unread badges are intentionally out of scope.

Diagnostics are startup warnings for reconciliation failures plus the existing hook/daemon logs; no timer, polling loop, dependency, or remote-wire change was added.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after behavior is documented and post-fix visual proof is attached
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path impact considered
  • pnpm tc, focused tests, changed-code quality, and a dev build pass; CI covers the full matrix

@coderabbitai

coderabbitai Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds transcript parsing that classifies the latest Claude turn. Adds validation for restored Claude panes through PTY, process, host, and transcript checks. Adds server state confirmation and startup reconciliation. Adds tests for parsing, confirmation, persistence, liveness, filtering, failure isolation, and repeat prevention.

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 11 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ⚠️ Warning The title accurately describes the files changed, but it conflicts with the stated PR objective. The objective describes terminal response echo cleanup for OSC 11 and DSR 997 responses, not restored C… Align the title with the stated objective, or update the PR objective if restored Claude status after restart is the intended change.
Description check ⚠️ Warning The description contains the required sections and detailed testing information, but it documents restored Claude working-state confirmation rather than the stated objective of fixing terminal respons… Update the description to explain cooked/readline prompt matching, OSC 11 and DSR 997 cleanup, preserved safety behavior, and the related 35 tests, or correct the PR objective to match the implemented change.
✅ Passed checks (2 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.
Full details: Title check

Explanation

The title accurately describes the files changed, but it conflicts with the stated PR objective. The objective describes terminal response echo cleanup for OSC 11 and DSR 997 responses, not restored Claude turn confirmation.

Full details: Description check

Explanation

The description contains the required sections and detailed testing information, but it documents restored Claude working-state confirmation rather than the stated objective of fixing terminal response echoes. It is therefore off-topic relative to the declared PR objective.


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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 814123f1-2cf9-4722-8906-d8af9cd65982

📥 Commits

Reviewing files that changed from the base of the PR and between a1ec047 and 45d83323dd5e1790feffdc296c047784d181e293.

📒 Files selected for processing (8)
  • src/main/agent-hooks/claude-transcript-tail-read.ts
  • src/main/agent-hooks/restored-claude-turn-confirmation.test.ts
  • src/main/agent-hooks/restored-claude-turn-confirmation.ts
  • src/main/agent-hooks/server-restored-turn-confirmation.test.ts
  • src/main/agent-hooks/server.ts
  • src/main/index.ts
  • src/shared/claude-transcript-turn-openness.test.ts
  • src/shared/claude-transcript-turn-openness.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@nwparker
nwparker force-pushed the nwparker/restart-keep-agent-status branch 5 times, most recently from 4783531 to 237bf82 Compare August 26, 2026 05:20

@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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a472ceac-9975-42fe-8144-4e2c1d2a4e20

📥 Commits

Reviewing files that changed from the base of the PR and between 47835315c7a80f0b64dd56db8e37f5603ef51760 and 237bf82b41f02a9dfd5ca8232d6ce8abe8b8ac28.

📒 Files selected for processing (8)
  • src/main/agent-hooks/restored-claude-turn-confirmation.test.ts
  • src/main/agent-hooks/restored-claude-turn-confirmation.ts
  • src/main/agent-hooks/server.ts
  • src/main/index.ts
  • src/main/native-chat/transcript-turn-markers.ts
  • src/shared/claude-transcript-turn-markers.ts
  • src/shared/claude-transcript-turn-openness.test.ts
  • src/shared/claude-transcript-turn-openness.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.

@nwparker
nwparker force-pushed the nwparker/restart-keep-agent-status branch 12 times, most recently from 7b03b56 to 96cf203 Compare August 26, 2026 09:33
… restart

A pane that was working when Orca quit comes back idle: hydrate stamps every
non-terminal row `restoredUnconfirmed`, and the flag only clears on the agent's
next hook event — so a pane inside a long tool call renders as not-running for
the whole call.

Chat already answers "is this turn still open" from the transcript, settling its
spinner off provider-authored lifecycle records. Reuse that reader and decoder
rather than inventing a second opinion about what a Claude transcript means: it
handles interrupt markers, `stop_reason` terminals, tool-result continuations
and harness noise rows, over a tail reader that is WSL-gated, byte-capped and
safe against a file that shrinks mid-walk.

Confirmation demands two independent positive proofs: Claude is the pane's
foreground process on this machine, and the transcript's newest boundary opened
a generation that never ended. An agent killed mid-tool leaves the same
open-looking transcript while its shell keeps the PTY alive, so neither counts
alone. Absence of a boundary is not evidence either — a quiet pane emits no hook
to correct a wrong guess — and an open boundary older than twelve hours is
refused, because an abandoned mid-turn transcript stays open forever while a
real one is minutes to hours old. Confirmation passes the same disposition gate
every other status ingress uses, so a retired pane is never revived, and it
withdraws the runtime-observation claim the accept path stamps: a transcript
may restore what the pane looks like without holding the machine awake for it.

Remote/SSH panes are skipped — their agent and transcript live on the execution
host, where absence is a read failure, never a verdict — while WSL relay ids
count as local, per wsl-hook-relay-contract.
@brennanb2025

brennanb2025 commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Final review verification (Brennan), refreshed on exact live head 51f8cb5a84e919324c1a551da35500317af43845. The review-until-clean loop fixed one proven medium lifecycle race: restored-Claude confirmation now rejects a pane that detaches after binding evidence is gathered, including the initially-unbound attach-then-detach path, instead of publishing stale process/transcript evidence. Independent correctness/lifecycle and environment/contract/performance passes found no remaining in-scope issues; both CodeRabbit threads remain resolved and outdated (2/2, zero unresolved).

Node 24 verification passed 5 focused files / 67 tests, pnpm tc, pnpm run check:code-quality:changed with 0 findings, git diff --check, and branch-head src/shared/runtime-client-export-parity.test.ts. Exact-head PR Checks run https://github.com/stablyai/orca/actions/runs/33067066862 finished 44 success, 3 failure, and 1 skipped across the PR rollup. Merge ref f6d70bdf39d86d4d97d8a08d806b104cb37ae8b5 has parents current main 026389a3bc03da03ca2d65295e805493712b0774 and this head; the only red test jobs are Node 24/26 shard 10, where current-main exports TERMINAL_PTY_DEGRADATION_CAPABILITY, TERMINAL_UNAVAILABLE_ERROR_CODE, and terminalUnavailableMessage but its exact-export inventory still expects five values. Dependent verify fails only because those shards failed. Branch-head parity passes, so adding the unrelated current-main exports here would broaden scope and break this branch-head contract.

Fresh exact-head Electron evidence used Playwright CDP only. A real Claude turn was visibly Working, window.api.app.restart() terminated Electron PID 31633, and replacement PID 43263 relaunched the same exact-worktree command while a renderer-only dev server held the exact-worktree renderer across the restart. The replacement visibly rendered Working on the worktree, Claude row, and terminal tab; backing state was working, foreground agent claude, the real provider transcript was present, observation.origin was process with a startup snapshot boundary, and restoredUnconfirmed was absent. Merge verdict: not ready only because the unrelated merge-ref CI failure remains; no in-scope review or changed-flow QA blocker remains, and this task did not merge the PR.

@brennanb2025

brennanb2025 commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

QA/evidence (Brennan), refreshed on exact SHA 51f8cb5a84e919324c1a551da35500317af43845. Playwright CDP attached to an exact-worktree Electron instance with identity sta-5647-pr16538-final-qa-r1 @ 51f8cb5a84. From the rendered terminal I started a real Claude turn, verified visible pre-restart Working, and invoked the real window.api.app.restart() API; old Electron PID 31633 exited and replacement PID 43263 launched with the same exact-worktree command. A renderer-only server from this exact worktree held the dev renderer across the restart, avoiding electron-vite's normal coupled-server exit without substituting a mocked app process.

The replacement process visibly rendered Working on the worktree row, Claude agent row, and terminal tab while the real Claude turn continued. Backing state reported state: working, foreground agent claude, the real provider transcript path, and observation.origin: process with a startup snapshot boundary; restoredUnconfirmed was absent. This directly exercised the changed restart-confirmation path rather than relying on optimistic renderer state.

Exact-head post-restart Claude Working state

Focused Node 24 regression coverage passed 67/67, typecheck and changed-code quality passed, and branch-head export parity passed. Exact-head CI is 44 success / 3 failure / 1 skipped: only Node 24/26 shard 10 plus dependent verify are red, from the current-main merge-ref export-parity mismatch described in the review comment. Mobile QA is not applicable because no mobile files changed; SSH, folder-workspace, WSL, remote-wire, cross-platform, performance, and lifecycle boundaries were reviewed. The screenshot is the full uncropped real app viewport, and no computer-use, accessibility, or OS-level interaction was used. QA verdict: the exact-head post-restart rendered and backing-state evidence passes; the PR remains unmerged and blocked only by unrelated merge-ref CI.

This branch has not been deployed

No deployments
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