Skip to content

fix(cli): answer subagent permission asks in headless run (#35073) - #35823

Closed
IsaVonxz-type wants to merge 7 commits into
anomalyco:devfrom
IsaVonxz-type:fix/subagent-permission-hang
Closed

fix(cli): answer subagent permission asks in headless run (#35073)#35823
IsaVonxz-type wants to merge 7 commits into
anomalyco:devfrom
IsaVonxz-type:fix/subagent-permission-hang

Conversation

@IsaVonxz-type

Copy link
Copy Markdown

Issue for this PR

Closes#35073

Type of change

  • Bug fix

What does this PR do?

Sync subagents (spawned by the task tool without background) run in their own child session with no human attached. In headless opencode run, the event responder only replied to permission asks whose sessionID matched the top-level session (if (permission.sessionID !== sessionID) continue). When a subagent hit a tool with permission set to ask, its ask was dropped and the Deferred in the permission service was never resolved, so the subagent hung forever.

This walks the parentID chain of the asking session (new isSessionInTree helper, the same lineage approach the app's permission-auto-respond already uses) and answers asks from any descendant session with the same policy as the top-level one: reply once under --auto, otherwise reject so the subagent fails closed instead of hanging. Only the headless responder changes — the TUI/desktop already surface subagent asks to the user, so no server-side behavior is touched.

How did you verify your code works?

  • Added test/cli/run/session-tree.test.ts covering the lineage check: self, direct child, nested descendant, unrelated tree, ancestor, and a cyclic parent chain.
  • bun test test/cli/run/ — 199 pass, 0 fail.
  • bun run typecheck (packages/opencode) — clean.
  • prettier --check and oxlint on the changed files — clean.

Screenshots / recordings

N/A — no UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Sync/background subagents run in their own child session with no human
attached. The headless `opencode run` responder only replied to asks whose
sessionID matched the top-level session, so a subagent that hit a tool with
permission set to "ask" hung forever waiting for a reply that never came.
Recognize asks from any descendant session by walking the parentID chain
(new isSessionInTree helper) and answer them with the same policy as the
top-level session: reply "once" under --auto, otherwise reject so the
subagent fails closed instead of hanging. Scoped to the headless responder;
the TUI/desktop already surface subagent asks via lineage.
Closesanomalyco#35073
@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: subagent permission asks hang indefinitely (sync subagents treated as interactive)

1 participant

@IsaVonxz-type