Repository navigation
fix(cli): stop read-only agent bash denies from blocking delegated subagents #12373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
c24e76b
72fe8e6
54396ce
e36dce1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@kilocode/cli": patch | ||
| "kilo-code": patch | ||
| --- | ||
|
|
||
| Fix subagent permission errors that referenced phantom deny rules and blocked commands the subagent's own config explicitly allowed. A read-only or delegating agent's `readOnlyBash` allowlist is no longer projected onto a writable subagent as a bash ceiling, so a delegated subagent can run its own allowed commands (e.g. `git status`). Edit, notebook, and MCP denials are still inherited as hard ceilings. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,9 +49,20 @@ export namespace KiloTask { | |
| * overriding the selected subagent's own allowlist with parent ask/allow rules. | ||
| * | ||
| * OpenCode removed parent-agent inheritance entirely in anomalyco/opencode#31696. | ||
| * Kilo intentionally differs: parent denials remain hard ceilings for Plan Mode | ||
| * and MCP restrictions, while parent ask/allow rules must not replace the | ||
| * selected subagent's policy. Preserve this distinction during upstream merges. | ||
| * Kilo intentionally differs: parent edit/notebook/MCP denials remain hard ceilings | ||
| * for Plan Mode and MCP restrictions, while parent ask/allow rules must not replace | ||
| * the selected subagent's policy. Preserve this distinction during upstream merges. | ||
| * | ||
| * Broad bash denies are deliberately NOT inherited from the calling agent. A read-only/delegating | ||
| * agent (plan, ask, orchestrator) carries a `readOnlyBash` allowlist whose deny rules | ||
| * (`*`, `git *`, shell-operator guards) exist only to shape that allowlist. Projecting | ||
| * those denies onto a writable subagent capped commands the subagent's own config | ||
| * explicitly allows (e.g. `git status`), surfacing phantom deny rules the user never | ||
| * wrote (#11523). The subagent's own bash policy governs its bash capabilities; an | ||
| * explicit session-scoped bash lockdown (sandbox / session deny) still reaches the | ||
| * child via `deriveSubagentSessionPermission`, which inherits session deny rules. Plan's | ||
| * concrete destructive-command denies remain ceilings so its built-in Explore delegation | ||
| * cannot bypass the read-only boundary. | ||
| * | ||
| * The caller must resolve `caller` (Agent.Info) and `session` (Session.Info) | ||
| * before calling. This function is pure/synchronous. | ||
|
|
@@ -64,14 +75,21 @@ export namespace KiloTask { | |
| const rules = Permission.merge(input.caller.permission ?? [], input.session.permission ?? []) | ||
| const prefixes = Object.keys(input.mcp ?? {}).map((k) => k.replace(/[^a-zA-Z0-9_-]/g, "_") + "_") | ||
| const isMcp = (p: string) => prefixes.some((prefix) => p.startsWith(prefix)) | ||
| const mutation = new Set(["edit", "bash", "notebook_edit", "notebook_execute"]) | ||
| // `bash` is intentionally excluded — see the doc comment above (#11523). | ||
| const mutation = new Set(["edit", "notebook_edit", "notebook_execute"]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing bash here may cause side effects in plan mode when under default permissions. Can you address the issue below? [P1] Preserve Plan Mode’s read-only boundary for built-in Explore Removing bash from the inherited ceilings globally makes the default Plan→Explore path writable. Plan can delegate to explore without asking, and the built-in Explore agent declares bash: "allow". On the merged tree, both rm -rf and git push resolve to allow for Plan→Explore; before this change they were denied. This allows Plan Mode to implement changes through shell commands even though its edit ceiling remains intact, recreating the Plan Mode mutation behavior users have reported. Please retain the intended fix for custom writable subagents, but give built-in Explore an enforcement-level read-only bash policy instead of blanket bash access. Regression coverage should prove that Plan→Explore denies mutating commands, still allows read-only commands such as git status and rg, and Plan→custom writable subagent continues honoring the child’s own allowlist. If reusing readOnlyBash, please also verify that gh *: ask cannot stall delegated execution and decide whether Explore should retain find support. |
||
| const inherited = rules.filter( | ||
| (r: Permission.Rule) => r.action === "deny" && (mutation.has(r.permission) || isMcp(r.permission)), | ||
| ) | ||
| for (const permission of mutation) { | ||
| if (Permission.evaluate(permission, "*", rules).action !== "deny") continue | ||
| inherited.push({ permission, pattern: "*", action: "deny" }) | ||
| } | ||
| if (input.caller.name === "plan") { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WARNING: The two hardcoded patterns only partially restore the read-only boundary the doc comment claims to hold. Plan→Explore (built-in Explore declares Additionally, gating on Consider deriving the ceiling from the caller's evaluated bash policy rather than a two-entry literal list — e.g. giving built-in Explore an enforcement-level read-only bash policy as the earlier review suggested — or at minimum extend coverage and add regression tests proving Plan→Explore denies mutating commands while allowing read-only ones. Reply with |
||
| for (const pattern of ["rm -rf *", "git push*"]) { | ||
| if (Permission.evaluate("bash", pattern, rules).action !== "deny") continue | ||
| inherited.push({ permission: "bash", pattern, action: "deny" }) | ||
| } | ||
| } | ||
| return merge(inherited) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -159,8 +159,9 @@ it.effect("subagent inherits parent session deny rules as hard runtime ceilings" | |
| }), | ||
| ) | ||
|
|
||
| // kilocode_change start - preserve Plan mutation ceilings across Kilo task delegation | ||
| it.instance("Plan delegation preserves notebook and process mutation ceilings", () => | ||
| // kilocode_change start - preserve Plan edit/notebook ceilings across Kilo task delegation, | ||
| // but do NOT project the caller's read-only bash allowlist onto a writable subagent (#11523) | ||
| it.instance("Plan delegation preserves notebook mutation ceilings", () => | ||
| Effect.gen(function* () { | ||
| const caller = yield* Agent.use.get("plan") | ||
| expect(caller).toBeDefined() | ||
|
|
@@ -172,7 +173,49 @@ it.instance("Plan delegation preserves notebook and process mutation ceilings", | |
|
|
||
| expect(Permission.evaluate("notebook_edit", "notebook.ipynb", rules).action).toBe("deny") | ||
| expect(Permission.evaluate("notebook_execute", "notebook.ipynb", rules).action).toBe("deny") | ||
| expect(Permission.evaluate("bash", "bun run server.ts", rules).action).toBe("deny") | ||
| // The caller's own readOnlyBash denies are no longer inherited as subagent ceilings; | ||
| // the subagent's own bash policy governs its bash capabilities (#11523). | ||
| expect(rules.some((rule) => rule.permission === "bash" && rule.action === "deny")).toBe(false) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CRITICAL: This assertion now fails against the PR's own HEAD commit. The second commit ( The test suite was not updated alongside the second commit. Please update this test to expect the two plan-specific ceilings (e.g. assert the exact inherited set), and consider adding the positive Plan→Explore regression coverage the earlier review requested: mutating commands denied, read-only commands like Reply with |
||
| }), | ||
| ) | ||
|
|
||
| it.instance( | ||
| "read-only caller does not cap a writable subagent's own bash allowlist", | ||
| () => | ||
| Effect.gen(function* () { | ||
| const caller = yield* Agent.use.get("plan") | ||
| const worker = yield* Agent.use.get("git_worker") | ||
| expect(caller).toBeDefined() | ||
| expect(worker).toBeDefined() | ||
|
|
||
| const rules = KiloTask.inherited({ | ||
| caller: caller!, | ||
| session: { permission: [] } as unknown as Parameters<typeof KiloTask.inherited>[0]["session"], | ||
| mcp: {}, | ||
| }) | ||
| // The phantom deny rules the issue reports must not leak from the read-only caller. | ||
| expect(rules).not.toContainEqual({ permission: "bash", pattern: "git *", action: "deny" }) | ||
| expect(rules).not.toContainEqual({ permission: "bash", pattern: "*", action: "deny" }) | ||
|
|
||
| // Mirror task.ts: the subagent runs with its own permission plus the inherited ceilings. | ||
| const effective = Permission.merge(worker!.permission, KiloTask.permissions(rules)) | ||
| expect(Permission.evaluate("bash", "git status", effective).action).toBe("allow") | ||
| }), | ||
| { | ||
| config: { | ||
| agent: { | ||
| git_worker: { | ||
| description: "A writable subagent that runs git", | ||
| mode: "subagent", | ||
| permission: { | ||
| bash: { | ||
| "*": "ask", | ||
| "git *": "allow", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| ) | ||
| // kilocode_change end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SUGGESTION: The changeset doesn't mention the behavior change to built-in Explore's bash access.
Beyond fixing the phantom denies, this PR also makes Explore's bash enforcement-level read-only (
exploreBashis merged afteruserinpatchAgents, andhardenExplorere-applies it after config-defined agent overrides), so a user can no longer grant Explore additional bash commands via config — even read-only ones not in the allowlist (e.g.docker ps), and even if they promote Explore to a primary agent. That's a reasonable hardening, but it's a user-visible behavior change distinct from the phantom-deny fix and worth one sentence in the release notes so users aren't surprised when their Explore bash allows stop applying.Reply with
@kilocode-bot fix itto have Kilo Code address this issue.