fix: surface reviewer response failures
This commit is contained in:
@@ -1,5 +1,19 @@
|
||||
import type { RpcClient } from "../rpc/rpc-client.js";
|
||||
|
||||
const GENERIC_MODEL_FAILURE =
|
||||
"Model request failed. Check provider connectivity, then Resume the session.";
|
||||
const SUBSCRIPTION_MODEL_FAILURE =
|
||||
"The selected model is unavailable for the current subscription. Choose another model and start a new session.";
|
||||
|
||||
function safeModelFailure(error: unknown): string {
|
||||
const detail = typeof error === "string" ? error : "";
|
||||
const isSubscriptionFailure =
|
||||
/\b429\b/.test(detail) &&
|
||||
/(subscription plan|code["':\s]+1311|does not yet include access)/i.test(detail);
|
||||
|
||||
return isSubscriptionFailure ? SUBSCRIPTION_MODEL_FAILURE : GENERIC_MODEL_FAILURE;
|
||||
}
|
||||
|
||||
export type ToolActivity = {
|
||||
kind: "tool";
|
||||
toolCallId: string;
|
||||
@@ -53,7 +67,7 @@ export class SessionBridge {
|
||||
this.fan({
|
||||
type: "info",
|
||||
level: "error",
|
||||
text: "Model request failed. Check provider connectivity, then Resume the session.",
|
||||
text: safeModelFailure(m.message.errorMessage),
|
||||
});
|
||||
}
|
||||
} else if (m.type === "extension_ui_request" && m.method === "notify") {
|
||||
|
||||
@@ -105,6 +105,30 @@ test("assistant provider errors are sanitized and leave the turn failed", () =>
|
||||
expect(JSON.stringify(seen)).not.toContain("DO_NOT_LEAK");
|
||||
});
|
||||
|
||||
test("subscription model errors become a safe actionable client message", () => {
|
||||
const { rpc, fire } = fakeRpc();
|
||||
const bridge = new SessionBridge(rpc);
|
||||
const seen: any[] = [];
|
||||
bridge.onClientEvent((event) => seen.push(event));
|
||||
|
||||
fire({
|
||||
type: "message_end",
|
||||
message: {
|
||||
role: "assistant",
|
||||
stopReason: "error",
|
||||
errorMessage: "429: {\"code\":\"1311\",\"message\":\"Your current subscription plan does not yet include access to GLM-5.3\",\"secret\":\"DO_NOT_LEAK\"}",
|
||||
},
|
||||
});
|
||||
|
||||
expect(seen).toContainEqual({
|
||||
type: "info",
|
||||
level: "error",
|
||||
text: "The selected model is unavailable for the current subscription. Choose another model and start a new session.",
|
||||
});
|
||||
expect(JSON.stringify(seen)).not.toContain("GLM-5.3");
|
||||
expect(JSON.stringify(seen)).not.toContain("DO_NOT_LEAK");
|
||||
});
|
||||
|
||||
test("markFailed records backend-detected failure without emitting raw detail", () => {
|
||||
const { rpc } = fakeRpc();
|
||||
const bridge = new SessionBridge(rpc);
|
||||
|
||||
Reference in New Issue
Block a user