@juicesharp/rpiv-workflow 1.19.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -8
- package/api.ts +18 -703
- package/audit-ctx.ts +103 -0
- package/audit-rows.ts +154 -0
- package/audit.ts +158 -190
- package/built-ins.ts +40 -45
- package/chain-state.ts +220 -0
- package/command-run.ts +64 -31
- package/command.ts +123 -21
- package/docs/workflow-authoring.md +356 -63
- package/{lifecycle.ts → events.ts} +161 -37
- package/execution-host.ts +75 -0
- package/host.ts +149 -64
- package/index.ts +25 -81
- package/internal-utils.ts +171 -71
- package/internal.ts +22 -1
- package/judge.ts +241 -0
- package/layers.ts +10 -15
- package/load/alias.ts +6 -12
- package/load/cache.ts +9 -6
- package/load/index.ts +27 -106
- package/load/issues.ts +31 -0
- package/load/legacy.ts +102 -0
- package/load/merge.ts +2 -2
- package/load/resolve-default.ts +3 -4
- package/load/shape-guards.ts +3 -6
- package/load/skill-contract-phase.ts +94 -0
- package/loop-constructors.ts +24 -0
- package/loop-def.ts +285 -0
- package/loop-kinds.ts +750 -0
- package/loop-parallel.ts +250 -0
- package/loop-waves.ts +99 -0
- package/loop.ts +330 -0
- package/loops/constructors.ts +334 -0
- package/loops/derivations.ts +65 -0
- package/loops/introspection.ts +184 -0
- package/loops/panel.ts +196 -0
- package/loops/verify.ts +99 -0
- package/messages.ts +249 -156
- package/outcomes/collectors/directory-path.ts +7 -3
- package/outcomes/collectors/index.ts +1 -0
- package/outcomes/collectors/require-opt.ts +11 -0
- package/outcomes/collectors/text-scan.ts +47 -0
- package/outcomes/collectors/tool-call.ts +8 -3
- package/outcomes/collectors/transcript-path.ts +4 -18
- package/outcomes/collectors/union.ts +30 -10
- package/outcomes/collectors/url.ts +9 -14
- package/outcomes/collectors/workspace-diff.ts +21 -14
- package/outcomes/exec.ts +17 -0
- package/outcomes/git-commit.ts +190 -100
- package/outcomes/index.ts +1 -0
- package/outcomes/parsers/json-body.ts +2 -2
- package/outcomes/side-effect.ts +3 -3
- package/output-spec.ts +36 -10
- package/output.ts +98 -20
- package/package.json +27 -11
- package/predicates.ts +11 -8
- package/preview.ts +81 -21
- package/registration.ts +117 -36
- package/routing-dsl.ts +322 -0
- package/routing.ts +48 -2
- package/runner/by-name.ts +2 -1
- package/runner/by-run-id.ts +2 -1
- package/runner/chain-advance.ts +84 -56
- package/runner/errors.ts +10 -0
- package/runner/failure.ts +163 -0
- package/runner/index.ts +7 -13
- package/runner/input-validation.ts +16 -23
- package/runner/preflight.ts +169 -0
- package/runner/resolve-stage.ts +68 -0
- package/runner/resume-entry.ts +121 -0
- package/runner/resume-loop.ts +131 -0
- package/runner/resume.ts +368 -262
- package/runner/run-context.ts +165 -0
- package/runner/run-stage.ts +490 -0
- package/runner/runner.ts +202 -449
- package/runner/script-stage.ts +104 -112
- package/schema-compat.ts +12 -1
- package/semaphore.ts +55 -0
- package/sessions/extraction.ts +146 -81
- package/sessions/halt-routing.ts +195 -0
- package/sessions/index.ts +3 -1
- package/sessions/locate.ts +141 -0
- package/sessions/reattach.ts +71 -0
- package/sessions/sessions.ts +114 -199
- package/sessions/spawn.ts +132 -119
- package/sessions/success-persist.ts +89 -0
- package/skill-contract.ts +22 -25
- package/skill-contracts/composition.ts +86 -37
- package/skill-contracts/{registries.ts → extension-points.ts} +45 -12
- package/skill-contracts/harvest.ts +4 -4
- package/skill-contracts/index.ts +15 -8
- package/skill-contracts/registry.ts +33 -50
- package/stage-def.ts +595 -0
- package/stage-errors.ts +84 -0
- package/stage-identity.ts +56 -0
- package/startup.ts +4 -1
- package/state/index.ts +8 -1
- package/state/names.ts +91 -65
- package/state/paths.ts +20 -0
- package/state/raw.ts +77 -0
- package/state/reads.ts +103 -85
- package/state/resolve.ts +73 -0
- package/state/state.ts +135 -15
- package/state/writes.ts +29 -12
- package/transcript.ts +24 -0
- package/triggers.ts +11 -3
- package/types.ts +290 -78
- package/validate/contract-compat.ts +198 -0
- package/validate/graph.ts +134 -0
- package/validate/issue.ts +328 -0
- package/validate/stage-rules.ts +499 -0
- package/validate-output.ts +82 -7
- package/validate-workflow.ts +57 -759
- package/validation-bounds.ts +35 -0
- package/control-flow.ts +0 -135
- package/fanout.ts +0 -102
- package/iterate.ts +0 -155
- package/load/cache.test.ts +0 -82
- package/load/shape-guards.test.ts +0 -74
- package/outcomes/collectors/directory-path.test.ts +0 -64
- package/outcomes/collectors/tool-call.test.ts +0 -110
- package/outcomes/collectors/transcript-path.test.ts +0 -70
- package/outcomes/collectors/union.test.ts +0 -59
- package/outcomes/collectors/url.test.ts +0 -67
- package/outcomes/collectors/workspace-diff.test.ts +0 -107
- package/outcomes/git-commit.test.ts +0 -194
- package/outcomes/parsers/json-body.test.ts +0 -80
- package/runner/by-name.test.ts +0 -95
- package/runner/by-run-id.test.ts +0 -115
- package/runner/resume-fanout.test.ts +0 -331
- package/runner/resume-fanout.ts +0 -136
- package/runner/resume-iterate.test.ts +0 -444
- package/runner/resume-iterate.ts +0 -111
- package/runner/resume.test.ts +0 -1130
- package/runner/stage-lifecycle.ts +0 -500
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stage resolution — derive a stage's dispatch identity ONCE, at the top of
|
|
3
|
+
* `runStage`, so the rest of the pipeline switches on data instead of
|
|
4
|
+
* re-probing the def's optional slots (`loop`/`verify`/`run`/`prompt`). The
|
|
5
|
+
* old probe-the-optionals ladder needed a "slot ordering (load-bearing)"
|
|
6
|
+
* comment; the ordering now lives in exactly one place (`stageModeOf`).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { LoopDef, StageDef } from "../api.js";
|
|
10
|
+
import { resolveSkill } from "../chain-state.js";
|
|
11
|
+
import { effectiveLoopOf } from "../loop-constructors.js";
|
|
12
|
+
import type { RunContext } from "../types.js";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* How a stage's BODY is dispatched:
|
|
16
|
+
* - `"script"` — `def.run` is called directly (no session).
|
|
17
|
+
* - `"prompt"` — author-owned raw text is sent (no `/skill:` prefix).
|
|
18
|
+
* - `"skill"` — `/skill:<skill> <args>` is sent.
|
|
19
|
+
* Loop stages dispatch each unit with this same body mode (script is
|
|
20
|
+
* load-rejected on loop stages, so loop bodies are prompt or skill).
|
|
21
|
+
*/
|
|
22
|
+
export type StageDispatch = "script" | "prompt" | "skill";
|
|
23
|
+
|
|
24
|
+
/** The top-level dispatch slot `runStage` switches on. */
|
|
25
|
+
export type StageMode = "loop" | StageDispatch;
|
|
26
|
+
|
|
27
|
+
export interface ResolvedStage {
|
|
28
|
+
def: StageDef;
|
|
29
|
+
name: string;
|
|
30
|
+
/** 1-based; for status line + audit row. */
|
|
31
|
+
stageNumber: number;
|
|
32
|
+
/** Label written to JSONL + the status line. */
|
|
33
|
+
skill: string;
|
|
34
|
+
/** Top-level dispatch slot — `"loop"` wins over the body mode. */
|
|
35
|
+
mode: StageMode;
|
|
36
|
+
/** Body dispatch — what one activation (or loop unit) actually sends/runs. */
|
|
37
|
+
dispatch: StageDispatch;
|
|
38
|
+
/** The effective loop spec (incl. a verify desugar); set iff `mode === "loop"`. */
|
|
39
|
+
loop?: LoopDef;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The ONE slot-priority rule: loop (incl. verify desugar) > script > prompt > skill. */
|
|
43
|
+
function dispatchOf(def: StageDef): StageDispatch {
|
|
44
|
+
if (def.run) return "script";
|
|
45
|
+
if (def.prompt !== undefined) return "prompt";
|
|
46
|
+
return "skill";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function resolveStage(currentName: string, idx: number, run: RunContext): ResolvedStage {
|
|
50
|
+
const def = run.workflow.stages[currentName];
|
|
51
|
+
if (!def) {
|
|
52
|
+
// validateWorkflow should catch this; defensive for tests bypassing validation.
|
|
53
|
+
throw new Error(`runStage: stage "${currentName}" referenced by edges but missing from workflow.stages`);
|
|
54
|
+
}
|
|
55
|
+
const loop = effectiveLoopOf(def);
|
|
56
|
+
const dispatch = dispatchOf(def);
|
|
57
|
+
// `skill` defaults to the record key; `resolveSkill` is the shared derivation
|
|
58
|
+
// the load-time contract lookups also use, so runtime and load can't disagree.
|
|
59
|
+
return {
|
|
60
|
+
def,
|
|
61
|
+
name: currentName,
|
|
62
|
+
stageNumber: idx + 1,
|
|
63
|
+
skill: resolveSkill(def, currentName),
|
|
64
|
+
mode: loop ? "loop" : dispatch,
|
|
65
|
+
dispatch,
|
|
66
|
+
loop,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resume entry selection — translate a reconstructed trail (`resume.ts`)
|
|
3
|
+
* into the chain re-entry thunk `resumeWorkflow` hands to `executeRun`, plus
|
|
4
|
+
* the refusal-reason rendering for a reconstruct that declined. Companion to
|
|
5
|
+
* `resume-loop.ts` (which owns the loop-trailer arm's dispatch).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
ERR_RESUME_MALFORMED_ROW,
|
|
10
|
+
ERR_RESUME_NO_ROWS,
|
|
11
|
+
ERR_RESUME_STAGE_GONE,
|
|
12
|
+
ERR_RESUME_VERSION_MISMATCH,
|
|
13
|
+
} from "../messages.js";
|
|
14
|
+
import { STATE_SCHEMA_VERSION } from "../state/index.js";
|
|
15
|
+
import type { RunContext, WorkflowHostContext } from "../types.js";
|
|
16
|
+
import { recordEntryThrow } from "./failure.js";
|
|
17
|
+
import type { ReconstructResult } from "./resume.js";
|
|
18
|
+
import { recordLoopDriftFailure, resumeLoopStage } from "./resume-loop.js";
|
|
19
|
+
import { advance, buildLoopDeps, resumeStageWithSession, runStageOrRecordFailure } from "./run-stage.js";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Pick the chain re-entry thunk from the trail trailer. Dispatch keys on the
|
|
23
|
+
* STRUCTURED `parent` field — no string matching, no per-primitive arms:
|
|
24
|
+
* - fold-detected drift → record the parent-attributed terminal failure
|
|
25
|
+
* (zero dispatch; lifecycle bracketing identical to every other entry);
|
|
26
|
+
* - trailing unit row → re-enter the loop with the fold's cursor;
|
|
27
|
+
* - completed normal trailer → route onward (finished run hits stop ⇒ no-op);
|
|
28
|
+
* - failed/aborted trailer → session-backed rows try promotion/reattach
|
|
29
|
+
* (`resumeStageWithSession`); sessionless rows re-run cold (today's
|
|
30
|
+
* behavior). Dispatch keys on the STRUCTURED `session` field, mirroring
|
|
31
|
+
* the `parent !== undefined` arm.
|
|
32
|
+
*/
|
|
33
|
+
export function selectResumeEntry(
|
|
34
|
+
ctx: WorkflowHostContext,
|
|
35
|
+
recon: Extract<ReconstructResult, { ok: true }>,
|
|
36
|
+
run: RunContext,
|
|
37
|
+
): () => Promise<unknown> {
|
|
38
|
+
if (recon.drift) {
|
|
39
|
+
const { parent, errMsg } = recon.drift;
|
|
40
|
+
return () => recordLoopDriftFailure(ctx, run, parent, errMsg);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// The fold's reconstructed chain index — NOT `stageNumber - 1`: the
|
|
44
|
+
// allocator counts every row including loop units, so past any loop the
|
|
45
|
+
// two diverge (a 10-unit loop would resume showing "stage 14/5").
|
|
46
|
+
const last = recon.rows[recon.rows.length - 1]!;
|
|
47
|
+
const idx = recon.lastChainIndex; // status-line / routing index; JSONL number comes from the allocator
|
|
48
|
+
|
|
49
|
+
if (last.parent !== undefined) {
|
|
50
|
+
// `recon.trailing` is set by construction: the fold always produces a
|
|
51
|
+
// trailing point for an open generation, and a unit-row trailer means
|
|
52
|
+
// the generation is open.
|
|
53
|
+
return () =>
|
|
54
|
+
guardResumeEntry(ctx, last.parent!, run, () =>
|
|
55
|
+
resumeLoopStage(ctx, recon.trailing!, idx, run, buildLoopDeps()),
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
if (recon.trailing && recon.trailing.parent === last.stage) {
|
|
59
|
+
// Open FANOUT generation whose trailer is its OWN parent-unset abort/halt
|
|
60
|
+
// stage row (a mid-flight abort). The fold keeps the generation open for
|
|
61
|
+
// exactly this case (see resume.ts), so `recon.trailing` carries the
|
|
62
|
+
// completed-unit slots — re-enter the loop to replay them and dispatch
|
|
63
|
+
// only the pending units (finding 7). Without this arm the aborted trailer
|
|
64
|
+
// falls through to the cold stage re-run below and re-dispatches EVERY
|
|
65
|
+
// unit, duplicating the channel and collapsing the downstream fan-in.
|
|
66
|
+
return () =>
|
|
67
|
+
guardResumeEntry(ctx, last.stage, run, () => resumeLoopStage(ctx, recon.trailing!, idx, run, buildLoopDeps()));
|
|
68
|
+
}
|
|
69
|
+
if (last.status === "completed") {
|
|
70
|
+
// c2 no-op path: a fully-completed run routes onward from its last stage,
|
|
71
|
+
// which hits `stop` ⇒ `finalizeWorkflow` ⇒ success. The walk runs the
|
|
72
|
+
// normal lifecycle bracket (onWorkflowStart/onWorkflowEnd) but dispatches
|
|
73
|
+
// no stage session — no stage re-run, no child spawned, zero new JSONL
|
|
74
|
+
// stage rows. This is the safe no-op behind resuming a finished run via
|
|
75
|
+
// @<runId>.
|
|
76
|
+
return () => guardResumeEntry(ctx, last.stage, run, () => advance(ctx, last.stage, idx, run));
|
|
77
|
+
}
|
|
78
|
+
// failed/aborted trailer — the c2 boundary. Re-attempting this stage is
|
|
79
|
+
// intentional and the core resume retry use case: session-backed rows try
|
|
80
|
+
// promotion/reattach (`resumeStageWithSession`), sessionless rows re-run cold
|
|
81
|
+
// (today's behavior). Deliberately OUTSIDE c2's no-op guarantee — a new stage
|
|
82
|
+
// row IS appended and the stage re-runs (see the completed-vs-failed boundary
|
|
83
|
+
// tests in resume.test.ts).
|
|
84
|
+
return last.session !== null
|
|
85
|
+
? () => resumeStageWithSession(ctx, last, idx, run)
|
|
86
|
+
: () => runStageOrRecordFailure(ctx, last.stage, idx, run);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Resume-entry counterpart of `runStageOrRecordFailure`'s catch. The live
|
|
91
|
+
* chain reaches user fns (loop `next`/`done`/`feedForward`, judge prompts,
|
|
92
|
+
* route predicates) only under that catch; the resume-loop and route-onward
|
|
93
|
+
* entry thunks call the same fns directly, so a throw would otherwise escape
|
|
94
|
+
* `executeRun` as a raw rejection — `onWorkflowEnd` never fires and the
|
|
95
|
+
* caller loses the result envelope.
|
|
96
|
+
*/
|
|
97
|
+
async function guardResumeEntry(
|
|
98
|
+
curCtx: WorkflowHostContext,
|
|
99
|
+
name: string,
|
|
100
|
+
run: RunContext,
|
|
101
|
+
entry: () => Promise<unknown>,
|
|
102
|
+
): Promise<void> {
|
|
103
|
+
try {
|
|
104
|
+
await entry();
|
|
105
|
+
} catch (e) {
|
|
106
|
+
await recordEntryThrow(curCtx, name, run, e);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function resumeRefusalError(recon: Extract<ReconstructResult, { ok: false }>, workflow: string): string {
|
|
111
|
+
switch (recon.reason) {
|
|
112
|
+
case "no-rows":
|
|
113
|
+
return ERR_RESUME_NO_ROWS(recon.detail);
|
|
114
|
+
case "stage-gone":
|
|
115
|
+
return ERR_RESUME_STAGE_GONE(recon.detail, workflow);
|
|
116
|
+
case "malformed-row":
|
|
117
|
+
return ERR_RESUME_MALFORMED_ROW(recon.detail);
|
|
118
|
+
case "version-mismatch":
|
|
119
|
+
return ERR_RESUME_VERSION_MISMATCH(recon.detail, STATE_SCHEMA_VERSION);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loop-resume dispatch. When a resumed run's trail trailer is a loop-unit
|
|
3
|
+
* row (`row.parent` set), `resumeWorkflow` routes here. The fold already
|
|
4
|
+
* verified EVERY unit row (full-row drift guard) and reconstructed the
|
|
5
|
+
* driver's own `LoopCursor`, so re-entry is: derive the frozen entry arg,
|
|
6
|
+
* announce iff work is pending, hand the cursor back to `runLoop`.
|
|
7
|
+
*
|
|
8
|
+
* All four assess pending paths fall out of `pullNext` with the
|
|
9
|
+
* reconstructed cursor — pending judge (grade without re-running the
|
|
10
|
+
* producer), pending produce with a recovered verdict (feedForward, no
|
|
11
|
+
* re-grade), done-verdict fast advance, and round-0 re-run — zero special
|
|
12
|
+
* cases here.
|
|
13
|
+
*
|
|
14
|
+
* The finished-loop resume is a pinned SILENT no-op: no onStageStart /
|
|
15
|
+
* onLoopStart re-fire, no toast (the driver's `ranThisInvocation` rule keeps
|
|
16
|
+
* the banner off; `hasPendingUnit` keeps the announce off). The iterate
|
|
17
|
+
* probe pull is the documented harmless deterministic double-pull.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { auditCtxFor, failedArgs, recordTerminalFailure } from "../audit.js";
|
|
21
|
+
import { resolveSkill } from "../chain-state.js";
|
|
22
|
+
import { announceLoopStart, pendingFanoutIndices, runFanoutResume, runLoop } from "../loop.js";
|
|
23
|
+
import { effectiveLoopOf, freezesEntryArgsOf } from "../loop-constructors.js";
|
|
24
|
+
import { buildLoopEntry, type LoopDeps, sequentialStrategyOf } from "../loop-kinds.js";
|
|
25
|
+
import { validateUnitDeps } from "../loop-waves.js";
|
|
26
|
+
import { FAIL_MISSING_ARTIFACT, type FailureText, MSG_RESUME_LOOP_MISMATCH } from "../messages.js";
|
|
27
|
+
import type { RunContext, WorkflowHostContext } from "../types.js";
|
|
28
|
+
import type { LoopResumePoint } from "./resume.js";
|
|
29
|
+
|
|
30
|
+
export async function resumeLoopStage(
|
|
31
|
+
ctx: WorkflowHostContext,
|
|
32
|
+
point: LoopResumePoint,
|
|
33
|
+
idx: number,
|
|
34
|
+
run: RunContext,
|
|
35
|
+
deps: LoopDeps,
|
|
36
|
+
): Promise<void> {
|
|
37
|
+
const def = run.workflow.stages[point.parent]!; // fold verified the parent carries a loop (or verify)
|
|
38
|
+
const loop = effectiveLoopOf(def)!;
|
|
39
|
+
const skill = resolveSkill(def, point.parent);
|
|
40
|
+
|
|
41
|
+
// Round-0 producer arg (assess-kind only), FROZEN by the fold at generation
|
|
42
|
+
// open — never re-derived from post-fold state, so neither a trailing judge
|
|
43
|
+
// row's transient roll nor the generation's own named appends can leak into
|
|
44
|
+
// it. `undefined` means the trail no longer carries the rows that published
|
|
45
|
+
// this stage's inputs — recorded refusal with the forward preflight's
|
|
46
|
+
// messages (today's posture, now covering `reads` projections too). A
|
|
47
|
+
// prompt-dispatch stage never refuses here: the authority freezes `""` (no
|
|
48
|
+
// skill args exist) and the driver re-resolves the stage's own `prompt` at
|
|
49
|
+
// round-0 dispatch.
|
|
50
|
+
let entryArgs = "";
|
|
51
|
+
if (freezesEntryArgsOf(loop)) {
|
|
52
|
+
if (point.entryArgs === undefined) {
|
|
53
|
+
await recordMissingArtifactFailure(ctx, run, point.parent, skill, idx);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
entryArgs = point.entryArgs;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const entry = buildLoopEntry(
|
|
60
|
+
{ stageIdx: idx, name: point.parent, skill, def, loop },
|
|
61
|
+
{
|
|
62
|
+
entryArtifact: point.entryArtifact,
|
|
63
|
+
entryArgs,
|
|
64
|
+
entryPair: point.entryPair,
|
|
65
|
+
units: point.units, // fanout: the fold's recomputed-and-verified list — no second compute
|
|
66
|
+
},
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
// Fanout resume re-dispatches ONLY the still-unfilled indices in bounded
|
|
70
|
+
// parallel (folding each at its declared slot) — never a cold whole-loop
|
|
71
|
+
// re-entry, so already-completed/collected units keep their place.
|
|
72
|
+
if (loop.kind === "fanout") {
|
|
73
|
+
// Re-validate the recomputed DAG: the id-only drift guard PASSES when a user edits
|
|
74
|
+
// only a slice's `deps` (ids/titles unchanged), so a newly-introduced cycle would
|
|
75
|
+
// otherwise reach the dispatcher. guardResumeEntry catches this throw → clean failure.
|
|
76
|
+
validateUnitDeps(point.units!, point.parent);
|
|
77
|
+
const pending = pendingFanoutIndices(point.cursor, point.units!.length); // slots === undefined
|
|
78
|
+
if (pending.length > 0) await announceLoopStart(ctx, run, entry);
|
|
79
|
+
await runFanoutResume(ctx, entry, point.cursor, run, deps, pending);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (await sequentialStrategyOf(loop.kind).hasPending(loop, point, run)) await announceLoopStart(ctx, run, entry);
|
|
84
|
+
|
|
85
|
+
await runLoop(ctx, entry, point.cursor, run, deps);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* One refusal recorder — the shared 3-step body for the two resume recorders
|
|
90
|
+
* (`recordMissingArtifactFailure` / `recordLoopDriftFailure`): resolve the
|
|
91
|
+
* terminal args + build the audit ctx + `recordTerminalFailure`. Each caller
|
|
92
|
+
* supplies its own descriptor — a `FailureText` (missing-artifact) or a
|
|
93
|
+
* `[notifyMsg, errMsg]` tuple (loop drift).
|
|
94
|
+
*/
|
|
95
|
+
function recordResumeRefusal(
|
|
96
|
+
ctx: WorkflowHostContext,
|
|
97
|
+
run: RunContext,
|
|
98
|
+
parent: string,
|
|
99
|
+
skill: string,
|
|
100
|
+
descriptor: FailureText | [notifyMsg: string, errMsg: string],
|
|
101
|
+
): Promise<void> {
|
|
102
|
+
const args = Array.isArray(descriptor) ? failedArgs(descriptor[0], descriptor[1]) : failedArgs(descriptor);
|
|
103
|
+
return recordTerminalFailure(ctx, auditCtxFor(run, parent, skill), args);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Recorded refusal for a corrupted/truncated trail (reuses the forward preflight's messages). */
|
|
107
|
+
function recordMissingArtifactFailure(
|
|
108
|
+
ctx: WorkflowHostContext,
|
|
109
|
+
run: RunContext,
|
|
110
|
+
parent: string,
|
|
111
|
+
skill: string,
|
|
112
|
+
idx: number,
|
|
113
|
+
): Promise<void> {
|
|
114
|
+
return recordResumeRefusal(ctx, run, parent, skill, FAIL_MISSING_ARTIFACT(skill, idx + 1));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Recorded terminal failure for a fold-detected drift (or a generator throw
|
|
119
|
+
* during the fold). Parent-attributed failed row, zero dispatch — used as
|
|
120
|
+
* the resume ENTRY thunk so lifecycle bracketing (onWorkflowStart/End)
|
|
121
|
+
* matches every other resume outcome.
|
|
122
|
+
*/
|
|
123
|
+
export function recordLoopDriftFailure(
|
|
124
|
+
ctx: WorkflowHostContext,
|
|
125
|
+
run: RunContext,
|
|
126
|
+
parent: string,
|
|
127
|
+
errMsg: string,
|
|
128
|
+
): Promise<void> {
|
|
129
|
+
const skill = resolveSkill(run.workflow.stages[parent]!, parent);
|
|
130
|
+
return recordResumeRefusal(ctx, run, parent, skill, [MSG_RESUME_LOOP_MISMATCH(parent), errMsg]);
|
|
131
|
+
}
|