Repository navigation
feat(coderd): enforce custom agent tool policy on child chats - #58
Conversation
Behind the fork-agent-definitions experiment, spawn_agent resolves custom agent types from the chat's pinned subagent context resources after the built-in types. A custom child runs with the definition body as a system message and the definition's model and reasoning effort unless the call passes explicit ones, and its chat_subagents row records the custom type. The spawn_agent description lists the custom types within a byte budget.
…r custom agent types
…es-4-tool-policy # Conflicts: # coderd/x/chatd/ARCHITECTURE.md # coderd/x/chatd/fork_agent_definitions.go # coderd/x/chatd/fork_agent_definitions_internal_test.go # coderd/x/chatd/fork_subagents.go # coderd/x/chatd/subagent_operations.go
|
@codex review
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 38636cb16f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…agent tool policy Move the policy hook after provider tools are built so tools allowlists and disallowed_tools also govern web_search and other provider tools, take the MCP server name from the tool name prefix so named mode works for inline and internal servers, add Grep, Glob and WebSearch aliases, and forward ToolPolicy in dbgen.ChatSubagent.
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cda71ab79e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…l name mcpclient sanitizes and truncates tool names, so two servers can share a name prefix. Map each MCP tool's server ID to its slug from org configs, the root chat's inline servers and internal servers.
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 355c81420e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…e servers in tool policy disallowed_tools now also matches mcp__<server>__<tool> against the chatd name <server>__<tool>. Named mcp no longer trims workspace server names, so a padded server cannot pass as its plain sibling.
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 13f45b9ecb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…policy removes spawn_agent A readonly custom child, or one whose tools or disallowed_tools exclude spawn_agent, no longer gets the <subagent-orchestration> block telling it to use tools it lacks.
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: aea9107b4d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…tool policy Server slugs and workspace server names are unique case-sensitively, so case folding let mcp: [docs] reach a distinct Docs server.
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2c6f1252a6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
… policy find_tools is built after the policy hook from the remaining deferred candidates, so denying it now drops the candidates and leaves the MCP tools undeferred.
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6982f7cfb6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
… names mcpclient sanitizes MCP tool names and caps them at the provider limit, so mcp__awslabs.foo__lookup has to become awslabs_foo__lookup before it can match.
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5d71442534
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
docs/fork/pstack-adapter.md maps Task to spawn_agent then wait_agent; the alias covers the whole subagent tool family the orchestration guidance names.
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bc85cf8d7f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The <subagent-orchestration> block tells the child to call spawn_agent, wait_agent and list_agents, so a policy that removes any of them now drops the block.
|
@codex review
|
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…es-4-tool-policy # Conflicts: # coderd/database/forkdb/sqlc.yaml
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: aa178d2f8d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review
|
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Merge evidence for head
|
With the
fork-agent-definitionsexperiment on, the tool fields of a custom agent definition now restrict the child chat it spawns. #51 resolved these types but gave every one of them its base type's full tool set.readonly: truekeeps only the explore allowlist (exploreToolAllowed):read_file,execute,process_output,read_skill,read_skill_file, and admin, internal and inline MCP tools; among provider tools it keeps onlyweb_search, as Explore children do.executestays available. This relaxes PRD R1.5 on purpose, because a read-only agent still has to run read-only commands, soreadonlyis not a sandbox. Workspace MCP tools are dropped.toolsis an allowlist of non-MCP tools, provider tools such asweb_searchincluded. Claude Code names work as aliases:Read,WriteandEdit/MultiEditmap toread_file,write_fileandedit_files;Bashmaps toexecuteplusprocess_output;GrepandGlobmap toread_file,executeandprocess_output, followingdocs/fork/pstack-adapter.md;WebSearchmaps toweb_search;Taskmaps to the subagent tools (spawn_agent,wait_agent,message_agent,interrupt_agent,list_agents,list_subagent_models). An empty list allows no non-MCP tools. MCP tools are governed bymcp, and so isfind_tools, the search tool that delivers deferred MCP tools; only an explicitdisallowed_toolsentry removes it.disallowed_toolsremoves any named tool, MCP tools included (by full tool name), with the same aliases. A Claude Code MCP tool ID,mcp__<server>__<tool>, also matches the chatd name<server>__<tool>, sanitized and capped the way chatd exposes MCP tools. Denyingfind_toolsdrops the deferred MCP candidates, so nofind_toolsis built and the allowed MCP tools stay directly callable.mcp: nonedrops every MCP tool.mcp: [names]keeps only MCP tools whose server matches one of the names exactly, case included, because server slugs and workspace server names are unique case-sensitively. For org, inline and internal servers the name is matched against the server's exact slug, looked up by server ID from the org's MCP server configs, the root chat's inline servers and the internal servers, and only whenmcpnames servers. The tool-name prefix is not used becausemcpclientsanitizes and truncates tool names, so two servers can share a prefix. For workspace MCP servers the name is the untrimmed server name, because workspace config can hold bothxandxas distinct servers.spawn_agent,wait_agentorlist_agents, the tools the<subagent-orchestration>block tells the child to call (throughreadonly, atoolsallowlist ordisallowed_tools), the child's system prompt drops that block, as children that cannot spawn already do (childGetsOrchestrationPrompt, one call site insubagent_operations.go).read_skill(atoolsallowlist without it, ordisallowed_tools), the child's system prompt drops the<available-skills>index, which tells it to callread_skill. readonly keepsread_skill, so a readonly child keeps the index. buildTurnEnvironment loads the stored policy once, before the system prompt (customAgentToolPolicyOfChat), and the same policy then filters the tools.The policy is stored at spawn, in the same transaction as the child, in a new nullable
chatd.chat_subagents.tool_policyjsonb column (chatdmig node01a1c08d…_chat_subagent_tool_policy; additive, no backfill). Snapshotting matters because a child that hasexecutecan refresh its pinned context resources and would otherwise be able to rewrite its own definition. Built-in types and older rows store NULL and are unaffected. If a stored policy cannot be decoded, the child's turn fails instead of running unrestricted.Enforcement is a second fork hook in
buildTurnEnvironment(turn_environment.go, 3 lines). It runs once every tool source is assembled, just before the active tool names are computed, and filters the turn's tools, the deferredfind_toolscandidates and the provider tools. The first hook (appendForkTools) cannot do this job because MCP tools, workspace MCP tools, the deferred catalog and provider tools are all added after it.find_toolsitself is built after the hook, but only from the candidates the policy already filtered.With the experiment off, or for a root chat, the hook returns before it reads anything.
Part of #7.