You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(droid): finish terminal rows after proven process exit - #47842
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.
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/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:
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.
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: 4
Check name
Status
Explanation
Title check
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
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description check
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
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.
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.
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.
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.
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.
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.
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.
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.
…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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
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.
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.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.SessionEndjoinsDROID_EVENTSindroid-hook-config-files.ts, so it is added tosettings.json, and tohooks.jsononly when that file already defines it. The process capture goes into the script inhook-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:
unverifiablewhen 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
/newsends 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:changedpassed on this commit after the rebase (format, oxlint, typecheck, tests importing the change, selected ratchets).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-fresh-profile-terminalfailed 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.
Changed test files:
src/shared/agent-hook-listener/normalization/agent-hook-listener-droid-exit.test.ts(replaysdroid-parent-process-hooks.jsonlanddroid-slow-start-hooks.jsonl)src/wsl-guest/agent-hooks/server/relay-droid-exit-watch.test.tssrc/main/droid/hook-service.test.ts(addsSessionEndto 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.tson 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
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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)Merge message