mirror of
https://github.com/KeygraphHQ/shannon.git
synced 2026-09-13 21:49:04 +02:00
fix(pi): give each task sub-session its own resource loader to prevent stale extension ctx
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user