Skip to content

fix(core): merge session permissions into subagent descriptions - #56979

Open
mengwEX wants to merge 2 commits into
anomalyco:devfrom
mengwEX:subagent-session-permissions
Open

mengwEX wants to merge 2 commits into
anomalyco:devfrom
mengwEX:subagent-session-permissions

Conversation

@mengwEX

@mengwEX mengwEX commented Oct 19, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #48106

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Merge the current session's permissions into the V2 subagent description filter, matching tool discovery and execution. Session-denied targets disappear from the advertised list; session allow/ask overrides make targets visible.

This replaces the legacy implementation in #48107, whose target package was removed. The change applies to the shared context, compaction, and generate hook.

How did you verify your code works?

Using Bun 1.4.2:

  • Core: bun run script/test.ts test/tool-subagent.test.ts test/permission.test.ts test/session-create.test.ts — 165 pass. The four description-only session-override cases fail on the unmodified base and pass with this fix.
  • tool-subagent.test.ts --rerun-each 10 — 150 pass.
  • bun run check — lint and all 34 typecheck tasks pass.
  • Full Core suite on macOS before the test-only reduction: 6653 pass, 43 skip, 8 fail. Seven Shell failures reproduce on the untouched base with macOS Bash 3.2; the .hg/branch watcher failure passes in isolation on both trees.

Screenshots / recordings

No UI changes.

Checklist

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

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@opencode-agent opencode-agent 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.

The fix looks right. With your test file on the base, the four session-override cases fail; with this change all 17 tests in tool-subagent.test.ts pass. permission.test.ts and session-create.test.ts also pass, and the core typecheck is clean. Combining the rules with Permission.merge(selected.permissions, session.permissions ?? []) matches how SessionContext.select already narrows tool discovery, so the list of subagents now matches what the session can actually call.

Public API: unchanged.

One request: the new test is large for a 4-line fix (see the inline comment).

expect(tool).toBeDefined()
expect(tool?.description?.includes("- reviewer:")).toBe(item.visible)
}
const result = yield* permissions.ask({

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.

This part checks things that already worked before this change: the permissions.ask result, and that running a denied subagent is rejected and creates no child session. The fix is only about the description. Could you cut the test down to the description check for the session-override cases? It would shrink a lot and still fail on the base.

This branch has not been deployed

No deployments
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.

Subagent description ignores session permissions

1 participant