fix: repair ambiguous top-level trace snapshots
This commit is contained in:
@@ -616,7 +616,12 @@ export async function loadPersistedAgentRunResult(traceId, options = {}) {
|
||||
const topLevelFinalTraceId = safeTraceId(session?.session?.finalResponse?.traceId ?? session?.session?.traceSummary?.traceId);
|
||||
const topLevelConflictsTrace = (agentRunTraceId && agentRunTraceId !== safeId) || (topLevelFinalTraceId && topLevelFinalTraceId !== safeId);
|
||||
const mayUseTopLevelAgentRun = !topLevelConflictsTrace && (latestTraceId === safeId || agentRunTraceId === safeId || topLevelFinalTraceId === safeId || (!latestTraceId && !agentRunTraceId && !topLevelFinalTraceId));
|
||||
const agentRun = traceEvidence?.agentRun ?? (mayUseTopLevelAgentRun ? topLevelAgentRun : null);
|
||||
const topLevelTraceEvidence = mayUseTopLevelAgentRun ? agentSessionTopLevelTraceEvidence(session, safeId) : null;
|
||||
if (!traceEvidence && topLevelTraceEvidence && ambiguousTopLevelAgentRunTrace(topLevelAgentRun)) {
|
||||
const repaired = await repairPersistedAgentRunResultFromRunCommands({ traceId: safeId, session, options }).catch(() => null);
|
||||
if (repaired) return repaired;
|
||||
}
|
||||
const agentRun = traceEvidence?.agentRun ?? (topLevelTraceEvidence ? topLevelAgentRun : null);
|
||||
const restored = persistedAgentRunResultFromSession({ traceId: safeId, session, agentRun, traceEvidence, options });
|
||||
if (restored) return restored;
|
||||
return await repairPersistedAgentRunResultFromRunCommands({ traceId: safeId, session, options });
|
||||
@@ -774,6 +779,21 @@ function validAgentSessionTraceEvidence(session, traceId) {
|
||||
return agentRunEvidenceMatchesTrace(evidence.agentRun, traceId, evidence, { requireAgentRunTraceId: true }) ? evidence : null;
|
||||
}
|
||||
|
||||
function agentSessionTopLevelTraceEvidence(session, traceId) {
|
||||
const snapshot = session?.session && typeof session.session === "object" ? session.session : null;
|
||||
if (!snapshot) return null;
|
||||
const evidence = {
|
||||
finalResponse: snapshot.finalResponse,
|
||||
traceSummary: snapshot.traceSummary
|
||||
};
|
||||
return agentRunEvidenceMatchesTrace(snapshot.agentRun, traceId, evidence) ? evidence : null;
|
||||
}
|
||||
|
||||
function ambiguousTopLevelAgentRunTrace(agentRun) {
|
||||
const run = agentRun && typeof agentRun === "object" ? agentRun : null;
|
||||
return Boolean(run?.runId && run?.commandId && !safeTraceId(run.traceId));
|
||||
}
|
||||
|
||||
function agentRunEvidenceMatchesTrace(agentRun, traceId, traceEvidence = null, options = {}) {
|
||||
const id = safeTraceId(traceId);
|
||||
if (!id) return false;
|
||||
|
||||
Reference in New Issue
Block a user