@intentius/chant 0.124.24 → 0.124.26
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/dist/cli/commands/build.d.ts.map +1 -1
- package/dist/cli/commands/build.js +4 -2
- package/dist/cli/commands/lint.d.ts.map +1 -1
- package/dist/cli/commands/lint.js +4 -2
- package/dist/cli/handlers/approve.d.ts.map +1 -1
- package/dist/cli/handlers/approve.js +39 -4
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +21 -7
- package/dist/cli/mcp/workspace-tools.d.ts +3 -3
- package/dist/cli/mcp/workspace-tools.d.ts.map +1 -1
- package/dist/cli/mcp/workspace-tools.js +27 -4
- package/dist/effect-receipt.d.ts +13 -0
- package/dist/effect-receipt.d.ts.map +1 -1
- package/dist/effect-receipt.js +19 -0
- package/dist/gate-decision.d.ts +1 -1
- package/dist/gate-decision.d.ts.map +1 -1
- package/dist/gate-decision.js +1 -1
- package/dist/lexicon-module.d.ts +7 -1
- package/dist/lexicon-module.d.ts.map +1 -1
- package/dist/lexicon-module.js +7 -2
- package/dist/lifecycle/gate-audit.d.ts +7 -1
- package/dist/lifecycle/gate-audit.d.ts.map +1 -1
- package/dist/lifecycle/gate-audit.js +40 -3
- package/dist/lifecycle/gate-checkpoint.d.ts +78 -0
- package/dist/lifecycle/gate-checkpoint.d.ts.map +1 -0
- package/dist/lifecycle/gate-checkpoint.js +103 -0
- package/dist/lifecycle/gate-ledger.d.ts +41 -0
- package/dist/lifecycle/gate-ledger.d.ts.map +1 -1
- package/dist/lifecycle/gate-ledger.js +18 -0
- package/dist/lifecycle/receipt-plan.d.ts.map +1 -1
- package/dist/lifecycle/receipt-plan.js +4 -2
- package/dist/lifecycle/run-ledger.d.ts +2 -0
- package/dist/lifecycle/run-ledger.d.ts.map +1 -1
- package/dist/lifecycle/run-ledger.js +2 -0
- package/dist/lint/rules/op/index.d.ts +6 -2
- package/dist/lint/rules/op/index.d.ts.map +1 -1
- package/dist/lint/rules/op/index.js +7 -3
- package/dist/lint/rules/op/ops016-gate-resume.d.ts +14 -0
- package/dist/lint/rules/op/ops016-gate-resume.d.ts.map +1 -0
- package/dist/lint/rules/op/ops016-gate-resume.js +31 -0
- package/dist/lint/rules/op/ops017-gate-alias.d.ts +30 -0
- package/dist/lint/rules/op/ops017-gate-alias.d.ts.map +1 -0
- package/dist/lint/rules/op/ops017-gate-alias.js +67 -0
- package/dist/op/activity-contract.d.ts +14 -0
- package/dist/op/activity-contract.d.ts.map +1 -1
- package/dist/op/activity-contract.js +16 -0
- package/dist/op/builders.d.ts +7 -0
- package/dist/op/builders.d.ts.map +1 -1
- package/dist/op/builders.js +13 -0
- package/dist/op/gate-alias.d.ts +57 -0
- package/dist/op/gate-alias.d.ts.map +1 -0
- package/dist/op/gate-alias.js +127 -0
- package/dist/op/gate-checkpoint.d.ts +123 -0
- package/dist/op/gate-checkpoint.d.ts.map +1 -0
- package/dist/op/gate-checkpoint.js +280 -0
- package/dist/op/gate.d.ts +54 -2
- package/dist/op/gate.d.ts.map +1 -1
- package/dist/op/gate.js +142 -1
- package/dist/op/index.d.ts +4 -1
- package/dist/op/index.d.ts.map +1 -1
- package/dist/op/index.js +2 -1
- package/dist/op/local-executor.d.ts +57 -2
- package/dist/op/local-executor.d.ts.map +1 -1
- package/dist/op/local-executor.js +200 -11
- package/dist/op/local-output.d.ts.map +1 -1
- package/dist/op/local-output.js +20 -2
- package/dist/op/op-ir.d.ts +4 -0
- package/dist/op/op-ir.d.ts.map +1 -1
- package/dist/op/op-ir.js +4 -0
- package/dist/op/receipt-store.d.ts +5 -0
- package/dist/op/receipt-store.d.ts.map +1 -1
- package/dist/op/receipt-store.js +4 -3
- package/dist/op/runtime.d.ts +15 -0
- package/dist/op/runtime.d.ts.map +1 -1
- package/dist/op/runtimes/local.d.ts.map +1 -1
- package/dist/op/runtimes/local.js +5 -0
- package/dist/op/step-output-ref.d.ts +26 -18
- package/dist/op/step-output-ref.d.ts.map +1 -1
- package/dist/op/step-output-ref.js +86 -63
- package/dist/op/types.d.ts +31 -0
- package/dist/op/types.d.ts.map +1 -1
- package/dist/wave-runtime.mjs +223 -221
- package/dist/workspace/agent-cli.d.ts.map +1 -1
- package/dist/workspace/agent-cli.js +3 -0
- package/dist/workspace/conformance/__writer_fixture__/answers/answer.schema.json +16 -1
- package/dist/workspace/conformance/writer.js +1 -1
- package/dist/workspace/decide.d.ts +51 -9
- package/dist/workspace/decide.d.ts.map +1 -1
- package/dist/workspace/decide.js +125 -14
- package/dist/workspace/lineage-upgrade.d.ts.map +1 -1
- package/dist/workspace/lineage-upgrade.js +20 -11
- package/dist/workspace/point-answer.schema.json +16 -1
- package/dist/workspace/points-cli.d.ts +5 -3
- package/dist/workspace/points-cli.d.ts.map +1 -1
- package/dist/workspace/points-cli.js +16 -7
- package/dist/workspace/points-write.schema.json +39 -4
- package/dist/workspace/points.schema.json +42 -3
- package/dist/workspace/reason-codes.d.ts +2 -1
- package/dist/workspace/reason-codes.d.ts.map +1 -1
- package/dist/workspace/reason-codes.js +2 -1
- package/dist/workspace/records-cli.d.ts +12 -2
- package/dist/workspace/records-cli.d.ts.map +1 -1
- package/dist/workspace/records-cli.js +27 -7
- package/dist/workspace/records-write.d.ts.map +1 -1
- package/dist/workspace/records-write.js +2 -3
- package/dist/workspace/records.d.ts +10 -4
- package/dist/workspace/records.d.ts.map +1 -1
- package/dist/workspace/records.js +16 -3
- package/dist/workspace/records.schema.json +2 -1
- package/dist/workspace/trust/gate-seal.d.ts +32 -1
- package/dist/workspace/trust/gate-seal.d.ts.map +1 -1
- package/dist/workspace/trust/gate-seal.js +41 -2
- package/dist/workspace/trust/seal.d.ts +1 -1
- package/dist/workspace/trust/seal.d.ts.map +1 -1
- package/dist/workspace/trust/seal.js +1 -1
- package/dist/workspace/trust/verify-cli.d.ts.map +1 -1
- package/dist/workspace/trust/verify-cli.js +2 -1
- package/dist/workspace/trust/verify.d.ts +22 -0
- package/dist/workspace/trust/verify.d.ts.map +1 -1
- package/dist/workspace/trust/verify.js +94 -14
- package/dist/workspace/write-scope.d.ts +3 -1
- package/dist/workspace/write-scope.d.ts.map +1 -1
- package/dist/workspace/write-scope.js +11 -4
- package/package.json +1 -1
- package/src/cli/commands/build.ts +9 -2
- package/src/cli/commands/lint.ts +4 -2
- package/src/cli/compiled-cli.e2e.test.ts +45 -1
- package/src/cli/handlers/approve.ts +46 -4
- package/src/cli/handlers/operator.test.ts +91 -0
- package/src/cli/main.test.ts +10 -0
- package/src/cli/main.ts +21 -7
- package/src/cli/mcp/workspace-tools.e2e.test.ts +1 -1
- package/src/cli/mcp/workspace-tools.ts +27 -4
- package/src/effect-receipt.ts +22 -0
- package/src/gate-decision.ts +2 -0
- package/src/lexicon-module.ts +9 -2
- package/src/lifecycle/gate-audit.ts +41 -4
- package/src/lifecycle/gate-checkpoint.test.ts +128 -0
- package/src/lifecycle/gate-checkpoint.ts +133 -0
- package/src/lifecycle/gate-ledger.ts +61 -0
- package/src/lifecycle/receipt-plan.test.ts +9 -0
- package/src/lifecycle/receipt-plan.ts +4 -1
- package/src/lifecycle/run-ledger.ts +4 -0
- package/src/lint/rules/op/index.ts +9 -3
- package/src/lint/rules/op/ops016-gate-resume.test.ts +53 -0
- package/src/lint/rules/op/ops016-gate-resume.ts +48 -0
- package/src/lint/rules/op/ops017-gate-alias.test.ts +85 -0
- package/src/lint/rules/op/ops017-gate-alias.ts +89 -0
- package/src/op/activity-contract.ts +22 -1
- package/src/op/builders.ts +21 -1
- package/src/op/effect-step.test.ts +95 -1
- package/src/op/gate-alias.e2e.test.ts +78 -0
- package/src/op/gate-alias.test.ts +350 -0
- package/src/op/gate-alias.ts +137 -0
- package/src/op/gate-checkpoint.test.ts +284 -0
- package/src/op/gate-checkpoint.ts +322 -0
- package/src/op/gate.ts +198 -4
- package/src/op/index.ts +4 -1
- package/src/op/local-executor.test.ts +65 -0
- package/src/op/local-executor.ts +248 -12
- package/src/op/local-output.ts +18 -2
- package/src/op/op-ir.test.ts +25 -0
- package/src/op/op-ir.ts +8 -0
- package/src/op/receipt-store.ts +13 -3
- package/src/op/runtime.ts +8 -0
- package/src/op/runtimes/local.ts +5 -0
- package/src/op/step-output-ref.test.ts +68 -24
- package/src/op/step-output-ref.ts +85 -65
- package/src/op/types.ts +32 -0
- package/src/workspace/agent-cli.ts +2 -0
- package/src/workspace/conformance/__writer_fixture__/answers/answer.schema.json +16 -1
- package/src/workspace/conformance/writer.ts +1 -1
- package/src/workspace/decide.test.ts +87 -3
- package/src/workspace/decide.ts +142 -17
- package/src/workspace/lineage-upgrade.test.ts +21 -0
- package/src/workspace/lineage-upgrade.ts +19 -11
- package/src/workspace/point-answer.schema.json +16 -1
- package/src/workspace/points-cli.ts +16 -8
- package/src/workspace/points-write.schema.json +39 -4
- package/src/workspace/points.schema.json +42 -3
- package/src/workspace/reason-codes.ts +2 -1
- package/src/workspace/record-assets.test.ts +14 -0
- package/src/workspace/records-cli.ts +28 -7
- package/src/workspace/records-write-commands.e2e.test.ts +32 -0
- package/src/workspace/records-write.ts +2 -3
- package/src/workspace/records.schema.json +2 -1
- package/src/workspace/records.ts +17 -4
- package/src/workspace/trust/gate-seal.test.ts +29 -2
- package/src/workspace/trust/gate-seal.ts +46 -2
- package/src/workspace/trust/seal.ts +1 -1
- package/src/workspace/trust/trust.test.ts +105 -0
- package/src/workspace/trust/verify-cli.ts +2 -1
- package/src/workspace/trust/verify.ts +106 -13
- package/src/workspace/write-scope.test.ts +18 -0
- package/src/workspace/write-scope.ts +16 -5
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resuming a run at an approved gate (#3947, epic #3946).
|
|
3
|
+
*
|
|
4
|
+
* Before this, a run that stopped at a gate kept nothing but its record:
|
|
5
|
+
* after `chant approve`, the next `chant run <op>` began again at the first
|
|
6
|
+
* phase and recomputed every step before the gate, so a value could not be
|
|
7
|
+
* carried across a gate with `stepOutput`. A gate with `resume: true` keeps
|
|
8
|
+
* the outputs the steps after it need, and the next run starts at the gate.
|
|
9
|
+
*
|
|
10
|
+
* Stopping. The run works out which outputs cross the gate from the Op's own
|
|
11
|
+
* references ({@link resumeGatesOf}): an output of a step before the gate
|
|
12
|
+
* that a step at or after it references, in the main phases, `onFailure` or
|
|
13
|
+
* the gate's own `approval` context. It writes them to a checkpoint
|
|
14
|
+
* (`../lifecycle/gate-checkpoint.ts`) and puts the checkpoint's digest on
|
|
15
|
+
* the pending fact. An output an activity contract marks secret is never
|
|
16
|
+
* stored, and the gate then doesn't resume ({@link checkpointBlocked}).
|
|
17
|
+
*
|
|
18
|
+
* Resuming. {@link decideGateResume} picks the last resume gate whose
|
|
19
|
+
* standing pending fact carries a checkpoint and has an approval that copied
|
|
20
|
+
* it. It resumes there only when the fact hasn't expired, the checkpoint file
|
|
21
|
+
* matches the digest the approver saw and names the fact's run, and this run
|
|
22
|
+
* is at the same commit and environment. Any failed check starts the run at
|
|
23
|
+
* the first phase and the reason is reported. The executor then re-runs the
|
|
24
|
+
* step that produced the gate's `plan`, and starts at the first phase if the
|
|
25
|
+
* digest moved, so live drift between the approval and the apply is still
|
|
26
|
+
* caught (`./local-executor.ts`).
|
|
27
|
+
*/
|
|
28
|
+
import { WORK_LEASE_STEP_ID } from "./types.js";
|
|
29
|
+
import { collectStepOutputRefs, isStepOutputRef } from "./step-output-ref.js";
|
|
30
|
+
import { gateName } from "./gate-name.js";
|
|
31
|
+
import { readsSecretOutput } from "./activity-contract.js";
|
|
32
|
+
import { isPendingGateExpired, latestPendingGate } from "../lifecycle/gate-ledger.js";
|
|
33
|
+
import { isApprovalSpent } from "../lifecycle/gate-applied.js";
|
|
34
|
+
import { samePlanDigest } from "../lifecycle/plan-digest.js";
|
|
35
|
+
import { checkpointOutputs, gateCheckpointDigest, gateCheckpointPath, isCheckpointRunId, parseGateCheckpoint, } from "../lifecycle/gate-checkpoint.js";
|
|
36
|
+
/** The step-output references a step reads when it runs: its args, a gate's plan, approval context and point inputs, and an effect's receipt and nested steps. */
|
|
37
|
+
function refsOfStep(step) {
|
|
38
|
+
if (step.kind === "activity")
|
|
39
|
+
return collectStepOutputRefs(step.args);
|
|
40
|
+
if (step.kind === "gate") {
|
|
41
|
+
const point = typeof step.point === "object" ? step.point.inputs : undefined;
|
|
42
|
+
return [
|
|
43
|
+
...(isStepOutputRef(step.plan) ? [step.plan] : []),
|
|
44
|
+
...collectStepOutputRefs(step.approval?.context),
|
|
45
|
+
...collectStepOutputRefs(point),
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
return [...collectStepOutputRefs(step.receipt), ...step.steps.flatMap(refsOfStep)];
|
|
49
|
+
}
|
|
50
|
+
/** Every gate step of `config` with `resume: true` that isn't at the top of a main phase. */
|
|
51
|
+
function misplacedResumeGates(config) {
|
|
52
|
+
const out = [];
|
|
53
|
+
for (const phase of config.phases) {
|
|
54
|
+
for (const step of phase.steps) {
|
|
55
|
+
if (step.kind === "effect")
|
|
56
|
+
for (const n of step.steps)
|
|
57
|
+
if (n.kind === "gate" && n.resume)
|
|
58
|
+
out.push({ phase: phase.name, gate: n });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
for (const phase of config.onFailure ?? []) {
|
|
62
|
+
for (const step of phase.steps) {
|
|
63
|
+
if (step.kind === "gate" && step.resume)
|
|
64
|
+
out.push({ phase: phase.name, gate: step });
|
|
65
|
+
if (step.kind === "effect")
|
|
66
|
+
for (const n of step.steps)
|
|
67
|
+
if (n.kind === "gate" && n.resume)
|
|
68
|
+
out.push({ phase: phase.name, gate: n });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The gates of `config` that resume, at the top of a main phase, in authored
|
|
75
|
+
* order, each with the outputs a checkpoint at it stores. A gate that asks a
|
|
76
|
+
* decision point, or one in an Op with a `workLease`, is left out: OPS016
|
|
77
|
+
* refuses both, and a run treats them as gates that don't resume.
|
|
78
|
+
*/
|
|
79
|
+
export function resumeGatesOf(config) {
|
|
80
|
+
if (config.workLease)
|
|
81
|
+
return [];
|
|
82
|
+
const out = [];
|
|
83
|
+
config.phases.forEach((phase, phaseIndex) => {
|
|
84
|
+
phase.steps.forEach((step, stepIndex) => {
|
|
85
|
+
if (step.kind !== "gate" || !step.resume || step.point !== undefined)
|
|
86
|
+
return;
|
|
87
|
+
// The steps that have finished when the run reaches the gate. In a
|
|
88
|
+
// parallel phase the gates are decided before any activity starts.
|
|
89
|
+
const before = new Map();
|
|
90
|
+
config.phases.forEach((p, pi) => {
|
|
91
|
+
if (pi > phaseIndex)
|
|
92
|
+
return;
|
|
93
|
+
p.steps.forEach((s, si) => {
|
|
94
|
+
if (s.kind !== "activity" || !s.id)
|
|
95
|
+
return;
|
|
96
|
+
if (pi === phaseIndex && (p.parallel || si >= stepIndex))
|
|
97
|
+
return;
|
|
98
|
+
before.set(s.id, { step: s, phaseIndex: pi, stepIndex: si });
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
const planStep = isStepOutputRef(step.plan) ? before.get(step.plan.step) : undefined;
|
|
102
|
+
// What reads them: the gate and every step after it, the compensation
|
|
103
|
+
// phases, the work lease, and the plan step, which runs again.
|
|
104
|
+
const after = [
|
|
105
|
+
...(phase.parallel ? phase.steps : phase.steps.slice(stepIndex)),
|
|
106
|
+
...config.phases.slice(phaseIndex + 1).flatMap((p) => p.steps),
|
|
107
|
+
...(config.onFailure ?? []).flatMap((p) => p.steps),
|
|
108
|
+
...(planStep ? [planStep.step] : []),
|
|
109
|
+
];
|
|
110
|
+
const crossing = after.flatMap(refsOfStep).filter((ref) => ref.step !== WORK_LEASE_STEP_ID && ref.step !== planStep?.step.id && before.has(ref.step));
|
|
111
|
+
const ids = new Set(crossing.map((r) => r.step));
|
|
112
|
+
const stored = [...before.values()]
|
|
113
|
+
.filter((p) => ids.has(p.step.id))
|
|
114
|
+
.sort((a, b) => a.phaseIndex - b.phaseIndex || a.stepIndex - b.stepIndex)
|
|
115
|
+
.map((p) => p.step.id);
|
|
116
|
+
out.push({ step, name: gateName(step), phaseIndex, stepIndex, ...(planStep ? { planStep } : {}), stored, crossing });
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
return out;
|
|
120
|
+
}
|
|
121
|
+
/** The step id that produced `ref`, and its activity, among the steps before `gate`. */
|
|
122
|
+
function producerOf(config, ref) {
|
|
123
|
+
for (const phase of config.phases) {
|
|
124
|
+
for (const step of phase.steps)
|
|
125
|
+
if (step.kind === "activity" && step.id === ref.step)
|
|
126
|
+
return step;
|
|
127
|
+
}
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Why a checkpoint at `gate` can't hold what the steps after it read, or
|
|
132
|
+
* undefined when it can (#3947): a reference to an output the producer's
|
|
133
|
+
* contract marks secret. Secret outputs are never stored.
|
|
134
|
+
*/
|
|
135
|
+
export function checkpointBlocked(config, gate, contracts) {
|
|
136
|
+
if (!contracts)
|
|
137
|
+
return undefined;
|
|
138
|
+
for (const ref of gate.crossing) {
|
|
139
|
+
const producer = producerOf(config, ref);
|
|
140
|
+
if (producer && readsSecretOutput(contracts.get(producer.fn), ref.path)) {
|
|
141
|
+
const what = ref.path ? `output "${ref.path}"` : "output";
|
|
142
|
+
return `step "${ref.step}"'s ${what} is secret (the ${producer.fn} contract marks it), and a checkpoint never stores a secret`;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* OPS016's check (#3947): what is wrong with the gates of `config` that set
|
|
149
|
+
* `resume`. A gate that resumes must sit at the top of a main phase, must not
|
|
150
|
+
* ask a decision point, must not be in an Op with a `workLease`, must name a
|
|
151
|
+
* plan step that runs before it when its plan is a reference, and must not
|
|
152
|
+
* need a secret output after it.
|
|
153
|
+
*/
|
|
154
|
+
export function validateGateResume(config, contracts) {
|
|
155
|
+
const issues = [];
|
|
156
|
+
const issue = (phase, gate, message) => issues.push({ opName: config.name, phase, fn: `gate:${gateName(gate)}`, message });
|
|
157
|
+
for (const { phase, gate } of misplacedResumeGates(config)) {
|
|
158
|
+
issue(phase, gate, "resume is supported only on a gate at the top of a main phase, not in onFailure or inside an effect");
|
|
159
|
+
}
|
|
160
|
+
config.phases.forEach((phase) => {
|
|
161
|
+
for (const step of phase.steps) {
|
|
162
|
+
if (step.kind !== "gate" || !step.resume)
|
|
163
|
+
continue;
|
|
164
|
+
if (config.workLease)
|
|
165
|
+
issue(phase.name, step, "a gate can't resume in an Op that runs under a workLease");
|
|
166
|
+
if (step.point !== undefined)
|
|
167
|
+
issue(phase.name, step, "a gate that asks a decision point can't resume");
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
for (const gate of resumeGatesOf(config)) {
|
|
171
|
+
const phase = config.phases[gate.phaseIndex].name;
|
|
172
|
+
if (isStepOutputRef(gate.step.plan) && !gate.planStep) {
|
|
173
|
+
issue(phase, gate.step, `its plan names step "${gate.step.plan.step}", which must be an activity that runs before the gate at the top of a main phase, so a resumed run can run it again`);
|
|
174
|
+
}
|
|
175
|
+
const blocked = checkpointBlocked(config, gate, contracts);
|
|
176
|
+
if (blocked)
|
|
177
|
+
issue(phase, gate.step, `can't resume: ${blocked}`);
|
|
178
|
+
}
|
|
179
|
+
return issues;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Build the checkpoint a run stores when it stops at `gate`, or say why it
|
|
183
|
+
* stores none: a secret output, an unknown commit, a run id that can't name
|
|
184
|
+
* a file, or an output JSON can't hold.
|
|
185
|
+
*/
|
|
186
|
+
export function buildGateCheckpoint(config, gate, input) {
|
|
187
|
+
const secret = checkpointBlocked(config, gate, input.contracts);
|
|
188
|
+
if (secret)
|
|
189
|
+
return { blocked: secret };
|
|
190
|
+
if (input.commit === undefined)
|
|
191
|
+
return { blocked: "the commit this run is at could not be read, and a resumed run must be at the same one" };
|
|
192
|
+
if (!isCheckpointRunId(input.runId))
|
|
193
|
+
return { blocked: `the run id "${input.runId}" can't name a checkpoint file` };
|
|
194
|
+
const stored = checkpointOutputs(input.outputs, gate.stored);
|
|
195
|
+
if ("unstorable" in stored)
|
|
196
|
+
return { blocked: `step "${stored.unstorable}"'s output can't be stored as JSON` };
|
|
197
|
+
return {
|
|
198
|
+
checkpoint: {
|
|
199
|
+
version: 1,
|
|
200
|
+
op: config.name,
|
|
201
|
+
gate: gate.name,
|
|
202
|
+
runId: input.runId,
|
|
203
|
+
commit: input.commit,
|
|
204
|
+
...(input.environment !== undefined ? { environment: input.environment } : {}),
|
|
205
|
+
...(input.planDigest !== undefined ? { planDigest: input.planDigest } : {}),
|
|
206
|
+
outputs: stored.outputs,
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Decide whether this run resumes, and at which gate. The last resume gate
|
|
212
|
+
* whose standing pending fact carries a checkpoint, and which an approval
|
|
213
|
+
* recorded since then copied, is the candidate. Approved gates are tried
|
|
214
|
+
* from the last one back, so a run that resumed at one gate and stopped at a
|
|
215
|
+
* later one resumes at the later one next time.
|
|
216
|
+
*
|
|
217
|
+
* Reads the gate ledger and the checkpoint file and writes nothing. A gate
|
|
218
|
+
* with no checkpoint, or none an approval copied, is not a candidate: the run
|
|
219
|
+
* starts at the first phase as before, and says nothing.
|
|
220
|
+
*/
|
|
221
|
+
export async function decideGateResume(port, config, input) {
|
|
222
|
+
const gates = resumeGatesOf(config);
|
|
223
|
+
if (gates.length === 0)
|
|
224
|
+
return { kind: "none" };
|
|
225
|
+
const ledger = await port.read(config.name);
|
|
226
|
+
const spent = port.readApplied ? await port.readApplied(config.name) : [];
|
|
227
|
+
const at = (iso) => new Date(iso).getTime();
|
|
228
|
+
for (const gate of [...gates].reverse()) {
|
|
229
|
+
const standing = latestPendingGate(ledger.pending, gate.name);
|
|
230
|
+
const digest = standing?.checkpointDigest;
|
|
231
|
+
if (!standing || digest === undefined)
|
|
232
|
+
continue;
|
|
233
|
+
// #3949: an approval carried from an alias never saw this gate's
|
|
234
|
+
// checkpoint, so it doesn't let the run resume. The run starts at the
|
|
235
|
+
// first phase and the carried approval passes the gate when it gets there.
|
|
236
|
+
const approved = ledger.resolutions.some((r) => r.gate === gate.name && r.carriedFrom === undefined && r.checkpointDigest === digest && at(r.timestamp) >= at(standing.timestamp) &&
|
|
237
|
+
samePlanDigest(r.planDigest, standing.planDigest) && !isApprovalSpent(spent, r));
|
|
238
|
+
if (!approved)
|
|
239
|
+
continue;
|
|
240
|
+
const refuse = (reason) => ({ kind: "refused", gate: gate.name, reason });
|
|
241
|
+
if (isPendingGateExpired(standing, input.now))
|
|
242
|
+
return refuse(`its pending fact expired at ${standing.expiresAt}`);
|
|
243
|
+
if (!standing.runId)
|
|
244
|
+
return refuse("its pending fact names no run");
|
|
245
|
+
const { dir, file } = gateCheckpointPath(config.name, standing.runId);
|
|
246
|
+
const text = port.readCheckpoint ? await port.readCheckpoint(config.name, standing.runId) : null;
|
|
247
|
+
if (text === null)
|
|
248
|
+
return refuse(`the checkpoint ${dir}/${file} is not on the ledger`);
|
|
249
|
+
const checkpoint = parseGateCheckpoint(text);
|
|
250
|
+
if (checkpoint === null)
|
|
251
|
+
return refuse(`${dir}/${file} is not a checkpoint`);
|
|
252
|
+
let actual;
|
|
253
|
+
try {
|
|
254
|
+
actual = gateCheckpointDigest(checkpoint);
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
return refuse(`${dir}/${file} is not a checkpoint`);
|
|
258
|
+
}
|
|
259
|
+
if (actual !== digest)
|
|
260
|
+
return refuse(`${dir}/${file} does not match the digest the approver saw (${digest}, the file is ${actual})`);
|
|
261
|
+
if (checkpoint.op !== config.name || checkpoint.gate !== gate.name || checkpoint.runId !== standing.runId) {
|
|
262
|
+
return refuse(`${dir}/${file} is for ${checkpoint.op} / ${checkpoint.gate}, run ${checkpoint.runId}`);
|
|
263
|
+
}
|
|
264
|
+
if (!samePlanDigest(checkpoint.planDigest, standing.planDigest))
|
|
265
|
+
return refuse(`${dir}/${file} names another plan than the pending fact`);
|
|
266
|
+
if (input.commit === undefined)
|
|
267
|
+
return refuse("the commit this run is at could not be read");
|
|
268
|
+
if (input.commit !== checkpoint.commit) {
|
|
269
|
+
return refuse(`the run that stopped there was at commit ${checkpoint.commit.slice(0, 12)}, and this one is at ${input.commit.slice(0, 12)}`);
|
|
270
|
+
}
|
|
271
|
+
if (input.environment !== checkpoint.environment) {
|
|
272
|
+
return refuse(`the run that stopped there was for environment ${checkpoint.environment ?? "(none)"}, and this one is for ${input.environment ?? "(none)"}`);
|
|
273
|
+
}
|
|
274
|
+
const missing = gate.stored.find((id) => !(id in checkpoint.outputs));
|
|
275
|
+
if (missing !== undefined)
|
|
276
|
+
return refuse(`${dir}/${file} holds no output for step "${missing}"`);
|
|
277
|
+
return { kind: "resume", gate, checkpoint, digest, pending: standing };
|
|
278
|
+
}
|
|
279
|
+
return { kind: "none" };
|
|
280
|
+
}
|
package/dist/op/gate.d.ts
CHANGED
|
@@ -34,6 +34,8 @@
|
|
|
34
34
|
import { type GateResolutionInput, type GateResolutionRecord, type PendingGateInput, type PendingGateRecord } from "../lifecycle/gate-ledger.js";
|
|
35
35
|
import { type AppliedGateRecord } from "../lifecycle/gate-applied.js";
|
|
36
36
|
import { type GateApprover, type ResolvedGateApproval } from "./gate-approval.js";
|
|
37
|
+
import { type GateCheckpoint } from "../lifecycle/gate-checkpoint.js";
|
|
38
|
+
import type { ResolvedGateAlias } from "./gate-alias.js";
|
|
37
39
|
/**
|
|
38
40
|
* What appending a pending fact learned about reaching the remote.
|
|
39
41
|
*
|
|
@@ -89,6 +91,15 @@ export interface GateLedgerPort {
|
|
|
89
91
|
pushed: boolean;
|
|
90
92
|
pushWarning?: string;
|
|
91
93
|
}>;
|
|
94
|
+
/**
|
|
95
|
+
* Store the checkpoint of a run that stops at a gate that resumes (#3947),
|
|
96
|
+
* at `_gates/<op>/checkpoints/<runId>.json`. Written before the pending
|
|
97
|
+
* fact that names its digest, and pushed with it. Absent on a port that
|
|
98
|
+
* keeps none, and the gate then doesn't resume.
|
|
99
|
+
*/
|
|
100
|
+
writeCheckpoint?(checkpoint: GateCheckpoint): Promise<void>;
|
|
101
|
+
/** The text of a run's checkpoint, or null when there is none (#3947). */
|
|
102
|
+
readCheckpoint?(op: string, runId: string): Promise<string | null>;
|
|
92
103
|
}
|
|
93
104
|
/** A workspace's rule for which approvals of a gate count (#3163): a signed approval, from a class when it names one. */
|
|
94
105
|
export interface GateApprovalRule {
|
|
@@ -123,6 +134,8 @@ export declare function memoryGateLedgerPort(seed?: {
|
|
|
123
134
|
appended: PendingGateRecord[];
|
|
124
135
|
resolved: GateResolutionRecord[];
|
|
125
136
|
applied: AppliedGateRecord[];
|
|
137
|
+
/** Checkpoint texts by `<op>/<runId>` (#3947). */
|
|
138
|
+
checkpoints: Map<string, string>;
|
|
126
139
|
};
|
|
127
140
|
/** What a caller has to say about the gate it just reached. */
|
|
128
141
|
export interface GateCheckInput {
|
|
@@ -178,6 +191,24 @@ export interface GateCheckInput {
|
|
|
178
191
|
fields?: Record<string, unknown>;
|
|
179
192
|
/** The pending fact it records carries `neverOverMcp` (#3821, chant#3485). */
|
|
180
193
|
neverOverMcp?: boolean;
|
|
194
|
+
/**
|
|
195
|
+
* The checkpoint of a run at a gate that resumes (#3947). Given, a pending
|
|
196
|
+
* fact this records first stores it through the port's `writeCheckpoint`
|
|
197
|
+
* and carries its digest as `checkpointDigest`. A standing fact with no
|
|
198
|
+
* checkpoint is recorded again, so the gate gets one.
|
|
199
|
+
*/
|
|
200
|
+
checkpoint?: GateCheckpoint;
|
|
201
|
+
/**
|
|
202
|
+
* The gate's old names (#3949), each with its Op filled in
|
|
203
|
+
* (`resolveGateAliases` in `./gate-alias.ts`). Read only on a gate bound
|
|
204
|
+
* to a plan. A person's approval recorded under one counts toward this
|
|
205
|
+
* gate when it answers that name's standing pending fact, the fact hasn't
|
|
206
|
+
* expired, it is for `planDigest` and `environment`, neither name has
|
|
207
|
+
* spent it, and it passes this gate's approval rule. An approval this
|
|
208
|
+
* counts is written again under this gate (`carriedFrom`), and a line
|
|
209
|
+
* carried earlier counts only while its alias is still declared.
|
|
210
|
+
*/
|
|
211
|
+
aliases?: readonly ResolvedGateAlias[];
|
|
181
212
|
}
|
|
182
213
|
/**
|
|
183
214
|
* A standing resolution that answers this gate but not this plan (#2300) —
|
|
@@ -221,11 +252,14 @@ export type GateCheck = {
|
|
|
221
252
|
/**
|
|
222
253
|
* Set on a gate that declares `approval` (#2508). `"quorum"` when enough
|
|
223
254
|
* human approvals were recorded, `"policy"` when an `enforce`-mode permit
|
|
224
|
-
* passed it on its own.
|
|
255
|
+
* passed it on its own. `"alias"` (#3949) when an approval recorded
|
|
256
|
+
* under one of the gate's aliases counted, on any gate.
|
|
225
257
|
*/
|
|
226
|
-
via?: "quorum" | "policy";
|
|
258
|
+
via?: "quorum" | "policy" | "alias";
|
|
227
259
|
/** Every approval that counted toward the quorum. Set with `via`. */
|
|
228
260
|
approvals?: GateResolutionRecord[];
|
|
261
|
+
/** The approvals this run carried from an alias and wrote under the gate's name (#3949). Set when `via` is `"alias"`. */
|
|
262
|
+
carried?: GateResolutionRecord[];
|
|
229
263
|
} | {
|
|
230
264
|
satisfied: false;
|
|
231
265
|
pending: PendingGateRecord;
|
|
@@ -306,6 +340,24 @@ export declare function tallyGateApprovals(records: GateResolutionRecord[], gate
|
|
|
306
340
|
* and environment are read.
|
|
307
341
|
*/
|
|
308
342
|
export declare function humanQuorumSince(pending: readonly PendingGateRecord[], standing: PendingGateRecord): string;
|
|
343
|
+
/**
|
|
344
|
+
* The approvals that answer `standing` (#3949): of its gate, environment and
|
|
345
|
+
* plan, recorded since it, or on a gate with an `approval` block since the
|
|
346
|
+
* human quorum's anchor ({@link humanQuorumSince}). The rule
|
|
347
|
+
* `resolutionAnswering` (`./gate-resume.ts`) decides by, without the tally:
|
|
348
|
+
* each one counts on its own toward a gate an alias names.
|
|
349
|
+
*/
|
|
350
|
+
export declare function approvalsAnswering(resolutions: readonly GateResolutionRecord[], standing: PendingGateRecord, pending?: readonly PendingGateRecord[]): GateResolutionRecord[];
|
|
351
|
+
/**
|
|
352
|
+
* The line a run writes for an approval it carries from an alias (#3949):
|
|
353
|
+
* the approval under `op`/`gate` at `now`, citing the line it came from.
|
|
354
|
+
* The approver, plan, environment, relay and seal are the original's. A
|
|
355
|
+
* policy decision is left behind, since it was evaluated against another
|
|
356
|
+
* gate, and so is a checkpoint digest, which moves onto `carriedFrom`: the
|
|
357
|
+
* approver saw that checkpoint, not one this gate stores, so a carried
|
|
358
|
+
* approval never lets a run resume.
|
|
359
|
+
*/
|
|
360
|
+
export declare function carriedApproval(r: GateResolutionRecord, op: string, gate: string, now: string): GateResolutionInput;
|
|
309
361
|
/**
|
|
310
362
|
* Decide a gate against the ledger, recording the pending fact when it isn't
|
|
311
363
|
* answered.
|
package/dist/op/gate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gate.d.ts","sourceRoot":"","sources":["../../src/op/gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EASL,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACvB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAA2D,KAAK,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAE5H,OAAO,EAAqB,KAAK,YAAY,EAAE,KAAK,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"gate.d.ts","sourceRoot":"","sources":["../../src/op/gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EASL,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACvB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAA2D,KAAK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,EAC/B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,QAAQ,EAAE,oBAAoB,EAC9B,cAAc,GAAE,MAAiB,GAChC,SAAS,CAiDX;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,SAAS,iBAAiB,EAAE,EAAE,QAAQ,EAAE,iBAAiB,GAAG,MAAM,CAc3G;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,SAAS,oBAAoB,EAAE,EAC5C,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,GAAE,SAAS,iBAAiB,EAAe,GACjD,oBAAoB,EAAE,CAOxB;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,oBAAoB,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,mBAAmB,CAsBnH;AAsDD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC,CAkKlG;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,MAAM,UAAQ,GAAG,MAAM,CAK1H;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,GAAE,MAAsB,GAAG,OAAO,CAAC,OAAO,CAAC,CAO9F"}
|
package/dist/op/gate.js
CHANGED
|
@@ -41,6 +41,7 @@ import { pushLifecycleReport, readBlobBySha, readBlobFromPath, readPathSha, requ
|
|
|
41
41
|
import { parseDuration } from "./duration.js";
|
|
42
42
|
import { resolveGateRunLocator } from "./gate-run-locator.js";
|
|
43
43
|
import { refuseGateWithoutRecording } from "../lifecycle/no-record.js";
|
|
44
|
+
import { gateCheckpointDigest, gateCheckpointText, readGateCheckpointText, writeGateCheckpoint } from "../lifecycle/gate-checkpoint.js";
|
|
44
45
|
/**
|
|
45
46
|
* The real port: the `chant/lifecycle` orphan branch.
|
|
46
47
|
*
|
|
@@ -80,6 +81,13 @@ export function gitGateLedgerPort(opts) {
|
|
|
80
81
|
const { record } = await appendPendingGate(input, opts);
|
|
81
82
|
return { record, ...(await pushLifecycleReport(opts)) };
|
|
82
83
|
},
|
|
84
|
+
async writeCheckpoint(checkpoint) {
|
|
85
|
+
await writeGateCheckpoint(checkpoint, opts);
|
|
86
|
+
},
|
|
87
|
+
async readCheckpoint(op, runId) {
|
|
88
|
+
await requireLifecycleLedger(opts);
|
|
89
|
+
return readGateCheckpointText(op, runId, opts);
|
|
90
|
+
},
|
|
83
91
|
async readApplied(op) {
|
|
84
92
|
await requireLifecycleLedger(opts);
|
|
85
93
|
const { dir, file } = appliedGatePath(op);
|
|
@@ -118,10 +126,18 @@ export function memoryGateLedgerPort(seed = {}) {
|
|
|
118
126
|
const appended = [];
|
|
119
127
|
const resolved = [];
|
|
120
128
|
const applied = [...(seed.applied ?? [])];
|
|
129
|
+
const checkpoints = new Map();
|
|
121
130
|
return {
|
|
122
131
|
appended,
|
|
123
132
|
resolved,
|
|
124
133
|
applied,
|
|
134
|
+
checkpoints,
|
|
135
|
+
async writeCheckpoint(checkpoint) {
|
|
136
|
+
checkpoints.set(`${checkpoint.op}/${checkpoint.runId}`, gateCheckpointText(checkpoint));
|
|
137
|
+
},
|
|
138
|
+
async readCheckpoint(op, runId) {
|
|
139
|
+
return checkpoints.get(`${op}/${runId}`) ?? null;
|
|
140
|
+
},
|
|
125
141
|
async readApplied(op) {
|
|
126
142
|
return applied.filter((a) => a.op === op);
|
|
127
143
|
},
|
|
@@ -278,6 +294,88 @@ export function humanQuorumSince(pending, standing) {
|
|
|
278
294
|
}
|
|
279
295
|
return anchor.timestamp;
|
|
280
296
|
}
|
|
297
|
+
/**
|
|
298
|
+
* The approvals that answer `standing` (#3949): of its gate, environment and
|
|
299
|
+
* plan, recorded since it, or on a gate with an `approval` block since the
|
|
300
|
+
* human quorum's anchor ({@link humanQuorumSince}). The rule
|
|
301
|
+
* `resolutionAnswering` (`./gate-resume.ts`) decides by, without the tally:
|
|
302
|
+
* each one counts on its own toward a gate an alias names.
|
|
303
|
+
*/
|
|
304
|
+
export function approvalsAnswering(resolutions, standing, pending = [standing]) {
|
|
305
|
+
const since = new Date(standing.approval ? humanQuorumSince(pending, standing) : standing.timestamp).getTime();
|
|
306
|
+
return resolutions.filter((r) => r.gate === standing.gate && r.environment === standing.environment && samePlanDigest(r.planDigest, standing.planDigest) &&
|
|
307
|
+
new Date(r.timestamp).getTime() >= since);
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* The line a run writes for an approval it carries from an alias (#3949):
|
|
311
|
+
* the approval under `op`/`gate` at `now`, citing the line it came from.
|
|
312
|
+
* The approver, plan, environment, relay and seal are the original's. A
|
|
313
|
+
* policy decision is left behind, since it was evaluated against another
|
|
314
|
+
* gate, and so is a checkpoint digest, which moves onto `carriedFrom`: the
|
|
315
|
+
* approver saw that checkpoint, not one this gate stores, so a carried
|
|
316
|
+
* approval never lets a run resume.
|
|
317
|
+
*/
|
|
318
|
+
export function carriedApproval(r, op, gate, now) {
|
|
319
|
+
return {
|
|
320
|
+
op,
|
|
321
|
+
gate,
|
|
322
|
+
resolvedBy: r.resolvedBy,
|
|
323
|
+
...(r.relayedBy !== undefined ? { relayedBy: r.relayedBy } : {}),
|
|
324
|
+
timestamp: now,
|
|
325
|
+
...(r.note ? { note: r.note } : {}),
|
|
326
|
+
...(r.url ? { url: r.url } : {}),
|
|
327
|
+
...(r.planDigest !== undefined ? { planDigest: r.planDigest } : {}),
|
|
328
|
+
...(r.environment !== undefined ? { environment: r.environment } : {}),
|
|
329
|
+
...(r.origin ? { origin: r.origin } : {}),
|
|
330
|
+
...(r.sameOriginOverride ? { sameOriginOverride: true } : {}),
|
|
331
|
+
approver: approverOf(r),
|
|
332
|
+
...(r.seal ? { seal: r.seal } : {}),
|
|
333
|
+
carriedFrom: {
|
|
334
|
+
op: r.op,
|
|
335
|
+
gate: r.gate,
|
|
336
|
+
timestamp: r.timestamp,
|
|
337
|
+
...(r.checkpointDigest !== undefined ? { checkpointDigest: r.checkpointDigest } : {}),
|
|
338
|
+
},
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* The approvals recorded under `input.aliases` that may count toward this
|
|
343
|
+
* gate (#3949), oldest first. Each answers its alias's standing pending
|
|
344
|
+
* fact, which hasn't expired and was recorded for this plan and
|
|
345
|
+
* environment. Each is a person's, is spent under neither name, hasn't been
|
|
346
|
+
* carried already (`ledger` is this gate's own, so a carried line that was
|
|
347
|
+
* spent keeps its original from being carried again), and passes `rule`,
|
|
348
|
+
* whose seal check reads the names the approval was signed under. One the
|
|
349
|
+
* rule refuses is added to `refused`.
|
|
350
|
+
*/
|
|
351
|
+
async function aliasApprovals(port, input, ledger, rule, now, refused) {
|
|
352
|
+
const at = (iso) => new Date(iso).getTime();
|
|
353
|
+
const carried = ledger.filter((r) => r.gate === input.gate && r.carriedFrom !== undefined);
|
|
354
|
+
const wasCarried = (r) => carried.some((c) => c.carriedFrom.op === r.op && c.carriedFrom.gate === r.gate && at(c.carriedFrom.timestamp) === at(r.timestamp) && c.resolvedBy === r.resolvedBy);
|
|
355
|
+
const ledgers = new Map();
|
|
356
|
+
const out = [];
|
|
357
|
+
for (const alias of input.aliases) {
|
|
358
|
+
let other = ledgers.get(alias.op);
|
|
359
|
+
if (!other)
|
|
360
|
+
ledgers.set(alias.op, (other = await port.read(alias.op)));
|
|
361
|
+
const pending = other.pending.filter((p) => p.environment === input.environment);
|
|
362
|
+
const standing = latestPendingGate(pending, alias.gate);
|
|
363
|
+
if (!standing || isPendingGateExpired(standing, now) || !samePlanDigest(standing.planDigest, input.planDigest))
|
|
364
|
+
continue;
|
|
365
|
+
const spent = alias.op === input.op && input.spent ? input.spent : ((await port.readApplied?.(alias.op)) ?? []);
|
|
366
|
+
for (const r of approvalsAnswering(other.resolutions, standing, pending)) {
|
|
367
|
+
if (r.carriedFrom !== undefined || approverOf(r).kind !== "human" || isApprovalSpent(spent, r) || wasCarried(r))
|
|
368
|
+
continue;
|
|
369
|
+
const reason = rule?.refuses(r) ?? null;
|
|
370
|
+
if (reason !== null) {
|
|
371
|
+
refused.push({ resolution: r, reason: `carried from ${alias.op}/${alias.gate}: ${reason}` });
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
out.push(r);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return out.sort((a, b) => at(a.timestamp) - at(b.timestamp));
|
|
378
|
+
}
|
|
281
379
|
/** Whether two resolved approval blocks are the same, so a standing pending fact still describes this gate. */
|
|
282
380
|
function sameApproval(a, b) {
|
|
283
381
|
return JSON.stringify(a ?? null, sortedJsonReplacer) === JSON.stringify(b ?? null, sortedJsonReplacer);
|
|
@@ -322,11 +420,16 @@ export async function evaluateGate(port, input) {
|
|
|
322
420
|
const rule = (await port.approvalRule?.(input.gate)) ?? null;
|
|
323
421
|
const standing = latestPendingGate(pending, input.gate);
|
|
324
422
|
const since = standing?.timestamp ?? EPOCH;
|
|
423
|
+
// #3949: aliases admit only approvals of this run's plan, and carrying one writes a line.
|
|
424
|
+
const aliases = input.planDigest !== undefined && port.appendResolution ? (input.aliases ?? []) : [];
|
|
425
|
+
const aliased = (from) => aliases.some((a) => a.op === from.op && a.gate === from.gate);
|
|
325
426
|
// #3841: an approval of this plan the rule refuses is named, so a wait says why.
|
|
326
427
|
const refused = [];
|
|
327
428
|
const resolutions = (env === undefined
|
|
328
429
|
? ledger.resolutions
|
|
329
430
|
: ledger.resolutions.filter((r) => r.environment === undefined || r.environment === env))
|
|
431
|
+
// #3949: a carried approval counts only while the gate still names its alias.
|
|
432
|
+
.filter((r) => r.gate !== input.gate || r.carriedFrom === undefined || aliased(r.carriedFrom))
|
|
330
433
|
.filter((r) => input.spent === undefined || r.gate !== input.gate || !isApprovalSpent(input.spent, r))
|
|
331
434
|
.filter((r) => {
|
|
332
435
|
if (rule === null || r.gate !== input.gate)
|
|
@@ -338,7 +441,15 @@ export async function evaluateGate(port, input) {
|
|
|
338
441
|
refused.push({ resolution: r, reason });
|
|
339
442
|
return false;
|
|
340
443
|
});
|
|
444
|
+
const fromAliases = aliases.length > 0 ? await aliasApprovals(port, { ...input, aliases }, ledger.resolutions, rule, now, refused) : [];
|
|
341
445
|
refused.sort((a, b) => new Date(a.resolution.timestamp).getTime() - new Date(b.resolution.timestamp).getTime());
|
|
446
|
+
// #3949: write the approvals that counted from an alias under this gate.
|
|
447
|
+
const carry = async (records) => {
|
|
448
|
+
const written = [];
|
|
449
|
+
for (const r of records)
|
|
450
|
+
written.push((await port.appendResolution(carriedApproval(r, input.op, input.gate, now))).record);
|
|
451
|
+
return written;
|
|
452
|
+
};
|
|
342
453
|
let mismatched;
|
|
343
454
|
let quorum;
|
|
344
455
|
if (input.approval) {
|
|
@@ -362,11 +473,30 @@ export async function evaluateGate(port, input) {
|
|
|
362
473
|
}
|
|
363
474
|
mismatched = tally.mismatched;
|
|
364
475
|
quorum = { approvers: tally.counted.map((r) => r.resolvedBy), need: tally.need };
|
|
476
|
+
// #3949: old and new approvals add up toward one quorum, each approver once.
|
|
477
|
+
const counted = new Set(tally.counted.map((r) => r.resolvedBy));
|
|
478
|
+
const extra = fromAliases.filter((r) => !counted.has(r.resolvedBy));
|
|
479
|
+
if (extra.length > 0) {
|
|
480
|
+
const asCarried = new Map(extra.map((r) => [{ version: 1, ...carriedApproval(r, input.op, input.gate, now) }, r]));
|
|
481
|
+
const combined = tallyGateApprovals([...resolutions, ...asCarried.keys()], input.gate, since, input.planDigest, input.approval, humansSince);
|
|
482
|
+
if (combined.counted.length >= combined.need) {
|
|
483
|
+
const written = await carry(combined.counted.filter((r) => asCarried.has(r)).map((r) => asCarried.get(r)));
|
|
484
|
+
const approvals = [...combined.counted.filter((r) => !asCarried.has(r)), ...written];
|
|
485
|
+
return { satisfied: true, resolution: written[written.length - 1], via: "alias", approvals, carried: written };
|
|
486
|
+
}
|
|
487
|
+
quorum = { approvers: combined.counted.map((r) => r.resolvedBy), need: combined.need };
|
|
488
|
+
}
|
|
365
489
|
}
|
|
366
490
|
else {
|
|
367
491
|
const found = latestResolutionForPlan(resolutions, input.gate, since, input.planDigest);
|
|
368
492
|
if (found.resolution)
|
|
369
493
|
return { satisfied: true, resolution: found.resolution };
|
|
494
|
+
// #3949: else the newest approval an alias admits passes it, written under this gate.
|
|
495
|
+
const newest = fromAliases[fromAliases.length - 1];
|
|
496
|
+
if (newest) {
|
|
497
|
+
const written = await carry([newest]);
|
|
498
|
+
return { satisfied: true, resolution: written[0], via: "alias", carried: written };
|
|
499
|
+
}
|
|
370
500
|
mismatched = found.mismatched;
|
|
371
501
|
}
|
|
372
502
|
// `input.planDigest` is defined whenever `mismatched` is — `latestResolutionForPlan`
|
|
@@ -389,10 +519,20 @@ export async function evaluateGate(port, input) {
|
|
|
389
519
|
// The same holds for the approval block (#2508): a pending fact recorded
|
|
390
520
|
// under another policy version or another context would have `chant
|
|
391
521
|
// approve` evaluate the policy against something this run no longer has.
|
|
522
|
+
// #3947: and for the checkpoint, so a gate that resumes gets one. A fact
|
|
523
|
+
// that already carries a checkpoint stands: an approval copies that one.
|
|
392
524
|
if (standing && !isPendingGateExpired(standing, now) && samePlanDigest(standing.planDigest, input.planDigest) &&
|
|
393
|
-
sameApproval(standing.approval, input.approval)
|
|
525
|
+
sameApproval(standing.approval, input.approval) &&
|
|
526
|
+
(input.checkpoint === undefined || port.writeCheckpoint === undefined || standing.checkpointDigest !== undefined)) {
|
|
394
527
|
return { satisfied: false, pending: standing, recorded: false, ...asMismatch };
|
|
395
528
|
}
|
|
529
|
+
// The checkpoint is written before the fact that names it, so a fact never
|
|
530
|
+
// points at a file that isn't there.
|
|
531
|
+
let checkpointDigest;
|
|
532
|
+
if (input.checkpoint !== undefined && port.writeCheckpoint) {
|
|
533
|
+
checkpointDigest = gateCheckpointDigest(input.checkpoint);
|
|
534
|
+
await port.writeCheckpoint(input.checkpoint);
|
|
535
|
+
}
|
|
396
536
|
const url = resolveApprovalUrl();
|
|
397
537
|
// #3683: in CI, where this job runs, so an approval can start it again.
|
|
398
538
|
const resume = resolveGateRunLocator();
|
|
@@ -407,6 +547,7 @@ export async function evaluateGate(port, input) {
|
|
|
407
547
|
...(url ? { url } : {}),
|
|
408
548
|
...(resume ? { resume } : {}),
|
|
409
549
|
...(input.planDigest !== undefined ? { planDigest: input.planDigest } : {}),
|
|
550
|
+
...(checkpointDigest !== undefined ? { checkpointDigest } : {}),
|
|
410
551
|
...(env !== undefined ? { environment: env } : {}),
|
|
411
552
|
...(input.approval ? { approval: input.approval } : {}),
|
|
412
553
|
...(input.neverOverMcp ? { neverOverMcp: true } : {}),
|
package/dist/op/index.d.ts
CHANGED
|
@@ -59,8 +59,11 @@ export type { OpRuntimeProvider, OpRunHandle, OpRunStartOptions, OpGateResolveOp
|
|
|
59
59
|
export { buildOpIR, serializeOpIR, opConfigFromIR, OP_IR_FORMAT_VERSION } from "./op-ir.js";
|
|
60
60
|
export type { OpIR, OpIRPhase, OpIRStep, OpIRActivityStep, OpIRGateStep, OpIREffectStep, OpIRActivityContract, } from "./op-ir.js";
|
|
61
61
|
export { renderHuman, renderJson } from "./local-output.js";
|
|
62
|
-
export { activityContract, isActivityContract, collectActivityContracts, validateActivitySteps, KNOWN_ACTIVITY_PROFILES, pathExistsInSchema, } from "./activity-contract.js";
|
|
62
|
+
export { activityContract, isActivityContract, collectActivityContracts, validateActivitySteps, KNOWN_ACTIVITY_PROFILES, pathExistsInSchema, readsSecretOutput, } from "./activity-contract.js";
|
|
63
63
|
export type { ActivityContract, ActivityContractIssue } from "./activity-contract.js";
|
|
64
|
+
export { validateGateResume, resumeGatesOf, decideGateResume } from "./gate-checkpoint.js";
|
|
65
|
+
export type { ResumeGate, GateResumeDecision } from "./gate-checkpoint.js";
|
|
66
|
+
export type { GateCheckpoint } from "../lifecycle/gate-checkpoint.js";
|
|
64
67
|
export { stepOutput, isStepOutputRef, collectStepOutputRefs, validateStepOutputRefs, validateStepOutputRefScope, makeOutProxy } from "./step-output-ref.js";
|
|
65
68
|
export type { StepOutputRef, WithStepRefs } from "./step-output-ref.js";
|
|
66
69
|
export type { NamedActivityStep } from "./builders.js";
|