Skip to content

Commit 03d02e6

Browse files
saphidclaude
andcommitted
fix(muse): failed Muse text generation explains Muse's error category
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 8d567bb commit 03d02e6

2 files changed

Lines changed: 66 additions & 20 deletions

File tree

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

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -226,20 +226,41 @@ it.layer(NodeServices.layer)("Muse text generation", (it) => {
226226
}),
227227
);
228228

229-
it.effect("keeps Muse's reason when the turn fails", () =>
229+
it.effect("explains a failed turn by Muse's error category", () =>
230230
Effect.gen(function* () {
231-
const test = fixture((emit) =>
232-
emit("turn/completed", {
233-
terminal: "failed",
234-
error: { message: "You've reached your usage limit." },
235-
}),
236-
);
237-
const service = yield* test.make;
238-
expect(yield* service.generateThreadTitle(titleInput).pipe(Effect.flip)).toMatchObject({
239-
_tag: "TextGenerationError",
240-
detail: "Muse Code text generation failed: You've reached your usage limit.",
241-
});
242-
expect(test.host.close).toHaveBeenCalledOnce();
231+
const message = "API error 429: raw provider text";
232+
const cases = [
233+
{
234+
error: { kind: "modelError", quota: { limitKind: "tierLimit", resetsAtMs: 1 } },
235+
detail: "Muse Code usage limit reached. Try again after it resets.",
236+
},
237+
{
238+
error: { kind: "authRequired" },
239+
detail: "Muse Code is not signed in. Run `muse login` on this T3 server host.",
240+
},
241+
{
242+
error: { kind: "modelError" },
243+
detail: "Muse Code's model request failed. Try again or choose another Muse model.",
244+
},
245+
{
246+
error: { kind: "stepLimit" },
247+
detail:
248+
"Muse Code text generation failed. Check Muse login and availability on this T3 server host.",
249+
},
250+
];
251+
for (const { error, detail } of cases) {
252+
const test = fixture((emit) =>
253+
emit("turn/completed", {
254+
terminal: "failed",
255+
error: { ...error, message, retryable: false },
256+
}),
257+
);
258+
const service = yield* test.make;
259+
const failure = yield* service.generateThreadTitle(titleInput).pipe(Effect.flip);
260+
expect(failure).toMatchObject({ _tag: "TextGenerationError", detail });
261+
expect(failure.detail).not.toContain(message);
262+
expect(test.host.close).toHaveBeenCalledOnce();
263+
}
243264
}),
244265
);
245266

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

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ const TurnCompleted = Schema.Struct({
4949
sessionId: Schema.String,
5050
turnId: Schema.String,
5151
terminal: Schema.String,
52-
error: Schema.optionalKey(Schema.Struct({ message: Schema.String })),
52+
error: Schema.optionalKey(
53+
Schema.Struct({
54+
kind: Schema.optionalKey(Schema.String),
55+
message: Schema.String,
56+
quota: Schema.optionalKey(Schema.Unknown),
57+
}),
58+
),
5359
});
5460
const ApprovalRequested = Schema.Struct({
5561
sessionId: Schema.String,
@@ -72,7 +78,29 @@ const encodeJson = Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown));
7278
const decodeJson = Schema.decodeEffect(Schema.fromJsonString(Schema.Unknown));
7379

7480
type Operation = keyof ProviderTextGeneration;
75-
class MuseTurnFailure extends Error {}
81+
type TurnError = NonNullable<(typeof TurnCompleted.Type)["error"]>;
82+
class MuseTurnFailure extends Error {
83+
readonly turnError: TurnError;
84+
constructor(turnError: TurnError) {
85+
super(turnError.message);
86+
this.turnError = turnError;
87+
}
88+
}
89+
90+
function museFailureDetail(cause: unknown): string {
91+
const error =
92+
Cause.isUnknownError(cause) && cause.cause instanceof MuseTurnFailure
93+
? cause.cause.turnError
94+
: undefined;
95+
// Muse sends `quota` only for quota exhaustion, which it still labels `modelError`.
96+
if (error?.quota !== undefined)
97+
return "Muse Code usage limit reached. Try again after it resets.";
98+
if (error?.kind === "authRequired")
99+
return "Muse Code is not signed in. Run `muse login` on this T3 server host.";
100+
if (error?.kind === "modelError")
101+
return "Muse Code's model request failed. Try again or choose another Muse model.";
102+
return "Muse Code text generation failed. Check Muse login and availability on this T3 server host.";
103+
}
76104

77105
async function generateMuseText(
78106
host: MuseSdkHost,
@@ -140,7 +168,7 @@ async function generateMuseText(
140168
} else {
141169
rejectCompletion(
142170
completed.error
143-
? new MuseTurnFailure(completed.error.message)
171+
? new MuseTurnFailure(completed.error)
144172
: new Error(`Muse turn ${completed.terminal}.`),
145173
);
146174
}
@@ -270,10 +298,7 @@ export const makeMuseTextGeneration = Effect.fn("makeMuseTextGeneration")(functi
270298
(cause) =>
271299
new TextGenerationError({
272300
operation,
273-
detail:
274-
Cause.isUnknownError(cause) && cause.cause instanceof MuseTurnFailure
275-
? `Muse Code text generation failed: ${cause.cause.message}`
276-
: "Muse Code text generation failed. Check Muse login and availability on this T3 server host.",
301+
detail: museFailureDetail(cause),
277302
cause,
278303
}),
279304
),

0 commit comments

Comments
 (0)