fix(agent): preserve runtime request context

OpenCode tools run in a child service, so they cannot read the Agent process-local session map. Hydrate a sanitized context through the authenticated internal bridge and centralize backend project headers to prevent context loss across both boundaries.
This commit is contained in:
2026-08-05 18:39:09 +08:00
parent a53839e157
commit 2dc37e3fd8
7 changed files with 291 additions and 19 deletions
+8 -6
View File
@@ -2,16 +2,18 @@ import { tool } from "@opencode-ai/plugin";
import { SkillStore } from "../../src/skills/store.js";
import {
getRuntimeSessionContext,
type RuntimeSessionContext,
} from "../../src/runtime/sessionContext.js";
readBridgedRuntimeSessionContext,
} from "../../src/runtime/internalSessionContextBridge.js";
import { type RuntimeSessionContext } from "../../src/runtime/sessionContext.js";
type ToolContextReader = {
read(sessionId: string): RuntimeSessionContext | null;
read(
sessionId: string,
): RuntimeSessionContext | null | Promise<RuntimeSessionContext | null>;
};
const runtimeContextReader: ToolContextReader = {
read: getRuntimeSessionContext,
read: readBridgedRuntimeSessionContext,
};
export const createSkillManagerTool = (
@@ -69,7 +71,7 @@ export const createSkillManagerTool = (
},
async execute(args, context) {
await initializePromise;
const sessionContext = toolContextStore.read(context.sessionID);
const sessionContext = await toolContextStore.read(context.sessionID);
if (!sessionContext) {
throw new Error(`session context not found for ${context.sessionID}`);
}