fix: report subagent timeout as 'timed out' instead of 'completed successfully' (#13996)

* fix: report subagent timeout as 'timed out' instead of 'completed successfully'

* fix: propagate subagent timeout status across agent.wait (#13996) (thanks @dario-github)

---------

Co-authored-by: Sebastian <19554889+sebslight@users.noreply.github.com>
This commit is contained in:
Dario Zhang
2026-02-12 01:55:30 +08:00
committed by GitHub
parent 2c6569a488
commit e85bbe01f2
5 changed files with 122 additions and 5 deletions

View File

@@ -0,0 +1,37 @@
import { describe, expect, it } from "vitest";
import { emitAgentEvent } from "../../infra/agent-events.js";
import { waitForAgentJob } from "./agent-job.js";
describe("waitForAgentJob", () => {
it("maps lifecycle end events with aborted=true to timeout", async () => {
const runId = `run-timeout-${Date.now()}-${Math.random().toString(36).slice(2)}`;
const waitPromise = waitForAgentJob({ runId, timeoutMs: 1_000 });
emitAgentEvent({ runId, stream: "lifecycle", data: { phase: "start", startedAt: 100 } });
emitAgentEvent({
runId,
stream: "lifecycle",
data: { phase: "end", endedAt: 200, aborted: true },
});
const snapshot = await waitPromise;
expect(snapshot).not.toBeNull();
expect(snapshot?.status).toBe("timeout");
expect(snapshot?.startedAt).toBe(100);
expect(snapshot?.endedAt).toBe(200);
});
it("keeps non-aborted lifecycle end events as ok", async () => {
const runId = `run-ok-${Date.now()}-${Math.random().toString(36).slice(2)}`;
const waitPromise = waitForAgentJob({ runId, timeoutMs: 1_000 });
emitAgentEvent({ runId, stream: "lifecycle", data: { phase: "start", startedAt: 300 } });
emitAgentEvent({ runId, stream: "lifecycle", data: { phase: "end", endedAt: 400 } });
const snapshot = await waitPromise;
expect(snapshot).not.toBeNull();
expect(snapshot?.status).toBe("ok");
expect(snapshot?.startedAt).toBe(300);
expect(snapshot?.endedAt).toBe(400);
});
});

View File

@@ -7,7 +7,7 @@ let agentRunListenerStarted = false;
type AgentRunSnapshot = {
runId: string;
status: "ok" | "error";
status: "ok" | "error" | "timeout";
startedAt?: number;
endedAt?: number;
error?: string;
@@ -55,7 +55,7 @@ function ensureAgentRunListener() {
agentRunStarts.delete(evt.runId);
recordAgentRunSnapshot({
runId: evt.runId,
status: phase === "error" ? "error" : "ok",
status: phase === "error" ? "error" : evt.data?.aborted ? "timeout" : "ok",
startedAt,
endedAt,
error,
@@ -118,7 +118,7 @@ export async function waitForAgentJob(params: {
const error = typeof evt.data?.error === "string" ? evt.data.error : undefined;
const snapshot: AgentRunSnapshot = {
runId: evt.runId,
status: phase === "error" ? "error" : "ok",
status: phase === "error" ? "error" : evt.data?.aborted ? "timeout" : "ok",
startedAt,
endedAt,
error,