Repository navigation
fix(runtime): a restored agent stays unconfirmed past 30 minutes instead of turning done - #30186
Conversation
…ydration window, not 30 minutes
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
6f64b295-2b50-46a5-b65f-c50848ba8610
📒 Files selected for processing: 5
src/main/agent-hooks/server/server-constants.tssrc/main/runtime/orca-runtime-hook-agent-status-projection.test.tssrc/main/runtime/runtime-mobile-agent-status-projection.tssrc/shared/agent-status-freshness.tssrc/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.
| (entry.evidenceObservedAt ?? entry.receivedAt) >= restoredAfter && | ||
| (!restored || entry.receivedAt > restored.receivedAt) | ||
| ) { | ||
| restored = entry | ||
| } | ||
| } |
There was a problem hiding this comment.
🎯 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 -100Repository: 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-hooksRepository: 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.
| (entry.evidenceObservedAt ?? entry.receivedAt) >= restoredAfter && | |
| (!restored || entry.receivedAt > restored.receivedAt) | |
| ) { | |
| restored = entry | |
| } | |
| } | |
| entry.receivedAt >= restoredAfter && | |
| (!restored || entry.receivedAt > restored.receivedAt) | |
| ) { | |
| restored = entry | |
| } | |
| } |
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 thesession.tabsprojection picks that row only if it is under 30 minutes old. So it fell through to the last-resort projection, which publishesdonefor 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:
selectRuntimeHookAgentRowForPanenow 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 inshared/agent-status-freshness.ts, and the hook server'sHYDRATE_MAX_AGE_MSreads it, so the two windows cannot drift apart.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
restoredUnconfirmedrows as identity only, with no age limit. This makes the host's projection agree with the store that owns the row.Alternatives considered:
donefrom 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.v1capability still get the legacydoneprojection, 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
src/main/runtime/orca-runtime-hook-agent-status-projection.test.ts, both using a fakeDate(no wall-clock dependence):working+restoredUnconfirmed. This failed on main, which publisheddone.donethat is itself over 30 minutes old still supersedes an older restored turn. This fails without the supersede change.done.src/main/agent-hooks/server,src/shared/agent-status*,src/main/runtime/runtime-mobile*,session-tab-agent-status-projection,runtime-agent-row-main-agent-projectionandorchestration/terminal-authority. 1,409 tests passed.pnpm tc, because the local bun is too old for the CI--compiler=bunpath.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.
Review
Agent skill upstream boundary
Notes
mobile/change.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)