Skip to content

fix(agent-status): restore hydrated nonterminal statuses as unconfirmed - #12346

Merged
brennanb2025 merged 5 commits into
mainfrom
brennanb2025/agent-status-hydrate-unconfirmed
Aug 4, 2026
Merged

brennanb2025 merged 5 commits into
mainfrom
brennanb2025/agent-status-hydrate-unconfirmed

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Summary

A hook transition that fires while Electron is down has no receiver and is discarded permanently (hook POSTs are fail-open with no retry). On the next launch last-status.json restores the last observation verbatim, so a working → done that happened during the restart window renders as confirmed working for up to the 7-day hydrate TTL — and the three status surfaces disagree about it (desktop sidebar decays at 30 min display-only, worktree.ps omits under narrow conditions, the raw snapshot serves working verbatim).

This PR makes restoration honest: a nonterminal (working/blocked/waiting) row hydrated from disk is stamped restoredUnconfirmed and treated as never fresh by the two freshness chokepoints (isFreshNonDoneAgentStatus shared, isExplicitAgentStatusFresh renderer), so every consumer — sidebar rows, worktree card activity, smart attention, tab activity, notifications, interrupt/question inference, worktree.ps activity merge — presents the same degraded semantics immediately instead of a confirmed working.

Semantics:

  • Terminal states (done, including interrupted) restore as-is — no later transition can have been missed.
  • Any accepted live hook event replaces the entry and clears the flag (the pane re-earns confirmed status).
  • The flag is never persisted — hydrate re-stamps it, so a stored copy could only drift.
  • Interrupt/question inference refuses to synthesize transitions onto unconfirmed rows (fabricating done from stale disk state).
  • Orchestration authority hydration ('hydrated_commitment') is deliberately untouched — it is a separate consumer of launch-token state with opposite trust polarity.

Screenshots

No new UI surfaces. The only visible change is that a restored-unconfirmed row renders through the existing stale-decay presentation (idle row state, same as the 30-minute decay path) immediately after restart instead of showing a confirmed working spinner for up to 30 minutes.

Testing

  • pnpm lint (oxlint + code-quality native + type-aware audits)
  • pnpm typecheck (also typecheck:tsc with --composite false)
  • pnpm test — 44,294 passed; 9 failures in 5 files (updater timing, daemon cwd-repair, relay exec, macOS helper benchmark, root-directory guard) reproduce byte-identically on the base commit 34291f07e9 in the same environment, so they are pre-existing local-environment failures, not regressions; none are in this change's surface
  • pnpm build (build:desktop; build:native untouched by this diff)
  • Added or updated high-quality tests that would catch regressions

New tests: server round-trip (ingest → persist → rehydrate) asserting nonterminal rows carry the flag, done rows don't, a live event clears it, the flag never reaches disk and re-stamps on every hydrate, and interrupt inference refuses an unconfirmed row with an exactly matching baseline (the guard is load-bearing — without it the inference applies). Shared-helper unit tests for never-fresh semantics. Sidebar test: a seconds-old unconfirmed working row decays to idle while an identical confirmed row stays working.

AI Review Report

Reviewed the full diff plus every consumer of the two freshness helpers (~15 call sites) and both IPC delivery paths.

  • Injection surfaces verified closed: the local HTTP hook path builds events through normalizeHookPayload's field whitelist and ingestRemote re-validates through an explicit field list — neither can smuggle restoredUnconfirmed in from outside; only hydrateLastStatusFromDisk stamps it. An injected flag would in any case make a row less trusted (fail-safe direction).
  • Both renderer delivery paths carry the flag: the getStatusSnapshot pull (via toAgentStatusIpcPayload and the spread-through enrichAgentStatusIpcPayload) and the agentStatus:set push replay on window recreate (explicit destructure in main/index.ts). The renderer's pending-retry queue stores the whole IPC payload, so retries preserve provenance.
  • Live replacement clears correctly: applyNormalizedStatus → attachStatusTiming constructs a fresh entry from the incoming payload only (no previous-entry spread), so the flag cannot survive an accepted live event.
  • Cross-platform: no paths, shortcuts, labels, or shell behavior touched. macOS/Linux/Windows identical. SSH-relayed and WSL-relayed hydrated rows get the same unconfirmed treatment as local; folder workspaces unaffected (identity stays paneKey-based, no worktree assumptions).
  • Flagged and fixed during review: the renderer payload rebuild in useIpcEvents is a field whitelist, so the flag had to be threaded explicitly (comment added at the site referencing the whitelist trap).

Security Audit

  • Additive optional boolean on existing IPC channels; no new IPC handlers, no new listeners, no new file I/O.
  • Trust boundaries unchanged: token auth, body caps, and normalization at the hook receiver are untouched. The flag is main-process-stamped only (verified both ingestion whitelists).
  • last-status.json schema unchanged — the flag is stripped in serializeStatusFile alongside the existing launch-token/bearer scrubbing, so no new data is written to disk.
  • Inference guards reduce attack surface: a matching-baseline interrupt inference can no longer convert stale disk state into a fabricated done.
  • No prompts, tokens, or workspace paths added to any log line.

Notes

  • This is Phase 0 of the daemon-owned agent-hook-status direction: it makes restart restoration honest for all sessions (including pre-existing ones) but cannot confirm a done that fired while Electron was down — only a receiver that outlives Electron can (follow-up work).
  • RuntimeWorktreeAgentRow now carries restoredUnconfirmed on the wire, and the worktree.ps activity/status merge already excludes unconfirmed rows; the mobile client still renders the row's raw state chip until it adopts the flag (small mobile follow-up, kept out of this PR's scope).
  • The OSC-title-derived status retention in the runtime is a separate path and is not part of this change.

A hook transition that fires while Electron is down has no receiver and is
discarded, so last-status.json can restore a stale 'working' as confirmed
truth for up to the 7-day hydrate TTL. Stamp hydrated nonterminal rows with
restoredUnconfirmed, carry it through both IPC paths, and treat such rows as
never-fresh in the shared and renderer freshness gates so the sidebar,
worktree.ps, and the raw snapshot all present the same degraded semantics.
Terminal states restore as-is; any accepted live event clears the flag; the
flag itself is never persisted. Interrupt/question inference refuses to
fabricate transitions onto unconfirmed rows.
@coderabbitai

coderabbitai Bot commented Aug 3, 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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e73c0178-d938-49e0-8593-5dc97170e7ca

📥 Commits

Reviewing files that changed from the base of the PR and between 4bc9de0 and acc464e.

📒 Files selected for processing (2)
  • src/renderer/src/components/sidebar/smart-attention.test.ts
  • src/renderer/src/components/sidebar/smart-attention.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/renderer/src/components/sidebar/smart-attention.test.ts
  • src/renderer/src/components/sidebar/smart-attention.ts

📝 Walkthrough

Walkthrough

The change adds restoredUnconfirmed tracking for nonterminal agent statuses restored from persistence. Hydration applies the marker, while serialization omits it. Live events and verified terminal reconciliation clear the marker. IPC, runtime rows, and renderer storage preserve it. Freshness checks and inference reject unconfirmed restored statuses. Tests cover hydration, persistence, reconciliation, inference, freshness, and sidebar rendering.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes restoring hydrated nonterminal agent statuses as unconfirmed.
Description check ✅ Passed The description covers the required summary, screenshots, testing, AI review, security audit, and notes sections with relevant details.
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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: 75493295-c54d-4889-98f5-c624cc17eae7

📥 Commits

Reviewing files that changed from the base of the PR and between e25381c and 7527921.

📒 Files selected for processing (11)
  • src/main/agent-hooks/server.test.ts
  • src/main/agent-hooks/server.ts
  • src/main/index.ts
  • src/main/runtime/orca-runtime.ts
  • src/renderer/src/components/sidebar/useWorktreeAgentRows.test.ts
  • src/renderer/src/hooks/useIpcEvents.ts
  • src/renderer/src/lib/pane-agent-evidence.ts
  • src/renderer/src/store/slices/agent-status.ts
  • src/shared/agent-status-types.test.ts
  • src/shared/agent-status-types.ts
  • src/shared/runtime-types.ts

Comment thread src/main/agent-hooks/server.ts Resolved
…rifies done

The restored-subagent reaper's reconciled entry spread carried
restoredUnconfirmed onto a process-probe-verified 'done', making freshness
gates suppress a legitimate completion. Keep the marker only while the
reconciled state stays nonterminal.
Sort accepted live evidence after hydrated rows even across wall-clock rollback. Let unconfirmed rows own their preserved pane titles without asserting live state, while retaining independently live sibling evidence.
Treat a single runtime title as covered by the single restored hook row while layout identity is unavailable. Preserve ordinary age-stale fallback and mapped sibling-pane evidence.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Electron QA

Validated the visible restart-degradation behavior in the real Orca desktop surface on acc464e7a7 using the razorbill @ review/pr-12346-clean-pass dev instance.

Confirmed live row: the recent working entry renders as Working in the worktree card and terminal tab.

Confirmed live working row

Restored-unconfirmed row: an otherwise equally recent working entry with hydrated-unconfirmed provenance renders through the existing Idle presentation; the worktree and terminal tab no longer claim active work.

Restored-unconfirmed row rendered idle

Backing evidence: CDP identity matched this worktree/branch; the renderer store preserved restoredUnconfirmed: true; the visible accessibility snapshot reported Idle; there were zero console errors. Screenshots are uncropped full-window captures.

@brennanb2025
brennanb2025 merged commit 9ec4907 into main Aug 4, 2026
42 checks passed
nwparker added a commit that referenced this pull request Aug 4, 2026
#12346 landed on main after this branch was cut: a nonterminal row restored from
last-status.json is stamped `restoredUnconfirmed` because its transition may have
fired while no receiver was up, and every freshness gate treats it as never-fresh.
The new headless `live` projection here only checked `receivedAt`, so a restart
inside the 30-minute window would republish the hydrated row — resurrecting the
AskUserQuestion card with no agent left to answer it.

`agentType` still reads those rows: they prove identity, just not liveness.

Co-authored-by: Orca <help@stably.ai>
nwparker added a commit that referenced this pull request Aug 4, 2026
…s on a paired headless server (#12223)

* fix(native-chat): show Claude's AskUserQuestion card when the agent runs on a paired headless host

Three gaps kept the question card off the desktop when the agent ran on a
remote `orca serve` host:

- The `session.tabs` projection reduced HTTP agent-hook rows to identity only,
  hard-coding `state: 'done'` and an empty prompt, so `toolName` and the full
  `interactivePrompt` never left the host. It now publishes the newest fresh
  hook row's status fields, bounded by the same staleness window `agentType`
  uses, excluding `providerSessionOnly` resume rows, and yielding to live
  title evidence unless a question is actually pending.
- Nothing republished `session.tabs` when only a hook row changed, and the
  re-emit carried an unchanged `snapshotVersion` that clients drop on their
  monotonic gate. Material hook transitions and pane/SSH status clears now
  bump the version and schedule a coalesced emit.
- The desktop card resolved only from live status. It now falls back to the
  pending ask in the transcript, matching mobile, so a relay gap can no longer
  leave the composer mounted over a pane parked on a selector.

Closes #11761

Co-authored-by: Orca <help@stably.ai>

* fix(native-chat): date the hook-row recency guard against a real clock

`resolveHookLiveAgentRow` compared a hook `receivedAt` (epoch ms) against
title stamps that are title-observation sequence numbers, so the guard could
never fire — any fresh hook row overrode live title-derived state, and a manual
rename (the one epoch writer) inverted it. Stamp the live OSC title path with
wall-clock ms and compare against that alone.

The regression test fabricated epoch-valued title stamps production never
writes; it now drives the title through `onPtyData`, and a new case pins the
opposite direction (hook row newer than the title wins).

Co-authored-by: Orca <help@stably.ai>

* fix(native-chat): stop an orphaned tool call from pinning a dead question card

extractPendingAsk pairs tool results to calls by a global FIFO (tool_use_id
is dropped at decode time), so one call that never gets a result desyncs the
queue for the rest of the transcript and strands an answered ask as pending.
Real transcripts also hold asks the user escaped and typed past. On desktop
that card replaces the composer, so the pane became unsendable.

Drop in-flight calls at a turn boundary — a user turn or the decoders'
interrupt row — since the turn that owned them is over. Claude's tool-result
turns decode as role 'tool', so normal FIFO resolution is untouched.

Co-authored-by: Orca <help@stably.ai>

* refactor(native-chat): trim the headless AskUserQuestion projection

Reuse rather than restate: the invalidator now takes the shared
`AgentHookEventPayload` instead of a locally redeclared row shape, and the
hook live row is a `Pick<>` of the retained OSC snapshot so one projection
branch consumes either carrier. Fold the immediate/coalesced session-tabs
emit into one method (also drops a redundant re-emit on the
provider-session push). Drop card tests that re-route shared-parser
assertions through React. Isolate pane-status-clear subscribers and prove
the no-republish case by version arithmetic instead of a timed silence.

Co-authored-by: Orca <help@stably.ai>

* test(native-chat): pin the AskUserQuestion card render under real Electron

Why: the 13 parser unit tests pin extraction, but nothing proved a card
actually renders where an inert tool call used to. This spec reproduces the
paired-headless topology from the client side — live status carrying agent
identity and state 'working' but no interactivePrompt/toolName, with the
pending ask present only in the transcript — and fails on main.

Refs #11761

Co-authored-by: Orca <help@stably.ai>

* test(native-chat): drop the unused testInfo parameter

Why: oxlint no-unused-vars fails the lint gate on an unused test parameter.

Co-authored-by: Orca <help@stably.ai>

* test(native-chat): drop leftover proof scaffolding from the ask-card spec

The env-var screenshot label and the fixed 2s settle only existed to make
the pre-fix capture comparable; the card assertion already waits.

Co-authored-by: Orca <help@stably.ai>

* test(runtime): use a truly unresolvable pane key in the hook republish guard

#11203 taught pane lookup to recover a reminted tab id by leaf id, so the old
fixture (new tab id, live leaf id) resolved and bumped the snapshot a second
time once this branch merged with main.

Co-authored-by: Orca <help@stably.ai>

* fix(runtime): refuse a hydrated unconfirmed hook row as live pane status

#12346 landed on main after this branch was cut: a nonterminal row restored from
last-status.json is stamped `restoredUnconfirmed` because its transition may have
fired while no receiver was up, and every freshness gate treats it as never-fresh.
The new headless `live` projection here only checked `receivedAt`, so a restart
inside the 30-minute window would republish the hydrated row — resurrecting the
AskUserQuestion card with no agent left to answer it.

`agentType` still reads those rows: they prove identity, just not liveness.

Co-authored-by: Orca <help@stably.ai>

---------

Co-authored-by: Orca <help@stably.ai>
Co-authored-by: Neil <nwparker@users.noreply.github.com>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ed (stablyai#12346)

* fix(agent-status): restore hydrated nonterminal statuses as unconfirmed

A hook transition that fires while Electron is down has no receiver and is
discarded, so last-status.json can restore a stale 'working' as confirmed
truth for up to the 7-day hydrate TTL. Stamp hydrated nonterminal rows with
restoredUnconfirmed, carry it through both IPC paths, and treat such rows as
never-fresh in the shared and renderer freshness gates so the sidebar,
worktree.ps, and the raw snapshot all present the same degraded semantics.
Terminal states restore as-is; any accepted live event clears the flag; the
flag itself is never persisted. Interrupt/question inference refuses to
fabricate transitions onto unconfirmed rows.

* fix(agent-status): shed unconfirmed marker when the liveness sweep verifies done

The restored-subagent reaper's reconciled entry spread carried
restoredUnconfirmed onto a process-probe-verified 'done', making freshness
gates suppress a legitimate completion. Keep the marker only while the
reconciled state stays nonterminal.

* fix(agent-status): let live evidence replace hydrated rows

* fix(agent-status): keep restored rows degraded

Sort accepted live evidence after hydrated rows even across wall-clock rollback. Let unconfirmed rows own their preserved pane titles without asserting live state, while retaining independently live sibling evidence.

* fix(agent-status): suppress unmapped restored titles

Treat a single runtime title as covered by the single restored hook row while layout identity is unavailable. Preserve ordinary age-stale fallback and mapped sibling-pane evidence.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…s on a paired headless server (stablyai#12223)

* fix(native-chat): show Claude's AskUserQuestion card when the agent runs on a paired headless host

Three gaps kept the question card off the desktop when the agent ran on a
remote `orca serve` host:

- The `session.tabs` projection reduced HTTP agent-hook rows to identity only,
  hard-coding `state: 'done'` and an empty prompt, so `toolName` and the full
  `interactivePrompt` never left the host. It now publishes the newest fresh
  hook row's status fields, bounded by the same staleness window `agentType`
  uses, excluding `providerSessionOnly` resume rows, and yielding to live
  title evidence unless a question is actually pending.
- Nothing republished `session.tabs` when only a hook row changed, and the
  re-emit carried an unchanged `snapshotVersion` that clients drop on their
  monotonic gate. Material hook transitions and pane/SSH status clears now
  bump the version and schedule a coalesced emit.
- The desktop card resolved only from live status. It now falls back to the
  pending ask in the transcript, matching mobile, so a relay gap can no longer
  leave the composer mounted over a pane parked on a selector.

Closes stablyai#11761

Co-authored-by: Orca <help@stably.ai>

* fix(native-chat): date the hook-row recency guard against a real clock

`resolveHookLiveAgentRow` compared a hook `receivedAt` (epoch ms) against
title stamps that are title-observation sequence numbers, so the guard could
never fire — any fresh hook row overrode live title-derived state, and a manual
rename (the one epoch writer) inverted it. Stamp the live OSC title path with
wall-clock ms and compare against that alone.

The regression test fabricated epoch-valued title stamps production never
writes; it now drives the title through `onPtyData`, and a new case pins the
opposite direction (hook row newer than the title wins).

Co-authored-by: Orca <help@stably.ai>

* fix(native-chat): stop an orphaned tool call from pinning a dead question card

extractPendingAsk pairs tool results to calls by a global FIFO (tool_use_id
is dropped at decode time), so one call that never gets a result desyncs the
queue for the rest of the transcript and strands an answered ask as pending.
Real transcripts also hold asks the user escaped and typed past. On desktop
that card replaces the composer, so the pane became unsendable.

Drop in-flight calls at a turn boundary — a user turn or the decoders'
interrupt row — since the turn that owned them is over. Claude's tool-result
turns decode as role 'tool', so normal FIFO resolution is untouched.

Co-authored-by: Orca <help@stably.ai>

* refactor(native-chat): trim the headless AskUserQuestion projection

Reuse rather than restate: the invalidator now takes the shared
`AgentHookEventPayload` instead of a locally redeclared row shape, and the
hook live row is a `Pick<>` of the retained OSC snapshot so one projection
branch consumes either carrier. Fold the immediate/coalesced session-tabs
emit into one method (also drops a redundant re-emit on the
provider-session push). Drop card tests that re-route shared-parser
assertions through React. Isolate pane-status-clear subscribers and prove
the no-republish case by version arithmetic instead of a timed silence.

Co-authored-by: Orca <help@stably.ai>

* test(native-chat): pin the AskUserQuestion card render under real Electron

Why: the 13 parser unit tests pin extraction, but nothing proved a card
actually renders where an inert tool call used to. This spec reproduces the
paired-headless topology from the client side — live status carrying agent
identity and state 'working' but no interactivePrompt/toolName, with the
pending ask present only in the transcript — and fails on main.

Refs stablyai#11761

Co-authored-by: Orca <help@stably.ai>

* test(native-chat): drop the unused testInfo parameter

Why: oxlint no-unused-vars fails the lint gate on an unused test parameter.

Co-authored-by: Orca <help@stably.ai>

* test(native-chat): drop leftover proof scaffolding from the ask-card spec

The env-var screenshot label and the fixed 2s settle only existed to make
the pre-fix capture comparable; the card assertion already waits.

Co-authored-by: Orca <help@stably.ai>

* test(runtime): use a truly unresolvable pane key in the hook republish guard

stablyai#11203 taught pane lookup to recover a reminted tab id by leaf id, so the old
fixture (new tab id, live leaf id) resolved and bumped the snapshot a second
time once this branch merged with main.

Co-authored-by: Orca <help@stably.ai>

* fix(runtime): refuse a hydrated unconfirmed hook row as live pane status

stablyai#12346 landed on main after this branch was cut: a nonterminal row restored from
last-status.json is stamped `restoredUnconfirmed` because its transition may have
fired while no receiver was up, and every freshness gate treats it as never-fresh.
The new headless `live` projection here only checked `receivedAt`, so a restart
inside the 30-minute window would republish the hydrated row — resurrecting the
AskUserQuestion card with no agent left to answer it.

`agentType` still reads those rows: they prove identity, just not liveness.

Co-authored-by: Orca <help@stably.ai>

---------

Co-authored-by: Orca <help@stably.ai>
Co-authored-by: Neil <nwparker@users.noreply.github.com>
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