repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

fix(ultra): normalize remaining runner failures

bd0e07745a43037345bd40f5ccb7de83da7dd687

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (7)

extensions/ultra/README.md

Modified
95 95 | -------------------------- | ------- | -------------------------------------------------- |
96 96 | `ultra.enabled` | `true` | When false, the tool + command refuse to run. |
97 97 | `ultra.concurrency` | `5` | Max concurrent sub-agents in a `fanout` phase. |
98 -| `ultra.maxRetries` | `2` | Schema-validation retries per step. |
98 +| `ultra.maxRetries` | `2` | Tool-less transport/output retries per step. |
99 99 | `ultra.subagentExtensions` | `"all"` | Load host extensions into sub-agents, or not. |
100 100 | `ultra.modelTiers` | `{}` | Optional `small` / `medium` / `big` model aliases. |

extensions/ultra/__tests__/runner.test.ts

Modified
341 341 expect(resolveModel).toHaveBeenCalledWith(undefined);
344 + it("normalizes model and auth resolver exceptions", async () => {
345 + const modelFailure = await runStep(
346 + toollessStep,
347 + makeCtx(),
348 + makeDrivers({
349 + resolveModel: vi.fn(() => {
350 + throw new Error("model exploded");
351 + }),
352 + }),
353 + baseOpts(),
354 + );
355 + expect(modelFailure).toMatchObject({
356 + ok: false,
357 + failure: { code: "session", message: "model exploded", attempts: 0 },
358 + });
360 + const authFailure = await runStep(
361 + toollessStep,
362 + makeCtx(),
363 + makeDrivers({
364 + resolveAuth: vi.fn(async () => {
365 + throw new Error("auth exploded");
366 + }),
367 + }),
368 + baseOpts(),
369 + );
370 + expect(authFailure).toMatchObject({
371 + ok: false,
372 + failure: { code: "auth", message: "auth exploded", attempts: 0 },
373 + });
374 + });
344 376 it("drops before calling completeFn when auth is unavailable", async () => {
345 377 const completeFn = vi.fn(
346 378 async (): Promise<CompleteResponse> => ({ text: "{}" }),
892 - it("normalizes session creation and prompt exceptions", async () => {
924 + it("normalizes tool model, session-manager, creation, and prompt exceptions", async () => {
925 + const model = await runStep(
926 + toolStep,
927 + makeCtx(),
928 + makeDrivers({
929 + resolveModel: vi.fn(() => {
930 + throw new Error("tool model exploded");
931 + }),
932 + }),
933 + baseOpts(),
934 + );
935 + expect(model).toMatchObject({
936 + ok: false,
937 + failure: { code: "session", message: "tool model exploded", attempts: 0 },
938 + });
940 + const manager = await runStep(
941 + toolStep,
943 + newSessionManager: () => {
944 + throw new Error("manager exploded");
945 + },
946 + },
947 + makeDrivers(),
948 + baseOpts(),
949 + );
950 + expect(manager).toMatchObject({
951 + ok: false,
952 + failure: { code: "session", message: "manager exploded", attempts: 0 },
953 + });
893 955 const creation = await runStep(
894 956 toolStep,
895 957 makeCtx(),

extensions/ultra/__tests__/ui.test.ts

Modified
234 234 phase: "review",
235 235 kind: "end",
236 236 status: "failed",
237 + item: { task: "scope" },
237 238 failure: {
238 239 code: "transport",
239 240 message: "rate limited",
270 271 expect(out).toContain("dropped");
271 272 expect(out).toContain("transport: rate limited");
272 273 expect(out).toContain("retryable · 2 attempts");
274 + expect(out).toContain('item {"task":"scope"}');
273 275 expect(out).toContain("bounded bad response");
274 276 // full live transcript bodies are NEVER rendered by the tool sink
275 277 expect(out).not.toContain("SECRET-TRANSCRIPT-BODY");

extensions/ultra/engine.ts

Modified
195 195 status: "dropped",
196 196 text: res.failure.message,
197 197 failure: res.failure,
198 + item,
200 201 return res;
228 229 status: "dropped",
229 230 text: failure.message,
230 231 failure,
232 + item,
232 234 dropped++;
233 235 values.push(null);

extensions/ultra/progress.ts

Modified
64 64 startedAt?: number;
65 65 usage?: TokenUsage;
66 66 failure?: StepFailure;
67 + item?: unknown;
67 68 /** Per-agent live controls (runner-bound; absent on the tool surface). */
68 69 controls?: AgentControls;
257 258 endedAt?: number;
258 259 usage?: TokenUsage;
259 260 failure?: StepFailure;
261 + item?: unknown;
260 262 /** Live controls (command overlay only); absent on tool-less / tool-surface rows. */
261 263 controls?: AgentControls;
412 414 endedAt: event.kind === "end" ? (base.endedAt ?? Date.now()) : base.endedAt,
413 415 usage: event.usage ?? base.usage,
414 416 failure: event.failure ?? base.failure,
417 + item: event.item ?? base.item,
415 418 controls: event.controls ?? base.controls,

extensions/ultra/runner.ts

Modified
495 495 tier: string | undefined,
496 496 ): Promise<RunStepResult> {
497 497 const startedAt = Date.now();
498 - const model = drivers.resolveModel(step.model);
498 + let model: unknown;
499 + try {
500 + model = drivers.resolveModel(step.model);
501 + } catch (error) {
502 + const message = error instanceof Error ? error.message : String(error);
503 + return finishComplete(
504 + opts,
505 + failed("session", message, true, 0, {
506 + model: step.model,
507 + thinkingLevel: step.thinkingLevel,
508 + }),
509 + );
499 511 const failureMeta = {
500 512 model: modelLabel(model, step.model),
501 513 thinkingLevel: step.thinkingLevel,
503 515 emitCompleteStart(opts, { tier, ...failureMeta, startedAt });
504 - const auth = await drivers.resolveAuth(model);
516 + let auth: ResolvedAuth;
517 + try {
518 + auth = await drivers.resolveAuth(model);
519 + } catch (error) {
520 + const message = error instanceof Error ? error.message : String(error);
521 + return finishComplete(opts, failed("auth", message, false, 0, failureMeta));
505 523 if (!auth.ok) {
506 524 return finishComplete(
580 598 status: result.ok ? "done" : "dropped",
581 599 text: result.ok ? undefined : result.failure.message,
582 600 failure: result.ok ? undefined : result.failure,
601 + item: opts.item,
583 602 usage: result.usage,
584 603 controls: NOOP_CONTROLS,
706 725 ): Promise<RunStepResult> {
707 726 const { agentId, phase, onProgress } = opts;
708 727 const startedAt = Date.now();
709 - const model = drivers.resolveModel(step.model);
728 + let model: unknown;
729 + try {
730 + model = drivers.resolveModel(step.model);
731 + } catch (error) {
732 + const message = error instanceof Error ? error.message : String(error);
733 + return failed("session", message, true, 0, {
734 + model: step.model,
735 + thinkingLevel: step.thinkingLevel,
736 + });
710 738 const meta = {
712 740 model: modelLabel(model, step.model),
742 - const sessionManager = ctxLike.newSessionManager();
743 770 let session: SessionLike | undefined;
744 771 let unsubscribe: () => void = () => {};
745 772 let usage: TokenUsage | undefined;
747 774 let manuallyAborted = false;
777 + const sessionManager = ctxLike.newSessionManager();
750 778 session = await drivers.sessionFactory({
751 779 model,
752 780 thinkingLevel: step.thinkingLevel,
823 851 const message = error instanceof Error ? error.message : String(error);
824 852 return failed("session", message, true, session ? 1 : 0, meta, transcript);
825 853 } finally {
826 - unsubscribe();
827 - session?.dispose();
854 + try {
855 + unsubscribe();
856 + } catch {}
857 + try {
858 + session?.dispose();
859 + } catch {}

extensions/ultra/ui.ts

Modified
140 140 label: "retry",
141 141 value: `${row.failure.retryable ? "retryable" : "terminal"} · ${row.failure.attempts} attempt${row.failure.attempts === 1 ? "" : "s"}`,
143 + if (row.item !== undefined)
144 + details.push({ label: "item", value: JSON.stringify(row.item) });
143 145 if (row.failure.transcriptTail)
144 146 details.push({ label: "tail", value: row.failure.transcriptTail });