fix(coding-agent): scoped subagent local root overrides

Keep subagent localProtocolOptions on their ToolSession instead of installing
them as the process-global LocalProtocolHandler override. No-context URL
consumers therefore retain the active top-level session's mapping while tan
and task subagents continue to resolve through their caller context.

Add SDK regression coverage proving subagent creation preserves an existing
global mapping.

Fixes #6971

(cherry picked from commit a02eef174b03036dc960c842a0901d22333ad9cd)
This commit is contained in:
roboomp
2026-07-29 23:08:44 +02:00
committed by can1357
parent fb4393ae16
commit dd4985f31e
4 changed files with 50 additions and 4 deletions
@@ -390,8 +390,9 @@ export class LocalProtocolHandler implements ProtocolHandler {
/**
* Install a process-global override that wins over the AgentRegistry-based
* derivation. Used by SDK consumers that wire `localProtocolOptions` on
* `createAgentSession` and by subagents that share their parent's root.
* derivation. Used by top-level SDK consumers that wire
* `localProtocolOptions` on `createAgentSession`; subagents keep their
* inherited mapping session-bound.
*/
static setOverride(value: LocalProtocolOptions | undefined): void {
LocalProtocolHandler.#override = value;
+1 -1
View File
@@ -1772,7 +1772,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
getArtifactsDir,
getSessionId: () => sessionManager.getSessionId?.() ?? null,
};
if (options.localProtocolOptions) {
if (options.localProtocolOptions && !options.parentTaskPrefix) {
LocalProtocolHandler.setOverride(options.localProtocolOptions);
}
toolSession.getArtifactsDir = getArtifactsDir;