pi-ext
bugabingas pi extensions
owned by bugabinga
fix(ultra): preserve failed runs and expose schemas
7ecff5c390a0fa867a68ae717bfd40f321093830
Oliver Krylow <o.krylow@isp-insoft.de> ·
SSH signature · not checked
Browse filesCompare with HEAD
Changed files (4)
extensions/ultra/__tests__/engine.test.ts
Modified 696 696 expect(res.tokenUsage.total).
toBe(
0);
699 + it(
"keeps a dropped journal incomplete so a later run reuses successful phases",
async ()
=> {
700 + const journal
= memoryJournal();
702 + return:
"{report.results}",
707 + step: { summary:
"Gather", prompt:
"Gather" },
712 + step: { summary:
"Report", prompt:
"Report" },
716 + const first
= fakeRunner((args)
=> 717 + args.phase
=== "gather" 718 + ? { ok:
true, value:
"evidence" }
719 + : failed(
"invalid report"),
725 + baseDeps({ stepRunner: first.runner, journal }),
728 + expect(journal.set).
toHaveBeenCalledTimes(
1);
729 + expect(journal.
complete).not.
toHaveBeenCalled();
731 + const resumed
= fakeRunner((args)
=> ({
733 + value:
`live-${args.phase}`,
735 + const result
= await runWorkflow(
738 + baseDeps({ stepRunner: resumed.runner, journal }),
741 + expect(resumed.calls.
map((call)
=> call.phase)).
toEqual([
"report"]);
742 + expect(result.result).
toEqual([
"live-report"]);
743 + expect(journal.
complete).
toHaveBeenCalledTimes(
1);
699 746 it(
"keeps an aborted journal incomplete so a later run reuses completed slots and runs missing slots",
async ()
=> {
700 747 const controller
= new AbortController();
701 748 const journal
= memoryJournal();
extensions/ultra/__tests__/runner.test.ts
Modified 247 247 expect(req.
headers).
toEqual({
"x-delete":
null,
"x-h":
"1" });
248 248 expect(req.model).
toEqual({ id:
"default-model" });
249 249 expect(req.messages[
0]).
toEqual({ role:
"user", content:
"do X" });
250 + expect(req.systemPrompt).
toContain(
251 + `The JSON object MUST match this schema:\n${JSON.stringify(VERDICT_SCHEMA)}`,
252 255 it(
"retries with a corrective message up to maxRetries, then drops to null + reason",
async ()
=> {
extensions/ultra/engine.ts
Modified308 308 : results[lastPhase.
id];
310 - if (
!deps.signal?.aborted)
await deps.journal?.
complete?.();
310 + if (
!deps.signal?.aborted
&& phases.
every((phase)
=> phase.dropped
=== 0))
311 + await deps.journal?.
complete?.();
313 314 workflow: spec.
name,
extensions/ultra/runner.ts
Modified491 - :
runCompleteStep(resolvedStep, drivers, opts, validator, tier);
491 + :
runCompleteStep(resolvedStep, drivers, opts, schemaObj, validator, tier);
498 498 drivers: StepDrivers,
499 499 opts: RunStepOptions,
500 + schemaObj: object
| undefined,
500 501 validator: CompiledValidator
| undefined,
501 502 tier: string
| undefined,
502 503 ):
Promise<RunStepResult
> {
554 - systemPrompt:
completeSystemPrompt(opts.systemPrompt),
555 + systemPrompt:
completeSystemPrompt(opts.systemPrompt, schemaObj),
555 556 signal: opts.signal,
614 -function completeSystemPrompt(extra
: string | undefined)
: string {
615 +function completeSystemPrompt(
616 + extra
: string | undefined,
617 + schemaObj
: object | undefined,
617 621 "Respond with ONLY a single JSON object — no prose, no markdown code fences.",
623 + ? `The JSON object MUST match this schema:\n${JSON.stringify(schemaObj)}`