Skip to content

feat(droid): finish terminal rows after proven process exit - #47842

Open
noter wants to merge 4 commits into
stablyai:mainfrom
codeious:ac/06-d2b-droid-exit-proof
Open

noter wants to merge 4 commits into
stablyai:mainfrom
codeious:ac/06-d2b-droid-exit-proof

Conversation

@noter

@noter noter commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When Droid exits in an Orca terminal, Orca's hooks had no reliable signal for it, so the terminal could keep showing Droid as working. Orca now listens for Droid's end-of-session hook, checks that the Droid process really exited, and then ends the row.

What Changed

Rebased onto main at 845867a. It depends on #47839, #47838, #47841; until they merge, this diff also shows their commits. Review only this PR's commit 5123915852.

  • Installs Droid's SessionEnd hook, and the Droid hook script now sends the agent process like Claude's does.
  • On a Droid SessionEnd, starts the exit watch from the earlier PR and publishes the end only after the probe confirms the process is gone, in both the main and WSL guest listeners.
  • Replayed and retried hooks do not start a new watch.
  • Keeps the pane's resume target while a replacement session starts.
  • Uses the hook layout from fix(droid): install managed hooks where Droid reads them #47853 (merged): SessionEnd joins DROID_EVENTS in droid-hook-config-files.ts, so it is added to settings.json, and to hooks.json only when that file already defines it. The process capture goes into the script in hook-service.ts, for local and SSH installs alike, inside fix(droid): preserve user hook commands and concurrent remote edits #49456's retrying remote install.

Review fixes since the first push:

  • The relay's process check reports unverifiable when the pane changed owner while the probe ran, instead of reporting the old owner's exit.

Why

On main, Droid hooks carry no process identity and Orca installs no Droid SessionEnd hook, so hooks cannot report that Droid exited and the row keeps its last state (the symptom in #9690). SessionEnd alone is not proof: recorded runs show /new sends SessionEnd for the old session, and later another one for it, while Droid keeps running.

Linked Issue

Part of #9690 (adds the exit signal it is missing; a live Ctrl+C retest is still to do, see Testing).

Visual Proof

N/A: verified by replaying recorded Droid hook sequences, not screenshots.

Testing

Local macOS only.

  • ORCA_CODE_QUALITY_BASE=ac/05-d2a-droid-child-work 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: 1326 test files passed, 2 failed, 15 skipped. The failing files also fail on main at 845867a on this machine: agent-cli-update-timeout (timing), bot-upcoming-copy (locale).
  • 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: a live Droid exit with Ctrl+C in a terminal (the #9690 scenario). 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-hook-listener/normalization/agent-hook-listener-droid-exit.test.ts (replays droid-parent-process-hooks.jsonl and droid-slow-start-hooks.jsonl)
  • src/wsl-guest/agent-hooks/server/relay-droid-exit-watch.test.ts
  • src/main/droid/hook-service.test.ts (adds SessionEnd to the expected managed events)

Performance

One bounded exit watch per pane after a Droid SessionEnd (at most 90 s, backoff 250 ms to 8 s).

Risk

Level: Medium

A probe that never agrees would leave a Droid row unchanged until the watch gives up, which is today's behavior. Overlap with droid-turn-outcome.ts on main is not checked yet. 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(droid): finish terminal rows after proven process exit

Droid hooks could not report that Droid exited, and SessionEnd also
precedes /new session switches. Install the SessionEnd hook, capture
the agent process, and end the row only after the exit watch proves
the process is gone, without re-watching replayed history.

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

The change adds provider-session normalization and provider-owned pane state. Droid hooks now track process ownership, lead and child sessions, and background-child status. Shared lease timers handle Claude and Droid expiry. Main and WSL hook servers add process-exit watches. Droid POSIX hook commands capture process identity.

Merge Risk: Moderate · up to 51239

Droid SessionEnd handling now depends on a process-exit watch that cannot confirm exit for native Windows sessions, so those rows may stay unfinished. Several smaller edge cases in child-session and lease handling remain open. They affect status accuracy rather than data safety. Resolve or accept these before merging.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "feat(droid): finish terminal rows after proven process exit" describes the main change: Droid SessionEnd handling that ends a terminal row only after an exit watch confirms the agent proces…
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 follows the repository template closely. It has ELI5, What Changed, Why, Linked Issue, Visual Proof (N/A with reason), Testing, Performance, Risk (level Medium with a back-out plan), R…
Full details: Title check

Explanation

The title "feat(droid): finish terminal rows after proven process exit" describes the main change: Droid SessionEnd handling that ends a terminal row only after an exit watch confirms the agent process exited. The changeset adds the SessionEnd hook, process capture, and the exit watch in the main and WSL guest listeners, so the title matches the primary behavior.

Full details: Description check

Explanation

The description follows the repository template closely. It has ELI5, What Changed, Why, Linked Issue, Visual Proof (N/A with reason), Testing, Performance, Risk (level Medium with a back-out plan), Review, Notes, and Checklist sections. Testing is detailed and states what was and was not run. Gaps: the Linked Issue is 'Part of #9690' rather than a 'Fixes #' closing reference, the AI Disclosure section is left as template text, and the 'Every added test fails without this change' box is unchecked. The 'pnpm lint, typecheck, test, build' box is also unchecked, though the author reports a partial local check run. The risk section does not name the riskiest part in depth beyond the probe-never-agrees case, and the 'Overlap with droid-turn-outcome.ts not checked' note is an open item.

  • 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: 8

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: 2f662dc1-8f2b-4dca-9b11-90f18405e44b
Commits

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

Files selected for processing: 59

  • config/main-blocking-helper-baseline.txt
  • config/scripts/test-runtime/environment/vitest-real-agent-home-write-guard.ts
  • src/main/agent-hooks/installation/remote-managed-hook-installers.ts
  • src/main/agent-hooks/server/agent-hook-server.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/main/agent-hooks/wsl-relay/wsl-hook-fs-adapter.ts
  • src/main/droid/droid-hook-config.ts
  • src/main/droid/droid-hook-file-remote.ts
  • src/main/droid/droid-hook-script.ts
  • src/main/droid/droid-hook-status.ts
  • src/main/droid/droid-hooks-file.test-fixture.ts
  • src/main/droid/droid-org-policy.ts
  • src/main/droid/hook-service.test.ts
  • src/main/droid/hook-service.ts
  • src/shared/__fixtures__/droid-parent-process-hooks.jsonl
  • src/shared/__fixtures__/droid-parent-process-hooks.meta.json
  • src/shared/__fixtures__/droid-slow-start-hooks.jsonl
  • src/shared/__fixtures__/droid-slow-start-hooks.meta.json
  • src/shared/__fixtures__/droid-subagent-hooks.jsonl
  • src/shared/__fixtures__/droid-subagent-hooks.meta.json
  • src/shared/agent-hook-listener/hook-normalization-policy.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/normalization/agent-hook-listener-droid-driver.test-support.ts
  • src/shared/agent-hook-listener/normalization/agent-hook-listener-droid-exit.test.ts
  • src/shared/agent-hook-listener/normalization/agent-hook-listener-droid-ownership.test.ts
  • src/shared/agent-hook-listener/normalization/hook-prompt-identity.ts
  • src/shared/agent-hook-listener/normalization/normalize-hook-payload.ts
  • src/shared/agent-hook-listener/pane-provider-session.ts
  • src/shared/agent-hook-listener/pane-state-claims.ts
  • src/shared/agent-hook-listener/provider-dispatch.ts
  • src/shared/agent-hook-listener/provider-hook-capabilities.ts
  • src/shared/agent-hook-listener/provider-hook-session.ts
  • src/shared/agent-hook-listener/providers/claude/background-tasks/claude-owed-notification-expiry-timers.ts
  • src/shared/agent-hook-listener/providers/droid/droid-events.ts
  • src/shared/agent-hook-listener/providers/droid/droid-hook-session.ts
  • src/shared/agent-hook-listener/providers/droid/droid-lease-expiry.ts
  • src/shared/agent-hook-listener/providers/droid/droid-probe-log-replay.test-fixture.ts
  • src/shared/agent-hook-listener/providers/droid/droid-session-owner.ts
  • src/shared/agent-hook-listener/providers/droid/droid-session-status.ts
  • src/shared/agent-hook-listener/providers/droid/droid-sessions.ts
  • src/shared/agent-hook-listener/providers/droid/droid-transcript-origin.ts
  • src/shared/agent-hook-listener/state/provider-hook-state-slots.ts
  • src/shared/agent-hook-listener/transport/agent-hook-policy-read-paths.ts
  • src/shared/agent-status/process/agent-process-exit-watch.test.ts
  • src/shared/agent-status/process/agent-process-exit-watch.ts
  • src/shared/agent-status/process/agent-process-presence.ts
  • src/shared/droid/droid-org-settings-path.ts
  • src/wsl-guest/agent-hooks/presence/relay-agent-presence.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
  • src/wsl-guest/agent-hooks/server/agent-hook-spool-ingest.ts
  • src/wsl-guest/agent-hooks/server/relay-droid-exit-watch.test.ts
  • src/wsl-guest/agent-hooks/status/agent-hook-event-admission.ts
  • src/wsl-guest/commands/wsl-hook-fs-bridge.ts

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

Comment thread src/main/droid/droid-hook-config.ts Outdated
continue
}
if (
!value.some((definition) => hookDefinitionHasManagedCommand(definition, isManagedCommand))

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

Handle non-object event members before the Droid hook helpers read them.

hooks.json and settings.json are checked only for a top-level object. An event array can therefore contain null. A null member makes hookDefinitionHasManagedCommand, removeManagedCommands, and resolveDroidHookCoverage throw a TypeError. For example, {"Stop":[null]} in hooks.json throws from remove(), install(), and getStatus(). install() and remove() throw before any config write. Remote install returns an error status instead.

The merge-base code had the same dereference for settings.json entries. This PR adds hooks.json as another input that reaches it.

Define the required behavior at the read boundary or in the helpers. Non-object members must not stop status, install, or removal. Choose one policy and apply it to every reader:

  • Reject the file with an explicit error status.
  • Skip non-object members in the helpers and leave them unmodified.

Comment thread src/main/droid/droid-hook-config.ts Outdated
scriptFileName: string
): { settingsChanged: boolean } {
const isManagedCommand = createManagedCommandMatcher(scriptFileName)
carrySettingsHooksIntoHooksFile(hooksFile, settings)

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.

Major · Data Integrity & Integration · Heavy lift

Carry legacy hooks/hooks.json entries into the new hooks.json.

When ~/.factory/hooks.json does not exist, install() starts from an empty hooksFile. It then writes a hooks.json that contains only the Orca-managed hooks. Factory reads hooks.json in place of the legacy ~/.factory/hooks/hooks.json, so the custom hooks in that legacy file stop running with no notice.

The SSH path in installRemote() has the same gap. It reads only the remote hooks.json.

Before writing hooks.json, both install paths must read the legacy hooks file when hooks.json is absent. They must carry its events into the new file for each event that hooks.json does not already define. The remove path must not drop these migrated hooks.

if (existing !== null) {
await writeTextFileRemoteAtomic(sftp, `${path}.bak`, existing)
}
await writeHooksJsonRemote(sftp, path, config, { serialized })

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 · Data Integrity & Integration · Heavy lift

Guard the Droid hooks.json publish against a concurrent save.

installRemote builds the config from the snapshot read at src/main/droid/hook-service.ts:137. writeDroidHookFileRemote then publishes that config without checking whether the remote file changed after the snapshot. writeHooksJsonRemote compares only the new content with the current file. A /hooks save that lands before the read at src/main/droid/droid-hook-file-remote.ts:14 is copied to .bak and then replaced. A save that lands after that read is replaced with no backup. In both cases, the saved user command is missing from hooks.json.

Writes derived from a snapshot must not publish when the file changed since that snapshot. writeTextFileRemoteAtomic already implements this with computedFrom, and returns false on conflict. Keep the Droid write on that contract, or add an equivalent check. On conflict, re-read the file, reapply the managed-hook mutation, and retry. Keep the early return for unchanged content. Choose the retry limit and the error returned when conflicts repeat.

The existing check still leaves one round trip between the comparison and the rename, as noted at src/main/agent-hooks/installation/remote/hook-text-files-remote.ts:72. A fix that reuses it narrows the window rather than closing it.

Comment thread src/main/droid/droid-hook-status.ts Outdated

// Why: report a silenced Droid in every branch, or a user would think a reinstall fixed it.
const reasons: string[] = []
if (hooksAreDisabled(files)) {

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 · Functional Correctness · Quick win

Include the organization-wide disable flag in coverage.

If organization settings contain {"hooks":{"hooksDisabled":true}}, Droid runs no hooks. This applies independently of allowManagedHooksOnly. (docs.factory.com)

The policy helper returns false for that configuration. With all managed commands present, this function therefore returns installed. Pass the organization disable flag into coverage and return partial with a disable reason. Keep complete, unrestricted configurations as installed.

}
const promptText = extractedPrompt.text
const dispatched = normalizeProviderEvent({
const sessionAdmission = prepareProviderHookSession(source, {

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 · Functional Correctness · Heavy lift

Child sessions from a separate same-agent process are refused before child admission.

readHookProcessAdmission refuses a hook whose host verdict is nested. The host returns nested when an ancestor runs the same agent in a different process group (hook-process-root-evidence.ts:105-117, 177-178). The refusal returns null at normalize-hook-payload.ts:138-154, before prepareProviderHookSession runs at line 219. A Droid child session whose hook comes from such a process can never reach DROID_HOOK_SESSION_PROVIDER.admit, so its work is not recorded. Children that share the root's process group are classified unknown and are not refused by this check.

Droid child sessions need a defined path into child admission. Either the nested refusal must not apply to a Droid child admitted by its calling session, or the refusal must be scoped so that child hooks reach prepareProviderHookSession. The repository does not establish which process topology real Droid child sessions use, so the choice of exemption point is a policy decision for the admission contract.

export const CLAUDE_OWED_NOTIFICATION_LEASE_PROVIDER: AgentLeaseExpiryProvider = {
lease(state, paneKey) {
// Only an idle main agent has one: the lease does not run while it is in a turn.
const idleSince = mainAgentIdleSince(state.claudeLeadStateByPaneKey.get(paneKey))

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.

Major · Data Integrity & Integration · Quick win

Guard the Claude owed-notification lease to Claude rows.

A Droid row can replace a Claude row in the same pane while Claude lead state and owed-task records remain. The Claude lease does not check the stored row, and HookLeaseExpiryTimers takes the first provider that returns a lease. The Claude lease can therefore hide the Droid background-child lease. When the Claude deadline expires, settle also publishes a Claude payload with the Droid row's providerSession and presence. Return no Claude lease unless the stored row is a Claude row.

Suggested fix

   lease(state, paneKey) {
+    // Why: a Droid row can replace a Claude row and keep its Claude debt; the Droid lease must not be masked.
+    if (state.lastStatusByPaneKey.get(paneKey)?.payload.agentType !== 'claude') {
+      return undefined
+    }
     // Only an idle main agent has one: the lease does not run while it is in a turn.

Comment on lines +188 to +190
stoppedByUser && status.stateName === 'done'
? droidVerdictFields('cancellation', Date.now())
: undefined

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 · Functional Correctness · Quick win

Retain cancellation while child work delays completion.

If an outliving child is still working when the lead sends idle_prompt, stoppedByUser is true but the combined row remains working. This condition drops the cancellation verdict. applyDroidLeadEvent stores only the lead state, so the later child Stop and lease expiry produce a done row without that verdict.

Store the cancellation with the lead state. Project it when the combined row becomes done, including through lease expiry. Preserve the current immediate verdict when no child holds the row open.

!sessions?.children.has(sessionId)
const parentId =
(isStart ? readString(hookPayload, 'calling_session_id') : undefined) ??
(isStart || unseen ? readDroidTranscriptCallingSessionId(hookPayload) : undefined)

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 · Functional Correctness · Quick win

Retry transcript discovery while the lead is provisional.

When the pane has no session state, a worker's first non-start hook makes that worker the provisional lead if its transcript yields no calling_session_id. Later hooks from that worker are recorded as lead events, so line 223 never reads its transcript again. Hooks from the real lead then fall through to SKIP at line 251, and the worker stays the lead.

Read the transcript while the lead is still provisional. A successful read repoints the lead to the real parent through adoptChild and confirmOrRepointLead. The current fallback stays unchanged when the transcript remains unavailable.

Suggested fix

--- "a/src/shared/agent-hook-listener/providers/droid/droid-sessions.ts"
+++ "b/src/shared/agent-hook-listener/providers/droid/droid-sessions.ts"
@@ -220,7 +220,7 @@
     !sessions?.children.has(sessionId)
   const parentId =
     (isStart ? readString(hookPayload, 'calling_session_id') : undefined) ??
-    (isStart || unseen ? readDroidTranscriptCallingSessionId(hookPayload) : undefined)
+    (isStart || unseen || sessions?.provisional ? readDroidTranscriptCallingSessionId(hookPayload) : undefined)
   if (isStart) {
     return admitStart(state, paneKey, sessions, previous, { sessionId, parentId }, sender)
   }
Committable suggestion

IMPORTANT
Review the replacement and indentation, then test before committing.

Suggested change
(isStart || unseen ? readDroidTranscriptCallingSessionId(hookPayload) : undefined)
(isStart || unseen || sessions?.provisional ? readDroidTranscriptCallingSessionId(hookPayload) : undefined)

@noter
noter force-pushed the ac/06-d2b-droid-exit-proof branch from a1afd70 to 7cb482d 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.
…se timers

Provider-owned pane maps now register with ProviderHookStateSlots, so pane
teardown, moves and claim checks reach them without each map being listed
in listener-state by hand. Claude's two claim-bearing maps and its prompt
turn order move onto slots.

Claude's owed-notification timers become one lease provider behind a
generic AgentLeaseExpiryTimers, which main and the WSL relay both arm
after every stored row. Claude rows restate exactly as before.
Child hooks describe their own work, not the pane's lead or resume target.
Keep a provider-owned roster and lease background work until the lead wakes.
Recover mission ancestry from transcripts when hooks omit their caller.
Route admission and resume ownership through provider-neutral registrations.
Replace the root-turn worker set with the roster: workers that outlive the
root's Stop stay on show, and a finished worker's late hooks stay out.
A prompt from an unseen root still takes the pane; a sub-session with no
lead in the pane settles when its own work ends.
Leave SessionEnd and process-exit handling unchanged for the next slice.
SessionEnd also precedes session switches, so it cannot prove a pane exited.
Capture the agent process and defer completion through the existing exit watch.
Let main and guest listeners publish an end only after their process probe agrees.
Keep replayed and retried history from starting a new watch.
Preserve the pane's resume target while a replacement session starts.

@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: 2

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: 9fdf206e-31d1-4044-b92c-37728a3888c4
Commits

Reviewing files that changed from the base of the PR and between a1afd70 and 7cb482d.

Files selected for processing: 18

  • config/main-blocking-helper-baseline.txt
  • src/main/agent-hooks/server/server-cleanup.ts
  • src/main/droid/droid-hook-config-files.ts
  • src/main/droid/hook-service.test.ts
  • src/main/droid/hook-service.ts
  • src/shared/agent-hook-listener/listener-state.ts
  • src/shared/agent-hook-listener/normalization/agent-hook-listener-droid-ownership.test.ts
  • src/shared/agent-hook-listener/pane-provider-session.ts
  • src/shared/agent-hook-listener/provider-dispatch.ts
  • src/shared/agent-hook-listener/providers/claude/background-tasks/claude-owed-notification-expiry-timers.ts
  • src/shared/agent-hook-listener/providers/droid/droid-events.ts
  • src/shared/agent-hook-listener/providers/droid/droid-session-status.ts
  • src/shared/agent-hook-listener/providers/droid/droid-sessions.ts
  • src/shared/agent-hook-listener/providers/droid/droid-subagent-hooks.test.ts
  • src/shared/agent-hook-listener/providers/droid/droid-worker-sessions.ts
  • src/wsl-guest/agent-hooks/presence/relay-agent-presence.ts
  • src/wsl-guest/agent-hooks/results/agent-hook-result-retry-scheduler.ts
  • src/wsl-guest/agent-hooks/server/agent-hook-server.ts
Files with no reviewable changes: 1

  • src/shared/agent-hook-listener/providers/droid/droid-worker-sessions.ts

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

for (const [id, child] of sessions.children) {
if (!child.outlivedStop) {
sessions.roster.delete(id)
sessions.children.delete(id)

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 · Functional Correctness · Quick win

Mark children that an idle prompt removes as finished.

When the lead sends idle_prompt, applyDroidLeadEvent removes each child whose outlivedStop is false. It does not add that child to finished, unlike applyDroidChildEvent on Stop and SessionEnd. A delayed PostToolUse from a removed child can then re-admit it through its transcript's callingSessionId. The re-admitted child is recorded with outlivedStop set, so the row can remain working after the user cancelled the turn, until that child sends its own idle notification, Stop, or SessionEnd.

Record the removed child in finished. This makes a late hook from that child drop, as finished already does for Stop and SessionEnd. Children that the idle prompt does not remove are unaffected.

Suggested fix

--- "a/src/shared/agent-hook-listener/providers/droid/droid-session-status.ts"
+++ "b/src/shared/agent-hook-listener/providers/droid/droid-session-status.ts"
@@ -82,14 +82,15 @@
       child.outlivedStop = true
     }
   }
   if (event.eventName === 'Notification' && event.notification === 'idle') {
     for (const [id, child] of sessions.children) {
       if (!child.outlivedStop) {
         sessions.roster.delete(id)
         sessions.children.delete(id)
+        sessions.finished.add(id)
       }
     }
   }
 }
 
 /** When the lease on a stopped lead's finished background child runs out; undefined when none runs. */
Committable suggestion

IMPORTANT
Review the replacement and indentation, then test before committing.

Suggested change
sessions.children.delete(id)
sessions.children.delete(id)
sessions.finished.add(id)

Comment on lines +213 to +214
if (eventName !== 'SessionEnd' || sessionId !== sessions?.leadId) {
clearExitMarker(state, paneKey)

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 · Functional Correctness · Quick win

Do not clear the exit marker for hooks that the admission rejects.

The unconditional clear at droid-sessions.ts:213-214 runs before admission decides the event. A late Stop from a child that is not in the active roster then gets SKIP at line 256 and still clears the marker. The exit watch then drops its next wakeup without probing (agent-process-exit-watch.ts:45-53). If Droid exits afterward, no probe observes the exit, and the row is not finished. The lead does not send another SessionEnd, so the row stays unfinished.

A rejected hook must leave the marker and the watch unchanged. The marker should be cleared only when admission accepts the event as lead or child activity. The correct placement depends on how each admitted branch returns, so this change needs its own review of the lead, child, and restate paths.

@noter
noter force-pushed the ac/06-d2b-droid-exit-proof branch from 7cb482d to 5123915 Compare November 26, 2026 11:47

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Major · Native Windows Droid sessions cannot be confirmed as exited by the new exit… · hook-service.ts:75

src/main/droid/hook-service.ts:75
Major · Stability & Availability · Heavy lift

Native Windows Droid sessions cannot be confirmed as exited by the new exit watch.

The Windows hook script returns before the new POSIX process capture, and its POST has no agentProcess field. The row therefore gets no agentPresence.process. checkAgentPresence returns null for such a row, and the exit watch stops on the first null probe without confirming exit. The SessionEnd gate for Droid no longer finishes the row immediately, so for native Windows the row depends on this watch, which cannot confirm exit.

Provide a Windows-capable process identity for native Windows Droid sessions, or a liveness source that the watch can probe. Until then, Windows rows should not wait on this watch to finish. Choose the approach that fits the platform contract. The fix must not leave native Windows Droid rows that never finish.

Source: Learnings

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: 023c99ae-28e5-48ef-b257-951996583ed4
Commits

Reviewing files that changed from the base of the PR and between 7cb482d and 5123915.

Files selected for processing: 2

  • src/main/droid/hook-service.test.ts
  • src/main/droid/hook-service.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.

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