Merge pull request #1601 from pikasTech/fix/1585-workbench-facts-session-cache
[P0] Workbench facts 复用 trace session lookup
This commit is contained in:
@@ -2481,7 +2481,7 @@ test("cloud api turn status reuses request session lookup without loading persis
|
||||
const body = await response.json();
|
||||
assert.equal(body.status, "unknown");
|
||||
assert.equal(body.projectionStatus, "unknown");
|
||||
assert.equal(sessionLookupCount, 2);
|
||||
assert.equal(sessionLookupCount, 1);
|
||||
assert.equal(calls.filter((call) => call.path === `/api/v1/runs/${runId}/events`).length, 0);
|
||||
} finally {
|
||||
await new Promise((resolve, reject) => {
|
||||
|
||||
@@ -11,6 +11,7 @@ const terminalDurableTraceCache = new Map();
|
||||
|
||||
export function createWorkbenchFactsStore(options = {}, actor = null) {
|
||||
const accessStore = options.accessController?.store ?? options.accessController ?? null;
|
||||
const traceSessionCache = options.codeAgentTraceSessionCache instanceof Map ? options.codeAgentTraceSessionCache : null;
|
||||
const traceStore = options.traceStore ?? defaultCodeAgentTraceStore;
|
||||
const runtimeStore = options.runtimeStore ?? null;
|
||||
const results = options.codeAgentChatResults ?? null;
|
||||
@@ -45,7 +46,12 @@ export function createWorkbenchFactsStore(options = {}, actor = null) {
|
||||
async function getSessionByTraceId(traceId) {
|
||||
const safeId = safeTraceId(traceId);
|
||||
if (!safeId) return null;
|
||||
if (traceSessionCache?.has(safeId)) {
|
||||
const cached = traceSessionCache.get(safeId) ?? null;
|
||||
return canActorReadSession(cached, actor) ? cached : null;
|
||||
}
|
||||
const session = await accessStore?.getAgentSessionByTraceId?.(safeId) ?? null;
|
||||
traceSessionCache?.set(safeId, session);
|
||||
return canActorReadSession(session, actor) ? session : null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user