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
fix(droid): keep a Task worker's hooks off the pane's agent row - #47836
Droid can hand part of a job to a helper (a "Task" subagent). The helper sends Orca its own "starting", "prompt" and "stopped" hooks under its own session id. Orca treated those as the main session's, so the pane's agent row went done while the main session was still working, and the helper's start wiped the main session's prompt from the row.
What Changed
Before: run Droid in an Orca terminal and have it launch a Task subagent while it keeps working. When the subagent stops, the pane's row shows done while the main session is still running. The subagent's start also clears the prompt the row was showing.
After: while the main session's turn is open, the row follows the main session only. A worker's SessionStart, UserPromptSubmit, Stop and idle Notification no longer start, reset or settle the row. Its tool and approval hooks still count, so the row shows working or waiting for the main session's turn.
Mechanism:
pane-provider-session.ts: a hook whose transcript's first record has a callingSessionId already kept the pane's root provider session. The remembered worker set is now checked first, which skips the sync transcript read for a known worker. The root's own UserPromptSubmit opens the turn by setting a fresh, empty worker set for the pane.
droid-worker-sessions.ts (new, no fs): a worker is remembered only while that set exists, that is, while the root's turn is open, and only when a Droid root row owns the pane.
droid-events.ts: drops a known worker's SessionStart and UserPromptSubmit, and its done (Stop or idle Notification). The root's own done deletes the pane's set.
listener-state.ts / dsh-events.ts: dshChildSessionIdsByPaneKey is renamed to childSessionIdsByPaneKey and shared, so the existing pane clear, move and clear-all cleanup covers Droid too. The Droid rule (the set exists only while the root's turn is open) is documented at the field.
The set needs no size cap: it is deleted at every root done, and Droid caps how many descendants a root can have active (maxActiveDescendantsPerRoot in the Droid 0.217.0 binary).
A worker that is still running after the root's Stop, or one that starts after it (including a nested Task), is not tracked. It reports as the root, the same as on main: working, waiting, then done at its own Stop. So an idle pane can't be left on working.
Why
Droid sends transcript_path on every hook, and the worker's first transcript record names its caller. That is enough to spot a worker the first time it shows up. Remembering it means its later hooks skip the transcript read. Dropping only the turn-boundary hooks keeps the worker's tool and approval activity visible.
Alternatives considered: dropping every known-worker hook once the row is done hid a background worker's approval wait; letting workers create the set on their own left an idle pane stuck on working after a nested Task. Tying the set to the root's open turn avoids both.
N/A. There is no new UI: the fix only changes which hooks move the terminal agent row's state, and no live Droid auth was available to record a Task run. The proof is the hook-normalization tests below, which replay the hook sequence Droid sends.
Testing
I manually tested these changes locally (not possible: no Droid auth for a live Task run)
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
src/shared/agent-hook-listener/providers/droid/droid-subagent-hooks.test.ts runs normalizeHookPayload and commits each row with upsertBoundedAgentHookStatus, so the root row is in lastStatusByPaneKey as in production. Reproduced on main: a worker's Stop gives {"state":"done","providerSession":"root-1","prompt":""} while the root is still working, and the cached prompt is wiped by the worker's SessionStart. The five cases:
A worker's SessionStart, UserPromptSubmit, idle Notification and Stop give no row. Its PostToolUse (even without transcript_path) keeps working/go on root-1. The root's Stop gives done. (Fails on main.)
A new root session (root-2) takes over the pane.
A background worker that outlives the root's turn reports as the root: waiting, working, waiting, working, done. (Fails on main.)
Background workers after the root's Stop (worker A's full turn, a second prompt on A, a nested Task B, then A's PostToolUse and Stop) end at done on root-1. This guards against an idle pane being left on working.
A lone sub-session with no root row still reports working, then done.
Also run on macOS: vitest on src/shared/agent-hook-listener, src/main/agent-hooks and src/shared/agent-status (20 files, 60 pass, 1 skipped); oxlint, oxfmt, the anti-slop, code-quality native plugins and ast-grep gates, the changed-code quality gate (0 findings), and typecheck:node. The logic is platform-independent (in-memory maps, no paths beyond the existing transcript read).
Performance
This runs in main-process hook ingest, once per Droid hook. Measured with a scratch vitest bench (normalizeHookPayload + upsert, 2000 turns x3 runs x2, us per hook), main vs this PR:
case
main
this PR
root-only turn (UPS, 20 PostToolUse, Stop)
4.18-4.95
4.17-4.99
root turn with a worker (SessionStart, UPS, 20 PostToolUse, Stop)
21.7-22.5
4.56-4.85
background worker PostToolUse after the root's Stop
21.0-22.3
20.7-21.4
A known worker's hooks get about 4.5x cheaper because they skip the sync transcript read. The typical root-only path is unchanged, and an untracked background worker costs the same as on main. The change adds one Map.set per root UserPromptSubmit and one Map.delete per root done. No new I/O, polling, timers or subprocesses, and no stall close to 16 ms.
Risk
Level: Low
The riskiest part is dropping a worker's Stop: if a worker were wrongly treated as such, the row could stay on working until the root's next done. The set only exists between the root's own UserPromptSubmit and its done, which bounds that.
Known limitations, unchanged from main:
A background worker from a previous turn is untracked. If it is still running during the next root turn, its Stop can settle that turn's row early.
With several background workers after the root's turn, the first one's Stop shows done while another is still working. That worker's next hook flips the row back to working.
The state lives in memory in HookListenerState. The SSH relay has its own instance, so an older relay just keeps main's behavior. Back it out with a plain revert.
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
Original fix by @2SinceJuly in #47836; the maintainer rework keeps their Co-authored-by credit.
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)
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.
The change tracks Droid worker sessions by pane and retains the pane owner when worker hooks identify a different session. Droid event normalization ignores selected worker events and clears tracked worker sessions when a non-worker event resolves to done. The shared child-session map now supports both DSH and Droid child sessions. Tests cover root and worker hook sequences, new root sessions, and sub-sessions without a root status row.
Severity of issue fixed: Medium
Merge Risk: Moderate · up to af98c
Droid subagent hooks can still mislabel or prematurely settle a pane's main-session row in some edge cases, such as a worker surviving the root's Stop or a refused prompt resetting worker tracking. The core open-turn case is handled, but these gaps should be resolved or accepted before merge.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the fix (droid) and the core behavior: a Task worker's hooks no longer change the pane's agent row. It is specific and matches the changeset, which keeps worker SessionStart, UserPromp…
Description check
The description follows the repository template closely. It has ELI5, What Changed, Why, Linked Issue (Fixes #47826), Visual Proof (N/A with reason), Testing with specific tests, Performance with meas…
Linked Issues check
[#47826] The issue requires that Droid Task subagent hooks not end or reset the main session row during the main turn. The PR addresses this at the reviewed head. droid-worker-sessions.ts keeps a per-…
Out of Scope Changes check
Each changed file supports the #47826 fix. droid-worker-sessions.ts (new, no fs) holds the worker-set lifecycle. droid-events.ts applies the worker filter and forgets workers on the root's done. pane-…
Full details: Title check
Explanation
The title names the fix (droid) and the core behavior: a Task worker's hooks no longer change the pane's agent row. It is specific and matches the changeset, which keeps worker SessionStart, UserPromptSubmit, and done hooks from altering the root row. Its length (63 characters, 11 words) is within reason.
Full details: Description check
Explanation
The description follows the repository template closely. It has ELI5, What Changed, Why, Linked Issue (Fixes #47826), Visual Proof (N/A with reason), Testing with specific tests, Performance with measurements, Risk with level and revert plan, AI Disclosure, the upstream boundary checkbox, and a checklist. The 'Review' and 'Notes' template headings are omitted, and the Testing checkboxes are ticked without a manual local test being described. These are minor gaps.
Full details: Linked Issues check
Explanation
[#47826] The issue requires that Droid Task subagent hooks not end or reset the main session row during the main turn. The PR addresses this at the reviewed head. droid-worker-sessions.ts keeps a per-pane worker set in state.childSessionIdsByPaneKey. openDroidRootTurn creates the set on the root's UserPromptSubmit. rememberDroidWorkerSession adds IDs only while the set exists. forgetDroidWorkerSessions deletes it on the root's done. droid-events.ts drops a known worker's SessionStart, UserPromptSubmit, and done (Stop or idle Notification). Its PreToolUse, PostToolUse, and approval Notification still update the root row as working or waiting. pane-provider-session.ts checks the worker set before the transcript read, so a known worker hook without transcript_path still maps to the owner row. This covers the reported bug: a subagent Stop during the root turn no longer sets done, and a subagent SessionStart no longer clears the main turn state. The tests in droid-subagent-hooks.test.ts cover these cases at hook-normalization level. Residual gaps, all disclosed by the PR: (1) a worker that outlives the root's Stop is untracked and reports as the root, so a prior-turn worker can settle a later turn early; (2) with several background workers after the root Stop, the first Stop can show done while another worker runs. These fall outside the main-turn behavior the issue asks for, and the PR documents them as scope limits. The evidence is hook-level tests, not a live Droid run. The current description no longer claims a 16-worker cap, so the previous unverified cap claim does not apply.
Full details: Out of Scope Changes check
Explanation
Each changed file supports the #47826 fix. droid-worker-sessions.ts (new, no fs) holds the worker-set lifecycle. droid-events.ts applies the worker filter and forgets workers on the root's done. pane-provider-session.ts checks the worker set first and opens the root turn on UserPromptSubmit. listener-state.ts and dsh-events.ts rename dshChildSessionIdsByPaneKey to childSessionIdsByPaneKey. The shared map lets Droid reuse the existing pane clear, move, and clear-all cleanup, and the PR states that a separate map would exceed the max-lines limit in listener-state.ts. droid-subagent-hooks.test.ts holds the supporting tests. The ratchet baseline change follows from the code change. No unrelated behavior was found in the reviewed summary and changed files.
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; 8 remain after this review.
1. A known worker keeps the owner row with no transcript.isDroidSubSession needs the transcript's first record, so a later hook from the same worker — which carries no transcript_path — fell through to the worker's own session. The registry is now checked before the transcript, so an already-remembered worker returns the owner's session and never repoints the row.
2. A session that names itself is not a worker. The old test compared the transcript's caller against the pane owner. When the caller was the owner itself, a fixture with callingSessionId === 'root-1' and session_id: 'worker-1' compared equal and was not classified as a worker. The check now compares the caller against the hook's own session_id: an orchestrator's record names itself, a worker's names the session that spawned it.
Two tests cover both, and both fail on the prior implementation (verified by reverting the source only): the row keeps root-1 when a transcript-less worker hook arrives, and a self-naming transcript is still treated as the orchestrator.
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 · Register a worker before its first hook can replace the pane… · pane-provider-session.ts:89-100
src/shared/agent-hook-listener/pane-provider-session.ts:89-100 Major · Functional Correctness · Heavy lift
Register a worker before its first hook can replace the pane owner.
For a Droid worker whose first hook has no readable transcript, the hook falls through to its own providerSession. If the event is admitted, the worker session becomes the cached pane owner, and the worker is not added to the worker registry.
After that, pane-provider-session.ts skips worker detection when owner?.id === providerSession.id. A later worker Stop with a readable transcript that names the main session is then not dropped by normalizeDroidEvent. The main row can show done while the main session is still working. The main session may emit no further hooks while it waits for the worker, so the wrong state can persist for the worker's run.
The owner must not stay bound to a worker session that the registry does not know. The fix must make the worker's Stop suppressible on this path. The choice between registering on the first hook and refusing that owner replacement is open.
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: 4306c501-f9e7-48b8-bbdc-07aef9478ece
Commits
Reviewing files that changed from the base of the PR and between 2bffba4 and 740b0b6.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Major · Functional Correctness · Heavy lift
Keep worker identity across root-turn completion.
If a background worker survives the root's Stop, this deletion forgets its identity. If the root submits another prompt before the worker sends Stop, the late worker hook can settle the new root turn.
Even with a readable worker transcript, rememberDroidWorkerSession cannot recreate an absent set for Stop. fromWorker is therefore false, and this function returns done for the root session.
Retain worker identity separately from main-turn activity. Allow the intended background activity after root completion, but prevent that worker from ending a later main turn.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Do not evict a worker that can still send transcriptless hooks.
If worker-1 stays in the background while 16 other workers start, this eviction removes worker-1. Worker completion does not remove the other IDs individually.
If worker-1 then sends Stop without transcript_path, the listener cannot recognize it. The hook returns done with worker-1 as the pane session. The existing transcriptless-hook test establishes that later hooks need not include a transcript.
Preserve worker attribution for every worker that can still emit hooks. Do not depend on a transcript to recover an evicted ID.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Stability & Availability · Quick win
Open the Droid root turn only after the hook passes admission.
normalizeHookPayload runs readPaneSessionContext before the refusal checks. Through readPaneProviderSession, a non-worker UserPromptSubmit calls openDroidRootTurn at pane-provider-session.ts:95-96. That call replaces the pane's worker set with an empty set, so workers remembered earlier are forgotten. The hook can still be refused later by readHookProcessAdmission or isInheritedHookStatus, for example when a new worker's prompt arrives with a foreign process. Refused hooks must not change child-session state. After a refusal, workers remembered earlier lose their classification, and their later turn-boundary hooks are no longer ignored by the registry check.
Move the root-turn reset so it runs only for an admitted UserPromptSubmit. The admission outcome is decided in normalize-hook-payload.ts, after readPaneSessionContext returns, so the reset must move out of readPaneProviderSession.
A Droid Task worker sends its own SessionStart, UserPromptSubmit and Stop
hooks under its own session_id. Each Stop settled the pane's row to done
while the root was still working, and each SessionStart wiped the root's
cached prompt.
The root's UserPromptSubmit now opens a per-pane worker set. While that
turn is open, a hook from a sub-session (first transcript record has
callingSessionId) is remembered as a worker; its SessionStart,
UserPromptSubmit and done (Stop or idle Notification) are dropped, while
its tool and approval hooks still count toward the root's row. The root's
done deletes the set, so a background worker that outlives the root turn
reports as the root, as before, and settles the row with its own Stop.
The DSH child-session map is renamed to childSessionIdsByPaneKey and
shared, so the existing pane clear, move and clear-all paths cover Droid.
Fixesstablyai#47826
Co-authored-by: 2SinceJuly <[email protected]>
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Add a self-naming root transcript case to the new-root test.
The new-root fixture at line 113 sets only id: 'root-2'. No test sets callingSessionId to the same value as the hook's own session_id. The PR's self-naming correction therefore has no test. A regression could classify the new root as a worker and suppress its prompt without failing the suite.
Add a separate case. Start with root-1 owning the pane. Then submit a transcript for root-2 with both id and callingSessionId set to root-2. Assert that the returned and cached rows use root-2. Then assert that the Stop for root-2 produces done. Keep the existing ordinary-root case.
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
Droid can hand part of a job to a helper (a "Task" subagent). The helper sends Orca its own "starting", "prompt" and "stopped" hooks under its own session id. Orca treated those as the main session's, so the pane's agent row went done while the main session was still working, and the helper's start wiped the main session's prompt from the row.
What Changed
Before: run Droid in an Orca terminal and have it launch a Task subagent while it keeps working. When the subagent stops, the pane's row shows done while the main session is still running. The subagent's start also clears the prompt the row was showing.
After: while the main session's turn is open, the row follows the main session only. A worker's
SessionStart,UserPromptSubmit,Stopand idleNotificationno longer start, reset or settle the row. Its tool and approval hooks still count, so the row shows working or waiting for the main session's turn.Mechanism:
pane-provider-session.ts: a hook whose transcript's first record has acallingSessionIdalready kept the pane's root provider session. The remembered worker set is now checked first, which skips the sync transcript read for a known worker. The root's ownUserPromptSubmitopens the turn by setting a fresh, empty worker set for the pane.droid-worker-sessions.ts(new, no fs): a worker is remembered only while that set exists, that is, while the root's turn is open, and only when a Droid root row owns the pane.droid-events.ts: drops a known worker'sSessionStartandUserPromptSubmit, and itsdone(Stopor idleNotification). The root's owndonedeletes the pane's set.listener-state.ts/dsh-events.ts:dshChildSessionIdsByPaneKeyis renamed tochildSessionIdsByPaneKeyand shared, so the existing pane clear, move and clear-all cleanup covers Droid too. The Droid rule (the set exists only while the root's turn is open) is documented at the field.The set needs no size cap: it is deleted at every root
done, and Droid caps how many descendants a root can have active (maxActiveDescendantsPerRootin the Droid 0.217.0 binary).A worker that is still running after the root's
Stop, or one that starts after it (including a nested Task), is not tracked. It reports as the root, the same as on main: working, waiting, then done at its ownStop. So an idle pane can't be left on working.Why
Droid sends
transcript_pathon every hook, and the worker's first transcript record names its caller. That is enough to spot a worker the first time it shows up. Remembering it means its later hooks skip the transcript read. Dropping only the turn-boundary hooks keeps the worker's tool and approval activity visible.Alternatives considered: dropping every known-worker hook once the row is
donehid a background worker's approval wait; letting workers create the set on their own left an idle pane stuck onworkingafter a nested Task. Tying the set to the root's open turn avoids both.Linked Issue
Fixes #47826
Visual Proof
N/A. There is no new UI: the fix only changes which hooks move the terminal agent row's state, and no live Droid auth was available to record a Task run. The proof is the hook-normalization tests below, which replay the hook sequence Droid sends.
Testing
src/shared/agent-hook-listener/providers/droid/droid-subagent-hooks.test.tsrunsnormalizeHookPayloadand commits each row withupsertBoundedAgentHookStatus, so the root row is inlastStatusByPaneKeyas in production. Reproduced on main: a worker's Stop gives{"state":"done","providerSession":"root-1","prompt":""}while the root is still working, and the cached prompt is wiped by the worker's SessionStart. The five cases:transcript_path) keepsworking/goonroot-1. The root's Stop givesdone. (Fails on main.)root-2) takes over the pane.doneonroot-1. This guards against an idle pane being left onworking.Also run on macOS: vitest on
src/shared/agent-hook-listener,src/main/agent-hooksandsrc/shared/agent-status(20 files, 60 pass, 1 skipped); oxlint, oxfmt, the anti-slop, code-quality native plugins and ast-grep gates, the changed-code quality gate (0 findings), andtypecheck:node. The logic is platform-independent (in-memory maps, no paths beyond the existing transcript read).Performance
This runs in main-process hook ingest, once per Droid hook. Measured with a scratch vitest bench (
normalizeHookPayload+ upsert, 2000 turns x3 runs x2, us per hook), main vs this PR:A known worker's hooks get about 4.5x cheaper because they skip the sync transcript read. The typical root-only path is unchanged, and an untracked background worker costs the same as on main. The change adds one
Map.setper root UserPromptSubmit and oneMap.deleteper rootdone. No new I/O, polling, timers or subprocesses, and no stall close to 16 ms.Risk
Level: Low
The riskiest part is dropping a worker's
Stop: if a worker were wrongly treated as such, the row could stay on working until the root's nextdone. The set only exists between the root's own UserPromptSubmit and itsdone, which bounds that.Known limitations, unchanged from main:
The state lives in memory in
HookListenerState. The SSH relay has its own instance, so an older relay just keeps main's behavior. Back it out with a plain revert.Agent skill upstream boundary
Notes
Original fix by @2SinceJuly in #47836; the maintainer rework keeps their Co-authored-by credit.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)