Skip to content

fix(opencode): track background subagent activity - #9750

Closed
bbingz wants to merge 1 commit into
stablyai:mainfrom
bbingz:bbingz/fix-9692-opencode-background-subagents
Closed

bbingz wants to merge 1 commit into
stablyai:mainfrom
bbingz:bbingz/fix-9692-opencode-background-subagents

Conversation

@bbingz

@bbingz bbingz commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Track active OpenCode child sessions by parent session.
  • Keep the parent session busy while any background child is still busy or retrying.
  • Ignore child-only lifecycle events and synthetic message parts so they do not leak into parent status or text activity.

Fixes #9692

Relationship to #11017

#11017 (54ed8c231, merged 2026-07-28) hardened OpenCode lifecycle status delivery in src/main/opencode/hook-service.ts and added the lifecycle-delivery, child-attention, fail-open-ownership, and message-part-throttle suites. This branch is rebased on top of it and extends those same suites.

Issue #9692 stayed open because that work does not roll a background child's busy or retrying state up to its parent: the parent still reads idle while a subagent is running. This PR adds the missing activeChildByKey rollup that keeps the parent busy for the lifetime of any active child, plus the part.synthetic message-part filter that stops a synthetic text part overwriting a real preview.

Screenshots

No visual change.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Focused verification passed: 33 OpenCode hook/plugin tests, changed-file oxlint/format/max-lines checks, and pnpm run build:desktop. The full repository test command was not run; the changed behaviour is covered by the focused suites.

AI Review Report

An independent AI reviewer returned spec-compliance PASS and code-quality APPROVED with no confirmed findings. It traced the complete child busy/retry/idle/error sequence, parent-id bookkeeping, root-idle suppression, synthetic-part filtering, cleanup, and regression coverage.

The review explicitly checked cross-platform compatibility for macOS, Linux, and Windows. This change is platform-neutral event bookkeeping and does not alter shortcuts, labels, filesystem paths, shell behaviour, or Electron platform branches.

Security Audit

Reviewed event parsing, session-id ownership, map/set cleanup, and untrusted synthetic-part handling. The change executes no commands, opens no paths, changes no authentication or IPC boundary, adds no dependency, and stores only transient session identifiers in memory.

Notes

The implementation intentionally does not emit child lifecycle events as independent Orca session state. Child activity contributes only to its parent session's busy/idle decision.

ELI5

OpenCode parent sessions looked idle while background subagents were still working. The parent now stays busy until its child sessions finish, so wait/idle automation does not fire early.

@coderabbitai

coderabbitai Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The OpenCode hook plugin now resolves parent sessions and tracks active child sessions to route busy, idle, and error events. Parent idle transitions are suppressed while child sessions remain active and emitted after children reach terminal states. Synthetic text message.part.updated events are ignored when real previews exist. Tests cover session hierarchy setup, child lifecycle ordering, source generation, and synthetic preview filtering.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes match #9692 by tracking active child sessions, suppressing synthetic parts, and covering the busy/idle regression flow.
Out of Scope Changes check ✅ Passed The modified code and tests stay focused on OpenCode child-session tracking and synthetic-part handling, with no unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly and concisely describes the main change: tracking background OpenCode subagent activity.
Description check ✅ Passed The description covers the required sections, behavior, testing status, AI review, security audit, and platform compatibility.

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 platform limitations.

⚠️ Outside diff range comments (1)
src/main/opencode/hook-service.ts (1)

302-329: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Blanket early-return for resolved-parent events silently drops permission.asked/question.asked from children, and drops all events (not just idle) on a transient parent-lookup failure.

Two related gaps in this gate:

  1. When parentSessionID is truthy (confirmed child), the code returns unconditionally at line 328 before ever reaching the permission.asked/question.asked handlers (lines 331-349). If a background subagent needs permission approval or asks the user a question, that request is silently dropped — the user is never notified, so the child (and therefore the parent, via hasActiveChildren) can hang indefinitely waiting on a response that will never be surfaced. This goes beyond the PR's stated intent of ignoring only "child-only lifecycle events and synthetic message parts."
  2. When getParentSessionID fails (network/SDK hiccup) for a root session, parentSessionID === undefined triggers an early return for that entire event — not just idle/error handling. If this happens to be the session's final session.idle, the pane can get stuck "busy" forever, since lookup failures aren't cached and no later event will necessarily re-trigger the transition. Fail-closed makes sense for idle/done transitions specifically (to avoid false completion), but doesn't need to suppress SessionBusy/MessagePart/permission events too.

Consider narrowing the early return so it only affects the idle/error/status-transition logic, and let permission.asked/question.asked bubble through even for child sessions (e.g., tagged with the parent context) instead of being dropped outright.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5e9a5e2e-9666-481e-a64f-f8182202169e

📥 Commits

Reviewing files that changed from the base of the PR and between 827cd49 and 582c5f1.

📒 Files selected for processing (3)
  • src/main/opencode/hook-plugin-message-part-throttle.test.ts
  • src/main/opencode/hook-service.test.ts
  • src/main/opencode/hook-service.ts

@bbingz

bbingz commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Ready for first review — fixes #9692 (OpenCode background subagent activity keeps parent busy).

MERGEABLE on current main.

@nwparker nwparker added the bug Something isn't working label Jul 27, 2026
@bbingz

bbingz commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded by current main.

Evidence on origin/main src/main/opencode/hook-service.ts (and tests):

  • busyRootOwnerBySessionID + parentID chain resolution for child sessions
  • Comments/tests covering “filters child sessions via parentID lookup before forwarding events”
  • Child completions must not flip the root pane to done

That is the same class of fix this PR landed (track background subagents). Keeping a parallel open PR would only create rebase noise.

@bbingz

bbingz commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by main openCode parentID/child-session tracking (see prior comment).

@bbingz bbingz closed this Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: OpenCode background subagents mark the parent task complete and replace its preview

3 participants