Skip to content

Commit 7188e4f

Browse files
committed
refactor: centralize agent run pending status
1 parent b32d4c5 commit 7188e4f

5 files changed

Lines changed: 25 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Docs: https://docs.openclaw.ai
7070
### Fixes
7171

7272
- Gateway/OpenAI-compatible: send the assistant role SSE chunk as soon as streaming chat-completion headers are accepted, so cold agent setup cannot leave `/v1/chat/completions` clients with a bodyless 200 response until their idle timeout fires.
73+
- Agents/media: avoid direct generated-media completion fallback while the announce-agent run is still pending, so async video and music completions do not duplicate raw media messages. (#77754)
7374
- TUI/sessions: bound the session picker to recent rows and use exact lookup-style refreshes for the active session, so dusty stores no longer make TUI hydrate weeks-old transcripts before becoming responsive. Thanks @vincentkoc.
7475
- Doctor/gateway: report recent supervisor restart handoffs in `openclaw doctor --deep`, using the installed service environment when available so service-managed clean exits are visible in guided diagnostics. Thanks @shakkernerd.
7576
- Gateway/status: show recent supervisor restart handoffs in `openclaw gateway status --deep`, including JSON details, so clean service-managed restarts are reported as restart handoffs instead of opaque stopped-service diagnostics. Thanks @shakkernerd.

src/agents/subagent-announce-delivery.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { normalizeAccountId } from "../routing/session-key.js";
66
import { defaultRuntime } from "../runtime.js";
77
import { deriveSessionChatTypeFromKey } from "../sessions/session-chat-type-shared.js";
88
import { isCronSessionKey } from "../sessions/session-key-utils.js";
9+
import { isNonTerminalAgentRunStatus } from "../shared/agent-run-status.js";
910
import { normalizeOptionalLowercaseString } from "../shared/string-coerce.js";
1011
import {
1112
mergeDeliveryContext,
@@ -694,7 +695,7 @@ function isGatewayAgentRunPending(response: unknown): boolean {
694695
return false;
695696
}
696697
const status = (response as { status?: unknown }).status;
697-
return status === "accepted" || status === "in_flight" || status === "started";
698+
return isNonTerminalAgentRunStatus(status);
698699
}
699700

700701
function inferCompletionChatType(params: {

src/gateway/server-methods/agent-wait-dedupe.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isNonTerminalAgentRunStatus } from "../../shared/agent-run-status.js";
12
import { setSafeTimeout } from "../../utils/timer-delay.js";
23
import type { DedupeEntry } from "../server-shared.js";
34

@@ -91,7 +92,7 @@ function readTerminalSnapshotFromDedupeEntry(entry: DedupeEntry): AgentWaitTermi
9192
}
9293
| undefined;
9394
const status = typeof payload?.status === "string" ? payload.status : undefined;
94-
if (status === "accepted" || status === "started" || status === "in_flight") {
95+
if (isNonTerminalAgentRunStatus(status)) {
9596
return null;
9697
}
9798

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { describe, expect, it } from "vitest";
2+
import { isNonTerminalAgentRunStatus } from "./agent-run-status.js";
3+
4+
describe("isNonTerminalAgentRunStatus", () => {
5+
it.each(["accepted", "started", "in_flight"])("recognizes %s as non-terminal", (status) => {
6+
expect(isNonTerminalAgentRunStatus(status)).toBe(true);
7+
});
8+
9+
it.each(["ok", "error", "timeout", "queued", "", null, undefined, 1, {}, []])(
10+
"does not recognize %s as non-terminal",
11+
(status) => {
12+
expect(isNonTerminalAgentRunStatus(status)).toBe(false);
13+
},
14+
);
15+
});

src/shared/agent-run-status.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const NON_TERMINAL_AGENT_RUN_STATUSES = new Set(["accepted", "started", "in_flight"]);
2+
3+
export function isNonTerminalAgentRunStatus(status: unknown): boolean {
4+
return typeof status === "string" && NON_TERMINAL_AGENT_RUN_STATUSES.has(status);
5+
}

0 commit comments

Comments
 (0)