Merge pull request #2472 from pikasTech/fix/workbench-debug-session-trace-fallback
Pipelines as Code CI / hwlab-nc01-v03-ci-poll- Success

fix: 从当前会话恢复调试 trace
This commit is contained in:
Lyon
2026-07-10 20:00:32 +08:00
committed by GitHub
3 changed files with 10 additions and 4 deletions
@@ -93,7 +93,8 @@ test("current Workbench debug trace prefers the active agent turn", () => {
{ id: "msg_old", role: "agent", title: "Code Agent", text: "done", status: "completed", traceId: "trc_old", createdAt: "2026-07-10T10:00:00.000Z" },
{ id: "msg_current", role: "agent", title: "Code Agent", text: "", status: "running", traceId: "trc_current", createdAt: "2026-07-10T10:01:00.000Z" }
] as ChatMessage[];
assert.equal(workbenchCurrentDebugTraceId(messages), "trc_current");
assert.equal(workbenchCurrentDebugTraceId(messages, "trc_session_fallback"), "trc_current");
assert.equal(workbenchCurrentDebugTraceId([], "trc_session_fallback"), "trc_session_fallback");
});
function debugEnvelope(offset: string, value: Record<string, unknown>) {
@@ -61,10 +61,15 @@ export function applyWorkbenchIsolatedKafkaDebugEvent(
return withLog({ ...base, message, appliedCount: state.appliedCount + 1, error: null }, event, traceId, reduced.action.type, plan.steps.map((step) => step.type), true, null);
}
export function workbenchCurrentDebugTraceId(messages: ChatMessage[]): string | null {
export function workbenchCurrentDebugTraceId(messages: ChatMessage[], sessionLastTraceId?: string | null): string | null {
const agentMessages = messages.filter((message) => message.role === "agent");
const running = [...agentMessages].reverse().find((message) => ["pending", "running"].includes(String(message.status ?? "").trim().toLowerCase()) && firstNonEmptyString(message.traceId, message.runnerTrace?.traceId));
return firstNonEmptyString(running?.traceId, running?.runnerTrace?.traceId, ...[...agentMessages].reverse().flatMap((message) => [message.traceId, message.runnerTrace?.traceId])) ?? null;
return firstNonEmptyString(
running?.traceId,
running?.runnerTrace?.traceId,
...[...agentMessages].reverse().flatMap((message) => [message.traceId, message.runnerTrace?.traceId]),
sessionLastTraceId
) ?? null;
}
function projectDebugMessage(previous: ChatMessage | null, traceId: string, realtimeEvent: WorkbenchRealtimeEvent, event: TraceEvent): ChatMessage {
@@ -31,7 +31,7 @@ const applyingRouteSession = ref(Boolean(rawRouteSessionId.value));
const componentActive = ref(false);
const isolatedDebugOpen = ref(false);
const isolatedDebugAvailable = computed(() => debugCapabilities.isolatedKafka && auth.isAdmin);
const isolatedDebugTraceId = computed(() => workbenchCurrentDebugTraceId(workbench.activeMessages));
const isolatedDebugTraceId = computed(() => workbenchCurrentDebugTraceId(workbench.activeMessages, workbench.activeSession?.lastTraceId));
type LaunchContextRecord = {
sourceId?: string | null;
hwpodId?: string | null;