fix: collapse AgentRun reuse trace noise
This commit is contained in:
@@ -666,6 +666,7 @@ function agentRunResultToCodeAgentPayload({ base, result, traceStore, traceId })
|
||||
const now = nowIso();
|
||||
const runnerTrace = traceStore.snapshot(traceId, agentRunTraceMeta({}, {}));
|
||||
const terminalEventCreatedAt = agentRunResultTraceCreatedAt(runnerTrace, now);
|
||||
const providerTrace = agentRunProviderTrace({ base, result, terminalStatus });
|
||||
if (terminalStatus === "completed" && String(result?.reply ?? "").trim()) {
|
||||
traceStore.append(traceId, {
|
||||
type: "result",
|
||||
@@ -691,7 +692,7 @@ function agentRunResultToCodeAgentPayload({ base, result, traceStore, traceId })
|
||||
toolCalls: agentRunToolCalls(result, "completed"),
|
||||
skills: { status: "delegated", provider: ADAPTER_ID, count: 0, items: [], valuesPrinted: false },
|
||||
longLivedSessionGate: agentRunLongLivedSessionGate(base),
|
||||
providerTrace: agentRunProviderTrace({ base, result, terminalStatus }),
|
||||
providerTrace,
|
||||
reply: {
|
||||
messageId: base.messageId ?? `msg_${traceId.slice(4)}`,
|
||||
role: "assistant",
|
||||
@@ -699,7 +700,7 @@ function agentRunResultToCodeAgentPayload({ base, result, traceStore, traceId })
|
||||
createdAt: now
|
||||
},
|
||||
usage: null,
|
||||
agentRun: { ...base.agentRun, terminalStatus, completed: true, reuseEligible: true, valuesPrinted: false },
|
||||
agentRun: { ...base.agentRun, terminalStatus, completed: true, reuseEligible: true, providerTrace, valuesPrinted: false },
|
||||
valuesPrinted: false
|
||||
};
|
||||
}
|
||||
@@ -729,7 +730,7 @@ function agentRunResultToCodeAgentPayload({ base, result, traceStore, traceId })
|
||||
runnerTrace,
|
||||
toolCalls: agentRunToolCalls(result, canceled ? "canceled" : "failed"),
|
||||
skills: { status: "delegated", provider: ADAPTER_ID, count: 0, items: [], valuesPrinted: false },
|
||||
providerTrace: agentRunProviderTrace({ base, result, terminalStatus }),
|
||||
providerTrace,
|
||||
error: {
|
||||
code,
|
||||
layer: "agentrun",
|
||||
@@ -751,7 +752,7 @@ function agentRunResultToCodeAgentPayload({ base, result, traceStore, traceId })
|
||||
route: "/v1/agent/chat",
|
||||
toolName: "agentrun.manual-dispatch"
|
||||
},
|
||||
agentRun: { ...base.agentRun, terminalStatus, completed: false, valuesPrinted: false },
|
||||
agentRun: { ...base.agentRun, terminalStatus, completed: false, providerTrace, valuesPrinted: false },
|
||||
valuesPrinted: false
|
||||
};
|
||||
}
|
||||
|
||||
@@ -378,6 +378,10 @@ test("cloud api /v1/agent/chat delegates v0.2 turns to AgentRun v0.1 over adapte
|
||||
assert.equal(secondPayload.status, "completed");
|
||||
assert.equal(secondPayload.agentRun.runId, "run_hwlab_adapter");
|
||||
assert.equal(secondPayload.agentRun.commandId, "cmd_hwlab_adapter_second");
|
||||
assert.equal(secondPayload.providerTrace.commandId, "cmd_hwlab_adapter_second");
|
||||
assert.equal(secondPayload.providerTrace.traceId, secondTraceId);
|
||||
assert.equal(secondPayload.agentRun.providerTrace.commandId, "cmd_hwlab_adapter_second");
|
||||
assert.equal(secondPayload.agentRun.providerTrace.traceId, secondTraceId);
|
||||
assert.equal(secondPayload.agentRun.jobName, "agentrun-v01-runner-hwlab-adapter");
|
||||
assert.equal(secondPayload.sessionReuse.reused, true);
|
||||
assert.match(secondPayload.reply.content, /复用已有 runner/u);
|
||||
|
||||
@@ -145,6 +145,32 @@ test("trace display rows collapse successful assistant-only AgentRun turns", ()
|
||||
assert.match(rows[0].body ?? "", /HWLAB663_FINAL_T2_OK/u);
|
||||
});
|
||||
|
||||
test("trace display rows collapse AgentRun reused backend lifecycle noise", () => {
|
||||
const events = [
|
||||
event(1, "agentrun:request:accepted", { message: "accepted" }),
|
||||
event(2, "agentrun:run:reused"),
|
||||
event(3, "agentrun:command:created"),
|
||||
event(4, "agentrun:runner-job:reused"),
|
||||
event(5, "agentrun:backend:codex-app-server:reused", { message: "codex-app-server:reused" }),
|
||||
event(6, "agentrun:backend:thread/resume:completed"),
|
||||
event(7, "agentrun:backend:turn/start:completed"),
|
||||
event(8, "agentrun:assistant:message", {
|
||||
type: "assistant",
|
||||
status: "running",
|
||||
message: "HWLAB663_REUSE_T2_OK"
|
||||
}),
|
||||
event(9, "agentrun:terminal:completed", { type: "result", terminal: true, status: "completed" })
|
||||
];
|
||||
|
||||
const rows = traceDisplayRows({ traceId: "trc_agentrun_reused_lifecycle", events }, events);
|
||||
const text = rows.map((row) => `${row.header}\n${row.body ?? ""}`).join("\n---\n");
|
||||
|
||||
assert.equal(rows.length, 1);
|
||||
assert.equal(rows[0].tone, "ok");
|
||||
assert.equal(/codex-app-server:reused/u.test(text), false);
|
||||
assert.match(rows[0].body ?? "", /HWLAB663_REUSE_T2_OK/u);
|
||||
});
|
||||
|
||||
function traceEvents() {
|
||||
return [
|
||||
event(1, "request:accepted", { promptSummary: "请检查 trace" }),
|
||||
|
||||
@@ -976,6 +976,7 @@ function isAgentRunLifecycleNoiseEvent(event) {
|
||||
label === "agentrun:command:created" ||
|
||||
label === "agentrun:runner-job:reused" ||
|
||||
label === "agentrun:terminal:completed" ||
|
||||
label === "agentrun:backend:codex-app-server:reused" ||
|
||||
/^agentrun:backend:(item\/agentMessage:(started|completed)|thread\/goal\/cleared)$/u.test(label);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user