Skip to content

Commit 1cb69b9

Browse files
t3dotggclaude
andcommitted
fix(muse): a waiting retry row says when Muse retries next
Web and mobile show only a retry row's failure message, so the delay was hidden. While a chain waits, its message ends with "Retrying in <delay>."; once it settles, the message is the cause alone. Each chain now keeps one record that later attempts replace. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent b0b6801 commit 1cb69b9

2 files changed

Lines changed: 34 additions & 21 deletions

File tree

‎packages/provider-muse/src/server/adapter.test.ts‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,11 +1918,14 @@ describe("MuseAdapterV2", () => {
19181918
const timeout = { maxAttempts: 2, retryDelayMs: 1_000, reason: "no first model event" };
19191919
const turnRetry = yield* retry("turn/retryScheduled", "record-1", 1, timeout);
19201920
assert.strictEqual(turnRetry?.status, "running");
1921-
assert.strictEqual(turnRetry?.failure.message, "no first model event");
1921+
assert.strictEqual(turnRetry?.failure.message, "no first model event. Retrying in 1s.");
19221922
assert.deepStrictEqual(turnRetry?.retry, { attempt: 1, maxAttempts: 1, retryDelayMs: 1_000 });
19231923
const http = { maxAttempts: 10, errorKind: "server", httpStatus: 504, retryDelayMs: 1_000 };
19241924
const modelRetry = yield* retry("turn/modelRetryScheduled", "record-2", 1, http);
1925-
assert.strictEqual(modelRetry?.failure.message, "Model request failed (HTTP 504)");
1925+
assert.strictEqual(
1926+
modelRetry?.failure.message,
1927+
"Model request failed (HTTP 504). Retrying in 1s.",
1928+
);
19261929
const nextChain = yield* retry("turn/retryScheduled", "record-3", 1, timeout);
19271930
assert.strictEqual(new Set([turnRetry?.id, modelRetry?.id, nextChain?.id]).size, 3);
19281931
const sameChain = yield* retry("turn/modelRetryScheduled", "record-4", 2, {
@@ -1948,9 +1951,13 @@ describe("MuseAdapterV2", () => {
19481951
},
19491952
});
19501953
const recovered = [yield* takeRetryRow(), yield* takeRetryRow(), yield* takeRetryRow()];
1951-
assert.deepStrictEqual(
1952-
recovered.map((row) => [row?.id, row?.status]),
1953-
[turnRetry, nextChain, sameChain].map((row) => [row?.id, "completed"]),
1954+
assert.sameMembers(
1955+
recovered.map((row) => `${row?.id} ${row?.status} ${row?.failure.message}`),
1956+
[
1957+
`${turnRetry?.id} completed no first model event`,
1958+
`${nextChain?.id} completed no first model event`,
1959+
`${sameChain?.id} completed Model request failed (HTTP 429)`,
1960+
],
19541961
);
19551962

19561963
const stalled = yield* retry("turn/modelRetryScheduled", "record-5", 1, http);

‎packages/provider-muse/src/server/adapter.ts‎

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
type OrchestrationV2ConversationMessage,
88
type OrchestrationV2ExecutionNode,
99
type OrchestrationV2ProviderCapabilities,
10-
type OrchestrationV2ProviderFailure,
1110
type OrchestrationV2ProviderRetry,
1211
type OrchestrationV2ProviderSession,
1312
type OrchestrationV2ProviderThread,
@@ -28,6 +27,7 @@ import {
2827
import type { MuseSettings } from "../settings.ts";
2928
import { AgentScope } from "@t3tools/shared/AgentScope";
3029
import { getModelSelectionStringOptionValue } from "@t3tools/shared/model";
30+
import { formatDuration } from "@t3tools/shared/orchestrationTiming";
3131
import * as Cause from "effect/Cause";
3232
import * as DateTime from "effect/DateTime";
3333
import * as Deferred from "effect/Deferred";
@@ -232,7 +232,8 @@ interface MuseRetryRow {
232232
readonly method: string;
233233
readonly nativeId: string;
234234
readonly retry: OrchestrationV2ProviderRetry;
235-
readonly failure: OrchestrationV2ProviderFailure;
235+
readonly cause: string;
236+
readonly code: string | undefined;
236237
running: boolean;
237238
}
238239

@@ -480,7 +481,16 @@ export const makeMuseAdapterV2 = Effect.fn("makeMuseAdapterV2")(function* (
480481
driver: MUSE_PROVIDER,
481482
nodeId: turn.input.rootNodeId,
482483
itemOrdinal: base.ordinal,
483-
failure: row.failure,
484+
failure: makeProviderFailure({
485+
// Clients show only the failure message, so a waiting row carries its delay.
486+
message:
487+
status === "running"
488+
? `${row.cause}. Retrying in ${formatDuration(row.retry.retryDelayMs ?? 0)}.`
489+
: row.cause,
490+
code: row.code,
491+
class: "provider_error",
492+
retryable: true,
493+
}),
484494
retry: row.retry,
485495
status,
486496
updatedAt: time,
@@ -1695,29 +1705,25 @@ export const makeMuseAdapterV2 = Effect.fn("makeMuseAdapterV2")(function* (
16951705
const cause =
16961706
retry.httpStatus === undefined ? retry.errorKind : `HTTP ${retry.httpStatus}`;
16971707
// A chain's first retry opens a row; its later attempts update that row.
1698-
const chain =
1699-
retry.attempt > 1 ? turn.retries.findLast((row) => row.method === method) : undefined;
1700-
if (chain) chain.running = false;
1708+
const index =
1709+
retry.attempt > 1 ? turn.retries.findLastIndex((row) => row.method === method) : -1;
17011710
const row: MuseRetryRow = {
17021711
method,
1703-
nativeId: chain?.nativeId ?? `retry:${retry.sourceRange.first.id}`,
1712+
nativeId: turn.retries[index]?.nativeId ?? `retry:${retry.sourceRange.first.id}`,
17041713
// Muse counts the first request as attempt 1; T3 counts retries.
17051714
retry: {
17061715
attempt: retry.attempt,
17071716
maxAttempts: Math.max(1, retry.maxAttempts - 1),
17081717
retryDelayMs: Math.trunc(retry.retryDelayMs),
17091718
},
1710-
failure: makeProviderFailure({
1711-
message:
1712-
retry.reason ??
1713-
(cause ? `Model request failed (${cause})` : "Model request failed"),
1714-
code: retry.errorKind,
1715-
class: "provider_error",
1716-
retryable: true,
1717-
}),
1719+
cause:
1720+
retry.reason ??
1721+
(cause ? `Model request failed (${cause})` : "Model request failed"),
1722+
code: retry.errorKind,
17181723
running: true,
17191724
};
1720-
turn.retries.push(row);
1725+
if (index === -1) turn.retries.push(row);
1726+
else turn.retries[index] = row;
17211727
yield* emitRetry(turn, row, "running");
17221728
break;
17231729
}

0 commit comments

Comments
 (0)