Skip to content

fix(agent-hooks): a proven agent exit survives restarts, late hooks and same-second attaches - #29483

Merged
nwparker merged 5 commits into
mainfrom
nwparker/remote-worker-liveness-followups
Oct 16, 2026
Merged

nwparker merged 5 commits into
mainfrom
nwparker/remote-worker-liveness-followups

Conversation

@nwparker

@nwparker nwparker commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​192 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​190
Prod 15 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​189 $\color{#cf222e}{\Huge{\mathbf{−}}}$​20 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​169

ELI5

#29276 taught the remote host to say "this worker's agent has exited" once it can prove it. This PR closes three gaps where that proof was lost, so the host went back to calling a dead worker "live". It never makes the host call a running agent "exited".

What Changed

Before

After

  • In all three cases the worker reads as exited. When a real successor agent starts in the pane, the proof is still cleared and the worker reads by its terminal's state again.

Mechanism (all on the execution host, in the hook-server store)

  • Persisted proof: proven exits are written to the existing last-status file as an optional agentExits list and restored on start. Each entry holds the time, every pane key the pane went by, and the ended agent's type and process. Older files simply lack the list.
  • What counts as a successor (new claimsPaneAfterExit):
    • a hook from a different process;
    • a hook from a different provider;
    • a provider-aware new turn or session start (isNewTurnEvent);
    • a process-lifetime Working start.
    • Not a terminal repaint, and not a late hook without an ID from the ended session. The claim is judged on the sender's own identity, not the owner the store stamped on the event.
  • Spool replays: a spooled hook written at least a full second before the exit describes the dead agent, so it is skipped. Spool timestamps are whole seconds, so a hook from the same second may be the successor and is still applied.
  • Attach: when a remote worker attaches to a pane, any exit proved earlier is dropped (new forgetHookAgentExit runtime binding). That lets the read cut-off use the attachment's own creation time instead of rounding up.

Why

  • The host owns status, so the proof stays in its hook-server store, the one store every reader already uses. I did not add a parallel record.
  • Each rule errs toward keeping live or unverifiable, never toward exited. A case the host can't prove stays live or unverifiable.
  • I chose forgetting earlier exits at attach over adding a millisecond timestamp column. It needs no schema change and fixes the same-second case directly.
  • Wire compatibility: nothing new crosses the wire. The new file field is optional and old builds ignore it.

Linked Issue

Fixes #29359
Fixes #29356
Fixes #29293

Visual Proof

N/A. Host-side liveness verdict with no UI.

Testing

  • server-agent-presence.test.ts gains cases for: restart persistence; a late hook without an ID; a provider-specific new turn; another provider without a new-turn event; a replacement after a late unidentified hook; an older spooled start (including one carrying an old process ID); a same-second spooled successor; a late terminal repaint from another provider; and forgetting at attach.

  • federation-agent-death-liveness.test.ts checks that attaching forgets earlier exits and that the read cut-off is no longer rounded up.

  • The new cases that cover the three issues fail on the fix(orchestration): remote worker liveness reports exited when the host proves the agent gone #29276 base.

  • I also re-ran the hook spool, last-status hydrate and persist-throttle suites.

  • pnpm tc:node and check:code-quality:changed pass.

  • Codex review (gpt-6.1-sol, high) took five rounds. Every finding was fixed, and the final round found nothing actionable.

  • 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

This builds on #29276, which has merged; the branch is rebased onto main.

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 16, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 4 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cf1e0d5b-1298-441f-a757-1c7fd488bf4a
📥 Commits

Reviewing files that changed from the base of the PR and between a4e3dc2 and 0a516e0e38c630b2da155ac9df22c4b96b42c362.

📒 Files selected for processing: 26
  • config/scripts/vitest-sqlite-runtime-files.mjs
  • src/main/agent-hooks/agent-hook-runtime-deps.ts
  • src/main/agent-hooks/server-agent-presence.test.ts
  • src/main/agent-hooks/server/agent-exit-evidence.ts
  • src/main/agent-hooks/server/server-agent-presence.ts
  • src/main/agent-hooks/server/server-authority-aliases.ts
  • src/main/agent-hooks/server/server-cleanup.ts
  • src/main/agent-hooks/server/server-hydration.ts
  • src/main/agent-hooks/server/server-ingest-normalization.ts
  • src/main/agent-hooks/server/server-ingest-terminal.ts
  • src/main/agent-hooks/server/server-persistence.ts
  • src/main/agent-hooks/server/server-state.ts
  • src/main/agent-hooks/server/server-status-update.ts
  • src/main/agent-hooks/server/server-types.ts
  • src/main/runtime/construction/runtime-construction-dependencies.ts
  • src/main/runtime/construction/runtime-construction.ts
  • src/main/runtime/construction/runtime-host-services.ts
  • src/main/runtime/orchestration/worker-terminal-release-runtime.ts
  • src/main/runtime/rpc/methods/orchestration/federation/federation-agent-death-liveness.test.ts
  • src/main/runtime/rpc/methods/orchestration/federation/federation-attachment-authority.ts
  • src/main/runtime/rpc/methods/orchestration/federation/federation-attachment-observation.ts
  • src/main/runtime/rpc/methods/orchestration/federation/federation-control.ts
  • src/main/runtime/terminal/adoption/adopt-terminal-orphans-from-inventory.ts
  • src/main/runtime/terminal/driver/terminal-driver-resources.ts
  • src/main/runtime/terminal/input/terminal-agent-status-and-submission.ts
  • src/main/runtime/terminal/output/terminal-title-tracker.ts
  • 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.

nwparker and others added 5 commits October 15, 2026 23:37
… hooks, and same-second attaches

- Persist proven exits with the hook store's status file and restore them on hydrate (#29359).
- Clear a retained exit only on evidence of a successor agent: a different process identity
  or a new turn/session, never a PID-less late hook from the ended session (#29356).
- Forget a pane's earlier exits when a remote worker attaches, so the attach fence no longer
  rounds up and drops exits in the creation second (#29293).

Co-Authored-By: Claude <[email protected]>
…same-second spool stamps count as successors

Co-Authored-By: Claude <[email protected]>
@nwparker
nwparker force-pushed the nwparker/remote-worker-liveness-followups branch from 0a516e0 to 8c26f3a Compare October 16, 2026 06:40
@nwparker
nwparker merged commit 224a139 into main Oct 16, 2026
10 of 11 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

1 participant