owenloop 0.5.8 → 0.5.10
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/CHANGELOG.md +69 -0
- package/README.md +81 -39
- package/bin/owenloop.mjs +16 -1
- package/dist/packages/work/src/agent/loop.d.ts +23 -8
- package/dist/packages/work/src/agent/loop.js +55 -6
- package/dist/packages/work/src/bundle/pull.d.ts +21 -0
- package/dist/packages/work/src/bundle/pull.js +118 -0
- package/dist/packages/work/src/consumed-verifier.js +6 -17
- package/dist/packages/work/src/exec/instructions.d.ts +4 -1
- package/dist/packages/work/src/exec/instructions.js +3 -0
- package/dist/packages/work/src/exec/loop.d.ts +2 -2
- package/dist/packages/work/src/exec/loop.js +273 -46
- package/dist/packages/work/src/exec/receipt.d.ts +7 -7
- package/dist/packages/work/src/exec/receipt.js +6 -6
- package/dist/packages/work/src/harness/claude.js +116 -0
- package/dist/packages/work/src/harness/codex.d.ts +8 -0
- package/dist/packages/work/src/harness/codex.js +27 -1
- package/dist/packages/work/src/harness/contract.d.ts +9 -0
- package/dist/packages/work/src/hub/client.d.ts +19 -4
- package/dist/packages/work/src/hub/client.js +7 -3
- package/dist/packages/work/src/hub/types.d.ts +84 -0
- package/dist/packages/work/src/main.js +1 -0
- package/dist/packages/work/src/roles/agent-run.js +57 -32
- package/dist/packages/work/src/roles/exec.js +27 -8
- package/dist/packages/work/src/roles/settings.js +2 -0
- package/dist/packages/work/src/roles/shift.js +14 -2
- package/dist/packages/work/src/roles/util.d.ts +1 -0
- package/dist/packages/work/src/roles/util.js +10 -0
- package/dist/packages/work/src/settings/hub-roster-cache.d.ts +68 -0
- package/dist/packages/work/src/settings/hub-roster-cache.js +370 -0
- package/dist/packages/work/src/settings/roster.d.ts +84 -0
- package/dist/packages/work/src/settings/roster.js +364 -5
- package/dist/packages/work/src/settings/serving.d.ts +17 -0
- package/dist/packages/work/src/settings/serving.js +79 -0
- package/dist/packages/work/src/settings/settings.d.ts +14 -1
- package/dist/packages/work/src/settings/settings.js +14 -0
- package/dist/packages/work/src/shift/loop.d.ts +108 -5
- package/dist/packages/work/src/shift/loop.js +416 -54
- package/dist/packages/work/src/shift/protocol.d.ts +7 -5
- package/dist/packages/work/src/shift/runtime.d.ts +18 -0
- package/dist/packages/work/src/shift/runtime.js +104 -5
- package/dist/packages/work/src/shift/server.js +2 -0
- package/dist/packages/work/src/shift/spawn.d.ts +17 -2
- package/dist/packages/work/src/shift/spawn.js +16 -13
- package/dist/packages/work/src/shift/state.d.ts +29 -2
- package/dist/packages/work/src/shift/state.js +45 -15
- package/dist/packages/work/src/submit-proof.d.ts +11 -8
- package/dist/packages/work/src/submit-proof.js +11 -8
- package/dist/packages/work/src/usage.d.ts +1 -1
- package/dist/packages/work/src/usage.js +7 -1
- package/dist/packages/work/src/util/modifier-init.d.ts +7 -0
- package/dist/packages/work/src/util/modifier-init.js +73 -0
- package/dist/src/bundle/tar.d.ts +9 -4
- package/dist/src/bundle/tar.js +9 -4
- package/dist/src/capabilities.d.ts +76 -6
- package/dist/src/capabilities.js +49 -6
- package/dist/src/capability-mapping-client.d.ts +29 -0
- package/dist/src/capability-mapping-client.js +160 -0
- package/dist/src/cli.d.ts +16 -3
- package/dist/src/cli.js +1925 -281
- package/dist/src/config-dir.d.ts +1 -1
- package/dist/src/config-dir.js +1 -1
- package/dist/src/crypto/index.d.ts +1 -1
- package/dist/src/crypto/index.js +1 -1
- package/dist/src/crypto/org-root.d.ts +30 -12
- package/dist/src/crypto/org-root.js +162 -14
- package/dist/src/crypto/records.d.ts +2 -0
- package/dist/src/crypto/records.js +2 -0
- package/dist/src/defs.d.ts +38 -2
- package/dist/src/defs.js +593 -86
- package/dist/src/engine.d.ts +103 -25
- package/dist/src/engine.js +331 -79
- package/dist/src/hub.d.ts +77 -0
- package/dist/src/hub.js +162 -0
- package/dist/src/implements.d.ts +56 -0
- package/dist/src/implements.js +790 -0
- package/dist/src/index.d.ts +11 -9
- package/dist/src/index.js +6 -5
- package/dist/src/mcp/serve.d.ts +22 -0
- package/dist/src/mcp/serve.js +330 -41
- package/dist/src/mcp/server.d.ts +10 -7
- package/dist/src/mcp/server.js +53 -8
- package/dist/src/model.d.ts +48 -10
- package/dist/src/model.js +252 -99
- package/dist/src/order-resolver.d.ts +1 -0
- package/dist/src/order-resolver.js +8 -1
- package/dist/src/schemas/index.d.ts +11 -0
- package/dist/src/schemas/order.v1.schema.json +7 -1
- package/dist/src/store/def-source.d.ts +19 -0
- package/dist/src/store/def-source.js +87 -17
- package/dist/src/store/gc-recovery.d.ts +46 -0
- package/dist/src/store/gc-recovery.js +258 -0
- package/dist/src/store/gc.d.ts +94 -0
- package/dist/src/store/gc.js +562 -0
- package/dist/src/store/index.d.ts +3 -1
- package/dist/src/store/index.js +2 -0
- package/dist/src/store/install.d.ts +34 -5
- package/dist/src/store/install.js +73 -11
- package/dist/src/store/pre-commit-verifier.js +42 -2
- package/dist/src/store/snapshot-guard.d.ts +18 -0
- package/dist/src/store/snapshot-guard.js +94 -0
- package/dist/src/store.d.ts +69 -4
- package/dist/src/store.js +254 -16
- package/dist/src/types.d.ts +101 -20
- package/dist/src/util.js +4 -1
- package/docs/authoring.md +235 -10
- package/docs/bundles.md +45 -2
- package/docs/cli.md +437 -55
- package/docs/crypto.md +32 -10
- package/docs/design.md +177 -47
- package/docs/evals/mcp-charter-baseline.json +428 -0
- package/docs/mcp-charter-eval.md +124 -0
- package/docs/routing.md +189 -34
- package/docs/shift-logs.md +38 -9
- package/docs/wire-contracts.md +78 -14
- package/examples/workflows/compile-dev-playbook.yaml +1 -1
- package/examples/workflows/delivery.yaml +31 -14
- package/examples/workflows/ship.yaml +38 -4
- package/package.json +2 -1
- package/plugins/claude-code/plugin/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/plugin/.mcp.json +1 -1
- package/plugins/claude-code/plugin/skills/author/SKILL.md +22 -0
- package/plugins/claude-code/plugin/skills/ephemeral/SKILL.md +95 -0
- package/plugins/claude-code/plugin/skills/graduate/SKILL.md +156 -0
- package/plugins/claude-code/plugin/skills/plan/SKILL.md +236 -0
- package/plugins/codex/plugins/owenloop/.codex-plugin/plugin.json +1 -1
- package/plugins/codex/plugins/owenloop/.mcp.json +1 -1
- package/plugins/codex/plugins/owenloop/skills/author/SKILL.md +22 -0
- package/plugins/codex/plugins/owenloop/skills/ephemeral/SKILL.md +95 -0
- package/plugins/codex/plugins/owenloop/skills/graduate/SKILL.md +156 -0
- package/plugins/codex/plugins/owenloop/skills/plan/SKILL.md +236 -0
package/dist/src/engine.js
CHANGED
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
* born-rejects the output instead of greening it.
|
|
11
11
|
*/
|
|
12
12
|
import { elementPath, parseElement, parseWorkdirFrom, sealPath, } from "./paths.js";
|
|
13
|
-
import { collectionStem, computeFingerprint, eligibleFirings, fingerprintMatches, groupBlockingWinner, isEscalated, isGreen, judgeNameOf, maintainDecisions, owedSchema, pendingOwed, plainConsumes, rejectionEpisode, requiredInputs, workflowStatus, } from "./model.js";
|
|
13
|
+
import { collectionStem, computeFingerprint, eligibleFirings, fingerprintMatches, groupBlockingWinner, isEscalated, isGreen, judgeNameOf, maintainDecisions, owedSchema, pendingOwed, plainConsumes, rejectionEpisode, requiredInputs, workflowDone, workflowStatus, } from "./model.js";
|
|
14
14
|
import { summarizeIssues, validateValue } from "./schema.js";
|
|
15
15
|
import { hashDef } from "./defs.js";
|
|
16
|
-
import { applyCapabilityRewrites, claimMatches, composeCapabilities } from "./capabilities.js";
|
|
16
|
+
import { applyCapabilityMappings, applyCapabilityRewrites, claimMatches, composeCapabilities } from "./capabilities.js";
|
|
17
17
|
import { localMidnightMs, nowMs, randId } from "./util.js";
|
|
18
18
|
import { createDefInstructionSource, OrderResolver } from "./order-resolver.js";
|
|
19
19
|
const DEFAULT_REAP_TTL_MS = 2 * 60 * 60 * 1000; // 2h
|
|
@@ -28,6 +28,7 @@ const DEFAULT_REAP_TTL_MS = 2 * 60 * 60 * 1000; // 2h
|
|
|
28
28
|
const DEFAULT_MAX_CALL_DEPTH = 64;
|
|
29
29
|
/** The artifact-history `action` written when an escalation promotes an offer. */
|
|
30
30
|
const ESCALATION_ACTION = 'escalated';
|
|
31
|
+
const BIND_ACTION = 'bound';
|
|
31
32
|
/**
|
|
32
33
|
* F2: a typed refusal for a produced-value/input-value schema mismatch, thrown
|
|
33
34
|
* by `createInstance` (seed provide) and `provideInput`. Distinct from a bare
|
|
@@ -196,7 +197,7 @@ export class Engine {
|
|
|
196
197
|
createInstance(defName, opts = {}) {
|
|
197
198
|
const def = this.resolveDef(defName);
|
|
198
199
|
const id = randId('wf');
|
|
199
|
-
this.store.
|
|
200
|
+
this.store.txWithWorkflowSnapshots(def, () => this.createInstanceInTx(defName, def, id, opts));
|
|
200
201
|
this.fire({ type: 'instance', workflow: id, def: defName });
|
|
201
202
|
this.fireSettled(id);
|
|
202
203
|
return id;
|
|
@@ -221,8 +222,9 @@ export class Engine {
|
|
|
221
222
|
wfData.params = opts.params;
|
|
222
223
|
// Validated against the SNAPSHOT being pinned on this same row, not
|
|
223
224
|
// against a live re-resolution — the modifier and the vocabulary that
|
|
224
|
-
// legitimizes it are stamped together
|
|
225
|
-
//
|
|
225
|
+
// legitimizes it are stamped together. Later bound-artifact writes still
|
|
226
|
+
// validate against this pinned vocabulary, even if the def is republished
|
|
227
|
+
// with a different set.
|
|
226
228
|
if (opts.modifier !== undefined) {
|
|
227
229
|
const declared = def.modifiers ?? [];
|
|
228
230
|
if (!declared.includes(opts.modifier)) {
|
|
@@ -297,7 +299,9 @@ export class Engine {
|
|
|
297
299
|
// gate advance landed" (discard). Pure computation over the already-fetched
|
|
298
300
|
// `parentArts` — no extra in-tx store read (E2 busy_timeout GOTCHA-safe).
|
|
299
301
|
let seenGateFp;
|
|
300
|
-
const
|
|
302
|
+
const needsSnapshot = Symbol('needs-workflow-snapshot');
|
|
303
|
+
let snapshotDef;
|
|
304
|
+
const transactionBody = () => {
|
|
301
305
|
// 1. FRESH parent snapshot — re-read inside the write lock; never trust
|
|
302
306
|
// the caller's STEP-1 map.
|
|
303
307
|
const parentArts = this.artMap(parentWf);
|
|
@@ -325,13 +329,19 @@ export class Engine {
|
|
|
325
329
|
let created = false;
|
|
326
330
|
let childDef;
|
|
327
331
|
if (!child) {
|
|
332
|
+
// Resolving a new child's CAS def must happen before its coordinated
|
|
333
|
+
// transaction acquires SQLite. Return a read-only sentinel on the
|
|
334
|
+
// first pass; `run` resolves, locks/revalidates the bundle store, and
|
|
335
|
+
// then repeats every gate/child read under the guarded write tx.
|
|
336
|
+
if (snapshotDef === undefined)
|
|
337
|
+
return needsSnapshot;
|
|
328
338
|
const childId = randId('wf');
|
|
329
339
|
// WS-6: resolve IN THE PARENT'S SCOPE. `parentDef` is the parent's own
|
|
330
340
|
// §28 pin (defFor prefers `defSnapshot` over the live resolver), so a
|
|
331
341
|
// bare `calls:` from a def installed out of a CAS bundle binds to that
|
|
332
342
|
// same bundle's workflow — the version the parent was pinned against —
|
|
333
343
|
// and not to whatever a later install happened to name the same thing.
|
|
334
|
-
childDef =
|
|
344
|
+
childDef = snapshotDef;
|
|
335
345
|
// WS-6: and the resolved child must still be the PINNED one. See
|
|
336
346
|
// `callsPinViolation`.
|
|
337
347
|
const violation = callsPinViolation(parentDef, childDef, step.calls);
|
|
@@ -393,7 +403,22 @@ export class Engine {
|
|
|
393
403
|
if (created || provided.length > 0)
|
|
394
404
|
this.settle(child.id, childDef, now);
|
|
395
405
|
return { childId: child.id, created, provided };
|
|
396
|
-
}
|
|
406
|
+
};
|
|
407
|
+
const transact = () => snapshotDef === undefined
|
|
408
|
+
? this.store.tx(transactionBody)
|
|
409
|
+
: this.store.txWithWorkflowSnapshots(snapshotDef, transactionBody);
|
|
410
|
+
const run = () => {
|
|
411
|
+
let result = transact();
|
|
412
|
+
if (result !== needsSnapshot)
|
|
413
|
+
return result;
|
|
414
|
+
// Resolve optimistically outside both locks. The snapshot guard then
|
|
415
|
+
// revalidates this CAS provenance under add.lock before SQLite begins.
|
|
416
|
+
snapshotDef = this.resolveDef(step.calls, parentDef);
|
|
417
|
+
result = transact();
|
|
418
|
+
if (result === needsSnapshot)
|
|
419
|
+
throw new Error('internal error: guarded child provision requested no snapshot');
|
|
420
|
+
return result;
|
|
421
|
+
};
|
|
397
422
|
try {
|
|
398
423
|
return run();
|
|
399
424
|
}
|
|
@@ -467,7 +492,7 @@ export class Engine {
|
|
|
467
492
|
const freshDef = this.resolveDef(wf.def);
|
|
468
493
|
const newHash = hashDef(freshDef);
|
|
469
494
|
const previousHash = wf.defHash;
|
|
470
|
-
this.store.
|
|
495
|
+
this.store.txWithWorkflowSnapshots(freshDef, () => {
|
|
471
496
|
this.store.repinWorkflowDef(workflow, freshDef, newHash);
|
|
472
497
|
this.settle(workflow, freshDef);
|
|
473
498
|
});
|
|
@@ -488,11 +513,11 @@ export class Engine {
|
|
|
488
513
|
*/
|
|
489
514
|
static CHILD_OUTCOME_PIN_KEY = '__child_outcome_version__';
|
|
490
515
|
/**
|
|
491
|
-
* F4: the single
|
|
492
|
-
* calls: artifact currently resting on"
|
|
493
|
-
*
|
|
494
|
-
*
|
|
495
|
-
* to pin to).
|
|
516
|
+
* F4: the single verdict-time helper that computes "what child-outcome
|
|
517
|
+
* version is this calls: artifact currently resting on" for reject
|
|
518
|
+
* propagation and human skip. STEP 6 publication reads and stamps the version
|
|
519
|
+
* from its authoritative in-transaction snapshot instead. Returns undefined
|
|
520
|
+
* if no child has ever been spawned (nothing to pin to).
|
|
496
521
|
*/
|
|
497
522
|
childOutcomePin(parentWf, callsPath) {
|
|
498
523
|
const child = this.store.findChildByParent(parentWf, callsPath);
|
|
@@ -660,7 +685,8 @@ export class Engine {
|
|
|
660
685
|
* Called at the top of tick (outside any tx) and as cascade-up prompt.
|
|
661
686
|
* For each calls: step: spawn the child if gate is ready and no child exists;
|
|
662
687
|
* re-attach if it exists; re-provide if parent inputs moved; machine-green
|
|
663
|
-
* the parent artifact when the child's declared output is green
|
|
688
|
+
* the parent artifact when the child's declared output is green and the
|
|
689
|
+
* whole child workflow is done.
|
|
664
690
|
*/
|
|
665
691
|
maintainCalls(parentWf, def, now) {
|
|
666
692
|
if (this._inMaintainCalls.has(parentWf))
|
|
@@ -784,23 +810,25 @@ export class Engine {
|
|
|
784
810
|
// rearmCallsGreen). Under WAL + BEGIN IMMEDIATE no other connection can
|
|
785
811
|
// commit between that in-tx re-read and the write, so a cross-connection
|
|
786
812
|
// interleave — the parent gate advanced to a newer version, or the child
|
|
787
|
-
// outcome re-armed,
|
|
788
|
-
//
|
|
789
|
-
// deferring to the next tick.
|
|
790
|
-
//
|
|
791
|
-
//
|
|
792
|
-
//
|
|
813
|
+
// outcome re-armed, or the child's completion state changed, between
|
|
814
|
+
// this stale pre-read and the write — is caught in-tx and the pass aborts
|
|
815
|
+
// (helper returns false, nothing written), deferring to the next tick.
|
|
816
|
+
// The published value, whole-child done result, gate fingerprint, and
|
|
817
|
+
// child-outcome pin therefore always come from ONE atomic snapshot.
|
|
818
|
+
// commit/settled events fire only when the helper wrote, so an aborted
|
|
819
|
+
// pass is silent to listeners.
|
|
793
820
|
//
|
|
794
821
|
// Re-read after potential re-provide.
|
|
795
822
|
childArts = this.artMap(existingChild.id);
|
|
796
823
|
childOutcomeArt = childArts.get(childOutcomeStem);
|
|
824
|
+
const childIsDone = workflowDone(childDef, childArts);
|
|
797
825
|
const parentCallsArt = this.store.getArtifact(parentWf, callsStem);
|
|
798
826
|
// F2: don't machine-green over a schema-rejected debt — it needs a
|
|
799
827
|
// human `retry` (or a moved gate, handled by the guard above) before
|
|
800
828
|
// this step revisits it.
|
|
801
829
|
if (parentCallsArt?.acceptance === 'rejected')
|
|
802
830
|
continue;
|
|
803
|
-
if (isGreen(childOutcomeArt) && childOutcomeArt?.value !== undefined) {
|
|
831
|
+
if (isGreen(childOutcomeArt) && childOutcomeArt?.value !== undefined && childIsDone) {
|
|
804
832
|
const alreadyGreen = isGreen(parentCallsArt);
|
|
805
833
|
const sameValue = alreadyGreen && deepEqual(childOutcomeArt.value, parentCallsArt?.value);
|
|
806
834
|
// F4: version-pinning. Only machine-green when the child outcome's
|
|
@@ -821,11 +849,13 @@ export class Engine {
|
|
|
821
849
|
}
|
|
822
850
|
}
|
|
823
851
|
}
|
|
824
|
-
else if (!isGreen(childOutcomeArt) && isGreen(parentCallsArt) && parentCallsArt) {
|
|
825
|
-
// M2B-REARM: child
|
|
826
|
-
//
|
|
827
|
-
//
|
|
828
|
-
//
|
|
852
|
+
else if ((!isGreen(childOutcomeArt) || !childIsDone) && isGreen(parentCallsArt) && parentCallsArt) {
|
|
853
|
+
// M2B-REARM: the child outcome is no longer green (e.g. re-provide
|
|
854
|
+
// re-armed it), OR the outcome is green while the child still has
|
|
855
|
+
// outstanding work. Re-arm the parent mirror to owed so deep descent
|
|
856
|
+
// can keep driving the child and downstream re-runs only after the
|
|
857
|
+
// whole child completes. The cascade cannot detect either condition
|
|
858
|
+
// because a calls: step declares consumes: [].
|
|
829
859
|
if (this.rearmCallsGreen(parentWf, def, callsStem, existingChild.id, childOutcomeStem, now)) {
|
|
830
860
|
this.fire({ type: 'commit', workflow: parentWf, path: callsStem, action: 'retry' });
|
|
831
861
|
this.fireSettled(parentWf);
|
|
@@ -881,11 +911,18 @@ export class Engine {
|
|
|
881
911
|
const child = this.store.findChildByParent(parentWf, callsStem);
|
|
882
912
|
if (!child || child.id !== expectedChildId)
|
|
883
913
|
return false;
|
|
914
|
+
const childDef = this.defFor(child.id);
|
|
915
|
+
const currentChildOutcomeStem = childDef.outputs?.[0];
|
|
916
|
+
if (currentChildOutcomeStem !== childOutcomeStem)
|
|
917
|
+
return false;
|
|
884
918
|
const childArts = this.artMap(child.id);
|
|
885
|
-
const childOutcomeArt = childArts.get(
|
|
886
|
-
// Child re-armed between the pre-read and
|
|
919
|
+
const childOutcomeArt = childArts.get(currentChildOutcomeStem);
|
|
920
|
+
// Child re-armed, or still has outstanding work, between the pre-read and
|
|
921
|
+
// here → defer. Only this in-tx snapshot authorizes publication.
|
|
887
922
|
if (!childOutcomeArt || !isGreen(childOutcomeArt) || childOutcomeArt.value === undefined)
|
|
888
923
|
return false;
|
|
924
|
+
if (!workflowDone(childDef, childArts))
|
|
925
|
+
return false;
|
|
889
926
|
// Gate still ready, and the child still consistent with the gate values
|
|
890
927
|
// the fingerprint is about to claim (the heart of the fix).
|
|
891
928
|
if (!this.callsGateReady(parentArts, step))
|
|
@@ -917,11 +954,12 @@ export class Engine {
|
|
|
917
954
|
/**
|
|
918
955
|
* STEP 6 re-arm as the mirror-image atomic guard. maintainCalls' optimistic
|
|
919
956
|
* pre-read decides only WHETHER to call this; the parent artifact AND the
|
|
920
|
-
* child
|
|
921
|
-
* if the parent is still green AND the child
|
|
922
|
-
*
|
|
923
|
-
*
|
|
924
|
-
* Returns true only when
|
|
957
|
+
* child definition/artifacts are re-read inside the write lock, and the
|
|
958
|
+
* re-arm happens only if the parent is still green AND either the child
|
|
959
|
+
* outcome is non-green or the whole child is unfinished in-tx. If the outcome
|
|
960
|
+
* is green and the child is done by then, this does nothing (returns false)
|
|
961
|
+
* and the next maintainCalls pass publishes normally. Returns true only when
|
|
962
|
+
* it wrote.
|
|
925
963
|
*/
|
|
926
964
|
rearmCallsGreen(parentWf, def, callsStem, expectedChildId, childOutcomeStem, now) {
|
|
927
965
|
return this.store.tx(() => {
|
|
@@ -931,19 +969,34 @@ export class Engine {
|
|
|
931
969
|
const child = this.store.findChildByParent(parentWf, callsStem);
|
|
932
970
|
if (!child || child.id !== expectedChildId)
|
|
933
971
|
return false;
|
|
934
|
-
const
|
|
935
|
-
|
|
936
|
-
if (
|
|
972
|
+
const childDef = this.defFor(child.id);
|
|
973
|
+
const currentChildOutcomeStem = childDef.outputs?.[0];
|
|
974
|
+
if (currentChildOutcomeStem !== childOutcomeStem)
|
|
937
975
|
return false;
|
|
976
|
+
const childArts = this.artMap(child.id);
|
|
977
|
+
const childOutcomeArt = childArts.get(currentChildOutcomeStem);
|
|
978
|
+
const childIsDone = workflowDone(childDef, childArts);
|
|
979
|
+
// Green outcome plus whole-child completion means the mirror is valid.
|
|
980
|
+
if (isGreen(childOutcomeArt) && childIsDone)
|
|
981
|
+
return false;
|
|
982
|
+
const childOutcomeGreenButUnfinished = isGreen(childOutcomeArt) && !childIsDone;
|
|
983
|
+
let fingerprint = artNow.fingerprint;
|
|
984
|
+
let reasonText = 'gate input moved: child re-running';
|
|
985
|
+
if (childOutcomeGreenButUnfinished) {
|
|
986
|
+
fingerprint = { ...(artNow.fingerprint ?? {}) };
|
|
987
|
+
delete fingerprint[Engine.CHILD_OUTCOME_PIN_KEY];
|
|
988
|
+
reasonText = 'called workflow is not done';
|
|
989
|
+
}
|
|
938
990
|
this.store.putArtifact({
|
|
939
991
|
...artNow,
|
|
940
992
|
acceptance: 'owed',
|
|
993
|
+
fingerprint,
|
|
941
994
|
reasons: [...artNow.reasons, {
|
|
942
995
|
at: nowMs(),
|
|
943
996
|
action: 'reopen',
|
|
944
997
|
kind: 'structural',
|
|
945
998
|
by: 'engine',
|
|
946
|
-
text:
|
|
999
|
+
text: reasonText,
|
|
947
1000
|
fromVersion: artNow.version,
|
|
948
1001
|
}],
|
|
949
1002
|
});
|
|
@@ -986,7 +1039,7 @@ export class Engine {
|
|
|
986
1039
|
tick(workflow, opts = {}) {
|
|
987
1040
|
// `capabilities` is passed through AS GIVEN — an omitted filter (undefined)
|
|
988
1041
|
// and an empty list are different claims. See `claimMatches`.
|
|
989
|
-
return this.tickInternal(workflow, opts.now ?? nowMs(), opts.deep ?? true, opts.capabilities, new Set(), 0, undefined, opts.matchModes ?? {}, opts.capabilityRewrites ?? {});
|
|
1042
|
+
return this.tickInternal(workflow, opts.now ?? nowMs(), opts.deep ?? true, opts.capabilities, new Set(), 0, undefined, opts.matchModes ?? {}, opts.capabilityMappings ?? {}, opts.capabilityRewrites ?? {}, opts.crewStamps ?? {});
|
|
990
1043
|
}
|
|
991
1044
|
/**
|
|
992
1045
|
* The recursive tick worker. Runs this instance's own maintain → reap →
|
|
@@ -1027,7 +1080,7 @@ export class Engine {
|
|
|
1027
1080
|
* edge it hangs from. The guard is silent (no debt/reasons/events), mirroring
|
|
1028
1081
|
* the abort discipline of `publishCallsGreen`/`provisionCallsChild`.
|
|
1029
1082
|
*/
|
|
1030
|
-
tickInternal(workflow, now, deep, capabilities, visited, depth, parentEdge, matchModes = {}, capabilityRewrites = {}) {
|
|
1083
|
+
tickInternal(workflow, now, deep, capabilities, visited, depth, parentEdge, matchModes = {}, capabilityMappings = {}, capabilityRewrites = {}, crewStamps = {}) {
|
|
1031
1084
|
if (depth > this.maxCallDepth) {
|
|
1032
1085
|
throw new Error(`calls depth limit exceeded (maxCallDepth=${this.maxCallDepth}) ticking '${workflow}': `
|
|
1033
1086
|
+ `a calls: composition is deeper than the bound, which usually means a calls: cycle `
|
|
@@ -1076,11 +1129,11 @@ export class Engine {
|
|
|
1076
1129
|
// Compute time facts for idle eligibility (clock-read boundary).
|
|
1077
1130
|
const timeFacts = this.computeTimeFacts(def, workflow, arts, now);
|
|
1078
1131
|
const firings = eligibleFirings(def, arts, timeFacts);
|
|
1079
|
-
const { selected, deferred } = this.applySchedule(workflow, def, firings, now, arts, capabilities, modifier, matchModes, capabilityRewrites);
|
|
1132
|
+
const { selected, deferred } = this.applySchedule(workflow, def, firings, now, arts, capabilities, modifier, matchModes, capabilityMappings, capabilityRewrites);
|
|
1080
1133
|
const orders = [];
|
|
1081
1134
|
const allDeferred = [...deferred];
|
|
1082
1135
|
for (const f of selected) {
|
|
1083
|
-
const claimed = this.claim(workflow, def, f, arts, now, modifier, capabilityRewrites);
|
|
1136
|
+
const claimed = this.claim(workflow, def, f, arts, now, modifier, capabilityMappings, capabilityRewrites, crewStamps);
|
|
1084
1137
|
if (claimed === 'in-flight') {
|
|
1085
1138
|
const d = { step: f.step, key: f.key, inputs: f.inputs, outputs: f.outputs, reason: 'in-flight' };
|
|
1086
1139
|
if (f.index !== undefined)
|
|
@@ -1115,7 +1168,7 @@ export class Engine {
|
|
|
1115
1168
|
parentWf: workflow,
|
|
1116
1169
|
step,
|
|
1117
1170
|
callsStem: step.produces[0].stem,
|
|
1118
|
-
}, matchModes, capabilityRewrites);
|
|
1171
|
+
}, matchModes, capabilityMappings, capabilityRewrites, crewStamps);
|
|
1119
1172
|
// orders: flatten; each Order already carries its own `workflow`.
|
|
1120
1173
|
result.orders.push(...cr.orders);
|
|
1121
1174
|
// deferred: stamp child-originated entries with the child id, preserving
|
|
@@ -1187,9 +1240,11 @@ export class Engine {
|
|
|
1187
1240
|
* Per-step cadence + daily budget + parallel cap over the eligible firings.
|
|
1188
1241
|
*
|
|
1189
1242
|
* A2: `capabilities` is the tick caller's claim filter, matched against the
|
|
1190
|
-
* step's OFFERED capabilities — the authored list
|
|
1191
|
-
*
|
|
1192
|
-
*
|
|
1243
|
+
* step's OFFERED capabilities — the authored list mapped onto the caller's
|
|
1244
|
+
* own capability names, composed with the modifier this firing will actually
|
|
1245
|
+
* be offered under (`wise` + `deep` → `wise:deep`), then rewritten by any
|
|
1246
|
+
* reroute the caller decided on, which is the same list the order will carry.
|
|
1247
|
+
* `claimMatches` owns the rule;
|
|
1193
1248
|
* see it for the four cases (no filter presented, capability-silent step,
|
|
1194
1249
|
* empty caller list, both non-empty) and for what `matchModes` changes.
|
|
1195
1250
|
* A firing this caller may not claim is deferred as `'capability-mismatch'`.
|
|
@@ -1203,7 +1258,7 @@ export class Engine {
|
|
|
1203
1258
|
* escalation authored every firing of a step composes identically, so this
|
|
1204
1259
|
* behaves exactly as a per-step filter would.
|
|
1205
1260
|
*/
|
|
1206
|
-
applySchedule(workflow, def, firings, now, arts, capabilities, modifier, matchModes, capabilityRewrites) {
|
|
1261
|
+
applySchedule(workflow, def, firings, now, arts, capabilities, modifier, matchModes, capabilityMappings, capabilityRewrites) {
|
|
1207
1262
|
const midnight = localMidnightMs(now);
|
|
1208
1263
|
const selected = [];
|
|
1209
1264
|
const deferred = [];
|
|
@@ -1219,13 +1274,14 @@ export class Engine {
|
|
|
1219
1274
|
continue;
|
|
1220
1275
|
// A2: caller capability filter vs. this firing's COMPOSED offer. Composed
|
|
1221
1276
|
// here, not authored, so a caller bound to `wise:deep` is judged against
|
|
1222
|
-
// what the order will actually carry — including
|
|
1277
|
+
// what the order will actually carry — including a mapping onto the org's
|
|
1278
|
+
// own capability vocabulary, including when `deep` came from the
|
|
1223
1279
|
// escalation rule rather than the run, and including a reroute the caller
|
|
1224
|
-
// decided on. The filter and `buildOrder` apply the same
|
|
1225
|
-
// the same order, so what is matched is always what gets stamped.
|
|
1280
|
+
// decided on. The filter and `buildOrder` apply the same three functions
|
|
1281
|
+
// in the same order, so what is matched is always what gets stamped.
|
|
1226
1282
|
const stepFirings = [];
|
|
1227
1283
|
for (const f of all) {
|
|
1228
|
-
const composed = composeCapabilities(step.capabilities, this.routingFor(step, f, arts, modifier).modifier);
|
|
1284
|
+
const composed = composeCapabilities(applyCapabilityMappings(step.capabilities, capabilityMappings), this.routingFor(step, f, arts, modifier).modifier);
|
|
1229
1285
|
const { offered } = applyCapabilityRewrites(composed, capabilityRewrites);
|
|
1230
1286
|
if (claimMatches(offered, capabilities, matchModes))
|
|
1231
1287
|
stepFirings.push(f);
|
|
@@ -1307,7 +1363,7 @@ export class Engine {
|
|
|
1307
1363
|
return this.staleness(task, now, ttl, maxLease) === 'fresh';
|
|
1308
1364
|
}
|
|
1309
1365
|
/** Claim a firing's lease via CAS, snapshot the fingerprint, open a run. */
|
|
1310
|
-
claim(workflow, def, f, arts, now, modifier, capabilityRewrites = {}) {
|
|
1366
|
+
claim(workflow, def, f, arts, now, modifier, capabilityMappings = {}, capabilityRewrites = {}, crewStamps = {}) {
|
|
1311
1367
|
const existing = this.store.getTask(workflow, f.step, f.key);
|
|
1312
1368
|
if (existing && existing.status === 'claimed') {
|
|
1313
1369
|
const run = existing.run ? this.store.getRun(existing.run) : undefined;
|
|
@@ -1335,7 +1391,7 @@ export class Engine {
|
|
|
1335
1391
|
// `applySchedule` so the offer and the filter read the same function on the
|
|
1336
1392
|
// same in-tx `arts` snapshot; nothing between them can move.
|
|
1337
1393
|
const routing = this.routingFor(this.step(def, f.step), f, arts, modifier);
|
|
1338
|
-
const order = this.buildOrder(def, workflow, runId, f, arts, fp, routing, capabilityRewrites);
|
|
1394
|
+
const order = this.buildOrder(def, workflow, runId, f, arts, fp, routing, capabilityMappings, capabilityRewrites, crewStamps);
|
|
1339
1395
|
if (typeof order === 'object' && 'deferred' in order)
|
|
1340
1396
|
return order;
|
|
1341
1397
|
// One history record per rejection episode. Written HERE, not in
|
|
@@ -1369,7 +1425,7 @@ export class Engine {
|
|
|
1369
1425
|
* snapshot is registered under the digest (a side effect of `digestOf`),
|
|
1370
1426
|
* so the order stays resolvable after the live definition map changes.
|
|
1371
1427
|
*/
|
|
1372
|
-
buildOrder(def, workflow, runId, f, arts, consumedFingerprint, routing = {}, capabilityRewrites = {}) {
|
|
1428
|
+
buildOrder(def, workflow, runId, f, arts, consumedFingerprint, routing = {}, capabilityMappings = {}, capabilityRewrites = {}, crewStamps = {}) {
|
|
1373
1429
|
const step = this.step(def, f.step);
|
|
1374
1430
|
const consumes = {};
|
|
1375
1431
|
for (const p of f.inputs) {
|
|
@@ -1461,12 +1517,17 @@ export class Engine {
|
|
|
1461
1517
|
// land, not the currently-committed one: `green()` writes
|
|
1462
1518
|
// `art.version + 1`, so that is the version a consumer will later see
|
|
1463
1519
|
// and check a submission proof against. Issued by the engine inside the
|
|
1464
|
-
// claim transaction and persisted with the
|
|
1465
|
-
//
|
|
1466
|
-
//
|
|
1467
|
-
//
|
|
1468
|
-
//
|
|
1469
|
-
//
|
|
1520
|
+
// claim transaction and persisted with the order.
|
|
1521
|
+
//
|
|
1522
|
+
// The target stays correct across every in-claim retry that does NOT
|
|
1523
|
+
// move the artifact — the schema reject and the artifact-bind reject in
|
|
1524
|
+
// `green()` leave the run open without bumping `version`. A judgment or
|
|
1525
|
+
// human reject also leaves the claim open, but it FOLLOWS a commit that
|
|
1526
|
+
// already bumped the artifact, so the frozen target is one behind from
|
|
1527
|
+
// that point on. `restampOwedTarget` re-stamps it at the reject site
|
|
1528
|
+
// for exactly that case; see its doc comment. A stale target that
|
|
1529
|
+
// escaped anyway fails the consumer's version check — a refusal, never
|
|
1530
|
+
// an admitted unverified value.
|
|
1470
1531
|
version: (a?.version ?? 0) + 1,
|
|
1471
1532
|
judgmentRejects: a?.judgmentRejects ?? 0,
|
|
1472
1533
|
schemaRejects: a?.schemaRejects ?? 0,
|
|
@@ -1488,18 +1549,33 @@ export class Engine {
|
|
|
1488
1549
|
};
|
|
1489
1550
|
if (f.index !== undefined)
|
|
1490
1551
|
order.index = f.index;
|
|
1491
|
-
// The routing snapshot of THIS offer. `capabilities` is the
|
|
1492
|
-
// absent on a capability-silent step, since there is
|
|
1493
|
-
//
|
|
1552
|
+
// The routing snapshot of THIS offer. `capabilities` is the mapped-then-
|
|
1553
|
+
// composed list — absent on a capability-silent step, since there is
|
|
1554
|
+
// nothing to map or compose onto. A mapping substitutes the org's own
|
|
1555
|
+
// capability name for the authored one before the modifier is attached, so
|
|
1556
|
+
// one entry covers every grade the step can be offered at; the authored
|
|
1557
|
+
// name stays recoverable through `defDigest`, which pins the def that wrote
|
|
1558
|
+
// it. `modifier` is stamped whenever the offer carries one, even for a
|
|
1494
1559
|
// capability-silent step, so the brief can surface the grade of service
|
|
1495
1560
|
// regardless of how the step routes; on an escalated offer it is the
|
|
1496
1561
|
// escalation target, and `escalated` marks it as such so the hub does not
|
|
1497
1562
|
// have to diff it against the run record. A claimed order is never
|
|
1498
1563
|
// recomposed: composition happens per offer, and this record is what the
|
|
1499
1564
|
// shift resolved against.
|
|
1500
|
-
const { offered, reroutedFrom } = applyCapabilityRewrites(composeCapabilities(step.capabilities, routing.modifier), capabilityRewrites);
|
|
1565
|
+
const { offered, reroutedFrom } = applyCapabilityRewrites(composeCapabilities(applyCapabilityMappings(step.capabilities, capabilityMappings), routing.modifier), capabilityRewrites);
|
|
1501
1566
|
if (offered.length > 0)
|
|
1502
1567
|
order.capabilities = offered;
|
|
1568
|
+
const crews = [];
|
|
1569
|
+
for (const capability of offered) {
|
|
1570
|
+
if (!Object.prototype.hasOwnProperty.call(crewStamps, capability))
|
|
1571
|
+
continue;
|
|
1572
|
+
for (const crew of crewStamps[capability] ?? []) {
|
|
1573
|
+
if (!crews.includes(crew))
|
|
1574
|
+
crews.push(crew);
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
if (crews.length > 0)
|
|
1578
|
+
order.crews = crews;
|
|
1503
1579
|
// Only when a rewrite actually fired. `reroutedFrom` is absent on every
|
|
1504
1580
|
// ordinary offer, so its presence alone tells a reader the order is not
|
|
1505
1581
|
// running on the capability its def asked for.
|
|
@@ -1535,6 +1611,101 @@ export class Engine {
|
|
|
1535
1611
|
resolveOrder(order) {
|
|
1536
1612
|
return this.resolver.resolveOrder(order);
|
|
1537
1613
|
}
|
|
1614
|
+
/** Return the binding declaration that owns this artifact path, if any. */
|
|
1615
|
+
artifactBind(def, art) {
|
|
1616
|
+
const step = def.steps.find((candidate) => candidate.name === art.producer);
|
|
1617
|
+
if (step === undefined)
|
|
1618
|
+
return undefined;
|
|
1619
|
+
const element = parseElement(art.path);
|
|
1620
|
+
if (element !== null) {
|
|
1621
|
+
return step.produces.find((produce) => produce.kind === 'map'
|
|
1622
|
+
&& produce.stem === element.stem
|
|
1623
|
+
&& produce.suffix === element.suffix)?.bind;
|
|
1624
|
+
}
|
|
1625
|
+
return step.produces.find((produce) => produce.kind === 'singleton' && produce.stem === art.path)?.bind;
|
|
1626
|
+
}
|
|
1627
|
+
/** Resolve a declared dot-path of object keys against an accepted artifact value. */
|
|
1628
|
+
boundValue(path, bind, acceptedValue) {
|
|
1629
|
+
let current = acceptedValue;
|
|
1630
|
+
for (const key of bind.from.split('.')) {
|
|
1631
|
+
if (current === null ||
|
|
1632
|
+
typeof current !== 'object' ||
|
|
1633
|
+
Array.isArray(current) ||
|
|
1634
|
+
!Object.prototype.hasOwnProperty.call(current, key)) {
|
|
1635
|
+
throw new Error(`artifact '${path}' bind.from '${bind.from}' cannot be resolved from its accepted value`);
|
|
1636
|
+
}
|
|
1637
|
+
current = current[key];
|
|
1638
|
+
}
|
|
1639
|
+
return current;
|
|
1640
|
+
}
|
|
1641
|
+
/**
|
|
1642
|
+
* The bind-time and reject-time modifier gate: membership in the def's
|
|
1643
|
+
* declared `modifiers` set, and nothing else — byte for byte the rule the
|
|
1644
|
+
* start path applies in `createInstanceInTx`. One value cannot be legal to
|
|
1645
|
+
* start a run with and illegal to bind.
|
|
1646
|
+
*
|
|
1647
|
+
* `def` here is the PINNED snapshot, so the vocabulary checked is the one
|
|
1648
|
+
* stamped on this run, not a later republish.
|
|
1649
|
+
*
|
|
1650
|
+
* The SHAPE of a name is constrained where a name is authored:
|
|
1651
|
+
* `parseModifiers` in `src/defs.ts` refuses an empty name, a name containing
|
|
1652
|
+
* whitespace, a name containing `MODIFIER_SEPARATOR`, and a duplicate.
|
|
1653
|
+
* Re-testing shape here is what split the vocabulary in the first place — a
|
|
1654
|
+
* value the parser admitted and `start_run` accepted, refused at bind.
|
|
1655
|
+
*/
|
|
1656
|
+
assertBoundModifier(def, value) {
|
|
1657
|
+
const declared = def.modifiers ?? [];
|
|
1658
|
+
if (typeof value !== 'string' || !declared.includes(value)) {
|
|
1659
|
+
const rendered = typeof value === 'string' ? value : JSON.stringify(value) ?? String(value);
|
|
1660
|
+
throw new ModifierRefusalError(def.name, rendered, declared);
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
/** Validate extraction before an acceptance branch changes an artifact. */
|
|
1664
|
+
validateArtifactBind(def, art, acceptedValue) {
|
|
1665
|
+
const bind = this.artifactBind(def, art);
|
|
1666
|
+
if (bind === undefined)
|
|
1667
|
+
return;
|
|
1668
|
+
const value = this.boundValue(art.path, bind, acceptedValue);
|
|
1669
|
+
if (bind.to === 'modifier')
|
|
1670
|
+
this.assertBoundModifier(def, value);
|
|
1671
|
+
}
|
|
1672
|
+
/**
|
|
1673
|
+
* Persist a declared instance-routing write and its single artifact-level
|
|
1674
|
+
* audit event. Call only from an already-accepted branch inside its tx.
|
|
1675
|
+
*/
|
|
1676
|
+
applyArtifactBind(workflow, def, art, acceptedValue, now) {
|
|
1677
|
+
const bind = this.artifactBind(def, art);
|
|
1678
|
+
if (bind === undefined)
|
|
1679
|
+
return;
|
|
1680
|
+
const value = this.boundValue(art.path, bind, acceptedValue);
|
|
1681
|
+
const routing = this.store.getWorkflow(workflow);
|
|
1682
|
+
if (routing === undefined)
|
|
1683
|
+
throw new Error(`cannot bind routing for unknown workflow '${workflow}'`);
|
|
1684
|
+
let prior;
|
|
1685
|
+
if (bind.to === 'modifier') {
|
|
1686
|
+
this.assertBoundModifier(def, value);
|
|
1687
|
+
prior = routing.modifier;
|
|
1688
|
+
this.store.setWorkflowRouting(workflow, { modifier: value });
|
|
1689
|
+
}
|
|
1690
|
+
else {
|
|
1691
|
+
const key = bind.to.slice('meta.'.length);
|
|
1692
|
+
prior = routing.meta?.[key];
|
|
1693
|
+
this.store.setWorkflowRouting(workflow, { meta: { [key]: value } });
|
|
1694
|
+
}
|
|
1695
|
+
this.store.recordArtifactEvent({
|
|
1696
|
+
workflow,
|
|
1697
|
+
path: art.path,
|
|
1698
|
+
version: 0,
|
|
1699
|
+
action: BIND_ACTION,
|
|
1700
|
+
actor: 'engine',
|
|
1701
|
+
dedupe: `${BIND_ACTION}:${art.path}:v${art.version}`,
|
|
1702
|
+
timestamp: now,
|
|
1703
|
+
reason: `artifact '${art.path}' bound ${bind.to}`,
|
|
1704
|
+
// JSON has no undefined value, so null faithfully records an unbound
|
|
1705
|
+
// target while preserving both sides of every accepted routing write.
|
|
1706
|
+
metadata: { from: prior ?? null, to: value },
|
|
1707
|
+
});
|
|
1708
|
+
}
|
|
1538
1709
|
// ---- producer commits ------------------------------------------------------
|
|
1539
1710
|
/**
|
|
1540
1711
|
* Commit a singleton/map output green — or born-reject it if an input moved.
|
|
@@ -1601,7 +1772,9 @@ export class Engine {
|
|
|
1601
1772
|
const producer = def.steps.find((l) => l.name === art.producer);
|
|
1602
1773
|
if (opts.terminal || producer?.terminal)
|
|
1603
1774
|
next.terminal = true;
|
|
1775
|
+
this.validateArtifactBind(def, next, value);
|
|
1604
1776
|
this.store.putArtifact(next, { action: 'green', actor: 'human', reason: 'human green' });
|
|
1777
|
+
this.applyArtifactBind(workflow, def, next, value, nowMs());
|
|
1605
1778
|
this.settle(workflow, def);
|
|
1606
1779
|
return { path, outcome: 'green' };
|
|
1607
1780
|
});
|
|
@@ -1642,7 +1815,9 @@ export class Engine {
|
|
|
1642
1815
|
const next = { ...art, acceptance: 'green', approvals };
|
|
1643
1816
|
if (producer?.terminal)
|
|
1644
1817
|
next.terminal = true;
|
|
1818
|
+
this.validateArtifactBind(def, next, art.value);
|
|
1645
1819
|
this.store.putArtifact(next, { action: 'judge-approved', actor: jName, reason: 'all judges approved' });
|
|
1820
|
+
this.applyArtifactBind(workflow, def, next, art.value, nowMs());
|
|
1646
1821
|
this.settle(workflow, def);
|
|
1647
1822
|
return { path: judgedStem, outcome: 'green' };
|
|
1648
1823
|
}
|
|
@@ -1697,6 +1872,20 @@ export class Engine {
|
|
|
1697
1872
|
return { path, outcome: 'schema-rejected', reason: text, issues: check.issues };
|
|
1698
1873
|
}
|
|
1699
1874
|
}
|
|
1875
|
+
try {
|
|
1876
|
+
this.validateArtifactBind(def, art, value);
|
|
1877
|
+
}
|
|
1878
|
+
catch (e) {
|
|
1879
|
+
const text = `artifact bind validation failed: ${e instanceof Error ? e.message : String(e)}`;
|
|
1880
|
+
this.store.putArtifact({
|
|
1881
|
+
...art,
|
|
1882
|
+
acceptance: 'rejected',
|
|
1883
|
+
schemaRejects: art.schemaRejects + 1,
|
|
1884
|
+
reasons: [...art.reasons, reason('schema-reject', 'validation', 'engine', text, art.version)],
|
|
1885
|
+
});
|
|
1886
|
+
this.settle(workflow, def);
|
|
1887
|
+
return { path, outcome: 'schema-rejected', reason: text };
|
|
1888
|
+
}
|
|
1700
1889
|
// §24 §4.4/§4.8: when this produce declares judges, the commit lands
|
|
1701
1890
|
// `submitted` (not `green`) and the version bumps here — CAS re-arms on
|
|
1702
1891
|
// resubmission, not on judge-approve. `approvals` resets so a prior
|
|
@@ -1722,12 +1911,14 @@ export class Engine {
|
|
|
1722
1911
|
actor: r.step,
|
|
1723
1912
|
reason: hasJudges ? 'submitted for judgment' : 'producer green',
|
|
1724
1913
|
});
|
|
1914
|
+
if (!hasJudges)
|
|
1915
|
+
this.applyArtifactBind(workflow, def, next, value, nowMs());
|
|
1725
1916
|
this.settle(workflow, def);
|
|
1726
1917
|
return { path, outcome: hasJudges ? 'submitted' : 'green' };
|
|
1727
1918
|
});
|
|
1728
1919
|
this.fire({ type: 'commit', workflow, run, path: result.path, action: 'green', outcome: result.outcome });
|
|
1729
1920
|
if (result.outcome === 'born-rejected') {
|
|
1730
|
-
this.fire({ type: 'closed', workflow, run, outcome: '
|
|
1921
|
+
this.fire({ type: 'closed', workflow, run, outcome: 'released' });
|
|
1731
1922
|
}
|
|
1732
1923
|
this.fireSettled(workflow);
|
|
1733
1924
|
// M2B cascade-up prompt: if this workflow has a producedBy link, trigger parent maintainCalls.
|
|
@@ -1826,7 +2017,7 @@ export class Engine {
|
|
|
1826
2017
|
});
|
|
1827
2018
|
this.fire({ type: 'commit', workflow, run, path: stem, action: 'emit', outcome: result.outcome });
|
|
1828
2019
|
if (result.outcome === 'born-rejected') {
|
|
1829
|
-
this.fire({ type: 'closed', workflow, run, outcome: '
|
|
2020
|
+
this.fire({ type: 'closed', workflow, run, outcome: 'released' });
|
|
1830
2021
|
}
|
|
1831
2022
|
this.fireSettled(workflow);
|
|
1832
2023
|
return result;
|
|
@@ -1865,7 +2056,7 @@ export class Engine {
|
|
|
1865
2056
|
});
|
|
1866
2057
|
this.fire({ type: 'commit', workflow, run, path: result.path, action: 'seal', outcome: result.outcome });
|
|
1867
2058
|
if (result.outcome === 'born-rejected') {
|
|
1868
|
-
this.fire({ type: 'closed', workflow, run, outcome: '
|
|
2059
|
+
this.fire({ type: 'closed', workflow, run, outcome: 'released' });
|
|
1869
2060
|
}
|
|
1870
2061
|
this.fireSettled(workflow);
|
|
1871
2062
|
return result;
|
|
@@ -1895,7 +2086,7 @@ export class Engine {
|
|
|
1895
2086
|
* See `docs/design.md` §24.9 for the full writeup and operator mitigations
|
|
1896
2087
|
* (`parallel: 1`, a generous `reapTtl:` on slow judge steps).
|
|
1897
2088
|
*/
|
|
1898
|
-
reject(workflow, path, by, text) {
|
|
2089
|
+
reject(workflow, path, by, text, requested) {
|
|
1899
2090
|
const def = this.defFor(workflow);
|
|
1900
2091
|
this.assertAuthority(def, by, path, 'reject');
|
|
1901
2092
|
// F4: a reject on an artifact produced by a `calls:` step is a verdict on
|
|
@@ -1906,7 +2097,14 @@ export class Engine {
|
|
|
1906
2097
|
// verb-guard rule below that a verdict needs a built version).
|
|
1907
2098
|
const producingStep = def.steps.find((s) => s.produces.some((p) => p.stem === path));
|
|
1908
2099
|
if (producingStep?.calls) {
|
|
1909
|
-
|
|
2100
|
+
const bind = producingStep.produces.find((p) => p.stem === path)?.bind;
|
|
2101
|
+
if (requested !== undefined) {
|
|
2102
|
+
if (bind?.to !== 'modifier') {
|
|
2103
|
+
throw new Error(`requested modifier is only valid when artifact '${path}' binds to modifier`);
|
|
2104
|
+
}
|
|
2105
|
+
this.assertBoundModifier(def, requested);
|
|
2106
|
+
}
|
|
2107
|
+
return this.rejectCallsArtifact(workflow, def, producingStep, path, by, text, requested);
|
|
1910
2108
|
}
|
|
1911
2109
|
const judgeStep = def.steps.find((s) => s.name === by);
|
|
1912
2110
|
const judgedStem = judgeStep?.judges;
|
|
@@ -1915,6 +2113,13 @@ export class Engine {
|
|
|
1915
2113
|
const art = this.store.getArtifact(workflow, path);
|
|
1916
2114
|
if (!art)
|
|
1917
2115
|
throw new Error(`cannot reject unknown artifact: ${path}`);
|
|
2116
|
+
if (requested !== undefined) {
|
|
2117
|
+
const bind = this.artifactBind(def, art);
|
|
2118
|
+
if (bind?.to !== 'modifier') {
|
|
2119
|
+
throw new Error(`requested modifier is only valid when artifact '${path}' binds to modifier`);
|
|
2120
|
+
}
|
|
2121
|
+
this.assertBoundModifier(def, requested);
|
|
2122
|
+
}
|
|
1918
2123
|
if (judgedStem !== undefined) {
|
|
1919
2124
|
// A judge's reject targets the judged stem, mirroring green()'s
|
|
1920
2125
|
// judge-approve branch (§24.4): CAS-guard against a stale verdict
|
|
@@ -1958,8 +2163,14 @@ export class Engine {
|
|
|
1958
2163
|
acceptance: 'rejected',
|
|
1959
2164
|
judgmentRejects: art.judgmentRejects + 1,
|
|
1960
2165
|
approvals: undefined,
|
|
1961
|
-
reasons: [...art.reasons, reason('reject', 'judgment', by, text, art.version)],
|
|
2166
|
+
reasons: [...art.reasons, reason('reject', 'judgment', by, text, art.version, requested)],
|
|
1962
2167
|
});
|
|
2168
|
+
// The producer's claim survives this reject (settle() writes artifact rows
|
|
2169
|
+
// only), so its frozen target is now one behind the version the next
|
|
2170
|
+
// commit will land. `art` is the pre-write snapshot and a reject does not
|
|
2171
|
+
// bump `version`, so `art.version + 1` is the same expression buildOrder
|
|
2172
|
+
// stamps at issue.
|
|
2173
|
+
this.restampOwedTarget(workflow, art.producer, path, art.version + 1);
|
|
1963
2174
|
this.settle(workflow, def);
|
|
1964
2175
|
return { outcome: 'rejected' };
|
|
1965
2176
|
});
|
|
@@ -1971,7 +2182,7 @@ export class Engine {
|
|
|
1971
2182
|
...(result.outcome === 'born-rejected' ? { outcome: 'born-rejected' } : {}),
|
|
1972
2183
|
});
|
|
1973
2184
|
if (result.outcome === 'born-rejected' && releasedRun !== undefined) {
|
|
1974
|
-
this.fire({ type: 'closed', workflow, run: releasedRun, outcome: '
|
|
2185
|
+
this.fire({ type: 'closed', workflow, run: releasedRun, outcome: 'released' });
|
|
1975
2186
|
}
|
|
1976
2187
|
this.fireSettled(workflow);
|
|
1977
2188
|
return result;
|
|
@@ -1989,7 +2200,7 @@ export class Engine {
|
|
|
1989
2200
|
* reasons entry is `parent:<by>` to make the indirection visible in its
|
|
1990
2201
|
* audit thread.
|
|
1991
2202
|
*/
|
|
1992
|
-
rejectCallsArtifact(parentWf, def, producingStep, callsStem, by, text) {
|
|
2203
|
+
rejectCallsArtifact(parentWf, def, producingStep, callsStem, by, text, requested) {
|
|
1993
2204
|
const child = this.store.findChildByParent(parentWf, callsStem);
|
|
1994
2205
|
if (!child) {
|
|
1995
2206
|
throw new Error(`cannot reject '${callsStem}': no child instance has been spawned yet (a verdict requires a built version)`);
|
|
@@ -2012,8 +2223,13 @@ export class Engine {
|
|
|
2012
2223
|
acceptance: 'rejected',
|
|
2013
2224
|
judgmentRejects: childArt.judgmentRejects + 1,
|
|
2014
2225
|
approvals: undefined,
|
|
2015
|
-
reasons: [...childArt.reasons, reason('reject', 'judgment', `parent:${by}`, text, childArt.version)],
|
|
2226
|
+
reasons: [...childArt.reasons, reason('reject', 'judgment', `parent:${by}`, text, childArt.version, requested)],
|
|
2016
2227
|
});
|
|
2228
|
+
// Same stranding as the plain reject above, one instance down: the child's
|
|
2229
|
+
// producing step can hold an open claim in the CHILD workflow. The parent
|
|
2230
|
+
// `calls` artifact reopened below needs no re-stamp — a `calls:` step never
|
|
2231
|
+
// becomes a worker order (src/model.ts), so no claim owes it.
|
|
2232
|
+
this.restampOwedTarget(child.id, childArt.producer, childOutcomeStem, childArt.version + 1);
|
|
2017
2233
|
this.settle(child.id, childDef);
|
|
2018
2234
|
// Parent calls artifact → reopened to owed (not left rejected), pinned
|
|
2019
2235
|
// to the just-rejected child outcome version.
|
|
@@ -2238,7 +2454,10 @@ export class Engine {
|
|
|
2238
2454
|
step: r.step,
|
|
2239
2455
|
key: r.key ?? '',
|
|
2240
2456
|
status: 'idle',
|
|
2241
|
-
|
|
2457
|
+
// A public close hands back a real claimed lease. Count the churn so
|
|
2458
|
+
// pickup-window lapses and explicit holder releases are visible in
|
|
2459
|
+
// instance status; released runs still remain outside run budgets.
|
|
2460
|
+
attempts: outcome === 'released' ? task.attempts + 1 : task.attempts,
|
|
2242
2461
|
...(task.alarmAt !== undefined ? { alarmAt: task.alarmAt } : {}),
|
|
2243
2462
|
});
|
|
2244
2463
|
}
|
|
@@ -2681,15 +2900,48 @@ export class Engine {
|
|
|
2681
2900
|
});
|
|
2682
2901
|
}
|
|
2683
2902
|
/**
|
|
2684
|
-
*
|
|
2903
|
+
* Re-stamp the owed version target for `path` on any OPEN claim that owes it.
|
|
2904
|
+
*
|
|
2905
|
+
* The target frozen at claim issue is `committed + 1`. That stays correct for
|
|
2906
|
+
* every refusal that leaves the run open WITHOUT bumping the artifact (the
|
|
2907
|
+
* schema reject and the artifact-bind reject in `green()`). It goes stale for
|
|
2908
|
+
* a judgment/human reject, which is preceded by a commit that already bumped
|
|
2909
|
+
* the artifact and which leaves the SAME claim live to retry: the next commit
|
|
2910
|
+
* lands `committed + 1` from the new committed version, while the producer is
|
|
2911
|
+
* still signing the old number into its proof's `produced[].version`. The
|
|
2912
|
+
* proof row is then stored under a key the envelope does not name, and the
|
|
2913
|
+
* consumer's version check refuses the artifact.
|
|
2914
|
+
*
|
|
2915
|
+
* Matching is by owed path, not by task key, so it is correct for map
|
|
2916
|
+
* elements without re-deriving the binding key. Runs inside the caller's open
|
|
2917
|
+
* tx (plain store writes, no nested tx).
|
|
2918
|
+
*/
|
|
2919
|
+
restampOwedTarget(workflow, producer, path, target) {
|
|
2920
|
+
for (const task of this.store.listTasks(workflow)) {
|
|
2921
|
+
if (task.step !== producer || task.status !== 'claimed' || task.run === undefined)
|
|
2922
|
+
continue;
|
|
2923
|
+
// A closed run's next claim rebuilds the order from scratch and already
|
|
2924
|
+
// gets a fresh target, so only an open one can strand.
|
|
2925
|
+
const run = this.store.getRun(task.run);
|
|
2926
|
+
if (!run || run.outcome !== undefined)
|
|
2927
|
+
continue;
|
|
2928
|
+
this.store.restampOrderTarget(task.run, path, target);
|
|
2929
|
+
}
|
|
2930
|
+
}
|
|
2931
|
+
/**
|
|
2932
|
+
* §12.2 born-reject lease release: close the run (`released`) and re-arm its
|
|
2685
2933
|
* task to `idle` so the firing is immediately re-claimable next tick. Runs
|
|
2686
2934
|
* inside the caller's open tx (plain store write, no nested tx). Unlike reap()
|
|
2687
|
-
* it does NOT bump attempts — a CAS-stale born-reject is not lease churn.
|
|
2935
|
+
* it does NOT bump attempts — a CAS-stale born-reject is not lease churn. For
|
|
2936
|
+
* the same reason the outcome is `released` and not `no_work`: the step never
|
|
2937
|
+
* ran, so the run must not spend the daily budget or restart the cadence
|
|
2938
|
+
* clock either. `no_work` is reserved for a step that DID run and had nothing
|
|
2939
|
+
* to produce, which is a firing and does spend both. The
|
|
2688
2940
|
* `closed` event is fired by the caller AFTER the tx commits (post-commit
|
|
2689
2941
|
* ordering), matching public close().
|
|
2690
2942
|
*/
|
|
2691
2943
|
releaseLeaseOnBornReject(workflow, run) {
|
|
2692
|
-
this.store.updateRun(run, { outcome: '
|
|
2944
|
+
this.store.updateRun(run, { outcome: 'released' });
|
|
2693
2945
|
const r = this.store.getRun(run);
|
|
2694
2946
|
if (!r)
|
|
2695
2947
|
return;
|
|
@@ -3023,8 +3275,8 @@ export class Engine {
|
|
|
3023
3275
|
}
|
|
3024
3276
|
}
|
|
3025
3277
|
// ---- helpers -----------------------------------------------------------------
|
|
3026
|
-
function reason(action, kind, by, text, fromVersion) {
|
|
3027
|
-
return { at: nowMs(), action, kind, by, text, fromVersion };
|
|
3278
|
+
function reason(action, kind, by, text, fromVersion, requested) {
|
|
3279
|
+
return { at: nowMs(), action, kind, by, text, fromVersion, ...(requested !== undefined ? { requested } : {}) };
|
|
3028
3280
|
}
|
|
3029
3281
|
function nextIndex(arts, stem) {
|
|
3030
3282
|
let max = -1;
|