Skip to content

Subagent detection in responsesApi.ts is broken (startsWith('subagent') never matches) #316154

@bhavyaus

Description

@bhavyaus

Summary

The subagent gate in responsesApi.ts uses subType?.startsWith('subagent'), which never matches in practice. Producers set subType to 'execution_subagent' and 'search_subagent', so the check evaluates to false for every real subagent request.

Where

extensions/copilot/src/platform/endpoint/node/responsesApi.ts:69

const isAllowedConversationAgent = options.location === ChatLocation.Agent || options.location === ChatLocation.MessagesProxy;
const isSubagent = options.telemetryProperties?.subType?.startsWith('subagent') ?? false;
const shouldDeferTools = toolSearchEnabled && isAllowedConversationAgent && !isSubagent;

Why it's wrong

The producers emit:

File Value
extension/prompt/node/executionSubagentToolCallingLoop.ts:366 'execution_subagent'
extension/prompt/node/searchSubagentToolCallingLoop.ts:172 'search_subagent'

Commit 5e01ed5de06 ("rename agent type so it doesn't get redacted") renamed the values from subagent/execution and subagent/search to put subagent as a suffix rather than a prefix. The detection in responsesApi.ts was not updated to match, so shouldDeferTools ends up true for subagent runs even though the gate is supposed to exclude them.

Impact

Client-executed tool search defers tools for subagent requests today, contrary to the comment / gate intent. Behavior may or may not be desirable — needs a product call — but at minimum the code does not match the apparent design.

Suggested fix

const isSubagent = options.telemetryProperties?.subType?.includes('subagent') ?? false;

includes matches both current names (execution_subagent, search_subagent) and stays robust if new subagent types like explore_subagent are added later. Same fix was applied to the new extended-cache-ttl gate in messagesApi.ts (PR / branch dev/bhavyau/anthropic-extended-cache-ttl).

Optionally, extract a tiny shared helper near subType?: string in extensions/copilot/src/platform/networking/common/networking.ts so both API paths stay in sync.

Acceptance

  • responsesApi.ts correctly identifies execution_subagent and search_subagent requests as subagents
  • (Optional) Shared helper used by both Messages and Responses API code paths

cc @bhavyaus — found while implementing the Anthropic extended cache TTL gate.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions