Skip to content

feat(agent-status): add a bounded agent process exit watch - #47839

Open
noter wants to merge 1 commit into
stablyai:mainfrom
codeious:ac/03-f7-process-exit-watch
Open

noter wants to merge 1 commit into
stablyai:mainfrom
codeious:ac/03-f7-process-exit-watch

Conversation

@noter

@noter noter commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Some agents say "session ended" while their process keeps running. This adds a small watcher that checks whether the process really exited before Orca marks the terminal as finished.

What Changed

Standalone. Rebased onto main at 845867a; it has no dependencies and can merge on its own. Commit ca8014bc9e.

  • Adds AgentProcessExitWatch, which probes a pane's agent process after it reports a session end.
  • Backs off from 250 ms to 8 s, for at most 90 s, and stops once the probe confirms the exit, has nothing to check, or the pane no longer holds what the watch started for.
  • Ignores a probe that settles after a stop or restart.
  • Nothing uses it yet; the Droid exit PR in this stack is the first caller.

Why

Droid sends SessionEnd both when it exits and when /new switches sessions (recorded on Droid 0.238.0 and 0.244.0), so SessionEnd alone cannot prove the process exited. A bounded, cancellable watch keeps that proof out of each provider.

Linked Issue

Part of #9690: groundwork for the Droid exit PR (see Stack).

Visual Proof

N/A: no caller in this PR.

Testing

Local macOS only.

  • ORCA_CODE_QUALITY_BASE=stablyai/main pnpm check:changed passed on this commit after the rebase (format, oxlint, typecheck, tests importing the change, selected ratchets).
  • Full unit suite (pnpm test --maxWorkers=6) on this branch: 1322 test files passed, 3 failed, 15 skipped. The failing files also fail on main at 845867a on this machine: agent-cli-update-timeout (timing), bot-upcoming-copy (locale), worktree-removal-real-git (temp-dir cleanup).
  • Golden E2E journeys ran on the previous stack tip (main at 59f3122): 8 passed, 4 skipped (Windows-only), and golden-fresh-profile-terminal failed the same way on main. Not rerun after the rebase.

Not run: Linux, Windows, or SSH remote hosts.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below
  • Every added test fails without this change and avoids the test anti-patterns

Changed test files:

  • src/shared/agent-status/process/agent-process-exit-watch.test.ts

Performance

None, because nothing starts a watch in this PR. Once used, a watch is bounded to 90 s per pane with backoff from 250 ms to 8 s.

Risk

Level: Low

New module with no caller here. Back out with a plain revert.

AI Disclosure

Review

Self-reviewed this PR's single commit for correctness, security, and performance. Merge order:

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

Considered security, macOS/Linux/Windows paths, SSH remote hosts, mobile compatibility, folder workspaces, and performance. Execution coverage is limited to the checks listed under Testing.

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)
  • I stated the risk: what could break, for whom, and how to back it out
  • 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)

Merge message

feat(agent-status): add a bounded agent process exit watch

An agent can report a session end while its process keeps running.
Add a bounded watch that probes the pane's agent process with backoff
for up to 90 s and stops once the exit is confirmed or the pane no
longer holds the watched process.

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

The changes add provider-managed pane-state cleanup and claims, replace Claude-specific expiry timers with lease-provider scheduling, and add polling for agent process exits. The runtime write guard also protects additional agent-home directories and inherited configuration paths.

Merge Risk: Low · up to 08e42

The new process-exit watch is not used yet, so merging does not change behavior today. Before the first caller is added, the watch should enforce its 90-second limit even when a probe never returns. Without that, a stuck probe keeps the watch alive indefinitely.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "feat(agent-status): add a bounded agent process exit watch" matches the main change: the new AgentProcessExitWatch class in src/shared/agent-status/process/ polls an agent process after a s…
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.
Description check Passed The description covers most required template sections. It has a substantive ELI5, a What Changed section with the mechanism (backoff from 250 ms to 8 s, 90 s limit, stop conditions), a Why section th…
Full details: Title check

Explanation

The title "feat(agent-status): add a bounded agent process exit watch" matches the main change: the new AgentProcessExitWatch class in src/shared/agent-status/process/ polls an agent process after a session-end report, with backoff and a 90-second deadline. The title is specific and follows a conventional commit style. It does not describe the rest of the stack's changes (hook state slots, lease timers, test home guards), but the PR's own changeset is mainly the exit watch plus its test, so the title is accurate.

Full details: Description check

Explanation

The description covers most required template sections. It has a substantive ELI5, a What Changed section with the mechanism (backoff from 250 ms to 8 s, 90 s limit, stop conditions), a Why section that explains the Droid SessionEnd ambiguity, Testing with commands and results, a Performance line, a Risk level with a revert plan, and completed checklist and upstream boundary items. Gaps: the Linked Issue section says 'Part of #9690' rather than the 'Fixes #' form the template asks for, and the template asks for a Visual Proof N/A reason, which is given. The AI Disclosure section is left as the raw template comment with no content. The Merge message block is extra content outside the template. The Testing section also reports that the full test suite had 3 failing files, which the reviewer should weigh. The checklist leaves the lint/typecheck/test/build item unchecked, with no note that CI will cover it. The Testing section does not say whether the new test was shown to fail without the change, which the anti-pattern checkbox requires.

Resolution

Optional improvements: fill in or mark the AI Disclosure section, state whether the new test fails without the change, and clarify the linked issue reference (the template asks for a 'Fixes #' link, and the author notes this PR is part of #9690). The PR description is mostly complete, so these items are not blocking.

  • 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

@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

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f6ba21d4-62f9-420d-8118-ff941837e801
Commits

Reviewing files that changed from the base of the PR and between 50f0c54 and 08e425a.

Files selected for processing: 15

  • config/scripts/test-runtime/environment/vitest-real-agent-home-write-guard.ts
  • src/main/agent-hooks/server/server-cleanup.ts
  • src/main/agent-hooks/server/server-lifecycle.ts
  • src/main/agent-hooks/server/server-status-row-mutation.ts
  • src/shared/agent-hook-listener/leases/agent-lease-expiry-timers.ts
  • src/shared/agent-hook-listener/leases/hook-lease-expiry-timers.ts
  • src/shared/agent-hook-listener/listener-state.ts
  • src/shared/agent-hook-listener/pane-state-claims.ts
  • src/shared/agent-hook-listener/providers/claude/background-tasks/claude-owed-notification-expiry-timers.ts
  • src/shared/agent-hook-listener/state/provider-hook-state-slots.ts
  • src/shared/agent-status/process/agent-process-exit-watch.test.ts
  • src/shared/agent-status/process/agent-process-exit-watch.ts
  • src/wsl-guest/agent-hooks/results/agent-hook-result-retry-scheduler.ts
  • src/wsl-guest/agent-hooks/server/agent-hook-request.ts
  • src/wsl-guest/agent-hooks/server/agent-hook-server.ts

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

this.watches.delete(key)
return
}
void watch.probe().then(

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.

Minor · Stability & Availability · Quick win

Expire watches while a probe is pending.

If watch.probe() never settles, no code checks the deadline again. The map retains the watch and its host beyond the stated 90-second window.

Add deadline cleanup that runs independently of probe settlement. Cancel that cleanup on completion, stop, or replacement. Keep the identity checks so late settlement cannot affect a replacement watch.

This follows the PR's bounded-watch objective and the retrieved learning about lifecycle-bound asynchronous work.

Source: Learnings

@noter
noter force-pushed the ac/03-f7-process-exit-watch branch from 08e425a to 3f5b80d Compare November 26, 2026 11:29
…ng its end

AgentProcessExitWatch probes a pane's agent process after it reports a
session end, backing off from 250 ms to 8 s for at most 90 s, and stops as
soon as the probe confirms the exit, has nothing to check, or the pane no
longer holds what the watch started for. A probe that settles after a stop
or restart is ignored.

Hook providers whose SessionEnd can precede the process exit (a /clear also
ends a session) use it to end the row only once the process is gone.
@noter
noter force-pushed the ac/03-f7-process-exit-watch branch from 3f5b80d to ca8014b Compare November 26, 2026 11:47

This branch has not been deployed

No deployments
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