Skip to content

fix(opencode): retire a subagent's blocker when the root turn ends - #22604

Merged
nwparker merged 1 commit into
mainfrom
nwparker/opencode2-root-idle-retires-child-blocker
Sep 24, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/opencode2-root-idle-retires-child-blocker

Conversation

@nwparker

@nwparker nwparker commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​24 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​22
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​21 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​20

ELI5

When a subagent asks you a question, Orca shows "needs input" on the pane — correctly, because something really is waiting on you. But if that turn ends without the question being answered, the indicator never went away. Nothing could clear it, and the main agent would tell you it has no question, because the question belonged to a subagent it doesn't know about.

What Changed

clearAttentionForSession matches blockers only by sourceSessionID. A descendant's question is stored under the child's own id but displayed on the root it rolled up to, so the root's own idle never matched it and the blocker survived the turn.

Adds clearAttentionForTurnEnd(sessionID, factoryID), which matches either the source id or the rolled-up root, and uses it from the idle branch only.

Before: root turn ends → last post is still AskUserQuestion; the pane stays blocked.
After: root turn ends → SessionIdle for the root; the pane settles.

Why

This is the mechanism behind #22371, and it reproduces deterministically:

× retires a child raised blocker when the root turn goes idle
  AssertionError: expected 'AskUserQuestion' to be 'SessionIdle'

It matches every fact in that report: the indicator appears (a subagent genuinely did ask), the lead agent truthfully says it has no pending question (the blocker belongs to a child it doesn't know about), and nothing clears it. The reporter's "workaround" of switching Orca tabs worked because unmounting deletes the row wholesale — that's #22445, a separate defect, and it's why this looked like a UI-state bug rather than a lifecycle one.

Why scoped to turn end rather than widening the existing clear. My first attempt widened clearAttentionForSession itself. That broke clears only the matching child reply or rejection and preserves root Busy — because the busy branch also calls it, and a live blocker must outrank the root going Busy: a subagent can be waiting on you while the root keeps working. That failing test is what identified the correct scope, so the narrow variant is deliberate, not incidental.

Alternatives considered:

  • Key the blocker to the root at mint time. Loses the exact child owner needed for precise reply, tool-completion and disposal cleanup — the design keeps both on purpose.
  • Retire on child idle only (today's behaviour). Leaves the blocker stranded whenever a child ends without its own idle event, which is the reported case.

Linked Issue

Fixes #22371

Visual Proof

N/A — and worth stating why, because an earlier attempt at this issue produced a misleading one.

The user-visible change is an indicator disappearing at the end of a turn. A before/after screenshot of the blocked moment is identical in both builds (the indicator correctly appears in both); the difference only shows after the turn ends, where "after" is an absence. I previously captured before/after shots for #22444 that looked identical and correctly concluded they proved nothing — the same trap applies here.

The proof is the hook-post sequence, which is exactly what the pane renders from:

before: … AskUserQuestion   (last post — pane stays blocked)
after:  … AskUserQuestion → SessionIdle { sessionID: ROOT }

Testing

retires a child raised blocker when the root turn goes idle — root starts a turn, a child raises a question form, the root turn succeeds. Asserts the final post is SessionIdle for the root.

Mutation-checked: swapping clearAttentionForTurnEnd back to clearAttentionForSession fails it (both plugin variants), with the last post still AskUserQuestion.

  • pnpm test src/main/opencode src/main/opencode2 src/main/agent-hooks src/main/mimo → 114 files, 1258 passed, 9 skipped
  • pnpm tc clean; pnpm run check:code-quality:changed → 0 findings

Both pinned plugin digests move, including mimo-code's — the ownership source is shared across the OpenCode family, so MiMo Code gets the same fix. That is intended, not collateral: it has the same subagent rollup.

Not verified: that this resolves the reporter's exact frame on their machine. I could not reproduce their original attribution (the Subagents dock emits no events at all — proven earlier with a real TUI capture), so this fixes the mechanism that matches their description, not a reproduction of their session. Worth their confirmation before considering it closed.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Failure direction: the change only ever retires a blocker at turn end. If the match were somehow too broad, a pane would under-report needing input — but the existing busy-path test pins the one case where that would matter, and it still passes untouched.
  • OpenCode 1 takes the same lifecycle source and gets the same fix; there is no v1/v2 split here.
  • SSH/remote and WSL: no wire change. The plugin runs on the execution host, which keeps owning agent status per docs/reference/agent-status-store.md.
  • Related, not fixed here: [Bug]: unmounting a pane deletes a genuine pending agent blocker, not just a stale one #22445 (unmount deletes a genuine pending blocker). That is the other half of why this was hard to see, and it is filed separately.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • 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 pass locally

A descendant's question is stored under its own sourceSessionID but displayed on
the root session it rolls up to. clearAttentionForSession matches only the
source, so the root's own idle could never retire it: the blocker outlived the
turn that raised it and pinned the pane on "needs input" with nothing left to
answer. The lead agent truthfully reports no pending question, because the
blocker belongs to a child it does not know about (#22371).

Add clearAttentionForTurnEnd, matching the source id or the rolled-up root, and
use it only from the idle branch. Scoped to turn end deliberately: a live
blocker must still outrank the root going Busy, since a subagent can be waiting
on the user while the root keeps working — widening the existing clear broke
exactly that test, which is what surfaced the right scope.

Shared with the OpenCode family, so mimo-code gets the same fix; both pinned
plugin digests move.

New test fails without the change: after the root turn ends the last post is
still AskUserQuestion instead of SessionIdle.
@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

📝 Walkthrough

Walkthrough

The generated status lifecycle plugin now calls clearAttentionForTurnEnd in its idle-event branch. The new helper removes matching attention records when the ending session matches either the record’s source session or its displayed session. A test covers a child-raised blocker followed by a successful root session execution. Expected plugin source digests were updated.

Fixed issue severity: <fixed_issue_severity>Low</fixed_issue_severity>

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to f2f86

A child’s question can remain displayed after the root turn ends if lineage lookup fails. Fix the fallback idle path before merging.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: retiring a subagent blocker when the root turn ends.
Description check ✅ Passed The description follows the required template and explains the user impact, mechanism, rationale, linked issue, testing, scope, and compatibility considerations. Minor omissions include no explicit bu…
Linked Issues check ✅ Passed Issue [#22371] reports a stale question indicator after a subagent interaction. The PR adds clearAttentionForTurnEnd, which clears attention owned by the ending session or by a blocker rolled up to …
Out of Scope Changes check ✅ Passed All changed files support issue [#22371]. The ownership and lifecycle changes implement blocker retirement. The new test covers the reported lifecycle. The digest updates keep generated OpenCode plugi…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@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 · Clear displayed-root attention when lineage lookup fails. · status-plugin-lifecycle-source.ts:56

src/main/opencode/status-plugin-lifecycle-source.ts:56
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Clear displayed-root attention when lineage lookup fails.

If a child blocker is displayed on the root and resolveRootSessionID returns null for the root’s idle event, this branch clears only records whose sourceSessionID is the root. The child blocker remains pending, so the pane can stay on “needs input” after the root turn ends. Use clearAttentionForTurnEnd here too; its source-or-displayed-session match preserves exact child cleanup while retiring blockers displayed on the ending root.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 76695dfe-48cd-414b-baa4-881586510467

📥 Commits

Reviewing files that changed from the base of the PR and between b4d7326 and f2f86f5.

📒 Files selected for processing (4)
  • src/main/opencode/hook-plugin-opencode2-session-lineage.test.ts
  • src/main/opencode/hook-service.test.ts
  • src/main/opencode/status-plugin-lifecycle-source.ts
  • src/main/opencode/status-plugin-ownership-source.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

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

ℹ️ Minor suggestions only — one test-comment wording nit; the lifecycle change itself is sound and well-tested.

Reviewed changes

  • Wider attention clear at root turn end — clearAttentionForTurnEnd matches either the blocker's sourceSessionID or the rolled-up display properties.sessionID, so a descendant blocker shown on the root is retired when the root goes idle.
  • Call site scoped to the idle branch — status-plugin-lifecycle-source.ts:117 uses the wider clear; the root-going-Busy path keeps the source-only clear so a live subagent blocker still outranks Busy.
  • Digest updates — hook-service.test.ts digests move for the opencode and mimo-code families, as expected from the shared ownership source.
  • New lineage test — retires a child raised blocker when the root turn goes idle; I mutation-reverted the lifecycle call to clearAttentionForSession and confirmed it fails (expected 'AskUserQuestion' to be 'SessionIdle'), so the test pins real behavior.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏


// Why this case: it is the shape reported in #22371 — a subagent asks, the lead
// agent truthfully reports no pending question, and the pane stays "needs input"
// with nothing able to clear it. With lineage unresolved the blocker keys to the

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.

The With lineage unresolved clause misstates the mechanism. The blocker keys to the child because attentionKey uses the child's sourceSessionID, not because resolution failed — and in the genuinely unresolved case properties.sessionID is also the child, so this fix would not retire it either. Describing it as the source-versus-display id split would avoid implying the unresolved path is covered.

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.

Understood — leaving the comment to track the reported scenario (#22371) rather than the resolved-lineage mechanism this test actually exercises.

Pullfrog  | View workflow run | via Pullfrog | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker

Copy link
Copy Markdown
Contributor Author

Thanks — I chased the outside-diff finding at status-plugin-lifecycle-source.ts:56 properly, and I could not make it reachable, so I'm not taking it. Reasoning, in case I'm wrong:

That branch runs when childState === null, i.e. lineage is unresolvable. For a child blocker to be displayed on the root in the first place, properties.sessionID is set to rootSessionID || sessionID at mint time — so a root-displayed blocker implies a lookup already succeeded, and success is cached by rememberSessionRoot. At the root's idle the cached entry resolves, childState is false, and control goes to the normal idle branch — which already uses clearAttentionForTurnEnd. When the lookup hasn't succeeded, the blocker is minted on the child (rootSessionID is null), so a turn-end match on the root wouldn't find it either.

I tried two ways to reach it and both refuted the concern:

  1. Lookups failing after the blocker is attributed (new harness option, fail after N successes): the root's lineage is cached, so the branch is never entered. Test passed with and without the change — non-discriminating, so I deleted it rather than keep a test that pins nothing.
  2. Forcing cache eviction (130 filler sessions past the 128-entry rememberSessionRoot cap): the entry is evicted, the lookup simply re-runs and succeeds, and the blocker is retired correctly. The final post was SessionBusy — because the filler sessions are running — not a stranded AskUserQuestion.

So the guard would be defence against a state I can't produce. I removed a similar unprovable guard from #22548 after review showed the collision it defended was ruled out by the key structure, and I'd rather stay consistent than carry a second one — especially with a // Why: comment asserting a risk that may not exist.

If you can construct a sequence that reaches that branch with a root-displayed blocker outstanding, I'll take the change immediately — it's a one-line swap and costs nothing at runtime. I just don't want to ship it justified by a scenario I couldn't demonstrate.

The core fix and its test are unchanged and both mutation-verified: reverting clearAttentionForTurnEnd → clearAttentionForSession at the idle branch fails retires a child raised blocker when the root turn goes idle with expected 'AskUserQuestion' to be 'SessionIdle'.

@pullfrog — noted on the test-comment wording nit; leaving it as-is since the comment describes the reported scenario rather than the mechanism, which is what I wanted a future reader to match against.

@nwparker
nwparker merged commit 8ddad49 into main Sep 24, 2026
31 checks passed
@nwparker
nwparker deleted the nwparker/opencode2-root-idle-retires-child-blocker branch September 24, 2026 06:45
@pullfrog

pullfrog Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

I took the invitation to construct it, and the branch is reachable. The one-premise-of-the-argument that breaks is "success is cached by rememberSessionRoot" — the cache is bounded and a live blocker does not pin its root.

rootSessionById evicts its oldest key once it holds 128 entries (rememberSessionRoot), and nothing keeps a root that owns a pending blocker resident. A long-lived process resolves more than 128 sessions, so the root's mapping can be gone by the time its idle arrives. If that idle's re-lookup then fails — exactly the SDK outage the fallback branch exists to handle — childState is null, and the source-only clearAttentionForSession cannot match a blocker displayed on the root. The busier the session, the more likely the mapping is already evicted.

I reproduced it end to end: mint the child's blocker on the root, insert 130 session.created events to evict the root from the 128-entry cache, then fail the root lookup at idle. Observed on the unknown-lineage idle:

  • with clearAttentionForSession — the form-child blocker stays pending, desired status stays waiting/AskUserQuestion, last post SessionStart
  • with clearAttentionForTurnEnd — pending map empty, desired/delivered idle:ses_root → SessionIdle { sessionID: ROOT }
  • mutation check: reverting the swap fails the new test with expected 'SessionStart' to be 'SessionIdle', for both plugin families.

So it is not defence against an unreachable state — it closes the one path where the cache-only assumption breaks under the SDK outage this branch is for.

Opened #22615 with the one-line swap and a regression test (retires a root displayed child blocker when the root idle cannot resolve lineage). The childState === null && Busy branch keeps the source-only clear, so the scope you chose there is untouched.

Pullfrog  | View workflow run | via Pullfrog | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

flosrn pushed a commit to flosrn/orca that referenced this pull request Sep 25, 2026
…tablyai#22604)

A descendant's question is stored under its own sourceSessionID but displayed on
the root session it rolls up to. clearAttentionForSession matches only the
source, so the root's own idle could never retire it: the blocker outlived the
turn that raised it and pinned the pane on "needs input" with nothing left to
answer. The lead agent truthfully reports no pending question, because the
blocker belongs to a child it does not know about (stablyai#22371).

Add clearAttentionForTurnEnd, matching the source id or the rolled-up root, and
use it only from the idle branch. Scoped to turn end deliberately: a live
blocker must still outrank the root going Busy, since a subagent can be waiting
on the user while the root keeps working — widening the existing clear broke
exactly that test, which is what surfaced the right scope.

Shared with the OpenCode family, so mimo-code gets the same fix; both pinned
plugin digests move.

New test fails without the change: after the root turn ends the last post is
still AskUserQuestion instead of SessionIdle.

(cherry picked from commit 8ddad49)
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.

[Bug] Orca incorrectly categorizes opencode2's subagent menu as a "question"

1 participant