Skip to content

fix(agent-status): reconcile completed Claude background tasks - #15591

Closed
OrcaWin wants to merge 4 commits into
mainfrom
OrcaWin/jinwoo-sta-4756-remote-stale-agent-status
Closed

OrcaWin wants to merge 4 commits into
mainfrom
OrcaWin/jinwoo-sta-4756-remote-stale-agent-status

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Aug 20, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​564 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​562
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​520 $\color{#cf222e}{\Huge{\mathbf{−}}}$​59 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​461

Summary

Addresses #15317 / STA-4756.

  • reconcile Claude background task ownership from exact terminal task notifications at a provider-owned idle_prompt boundary
  • keep unknown, unbounded, mismatched, and transcript-less work fail-active
  • retire a missed SubagentStop through the same exact task-id evidence
  • replay the reconciled ordinary done payload without adding a wire field or opcode

Root cause

Claude can emit Stop while background_tasks still contains running work, append a structured <task-notification> when that work terminates, resume internally without UserPromptSubmit, and then miss the final Stop/SubagentStop hook. Orca consequently retains the last working tool event in authoritative relay state. Reconnect and client restart faithfully replay that stale host state; replay is propagation, not the source.

An idle_prompt notification alone is not a completion signal: Claude 2.1.237 also emits it while a background shell is still running. This change only clears task IDs that Orca previously observed as running in the same transcript and whose terminal notification was appended at or after Orca observed that ownership. The transcript scan is bounded to 4 MiB and fails active if evidence is unavailable.

Real paired candidate validation

Fresh candidate server on Windows 2 (6aae67d0-9e72-4bb7-b1ac-f5b21f09cb43):

  • Claude 2.1.237 ran a real background sleep 12; provider output reached FINISHED and the TUI was idle
  • authoritative remote worktree ps transitioned from agent working while the shell ran to done after the provider-authored task delivery
  • the installed client was fully restarted while the candidate server and Claude process survived; Electron CDP rendered the remote workspace and agent as Done
  • switching to a local workspace and back preserved rendered Done
  • a separate Codex control could not start because the isolated candidate profile lacked CODEX_LB_API_KEY; no Codex product conclusion is drawn from that environment failure

This covers provider/session state, execution-host authority, client mirror/rendering, reconnect/client restart, and hidden workspace switching. Parking was not involved in the reproduced failure or the authoritative fix.

Reviewer hardening

Three independent gpt-5.6-luna reviewers challenged the lifecycle and compatibility boundary. Valid findings were fixed before this update:

  • idle_prompt without an exact owned terminal task record emits no completion
  • rejected nested/stale hooks roll back both subagent roster and lead lifecycle state
  • repeated running inventories retain the original ownership boundary so a delayed idle hook can still consume an already-written completion
  • authoritative reconciliation accepts only Claude's promptSource: system / origin.kind: task-notification delivery record and rejects queue, user-authored, and malformed shapes; the view-only AI Vault scanner retains historical queue-record support

The 4 MiB transcript scan and in-memory ownership are deliberately fail-active: missing evidence preserves working rather than fabricating done.

Windows 2 evidence

Installed Orca 1.4.185, paired remote workspace:

  • workspace: C:/Users/neil/orca/workspaces/orca/fix-windows-enumerate-the-process-table-through
  • pane: f02245b1-f3fb-46e9-8b51-5f2fa1dfdd76:204ffd75-ce36-4a11-9c2b-c9a74695d68f
  • terminal: term_e89c6c93-24c5-4b1a-a379-bfd6f0fcda73
  • Claude session: e6a90aa2-d59a-4ce3-b084-76f19153b7b7

Independent signals at failure:

  • provider session file reported idle; provider PID remained live
  • orca terminal wait --for tui-idle succeeded and the prompt/title was idle
  • authoritative orca worktree ps --json and persisted Orca state remained working, with last hook PostToolUse:Bash
  • disconnect/reconnect and full client restart replayed working while the remote server survived

This excludes process death, terminal parking, and renderer-only projection staleness for the reproduced failure.

Deterministic proof

src/relay/agent-hook-server.test.ts reproduces the exact host transition and reconnect replay. Mutation proof:

  • reconciliation disabled: expected done, received working
  • reconciliation restored: same test passes and replay returns done

Additional coverage pins exact-id matching, multiple tasks, repeated-inventory ownership retention, provider-authored notification provenance, malformed/unidentified tasks, missed SubagentStop, cron isolation, hook preservation, partial JSONL records, and the bounded scan boundary.

Validation

  • 213 relevant Claude/relay/parser/installer tests pass (10 skipped by existing platform guards)
  • mutation proof: disabling reconciliation reproduces expected done, received working; restoring it passes and reconnect replay returns done
  • full pnpm run typecheck
  • focused oxlint --deny-warnings
  • pnpm run check:max-lines-ratchet
  • git diff --check
  • prior pushed head passed all PR CI, including Windows packaging, managed hooks on Node 18, Git compatibility, and cross-version wire compatibility; the hardened head is running the same checks
  • local cross-version harness remains blocked before execution by its Windows sh/tar -C native-path handling; CI's cross-version job passed

Residual risks

  • ownership is in-memory and transcript scanning is bounded to 4 MiB; missing evidence fails active and preserves working
  • transcript file identity is path-based; replacement by another local process is outside the proven provider lifecycle boundary
  • Claude task IDs are treated as session-unique provider identities; preserving the original offset across repeated stale inventories is required for the demonstrated final-Stop sequence
  • nested cross-provider working-hook cache ownership predates this change; the new idle/done reconciliation path is covered by admission rollback

Compatibility

The execution host/relay owns reconciliation. There is no RPC, stream-frame, or status-payload schema change; mixed-version clients receive the existing done payload. Native, WSL, SSH, and folder-workspace authority remains at the execution host. Parked/hidden renderer paths are not modified.

Open PR #15558 independently filters Claude settings to schema-supported hook events. Notification is a Claude-supported event, but that PR's allowlist must retain it if both changes land.

@OrcaWin
OrcaWin force-pushed the OrcaWin/jinwoo-sta-4756-remote-stale-agent-status branch from 9ca211d to 621b34c Compare August 20, 2026 10:23
@nwparker

Copy link
Copy Markdown
Contributor

Thank you @OrcaWin for this PR. Keeping the agent working while background Claude tasks are live landed in #22295 and #22452, and this PR now conflicts with main, so I am closing it as superseded. Your effort is appreciated.

@nwparker nwparker closed this Oct 24, 2026
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