fix(pi): give each task sub-session its own resource loader to prevent stale extension ctx

This commit is contained in:
ezl-keygraph
2026-09-01 01:45:46 +05:30
parent e9cf782081
commit 4e145a0f3f
2 changed files with 5 additions and 4 deletions
+2 -2
View File
@@ -299,7 +299,7 @@ export async function runPiPrompt(
childUsage.cacheReadTokens += usage.cacheReadTokens;
childUsage.cacheWriteTokens += usage.cacheWriteTokens;
},
resourceLoader,
createResourceLoader: () => buildResourceLoader(sourceDir, logger, agentName),
...(cancellationSignal && { cancellationSignal }),
}),
createTodoWriteTool(),
@@ -403,7 +403,6 @@ export async function runPiPrompt(
// 6. Run the agent to completion (resolves at agent_end).
await session.prompt(fullPrompt);
session.dispose();
// 7. Surface any error captured during the run.
if (pendingError) throw pendingError;
@@ -469,6 +468,7 @@ export async function runPiPrompt(
retryable,
};
} finally {
session?.dispose();
cancellationSignal?.removeEventListener('abort', onCancellation);
}
}
+3 -2
View File
@@ -26,7 +26,7 @@ export interface TaskToolContext {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
readonly model: Model<any>;
readonly modelRuntime: ModelRuntime;
readonly resourceLoader: ResourceLoader;
readonly createResourceLoader: () => Promise<ResourceLoader>;
readonly parentAgentName: LoggableAgentName;
readonly workflowLogPath?: string | undefined;
readonly onDelegationStart?: ((child: string) => Promise<void>) | undefined;
@@ -129,10 +129,11 @@ export function createTaskTool(config: TaskToolContext): ToolDefinition {
const onCancellation = (): void => abortChildSession();
try {
const resourceLoader = await config.createResourceLoader();
({ session: subSession } = await createAgentSession({
cwd: config.cwd,
agentDir,
resourceLoader: config.resourceLoader,
resourceLoader,
model: config.model,
tools: CHILD_TOOLS,
modelRuntime: config.modelRuntime,