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:
@@ -1,9 +1,8 @@
|
||||
import { tool } from "@opencode-ai/plugin";
|
||||
|
||||
import { MemoryStore } from "../../src/memory/store.js";
|
||||
import {
|
||||
getRuntimeSessionContext,
|
||||
setRuntimeSessionContext,
|
||||
} from "../../src/runtime/sessionContext.js";
|
||||
import { readBridgedRuntimeSessionContext } from "../../src/runtime/internalSessionContextBridge.js";
|
||||
import { setRuntimeSessionContext } from "../../src/runtime/sessionContext.js";
|
||||
|
||||
const memoryStore = new MemoryStore();
|
||||
const initializePromise = memoryStore.initialize();
|
||||
@@ -36,7 +35,9 @@ export default tool({
|
||||
},
|
||||
async execute(args, context) {
|
||||
await initializePromise;
|
||||
const sessionContext = getRuntimeSessionContext(context.sessionID);
|
||||
const sessionContext = await readBridgedRuntimeSessionContext(
|
||||
context.sessionID,
|
||||
);
|
||||
if (!sessionContext) {
|
||||
throw new Error(`session context not found for ${context.sessionID}`);
|
||||
}
|
||||
|
||||
@@ -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}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user