Surface wait_for_finish agent errors

This commit is contained in:
Mohamed Boudra
2026-04-07 16:50:17 +07:00
parent 5ce4562eed
commit ee611d65b6
2 changed files with 48 additions and 2 deletions
+16 -2
View File
@@ -257,6 +257,17 @@ export function resolveCreateAgentTitles(options: {
};
}
export function resolveWaitForFinishError(options: {
status: "permission" | "error" | "idle";
final: AgentSnapshotPayload | null;
}): string | null {
if (options.status !== "error") {
return null;
}
const message = options.final?.lastError;
return typeof message === "string" && message.trim().length > 0 ? message : "Agent failed";
}
type ProcessingPhase = "idle" | "transcribing";
type WorkspaceGitWatchTarget = {
@@ -6569,9 +6580,10 @@ export class Session {
: record.lastStatus === "error"
? "error"
: "idle";
const error = resolveWaitForFinishError({ status, final });
this.emit({
type: "wait_for_finish_response",
payload: { requestId, status, final, error: null, lastMessage: null },
payload: { requestId, status, final, error, lastMessage: null },
});
return;
}
@@ -6598,9 +6610,11 @@ export class Session {
: result.status === "error"
? "error"
: "idle";
const error = resolveWaitForFinishError({ status, final });
this.emit({
type: "wait_for_finish_response",
payload: { requestId, status, final, error: null, lastMessage: result.lastMessage },
payload: { requestId, status, final, error, lastMessage: result.lastMessage },
});
} catch (error) {
const isAbort =
@@ -0,0 +1,32 @@
import { describe, expect, test } from "vitest";
import { resolveWaitForFinishError } from "./session.js";
describe("resolveWaitForFinishError", () => {
test("returns the agent error when the wait result is an error", () => {
expect(
resolveWaitForFinishError({
status: "error",
final: { lastError: "invalid_json_schema" } as any,
}),
).toBe("invalid_json_schema");
});
test("returns a generic fallback when the agent ended in error without a message", () => {
expect(
resolveWaitForFinishError({
status: "error",
final: {} as any,
}),
).toBe("Agent failed");
});
test("returns null for non-error wait results", () => {
expect(
resolveWaitForFinishError({
status: "idle",
final: { lastError: "should not surface" } as any,
}),
).toBeNull();
});
});