fix: avoid ctx.log in gsd provider error recovery

This commit is contained in:
Flux Labs 2026-03-15 09:22:07 -05:00
parent 8b7b8bc651
commit 967429cf29
3 changed files with 43 additions and 2 deletions

View file

@ -53,6 +53,7 @@ import { join } from "node:path";
import { existsSync } from "node:fs";
import { shortcutDesc } from "../shared/terminal.js";
import { Text } from "@gsd/pi-tui";
import { pauseAutoForProviderError } from "./provider-error-pause.js";
// ── Depth verification state ──────────────────────────────────────────────
let depthVerificationDone = false;
@ -385,8 +386,7 @@ export default function (pi: ExtensionAPI) {
}
}
(ctx as any).log(`Auto-mode paused due to provider error${errorDetail}`);
await pauseAuto(ctx, pi);
await pauseAutoForProviderError(ctx.ui, errorDetail, () => pauseAuto(ctx, pi));
return;
}

View file

@ -0,0 +1,12 @@
export type ProviderErrorPauseUI = {
notify(message: string, level: string): void;
};
export async function pauseAutoForProviderError(
ui: ProviderErrorPauseUI,
errorDetail: string,
pause: () => Promise<void>,
): Promise<void> {
ui.notify(`Auto-mode paused due to provider error${errorDetail}`, "warning");
await pause();
}

View file

@ -0,0 +1,29 @@
import test from "node:test";
import assert from "node:assert/strict";
import { pauseAutoForProviderError } from "../provider-error-pause.ts";
test("pauseAutoForProviderError warns and pauses without requiring ctx.log", async () => {
const notifications: Array<{ message: string; level: string }> = [];
let pauseCalls = 0;
await pauseAutoForProviderError(
{
notify(message, level) {
notifications.push({ message, level });
},
},
": terminated",
async () => {
pauseCalls += 1;
},
);
assert.equal(pauseCalls, 1, "should pause auto-mode exactly once");
assert.deepEqual(notifications, [
{
message: "Auto-mode paused due to provider error: terminated",
level: "warning",
},
]);
});