fix(agent): pass sessionId to tools for sub-agent session tracking

toolsOptions spread `options` which had sessionId undefined for
auto-generated sessions. This caused sessions_list and sessions_spawn
to fail with "No session ID available" — breaking sub-agent orchestration.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jiayuan Zhang 2026-02-15 19:53:03 +08:00
parent a254daff01
commit d162ba98a9

View file

@ -393,9 +393,12 @@ export class Agent {
const profileToolsConfig = this.profile?.getToolsConfig();
const mergedToolsConfig = mergeToolsConfig(profileToolsConfig, options.tools);
const profileDir = this.profile?.getProfileDir();
// Use this.sessionId (which may be auto-generated) instead of options.sessionId
// (which may be undefined). Without this, sessions_list and sessions_spawn
// can't find sub-agent runs because they have no session context.
this.toolsOptions = mergedToolsConfig
? { ...options, cwd: effectiveCwd, tools: mergedToolsConfig, profileDir, provider: this.resolvedProvider }
: { ...options, cwd: effectiveCwd, profileDir, provider: this.resolvedProvider };
? { ...options, sessionId: this.sessionId, cwd: effectiveCwd, tools: mergedToolsConfig, profileDir, provider: this.resolvedProvider }
: { ...options, sessionId: this.sessionId, cwd: effectiveCwd, profileDir, provider: this.resolvedProvider };
const tools = resolveTools(this.toolsOptions);
if (this.debug) {