fix: align AgentRun reuse assertions with spec

This commit is contained in:
lyon
2026-06-17 00:53:50 +08:00
parent 41e8e6fce4
commit 1527a992c3
3 changed files with 30 additions and 4 deletions
+13 -2
View File
@@ -448,7 +448,7 @@ export async function syncAgentRunChatResult({ traceId, currentResult = null, op
timeoutMs,
env
});
const nextMapping = {
const nextMapping = withAgentRunRunnerJobCount({
...mapped.agentRun,
...agentRunResultRefs(result),
lastSeq: eventsResponse ? agentRunTraceCursorSeq(eventsResponse, mapped.agentRun.lastSeq) : mapped.agentRun.lastSeq,
@@ -458,7 +458,7 @@ export async function syncAgentRunChatResult({ traceId, currentResult = null, op
terminalStatus: result?.terminalStatus ?? mapped.agentRun.terminalStatus ?? null,
updatedAt: nowIso(options.now),
valuesPrinted: false
};
});
const base = { ...mapped, agentRun: nextMapping, updatedAt: nowIso(options.now) };
const payload = agentRunResultToCodeAgentPayload({ base, result, traceStore, traceId, appendResultEvent });
options.codeAgentChatResults?.set?.(traceId, payload);
@@ -2065,6 +2065,17 @@ function agentRunResultRefs(result = {}) {
return refs;
}
function withAgentRunRunnerJobCount(mapping = {}) {
if (!mapping || typeof mapping !== "object") return mapping;
const count = Number(mapping.runnerJobCount);
if (Number.isFinite(count) && count >= 0) return mapping;
const runnerJobEnsured = mapping.reused === true || mapping.status === "runner-job-ensured";
if (runnerJobEnsured && (mapping.runnerJobId || mapping.jobName || mapping.attemptId || mapping.runnerId)) {
return { ...mapping, runnerJobCount: 1 };
}
return mapping;
}
function hwlabSessionIdForParams(params = {}, traceId) {
return safeSessionId(params.sessionId) || agentRunSessionId(traceId);
}