Skip to content

Agent status C2: recover turns when completion goes missing - #21056

Closed
brennanb2025 wants to merge 11 commits into
mainfrom
brennanb2025/agent-status-c2-turn-recovery
Closed

brennanb2025 wants to merge 11 commits into
mainfrom
brennanb2025/agent-status-c2-turn-recovery

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

This draft builds the part of Orca that can recover when an agent finishes but its final completion signal never arrives. It ties each piece of provider evidence to a specific run and turn, keeps child tasks and long-running background work separate, and preserves an honest unknown outcome when the available evidence cannot prove success or failure.

It is not yet an end-to-end fix for the visible stuck spinner. The production launch, provider-query, execution-observation, and status-publication paths described below still need to connect this work before the UI can rely on it.

What changes

  • Converts provider start, end, interrupt, child-task, background-work, current-turn inventory, and terminal-record signals into one host-owned turn lifecycle.
  • Requires evidence to match the exact run and terminal attachment, so a delayed completion from an older run cannot finish a newer one.
  • Carries turn evidence through the direct-SSH relay path and records "interrupt input was written" separately from "the provider confirmed the interrupt."
  • Treats a confirmed agent-process exit as the end of that agent's presence without claiming its work succeeded.
  • Reorders covered PTY teardown paths so exit evidence is processed before status cleanup can erase the row needed for reconciliation.
  • Bounds recovery tracking and supports explicit abandonment instead of retrying forever.

User-facing before / after

Before After this draft
Lost final completion A pane can remain Working until another prompt, reconnect, or terminal close happens. The host can settle the exact turn from matching provider inventory or a matching terminal record. Production providers are not connected to those recovery queries yet.
Child and background work A milestone or child completion can be confused with the main turn, while a persistent monitor can keep the whole pane looking busy. Main turns, finite child tasks, and persistent background work have separate records in the lifecycle engine and tests.
Interrupts over SSH Writing Escape or Ctrl+C can be mistaken for proof that the agent stopped, or ignored because the relay cannot acknowledge the write. Input delivery, interrupt request, and provider acknowledgement are separate facts; ambiguous delivery does not fabricate completion.
Agent exits to a shell Cleanup can remove status before the lifecycle sees the exit, or treat exit as successful work. Covered teardown paths record the confirmed exit first, while the turn remains unresolved unless separate evidence establishes its outcome.
Visible UI The spinner may stay stale. No standalone UI change yet. The visible behavior depends on the follow-up integrations listed below.

Issues

Fully addressed by this PR

None. These reports remain open because this draft provides the shared handling and regression cases but does not yet connect every production evidence source and reader. No issue should be auto-closed from this PR.

Partially addressed; still open

The broader C2 roster also includes launch, freeze, crash, output-delivery, title-identity, and conversation-list symptoms. This PR does not claim those are turn-recovery bugs; each still needs its own reproduced cause and acceptance test.

Why this approach

The status should follow evidence about a particular turn, not the continued existence of a terminal or agent process. A live CLI can be idle after finishing, so process presence cannot keep Working true. A timeout can hide the symptom but may mark real long-running work finished, and waiting for the next prompt leaves the final turn stuck forever. Treating a later turn as proof that an older turn succeeded would also invent an outcome.

Instead, the execution host reduces attributable provider events and complete snapshots for the exact run and turn. Missing evidence stays unknown, and every recovery attempt ends through a verified result, a bounded expiry, or explicit abandonment. This matches the useful part of the inspected reference mechanisms—host-owned, turn-keyed events with explicit recovery—while deliberately retaining uncertainty where Orca's providers do not yet expose a complete queryable record.

Scope, dependencies, and overlap

  • This branch includes the shared turn reducer also carried by C1 #21053 and owner-binding foundations related to C5 #21058. That overlap must be reconciled as one landing sequence, not reviewed as independent duplicate implementations.
  • C5 #21058 overlaps the combined C5/C10 branch #21054; do not merge both independently.
  • C4 #21057 still needs to supply real provider inventory and terminal-record sources.
  • C6 #21059 still needs exact-attachment live / unverifiable / exited observations and the bounded host scheduler.
  • C7 #21060 still needs to publish the resulting status to desktop, headless, direct SSH, CLI, and mobile readers with mixed-version handling.
  • Restart recovery still needs a durable record or a complete host resnapshot with continuous delivery tracking; the in-memory map in this branch cannot recover a turn across restart by itself.

Review and validation status

Draft / not merge-ready. Earlier independent review found the production wiring and restart gaps above. Merging current origin/main resolved conflicts by preserving main's structured-session status store and listing behavior while keeping provider turn evidence ahead of legacy presentation filtering; this integration needs fresh independent review because it composes two status-lifecycle changes.

Checks rerun on merged head 0970c7149848023bcc06f281259bc0e27129c929 against origin/main 383c543e0f6651a6c2d99ecca5ab43fbedd1bee8:

  • 7 focused reducer, provider, hook-server, structured-status, teardown, and SSH relay test files: 71 tests passed.
  • pnpm tc:node, pnpm tc:web, and pnpm tc:cli passed.
  • pnpm run check:code-quality:changed, formatting hooks, lint hooks, and diff/conflict-marker checks passed.

Not performed on this revision: live provider drop/recovery, direct-SSH interruption, Windows/WSL execution, restart/replay, independent final review, or Electron/mobile UI QA. No UI code changed in the conflict resolution, and no rendered behavior is claimed from the unit and type checks.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review and validation handoff — 2026-09-16

Draft / not merge-ready. Published at the user's request before review/QA completion. Published head: 07c60e9ba1d5072d95c044c2d7b067b7c2e3dd1d.

What has been done

Independent review-and-fix traced provider/reducer/relay/PTY teardown paths; fixed anonymous-child rebinding, interrupt markers, exact unregister, exit observation after dismissal and reconcile-before-cleanup ordering. Focused tests and type/lint checks were reported passing.

These are recorded worker/reviewer results from the stated revisions, not a fresh coordinator rerun, CI result, or blanket approval of today's PR head. Recovery/review workers used GPT-5.6 Sol xhigh; provider interruptions prevented some follow-up stages from finishing.

What still needs to be done

Resolve owner-registration/binding, provider producer/terminal-record delivery, authoritative execution observation, canonical host projection/replication and restart-durability dependencies. Full end-to-end acceptance failed. Final-head integration review and fresh Electron QA are outstanding.

Before marking ready: address proven findings, reconcile current main and cross-batch overlap, complete independent review of the final diff, rerun relevant tests/typechecks/quality, and perform fresh manual Electron QA against that exact head. Use background/hidden CDP validation; unavailable auth/platform scenarios remain explicitly unverified. No successful final-head review or QA should be inferred from old report filenames or task completion labels.

Related batch PRs

C1: #21053 · C10: #21054 · C2: #21056 · C3: #21055 · C4: #21057 · C5: #21058 · C6: #21059 · C7: #21060

The remaining full-batch work stays open; opening this draft does not mark those requirements complete.

@brennanb2025 brennanb2025 changed the title Agent status C2: turn evidence and recovery integration Agent status C2: recover turns when completion goes missing Sep 16, 2026
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Main integration update

  • New head: 0970c7149848023bcc06f281259bc0e27129c929
  • Integrated upstream: origin/main at 383c543e0f6651a6c2d99ecca5ab43fbedd1bee8
  • Resolved conflicts:
    • server-listeners.ts: kept main's combined legacy/structured status replay and snapshot behavior, with the C2 turn-lifecycle layer still in the server inheritance chain.
    • server-status-update.ts: kept C2 provider evidence processing before main's legacy-row write check, so a presentation filter cannot discard matching recovery evidence while main's store rules still gate the visible row.

Checks rerun on this head: 7 focused test files / 71 tests passed; pnpm tc:node, pnpm tc:web, and pnpm tc:cli passed; changed-file quality, formatting/lint hooks, diff checks, and conflict-marker checks passed.

Still blocked from merge readiness: no production owner registration, provider inventory/terminal-record queries, bounded recovery scheduler, final status publication, or restart re-derivation; live SSH/Windows/provider-drop cases and final Electron/mobile QA remain unverified. This conflict resolution composes two status-lifecycle changes and needs fresh independent review; the PR remains draft.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Closing this draft from the September 14 agent-status plan. That plan was re-examined against current main and replaced.

This branch conflicts with main, and its central work duplicated contracts that had already merged (the canonical status store and the child-work contract landed on 15–16 September). The replacement work is being done as smaller root-cause PRs, each planned, challenged and reviewed first.

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