pi-ext
bugabingas pi extensions
owned by bugabinga
fix(ultra): remove subagent timeouts
3ce30eaafcded80ef49d404651291420f2b5ea56
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
Browse filesCompare with HEAD
Changed files (13)
extensions/ultra/README.md
Modified 82 82 `<cwd>/settings.json` (later overriding earlier), with the runtime settings
85 -| Key | Default | Meaning |
86 -| -------------------------- | -------- | -------------------------------------------------- |
87 -| `ultra.enabled` | `true` | When false, the tool + command refuse to run. |
88 -| `ultra.concurrency` | `5` | Max concurrent sub-agents in a `fanout` phase. |
89 -| `ultra.maxRetries` | `2` | Schema-validation retries per step. |
90 -| `ultra.defaultTimeoutMs` | `180000` | Per-step timeout when a step omits `timeoutMs`. |
91 -| `ultra.subagentExtensions` | `"all"` | Load host extensions into sub-agents, or not. |
92 -| `ultra.modelTiers` | `{}` | Optional `small` / `medium` / `big` model aliases. |
85 +| Key | Default | Meaning |
86 +| -------------------------- | ------- | -------------------------------------------------- |
87 +| `ultra.enabled` | `true` | When false, the tool + command refuse to run. |
88 +| `ultra.concurrency` | `5` | Max concurrent sub-agents in a `fanout` phase. |
89 +| `ultra.maxRetries` | `2` | Schema-validation retries per step. |
90 +| `ultra.subagentExtensions` | `"all"` | Load host extensions into sub-agents, or not. |
91 +| `ultra.modelTiers` | `{}` | Optional `small` / `medium` / `big` model aliases. |
94 93 `ultra.modelTiers` maps workflow step `model` values of `small`, `medium`, or `big` to concrete model refs.
95 94 Unset tiers fall back to the session model.
extensions/ultra/__tests__/progress.test.ts
Modified253 253 pe({ agentId:
"a", phase:
"p1", kind:
"end", status:
"done" }),
254 254 pe({ agentId:
"b", phase:
"p1", kind:
"end", status:
"dropped" }),
255 - pe({ agentId:
"c", phase:
"p1", kind:
"end", status:
"timeout" }),
255 + pe({ agentId:
"c", phase:
"p1", kind:
"end", status:
"failed" }),
257 257 expect(s).
toMatchObject({ total:
3, done:
1, dropped:
2 });
extensions/ultra/__tests__/runner.test.ts
Modified 44 44 function baseOpts(over
: Partial<
RunStepOptions>
= {})
: RunStepOptions {
47 - defaultTimeoutMs:
1000,
49 48 agentId:
"review#0",
84 83 interface FakeSessionBehavior {
86 85 drive?: (api
: DriveApi)
=> Promise<
void>
| void;
490 489 expect(state.transcripts[
"review#0"]).
toContain(
"schema validation failed");
493 - it(
"times out a stalled completeFn → reason 'timeout'",
async ()
=> {
494 - const completeFn
= vi.
fn(()
=> new Promise<
CompleteResponse>(()
=> {}));
495 - const drivers
= makeDrivers({ completeFn });
492 + it(
"observes cancellation triggered while a completion starts",
async ()
=> {
493 + const controller
= new AbortController();
494 + const completeFn
= vi.
fn(()
=> {
495 + controller.
abort();
496 + return new Promise<
CompleteResponse>(()
=> {});
497 - const result
= await runStep(
499 + const result
= await Promise.
race([
503 + makeDrivers({ completeFn }),
504 + baseOpts({ signal: controller.signal }),
506 + new Promise<
"missed">((resolve)
=> 507 + setTimeout(()
=> resolve(
"missed"),
20),
511 + expect(result).
toEqual({ ok:
false, value:
null, reason:
"aborted" });
514 + it(
"lets a stalled completeFn run until it completes",
async ()
=> {
515 + let finish!: (value
: CompleteResponse)
=> void;
516 + const completeFn
= vi.
fn(
518 + new Promise<
CompleteResponse>((resolve)
=> {
522 + const pending
= runStep(
501 - baseOpts({ defaultTimeoutMs:
10 }),
525 + makeDrivers({ completeFn }),
528 + let settled
= false;
529 + void pending.
finally(()
=> {
504 - expect(result).
toEqual({ ok:
false, value:
null, reason:
"timeout" });
533 + await new Promise((resolve)
=> setTimeout(resolve,
20));
534 + expect(settled).
toBe(
false);
535 + finish({ text:
'{ "verdict": "ok" }' });
536 + await expect(pending).resolves.
toEqual({
538 + value: { verdict:
"ok" },
686 721 expect(harness.captured.spies?.dispose).
toHaveBeenCalledTimes(
1);
689 - it(
"times out a stalled session → reason 'timeout' and calls session.abort()",
async ()
=> {
690 - const harness
= makeSessionHarness({ hang:
true });
691 - const drivers
= makeDrivers({ sessionFactory: harness.factory });
693 - const result
= await runStep(
724 + it(
"lets a stalled session run until it completes",
async ()
=> {
725 + let release!: ()
=> void;
726 + const harness
= makeSessionHarness({
727 + drive:
async ({ emit, callStructured })
=> {
728 + await new Promise<
void>((resolve)
=> {
731 + await callStructured({ verdict:
"ok" });
732 + emit({ type:
"agent_end", messages: [], willRetry:
false });
735 + const pending
= runStep(
697 - baseOpts({ defaultTimeoutMs:
10 }),
738 + makeDrivers({ sessionFactory: harness.factory }),
741 + let settled
= false;
742 + void pending.
finally(()
=> {
700 - expect(result).
toEqual({ ok:
false, value:
null, reason:
"timeout" });
701 - expect(harness.captured.spies?.abort).
toHaveBeenCalledTimes(
1);
746 + await new Promise((resolve)
=> setTimeout(resolve,
20));
747 + expect(settled).
toBe(
false);
749 + await expect(pending).resolves.
toEqual({
751 + value: { verdict:
"ok" },
753 + expect(harness.captured.spies?.abort).not.
toHaveBeenCalled();
702 754 expect(harness.captured.spies?.unsubscribe).
toHaveBeenCalledTimes(
1);
703 755 expect(harness.captured.spies?.dispose).
toHaveBeenCalledTimes(
1);
715 - baseOpts({ signal: controller.signal, defaultTimeoutMs:
5000 }),
767 + baseOpts({ signal: controller.signal }),
718 770 await new Promise((r)
=> setTimeout(r,
0));
736 - baseOpts({ signal: AbortSignal.
abort(), defaultTimeoutMs:
5000 }),
788 + baseOpts({ signal: AbortSignal.
abort() }),
739 791 expect(result).
toEqual({ ok:
false, value:
null, reason:
"aborted" });
758 810 const runner
= makeStepRunner(drivers, ctx, {
760 - defaultTimeoutMs:
1000,
762 813 const result
= await runner({
763 814 step: toollessStep,
811 862 const runner
= makeStepRunner(drivers, ctx, {
813 - defaultTimeoutMs:
1000,
815 865 const result
= await runner({
extensions/ultra/__tests__/settings.test.ts
Modified 15 - defaultTimeoutMs:
180000,
16 15 subagentExtensions:
"all",
64 - defaultTimeoutMs:
5000,
66 64 small:
"openai/gpt-5-mini:low",
67 65 medium:
"anthropic/claude-sonnet-4",
77 - defaultTimeoutMs:
5000,
79 76 small:
"openai/gpt-5-mini:low",
80 77 medium:
"anthropic/claude-sonnet-4",
121 - defaultTimeoutMs:
180000,
122 118 subagentExtensions:
"all",
123 119 modelTiers: {
big:
"openai/gpt-5" },
147 - defaultTimeoutMs:
180000,
148 143 subagentExtensions:
"all",
extensions/ultra/__tests__/spec.test.ts
Modified154 154 expect(()
=> parseWorkflow(s)).
toThrow();
157 + it(
"rejects unknown step fields", ()
=> {
158 + const s
= validSpec();
159 + s.phases[
0].step.unknown
= true;
160 + expect(()
=> parseWorkflow(s)).
toThrow(
/additional properties/i);
157 163 it(
"throws a clear message when a step references an unknown schema name", ()
=> {
158 164 const s
= validSpec();
159 165 s.phases[
1].step.schema
= "Nonexistent";
extensions/ultra/__tests__/ui.test.ts
Modified129 129 const scripted
= stateFrom([
130 130 pe({ agentId:
"a", phase:
"review", kind:
"start" }),
142 142 text:
"SECRET-TRANSCRIPT-BODY",
144 144 pe({ agentId:
"b", phase:
"review", kind:
"start" }),
145 - pe({ agentId:
"b", phase:
"review", kind:
"end", status:
"timeout" }),
145 + pe({ agentId:
"b", phase:
"review", kind:
"end", status:
"failed" }),
148 148 it(
"collapsed: shows phase/agent counts + summary + expand hint, never bodies", ()
=> {
extensions/ultra/__tests__/wire.test.ts
Modified 51 - { ok:
false, value:
null, reason:
"timeout" },
51 + { ok:
false, value:
null, reason:
"provider error" },
75 75 expect(markdown).
toContain(
"# ultra review");
76 76 expect(markdown).
toContain(
"No final results");
77 77 expect(markdown).
toContain(
"review: 2/3 ok, 1 dropped");
78 - expect(markdown).
toContain(
"review#0: timeout");
78 + expect(markdown).
toContain(
"review#0: provider error");
79 79 expect(markdown).
toContain(
"Refuted findings");
80 80 expect(markdown).
toContain(
"possible issue");
81 81 expect(markdown).
toContain(
"not reproducible");
extensions/ultra/index.ts
Modified141 141 const baseOpts
: BaseStepOptions = {
142 142 maxRetries: cfg.maxRetries,
143 - defaultTimeoutMs: cfg.defaultTimeoutMs,
144 143 schemas: spec.schemas,
145 144 modelTiers: cfg.modelTiers,
extensions/ultra/progress.ts
Modified303 -const DROP_STATUSES
= new Set([
303 +const DROP_STATUSES
= new Set([
"dropped",
"error",
"aborted",
"failed"]);
311 305 function classifyEnd(status
: string | undefined)
: AgentStatus {
312 306 return status
!== undefined && DROP_STATUSES.
has(status)
? "dropped" : "done";
extensions/ultra/runner.ts
Modified162 162 export interface BaseStepOptions {
163 163 maxRetries
: number;
164 - defaultTimeoutMs
: number;
166 165 schemas
?: Record<
string,
object>;
359 358 type GuardOutcome<
T>
= 360 359 | { outcome
: "done"; value
: T; error
?: unknown }
361 - | { outcome
: "timeout" }
362 360 | { outcome
: "aborted" };
372 -async function raceGuards<
T>(
373 - work: (signal
: AbortSignal)
=> Promise<
T>,
368 +async function raceAbort<
T>(
369 + work: (signal
: AbortSignal | undefined)
=> Promise<
T>,
375 370 externalSignal
: AbortSignal | undefined,
376 371 )
: Promise<
GuardOutcome<
T>> {
377 372 if (externalSignal?.aborted)
return { outcome:
"aborted" };
379 - const controller
= new AbortController();
380 - let timeoutId
: ReturnType<
typeof setTimeout>
| undefined;
381 - let onAbort
: (()
=> void)
| undefined;
374 + const run = ()
: Promise<
GuardOutcome<
T>>
=> 375 + work(externalSignal).
then(
376 + (value)
=> ({ outcome:
"done", value })
as GuardOutcome<
T>,
384 + value:
undefined as unknown as T,
386 + })
as GuardOutcome<
T>,
388 + if (
!externalSignal)
return run();
383 - const guard
= new Promise<
GuardOutcome<
T>>((resolve)
=> {
384 - timeoutId
= setTimeout(()
=> {
385 - controller.
abort();
386 - resolve({ outcome:
"timeout" });
388 - if (externalSignal) {
390 - controller.
abort();
391 - resolve({ outcome:
"aborted" });
393 - externalSignal.
addEventListener(
"abort", onAbort, { once:
true });
390 + let onAbort!: ()
=> void;
391 + const aborted
= new Promise<
GuardOutcome<
T>>((resolve)
=> {
392 + onAbort = ()
=> resolve({ outcome:
"aborted" });
393 + externalSignal.
addEventListener(
"abort", onAbort, { once:
true });
397 - const workP
: Promise<
GuardOutcome<
T>>
= work(controller.signal).
then(
398 - (value)
=> ({ outcome:
"done", value })
as GuardOutcome<
T>,
406 - value:
undefined as unknown as T,
408 - })
as GuardOutcome<
T>,
395 + if (externalSignal.aborted)
onAbort();
412 - return await Promise.
race([workP, guard]);
397 + return await Promise.
race([
run(), aborted]);
414 - if (timeoutId)
clearTimeout(timeoutId);
415 - if (externalSignal
&& onAbort)
416 - externalSignal.
removeEventListener(
"abort", onAbort);
399 + externalSignal.
removeEventListener(
"abort", onAbort);
433 416 const validator
= schemaObj
434 417 ? (
compileSchema(schemaObj)
as CompiledValidator)
436 - const timeoutMs
= resolvedStep.timeoutMs
?? opts.defaultTimeoutMs;
437 419 const usesTools
= 438 420 Array.
isArray(resolvedStep.tools)
&& resolvedStep.tools.
length > 0;
451 - :
runCompleteStep(resolvedStep, drivers, opts, validator, timeoutMs, tier);
432 + :
runCompleteStep(resolvedStep, drivers, opts, validator, tier);
458 439 drivers: StepDrivers,
459 440 opts: RunStepOptions,
460 441 validator: CompiledValidator
| undefined,
462 442 tier: string
| undefined,
463 443 ):
Promise<RunStepResult
> {
464 444 const startedAt
= Date.
now();
491 471 systemPrompt:
completeSystemPrompt(opts.systemPrompt),
493 472 signal: opts.signal,
556 535 messages: CompleteMessage[];
557 536 validator: CompiledValidator
| undefined;
558 537 systemPrompt: string;
560 538 signal
?: AbortSignal;
563 541 async function completeAttempt(
564 542 input
: CompleteAttemptInput,
565 543 )
: Promise<
CompleteAttempt> {
566 - const guarded
= await raceGuards(
544 + const guarded
= await raceAbort(
568 546 input.drivers.
completeFn({
569 547 model: input.model,
573 551 headers: input.auth.
headers,
580 - if (guarded.outcome
=== "timeout")
583 - result: { ok:
false, value:
null, reason:
"timeout" },
585 557 if (guarded.outcome
=== "aborted")
654 626 opts: RunStepOptions,
655 627 schemaObj: object
| undefined,
656 628 validator: CompiledValidator
| undefined,
658 629 tier: string
| undefined,
659 630 ):
Promise<RunStepResult
> {
660 631 const { agentId, phase, onProgress }
= opts;
736 - const guarded
= await raceGuards(
707 + const guarded
= await raceAbort(
737 708 ()
=> live.
prompt(step.
prompt, { source:
"extension" }),
742 712 if (guarded.outcome
!== "done") {
745 715 await Promise.
resolve(live.
abort()).
catch(()
=> {});
746 716 return { ok:
false, value:
null, reason: guarded.outcome };
extensions/ultra/settings.ts
Modified 13 13 concurrency: number;
15 15 maxRetries: number;
17 - defaultTimeoutMs: number;
31 - defaultTimeoutMs:
180000,
32 29 subagentExtensions:
"all",
61 58 if (
typeof ultra.concurrency
=== "number")
62 59 out.concurrency
= ultra.concurrency;
63 60 if (
typeof ultra.maxRetries
=== "number") out.maxRetries
= ultra.maxRetries;
64 - if (
typeof ultra.defaultTimeoutMs
=== "number")
65 - out.defaultTimeoutMs
= ultra.defaultTimeoutMs;
66 61 if (ultra.subagentExtensions
=== "none" || ultra.subagentExtensions
=== "all")
67 62 out.subagentExtensions
= ultra.subagentExtensions;
68 63 const modelTiers
= pickModelTiers(ultra.modelTiers);
82 77 typeof p.concurrency
=== "number" ? p.concurrency
: into.concurrency,
84 79 typeof p.maxRetries
=== "number" ? p.maxRetries
: into.maxRetries,
86 - typeof p.defaultTimeoutMs
=== "number" 87 - ? p.defaultTimeoutMs
88 - : into.defaultTimeoutMs,
89 80 subagentExtensions:
90 81 p.subagentExtensions
=== "none" || p.subagentExtensions
=== "all" 91 82 ? p.subagentExtensions
extensions/ultra/skills/authoring-workflows/references/spec-format.md
Modified 59 59 | `model` | no | string | `provider/id` override, or configured tier `small`/`medium`/`big`; defaults to the session model. |
60 60 | `thinkingLevel` | no | off…xhigh | Reasoning budget for this step. |
61 61 | `schema` | no | string
\| JSON Schema | A `schemas` name, or an inline schema. Forces structured output. |
62 -| `timeoutMs` | no | number | Per-agent timeout. |
64 63 A string `schema` is a **name reference** and must resolve in the spec's
65 64 `schemas` map, or validation fails.
extensions/ultra/spec.ts
Modified 26 26 const StepSchemaRef
= Type.
Union([Type.
String(), JsonSchemaObject]);
28 -export const StepSchema
= Type.
Object({
29 - prompt: Type.
String(),
30 - tools: Type.
Optional(Type.
Array(Type.
String())),
31 - model: Type.
Optional(Type.
String()),
32 - thinkingLevel: Type.
Optional(ThinkingLevelSchema),
33 - schema: Type.
Optional(StepSchemaRef),
34 - timeoutMs: Type.
Optional(Type.
Number()),
28 +export const StepSchema
= Type.
Object(
30 + prompt: Type.
String(),
31 + tools: Type.
Optional(Type.
Array(Type.
String())),
32 + model: Type.
Optional(Type.
String()),
33 + thinkingLevel: Type.
Optional(ThinkingLevelSchema),
34 + schema: Type.
Optional(StepSchemaRef),
36 + { additionalProperties:
false },
38 40 const OverSchema
= Type.
Union([Type.
Array(Type.
Unknown()), Type.
String()]);