feat: make Kafka projector the Workbench realtime authority

This commit is contained in:
root
2026-07-10 05:23:03 +02:00
parent a685be0b78
commit ce83ffdf49
74 changed files with 7746 additions and 9863 deletions
+7 -22
View File
@@ -1,5 +1,5 @@
// SPEC: PJ2026-0104010803 Workbench唯一投影 draft-2026-06-19-p1-agentrun-incremental-cursor; draft-2026-06-20-p2-terminal-outbox-recovery; PJ2026-010205 HWLAB接入 draft-2026-06-17-r0; draft-2026-06-25-p0-session-warm-runner-contract; PJ2026-01060505 Workbench Performance draft-2026-06-17-p0.
// Responsibility: AgentRun command-result/event mapping, terminal projection, and trace observability helpers.
// Responsibility: AgentRun command-result/event mapping and trace observability helpers; Kafka owns persistence.
import { randomUUID } from "node:crypto";
@@ -20,25 +20,6 @@ import {
isAgentRunManagerInternalServiceHost,
resolveAgentRunManagerUrl
} from "./code-agent-agentrun-runtime.ts";
import {
agentRunErrorWithPolling,
agentRunEventCommandId,
agentRunMetricStatusForError,
agentRunPollingRetryableError,
agentRunPollingRootCause,
agentRunProjectionPollCount,
agentRunProjectionPollingState,
agentRunTerminalConsistencyGap,
agentRunTerminalResultRefreshSatisfied,
agentRunTerminalStatusFromEvents,
agentRunTraceCursorSeq,
emitAgentRunProjectionPollingSpan,
fetchAgentRunEventsForTrace,
measuredAgentRunEventsFetch,
measuredAgentRunResultFetch,
nonNegativeNumber,
recordAgentRunEventsProjectionMetrics
} from "./code-agent-agentrun-projection-polling.ts";
import {
agentRunAlreadyTerminalCancelPayload,
agentRunCancelBlockedPayload,
@@ -65,7 +46,6 @@ import {
agentRunPromptMetadataFromText,
messageAuthorityTextValue
} from "./code-agent-agentrun-prompt.ts";
import { agentRunResultSyncDeferred, buildAgentRunProjectionEventsFetchPlan, buildWorkbenchProjectionStateUpdate } from "./workbench-projection-cursor.ts";
import { codeAgentOtelTraceFields, codeAgentOtelTraceContext, emitCodeAgentOtelSpan } from "./otel-trace.ts";
const ADAPTER_ID = "agentrun-v01";
@@ -313,7 +293,7 @@ export function agentRunResultToCodeAgentPayload({ base, result, traceStore, tra
status: "completed",
label: "agentrun:result:completed",
createdAt: terminalEventCreatedAt,
message: "AgentRun result is ready for HWLAB short-connection polling.",
message: "AgentRun result is committed to the Workbench projection event stream.",
runId: base.agentRun.runId,
commandId: base.agentRun.commandId,
terminal: true,
@@ -574,6 +554,11 @@ export function appendAgentRunEventsToTrace(traceStore, traceId, events, mapping
if (normalized) traceStore.append(traceId, normalized, agentRunTraceMeta({}, {}));
}
}
function agentRunEventCommandId(event) {
const payload = event?.payload && typeof event.payload === "object" ? event.payload : {};
if (typeof event?.commandId === "string") return event.commandId;
return typeof payload.commandId === "string" ? payload.commandId : "";
}
export function isForeignAgentRunCommandEvent(event, mapping = {}) {
const currentCommandId = typeof mapping.commandId === "string" ? mapping.commandId : "";