@intentius/chant 0.124.56 → 0.124.57

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 (93) hide show
  1. package/dist/ci-audit/index.d.ts.map +1 -1
  2. package/dist/ci-audit/index.js +1 -2
  3. package/dist/ci-product.d.ts.map +1 -1
  4. package/dist/ci-product.js +4 -5
  5. package/dist/cli/handlers/lifecycle.d.ts.map +1 -1
  6. package/dist/cli/handlers/lifecycle.js +14 -0
  7. package/dist/cli/handlers/pr.d.ts.map +1 -1
  8. package/dist/cli/handlers/pr.js +90 -35
  9. package/dist/components/auto-release.d.ts +5 -2
  10. package/dist/components/auto-release.d.ts.map +1 -1
  11. package/dist/components/auto-release.js +9 -4
  12. package/dist/components/capability.d.ts +10 -0
  13. package/dist/components/capability.d.ts.map +1 -1
  14. package/dist/components/deploy-units.d.ts +12 -0
  15. package/dist/components/deploy-units.d.ts.map +1 -1
  16. package/dist/components/deploy-units.js +20 -1
  17. package/dist/components/pr-pipeline.d.ts +8 -2
  18. package/dist/components/pr-pipeline.d.ts.map +1 -1
  19. package/dist/components/pr-pipeline.js +11 -3
  20. package/dist/components/row-lease.d.ts +22 -1
  21. package/dist/components/row-lease.d.ts.map +1 -1
  22. package/dist/components/row-lease.js +32 -6
  23. package/dist/e2e-harness/index.d.ts.map +1 -1
  24. package/dist/e2e-harness/index.js +1 -2
  25. package/dist/lexicon.d.ts +9 -0
  26. package/dist/lexicon.d.ts.map +1 -1
  27. package/dist/lifecycle/git.d.ts +39 -3
  28. package/dist/lifecycle/git.d.ts.map +1 -1
  29. package/dist/lifecycle/git.js +223 -15
  30. package/dist/lifecycle/lock-rows.d.ts +23 -0
  31. package/dist/lifecycle/lock-rows.d.ts.map +1 -1
  32. package/dist/lifecycle/lock-rows.js +47 -8
  33. package/dist/lifecycle/resource-lock.d.ts +70 -0
  34. package/dist/lifecycle/resource-lock.d.ts.map +1 -1
  35. package/dist/lifecycle/resource-lock.js +241 -5
  36. package/dist/op/gate.js +21 -4
  37. package/dist/op/op-waves-release-port.js +1 -1
  38. package/dist/op/op-waves-release.d.ts +2 -1
  39. package/dist/op/op-waves-release.d.ts.map +1 -1
  40. package/dist/op/op-waves-run.d.ts +8 -0
  41. package/dist/op/op-waves-run.d.ts.map +1 -1
  42. package/dist/op/op-waves-run.js +101 -29
  43. package/dist/op/op-waves.d.ts +18 -0
  44. package/dist/op/op-waves.d.ts.map +1 -1
  45. package/dist/op/op-waves.js +16 -0
  46. package/dist/pr-loop.d.ts.map +1 -1
  47. package/dist/pr-loop.js +1 -2
  48. package/dist/release-floors.d.ts +1 -1
  49. package/dist/release-floors.js +1 -1
  50. package/dist/wave-runtime.mjs +310 -300
  51. package/package.json +1 -1
  52. package/src/ci-audit/index.ts +1 -2
  53. package/src/ci-product.ts +4 -5
  54. package/src/cli/handlers/lifecycle.ts +13 -0
  55. package/src/cli/handlers/pr-before-merge.test.ts +1 -1
  56. package/src/cli/handlers/pr-deploy-inputs.test.ts +1 -1
  57. package/src/cli/handlers/pr-endpoint.test.ts +1 -1
  58. package/src/cli/handlers/pr-green.test.ts +1 -1
  59. package/src/cli/handlers/pr-plan-comment-targets.test.ts +1 -1
  60. package/src/cli/handlers/pr-plan-flags.test.ts +1 -1
  61. package/src/cli/handlers/pr-plan-targets.test.ts +1 -1
  62. package/src/cli/handlers/pr-record.test.ts +34 -2
  63. package/src/cli/handlers/pr-waves-blocked.test.ts +1 -1
  64. package/src/cli/handlers/pr-waves.test.ts +1 -1
  65. package/src/cli/handlers/pr.test.ts +1 -1
  66. package/src/cli/handlers/pr.ts +86 -31
  67. package/src/components/auto-release.test.ts +4 -2
  68. package/src/components/auto-release.ts +9 -5
  69. package/src/components/capability.ts +10 -0
  70. package/src/components/deploy-units.test.ts +18 -1
  71. package/src/components/deploy-units.ts +26 -1
  72. package/src/components/pr-pipeline.ts +12 -3
  73. package/src/components/row-lease.test.ts +61 -1
  74. package/src/components/row-lease.ts +48 -7
  75. package/src/e2e-harness/index.ts +1 -2
  76. package/src/lexicon.ts +9 -0
  77. package/src/lifecycle/git.test.ts +155 -0
  78. package/src/lifecycle/git.ts +213 -17
  79. package/src/lifecycle/lock-rows.test.ts +6 -1
  80. package/src/lifecycle/lock-rows.ts +58 -7
  81. package/src/lifecycle/resource-lock-wait.test.ts +292 -0
  82. package/src/lifecycle/resource-lock.ts +261 -7
  83. package/src/op/gate.test.ts +7 -5
  84. package/src/op/gate.ts +20 -4
  85. package/src/op/op-waves-after-plan.test.ts +1 -2
  86. package/src/op/op-waves-ledger-lock.test.ts +208 -0
  87. package/src/op/op-waves-release-port.ts +1 -1
  88. package/src/op/op-waves-release.ts +1 -1
  89. package/src/op/op-waves-run.ts +104 -29
  90. package/src/op/op-waves.ts +18 -0
  91. package/src/pr-loop-bundle.test.ts +0 -2
  92. package/src/pr-loop.ts +1 -2
  93. package/src/release-floors.ts +1 -1
package/src/op/gate.ts CHANGED
@@ -59,7 +59,7 @@ import {
59
59
  quorumNeed, quorumRuleProgress, quorumRules, ruleNeedsProof, samePrincipal, trustQuorumJudge, UNPROVEN_JUDGE,
60
60
  type GateQuorumJudge, type GateQuorumRuleProgress, type GateQuorumSpec,
61
61
  } from "./gate-quorum";
62
- import { pushLifecycleReport, readBlobBySha, readBlobFromPath, readPathSha, requireLifecycleLedger, writeBlobToPath, RefCASConflictError } from "../lifecycle/git";
62
+ import { LifecyclePushLostError, pushLifecycleRebasing, readBlobBySha, readBlobFromPath, readPathSha, requireLifecycleLedger, writeBlobToPath, RefCASConflictError } from "../lifecycle/git";
63
63
  import { parseDuration } from "./duration";
64
64
  import { ciRunIdFromEnv, resolveGateRunLocator } from "./gate-run-locator";
65
65
  import { resolveCommitSha } from "../lifecycle/commit-sha";
@@ -202,11 +202,11 @@ export function gitGateLedgerPort(opts?: { cwd?: string }): GateLedgerPort {
202
202
  },
203
203
  async appendResolution(input) {
204
204
  const { record } = await appendGateResolution(input, opts);
205
- return { record, ...(await pushLifecycleReport(opts)) };
205
+ return { record, ...(await pushGateLine(opts)) };
206
206
  },
207
207
  async appendPending(input) {
208
208
  const { record } = await appendPendingGate(input, opts);
209
- return { record, ...(await pushLifecycleReport(opts)) };
209
+ return { record, ...(await pushGateLine(opts)) };
210
210
  },
211
211
  async writeCheckpoint(checkpoint) {
212
212
  await writeGateCheckpoint(checkpoint, opts);
@@ -255,7 +255,7 @@ export function gitGateLedgerPort(opts?: { cwd?: string }): GateLedgerPort {
255
255
  ...opts,
256
256
  expectPriorPathSha: prior,
257
257
  });
258
- return pushLifecycleReport(opts);
258
+ return pushGateLine(opts);
259
259
  } catch (err) {
260
260
  if (!(err instanceof RefCASConflictError)) throw err;
261
261
  lastErr = err;
@@ -1120,3 +1120,19 @@ export async function gateIsSealed(gate: string, cwd: string = process.cwd()): P
1120
1120
  return false;
1121
1121
  }
1122
1122
  }
1123
+
1124
+ /**
1125
+ * Push the gate line just written (plywood#22 finding 9): a push another
1126
+ * writer beat replays this checkout's commits on the remote's tip and pushes
1127
+ * again (`pushLifecycleRebasing`). One that never lands is reported as not
1128
+ * pushed, with `LifecyclePushLostError`'s message, so the spend line's
1129
+ * caller fails the wave as it does for any push that did not land.
1130
+ */
1131
+ async function pushGateLine(opts?: { cwd?: string }): Promise<{ pushed: boolean; pushWarning?: string }> {
1132
+ try {
1133
+ return await pushLifecycleRebasing(opts);
1134
+ } catch (err) {
1135
+ if (err instanceof LifecyclePushLostError) return { pushed: false, pushWarning: `LifecyclePushLostError: ${err.message}` };
1136
+ throw err;
1137
+ }
1138
+ }
@@ -11,7 +11,6 @@ import type { OpWavesSpec } from "./op-waves";
11
11
  import { assertOpWavesSpec } from "./op-waves";
12
12
  import { runOpWave, opWavePlanPath, type OpWaveShowAtBase } from "./op-waves-run";
13
13
  import { memoryGateLedgerPort } from "./gate";
14
- import { NEXT_RELEASE } from "../release-floors";
15
14
  import { CapabilityRegistry, type Capability } from "../components/capability";
16
15
  import type { ChangeSetPart } from "../change-set";
17
16
  import type { OpRunRecordInput } from "./runtime";
@@ -280,7 +279,7 @@ describe("opWavePlanPath", () => {
280
279
  test("is exported from the op entry beside opWavePlansPath, and names one target's plan file", async () => {
281
280
  const entry = await import("./index");
282
281
  expect(entry.opWavePlanPath).toBe(opWavePlanPath);
283
- expect(entry.OP_WAVE_PLAN_PATH_FLOOR).toBe(NEXT_RELEASE);
282
+ expect(entry.OP_WAVE_PLAN_PATH_FLOOR).toBe("0.124.56");
284
283
  const spec = { name: "demo" };
285
284
  expect(entry.opWavePlanPath(spec, 2, "stacks/a b")).toBe(".chant/op-waves/demo/wave-2/stacks_a_b.plan.json");
286
285
  expect(entry.opWavePlanPath(spec, 2, "x")).not.toBe(entry.opWavePlansPath(spec, 2));
@@ -0,0 +1,208 @@
1
+ /**
2
+ * Op waves under the ruling for ci-products (2026-10-28), "Ledger lock",
3
+ * and plywood#22 finding 9, on a bare remote with one clone per writer:
4
+ *
5
+ * - a run on the `target` grain whose lexicon names its target's row waits
6
+ * for it on the ledger, then applies; at the deadline it applies nothing,
7
+ * held, exit 5, by name;
8
+ * - a run on the resource grain never waits: a held row is exit 5 at once;
9
+ * - a run whose plan changes nothing takes no row;
10
+ * - the job's run record lands when another writer pushed to the same
11
+ * ledger file first.
12
+ */
13
+ import { afterAll, describe, expect, test } from "vitest";
14
+ import { execFileSync } from "node:child_process";
15
+ import { mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs";
16
+ import { tmpdir } from "node:os";
17
+ import { join } from "node:path";
18
+ import type { OpWavesSpec } from "./op-waves";
19
+ import { gitOpWaveRunPort, runOpWave, type OpWaveShowAtBase } from "./op-waves-run";
20
+ import { memoryGateLedgerPort } from "./gate";
21
+ import { CapabilityRegistry, type Capability } from "../components/capability";
22
+ import type { ChangeSetPart } from "../change-set";
23
+ import { rootRowKey, type LockGrain } from "../lifecycle/lock-rows";
24
+ import { leaseLockRows, readLockRows } from "../lifecycle/resource-lock";
25
+ import { appendRunRecord, readRunLedger } from "../lifecycle/run-ledger";
26
+ import { pushLifecycle } from "../lifecycle/git";
27
+ import { CHANT_EXIT } from "../exit-codes";
28
+
29
+ const dirs: string[] = [];
30
+ afterAll(() => {
31
+ for (const d of dirs) rmSync(d, { recursive: true, force: true });
32
+ });
33
+
34
+ function tmp(prefix: string): string {
35
+ const d = realpathSync(mkdtempSync(join(tmpdir(), prefix)));
36
+ dirs.push(d);
37
+ return d;
38
+ }
39
+
40
+ function git(cwd: string, ...args: string[]): string {
41
+ return execFileSync("git", args, { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
42
+ }
43
+
44
+ function writers(n: number): string[] {
45
+ const remote = tmp("op-waves-lock-remote-");
46
+ git(remote, "init", "-q", "--bare", "-b", "main");
47
+ const seed = tmp("op-waves-lock-seed-");
48
+ git(seed, "init", "-q", "-b", "main");
49
+ git(seed, "config", "user.email", "seed@chant.dev");
50
+ git(seed, "config", "user.name", "Seed");
51
+ git(seed, "config", "commit.gpgsign", "false");
52
+ writeFileSync(join(seed, "README.md"), "# t\n");
53
+ git(seed, "add", "README.md");
54
+ git(seed, "commit", "-q", "-m", "init");
55
+ git(seed, "remote", "add", "origin", remote);
56
+ git(seed, "push", "-q", "origin", "main");
57
+ return Array.from({ length: n }, (_, i) => {
58
+ const c = tmp(`op-waves-lock-clone-${i}-`);
59
+ git(c, "clone", "-q", remote, ".");
60
+ git(c, "config", "user.email", `w${i}@chant.dev`);
61
+ git(c, "config", "user.name", `Writer ${i}`);
62
+ git(c, "config", "commit.gpgsign", "false");
63
+ return c;
64
+ });
65
+ }
66
+
67
+ const digest = (n: string) => `sha256:${n.repeat(64)}`;
68
+ const alive = async () => "alive" as const;
69
+
70
+ /** A root capability on `grain`: the target grain names `root <root>`, the resource grain one row per root. */
71
+ function rootCapability(grain: LockGrain, action: "create" | "no-op" = "create"): { registry: CapabilityRegistry; ran: string[] } {
72
+ const ran: string[] = [];
73
+ const part = (member: string): ChangeSetPart => ({
74
+ member: { member, lexicon: "terraform", planner: "chant", status: "planned", planDigest: digest("9"), holes: [] },
75
+ entries: [{ member, address: `aws_s3_bucket.${member}`, type: "aws_s3_bucket", action } as ChangeSetPart["entries"][number]],
76
+ });
77
+ const cap: Capability<Record<string, unknown>, unknown> = {
78
+ kind: "fake-root",
79
+ async plan(_ctx, input) {
80
+ const root = String(input.root);
81
+ return { member: root, planDigest: digest(root === "network" ? "1" : "2"), artifact: { root }, changeSet: part(root) };
82
+ },
83
+ async run(_ctx, input) {
84
+ ran.push(String(input.root));
85
+ return { applied: input.root };
86
+ },
87
+ defaultLockGrain: () => grain,
88
+ targetLockRow: (input) => ({ key: rootRowKey(String(input.root)), target: String(input.root), address: String(input.root) }),
89
+ lockRows: (input) => [{ key: `root ${String(input.root)} aws_s3_bucket.${String(input.root)}`, target: String(input.root), address: `aws_s3_bucket.${String(input.root)}` }],
90
+ };
91
+ return { registry: new CapabilityRegistry().register(cap), ran };
92
+ }
93
+
94
+ const spec: OpWavesSpec = {
95
+ name: "roots",
96
+ op: "tf-apply",
97
+ step: { kind: "fake-root", root: "{target}" },
98
+ waves: [{ name: "dev", runs: [{ target: "network" }], gate: "never" }],
99
+ };
100
+ const show: OpWaveShowAtBase = () => ({ sha: "b".repeat(40), text: JSON.stringify(spec) });
101
+
102
+ describe("op waves and the ledger lock", () => {
103
+ test("a root on the target grain waits for its root row, then applies once the other run lets go", async () => {
104
+ const [other, job] = writers(2) as [string, string];
105
+ const held = await leaseLockRows("pr-apply", [{ key: rootRowKey("network"), target: "network", address: "network" }], { cwd: other, alive, holder: { run: "71", at: new Date().toISOString() } });
106
+ expect(held.ok).toBe(true);
107
+ if (!held.ok) return;
108
+ const { registry, ran } = rootCapability("target");
109
+ const lines: string[] = [];
110
+ // The other run lets go once the job shows in the queue, so the job waits whatever the machine's speed.
111
+ let stop = false;
112
+ const letGo = (async () => {
113
+ while (!stop) {
114
+ const now = await readLockRows("pr-apply", { cwd: other });
115
+ if (Object.keys(now.waiting ?? {}).length > 0) return held.lease.release();
116
+ await new Promise((r) => setTimeout(r, 50));
117
+ }
118
+ return false;
119
+ })();
120
+ try {
121
+ const result = await runOpWave({
122
+ spec,
123
+ specFile: "waves.json",
124
+ wave: 1,
125
+ cwd: job,
126
+ show,
127
+ gates: memoryGateLedgerPort(),
128
+ capabilities: registry,
129
+ lockLiveness: alive,
130
+ lockPollMs: 50,
131
+ lockWaitSeconds: 60,
132
+ log: (l) => lines.push(l),
133
+ });
134
+ expect(result).toMatchObject({ exitCode: 0, applied: ["network"] });
135
+ } finally {
136
+ stop = true;
137
+ }
138
+ expect(await letGo).toBe(true);
139
+ expect(ran).toEqual(["network"]);
140
+ const text = lines.join("\n");
141
+ expect(text).toContain("wave 1 (dev): waits for root network of pr-apply: run 71 is applying network: network");
142
+ expect(text).toMatch(/wave 1 \(dev\): holds 1 row of pr-apply after waiting \d+s while it applies/);
143
+ // The job let go of the row when the wave ended.
144
+ expect((await readLockRows("pr-apply", { cwd: other })).rows).toEqual({});
145
+ });
146
+
147
+ test("a wait that reaches the job's deadline applies nothing, held, exit 5, by name", async () => {
148
+ const [other, job] = writers(2) as [string, string];
149
+ const held = await leaseLockRows("pr-apply", [{ key: rootRowKey("network"), target: "network", address: "network" }], { cwd: other, alive, holder: { run: "72", at: new Date().toISOString() } });
150
+ expect(held.ok).toBe(true);
151
+ const { registry, ran } = rootCapability("target");
152
+ const result = await runOpWave({ spec, specFile: "waves.json", wave: 1, cwd: job, show, gates: memoryGateLedgerPort(), capabilities: registry, lockLiveness: alive, lockPollMs: 10, lockWaitSeconds: 0, log: () => {} });
153
+ expect(result.exitCode).toBe(CHANT_EXIT.held);
154
+ expect(result.outcome).toMatchObject({ outcome: "held", holder: { run: "72" } });
155
+ expect(result.outcome!.reason).toMatch(/^LockWaitTimeoutError: waited \d+s for root network of pr-apply/);
156
+ expect(ran).toEqual([]);
157
+ expect((await readLockRows("pr-apply", { cwd: other })).waiting).toBeUndefined();
158
+ });
159
+
160
+ test("a run on the resource grain never waits: a held row is exit 5 at once", async () => {
161
+ const [other, job] = writers(2) as [string, string];
162
+ const key = "root network aws_s3_bucket.network";
163
+ const held = await leaseLockRows("pr-apply", [{ key, target: "network", address: "aws_s3_bucket.network" }], { cwd: other, alive, holder: { run: "73", at: new Date().toISOString() } });
164
+ expect(held.ok).toBe(true);
165
+ const { registry, ran } = rootCapability("resource");
166
+ const result = await runOpWave({ spec, specFile: "waves.json", wave: 1, cwd: job, show, gates: memoryGateLedgerPort(), capabilities: registry, lockLiveness: alive, lockPollMs: 10, lockWaitSeconds: 60, log: () => {} });
167
+ expect(result.exitCode).toBe(CHANT_EXIT.held);
168
+ expect(result.outcome!.reason).not.toContain("LockWaitTimeoutError");
169
+ expect(ran).toEqual([]);
170
+ });
171
+
172
+ test("a run whose plan changes nothing takes no row and applies beside the holder", async () => {
173
+ const [other, job] = writers(2) as [string, string];
174
+ const held = await leaseLockRows("pr-apply", [{ key: rootRowKey("network"), target: "network", address: "network" }], { cwd: other, alive, holder: { run: "74", at: new Date().toISOString() } });
175
+ expect(held.ok).toBe(true);
176
+ const { registry } = rootCapability("target", "no-op");
177
+ const result = await runOpWave({ spec, specFile: "waves.json", wave: 1, cwd: job, show, gates: memoryGateLedgerPort(), capabilities: registry, lockLiveness: alive, lockPollMs: 10, lockWaitSeconds: 0, log: () => {} });
178
+ expect(result.exitCode).toBe(0);
179
+ });
180
+ });
181
+
182
+ describe("plywood#22 finding 9: the waves run's run record", () => {
183
+ test("lands on the remote when another writer appended to the same run ledger first", async () => {
184
+ const [a, b] = writers(2) as [string, string];
185
+ const record = (ended: string) => ({
186
+ op: "pulumi-up",
187
+ env: "dev",
188
+ started: "2026-10-28T23:39:08.000Z",
189
+ ended,
190
+ status: "ok" as const,
191
+ labels: { Env: "dev" },
192
+ outcomes: {},
193
+ phases: [],
194
+ });
195
+ // B's job wrote nothing yet; A, the other push's job, appends to dev/pulumi-up's ledger and pushes first.
196
+ await appendRunRecord(record("2026-10-28T23:40:03.000Z"), { cwd: a });
197
+ expect(await pushLifecycle({ cwd: a })).toBe(true);
198
+ git(b, "fetch", "-q", "origin", "chant/lifecycle:chant/lifecycle");
199
+ await appendRunRecord(record("2026-10-28T23:40:30.000Z"), { cwd: a });
200
+ expect(await pushLifecycle({ cwd: a })).toBe(true);
201
+ // B appends on the copy it fetched before A's second push, and its push replays on A's tip.
202
+ const port = gitOpWaveRunPort({ cwd: b });
203
+ expect(await port.append(record("2026-10-28T23:41:17.000Z"))).toEqual({});
204
+ git(a, "fetch", "-q", "origin", "chant/lifecycle:chant/lifecycle");
205
+ const { records } = await readRunLedger("dev", "pulumi-up", { cwd: a });
206
+ expect(records.map((r) => r.ended)).toEqual(["2026-10-28T23:40:03.000Z", "2026-10-28T23:40:30.000Z", "2026-10-28T23:41:17.000Z"]);
207
+ });
208
+ });
@@ -55,7 +55,7 @@ export function gitOpWaveReleasePort(opts: { cwd?: string; actor?: string } = {}
55
55
  if (got.recorded) {
56
56
  out.push({ recorded: true, env: req.env, component: req.component, digest: got.record.digest, ...(got.record.releaseDigest ? { releaseDigest: got.record.releaseDigest } : {}) });
57
57
  } else {
58
- out.push({ recorded: false, reason: got.reason === "error" ? got.error : got.detail ?? got.reason });
58
+ out.push({ recorded: false, reason: got.reason === "error" ? got.error : got.detail ?? got.reason, ...(got.reason === "error" && got.lost ? { lost: true as const } : {}) });
59
59
  }
60
60
  }
61
61
  return out;
@@ -59,7 +59,7 @@ export interface OpWaveReleaseRequest {
59
59
  /** How one record came out. */
60
60
  export type OpWaveReleaseOutcome =
61
61
  | { recorded: true; env: string; component: string; digest: string; releaseDigest?: string }
62
- | { recorded: false; reason: string };
62
+ | { recorded: false; reason: string; /** The record was written and its push never landed (plywood#22 finding 9). */ lost?: true };
63
63
 
64
64
  /** Where an op wave job's release records go (#4615). */
65
65
  export interface OpWaveReleasePort {
@@ -88,7 +88,7 @@ import type { TrustPolicy } from "../workspace/trust/policy";
88
88
  import type { GateSigners } from "../lifecycle/gate-seal";
89
89
  import { ciRunIdFromEnv } from "./gate-run-locator";
90
90
  import { appendRunRecord, DEFAULT_RUN_ENV } from "../lifecycle/run-ledger";
91
- import { pushLifecycleReport } from "../lifecycle/git";
91
+ import { LifecyclePushLostError, pushLifecycleRebasing } from "../lifecycle/git";
92
92
  import { resolveCiJob } from "../lifecycle/release-ledger";
93
93
  import type { OpRunPolicyRow, OpRunRecordInput, OpRunStepRecord, OpRunWave, OpRunWavePlan, OpRunWaveTarget } from "./runtime";
94
94
  import { foldPolicyRows, opWaveAfterPlanProblems, runOpWaveAfterPlanHooks, type OpWaveAfterPlanHook, type OpWaveAfterPlanRun } from "./op-waves-after-plan";
@@ -119,7 +119,6 @@ import {
119
119
  type OpWaveHolds,
120
120
  type OpWaveStepPlan,
121
121
  } from "./op-waves-capability";
122
- import { NEXT_RELEASE } from "../release-floors";
123
122
  import {
124
123
  changeInvolvement, quorumProblems, quorumRuleLine, quorumRulesFor, quorumWaiting, recordedReviewApprovals, ruleNeedsProof, samePrincipal, trustQuorumJudge,
125
124
  type GateQuorumJudge, type GateQuorumRule, type GateQuorumRuleProgress, type QuorumJudgement,
@@ -682,7 +681,7 @@ function pointAtBase(spec: OpWavesSpec, name: string, where: string): Pick<OpWav
682
681
  }
683
682
 
684
683
  /** The first chant whose op entry exports {@link opWavePlanPath} (terragucci#1304). */
685
- export const OP_WAVE_PLAN_PATH_FLOOR = NEXT_RELEASE;
684
+ export const OP_WAVE_PLAN_PATH_FLOOR = "0.124.56";
686
685
 
687
686
  /** Where a run's plan file goes: one target's plan, as opposed to {@link opWavePlansPath}, the wave's `plans.json`. */
688
687
  export function opWavePlanPath(spec: Pick<OpWavesSpec, "name">, wave: number, target: string): string {
@@ -790,6 +789,14 @@ export interface RunOpWaveOptions {
790
789
  lockGate?: string;
791
790
  /** Whether a run holding rows still runs (#4552). Default: the forge's answer, with the lease's age. */
792
791
  lockLiveness?: LockLiveness;
792
+ /**
793
+ * How long a wave on the `target` or `repo` grain waits for its rows, in
794
+ * seconds (ruling for ci-products 2026-10-28). Default `CHANT_LOCK_WAIT`,
795
+ * which the waves pipelines set from the job's timeout.
796
+ */
797
+ lockWaitSeconds?: number;
798
+ /** How often a waiting wave reads the rows file again, in ms. Default `CHANT_LOCK_POLL` seconds, else 10 s. */
799
+ lockPollMs?: number;
793
800
  /** Overrides the spec's `standDown` (#4581). */
794
801
  standDown?: boolean;
795
802
  /** How the job finds a newer commit on its branch (#4581). Default: fetch the branch from `origin` ({@link gitOpWaveNewerCommit}). */
@@ -833,7 +840,8 @@ export function gitOpWaveRunPort(opts?: { cwd?: string }): OpWaveRunPort {
833
840
  return {
834
841
  async append(record) {
835
842
  await appendRunRecord(record, opts);
836
- const { pushWarning } = await pushLifecycleReport(opts);
843
+ // plywood#22 finding 9: a push another writer beat replays on its tip and pushes again; one that never lands throws LifecyclePushLostError.
844
+ const { pushWarning } = await pushLifecycleRebasing(opts);
837
845
  return pushWarning ? { pushWarning } : {};
838
846
  },
839
847
  };
@@ -1100,36 +1108,88 @@ async function declaredLockGrain(cwd: string, base: string | undefined): Promise
1100
1108
  }
1101
1109
 
1102
1110
  /**
1103
- * Lease the rows of a wave's runs on the resource grain (#4552), before
1104
- * anything of the wave applies, all in one take. A held row makes the wave
1105
- * apply nothing with the `held` outcome, exit 5, naming the run that holds it.
1111
+ * Lease the rows of a wave's runs (#4552), before anything of the wave
1112
+ * applies. First the rows its runs on the `target` and `repo` grains wait
1113
+ * for (ruling for ci-products 2026-10-28, "Ledger lock"): a stock Pulumi
1114
+ * stack's `stack` row, a Terraform root's `root` row, the `repo` row. The
1115
+ * wave waits for them in the ledger's queue, oldest commit first, up to
1116
+ * `lockWaitSeconds` (`CHANT_LOCK_WAIT`, set from the job's timeout), and at
1117
+ * the deadline applies nothing with the `held` outcome, exit 5. Then the rows
1118
+ * of its runs on the resource grain, all in one take with no wait: a held row
1119
+ * makes the wave apply nothing with the `held` outcome, exit 5, naming the
1120
+ * run that holds it. A run whose plan changes nothing takes no row, and
1121
+ * outside a git work tree the waiting grains take none.
1106
1122
  */
1107
1123
  async function leaseWaveRows(
1108
1124
  options: RunOpWaveOptions,
1109
1125
  ctx: WaveContext,
1110
1126
  runs: readonly OpWaveRun[],
1111
1127
  ): Promise<{ release(): Promise<boolean> } | OpWaveApplyOutcome | { failed: string } | undefined> {
1112
- const rows = runs.flatMap((r) => {
1113
- const lock = ctx.steps?.get(r.target)?.lock;
1114
- return lock?.grain === "resource" ? lock.rows : [];
1128
+ const locks = runs.flatMap((r) => {
1129
+ const plan = ctx.steps?.get(r.target);
1130
+ return plan?.lock && !plan.empty ? [plan.lock] : [];
1115
1131
  });
1116
- if (rows.length === 0) return undefined;
1117
- const { leaseLockRows } = await import("../lifecycle/resource-lock");
1132
+ const rows = locks.flatMap((l) => (l.grain === "resource" ? l.rows : []));
1133
+ // Outside a git work tree no ledger holds a queue, so a waiting grain takes no row there, as `chant run --components` takes none.
1134
+ const queued = locks.flatMap((l) => (l.grain !== "resource" ? (l.queue ?? []) : []));
1135
+ const queue = queued.length > 0 && inGitWorkTree(ctx.cwd) ? queued : [];
1136
+ if (rows.length === 0 && queue.length === 0) return undefined;
1137
+ const { commitTimeOf, leaseLockRows, lockPollMs, lockWaitSeconds } = await import("../lifecycle/resource-lock");
1118
1138
  const { PR_APPLY_GATE } = await import("../pr-loop");
1119
1139
  const gate = options.lockGate ?? PR_APPLY_GATE;
1120
- let leased: Awaited<ReturnType<typeof leaseLockRows>>;
1121
- try {
1122
- leased = await leaseLockRows(gate, rows, { cwd: ctx.cwd, ...(options.lockLiveness ? { alive: options.lockLiveness } : {}) });
1123
- } catch (err) {
1124
- return { failed: `wave ${ctx.k} (${ctx.wave.name}): could not hold the rows its runs change in ${gate}, so nothing was applied: ${err instanceof Error ? err.message : String(err)}` };
1140
+ const label = `wave ${ctx.k} (${ctx.wave.name})`;
1141
+ const alive = options.lockLiveness ? { alive: options.lockLiveness } : {};
1142
+ const held: Array<{ release(): Promise<boolean> }> = [];
1143
+ const releaseAll = async () => {
1144
+ let ok = true;
1145
+ for (const l of held.reverse()) ok = (await l.release()) && ok;
1146
+ return ok;
1147
+ };
1148
+ const take = async (wanted: typeof rows, wait: boolean): Promise<OpWaveApplyOutcome | { failed: string } | undefined> => {
1149
+ if (wanted.length === 0) return undefined;
1150
+ let leased: Awaited<ReturnType<typeof leaseLockRows>>;
1151
+ try {
1152
+ const waitFor = wait
1153
+ ? {
1154
+ wait: {
1155
+ deadline: Date.now() + (options.lockWaitSeconds ?? lockWaitSeconds(process.env)) * 1000,
1156
+ pollMs: options.lockPollMs ?? lockPollMs(process.env),
1157
+ log: (line: string) => ctx.log(`${label}: ${line}`),
1158
+ ...(await commitTimeOf(options.head ?? "HEAD", ctx.cwd).then((t) => (t ? { commitAt: t } : {}))),
1159
+ },
1160
+ }
1161
+ : {};
1162
+ leased = await leaseLockRows(gate, wanted, { cwd: ctx.cwd, ...alive, ...waitFor });
1163
+ } catch (err) {
1164
+ return { failed: `${label}: could not hold the rows its runs change in ${gate}, so nothing was applied: ${err instanceof Error ? err.message : String(err)}` };
1165
+ }
1166
+ if (!leased.ok) {
1167
+ const first = leased.held[0]?.holder;
1168
+ const reason = leased.timedOut ? `LockWaitTimeoutError: ${leased.message}` : leased.message;
1169
+ return { outcome: "held", reason, ...(first ? { holder: { run: first.run, ...(first.url ? { url: first.url } : {}) } } : {}) };
1170
+ }
1171
+ for (const h of leased.tookOver) ctx.log(`${label}: took over the rows of run ${h.run}, which is gone`);
1172
+ const waited = leased.waited ? ` after waiting ${leased.waitedSeconds ?? 0}s` : "";
1173
+ ctx.log(`${label}: holds ${leased.lease.keys.length} row${leased.lease.keys.length === 1 ? "" : "s"} of ${gate}${waited} while it applies`);
1174
+ held.push(leased.lease);
1175
+ return undefined;
1176
+ };
1177
+ for (const [wanted, wait] of [[queue, true], [rows, false]] as const) {
1178
+ const stop = await take(wanted, wait);
1179
+ if (stop) {
1180
+ if (!(await releaseAll())) ctx.log(`${label}: could not let go of the rows it held; the next apply takes them over once this run is gone`);
1181
+ return stop;
1182
+ }
1125
1183
  }
1126
- if (!leased.ok) {
1127
- const first = leased.held[0]!.holder;
1128
- return { outcome: "held", reason: leased.message, holder: { run: first.run, ...(first.url ? { url: first.url } : {}) } };
1184
+ return { release: releaseAll };
1185
+ }
1186
+
1187
+ function inGitWorkTree(cwd: string): boolean {
1188
+ try {
1189
+ return execFileSync("git", ["rev-parse", "--is-inside-work-tree"], { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim() === "true";
1190
+ } catch {
1191
+ return false;
1129
1192
  }
1130
- for (const h of leased.tookOver) ctx.log(`wave ${ctx.k} (${ctx.wave.name}): took over the rows of run ${h.run}, which is gone`);
1131
- ctx.log(`wave ${ctx.k} (${ctx.wave.name}): holds ${leased.lease.keys.length} row${leased.lease.keys.length === 1 ? "" : "s"} of ${gate} while it applies`);
1132
- return leased.lease;
1133
1193
  }
1134
1194
 
1135
1195
  /** A wave's cost hold over its plans (#4545): each changing run priced, the sum against `approveAbove`. */
@@ -1782,12 +1842,14 @@ export async function runOpWave(options: RunOpWaveOptions): Promise<RunOpWaveRes
1782
1842
  try {
1783
1843
  result = await runOpWaveJob(options);
1784
1844
  } catch (err) {
1785
- const record = await recordOpWaveRun(options, started, { error: err });
1845
+ const { lost: _lost, ...record } = await recordOpWaveRun(options, started, { error: err });
1786
1846
  await closeOpWaveEvents(options, events, record);
1787
1847
  throw err;
1788
1848
  }
1789
- const record = await recordOpWaveRun(options, started, { result });
1849
+ const { lost, ...record } = await recordOpWaveRun(options, started, { result });
1790
1850
  await closeOpWaveEvents(options, events, record, result);
1851
+ // plywood#22 finding 9: a run record that never reached the remote fails a job that would have passed.
1852
+ if (lost !== undefined && result.exitCode === CHANT_EXIT.done) result.exitCode = CHANT_EXIT.failed;
1791
1853
  return result;
1792
1854
  }
1793
1855
 
@@ -1950,8 +2012,13 @@ export function opWaveRunRecord(
1950
2012
  };
1951
2013
  }
1952
2014
 
1953
- /** Append the job's run record (#4551). A failed write warns and never changes the job's exit code. */
1954
- async function recordOpWaveRun(options: RunOpWaveOptions, started: string, outcome: { result: RunOpWaveResult } | { error: unknown }): Promise<OpRunRecordInput> {
2015
+ /**
2016
+ * Append the job's run record (#4551). A failed write warns and never
2017
+ * changes the job's exit code, except a record whose push never landed
2018
+ * after its replays (`LifecyclePushLostError`, plywood#22 finding 9): that
2019
+ * fails the job by name, through `lost`.
2020
+ */
2021
+ async function recordOpWaveRun(options: RunOpWaveOptions, started: string, outcome: { result: RunOpWaveResult } | { error: unknown }): Promise<OpRunRecordInput & { lost?: string }> {
1955
2022
  const cwd = options.cwd ?? process.cwd();
1956
2023
  const port = options.runs ?? (options.gates ? undefined : gitOpWaveRunPort({ cwd }));
1957
2024
  const log = options.log ?? ((line: string) => console.error(line));
@@ -1971,7 +2038,12 @@ async function recordOpWaveRun(options: RunOpWaveOptions, started: string, outco
1971
2038
  const wrote = await port.append(record);
1972
2039
  if (wrote && wrote.pushWarning) log(`wave ${options.wave}: the run record was written and not pushed: ${wrote.pushWarning}`);
1973
2040
  } catch (err) {
1974
- log(`wave ${options.wave}: could not record the run on the run ledger: ${err instanceof Error ? err.message : String(err)}`);
2041
+ const message = err instanceof Error ? err.message : String(err);
2042
+ if (err instanceof LifecyclePushLostError) {
2043
+ log(`wave ${options.wave}: LifecyclePushLostError: the run record was written and never reached the remote, so the job fails: ${message}`);
2044
+ return Object.assign(record, { lost: message });
2045
+ }
2046
+ log(`wave ${options.wave}: could not record the run on the run ledger: ${message}`);
1975
2047
  }
1976
2048
  return record;
1977
2049
  }
@@ -3566,7 +3638,9 @@ async function applyStepRunsAtOnce(options: RunOpWaveOptions, ctx: WaveContext,
3566
3638
  /**
3567
3639
  * The release records of the runs this wave applied through its step
3568
3640
  * (#4615), one per run, on the environment ledger each names. A record that
3569
- * is not written is a line in the log; the job's exit code stays.
3641
+ * is not written is a line in the log and the job's exit code stays, except
3642
+ * one written whose push never landed after its replays (plywood#22 finding
3643
+ * 9), which fails the wave by name.
3570
3644
  */
3571
3645
  async function recordStepReleases(options: RunOpWaveOptions, ctx: WaveContext, decision: OpWaveDecision, runs: readonly OpWaveRun[]): Promise<void> {
3572
3646
  const { spec, k, wave, log, result } = ctx;
@@ -3601,6 +3675,7 @@ async function recordStepReleases(options: RunOpWaveOptions, ctx: WaveContext, d
3601
3675
  for (const [i, req] of requests.entries()) {
3602
3676
  const got = outcomes[i];
3603
3677
  if (got?.recorded) log(`${req.target}: recorded on the "${got.env}" release ledger as ${got.component} ${got.digest}${got.releaseDigest ? ` under release ${got.releaseDigest}` : ""}`);
3678
+ else if (got && !got.recorded && got.lost) failed(ctx, `${req.target}: applied, and LifecyclePushLostError: the release record for ${req.component} in "${req.env}" was written and never reached the remote, so the wave fails: ${got.reason}`);
3604
3679
  else log(`${req.target}: applied, and no release record was written for ${req.component} in "${req.env}": ${got?.reason ?? "the port gave no answer"}`);
3605
3680
  }
3606
3681
  }
@@ -651,6 +651,24 @@ export interface OpWavesDigest {
651
651
  over?: "all" | "changing";
652
652
  }
653
653
 
654
+ /**
655
+ * A wave job's default timeout in minutes (ruling for ci-products
656
+ * 2026-10-28, "Ledger lock"): three hours, a Forgejo runner's default, under
657
+ * GitHub's six. The generators write it on every wave job.
658
+ */
659
+ export const OP_WAVE_JOB_TIMEOUT_MINUTES = 180;
660
+
661
+ /**
662
+ * The job's timeout, and the `CHANT_LOCK_WAIT` a wave job carries: the
663
+ * seconds a run on the `target` or `repo` grain waits for its row on the
664
+ * ledger, five minutes under the job's timeout (at least one minute), so the
665
+ * wait gives up by name before the forge stops the job.
666
+ */
667
+ export function opWaveJobTimeout(minutes: number | undefined): { minutes: number; env: { CHANT_LOCK_WAIT: string } } {
668
+ const m = minutes !== undefined && Number.isFinite(minutes) && minutes > 0 ? Math.ceil(minutes) : OP_WAVE_JOB_TIMEOUT_MINUTES;
669
+ return { minutes: m, env: { CHANT_LOCK_WAIT: String(Math.max(60, (m - 5) * 60)) } };
670
+ }
671
+
654
672
  export const OP_WAVES_DIGEST_OVER = ["all", "changing"] as const;
655
673
 
656
674
  /** The default gate name pattern. */
@@ -45,8 +45,6 @@ describe("the pull-request loop bundle", () => {
45
45
  "packages/core/src/pr-migrations.ts",
46
46
  // The Pulumi URN rule (#4548, the may-appear rows): no imports.
47
47
  "packages/core/src/pulumi-urn.ts",
48
- // The next-release floor constant (#4480, #4626's narrowed floor): no imports.
49
- "packages/core/src/release-floors.ts",
50
48
  ]);
51
49
  // About 89 KB today, after the hooks line (#4288), the blocked set (#4291), the scheduled-run reads (#4289) the requires checks (#4301) and the migration notes (#4407), about 97 KB; with the group lines (#4446), about 100 KB.
52
50
  // 120 KB (122,880 bytes) is the ruled ceiling: raised from 110 KB by the maintainer ruling of 2026-10-27 on #4481. It is not a figure to lower by trimming note text.
package/src/pr-loop.ts CHANGED
@@ -47,7 +47,6 @@
47
47
  * `identity.gates` entry covers every member.
48
48
  */
49
49
 
50
- import { NEXT_RELEASE } from "./release-floors";
51
50
  import type { ChangeSetAction, ChangeSetDocument, ChangeSetEntry } from "./change-set";
52
51
  import { parsePulumiUrn, pulumiMayAppearParent } from "./pulumi-urn";
53
52
  import type { PrRequireOutcome } from "./pr-requires";
@@ -105,7 +104,7 @@ export const PR_REPORT_GROUPS_FLOOR = "0.124.54";
105
104
  export const PR_REPORT_LOCK_TARGETS_FLOOR = "0.124.55";
106
105
 
107
106
  /** The first chant whose report carries {@link PrReport.narrowed} (#4626). */
108
- export const PR_REPORT_NARROWED_FLOOR = NEXT_RELEASE;
107
+ export const PR_REPORT_NARROWED_FLOOR = "0.124.56";
109
108
 
110
109
  /** The first chant whose report carries {@link PrReport.crossStackEdges} (#4617). */
111
110
  export const PR_REPORT_CROSS_STACK_FLOOR = "0.124.55";
@@ -19,4 +19,4 @@
19
19
  * this constant to the next patch (#4501). The check fails while a floor
20
20
  * still names this constant after its version shipped.
21
21
  */
22
- export const NEXT_RELEASE = "0.124.56";
22
+ export const NEXT_RELEASE = "0.124.57";