@kungfu-tech/buildchain 4.0.2-alpha.14 → 4.0.2-alpha.16

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.
@@ -26,12 +26,12 @@
26
26
  },
27
27
  "repositoryBudgets": {
28
28
  "baselineRevision": "858dbe00b6206a8f356b4a12d2659bee7a72e71b",
29
- "maxHandMaintainedSourceFiles": 462,
30
- "maxHandMaintainedSourceLines": 170347,
29
+ "maxHandMaintainedSourceFiles": 463,
30
+ "maxHandMaintainedSourceLines": 170469,
31
31
  "maxWorkflowFiles": 80,
32
32
  "maxWorkflowLines": 26791,
33
- "latestTransition": "The proven r31 publication runtime is absorbed into protected dev without replacing later dev work.",
34
- "latestTransitionRationale": "The linear Project Cut absorbs the complete reviewed Train r31 runtime delta while preserving the current protected dev tree, including later Warrant readback and protected product-finalization repairs; the immutable r31 SHA remains the evidence and publication-engine coordinate. The combined runtime keeps the single admitted universal engine, clean-consumer dependency bridge, source-bound recovery version, rooted result channel, and protected finalization ancestry without adding a second publisher, mutation authority, or release engine. The exact inventory contains 462 hand-maintained source files and 170347 lines; the ceiling binds the complete combined tree rather than hiding merge-time debt.",
33
+ "latestTransition": "Dev Delivery persists expired lease recovery before a fresh Warrant selection.",
34
+ "latestTransitionRationale": "The Warrant store retries only transient JSON syntax failures while reading immutable GitHub ref, commit, tree, and blob data; it never retries a write or bypasses expected-old CAS. Expired non-native lease recovery is now its own expected-old transition followed by an immutable reread before reselection, so no selection receipt names an unobserved intermediate root. The exact inventory contains 463 hand-maintained source files and 170469 lines; the ceiling binds these bounded integrity recoveries without adding workflow, provider permission, merge authority, or admission scope.",
35
35
  "rationale": "Bounded modules separate candidate, evidence, native proof and execution, canonical failure verification, closed-set execution transfer, process-boundary verification, Warrant state and qualification, authority state, qualification, Landing acquisition, verified-attempt admission, Landing settlement and fence validation, provider attempt and heartbeat readback, sealed terminal evidence, hosted heartbeat, resume, store, options, command-specific adapters, and CLI orchestration responsibilities. The protected delivery workflow gives candidate and seal jobs no provider write credential, recursively rejects transfer drift, scopes every transfer artifact to the exact provider run attempt, chains every durable heartbeat state and receipt root on a distinct hosted runner domain, and permits qualification or exact failure settlement only after the finalizer verifies live jobs and the latest durable authority state. Public Landing admission and heartbeat always perform non-injectable fresh exact-attempt provider readback, tolerate only a not-yet-materialized seal job while retaining exact native and duplicate-job rejection, and heartbeat-loss coordination never invokes GitHub's run-scoped cancellation API where a successor rerun could race. The hosted process boundary anchors trust in the kernel-resolved versioned Runner.Worker path while accepting an equivalent argv-zero spelling with the same basename; its public boundary marker is allowed only at the one exact non-secret value, so a forged value under the same credential-like name still fails closed. The credentialless transfer seal validates the rooted native reuse decision against the Warrant-bound source, closure, dependency, toolchain, environment and command inputs; qualifiedBase stays in the proof and decision where it is rooted and later independently rechecked, rather than being assumed on the Warrant schema. V2 mutation cannot initialize a second empty authority beside a legacy ref: migration reads and roots the canonical live v1 ref, rechecks it, applies the explicit configured v2 policy, and atomically replaces its bytes through one expected-old non-force update, so old v1 controllers fail closed while the prior commit remains immutable history. Candidate ancestry classifies the GitHub artifact runtime token as credential authority. Every Landing settlement, including an unexpired fence, requires product-owned terminal readback. Terminal cleanup reads the immutable historical attempt, derives workflow and hosted Landing job identity from live run data, reads the exact protected ref head and compares containment against that immutable SHA, and seals merged only when the admitted merge-group head is contained by that protected base; a later different-head merge settles the old attempt as dequeued. Terminal normalization preserves transfer, finalizer boundary, native and seal job, admitted provider attempt, protected-base head, containment result, and terminal readback coordinates. The public reusable workflow truthfully retains its single-flight v1 authority without advertising v2 migration, while bounded v2 remains a separate opt-in CLI, Node API, and schema contract; the tracked self-caller stays on public v4-alpha with matching stable and alpha locks, and transient train selection is dispatch-only. Next-development parity adds one versioned transition authority, one durable controller, one bounded reservation adapter, and pure public-contract recovery evidence while retaining the existing thin floating-channel callers byte-for-byte. The floating-consumer gate reuses the existing contract-world evaluator so SHA drift passes only under the selected lock's compatibility policy, breaking surface drift still fails closed, and external certification reconstructs the receipt from the observed workflow SHA rather than the lock's historical evidence SHA. Tail reseal adds no Stage Capsule effect or general rebuild authority: it verifies the exact retained four-platform bytes, admits one known macOS tail failure through live provider readback, fences signing and finalization to explicit credentials and Warrant identity, and requires standard candidate Passport plus provider and protected readback. Compatibility Facts parity isolates canonical encoding, temporal verification, lifecycle validation, fixture projection, public authority projection, and CLI adaptation into bounded modules; legacy digest and proof arrays are derived only from exact current Fact lineage. Publication Rehearsal adds no production release authority: the content-addressed capsule contract binds source, candidate, manifest, config, canonical data-only provider bindings, provider policy, observations and core version separately from filesystem, runtime and rehearsal-only provider authority; simulate, replay and explicitly authorized provider rehearsal all reuse the release-tail planner, while same-commit local dogfood resolves the new reusable contract and exact current runtime before external callers remain on floating v4-alpha. Cross-runtime candidate recovery preserves original runtime and provider roots and creates resume lineage only after exact public ref, tag, ancestry, npm version and integrity readback. Adopter Delivery restores the reviewed public v3 gate, drivers, Passport binding, N-1 bootstrap and exact archive loader through one public v4 surface while keeping provider and release authority explicit non-claims. Floating Alpha bootstrap uses only the existing exact resolver and protected Alpha private shell to move an otherwise stale floating shell, retains public v4 stable promotion, and removes itself after protected readback. CI lane change-budget enforcement adds a bounded parser, evaluator, guard, and tests without creating another merge authority.",
36
36
  "governance": "legacy-debt-sunset-2026q4"
37
37
  },
@@ -4,7 +4,7 @@
4
4
  "product": {
5
5
  "name": "Buildchain",
6
6
  "package": "@kungfu-tech/buildchain",
7
- "version": "4.0.2-alpha.14",
7
+ "version": "4.0.2-alpha.16",
8
8
  "repository": "https://github.com/kungfu-systems/buildchain"
9
9
  },
10
10
  "majorLine": "v4",
@@ -5444,5 +5444,5 @@
5444
5444
  "compatibilityFactCutRoot": "sha256:f61b975d4a96c921cc4bd37fb3ed9a0596b47004fe34dc7219979d697e3707f9",
5445
5445
  "compatibilityProofRegistryRoot": "sha256:b7194b811e4d3af2df4390bc4d1731e16a86215bd64ee18cb630dd5492f4fb63",
5446
5446
  "compatibilityDigest": "sha256:20411029d83211dff426fb6535a608902129844a5ccb4788db77d3f81becb839",
5447
- "contractDigest": "sha256:a7fa27e20846c32f1ce22a0c37cc32b47818b3b30d72640c0d608c2b67d323c6"
5447
+ "contractDigest": "sha256:c56f7a9130b97aa2a6bc3524dff9d5996327a0994f7094c4a620d2fa6b884d61"
5448
5448
  }
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "contract": "kungfu-buildchain-site-bundle",
4
- "generatedAt": "2026-09-01T14:47:21.000Z",
5
- "publishedAt": "2026-09-01T14:47:21.000Z",
4
+ "generatedAt": "2026-09-02T04:48:33.000Z",
5
+ "publishedAt": "2026-09-02T04:48:33.000Z",
6
6
  "reproducible": true,
7
7
  "timestampPolicy": "ci-injected",
8
8
  "deterministicInputs": [
@@ -19,7 +19,7 @@
19
19
  "declared Buildchain surface manifest contract"
20
20
  ],
21
21
  "sourceDateEpoch": "0",
22
- "sourceRevision": "94a4c73e3bc7fa20c4a1bcf732bd00c4593fd5d3",
22
+ "sourceRevision": "35f5890e2af28a15d92ba68f623c1cbd062c3a5d",
23
23
  "timestampPolicyDetails": {
24
24
  "contract": "kungfu-buildchain-surface-timestamp-policy",
25
25
  "timestampFields": [
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "package": {
39
39
  "name": "@kungfu-tech/buildchain",
40
- "version": "4.0.2-alpha.14",
40
+ "version": "4.0.2-alpha.16",
41
41
  "versionSource": "package.json#version"
42
42
  },
43
43
  "source": {
@@ -21,7 +21,7 @@
21
21
  "contract": "kungfu-buildchain-public-surface-reverse-audit",
22
22
  "path": "dist/site/public-surface-audit.json",
23
23
  "status": "passed",
24
- "sha256": "444c6427bf82c74fe401cf9fbedddd96be6e016260ea53d77b4e091d1718e812",
24
+ "sha256": "73c5d2608b9ad132d875cb8d0e3687456705edf77244b1d4f1085bf09c7781df",
25
25
  "summary": {
26
26
  "cliCommandCount": 117,
27
27
  "workflowCount": 80,
@@ -246,7 +246,7 @@
246
246
  "contract": "kungfu-buildchain-public-surface-reverse-audit",
247
247
  "path": "dist/site/public-surface-audit.json",
248
248
  "status": "passed",
249
- "sha256": "444c6427bf82c74fe401cf9fbedddd96be6e016260ea53d77b4e091d1718e812",
249
+ "sha256": "73c5d2608b9ad132d875cb8d0e3687456705edf77244b1d4f1085bf09c7781df",
250
250
  "summary": {
251
251
  "cliCommandCount": 117,
252
252
  "workflowCount": 80,
@@ -4,7 +4,7 @@
4
4
  "product": {
5
5
  "id": "kungfu-tech-buildchain",
6
6
  "name": "@kungfu-tech/buildchain",
7
- "version": "4.0.2-alpha.14",
7
+ "version": "4.0.2-alpha.16",
8
8
  "repository": "https://github.com/kungfu-systems/buildchain"
9
9
  },
10
10
  "source": {
@@ -9035,7 +9035,7 @@
9035
9035
  "workflowRegistryPath": "dist/site/workflow-registry.json",
9036
9036
  "pageRegistryPath": "dist/site/page-registry.json",
9037
9037
  "cliRegistryDigest": "fbc23073bbae240489a2f826b2c26daadc58e704050c5f8df366509f5c5a1c3e",
9038
- "workflowRegistryDigest": "8f19cd149a2c8c6a2a4931b7c5fc13c82a7fa3b03aef1676eb28914fd9d1fd2e",
9038
+ "workflowRegistryDigest": "acf5c142b762faa4743b41974b5446d4f7112bc9d192a4f3857873275053803d",
9039
9039
  "pageRegistryDigest": "8e2a30416d969f390d1fa57468c8d29f5e89d179b6d1ea1600159e72adff8130"
9040
9040
  },
9041
9041
  "comparison": {
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "contract": "kungfu-buildchain-publication-release-registry",
4
- "generatedAt": "2026-09-01T14:47:21.000Z",
5
- "publishedAt": "2026-09-01T14:47:21.000Z",
4
+ "generatedAt": "2026-09-02T04:48:33.000Z",
5
+ "publishedAt": "2026-09-02T04:48:33.000Z",
6
6
  "reproducible": true,
7
7
  "timestampPolicy": "ci-injected",
8
8
  "deterministicInputs": [
@@ -19,7 +19,7 @@
19
19
  "declared Buildchain surface manifest contract"
20
20
  ],
21
21
  "sourceDateEpoch": "0",
22
- "sourceRevision": "94a4c73e3bc7fa20c4a1bcf732bd00c4593fd5d3",
22
+ "sourceRevision": "35f5890e2af28a15d92ba68f623c1cbd062c3a5d",
23
23
  "timestampPolicyDetails": {
24
24
  "contract": "kungfu-buildchain-surface-timestamp-policy",
25
25
  "timestampFields": [
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "package": {
34
34
  "name": "@kungfu-tech/buildchain",
35
- "version": "4.0.2-alpha.14",
35
+ "version": "4.0.2-alpha.16",
36
36
  "versionSource": "package.json#version"
37
37
  },
38
38
  "sourceKind": "package-site-bundle",
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "contract": "kungfu-buildchain-site-manifest",
4
- "generatedAt": "2026-09-01T14:47:21.000Z",
5
- "publishedAt": "2026-09-01T14:47:21.000Z",
4
+ "generatedAt": "2026-09-02T04:48:33.000Z",
5
+ "publishedAt": "2026-09-02T04:48:33.000Z",
6
6
  "reproducible": true,
7
7
  "timestampPolicy": "ci-injected",
8
8
  "deterministicInputs": [
@@ -19,7 +19,7 @@
19
19
  "declared Buildchain surface manifest contract"
20
20
  ],
21
21
  "sourceDateEpoch": "0",
22
- "sourceRevision": "94a4c73e3bc7fa20c4a1bcf732bd00c4593fd5d3",
22
+ "sourceRevision": "35f5890e2af28a15d92ba68f623c1cbd062c3a5d",
23
23
  "timestampPolicyDetails": {
24
24
  "contract": "kungfu-buildchain-surface-timestamp-policy",
25
25
  "timestampFields": [
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "package": {
39
39
  "name": "@kungfu-tech/buildchain",
40
- "version": "4.0.2-alpha.14",
40
+ "version": "4.0.2-alpha.16",
41
41
  "versionSource": "package.json#version"
42
42
  },
43
43
  "entrypoint": "buildchain-site.json",
@@ -2096,7 +2096,7 @@
2096
2096
  "status": "preview",
2097
2097
  "owner": "buildchain-workflows",
2098
2098
  "maturity": "preview",
2099
- "introducedVersion": "4.0.2-alpha.14",
2099
+ "introducedVersion": "4.0.2-alpha.16",
2100
2100
  "compatibilityPromise": "preserved-through-the-v3-major-line",
2101
2101
  "deprecationReplacement": "",
2102
2102
  "sunsetCondition": "explicit-breaking-change-review-in-a-future-major-line",
@@ -2117,7 +2117,7 @@
2117
2117
  "status": "preview",
2118
2118
  "owner": "buildchain-workflows",
2119
2119
  "maturity": "preview",
2120
- "introducedVersion": "4.0.2-alpha.14",
2120
+ "introducedVersion": "4.0.2-alpha.16",
2121
2121
  "compatibilityPromise": "preserved-through-the-v3-major-line",
2122
2122
  "deprecationReplacement": "",
2123
2123
  "sunsetCondition": "explicit-breaking-change-review-in-a-future-major-line",
@@ -2138,7 +2138,7 @@
2138
2138
  "status": "preview",
2139
2139
  "owner": "buildchain-workflows",
2140
2140
  "maturity": "preview",
2141
- "introducedVersion": "4.0.2-alpha.14",
2141
+ "introducedVersion": "4.0.2-alpha.16",
2142
2142
  "compatibilityPromise": "preserved-through-the-v3-major-line",
2143
2143
  "deprecationReplacement": "",
2144
2144
  "sunsetCondition": "explicit-breaking-change-review-in-a-future-major-line",
@@ -2189,7 +2189,7 @@
2189
2189
  "status": "preview",
2190
2190
  "owner": "buildchain-workflows",
2191
2191
  "maturity": "preview",
2192
- "introducedVersion": "4.0.2-alpha.14",
2192
+ "introducedVersion": "4.0.2-alpha.16",
2193
2193
  "compatibilityPromise": "preserved-through-the-v3-major-line",
2194
2194
  "deprecationReplacement": "",
2195
2195
  "sunsetCondition": "explicit-breaking-change-review-in-a-future-major-line",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kungfu-tech/buildchain",
3
- "version": "4.0.2-alpha.14",
3
+ "version": "4.0.2-alpha.16",
4
4
  "private": false,
5
5
  "description": "Buildchain Release Passport, release governance, CLI toolkit, and site facts.",
6
6
  "repository": "https://github.com/kungfu-systems/buildchain",
@@ -7,6 +7,7 @@ import {
7
7
  import { normalizeDevDeliveryAuthorityState } from "../packages/core/dev-delivery-authority-state.js";
8
8
 
9
9
  const STATE_PATH = "queue.json";
10
+ const READ_ATTEMPTS = 3;
10
11
 
11
12
  function text(value = "") {
12
13
  return String(value ?? "").trim();
@@ -20,6 +21,14 @@ function exactSha(value, label) {
20
21
  return normalized;
21
22
  }
22
23
 
24
+ function positiveInteger(value, label) {
25
+ const parsed = Number(value);
26
+ if (!Number.isInteger(parsed) || parsed < 1) {
27
+ throw new Error(`${label} must be a positive integer`);
28
+ }
29
+ return parsed;
30
+ }
31
+
23
32
  function normalizeRepository(value) {
24
33
  const normalized = text(value);
25
34
  const match = normalized.match(/^([^/\s]+)\/([^/\s]+)$/);
@@ -70,6 +79,7 @@ export class GitHubDevDeliveryStore {
70
79
  apiUrl = "https://api.github.com",
71
80
  fetchImpl = globalThis.fetch,
72
81
  createInitialState = createDevDeliveryQueue,
82
+ readAttempts = READ_ATTEMPTS,
73
83
  } = {}) {
74
84
  this.repository = normalizeRepository(repository);
75
85
  if (!fetchImpl) throw new Error("fetch is required");
@@ -81,6 +91,22 @@ export class GitHubDevDeliveryStore {
81
91
  this.apiUrl = apiUrl.replace(/\/+$/, "");
82
92
  this.fetch = fetchImpl;
83
93
  this.createInitialState = createInitialState;
94
+ this.readAttempts = positiveInteger(readAttempts, "readAttempts");
95
+ }
96
+
97
+ async retryParseableRead(operation) {
98
+ let failure;
99
+ for (let attempt = 1; attempt <= this.readAttempts; attempt += 1) {
100
+ try {
101
+ return await operation();
102
+ } catch (error) {
103
+ failure = error;
104
+ if (!(error instanceof SyntaxError) || attempt === this.readAttempts) {
105
+ throw error;
106
+ }
107
+ }
108
+ }
109
+ throw failure;
84
110
  }
85
111
 
86
112
  async request(method, requestPath, body) {
@@ -132,6 +158,17 @@ export class GitHubDevDeliveryStore {
132
158
  }
133
159
 
134
160
  async read({ stateRef, protectedBase, now, allowLegacyV3Readback = false }) {
161
+ return this.retryParseableRead(async () =>
162
+ this.readOnce({ stateRef, protectedBase, now, allowLegacyV3Readback }),
163
+ );
164
+ }
165
+
166
+ async readOnce({
167
+ stateRef,
168
+ protectedBase,
169
+ now,
170
+ allowLegacyV3Readback = false,
171
+ }) {
135
172
  let ref;
136
173
  try {
137
174
  ref = await this.request(
@@ -158,6 +195,12 @@ export class GitHubDevDeliveryStore {
158
195
  }
159
196
 
160
197
  async readCommit(commitShaInput, { allowLegacyV3Readback = false } = {}) {
198
+ return this.retryParseableRead(async () =>
199
+ this.readCommitOnce(commitShaInput, { allowLegacyV3Readback }),
200
+ );
201
+ }
202
+
203
+ async readCommitOnce(commitShaInput, { allowLegacyV3Readback = false } = {}) {
161
204
  const commitSha = exactSha(commitShaInput, "state commit");
162
205
  const commit = await this.request(
163
206
  "GET",
@@ -0,0 +1,109 @@
1
+ import { recoverExpiredDevDeliveryWarrant } from "../packages/core/dev-delivery-warrant.js";
2
+
3
+ async function recoverExpiredLeaseBeforeReselection({
4
+ store,
5
+ options,
6
+ loaded,
7
+ initialLoaded,
8
+ }) {
9
+ const recovery = recoverExpiredDevDeliveryWarrant(loaded.queue, {
10
+ now: options.now,
11
+ });
12
+ if (recovery.receipt.expectedOldStateRoot !== loaded.queue.stateRoot) {
13
+ throw new Error(
14
+ "expired Warrant recovery receipt expected-old root does not match the loaded authority",
15
+ );
16
+ }
17
+ await store.write({
18
+ stateRef: options.stateRef,
19
+ queue: recovery.queue,
20
+ expectedCommitSha: loaded.commitSha,
21
+ expectedStateRoot: loaded.queue.stateRoot,
22
+ receiptRoot: recovery.receiptRoot,
23
+ });
24
+ const reloaded = await store.read({
25
+ stateRef: options.stateRef,
26
+ protectedBase: options.branch,
27
+ now: options.now,
28
+ });
29
+ return {
30
+ loaded: reloaded,
31
+ concurrencyRecovery: {
32
+ schema: "kungfu.buildchain.dev-delivery-concurrency-recovery/v1",
33
+ action: "expired-lease-recovered-before-reselection",
34
+ initialCommitSha: initialLoaded.commitSha,
35
+ recoveredStateRoot: recovery.queue.stateRoot,
36
+ observedCommitSha: reloaded.commitSha,
37
+ observedStateRoot: reloaded.queue.stateRoot,
38
+ },
39
+ };
40
+ }
41
+
42
+ export async function persistDevDeliveryTransition({
43
+ store,
44
+ options,
45
+ loaded,
46
+ initialLoaded,
47
+ changed,
48
+ transitionFor,
49
+ }) {
50
+ let concurrencyRecovery = null;
51
+ if (
52
+ options.execute &&
53
+ options.command === "select" &&
54
+ changed.recoveryReceipt?.action === "recovered-expired-lease"
55
+ ) {
56
+ const recovery = await recoverExpiredLeaseBeforeReselection({
57
+ store,
58
+ options,
59
+ loaded,
60
+ initialLoaded,
61
+ });
62
+ loaded = recovery.loaded;
63
+ changed = transitionFor(options.command, loaded.queue, options);
64
+ concurrencyRecovery = recovery.concurrencyRecovery;
65
+ }
66
+ if (!options.execute || changed.queue.stateRoot === loaded.queue.stateRoot)
67
+ return { loaded, changed, write: null, concurrencyRecovery };
68
+ if (changed.receipt.expectedOldStateRoot !== loaded.queue.stateRoot) {
69
+ throw new Error(
70
+ "transition receipt expected-old root does not match the loaded authority",
71
+ );
72
+ }
73
+ try {
74
+ const write = await store.write({
75
+ stateRef: options.stateRef,
76
+ queue: changed.queue,
77
+ expectedCommitSha: loaded.commitSha,
78
+ expectedStateRoot: loaded.queue.stateRoot,
79
+ receiptRoot: changed.receiptRoot,
80
+ });
81
+ return { loaded, changed, write, concurrencyRecovery };
82
+ } catch (error) {
83
+ if (options.command !== "settle" || options.expectedOldStateRoot)
84
+ throw error;
85
+ const latest = await store.read({
86
+ stateRef: options.stateRef,
87
+ protectedBase: options.branch,
88
+ now: options.now,
89
+ });
90
+ const reconciled = transitionFor(options.command, latest.queue, options);
91
+ if (
92
+ reconciled.queue.stateRoot !== latest.queue.stateRoot ||
93
+ reconciled.receipt.action !== "duplicate-terminal-event-noop"
94
+ )
95
+ throw error;
96
+ return {
97
+ loaded: latest,
98
+ changed: reconciled,
99
+ write: null,
100
+ concurrencyRecovery: {
101
+ schema: "kungfu.buildchain.dev-delivery-concurrency-recovery/v1",
102
+ action: "terminal-settlement-race-noop",
103
+ initialCommitSha: initialLoaded.commitSha,
104
+ observedCommitSha: latest.commitSha,
105
+ observedStateRoot: latest.queue.stateRoot,
106
+ },
107
+ };
108
+ }
109
+ }
@@ -10,7 +10,6 @@ import {
10
10
  heartbeatDevDeliveryWarrant,
11
11
  observeDevDeliveryQueue,
12
12
  qualifyDevDeliveryWarrant,
13
- recoverExpiredDevDeliveryWarrant,
14
13
  reconcileDevDeliveryTerminalEvidence,
15
14
  selectDevDeliveryWarrant,
16
15
  settleDevDeliveryTerminalEvent,
@@ -21,6 +20,7 @@ import { reuseExactActiveDevDeliverySourceProof } from "../packages/core/dev-del
21
20
  import { runV4DeliveryWarrantReadCandidate } from "../packages/core/v4-delivery-warrant-read-candidate.js";
22
21
 
23
22
  import { GitHubDevDeliveryStore } from "./dev-delivery-warrant-store.mjs";
23
+ import { persistDevDeliveryTransition } from "./dev-delivery-warrant-transition.mjs";
24
24
  import { devDeliveryCliOptions } from "./dev-delivery-warrant-options.mjs";
25
25
  export { GitHubDevDeliveryStore, devDeliveryCliOptions };
26
26
 
@@ -463,51 +463,16 @@ export async function runDevDeliveryCommand(optionsInput = {}, clientInput) {
463
463
  }
464
464
  if (options.command === "observe") return observeQueue(loaded, options);
465
465
  const initialLoaded = loaded;
466
- let changed = transitionFor(options.command, loaded.queue, options);
467
- let mutates = changed.queue.stateRoot !== loaded.queue.stateRoot;
468
- let write = null;
469
- if (options.execute && mutates) {
470
- if (changed.receipt.expectedOldStateRoot !== loaded.queue.stateRoot) {
471
- throw new Error(
472
- "transition receipt expected-old root does not match the loaded authority",
473
- );
474
- }
475
- try {
476
- write = await store.write({
477
- stateRef: options.stateRef,
478
- queue: changed.queue,
479
- expectedCommitSha: loaded.commitSha,
480
- expectedStateRoot: loaded.queue.stateRoot,
481
- receiptRoot: changed.receiptRoot,
482
- });
483
- } catch (error) {
484
- if (options.command !== "settle" || options.expectedOldStateRoot)
485
- throw error;
486
- const latest = await store.read({
487
- stateRef: options.stateRef,
488
- protectedBase: options.branch,
489
- now: options.now,
490
- });
491
- const reconciled = transitionFor(options.command, latest.queue, options);
492
- const reconciledMutates =
493
- reconciled.queue.stateRoot !== latest.queue.stateRoot;
494
- if (
495
- reconciledMutates ||
496
- reconciled.receipt.action !== "duplicate-terminal-event-noop"
497
- )
498
- throw error;
499
- loaded = latest;
500
- changed = reconciled;
501
- mutates = false;
502
- concurrencyRecovery = {
503
- schema: "kungfu.buildchain.dev-delivery-concurrency-recovery/v1",
504
- action: "terminal-settlement-race-noop",
505
- initialCommitSha: initialLoaded.commitSha,
506
- observedCommitSha: latest.commitSha,
507
- observedStateRoot: latest.queue.stateRoot,
508
- };
509
- }
510
- }
466
+ const persisted = await persistDevDeliveryTransition({
467
+ store,
468
+ options,
469
+ loaded,
470
+ initialLoaded,
471
+ changed: transitionFor(options.command, loaded.queue, options),
472
+ transitionFor,
473
+ });
474
+ loaded = persisted.loaded;
475
+ concurrencyRecovery = persisted.concurrencyRecovery || concurrencyRecovery;
511
476
  return {
512
477
  schema: "kungfu.buildchain.dev-delivery-command-result/v1",
513
478
  ok: true,
@@ -516,16 +481,21 @@ export async function runDevDeliveryCommand(optionsInput = {}, clientInput) {
516
481
  stateRef: options.stateRef,
517
482
  before: { commitSha: loaded.commitSha, stateRoot: loaded.queue.stateRoot },
518
483
  after: {
519
- commitSha: write?.commitSha || loaded.commitSha,
520
- stateRoot: changed.queue.stateRoot,
484
+ commitSha: persisted.write?.commitSha || loaded.commitSha,
485
+ stateRoot: persisted.changed.queue.stateRoot,
521
486
  },
522
487
  mutationAuthorized: options.execute,
523
- mutationApplied: Boolean(write),
488
+ mutationApplied: Boolean(persisted.write),
524
489
  concurrencyRecovery,
525
- receipt: changed.receipt,
526
- receiptRoot: changed.receiptRoot,
527
- warrant: changed.warrant || changed.queue.activeWarrant || null,
528
- observation: observeDevDeliveryQueue(changed.queue, { now: options.now }),
490
+ receipt: persisted.changed.receipt,
491
+ receiptRoot: persisted.changed.receiptRoot,
492
+ warrant:
493
+ persisted.changed.warrant ||
494
+ persisted.changed.queue.activeWarrant ||
495
+ null,
496
+ observation: observeDevDeliveryQueue(persisted.changed.queue, {
497
+ now: options.now,
498
+ }),
529
499
  };
530
500
  }
531
501