@kungfu-tech/buildchain 4.0.1-alpha.36 → 4.0.1-alpha.37

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.
@@ -6,11 +6,11 @@
6
6
  "repositoryBudgets": {
7
7
  "baselineRevision": "858dbe00b6206a8f356b4a12d2659bee7a72e71b",
8
8
  "maxHandMaintainedSourceFiles": 427,
9
- "maxHandMaintainedSourceLines": 159840,
9
+ "maxHandMaintainedSourceLines": 159889,
10
10
  "maxWorkflowFiles": 76,
11
- "maxWorkflowLines": 26318,
12
- "latestTransition": "Stable promotion forwards the exact sealed-candidate recovery identity into the existing v4 workflow shell.",
13
- "latestTransitionRationale": "The generated stable route now forwards the nine existing resume inputs already accepted and independently verified by the v4 private promotion shell. This preserves the original candidate bytes, tree and runtime A while binding recovery runtime B; it does not add a new recovery mode or publication authority. Workflow size grows by exactly nine generated pass-through lines while the source ceiling remains unchanged. These exact 427-file, 159840-source-line, 76-workflow-file and 26318-workflow-line ceilings add no unrelated headroom.",
11
+ "maxWorkflowLines": 26320,
12
+ "latestTransition": "Required Dev delivery fences readiness behind an exact-head pending Warrant status.",
13
+ "latestTransitionRationale": "Required source qualification now writes and reads back the existing Queue admission lease context as pending before adding readiness, retains that pending fence while the Warrant is produced, and permits success only after exact current-Warrant verification. The reusable caller passes the existing Warrant mode and queue context into the pre-readiness phase, and regressions prove ordering, missing-context rejection, pending retention, and failure closure without adding a new lane or merge authority. These exact 427-file, 159889-source-line, 76-workflow-file and 26320-workflow-line ceilings account for 49 source lines and two workflow wiring lines with no unrelated headroom.",
14
14
  "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."
15
15
  },
16
16
  "sourceBudgets": {
@@ -4,7 +4,7 @@
4
4
  "product": {
5
5
  "name": "Buildchain",
6
6
  "package": "@kungfu-tech/buildchain",
7
- "version": "4.0.1-alpha.36",
7
+ "version": "4.0.1-alpha.37",
8
8
  "repository": "https://github.com/kungfu-systems/buildchain"
9
9
  },
10
10
  "majorLine": "v4",
@@ -1492,7 +1492,7 @@
1492
1492
  "durable consumers call the public floating workflow and may route a train or exact runtime only through trusted non-persistent dispatch input"
1493
1493
  ],
1494
1494
  "breakingDigest": "sha256:21b65d0746d2e8b3e8a7df4c6fab295a85c8fd42cc405ec3bc5df5cdab0421f0",
1495
- "auditDigest": "sha256:1392bc85e8aef8c19161b06764900c2cdb0f0cd57bf65dc95ad578040add7bea"
1495
+ "auditDigest": "sha256:6bd7c071717e16813c03c018e8bf868e54e9f98bff388b6790f6861d18a58831"
1496
1496
  },
1497
1497
  {
1498
1498
  "contractVersion": 1,
@@ -5308,5 +5308,5 @@
5308
5308
  "compatibilityFactCutRoot": "sha256:f61b975d4a96c921cc4bd37fb3ed9a0596b47004fe34dc7219979d697e3707f9",
5309
5309
  "compatibilityProofRegistryRoot": "sha256:b7194b811e4d3af2df4390bc4d1731e16a86215bd64ee18cb630dd5492f4fb63",
5310
5310
  "compatibilityDigest": "sha256:5de1c69386510b74b17eb70141b8bdd07063d62c504f91db5e84b67c6d4b64a2",
5311
- "contractDigest": "sha256:08da7cb857e3c977a4dd0a918af9659de8628a9404c6a5a907593d8f89d294ae"
5311
+ "contractDigest": "sha256:c0eb393d8c1da241d04e2d905ebbe31c9a064fc39c59146f5c3335632afb77de"
5312
5312
  }
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "contract": "kungfu-buildchain-site-bundle",
4
- "generatedAt": "2026-08-24T04:04:36.516Z",
5
- "publishedAt": "2026-08-24T04:04:36.516Z",
4
+ "generatedAt": "2026-08-24T06:09:08.176Z",
5
+ "publishedAt": "2026-08-24T06:09:08.176Z",
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": "975c93b1e33d04d6c27e2879651f8dcfd9b5fe42",
22
+ "sourceRevision": "4301b1d6db0027ed877f16b1d807d6f5894170fc",
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.1-alpha.36",
40
+ "version": "4.0.1-alpha.37",
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": "94f0e944155b53b68186da6ff5edaad13f23514e0207e2a9516a8c402f7f44a9",
24
+ "sha256": "a50ea8aee1841f47dc896da9facaacc27a7fb03b3411ccdfc44cbc0b6c00e7fa",
25
25
  "summary": {
26
26
  "cliCommandCount": 117,
27
27
  "workflowCount": 76,
@@ -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": "94f0e944155b53b68186da6ff5edaad13f23514e0207e2a9516a8c402f7f44a9",
249
+ "sha256": "a50ea8aee1841f47dc896da9facaacc27a7fb03b3411ccdfc44cbc0b6c00e7fa",
250
250
  "summary": {
251
251
  "cliCommandCount": 117,
252
252
  "workflowCount": 76,
@@ -4,7 +4,7 @@
4
4
  "product": {
5
5
  "id": "kungfu-tech-buildchain",
6
6
  "name": "@kungfu-tech/buildchain",
7
- "version": "4.0.1-alpha.36",
7
+ "version": "4.0.1-alpha.37",
8
8
  "repository": "https://github.com/kungfu-systems/buildchain"
9
9
  },
10
10
  "source": {
@@ -8846,7 +8846,7 @@
8846
8846
  "workflowRegistryPath": "dist/site/workflow-registry.json",
8847
8847
  "pageRegistryPath": "dist/site/page-registry.json",
8848
8848
  "cliRegistryDigest": "ea47a31ce7ef3577f23e22055ab7be7715c3af494bcef63f76b426f2883086aa",
8849
- "workflowRegistryDigest": "1b21627d15c546740ad5fbf98df3c0ea989009193f86b55a15cf139f45934439",
8849
+ "workflowRegistryDigest": "9e42b64221ce75615ccf783dd9db878b7be250964c35701b030a704740f8bbd9",
8850
8850
  "pageRegistryDigest": "619910e5c57fb8e94ea1525de1fb7699c412a8dafd7269bc9354cc6c4fe83f48"
8851
8851
  },
8852
8852
  "comparison": {
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "contract": "kungfu-buildchain-publication-release-registry",
4
- "generatedAt": "2026-08-24T04:04:36.516Z",
5
- "publishedAt": "2026-08-24T04:04:36.516Z",
4
+ "generatedAt": "2026-08-24T06:09:08.176Z",
5
+ "publishedAt": "2026-08-24T06:09:08.176Z",
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": "975c93b1e33d04d6c27e2879651f8dcfd9b5fe42",
22
+ "sourceRevision": "4301b1d6db0027ed877f16b1d807d6f5894170fc",
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.1-alpha.36",
35
+ "version": "4.0.1-alpha.37",
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-08-24T04:04:36.516Z",
5
- "publishedAt": "2026-08-24T04:04:36.516Z",
4
+ "generatedAt": "2026-08-24T06:09:08.176Z",
5
+ "publishedAt": "2026-08-24T06:09:08.176Z",
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": "975c93b1e33d04d6c27e2879651f8dcfd9b5fe42",
22
+ "sourceRevision": "4301b1d6db0027ed877f16b1d807d6f5894170fc",
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.1-alpha.36",
40
+ "version": "4.0.1-alpha.37",
41
41
  "versionSource": "package.json#version"
42
42
  },
43
43
  "entrypoint": "buildchain-site.json",
@@ -2027,7 +2027,7 @@
2027
2027
  "status": "preview",
2028
2028
  "owner": "buildchain-workflows",
2029
2029
  "maturity": "preview",
2030
- "introducedVersion": "4.0.1-alpha.36",
2030
+ "introducedVersion": "4.0.1-alpha.37",
2031
2031
  "compatibilityPromise": "preserved-through-the-v3-major-line",
2032
2032
  "deprecationReplacement": "",
2033
2033
  "sunsetCondition": "explicit-breaking-change-review-in-a-future-major-line",
@@ -2048,7 +2048,7 @@
2048
2048
  "status": "preview",
2049
2049
  "owner": "buildchain-workflows",
2050
2050
  "maturity": "preview",
2051
- "introducedVersion": "4.0.1-alpha.36",
2051
+ "introducedVersion": "4.0.1-alpha.37",
2052
2052
  "compatibilityPromise": "preserved-through-the-v3-major-line",
2053
2053
  "deprecationReplacement": "",
2054
2054
  "sunsetCondition": "explicit-breaking-change-review-in-a-future-major-line",
@@ -2069,7 +2069,7 @@
2069
2069
  "status": "preview",
2070
2070
  "owner": "buildchain-workflows",
2071
2071
  "maturity": "preview",
2072
- "introducedVersion": "4.0.1-alpha.36",
2072
+ "introducedVersion": "4.0.1-alpha.37",
2073
2073
  "compatibilityPromise": "preserved-through-the-v3-major-line",
2074
2074
  "deprecationReplacement": "",
2075
2075
  "sunsetCondition": "explicit-breaking-change-review-in-a-future-major-line",
@@ -2119,7 +2119,7 @@
2119
2119
  "status": "preview",
2120
2120
  "owner": "buildchain-workflows",
2121
2121
  "maturity": "preview",
2122
- "introducedVersion": "4.0.1-alpha.36",
2122
+ "introducedVersion": "4.0.1-alpha.37",
2123
2123
  "compatibilityPromise": "preserved-through-the-v3-major-line",
2124
2124
  "deprecationReplacement": "",
2125
2125
  "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.1-alpha.36",
3
+ "version": "4.0.1-alpha.37",
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",
@@ -3,7 +3,7 @@ import crypto from "node:crypto";
3
3
  import { spawnSync } from "node:child_process";
4
4
  import fs from "node:fs";
5
5
  import path from "node:path";
6
- import { admitExistingQueueEntry, createDevPrAdmissionReceipt, qualifyAtomicQueueAdmission, readDeliveryWarrantResult, runSourceQualification, runTargetedQueueAdmission, setActiveLeaseStatus, verifyCurrentDeliveryWarrant } from "./dev-pr-delivery-warrant.mjs";
6
+ import { admitExistingQueueEntry, createDevPrAdmissionReceipt, createPreReadinessQueueFence, qualifyAtomicQueueAdmission, readDeliveryWarrantResult, runSourceQualification, runTargetedQueueAdmission, setActiveLeaseStatus, setQueueAdmissionStatus, verifyCurrentDeliveryWarrant } from "./dev-pr-delivery-warrant.mjs";
7
7
  import { projectCutQualification } from "./dev-pr-prequeue-guard.mjs";
8
8
  const DEFAULT_BLOCK_LABELS = ["blocked", "do-not-merge", "work-in-progress"];
9
9
  const DEFAULT_ALLOWED_HEAD_PREFIXES = ["feature/", "fix/", "chore/", "docs/", "ci/", "refactor/"];
@@ -197,12 +197,6 @@ function mergeableAccepted(pr, landingMode = "direct", projectCutQualified = fal
197
197
  function rejectBaseMoveBeforeAtomicReplay(options, initialBaseSha, observedBaseSha) {
198
198
  return observedBaseSha !== initialBaseSha && options.warrantMode !== "required";
199
199
  }
200
- async function setQueueAdmissionStatus(client, repository, sha, context, state) {
201
- if (!context) return null;
202
- await client.request("POST", `/repos/${repository.owner}/${repository.repo}/statuses/${sha}`, { body: { state, context, description: state === "success" ? "Buildchain admitted this exact PR head to the merge queue" : "Buildchain rejected merge queue admission for this exact PR head" } });
203
- return { context, state, sha };
204
- }
205
-
206
200
  function skip(reason, details = {}) {
207
201
  return { action: "skip", reason, ...details };
208
202
  }
@@ -790,8 +784,10 @@ export async function runDevPrAdmission(optionsInput = {}, clientInput) {
790
784
  return targetedFailure({ options, pr: {}, state: "missing", reason: "pull-request-not-found" });
791
785
  }
792
786
 
787
+ const readinessFence = createPreReadinessQueueFence({ client, options, sleep: delay });
793
788
  const reject = async (state, reason, readiness = { observed: hasReadyLabel(pr, options.readyLabel), established: false }) => {
794
789
  const result = targetedFailure({ options, pr, state, reason, readiness });
790
+ await readinessFence.finish(result);
795
791
  if (!options.dryRun) result.diagnostic = await publishAdmissionDiagnostic(client, options, result.receipt, result.receiptRoot);
796
792
  return result;
797
793
  };
@@ -803,6 +799,12 @@ export async function runDevPrAdmission(optionsInput = {}, clientInput) {
803
799
  if (pr.draft) return reject("blocked", "draft");
804
800
  if (!headPrefixAllowed(pr, options.allowedHeadPrefixes)) return reject("blocked", "head-prefix-not-allowed");
805
801
 
802
+ try {
803
+ await readinessFence.establish();
804
+ } catch (error) {
805
+ return reject("blocked", error.code || "pre-readiness-queue-fence-failed");
806
+ }
807
+
806
808
  let readiness = { observed: hasReadyLabel(pr, options.readyLabel), established: false };
807
809
  if (!readiness.observed) {
808
810
  if (options.dryRun) return reject("rejected", "missing-ready-label", readiness);
@@ -825,7 +827,7 @@ export async function runDevPrAdmission(optionsInput = {}, clientInput) {
825
827
  }
826
828
 
827
829
  if (options.qualificationOnly) {
828
- return runSourceQualification({
830
+ const result = await runSourceQualification({
829
831
  options, pullRequest: pr, readiness, client, reject,
830
832
  evaluate: evaluatePullRequest,
831
833
  admissionState: admissionStateFor,
@@ -833,6 +835,7 @@ export async function runDevPrAdmission(optionsInput = {}, clientInput) {
833
835
  root: contentRoot,
834
836
  publishDiagnostic: publishAdmissionDiagnostic,
835
837
  });
838
+ return readinessFence.finish(result);
836
839
  }
837
840
 
838
841
  const initialQueue = await client.getMergeQueueState(options.targetBranch);
@@ -844,6 +847,7 @@ export async function runDevPrAdmission(optionsInput = {}, clientInput) {
844
847
  }
845
848
  const matchingEntry = initialQueue.entries.find((entry) =>
846
849
  entry.pullRequestNumber === pr.number && entry.pullRequestHeadSha === options.expectedHeadSha);
850
+ await readinessFence.qualifyExisting(matchingEntry);
847
851
  const existing = await admitExistingQueueEntry({
848
852
  options, pullRequest: pr, readiness, client, entry: matchingEntry, warrant,
849
853
  createReceipt: createAdmissionReceipt,
@@ -852,7 +856,7 @@ export async function runDevPrAdmission(optionsInput = {}, clientInput) {
852
856
  });
853
857
  if (existing) return existing;
854
858
 
855
- return runTargetedQueueAdmission({
859
+ const result = await runTargetedQueueAdmission({
856
860
  options, pullRequest: pr, readiness, client, warrant,
857
861
  runController: runDevPrAutoMerge,
858
862
  admissionState: admissionStateFor,
@@ -860,6 +864,7 @@ export async function runDevPrAdmission(optionsInput = {}, clientInput) {
860
864
  root: contentRoot,
861
865
  publishDiagnostic: publishAdmissionDiagnostic,
862
866
  });
867
+ return readinessFence.finish(result);
863
868
  }
864
869
 
865
870
  function finalizePatrolResult(result) {
@@ -1132,6 +1137,11 @@ function cliFlag(args, name) {
1132
1137
 
1133
1138
  export function cliOptions(args = [], environment = process.env) {
1134
1139
  const targetPullRequestNumber = cliValue(args, "pull-request", environment.BUILDCHAIN_DEV_PR_EXPECTED_PR_NUMBER);
1140
+ const warrantMode = cliValue(
1141
+ args,
1142
+ "warrant-mode",
1143
+ environment.BUILDCHAIN_DEV_PR_WARRANT_MODE || environment.WARRANT_MODE,
1144
+ );
1135
1145
  return {
1136
1146
  repository: cliValue(args, "repository", environment.BUILDCHAIN_DEV_PR_REPOSITORY || environment.GITHUB_REPOSITORY),
1137
1147
  targetBranch: cliValue(args, "branch", environment.BUILDCHAIN_DEV_PR_TARGET_BRANCH || environment.GITHUB_REF_NAME),
@@ -1141,10 +1151,14 @@ export function cliOptions(args = [], environment = process.env) {
1141
1151
  blockLabels: cliValue(args, "block-labels", environment.BUILDCHAIN_DEV_PR_BLOCK_LABELS),
1142
1152
  allowedHeadPrefixes: cliValue(args, "allowed-head-prefixes", environment.BUILDCHAIN_DEV_PR_ALLOWED_HEAD_PREFIXES),
1143
1153
  requiredChecks: cliValue(args, "required-checks", environment.BUILDCHAIN_DEV_PR_REQUIRED_CHECKS),
1144
- queueAdmissionContext: cliValue(args, "queue-admission-context", environment.BUILDCHAIN_DEV_PR_QUEUE_ADMISSION_CONTEXT),
1154
+ queueAdmissionContext: cliValue(
1155
+ args,
1156
+ "queue-admission-context",
1157
+ environment.BUILDCHAIN_DEV_PR_QUEUE_ADMISSION_CONTEXT || (warrantMode === "required" ? "Queue admission lease" : ""),
1158
+ ),
1145
1159
  activeLeaseContext: cliValue(args, "active-lease-context", environment.BUILDCHAIN_DEV_PR_ACTIVE_LEASE_CONTEXT),
1146
1160
  diagnosticContext: cliValue(args, "diagnostic-context", environment.BUILDCHAIN_DEV_PR_DIAGNOSTIC_CONTEXT),
1147
- warrantMode: cliValue(args, "warrant-mode", environment.BUILDCHAIN_DEV_PR_WARRANT_MODE),
1161
+ warrantMode,
1148
1162
  warrantResultPath: cliValue(args, "warrant-result", environment.BUILDCHAIN_DEV_PR_WARRANT_RESULT_PATH),
1149
1163
  projectCutProofPath: cliValue(args, "project-cut-proof", environment.BUILDCHAIN_DEV_PR_PROJECT_CUT_PROOF_PATH),
1150
1164
  sourceProofPath: cliValue(args, "source-proof", environment.BUILDCHAIN_DEV_PR_SOURCE_PROOF_PATH),
@@ -206,6 +206,50 @@ export async function setActiveLeaseStatus(client, repository, sha, context, sta
206
206
  return { context, state, sha };
207
207
  }
208
208
 
209
+ export async function setQueueAdmissionStatus(client, repository, sha, context, state) {
210
+ if (!context) return null;
211
+ const descriptions = {
212
+ pending: "Buildchain is awaiting a qualified Warrant for this exact PR head",
213
+ success: "Buildchain admitted this exact PR head to the merge queue",
214
+ failure: "Buildchain rejected merge queue admission for this exact PR head",
215
+ };
216
+ await client.request("POST", `/repos/${repository.owner}/${repository.repo}/statuses/${sha}`, {
217
+ body: { state, context, description: descriptions[state] || descriptions.failure },
218
+ });
219
+ return { context, state, sha };
220
+ }
221
+
222
+ export function createPreReadinessQueueFence({ client, options, sleep }) {
223
+ let status = null;
224
+ const write = async (state) => {
225
+ status = await setQueueAdmissionStatus(client, options.repository, options.expectedHeadSha, options.queueAdmissionContext, state);
226
+ return status;
227
+ };
228
+ return {
229
+ async establish() {
230
+ if (options.dryRun || options.warrantMode !== "required") return null;
231
+ if (!options.queueAdmissionContext) mismatch("queue-admission-context-required-before-readiness");
232
+ await write("pending");
233
+ for (let attempt = 1; attempt <= Math.max(1, options.pollMergeableAttempts); attempt += 1) {
234
+ const checks = await client.listCommitChecks(options.expectedHeadSha);
235
+ const readback = (checks?.statuses || []).find((entry) => entry.context === options.queueAdmissionContext);
236
+ if (readback?.state === "pending") return { ...status, readbackAttempts: attempt };
237
+ if (attempt < options.pollMergeableAttempts) await sleep(options.pollMergeableDelayMs);
238
+ }
239
+ await write("failure");
240
+ mismatch("pre-readiness-queue-fence-readback-mismatch");
241
+ },
242
+ async qualifyExisting(entry) {
243
+ if (entry && status?.state === "pending") await write("success");
244
+ },
245
+ async finish(result) {
246
+ const controllerFailed = result.controller?.evaluated?.some((entry) => entry.queueAdmissionStatus?.state === "failure");
247
+ if (!result.ok && status?.state === "pending" && !controllerFailed) await write("failure");
248
+ return result;
249
+ },
250
+ };
251
+ }
252
+
209
253
  async function readBackAdmissionStatuses(client, options, expectedHeadSha, sleep) {
210
254
  let last = { queueAdmission: null, activeLease: null };
211
255
  const attempts = Math.max(1, options.pollMergeableAttempts);