Skip to content

fix(runtime): a restored agent stays unconfirmed past 30 minutes instead of turning done - #30186

Merged
nwparker merged 1 commit into
mainfrom
nwparker/mobile-restored-status-retention
Oct 18, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/mobile-restored-status-retention

Conversation

@nwparker

@nwparker nwparker commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​63 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​63
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​20 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​14

ELI5

If Orca's server on a host restarts while an agent is still running, the agent's last known status is restored as "unconfirmed". #29604 showed that unconfirmed status instead of a false "done". But it only did so for 30 minutes. If the agent's last report was older than that, every client saw it as finished, even though nothing showed it had exited.

What Changed

Before: an agent has been working without a hook event for 31 minutes, for example during a long build. The host's server restarts. The daemon keeps the agent running, and the hook server reloads its row as restoredUnconfirmed (it keeps those rows for 7 days). But the session.tabs projection picks that row only if it is under 30 minutes old. So it fell through to the last-resort projection, which publishes done for any pane that has a resume identity. Phones, web and paired desktops showed a green check for a running agent.

After: a restored unfinished row stays unconfirmed ("state unknown": no spinner, no done check) for as long as the hook server keeps it. Real evidence still ends it as before: a newer hook report, or a shell title painted after the turn.

Mechanism:

  • selectRuntimeHookAgentRowForPane now bounds restored rows by the hydration window (AGENT_STATUS_HYDRATE_MAX_AGE_MS, 7 days), not by the 30-minute live-freshness window. The constant now lives in shared/agent-status-freshness.ts, and the hook server's HYDRATE_MAX_AGE_MS reads it, so the two windows cannot drift apart.
  • A confirmed row at least as new as the restored one still supersedes it, even when that confirmed row is itself past the 30-minute window. Before, the check only looked at fresh confirmed rows. That was harmless while restored rows were themselves capped at 30 minutes. It isn't now: without this change, an old restored row could outlive a newer confirmed done.

Why

Losing contact with a turn is not evidence that it ended, so the verdict here is "unverifiable", not "exited". The 30-minute window measures whether a status is fresh enough to show as live. It was never a signal that the agent exited. The renderer already treats restoredUnconfirmed rows as identity only, with no age limit. This makes the host's projection agree with the store that owns the row.

Alternatives considered:

  • Drop the age bound entirely. A host that stays up for weeks would keep an in-memory restored row past the point where the next restart would discard it. Tying the bound to hydration keeps one retention rule.
  • Publish nothing after 30 minutes. This drops the provider-session identity that native chat and resume need, and old clients would still see done from the fallback.

The hook-server store remains the single owner of the row. This reader only chooses which of the store's rows to present. No wire change: older clients without the agent-status.restored-unconfirmed.v1 capability still get the legacy done projection, as before.

Linked Issue

No issue. Found in review of #29604.

Visual Proof

N/A: this changes host-side status projection only. The display of an unconfirmed row is unchanged from #29604.

Testing

  • New in src/main/runtime/orca-runtime-hook-agent-status-projection.test.ts, both using a fake Date (no wall-clock dependence):
    • A restored working turn 31 minutes old stays working + restoredUnconfirmed. This failed on main, which published done.
    • A newer confirmed done that is itself over 30 minutes old still supersedes an older restored turn. This fails without the supersede change.
  • fix(ssh): a managed server restart no longer marks still-running agents done #29604's tests still pass: a restored turn stays unverifiable with its own timestamps, and a later shell title retires it to done.
  • Ran single-worker: src/main/agent-hooks/server, src/shared/agent-status*, src/main/runtime/runtime-mobile*, session-tab-agent-status-projection, runtime-agent-row-main-agent-projection and orchestration/terminal-authority. 1,409 tests passed.
  • Full local replay of the pr.yml static-analysis job: import and spawn ratchets, lint, anti-slop, native and type-aware code quality, changed-code quality, React Doctor, the remaining ratchets, the generated catalogs, localization extraction, and the orcad terminal smoke (PASS). Typecheck ran via pnpm tc, because the local bun is too old for the CI --compiler=bun path.
  • Codex review (gpt-6.1-sol, high): no findings.

Verified live vs only in tests: verified in unit tests only. The live server-restart flow is the one #29604 verified end to end. This change only widens the age gate on that same path.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Review

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

  • Remote SSH: this is the case being fixed.
  • Mobile: gets the corrected publication. No mobile/ change.
  • Folder workspaces: unaffected. The projection works per pane.

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)

@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The change defines and exports a shared seven-day agent-status hydration age limit. The server hydration constant now uses this value. The runtime selector retains eligible restored rows based on hydration age rather than the live freshness window. A confirmed row with an equal or newer receivedAt supersedes a restored row. Tests cover stale restored rows and newer confirmed rows.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 632ee

A replayed unfinished agent can still appear done after a restart. Align the selector with hydration’s timestamp before merging, or accept this bounded edge case.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Description check Inconclusive The description is detailed and covers the user impact, mechanism, rationale, testing, visual proof, compatibility considerations, and checklist. However, it states "No issue" instead of providing the… Confirm that the author is an internal maintainer. If not, add a direct link to the issue addressed by this pull request.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary runtime behavior change: restored agents remain unconfirmed beyond the 30-minute freshness window instead of becoming done.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 5 files.
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: Description check

Explanation

The description is detailed and covers the user impact, mechanism, rationale, testing, visual proof, compatibility considerations, and checklist. However, it states "No issue" instead of providing the actual linked issue required by the template, unless the author is an internal maintainer covered by the template exception.

Resolution

Confirm that the author is an internal maintainer. If not, add a direct link to the issue addressed by this pull request.

✨ Finishing Touches
📝 Generate docstrings
  • 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.

@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: Advanced
  • Run ID: 6f64b295-2b50-46a5-b65f-c50848ba8610
📥 Commits

Reviewing files that changed from the base of the PR and between ed40719 and 632ee74.

📒 Files selected for processing: 5
  • src/main/agent-hooks/server/server-constants.ts
  • src/main/runtime/orca-runtime-hook-agent-status-projection.test.ts
  • src/main/runtime/runtime-mobile-agent-status-projection.ts
  • src/shared/agent-status-freshness.ts
  • src/shared/agent-status-types.ts

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

Comment on lines +170 to 175
(entry.evidenceObservedAt ?? entry.receivedAt) >= restoredAfter &&
(!restored || entry.receivedAt > restored.receivedAt)
) {
restored = entry
}
}

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '65,125p' src/main/agent-hooks/server/server-hydration.ts
sed -n '130,195p' src/main/runtime/runtime-mobile-agent-status-projection.ts
sed -n '140,180p' src/main/agent-hooks/server/server-status-application.ts
rg -n 'evidenceObservedAt|restoredUnconfirmed' src/main/runtime/orca-runtime-hook-agent-status-projection.test.ts src/main/agent-hooks/server/*test.ts | head -100

Repository: stablyai/orca

Length of output: 9131


🏁 Script executed:

nl -ba src/main/runtime/runtime-mobile-agent-status-projection.ts | sed -n '1,205p'
nl -ba src/main/agent-hooks/server/server-hydration.ts | sed -n '65,120p'
nl -ba src/main/runtime/runtime-mobile-agent-status-builder.ts | sed -n '90,175p'
nl -ba src/main/runtime/orca-runtime-hook-agent-status-projection.test.ts | sed -n '210,365p'
rg -n -F -- 'AGENT_STATUS_HYDRATE_MAX_AGE_MS' src/main/runtime src/main/agent-hooks

Repository: stablyai/orca

Length of output: 24675


🏁 Script executed:

nl -ba src/main/runtime/runtime-mobile-agent-status-builder.ts | sed -n '168,215p'

Repository: stablyai/orca

Length of output: 1577


Use receivedAt for the restored hydration window.

Hydration retains nonterminal rows by receivedAt, and replay can refresh receivedAt while preserving an older evidenceObservedAt. The restored selector applies the seven-day cutoff to evidenceObservedAt instead. A replayed unfinished row can therefore survive hydration but fall through to the builder’s done projection instead of remaining restoredUnconfirmed.

Suggested fix
--- "a/src/main/runtime/runtime-mobile-agent-status-projection.ts"
+++ "b/src/main/runtime/runtime-mobile-agent-status-projection.ts"
@@ -167,7 +167,7 @@
       entry.providerSessionOnly !== true &&
       entry.restoredUnconfirmed === true &&
       entry.state !== 'done' &&
-      (entry.evidenceObservedAt ?? entry.receivedAt) >= restoredAfter &&
+      entry.receivedAt >= restoredAfter &&
       (!restored || entry.receivedAt > restored.receivedAt)
     ) {
       restored = entry
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
(entry.evidenceObservedAt ?? entry.receivedAt) >= restoredAfter &&
(!restored || entry.receivedAt > restored.receivedAt)
) {
restored = entry
}
}
entry.receivedAt >= restoredAfter &&
(!restored || entry.receivedAt > restored.receivedAt)
) {
restored = entry
}
}

@nwparker
nwparker merged commit 904259d into main Oct 18, 2026
34 checks 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