@sensigo/realm 0.31.2 → 0.33.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.
Files changed (51) hide show
  1. package/dist/engine/abandon-run.d.ts.map +1 -1
  2. package/dist/engine/abandon-run.js +17 -9
  3. package/dist/engine/abandon-run.js.map +1 -1
  4. package/dist/engine/apply-resume.d.ts +43 -0
  5. package/dist/engine/apply-resume.d.ts.map +1 -0
  6. package/dist/engine/apply-resume.js +80 -0
  7. package/dist/engine/apply-resume.js.map +1 -0
  8. package/dist/engine/defaulted-steps.d.ts +17 -0
  9. package/dist/engine/defaulted-steps.d.ts.map +1 -0
  10. package/dist/engine/defaulted-steps.js +26 -0
  11. package/dist/engine/defaulted-steps.js.map +1 -0
  12. package/dist/engine/eligibility.d.ts +20 -2
  13. package/dist/engine/eligibility.d.ts.map +1 -1
  14. package/dist/engine/eligibility.js +46 -24
  15. package/dist/engine/eligibility.js.map +1 -1
  16. package/dist/engine/execution-loop.d.ts +38 -3
  17. package/dist/engine/execution-loop.d.ts.map +1 -1
  18. package/dist/engine/execution-loop.js +1500 -112
  19. package/dist/engine/execution-loop.js.map +1 -1
  20. package/dist/engine/lifecycle.d.ts +14 -0
  21. package/dist/engine/lifecycle.d.ts.map +1 -1
  22. package/dist/engine/lifecycle.js +14 -0
  23. package/dist/engine/lifecycle.js.map +1 -1
  24. package/dist/engine/run-health.d.ts +1 -1
  25. package/dist/engine/run-health.d.ts.map +1 -1
  26. package/dist/engine/run-health.js +88 -4
  27. package/dist/engine/run-health.js.map +1 -1
  28. package/dist/engine/settlement.d.ts +38 -0
  29. package/dist/engine/settlement.d.ts.map +1 -0
  30. package/dist/engine/settlement.js +825 -0
  31. package/dist/engine/settlement.js.map +1 -0
  32. package/dist/index.d.ts +8 -2
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +11 -2
  35. package/dist/index.js.map +1 -1
  36. package/dist/store/json-file-store.d.ts +56 -3
  37. package/dist/store/json-file-store.d.ts.map +1 -1
  38. package/dist/store/json-file-store.js +178 -22
  39. package/dist/store/json-file-store.js.map +1 -1
  40. package/dist/store/store-interface.d.ts +50 -1
  41. package/dist/store/store-interface.d.ts.map +1 -1
  42. package/dist/types/run-record.d.ts +90 -0
  43. package/dist/types/run-record.d.ts.map +1 -1
  44. package/dist/types/settlement.d.ts +248 -0
  45. package/dist/types/settlement.d.ts.map +1 -0
  46. package/dist/types/settlement.js +2 -0
  47. package/dist/types/settlement.js.map +1 -0
  48. package/dist/types/workflow-error.d.ts +1 -1
  49. package/dist/types/workflow-error.d.ts.map +1 -1
  50. package/dist/types/workflow-error.js.map +1 -1
  51. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  import { classifyInProgressClaims } from './claim-liveness.js';
2
2
  import { findCapabilityBlockedSteps } from './capability.js';
3
- import { findEligibleSteps } from './eligibility.js';
3
+ import { findEligibleSteps, findEligibleGuardSteps } from './eligibility.js';
4
4
  /**
5
5
  * Default age threshold for the `never_claimed_idle` finding (issue #221) — 24 hours. Engine-
6
6
  * minted so detection never REQUIRES an operator-supplied threshold; callers (surfaces) may
@@ -9,16 +9,83 @@ import { findEligibleSteps } from './eligibility.js';
9
9
  * inspect take no override by design (agents don't tune detectors).
10
10
  */
11
11
  export const DEFAULT_IDLE_THRESHOLD_MS = 24 * 60 * 60 * 1000;
12
+ /**
13
+ * G-2-corruption detector (issue #279, increment 2, PR-D, design record §9/N9): a `settled` entry
14
+ * recording a resolved gate (`outcome === 'gate'`) whose `token` equals the run's OWN live
15
+ * `pending_gate.gate_id` — the both-match corruption `settleGateArms`'s lookup-first ordering
16
+ * fail-safes against (NOOP, never RESOLVE — settlement.ts), but which then leaves `pending_gate`
17
+ * permanently unclearable by normal means (exits: `settle_step` abort, or `realm run purge`).
18
+ * Out-of-contract producer only (a real store honoring `settleStep`'s own atomicity can never
19
+ * produce this); a run-health finding is the detection surface. Checked from BOTH branches of
20
+ * {@link classifyRunHealth} (a live pending_gate can coexist with this corruption whether or not
21
+ * the run has separately gone terminal).
22
+ */
23
+ function findGateCorruption(run) {
24
+ if (run.pending_gate === undefined)
25
+ return undefined;
26
+ const gateId = run.pending_gate.gate_id;
27
+ for (const [step, entry] of Object.entries(run.settled ?? {})) {
28
+ if (entry.outcome === 'gate' && entry.token === gateId) {
29
+ return {
30
+ kind: 'gate_corruption',
31
+ step,
32
+ reason: 'settled gate entry coexists with a live pending_gate bearing the same gate_id — ' +
33
+ 'store history divergent',
34
+ evidence: { gate_id: gateId },
35
+ };
36
+ }
37
+ }
38
+ return undefined;
39
+ }
12
40
  /**
13
41
  * Classifies a run's health into zero or more typed findings. Pure, read-only, definition-
14
42
  * optional, `now`-injectable. See the module doc above for the full branch-conditioning table
15
43
  * (design record §1, fold B1) and the honest-admission rule.
16
44
  */
17
45
  export function classifyRunHealth(run, opts) {
18
- // Branch 1 — unconditional first guard (record §1, B1).
19
- if (run.terminal_state)
20
- return [];
21
46
  const now = opts?.now ?? new Date();
47
+ // Branch 1 — NARROWED first guard (issue #279, increment 1, PR-B, design record §6, explicitly
48
+ // authorized): checked BEFORE the terminal short-circuit. A terminal run with a still-'pending'
49
+ // finalizer_ledger entry gets EXACTLY these findings and returns immediately — no claim,
50
+ // capability, or idle finding may leak through on a terminal run.
51
+ if (run.terminal_state) {
52
+ const pendingFindings = [];
53
+ for (const [name, entry] of Object.entries(run.finalizer_ledger ?? {})) {
54
+ if (entry.status !== 'pending')
55
+ continue;
56
+ const isLeased = entry.lease_token !== undefined && entry.lease_deadline !== undefined;
57
+ const leaseExpired = isLeased && new Date(entry.lease_deadline).getTime() <= now.getTime();
58
+ const reason = !isLeased ? 'never_leased' : leaseExpired ? 'lease_expired' : 'lease_held';
59
+ pendingFindings.push({
60
+ kind: 'terminal_pending_finalizer',
61
+ step: name,
62
+ reason,
63
+ evidence: {
64
+ rank: entry.rank,
65
+ ...(entry.lease_deadline !== undefined ? { lease_deadline: entry.lease_deadline } : {}),
66
+ },
67
+ });
68
+ }
69
+ // issue #279 (increment 2, PR-D, design record §9): terminal-with-stale-gate — the #282
70
+ // class's own surface. A terminal record that STILL carries a pending_gate is a grandfathered
71
+ // (or mixed-fleet old-binary-written) record; purge is the disposal path.
72
+ if (run.pending_gate !== undefined) {
73
+ pendingFindings.push({
74
+ kind: 'terminal_with_stale_gate',
75
+ step: run.pending_gate.step_name,
76
+ reason: 'run is terminal but still carries a pending_gate (a grandfathered #282-class record)',
77
+ evidence: { gate_id: run.pending_gate.gate_id },
78
+ });
79
+ }
80
+ // G-2-corruption: checked here too — a terminal record can carry the same both-match
81
+ // corruption a live run can (N9).
82
+ const terminalGateCorruption = findGateCorruption(run);
83
+ if (terminalGateCorruption !== undefined)
84
+ pendingFindings.push(terminalGateCorruption);
85
+ if (pendingFindings.length > 0)
86
+ return pendingFindings;
87
+ return []; // terminal ∧ no pending ledger entries ⇒ [] (byte-identical to pre-#279 behavior)
88
+ }
22
89
  const idleThresholdMs = opts?.idleThresholdMs ?? DEFAULT_IDLE_THRESHOLD_MS;
23
90
  const findings = [];
24
91
  // Branch 2 — claim findings (subsumes list.ts's pre-#221 wedgedNonGatedClaims).
@@ -45,6 +112,23 @@ export function classifyRunHealth(run, opts) {
45
112
  evidence: { requirement: b.requirement, code: b.code },
46
113
  });
47
114
  }
115
+ // issue #279 (increment 2, PR-D, design record §9): G-2-corruption on the non-terminal path too
116
+ // — a live pending_gate can coexist with the same both-match corruption a terminal record can.
117
+ const gateCorruption = findGateCorruption(run);
118
+ if (gateCorruption !== undefined)
119
+ findings.push(gateCorruption);
120
+ // issue #279 (increment 2, PR-D, design record §9, N8's surface): resolved-gate-with-eligible-
121
+ // guard. findEligibleGuardSteps ALREADY self-filters both a terminal run and an open gate
122
+ // (eligibility.ts), so no extra gating is needed beyond requiring a definition.
123
+ if (opts?.definition !== undefined) {
124
+ for (const guardName of findEligibleGuardSteps(opts.definition, run)) {
125
+ findings.push({
126
+ kind: 'resolved_gate_with_eligible_guard',
127
+ step: guardName,
128
+ reason: `gate resolved; guard '${guardName}' awaits the next drive`,
129
+ });
130
+ }
131
+ }
48
132
  // Branch 4 — never_claimed_idle (the #221 class). since/idle_ms/evidence.idle_threshold_ms are
49
133
  // REQUIRED on this finding.
50
134
  if (run.run_phase === 'running' &&
@@ -1 +1 @@
1
- {"version":3,"file":"run-health.js","sourceRoot":"","sources":["../../src/engine/run-health.ts"],"names":[],"mappings":"AAqDA,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AA+B7D;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAC/B,GAAc,EACd,IAAgF;IAEhF,wDAAwD;IACxD,IAAI,GAAG,CAAC,cAAc;QAAE,OAAO,EAAE,CAAC;IAElC,MAAM,GAAG,GAAG,IAAI,EAAE,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC;IACpC,MAAM,eAAe,GAAG,IAAI,EAAE,eAAe,IAAI,yBAAyB,CAAC;IAC3E,MAAM,QAAQ,GAAuB,EAAE,CAAC;IAExC,gFAAgF;IAChF,KAAK,MAAM,CAAC,IAAI,wBAAwB,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;QACnD,IAAI,CAAC,CAAC,KAAK,KAAK,SAAS;YAAE,SAAS;QACpC,IAAI,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,YAAY,EAAE,SAAS;YAAE,SAAS,CAAC,uCAAuC;QAC7F,QAAQ,CAAC,IAAI,CAAC;YACZ,IAAI,EAAE,GAAG,CAAC,SAAS,KAAK,cAAc,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,aAAa;YAC9E,IAAI,EAAE,CAAC,CAAC,I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;gBACR,iBAAiB,EAAE,eAAe;gBAClC,GAAG,CAAC,IAAI,EAAE,UAAU,KAAK,SAAS;oBAChC,CAAC,CAAC,EAAE,cAAc,EAAE,iBAAiB,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,EAAE;oBAC7D,CAAC,CAAC,EAAE,CAAC;aACR;SACF,CAAC,CAAC;IACL,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { RunRecord } from '../types/run-record.js';
2
+ import type { WorkflowDefinition } from '../types/workflow-definition.js';
3
+ import type { SettlementDelta, SettlementResult, SettleStepOutcome } from '../types/settlement.js';
4
+ /**
5
+ * Selects the finalizer steps that fire for a terminal `outcome`, in the drain order (design
6
+ * record §4/§6; extracted from `buildFinalizedSeal`'s selection, execution-loop.ts :3117-3126):
7
+ * Group A (rank precedence) — `on_outcome` contains `outcome` (the specific catch/complete arm);
8
+ * Group B — `on_outcome` contains `'always'` but NOT `outcome` (a finalizer listing both runs
9
+ * once, in Group A). Each group in `Object.entries` declaration order; Group A then Group B.
10
+ * `settledStepNames` excludes any finalizer already at-most-once settled (resume/re-drive safety)
11
+ * — pass `completed_steps ∪ failed_steps`, NEVER the `RunRecord.settled` map (a different,
12
+ * per-step-outcome-keyed structure this selection does not consult).
13
+ */
14
+ export declare function selectFinalizers(definition: WorkflowDefinition, settledStepNames: ReadonlySet<string>, outcome: SettleStepOutcome): string[];
15
+ /**
16
+ * Applies one {@link SettlementDelta} against `fresh` — pure, synchronous, no I/O, no registry
17
+ * (design record §7 CS-purity: `options` carries VALUES only). `definition` is passed per call
18
+ * (never cached) — `lease_finalizer`/`mark_finalizer` deltas do not use it (their arms never
19
+ * reference the workflow definition; only `settle_step`'s terminal-edge `mintFresh` does).
20
+ *
21
+ * `result.run` on `applied: true` is the AS-APPLIED transform output — see
22
+ * {@link SettlementResult}'s own doc for the never-a-re-read invariant this carries.
23
+ */
24
+ export declare function applySettlement(fresh: RunRecord, delta: SettlementDelta, definition: WorkflowDefinition, options?: {
25
+ now?: Date;
26
+ }): SettlementResult;
27
+ /**
28
+ * Named constant (issue #279, increment 2, PR-C; design record §4.3) tying reclaim-step.ts's own
29
+ * open-gate refusal (`reclaimStep`, ~line 389: "the claim is legitimately pinned by a human gate")
30
+ * to this design's "unfenced-release soundness rests on reclaim" premise: `settle_step` abort's
31
+ * cancel-gate write (`applyAbortEdge`, above) is the ONLY path that may release an open gate's
32
+ * claim; `reclaimStep`/`isAutoReclaimable` must NEVER also release it, or the two paths could race
33
+ * and double-release the same claim. Referenced (not asserted via) by this invariant's two
34
+ * existing pinning tests (`reclaim-step.test.ts` + the CLI's `reclaim.test.ts`) so a future reader
35
+ * can grep this name to find both, and reclaim-step.ts's own SOURCE stays untouched by this PR.
36
+ */
37
+ export declare const RECLAIM_REFUSES_GATE_STEP = "reclaim never releases the open-gate claim (design record design-d5-increment2.md \u00A74.3, unfenced-release soundness)";
38
+ //# sourceMappingURL=settlement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settlement.d.ts","sourceRoot":"","sources":["../../src/engine/settlement.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAoB,MAAM,iCAAiC,CAAC;AAC5F,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAEhB,iBAAiB,EAOlB,MAAM,wBAAwB,CAAC;AA4GhC;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,kBAAkB,EAC9B,gBAAgB,EAAE,WAAW,CAAC,MAAM,CAAC,EACrC,OAAO,EAAE,iBAAiB,GACzB,MAAM,EAAE,CAWV;AAuyBD;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,eAAe,EACtB,UAAU,EAAE,kBAAkB,EAC9B,OAAO,CAAC,EAAE;IAAE,GAAG,CAAC,EAAE,IAAI,CAAA;CAAE,GACvB,gBAAgB,CAkBlB;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,yBAAyB,6HACiF,CAAC"}