@kungfu-tech/buildchain 4.1.3-alpha.0 → 4.1.3-alpha.10

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 (278) hide show
  1. package/AGENTS.md +41 -75
  2. package/CONTRIBUTING.md +19 -26
  3. package/architecture/action-taxonomy.json +24 -0
  4. package/architecture/agent-change-map.md +272 -12
  5. package/architecture/capability-state-machine-manifest.json +1 -4
  6. package/architecture/ci-lane-change-budget.json +190 -807
  7. package/architecture/core-mechanisms.json +3 -6
  8. package/architecture/decisions/0005-minimal-consumer-contract.md +122 -0
  9. package/architecture/decisions/0006-business-attempt-journal.md +89 -0
  10. package/architecture/decisions/0007-hosted-pipeline-controller.md +106 -0
  11. package/architecture/decisions/0008-pipeline-product-publication.md +120 -0
  12. package/architecture/decisions/0009-pipeline-version-preparation.md +186 -0
  13. package/architecture/internal-capabilities.json +371 -9
  14. package/architecture/maintainability-debt.json +50 -34
  15. package/architecture/maintainability-policy.json +8 -8
  16. package/architecture/minimal-consumer-migration.json +5670 -0
  17. package/architecture/platform-stage-checkpoints.json +31 -7
  18. package/architecture/product-upstreams.json +20 -0
  19. package/architecture/release-topology.json +331 -74
  20. package/architecture/stage-capsule-qualification.json +3 -1
  21. package/architecture/universal-workflow-bootstrap.json +15 -1
  22. package/architecture/universal-workflow-capability-policy.json +9 -9
  23. package/architecture/universal-workflow-fault-campaign.json +3 -1
  24. package/architecture/workflow-taxonomy.json +77 -328
  25. package/contracts/release-discussion-v1.schema.json +3 -0
  26. package/dist/readers/business-attempt.cjs +809 -0
  27. package/dist/readers/release-discussion.cjs +4 -0
  28. package/dist/site/buildchain-contract.json +16 -68
  29. package/dist/site/buildchain-site.json +47 -27
  30. package/dist/site/capability-registry.json +4 -4
  31. package/dist/site/controller-registry.json +1 -47
  32. package/dist/site/kfd-claims.json +499 -494
  33. package/dist/site/kfd-upstream-aggregate.json +1 -1
  34. package/dist/site/manual-registry.json +3 -3
  35. package/dist/site/node-api-registry.json +56 -56
  36. package/dist/site/page-registry.json +40 -20
  37. package/dist/site/public-surface-audit.json +286 -349
  38. package/dist/site/publication-authority-registry.json +203 -523
  39. package/dist/site/publication-registry.json +4 -4
  40. package/dist/site/site-manifest.json +7 -7
  41. package/dist/site/workflow-registry.json +590 -940
  42. package/docs/code-organization.md +9 -6
  43. package/docs/node-api-reference.md +103 -103
  44. package/docs/release-discussions.md +44 -5
  45. package/docs/release-governance.md +10 -12
  46. package/docs/runtime-entry.md +73 -5
  47. package/docs/runtime-train-validation.md +39 -11
  48. package/docs/stable-candidate-patrol.md +6 -5
  49. package/docs/workflow-catalog.md +9 -32
  50. package/package.json +4 -3
  51. package/packages/core/adoption/buildchain-kfd-claims.js +7 -7
  52. package/packages/core/build/standalone/build.js +7 -1
  53. package/packages/core/consumer/buildchain-config.js +2 -21
  54. package/packages/core/consumer/contract/entries.js +85 -0
  55. package/packages/core/consumer/contract/examples.js +96 -0
  56. package/packages/core/consumer/contract/identity.js +65 -0
  57. package/packages/core/consumer/contract/inspection.js +45 -0
  58. package/packages/core/consumer/contract/plan.js +149 -0
  59. package/packages/core/consumer/contract/products.js +119 -0
  60. package/packages/core/consumer/contract/reader.js +47 -0
  61. package/packages/core/consumer/contract/shape.js +46 -0
  62. package/packages/core/dev-delivery/candidate/admission.js +9 -5
  63. package/packages/core/dev-delivery/candidate/reservation.js +11 -0
  64. package/packages/core/dev-delivery/candidate/source-paths.js +12 -4
  65. package/packages/core/dev-delivery/commands/project-cut-merge-queue-admission.mjs +47 -20
  66. package/packages/core/dev-delivery/dev-delivery-provider-heartbeat.js +18 -15
  67. package/packages/core/dev-delivery/native/actions.js +9 -1
  68. package/packages/core/dev-delivery/native/heartbeat-action.js +16 -0
  69. package/packages/core/dev-delivery/native/heartbeat.js +6 -4
  70. package/packages/core/dev-delivery/native/process-entry.js +19 -0
  71. package/packages/core/dev-delivery/queue/landing-action.js +53 -0
  72. package/packages/core/dev-delivery/warrant/failure-settlement.js +8 -6
  73. package/packages/core/dev-delivery/warrant/service.js +7 -0
  74. package/packages/core/governance/buildchain-publication-authority.js +8 -23
  75. package/packages/core/governance/github-governance-authority.js +1 -0
  76. package/packages/core/observability/controller-evidence.js +0 -8
  77. package/packages/core/paper/operations/bootstrap.js +2 -0
  78. package/packages/core/paper/paper-npm-bootstrap.js +2 -2
  79. package/packages/core/providers/github/attempt-index.js +60 -0
  80. package/packages/core/providers/github/attempt-journal.js +154 -0
  81. package/packages/core/providers/github/discussions/materials.js +35 -11
  82. package/packages/core/providers/github/discussions/transport.js +16 -5
  83. package/packages/core/providers/github/pipeline-checkout.js +49 -0
  84. package/packages/core/providers/github/pipeline-entry-runs.js +210 -0
  85. package/packages/core/providers/github/pipeline-events.js +131 -0
  86. package/packages/core/providers/github/pipeline-integration.js +95 -0
  87. package/packages/core/providers/github/pipeline-policy.js +240 -0
  88. package/packages/core/providers/github/pipeline-product-payload.js +50 -0
  89. package/packages/core/providers/github/pipeline-product-release.js +198 -0
  90. package/packages/core/providers/github/pipeline-publication-artifacts.js +153 -0
  91. package/packages/core/providers/github/pipeline-release-evidence.js +30 -0
  92. package/packages/core/providers/github/pipeline-run-entry.js +86 -0
  93. package/packages/core/providers/github/pipeline-runs.js +132 -0
  94. package/packages/core/providers/github/pipeline-source.js +195 -0
  95. package/packages/core/providers/github/pipeline-stable-baseline.js +86 -0
  96. package/packages/core/providers/github/pipeline-stable-source.js +372 -0
  97. package/packages/core/providers/github/pipeline-version-artifacts.js +91 -0
  98. package/packages/core/providers/github/pipeline-version-readback.js +117 -0
  99. package/packages/core/providers/github/pipeline-version.js +199 -0
  100. package/packages/core/providers/github/pipeline-worker.js +108 -0
  101. package/packages/core/providers/github/release-evidence-assets.js +97 -0
  102. package/packages/core/publication/candidate/registry-hydration.js +2 -2
  103. package/packages/core/publication/npm/pack-preview.js +2 -2
  104. package/packages/core/publication/npm/pack-result.js +31 -0
  105. package/packages/core/publication/npm/package.js +3 -6
  106. package/packages/core/publication/npm/pipeline-channel.js +36 -0
  107. package/packages/core/publication/npm/pipeline-provider.js +137 -0
  108. package/packages/core/publication/npm/registry.js +12 -9
  109. package/packages/core/publication/pipeline/actions.js +116 -0
  110. package/packages/core/publication/pipeline/apply.js +189 -0
  111. package/packages/core/publication/pipeline/build-segments.js +107 -0
  112. package/packages/core/publication/pipeline/capsules.js +92 -0
  113. package/packages/core/publication/pipeline/context.js +39 -0
  114. package/packages/core/publication/pipeline/development-anchor.js +91 -0
  115. package/packages/core/publication/pipeline/development-current.js +63 -0
  116. package/packages/core/publication/pipeline/development-pr.js +112 -0
  117. package/packages/core/publication/pipeline/development-proof.js +76 -0
  118. package/packages/core/publication/pipeline/development-transition.js +112 -0
  119. package/packages/core/publication/pipeline/distribution.js +130 -0
  120. package/packages/core/publication/pipeline/documents.js +192 -0
  121. package/packages/core/publication/pipeline/effects.js +192 -0
  122. package/packages/core/publication/pipeline/files.js +66 -0
  123. package/packages/core/publication/pipeline/imported-materials.js +32 -0
  124. package/packages/core/publication/pipeline/journal.js +122 -0
  125. package/packages/core/publication/pipeline/next-development.js +117 -0
  126. package/packages/core/publication/pipeline/pack.js +180 -0
  127. package/packages/core/publication/pipeline/package-policy.js +22 -0
  128. package/packages/core/publication/pipeline/plan.js +136 -0
  129. package/packages/core/publication/pipeline/prepare.js +139 -0
  130. package/packages/core/publication/pipeline/qualification.js +175 -0
  131. package/packages/core/publication/pipeline/qualify.js +104 -0
  132. package/packages/core/publication/pipeline/recovery-admission.js +122 -0
  133. package/packages/core/publication/pipeline/recovery-build-download.js +80 -0
  134. package/packages/core/publication/pipeline/recovery-build-plan.js +122 -0
  135. package/packages/core/publication/pipeline/recovery-build-readback.js +68 -0
  136. package/packages/core/publication/pipeline/recovery-capsules.js +54 -0
  137. package/packages/core/publication/pipeline/recovery-import.js +80 -0
  138. package/packages/core/publication/pipeline/recovery-inspection.js +218 -0
  139. package/packages/core/publication/pipeline/recovery-materials.js +104 -0
  140. package/packages/core/publication/pipeline/recovery-plan.js +46 -0
  141. package/packages/core/publication/pipeline/recovery-prepare.js +73 -0
  142. package/packages/core/publication/pipeline/recovery-qualification.js +128 -0
  143. package/packages/core/publication/pipeline/recovery-readback.js +56 -0
  144. package/packages/core/publication/pipeline/recovery-signing.js +58 -0
  145. package/packages/core/publication/pipeline/sealed-products.js +79 -0
  146. package/packages/core/publication/pipeline/settle.js +42 -0
  147. package/packages/core/publication/pipeline/signing.js +140 -0
  148. package/packages/core/publication/pipeline/source-plan.js +83 -0
  149. package/packages/core/publication/pipeline/stable-entry.js +219 -0
  150. package/packages/core/publication/pipeline/stable-products.js +317 -0
  151. package/packages/core/publication/pipeline/stable-wait.js +170 -0
  152. package/packages/core/publication/pipeline/stable.js +82 -0
  153. package/packages/core/publication/pipeline/version-actions.js +93 -0
  154. package/packages/core/publication/pipeline/version-build.js +130 -0
  155. package/packages/core/publication/pipeline/version-context.js +143 -0
  156. package/packages/core/publication/pipeline/version-material.js +36 -0
  157. package/packages/core/publication/pipeline/version-preparation.js +69 -0
  158. package/packages/core/publication/pipeline/version-regeneration.js +162 -0
  159. package/packages/core/publication/pipeline/version-source-guard.js +69 -0
  160. package/packages/core/publication/pipeline/version.js +81 -0
  161. package/packages/core/publication/pipeline/worker.js +72 -0
  162. package/packages/core/publication/publication-reproducibility.js +2 -2
  163. package/packages/core/release/discussion/binary.js +11 -0
  164. package/packages/core/release/discussion/checkpoints.js +45 -4
  165. package/packages/core/release/discussion/envelope.js +1 -0
  166. package/packages/core/release/discussion/evidence.js +51 -0
  167. package/packages/core/release/discussion/presentation.js +92 -0
  168. package/packages/core/release/discussion/publication.js +3 -1
  169. package/packages/core/release/discussion/qualification.js +1 -0
  170. package/packages/core/release/discussion/reader.js +9 -0
  171. package/packages/core/release/discussion/session.js +2 -0
  172. package/packages/core/release/discussion/store.js +28 -31
  173. package/packages/core/release/discussion/threads.js +83 -0
  174. package/packages/core/release/next-development-transition.js +15 -15
  175. package/packages/core/release/promote-candidate/product-provider-adapters.js +4 -3
  176. package/packages/core/release/promote-ref/internal/npm-existing-evidence.js +2 -1
  177. package/packages/core/release/promote-ref/internal/publish-command.js +16 -5
  178. package/packages/core/release/stable-release-gate.js +11 -0
  179. package/packages/core/runtime/buildchain-domain.wasm +0 -0
  180. package/packages/core/runtime/domain-wasm-artifact.js +2 -2
  181. package/packages/core/runtime/entry/actions.js +27 -25
  182. package/packages/core/runtime/entry/attempt.js +25 -0
  183. package/packages/core/runtime/entry/selection.js +14 -0
  184. package/packages/core/runtime/entry/source.js +62 -0
  185. package/packages/core/workflow/attempt/identity.js +170 -0
  186. package/packages/core/workflow/attempt/journal.js +89 -0
  187. package/packages/core/workflow/attempt/materials.js +72 -0
  188. package/packages/core/workflow/attempt/reader-entry.js +12 -0
  189. package/packages/core/workflow/attempt/reader.js +149 -0
  190. package/packages/core/workflow/attempt/records.js +153 -0
  191. package/packages/core/workflow/attempt/store.js +75 -0
  192. package/packages/core/workflow/commands/pipeline-build.mjs +23 -0
  193. package/packages/core/workflow/pipeline/action-output.js +11 -0
  194. package/packages/core/workflow/pipeline/actions.js +52 -0
  195. package/packages/core/workflow/pipeline/build-control.js +140 -0
  196. package/packages/core/workflow/pipeline/build-evidence.js +210 -0
  197. package/packages/core/workflow/pipeline/build-qualification.js +145 -0
  198. package/packages/core/workflow/pipeline/build-result.js +78 -0
  199. package/packages/core/workflow/pipeline/build.js +142 -0
  200. package/packages/core/workflow/pipeline/cancellation.js +169 -0
  201. package/packages/core/workflow/pipeline/channel-control.js +157 -0
  202. package/packages/core/workflow/pipeline/channel-source.js +53 -0
  203. package/packages/core/workflow/pipeline/controller.js +141 -0
  204. package/packages/core/workflow/pipeline/delivery-control.js +249 -0
  205. package/packages/core/workflow/pipeline/delivery-observation.js +124 -0
  206. package/packages/core/workflow/pipeline/delivery-request.js +198 -0
  207. package/packages/core/workflow/pipeline/events.js +84 -0
  208. package/packages/core/workflow/pipeline/fence.js +42 -0
  209. package/packages/core/workflow/pipeline/group-control.js +59 -0
  210. package/packages/core/workflow/pipeline/guard-build.js +74 -0
  211. package/packages/core/workflow/pipeline/guard.js +158 -0
  212. package/packages/core/workflow/pipeline/host.js +144 -0
  213. package/packages/core/workflow/pipeline/integration-status.js +113 -0
  214. package/packages/core/workflow/pipeline/materials.js +58 -0
  215. package/packages/core/workflow/pipeline/notifications.js +36 -0
  216. package/packages/core/workflow/pipeline/parent-notification.js +27 -0
  217. package/packages/core/workflow/pipeline/platforms.js +21 -0
  218. package/packages/core/workflow/pipeline/progress.js +108 -0
  219. package/packages/core/workflow/pipeline/projection.js +20 -0
  220. package/packages/core/workflow/pipeline/reconcile.js +194 -0
  221. package/packages/core/workflow/pipeline/record-action.js +27 -0
  222. package/packages/core/workflow/pipeline/recorder-status.js +69 -0
  223. package/packages/core/workflow/pipeline/recovery-action.js +30 -0
  224. package/packages/core/workflow/pipeline/recovery-admission.js +122 -0
  225. package/packages/core/workflow/pipeline/recovery-build-control.js +95 -0
  226. package/packages/core/workflow/pipeline/recovery-build-evidence.js +71 -0
  227. package/packages/core/workflow/pipeline/recovery-build.js +121 -0
  228. package/packages/core/workflow/pipeline/recovery-controller.js +91 -0
  229. package/packages/core/workflow/pipeline/recovery-integration.js +79 -0
  230. package/packages/core/workflow/pipeline/recovery-merge-proof.js +90 -0
  231. package/packages/core/workflow/pipeline/recovery-ownership-settlement.js +150 -0
  232. package/packages/core/workflow/pipeline/recovery-ownership.js +91 -0
  233. package/packages/core/workflow/pipeline/recovery-plan.js +126 -0
  234. package/packages/core/workflow/pipeline/recovery-runtime.js +68 -0
  235. package/packages/core/workflow/pipeline/recovery-session.js +129 -0
  236. package/packages/core/workflow/pipeline/recovery-transition.js +135 -0
  237. package/packages/core/workflow/pipeline/recovery-unrecorded-build.js +74 -0
  238. package/packages/core/workflow/pipeline/runtime-source.js +111 -0
  239. package/packages/core/workflow/pipeline/selection.js +111 -0
  240. package/packages/core/workflow/pipeline/session.js +72 -0
  241. package/packages/core/workflow/pipeline/settlement.js +137 -0
  242. package/packages/core/workflow/pipeline/wake.js +38 -0
  243. package/packages/core/workflow/pipeline/web-status.js +108 -0
  244. package/packages/core/workflow/workflow-taxonomy.mjs +67 -47
  245. package/scripts/build-release-discussion-reader.mjs +11 -7
  246. package/scripts/check-inventory.mjs +7 -70
  247. package/scripts/check-pipeline-publication-topology.mjs +50 -0
  248. package/scripts/check-public-dogfood-contract.mjs +38 -51
  249. package/scripts/check-release-topology.mjs +15 -8
  250. package/scripts/check-self-consumer-contract.mjs +133 -0
  251. package/scripts/check-universal-workflow-bootstrap.mjs +4 -6
  252. package/scripts/generate-minimal-consumer-contract.mjs +155 -0
  253. package/scripts/generate-site-bundle.mjs +1 -1
  254. package/scripts/inventory/binary.mjs +9 -19
  255. package/scripts/inventory/promotion.mjs +2 -13
  256. package/scripts/prepare-product-toolchain.mjs +10 -0
  257. package/scripts/verify-golden-path.mjs +5 -1
  258. package/scripts/verify-product-platform.mjs +65 -0
  259. package/scripts/verify-standalone-product.mjs +42 -0
  260. package/templates/minimal-consumer/binary/.buildchain/buildchain.toml +45 -0
  261. package/templates/minimal-consumer/binary/.github/workflows/buildchain-recover.yml +30 -0
  262. package/templates/minimal-consumer/binary/.github/workflows/buildchain.yml +28 -0
  263. package/templates/minimal-consumer/binary/package.json +6 -0
  264. package/templates/minimal-consumer/binary/src/build.mjs +5 -0
  265. package/templates/minimal-consumer/binary/src/hello.c +2 -0
  266. package/templates/minimal-consumer/binary/src/verify.mjs +3 -0
  267. package/templates/minimal-consumer/npm/.buildchain/buildchain.toml +46 -0
  268. package/templates/minimal-consumer/npm/.github/workflows/buildchain-recover.yml +30 -0
  269. package/templates/minimal-consumer/npm/.github/workflows/buildchain.yml +28 -0
  270. package/templates/minimal-consumer/npm/package.json +6 -0
  271. package/templates/minimal-consumer/npm/src/build.mjs +5 -0
  272. package/templates/minimal-consumer/npm/src/verify.mjs +3 -0
  273. package/templates/minimal-consumer/paper/.buildchain/buildchain.toml +45 -0
  274. package/templates/minimal-consumer/paper/.github/workflows/buildchain-recover.yml +30 -0
  275. package/templates/minimal-consumer/paper/.github/workflows/buildchain.yml +28 -0
  276. package/templates/minimal-consumer/paper/package.json +6 -0
  277. package/templates/minimal-consumer/paper/src/build.mjs +12 -0
  278. package/templates/minimal-consumer/paper/src/verify.mjs +3 -0
@@ -0,0 +1,194 @@
1
+ import { recordDigest } from "../../release/discussion/envelope.js";
2
+
3
+ const TERMINAL = new Set([
4
+ "merged",
5
+ "terminal-failure",
6
+ "dequeued",
7
+ "cancelled",
8
+ ]);
9
+ const wait = (reason) => ({ operation: "wait", reason });
10
+
11
+ export function terminalPipelineCandidate(candidate) {
12
+ return Boolean(candidate && TERMINAL.has(candidate.status));
13
+ }
14
+
15
+ export function pipelineCandidateRoot(current) {
16
+ if (
17
+ !current.identity?.id ||
18
+ current.identity.generation !== current.generation.id
19
+ )
20
+ throw new Error(
21
+ "Pipeline candidate requires its exact business attempt identity",
22
+ );
23
+ return recordDigest({
24
+ schema: "buildchain.pipeline-candidate-source/v1",
25
+ intent: current.intent,
26
+ attempt: current.identity,
27
+ generation: current.generation,
28
+ });
29
+ }
30
+
31
+ export function pipelineCandidate(queue, current) {
32
+ const source = current.generation.source;
33
+ const number = current.intent.source.pullRequest;
34
+ const matches = queue.candidates.filter(
35
+ (candidate) =>
36
+ candidate.pullRequestNumber === number &&
37
+ candidate.sourceHead === source.commit &&
38
+ candidate.sourceRoot === pipelineCandidateRoot(current),
39
+ );
40
+ const active = matches.find(
41
+ (candidate) => candidate.candidateId === queue.activeWarrant?.candidateId,
42
+ );
43
+ return active || matches.at(-1) || null;
44
+ }
45
+
46
+ function cancellation({
47
+ candidate,
48
+ queue,
49
+ worker,
50
+ reason,
51
+ observedSourceHead,
52
+ }) {
53
+ if (candidate && ["cancelled", "dequeued"].includes(candidate.status))
54
+ return {
55
+ operation: "record-cancellation",
56
+ reason,
57
+ candidateId: candidate.candidateId,
58
+ };
59
+ if (!candidate || TERMINAL.has(candidate.status))
60
+ return { operation: "supersede", reason };
61
+ if (candidate.candidateId !== queue.activeWarrant?.candidateId) {
62
+ if (candidate.status !== "queued") return wait("unfenced-candidate-state");
63
+ return {
64
+ operation: "cancel-queued",
65
+ reason,
66
+ candidateId: candidate.candidateId,
67
+ expectedSourceHead: candidate.sourceHead,
68
+ observedSourceHead,
69
+ };
70
+ }
71
+ // Expiration is not evidence that the old native worker stopped. Never
72
+ // release or transfer an active Warrant until the provider proves terminality.
73
+ if (!worker || worker.status !== "completed")
74
+ return {
75
+ operation: "stop-worker",
76
+ reason: "active-worker-not-terminal",
77
+ candidateId: candidate.candidateId,
78
+ };
79
+ return {
80
+ operation: "settle-cancelled",
81
+ reason,
82
+ candidateId: candidate.candidateId,
83
+ };
84
+ }
85
+
86
+ function sameSource(current, live) {
87
+ if (!live.source) return false;
88
+ return recordDigest(current.generation.source) === recordDigest(live.source);
89
+ }
90
+
91
+ function mergedDelivery(candidate, live, evidence) {
92
+ if (!candidate) return wait("merged-candidate-authority-required");
93
+ if (
94
+ !evidence.integration ||
95
+ evidence.integration.sourceHead !== live.source.commit
96
+ )
97
+ return wait("exact-protected-integration-proof-required");
98
+ if (candidate.status !== "merged")
99
+ return { operation: "settle-merged", reason: "protected-merge-observed" };
100
+ if (
101
+ !evidence.settlement ||
102
+ evidence.settlement.candidateId !== candidate.candidateId
103
+ )
104
+ return wait("terminal-settlement-readback-required");
105
+ return { operation: "wake-publication", reason: "delivery-terminal" };
106
+ }
107
+
108
+ // This pure planner selects the next domain transaction. Its booleans are
109
+ // authenticated provider readbacks at the adapter boundary, never workflow inputs.
110
+ // A selected operation is not a receipt or permission to skip that domain's gates.
111
+ export function reconcilePipeline({ current, live, queue, worker, evidence }) {
112
+ if (
113
+ queue.repository !== current.intent.repository ||
114
+ queue.protectedBase !== current.intent.source.targetBranch ||
115
+ live.pullRequest !== current.intent.source.pullRequest
116
+ )
117
+ throw new Error("Pipeline observation belongs to another intent");
118
+ const candidate = pipelineCandidate(queue, current);
119
+ const cancellationInput = {
120
+ candidate,
121
+ queue,
122
+ worker,
123
+ observedSourceHead: live.observedHead || live.source?.commit,
124
+ };
125
+ if (live.state === "closed" && !live.merged)
126
+ return cancellation({
127
+ ...cancellationInput,
128
+ reason: "pull-request-closed",
129
+ });
130
+ if (
131
+ live.targetBranch &&
132
+ live.targetBranch !== current.intent.source.targetBranch
133
+ )
134
+ return cancellation({
135
+ ...cancellationInput,
136
+ reason: "target-branch-changed",
137
+ });
138
+ if (live.routeEnabled === false)
139
+ return cancellation({
140
+ ...cancellationInput,
141
+ reason: "channel-policy-changed",
142
+ });
143
+ if (!sameSource(current, live))
144
+ return cancellation({
145
+ ...cancellationInput,
146
+ reason: "source-generation-changed",
147
+ });
148
+ if (live.merged) return mergedDelivery(candidate, live, evidence);
149
+ if (current.generation.baseCommit !== live.baseCommit)
150
+ return cancellation({
151
+ ...cancellationInput,
152
+ reason: "protected-base-advanced",
153
+ });
154
+ if (live.dequeued === true)
155
+ return cancellation({
156
+ ...cancellationInput,
157
+ reason: "pull-request-dequeued",
158
+ });
159
+ return openDelivery({ candidate, live, queue, worker, evidence });
160
+ }
161
+
162
+ function openDelivery({ candidate, live, queue, worker, evidence }) {
163
+ if (live.state !== "open") return wait("unknown-provider-state");
164
+ if (live.terminalOnly) return wait("terminal-event-cannot-start-execution");
165
+ if (candidate && TERMINAL.has(candidate.status))
166
+ return wait("successor-attempt-required");
167
+ if (!evidence.build)
168
+ return { operation: "build", reason: "source-needs-qualification" };
169
+ if (evidence.build.sourceHead !== live.source.commit)
170
+ throw new Error("Build evidence belongs to another source");
171
+ if (evidence.build.outcome !== "success") {
172
+ if (candidate && candidate.candidateId === queue.activeWarrant?.candidateId)
173
+ return worker?.status === "completed"
174
+ ? { operation: "settle-failure", reason: "native-execution-failed" }
175
+ : { operation: "stop-worker", reason: "failed-worker-not-terminal" };
176
+ return wait("build-failed");
177
+ }
178
+ if (!live.ready || live.draft) return wait("ready-review-required");
179
+ if (!evidence.review) return wait("independent-protected-review-required");
180
+ if (!evidence.checks) return wait("exact-required-checks-pending");
181
+ if (!candidate) return { operation: "reserve", reason: "source-admitted" };
182
+ if (candidate.candidateId !== queue.activeWarrant?.candidateId)
183
+ return queue.activeWarrant
184
+ ? wait("another-candidate-active")
185
+ : { operation: "select", reason: "candidate-queued" };
186
+ if (queue.activeWarrant.phase === "provisional")
187
+ return {
188
+ operation: "qualify-native",
189
+ reason: "independent-native-proof-required",
190
+ };
191
+ if (!evidence.qualification)
192
+ return wait("qualified-warrant-readback-required");
193
+ return { operation: "land", reason: "protected-queue-admission" };
194
+ }
@@ -0,0 +1,27 @@
1
+ import { pipelineHost } from "./host.js";
2
+ import { recordPipelineBuild } from "./build-control.js";
3
+ import { publishRecorderStatus } from "./recorder-status.js";
4
+ import {
5
+ RECOVERY_BUILD_CONTEXT,
6
+ recordRecoveryBuild,
7
+ } from "./recovery-build-control.js";
8
+
9
+ export async function recordPipelineBuildAction(core, env) {
10
+ const host = await pipelineHost(core, env, "Record product build");
11
+ host.publishBuildStatus = (context, readback) =>
12
+ publishRecorderStatus(context, readback, host);
13
+ const context = JSON.parse(core.getInput("context", { required: true }));
14
+ if (context.schema === "buildchain.pipeline-group-build-context/v1")
15
+ return host.groupRecord(context);
16
+ const result =
17
+ context.schema === RECOVERY_BUILD_CONTEXT
18
+ ? await recordRecoveryBuild(context, host)
19
+ : await recordPipelineBuild(context, host);
20
+ if (result.outcome !== "success")
21
+ throw new Error("Product build did not succeed");
22
+ core.info(
23
+ result.wakePending
24
+ ? "Build retained; next event will retry delivery wake"
25
+ : "Build retained and attempt woken",
26
+ );
27
+ }
@@ -0,0 +1,69 @@
1
+ import { createHash } from "node:crypto";
2
+ import { parse } from "yaml";
3
+ import { publishPipelineBuildStatus } from "./guard-build.js";
4
+ import { recordDigest } from "../../release/discussion/envelope.js";
5
+
6
+ // A repaired runtime may execute through an older immutable published entry.
7
+ // Read the real recorder job's permission, rather than assuming the runtime's
8
+ // current workflow is the one GitHub scheduled. API failures are never ignored.
9
+ export async function publishRecorderStatus(context, readback, host) {
10
+ const { root, ...body } = readback;
11
+ if (
12
+ context.runId !== host.runId ||
13
+ context.runAttempt !== host.runAttempt ||
14
+ readback.runId !== host.runId ||
15
+ readback.runAttempt !== host.runAttempt ||
16
+ recordDigest(context.source) !== recordDigest(readback.source) ||
17
+ root !== recordDigest(body)
18
+ )
19
+ throw new Error("Recorder status changed its current source or execution");
20
+ const { run } = await host.runs.read(host.runId, host.runAttempt);
21
+ const path = ".github/workflows/.ops-pipeline-execute.yml";
22
+ const entries = (run.referenced_workflows || []).filter((entry) =>
23
+ entry.path?.startsWith(`kungfu-systems/buildchain/${path}@`),
24
+ );
25
+ if (entries.length !== 1 || !/^[0-9a-f]{40}$/u.test(entries[0].sha || ""))
26
+ throw new Error("Recorder has no exact published execution workflow");
27
+ const file = await host.request(
28
+ `/repos/kungfu-systems/buildchain/contents/${path}?ref=${entries[0].sha}`,
29
+ );
30
+ if (
31
+ file.type !== "file" ||
32
+ file.encoding !== "base64" ||
33
+ !Number.isSafeInteger(file.size) ||
34
+ file.size < 1 ||
35
+ file.size > 64000 ||
36
+ typeof file.content !== "string" ||
37
+ file.content.length > 128000
38
+ )
39
+ throw new Error(
40
+ "Recorder execution workflow is unavailable or exceeds its bound",
41
+ );
42
+ const bytes = Buffer.from(file.content, "base64");
43
+ const blob = createHash("sha1")
44
+ .update(`blob ${bytes.length}\0`)
45
+ .update(bytes)
46
+ .digest("hex");
47
+ if (bytes.length !== file.size || blob !== file.sha)
48
+ throw new Error("Recorder execution workflow bytes changed");
49
+ const job = parse(bytes.toString("utf8")).jobs?.["record-build"];
50
+ if (job?.name !== "Record product build")
51
+ throw new Error("Recorder execution workflow changed its job identity");
52
+ if (job.permissions?.statuses !== "write") return { published: false };
53
+ if (readback.outcome !== "success") return { published: false };
54
+ await publishPipelineBuildStatus(
55
+ {
56
+ "expected-head-sha": context.source.commit,
57
+ "source-workflow-run-id": String(readback.runId),
58
+ },
59
+ {
60
+ sourceHead: context.source.commit,
61
+ outcome: readback.outcome,
62
+ run: { id: readback.runId, run_attempt: readback.runAttempt },
63
+ readback,
64
+ },
65
+ host.request,
66
+ host.repository,
67
+ );
68
+ return { published: true };
69
+ }
@@ -0,0 +1,30 @@
1
+ import { recoveryInputs } from "../../consumer/contract/entries.js";
2
+ import { pipelineHost } from "./host.js";
3
+ import { controlPipelineRecovery } from "./recovery-controller.js";
4
+ import { pipelineActionOutputs } from "./action-output.js";
5
+ import { resumePipelineSession } from "./session.js";
6
+
7
+ export async function recoverPipelineAction(core, env) {
8
+ const { attempt } = recoveryInputs({
9
+ attempt: core.getInput("attempt", { required: true }),
10
+ });
11
+ const host = await pipelineHost(core, env, "Buildchain recovery controller");
12
+ try {
13
+ const result = await controlPipelineRecovery(
14
+ attempt,
15
+ core.getInput("definition-sha", { required: true }),
16
+ host,
17
+ );
18
+ pipelineActionOutputs(core, result);
19
+ } catch (error) {
20
+ try {
21
+ const session = await resumePipelineSession({ ...host, attempt }, host);
22
+ await host.project(session);
23
+ } catch {
24
+ core.warning(
25
+ "Recovery status projection is unavailable; the canonical attempt remains authoritative.",
26
+ );
27
+ }
28
+ throw error;
29
+ }
30
+ }
@@ -0,0 +1,122 @@
1
+ import { recordDigest } from "../../release/discussion/envelope.js";
2
+ import { readPipelineCaller } from "../../providers/github/pipeline-run-entry.js";
3
+ import { RECOVERY_ENTRY } from "../../consumer/contract/entries.js";
4
+
5
+ export async function recoveryExecution(host, definitionSha) {
6
+ const { run } = await host.runs.read(host.runId, host.runAttempt);
7
+ const definitions = (run.referenced_workflows || []).filter((item) =>
8
+ item.path?.startsWith(`kungfu-systems/buildchain/${RECOVERY_ENTRY}@`),
9
+ );
10
+ if (
11
+ run.event !== "workflow_dispatch" ||
12
+ run.status !== "in_progress" ||
13
+ run.repository?.full_name !== host.repository ||
14
+ run.head_repository?.full_name !== host.repository ||
15
+ run.path?.split("@")[0] !== ".github/workflows/buildchain-recover.yml" ||
16
+ definitions.length !== 1 ||
17
+ definitions[0].sha !== definitionSha ||
18
+ !/^[0-9a-f]{40}$/u.test(definitionSha || "")
19
+ )
20
+ throw new Error(
21
+ "Recovery must execute the exact canonical entry from the same consumer repository",
22
+ );
23
+ const channel = definitions[0].path
24
+ .split("@")
25
+ .at(-1)
26
+ .replace(/^refs\/tags\//u, "");
27
+ if (!["v4", "v4-alpha"].includes(channel))
28
+ throw new Error("Recovery entry must be a published floating channel");
29
+ return {
30
+ run,
31
+ channel,
32
+ entry: {
33
+ repository: "kungfu-systems/buildchain",
34
+ workflow: RECOVERY_ENTRY,
35
+ sha: definitionSha,
36
+ },
37
+ };
38
+ }
39
+
40
+ export async function admitRecoverySource(session, execution, host) {
41
+ const current = session.observed.history.at(-1);
42
+ const original = current.generation.source;
43
+ const source = await host.source.source(original.commit, original.configPath);
44
+ if (
45
+ recordDigest(source.identity) !== recordDigest(original) ||
46
+ host.selection.source?.sha !== original.commit ||
47
+ host.selection.source?.repository !== host.repository
48
+ )
49
+ throw new Error(
50
+ "Recovery source, config or selected runtime source changed",
51
+ );
52
+ const caller = await readPipelineCaller(
53
+ execution.run,
54
+ original.configPath,
55
+ host.request,
56
+ host.repository,
57
+ );
58
+ const admission = await host.source.observeIntent(
59
+ session.intent,
60
+ current.generation,
61
+ { "config-path": original.configPath },
62
+ );
63
+ if (
64
+ !admission.live.source ||
65
+ recordDigest(admission.live.source) !== recordDigest(original) ||
66
+ admission.live.targetBranch !== session.intent.source.targetBranch ||
67
+ (!admission.live.merged &&
68
+ (admission.live.state !== "open" ||
69
+ admission.live.routeEnabled === false ||
70
+ admission.live.baseCommit !== current.generation.baseCommit))
71
+ )
72
+ throw new Error(
73
+ "Selected source was closed, superseded or rebased; use its current admitted attempt",
74
+ );
75
+ return {
76
+ source,
77
+ admission,
78
+ caller,
79
+ };
80
+ }
81
+
82
+ export async function recoveryPredecessorRuns(session, host) {
83
+ const current = session.observed.history.at(-1);
84
+ const keys = [
85
+ ...new Map(
86
+ current.runs.map((writer) => [
87
+ `${writer.runId}:${writer.runAttempt}`,
88
+ writer,
89
+ ]),
90
+ ).values(),
91
+ ];
92
+ if (keys.length > 100)
93
+ throw new Error("Recovery predecessor run inventory exceeds its bound");
94
+ const observations = [];
95
+ for (const writer of keys) {
96
+ if (
97
+ Number(writer.runId) === host.runId &&
98
+ Number(writer.runAttempt) === host.runAttempt
99
+ )
100
+ throw new Error("Recovery cannot replace its own live execution");
101
+ const { run } = await host.runs.read(
102
+ Number(writer.runId),
103
+ Number(writer.runAttempt),
104
+ );
105
+ if (
106
+ run.repository?.full_name !== host.repository ||
107
+ run.head_repository?.full_name !== host.repository
108
+ )
109
+ throw new Error(
110
+ "Recovery predecessor execution crossed a repository or fork boundary",
111
+ );
112
+ observations.push(run);
113
+ }
114
+ return {
115
+ schema: "buildchain.pipeline-recovery-executions/v1",
116
+ predecessor: current.identity.id,
117
+ runs: observations,
118
+ terminal: observations.every(
119
+ (run) => run.status === "completed" && run.conclusion,
120
+ ),
121
+ };
122
+ }
@@ -0,0 +1,95 @@
1
+ import { object } from "../../consumer/contract/shape.js";
2
+ import { recordDigest } from "../../release/discussion/envelope.js";
3
+ import { resumePipelineSession } from "./session.js";
4
+ import { recoveryBuildEvidence } from "./recovery-build-evidence.js";
5
+ import { qualifyPipelineBuild } from "./build-qualification.js";
6
+ import { retainPipelineBuildResult } from "./build-result.js";
7
+
8
+ export const RECOVERY_BUILD_CONTEXT =
9
+ "buildchain.pipeline-recovery-build-context/v1";
10
+
11
+ export async function beginRecoveryBuild(session, host) {
12
+ session.observed = await session.journal.read();
13
+ const { plan, build } = await recoveryBuildEvidence(session, host);
14
+ const observed = session.observed;
15
+ const previous = observed.phases.build;
16
+ if (
17
+ previous &&
18
+ (previous.payload.writer.runId !== String(host.runId) ||
19
+ previous.payload.writer.runAttempt !== String(host.runAttempt))
20
+ )
21
+ return null;
22
+ await session.progress.progress({
23
+ attempt: observed.attempt,
24
+ phase: "build",
25
+ state: "running",
26
+ eventKey: `build-start:${host.runId}:${host.runAttempt}`,
27
+ expectedHead: observed.head,
28
+ reason: build.reason,
29
+ });
30
+ return {
31
+ schema: RECOVERY_BUILD_CONTEXT,
32
+ attempt: observed.attempt,
33
+ generation: observed.generation,
34
+ source: build.source,
35
+ runId: host.runId,
36
+ runAttempt: host.runAttempt,
37
+ platforms: build.scheduled,
38
+ recoveryPlanRoot: plan.root,
39
+ };
40
+ }
41
+
42
+ export async function recordRecoveryBuild(context, host) {
43
+ object(context, [
44
+ "schema",
45
+ "attempt",
46
+ "generation",
47
+ "source",
48
+ "runId",
49
+ "runAttempt",
50
+ "platforms",
51
+ "recoveryPlanRoot",
52
+ ]);
53
+ if (
54
+ context.schema !== RECOVERY_BUILD_CONTEXT ||
55
+ context.runId !== host.runId ||
56
+ context.runAttempt !== host.runAttempt
57
+ )
58
+ throw new Error("Recovery build callback belongs to another execution");
59
+ const session = await resumePipelineSession(
60
+ { ...host, attempt: context.attempt },
61
+ host,
62
+ );
63
+ const { plan, build } = await recoveryBuildEvidence(session, host);
64
+ const writer = session.observed.phases.build?.payload.writer;
65
+ if (
66
+ context.generation !== session.observed.generation ||
67
+ context.recoveryPlanRoot !== plan.root ||
68
+ recordDigest(context.source) !== recordDigest(build.source) ||
69
+ recordDigest(context.platforms) !== recordDigest(build.scheduled) ||
70
+ writer?.runId !== String(host.runId) ||
71
+ writer?.runAttempt !== String(host.runAttempt)
72
+ )
73
+ throw new Error(
74
+ "Recovery build callback changed its reserved work or admission",
75
+ );
76
+ const segments = structuredClone(build.segments);
77
+ if (build.scheduled.length) {
78
+ const platforms = build.scheduled.map((item) => item.platform);
79
+ const readback = await host.runs.build(
80
+ host.runId,
81
+ host.runAttempt,
82
+ build.source,
83
+ platforms,
84
+ );
85
+ segments.push({ readback, platforms, runtime: host.runtime });
86
+ }
87
+ const result = qualifyPipelineBuild({
88
+ source: build.source,
89
+ platforms: build.platforms.map((item) => item.platform),
90
+ segments,
91
+ runId: host.runId,
92
+ runAttempt: host.runAttempt,
93
+ });
94
+ return retainPipelineBuildResult(context, result, session, host);
95
+ }
@@ -0,0 +1,71 @@
1
+ import { recordDigest } from "../../release/discussion/envelope.js";
2
+ import { retainedRecoveryEvidence } from "./recovery-session.js";
3
+ import { pipelinePlatforms } from "./platforms.js";
4
+ import { buildReadbackPlatforms } from "./build-qualification.js";
5
+ import { qualifyRecoveryRuntime } from "./recovery-runtime.js";
6
+
7
+ export async function recoveryBuildEvidence(session, host) {
8
+ const { plan, evidence } = await retainedRecoveryEvidence(session, host);
9
+ const build = evidence.build;
10
+ if (!build) throw new Error("Recovery admission has no qualified build plan");
11
+ const { root, ...body } = build;
12
+ const current = session.observed.history.at(-1);
13
+ const source = await host.source.source(
14
+ current.generation.source.commit,
15
+ current.generation.source.configPath,
16
+ );
17
+ if (
18
+ root !== recordDigest(body) ||
19
+ body.schema !== "buildchain.pipeline-recovery-build/v1" ||
20
+ body.predecessor !== plan.predecessor ||
21
+ recordDigest(body.source) !== recordDigest(current.generation.source) ||
22
+ recordDigest(source.identity) !== recordDigest(body.source) ||
23
+ recordDigest(pipelinePlatforms(source.plan)) !==
24
+ recordDigest(body.platforms) ||
25
+ recordDigest(host.runtime) !== recordDigest(plan.runtime)
26
+ )
27
+ throw new Error(
28
+ "Recovery build plan changed its source, platform inventory or executor",
29
+ );
30
+ const selected = new Set();
31
+ for (const segment of build.segments) {
32
+ const old = segment.readback;
33
+ const inventory = buildReadbackPlatforms(old);
34
+ const fresh = await host.runs.build(
35
+ old.runId,
36
+ old.runAttempt,
37
+ build.source,
38
+ inventory,
39
+ );
40
+ const runtime = await qualifyRecoveryRuntime(
41
+ segment.runtime,
42
+ host.runtime,
43
+ "build",
44
+ host.request,
45
+ );
46
+ if (recordDigest(fresh) !== recordDigest(old) || !runtime.compatible)
47
+ throw new Error(
48
+ "Recovered platform changed during execution requalification",
49
+ );
50
+ for (const platform of segment.platforms) {
51
+ const job = old.jobs[inventory.indexOf(platform)];
52
+ if (
53
+ selected.has(platform) ||
54
+ job?.status !== "completed" ||
55
+ job.conclusion !== "success"
56
+ )
57
+ throw new Error(
58
+ "Recovery cannot reuse duplicate or unsuccessful platform results",
59
+ );
60
+ selected.add(platform);
61
+ }
62
+ }
63
+ if (
64
+ recordDigest(build.scheduled) !==
65
+ recordDigest(build.platforms.filter((item) => !selected.has(item.platform)))
66
+ )
67
+ throw new Error(
68
+ "Recovery scheduling differs from the qualified remaining platform set",
69
+ );
70
+ return { plan, build };
71
+ }