@defrex/autobuild 1.4.2 → 1.6.0

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 (218) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +512 -101
  3. package/bin/ab-dispatch-kernel.ts +1 -0
  4. package/docs/accounts.md +9 -0
  5. package/docs/agent-runtimes.md +1 -0
  6. package/docs/answering-blocked-builds.md +7 -3
  7. package/docs/architecture.md +313 -130
  8. package/docs/assets/headline-wide.png +0 -0
  9. package/docs/build-store.md +33 -3
  10. package/docs/cli.md +2 -1
  11. package/docs/configuration-overview.md +9 -0
  12. package/docs/configuration.md +217 -106
  13. package/docs/dispatcher-hosting.md +19 -3
  14. package/docs/dispatcher.md +11 -6
  15. package/docs/glossary.md +1 -1
  16. package/docs/integration-overview.md +2 -2
  17. package/docs/integration-tree.md +91 -28
  18. package/docs/merge-policy.md +28 -9
  19. package/docs/operating.md +1 -1
  20. package/docs/operator-api.md +57 -20
  21. package/docs/operator-surfaces.md +1 -1
  22. package/docs/plugin-authoring.md +89 -8
  23. package/docs/remote-store-protocol.md +39 -11
  24. package/docs/remote-ticket-protocol.md +126 -12
  25. package/docs/restacking.md +24 -6
  26. package/docs/seams.md +2 -2
  27. package/docs/setup.md +19 -13
  28. package/docs/spec-standard.md +2 -1
  29. package/docs/ticket-dependencies.md +26 -8
  30. package/docs/ticket-migration.md +70 -7
  31. package/docs/ticket-sources.md +82 -5
  32. package/docs/tickets.md +34 -2
  33. package/docs/troubleshooting.md +3 -3
  34. package/docs/verification.md +5 -5
  35. package/docs/website.md +8 -0
  36. package/docs/workspaces.md +1 -1
  37. package/package.json +4 -3
  38. package/packages/core/src/accounts/hosted-readiness.ts +21 -0
  39. package/packages/core/src/cli/attention.ts +3 -0
  40. package/packages/core/src/cli/build-control.ts +36 -12
  41. package/packages/core/src/cli/connect.ts +9 -18
  42. package/packages/core/src/cli/context.ts +44 -0
  43. package/packages/core/src/cli/dashboard/configuration.ts +11 -0
  44. package/packages/core/src/cli/dashboard/model.ts +51 -11
  45. package/packages/core/src/cli/dashboard/poll.ts +14 -0
  46. package/packages/core/src/cli/dashboard/queue.ts +21 -0
  47. package/packages/core/src/cli/dashboard/render.ts +43 -22
  48. package/packages/core/src/cli/dispatch-frontend.ts +63 -30
  49. package/packages/core/src/cli/dispatch-mode.ts +35 -16
  50. package/packages/core/src/cli/dispatch-preflight.ts +4 -1
  51. package/packages/core/src/cli/dispatch-repository-feed.ts +40 -11
  52. package/packages/core/src/cli/dispatch-tickets.ts +47 -0
  53. package/packages/core/src/cli/dispatch-upgrade-controller.ts +3 -0
  54. package/packages/core/src/cli/dispatch.ts +522 -145
  55. package/packages/core/src/cli/help.ts +63 -24
  56. package/packages/core/src/cli/init-hosted-accounts.ts +54 -0
  57. package/packages/core/src/cli/init-readiness-remote.ts +16 -3
  58. package/packages/core/src/cli/init-validation.ts +144 -42
  59. package/packages/core/src/cli/issue-links.ts +67 -0
  60. package/packages/core/src/cli/main.ts +32 -15
  61. package/packages/core/src/cli/pr-summary-publication.ts +38 -7
  62. package/packages/core/src/cli/publication-settlement.ts +36 -24
  63. package/packages/core/src/cli/repo-lease.ts +225 -0
  64. package/packages/core/src/cli/repository-status.ts +203 -49
  65. package/packages/core/src/cli/status.ts +42 -4
  66. package/packages/core/src/cli/terminals.ts +37 -2
  67. package/packages/core/src/cli/ticket-editor.ts +20 -6
  68. package/packages/core/src/cli/ticket.ts +264 -46
  69. package/packages/core/src/cli/triage-count-sampler.ts +59 -0
  70. package/packages/core/src/cli/wait.ts +4 -1
  71. package/packages/core/src/cli/watch.ts +19 -4
  72. package/packages/core/src/config/live.ts +45 -4
  73. package/packages/core/src/config/load.ts +9 -0
  74. package/packages/core/src/config/pipeline-source.ts +6 -2
  75. package/packages/core/src/config/ready-assignee.ts +86 -0
  76. package/packages/core/src/config/schema.ts +202 -38
  77. package/packages/core/src/distribution-packaging.ts +1 -1
  78. package/packages/core/src/events/catalog.ts +7 -0
  79. package/packages/core/src/events/compatibility.ts +2 -1
  80. package/packages/core/src/events/payloads.ts +85 -0
  81. package/packages/core/src/events/policy.ts +10 -0
  82. package/packages/core/src/events/repository.ts +93 -28
  83. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +237 -230
  84. package/packages/core/src/kernel/build-identity.ts +12 -0
  85. package/packages/core/src/kernel/change-presence.ts +139 -6
  86. package/packages/core/src/kernel/dispatch-capacity.ts +189 -19
  87. package/packages/core/src/kernel/dispatch-status.ts +10 -1
  88. package/packages/core/src/kernel/dispatch-upgrade.ts +104 -5
  89. package/packages/core/src/kernel/engine.ts +17 -8
  90. package/packages/core/src/kernel/finalize-pr-rejection.ts +95 -0
  91. package/packages/core/src/kernel/generators/build-log.ts +9 -0
  92. package/packages/core/src/kernel/generators/repository-journals.ts +15 -1
  93. package/packages/core/src/kernel/harvest.ts +4 -1
  94. package/packages/core/src/kernel/incremental-fixtures.ts +1 -0
  95. package/packages/core/src/kernel/integration-completeness.ts +104 -17
  96. package/packages/core/src/kernel/integration-landing.ts +17 -0
  97. package/packages/core/src/kernel/integration-state.ts +17 -0
  98. package/packages/core/src/kernel/issue-keywords.ts +202 -0
  99. package/packages/core/src/kernel/janitor-failure.ts +96 -5
  100. package/packages/core/src/kernel/kernel-git.ts +87 -0
  101. package/packages/core/src/kernel/landing-readiness.ts +25 -17
  102. package/packages/core/src/kernel/leaf-restack-state.ts +4 -2
  103. package/packages/core/src/kernel/log-index.ts +1 -1
  104. package/packages/core/src/kernel/node-issue-links.ts +142 -0
  105. package/packages/core/src/kernel/node-landing.ts +2 -1
  106. package/packages/core/src/kernel/node-parent.ts +6 -0
  107. package/packages/core/src/kernel/node-restack-transaction.ts +2 -0
  108. package/packages/core/src/kernel/pr-summary.ts +24 -0
  109. package/packages/core/src/kernel/read-deferrals.ts +75 -12
  110. package/packages/core/src/kernel/read-facts.ts +32 -1
  111. package/packages/core/src/kernel/reconcile-restack.ts +1 -1
  112. package/packages/core/src/kernel/reducer-registry.ts +37 -2
  113. package/packages/core/src/kernel/reducer.ts +147 -5
  114. package/packages/core/src/kernel/ticket-preparation.ts +16 -0
  115. package/packages/core/src/kernel/verify-budget.ts +43 -0
  116. package/packages/core/src/operator/index.ts +3 -1
  117. package/packages/core/src/operator/presentation.ts +3 -0
  118. package/packages/core/src/operator/protocol.ts +38 -2
  119. package/packages/core/src/operator/query.ts +69 -29
  120. package/packages/core/src/operator/registry.ts +47 -26
  121. package/packages/core/src/operator/tickets.ts +77 -10
  122. package/packages/core/src/plugin-sdk/index.ts +13 -0
  123. package/packages/core/src/plugins/manifest.ts +1 -1
  124. package/packages/core/src/plugins/registry.ts +1 -0
  125. package/packages/core/src/ports/forge/contract.ts +69 -0
  126. package/packages/core/src/ports/forge/create.ts +5 -0
  127. package/packages/core/src/ports/forge/fake.ts +184 -3
  128. package/packages/core/src/ports/forge/git-rewrite.ts +4 -2
  129. package/packages/core/src/ports/forge/github.ts +175 -38
  130. package/packages/core/src/ports/forge/local-git.ts +14 -0
  131. package/packages/core/src/ports/forge/readiness.ts +10 -0
  132. package/packages/core/src/ports/forge-failure.ts +43 -0
  133. package/packages/core/src/ports/runner/claude.ts +7 -1
  134. package/packages/core/src/ports/runner/codex.ts +7 -2
  135. package/packages/core/src/ports/runner/native-cli-fixture.ts +2 -1
  136. package/packages/core/src/ports/runner/pi.ts +7 -1
  137. package/packages/core/src/ports/runner/runtime.ts +3 -0
  138. package/packages/core/src/ports/runner/start-prompt.ts +37 -0
  139. package/packages/core/src/ports/tickets/contract.ts +320 -7
  140. package/packages/core/src/ports/tickets/create.ts +89 -20
  141. package/packages/core/src/ports/tickets/fake.ts +18 -0
  142. package/packages/core/src/ports/tickets/file-codec.ts +20 -0
  143. package/packages/core/src/ports/tickets/file.ts +43 -1
  144. package/packages/core/src/ports/tickets/github-fake.ts +1123 -0
  145. package/packages/core/src/ports/tickets/github-issues.ts +431 -0
  146. package/packages/core/src/ports/tickets/github-validators.ts +194 -0
  147. package/packages/core/src/ports/tickets/github.ts +2029 -0
  148. package/packages/core/src/ports/tickets/hosted-index.ts +34 -3
  149. package/packages/core/src/ports/tickets/issue-links.ts +86 -0
  150. package/packages/core/src/ports/tickets/lifecycle.ts +60 -4
  151. package/packages/core/src/ports/tickets/linear.ts +66 -6
  152. package/packages/core/src/ports/tickets/migration.ts +290 -68
  153. package/packages/core/src/ports/tickets/operations.ts +98 -12
  154. package/packages/core/src/ports/tickets/priority.ts +55 -0
  155. package/packages/core/src/ports/tickets/remote-protocol.ts +195 -29
  156. package/packages/core/src/ports/tickets/remote.ts +188 -13
  157. package/packages/core/src/ports/tickets/revision.ts +22 -1
  158. package/packages/core/src/ports/tickets/states.ts +43 -0
  159. package/packages/core/src/ports/tickets/tree.ts +58 -12
  160. package/packages/core/src/ports/tickets/update.ts +12 -2
  161. package/packages/core/src/ports/types.ts +194 -9
  162. package/packages/core/src/ports/workspace/commit-preservation.ts +163 -25
  163. package/packages/core/src/ports/workspace/git-worktree.ts +6 -2
  164. package/packages/core/src/ports/workspace/harvest-execution.ts +4 -2
  165. package/packages/core/src/ports/workspace/vercel-sandbox.ts +121 -27
  166. package/packages/core/src/processes/build-runner.ts +101 -22
  167. package/packages/core/src/processes/dispatcher.ts +1046 -372
  168. package/packages/core/src/processes/execution-no-progress.ts +7 -0
  169. package/packages/core/src/processes/harvest-child.ts +4 -2
  170. package/packages/core/src/processes/harvest-execution-state.ts +104 -0
  171. package/packages/core/src/processes/harvest-runner.ts +263 -25
  172. package/packages/core/src/processes/harvest.ts +5 -8
  173. package/packages/core/src/processes/tick-publication.ts +12 -2
  174. package/packages/core/src/processes/ticket-scan-schedule.ts +78 -0
  175. package/packages/core/src/processes/workspace-preservation.ts +36 -1
  176. package/packages/core/src/runtime-identity.ts +10 -2
  177. package/packages/core/src/scenarios/harness.ts +149 -35
  178. package/packages/core/src/store/adapter.ts +7 -1
  179. package/packages/core/src/store/contract.ts +83 -2
  180. package/packages/core/src/store/digest.ts +32 -1
  181. package/packages/core/src/store/reduced-reads.ts +10 -0
  182. package/packages/core/src/store/reducer-value-shapes.json +4471 -3427
  183. package/packages/core/src/store/remote/protocol.ts +2 -0
  184. package/packages/core/src/store/remote/released-clients.json +22 -0
  185. package/packages/core/src/store/remote/released-reducer-values/1.5.0.json +26924 -0
  186. package/packages/core/src/store/remote/released-reducer-values/1.6.0.json +27173 -0
  187. package/packages/core/src/store/remote/released-reducer-values/index.ts +4 -0
  188. package/packages/core/src/store/repo-state-events.ts +2 -0
  189. package/packages/core/src/store/types.ts +5 -0
  190. package/packages/core/src/testing/dispatch-read-budget.ts +729 -123
  191. package/packages/core/src/testing/index.ts +18 -1
  192. package/packages/core/src/testing/presence-history.ts +79 -0
  193. package/packages/core/src/testing/reduced-read-budget.ts +1424 -33
  194. package/packages/core/src/testing/upgrade-generations.ts +77 -0
  195. package/skills/code-review/SKILL.md +4 -3
  196. package/skills/finalize/SKILL.md +18 -2
  197. package/skills/guide/SKILL.md +417 -143
  198. package/skills/guide/references/accounts.md +9 -0
  199. package/skills/guide/references/integration-tree.md +91 -28
  200. package/skills/guide/references/merge-policy.md +28 -9
  201. package/skills/guide/references/operator-api.md +57 -20
  202. package/skills/guide/references/plugin-authoring.md +89 -8
  203. package/skills/guide/references/remote-store-protocol.md +39 -11
  204. package/skills/guide/references/remote-ticket-protocol.md +126 -12
  205. package/skills/guide/references/restacking.md +24 -6
  206. package/skills/guide/references/setup.md +19 -13
  207. package/skills/guide/references/spec-standard.md +2 -1
  208. package/skills/guide/references/ticket-dependencies.md +26 -8
  209. package/skills/guide/references/ticket-migration.md +70 -7
  210. package/skills/harvest-review/SKILL.md +4 -3
  211. package/skills/implement/SKILL.md +20 -1
  212. package/skills/operate/SKILL.md +149 -35
  213. package/skills/plan/SKILL.md +1 -1
  214. package/skills/reconcile/SKILL.md +5 -4
  215. package/skills/spec/SKILL.md +15 -2
  216. package/skills/tickets/SKILL.md +116 -37
  217. package/templates/autobuild.toml +5 -0
  218. package/templates/hosted-service/package.json +2 -2
@@ -5,6 +5,7 @@ import {
5
5
  import { WorkspaceCleanupRequired } from '../types'
6
6
  import { inspectGitCandidate, preserveGitCommits, restoreGitCommits } from './commit-preservation'
7
7
  import { accountPolicy, accountGuestEnvironment } from './account-policy'
8
+ import { HOSTED_ACCOUNT_READINESS_ENV } from '../../accounts/hosted-readiness'
8
9
  import { gitRewrite, parseRemoteHead } from '../forge/git-rewrite'
9
10
  import { delegateCredential } from '../../store/remote/credentials'
10
11
  import type { ExecutionLaunchAuth } from './build-execution'
@@ -67,7 +68,7 @@ export const VERCEL_PROVISIONED_MARKER = `${VERCEL_AUTOBUILD_PATH}/.provisioned`
67
68
  * instead of resuming a stale distribution that the hosted store would
68
69
  * reject. */
69
70
  export const VERCEL_DISTRIBUTION_VERSION_MARKER = `${VERCEL_AUTOBUILD_PATH}/.distribution-version`
70
- export const VERCEL_BUN_VERSION = '1.4.0'
71
+ export const VERCEL_BUN_VERSION = '1.4.4'
71
72
  export const VERCEL_BUN_PREFIX = '/opt/autobuild-runtime'
72
73
  export const VERCEL_BUN_BIN_PATH = `${VERCEL_BUN_PREFIX}/node_modules/.bin`
73
74
  export const VERCEL_BUN_EXECUTABLE = `${VERCEL_BUN_BIN_PATH}/bun`
@@ -650,6 +651,31 @@ function bunProvisioningError(image: string, operation: string, error: unknown):
650
651
  )
651
652
  }
652
653
 
654
+ /** The trimmed `bun --version` output of the provisioned executable, or
655
+ * undefined when it cannot run or prints nothing. */
656
+ async function reportedBunVersion(
657
+ sandbox: VercelSandboxHandle,
658
+ signal?: AbortSignal,
659
+ ): Promise<string | undefined> {
660
+ try {
661
+ const version = (
662
+ await readableCommand(sandbox, {
663
+ cmd: VERCEL_BUN_EXECUTABLE,
664
+ args: ['--version'],
665
+ ...(signal === undefined ? {} : { signal }),
666
+ })
667
+ ).trim()
668
+ return version === '' ? undefined : version
669
+ } catch (error) {
670
+ if (signal?.aborted) throw error
671
+ return undefined
672
+ }
673
+ }
674
+
675
+ function describeBunVersion(version: string | undefined): string {
676
+ return version === undefined ? 'no version' : version
677
+ }
678
+
653
679
  async function provisionBun(
654
680
  sandbox: VercelSandboxHandle,
655
681
  image: string,
@@ -664,14 +690,15 @@ async function provisionBun(
664
690
  } catch (error) {
665
691
  throw bunProvisioningError(image, 'provision', error)
666
692
  }
667
- try {
668
- await commandOrThrow(sandbox, {
669
- cmd: VERCEL_BUN_EXECUTABLE,
670
- args: ['--version'],
671
- ...(signal === undefined ? {} : { signal }),
672
- })
673
- } catch (error) {
674
- throw bunProvisioningError(image, 'verify provisioned', error)
693
+ const reported = await reportedBunVersion(sandbox, signal)
694
+ if (reported !== VERCEL_BUN_VERSION) {
695
+ throw bunProvisioningError(
696
+ image,
697
+ 'verify provisioned',
698
+ new Error(
699
+ `vercel-sandbox provisioned Bun reports ${describeBunVersion(reported)} but the pin is ${VERCEL_BUN_VERSION} on image ${JSON.stringify(image)}`,
700
+ ),
701
+ )
675
702
  }
676
703
  }
677
704
 
@@ -768,12 +795,26 @@ async function runSystemProvisioning(
768
795
  return completed
769
796
  }
770
797
 
771
- async function preflightBun(sandbox: VercelSandboxHandle, image: string): Promise<void> {
798
+ /** Bring a reused sandbox's Bun to exactly the pin before any guest command
799
+ * runs with it. A matching `bun --version` costs one command; any other
800
+ * report (a stale pin, a missing or unrunnable executable) is reinstalled at
801
+ * the pin with the provisioning recipe. The comparison is exact, so a partly
802
+ * applied upgrade is never accepted by this or any later preflight. */
803
+ async function ensurePinnedBun(
804
+ sandbox: VercelSandboxHandle,
805
+ image: string,
806
+ signal?: AbortSignal,
807
+ ): Promise<void> {
808
+ const reported = await reportedBunVersion(sandbox, signal)
809
+ if (reported === VERCEL_BUN_VERSION) return
772
810
  try {
773
- await commandOrThrow(sandbox, { cmd: VERCEL_BUN_EXECUTABLE, args: ['--version'] })
811
+ await provisionBun(sandbox, image, signal)
774
812
  } catch (error) {
813
+ const cause = error instanceof Error && error.cause instanceof Error ? error.cause : error
775
814
  throw new Error(
776
- `vercel-sandbox Bun ${VERCEL_BUN_VERSION} preflight failed on image ${JSON.stringify(image)}; release and reprovision this sandbox before retrying the build`,
815
+ `vercel-sandbox Bun preflight on image ${JSON.stringify(image)} found ${describeBunVersion(reported)} (pin ${VERCEL_BUN_VERSION}) and could not bring it to the pin: ${
816
+ cause instanceof Error ? cause.message : String(cause)
817
+ }; release and reprovision this sandbox before retrying the build`,
777
818
  { cause: error },
778
819
  )
779
820
  }
@@ -999,8 +1040,8 @@ export async function validateVercelSandbox(
999
1040
  ),
1000
1041
  AB_STORE: options.storeRef,
1001
1042
  AB_TOKEN: options.storeToken,
1002
- ...(options.env.AB_CHATGPT_HOSTED_READINESS
1003
- ? { AB_CHATGPT_HOSTED_READINESS: options.env.AB_CHATGPT_HOSTED_READINESS }
1043
+ ...(options.env[HOSTED_ACCOUNT_READINESS_ENV]
1044
+ ? { [HOSTED_ACCOUNT_READINESS_ENV]: options.env[HOSTED_ACCOUNT_READINESS_ENV] }
1004
1045
  : {}),
1005
1046
  },
1006
1047
  }),
@@ -1422,6 +1463,10 @@ export class VercelSandboxProvider implements WorkspaceProvider {
1422
1463
  revision?: string
1423
1464
  generation?: number
1424
1465
  restoration?: import('../types').WorkspacePreservationHead[]
1466
+ restorationReplaced?: string[]
1467
+ /** Ignored: a sandbox clone never holds archive refs, so restoration here
1468
+ * always fetches each exact ref from origin, whatever the forge. */
1469
+ restorationArchives?: 'local' | 'remote'
1425
1470
  }): Promise<WorkspaceProvisionResult> {
1426
1471
  const scopedToken = await (this.options.delegateCredential ?? delegateCredential)(
1427
1472
  this.options.storeRef,
@@ -1477,6 +1522,7 @@ export class VercelSandboxProvider implements WorkspaceProvider {
1477
1522
  // without a marker — is refreshed in place. Any refresh failure
1478
1523
  // deletes the sandbox so the next pass rematerializes cleanly.
1479
1524
  try {
1525
+ await ensurePinnedBun(sandbox, this.options.config.image, this.operationSignal())
1480
1526
  const archive = await this.archiveBytes()
1481
1527
  await installDistribution(
1482
1528
  sandbox,
@@ -1616,14 +1662,18 @@ export class VercelSandboxProvider implements WorkspaceProvider {
1616
1662
  }
1617
1663
  }
1618
1664
  let provisionHead = base
1665
+ let restorationSkipped: import('../types').RestorationSkip[] = []
1619
1666
  if (opts.restoration?.length) {
1620
1667
  provisionHead = await this.withTrustedGit(sandbox, name, async (exec) => {
1621
- await restoreGitCommits({
1622
- exec,
1623
- workspacePath: VERCEL_WORKSPACE_PATH,
1624
- branch: opts.branch,
1625
- heads: opts.restoration!,
1626
- })
1668
+ restorationSkipped = (
1669
+ await restoreGitCommits({
1670
+ exec,
1671
+ workspacePath: VERCEL_WORKSPACE_PATH,
1672
+ branch: opts.branch,
1673
+ heads: opts.restoration!,
1674
+ replaced: opts.restorationReplaced,
1675
+ })
1676
+ ).skipped
1627
1677
  const result = await exec(
1628
1678
  ['git', 'rev-parse', '--verify', `refs/heads/${opts.branch}^{commit}`],
1629
1679
  { cwd: VERCEL_WORKSPACE_PATH },
@@ -1643,6 +1693,7 @@ export class VercelSandboxProvider implements WorkspaceProvider {
1643
1693
  source: opts.restoration?.length || existing !== null ? 'existing' : 'remote',
1644
1694
  sha: provisionHead,
1645
1695
  },
1696
+ ...(restorationSkipped.length ? { restorationSkipped } : {}),
1646
1697
  }
1647
1698
  }
1648
1699
 
@@ -1819,7 +1870,16 @@ export class VercelSandboxProvider implements WorkspaceProvider {
1819
1870
  // stranded by a protocol-only bump or a missing/unreadable marker — is
1820
1871
  // refreshed before the runner starts, or the hosted store would 409 its
1821
1872
  // heartbeat and the build would strand. Refresh failure retains the
1822
- // sandbox for dispatcher-owned preservation and cleanup.
1873
+ // sandbox for dispatcher-owned preservation and cleanup. Bun is brought
1874
+ // to the pin first, because the refresh and the runner both run with it.
1875
+ try {
1876
+ await ensurePinnedBun(sandbox, this.options.config.image, this.operationSignal())
1877
+ } catch (error) {
1878
+ throw new WorkspaceCleanupRequired(
1879
+ { provider: this.name, ref, path: VERCEL_WORKSPACE_PATH, branch: `ab/${input.slug}` },
1880
+ error,
1881
+ )
1882
+ }
1823
1883
  const distributionIdentity = await this.identityStamp()
1824
1884
  const installed = await readDistributionVersionMarker(sandbox, this.operationSignal())
1825
1885
  if (installed !== distributionIdentity) {
@@ -1833,7 +1893,6 @@ export class VercelSandboxProvider implements WorkspaceProvider {
1833
1893
  )
1834
1894
  }
1835
1895
  }
1836
- await preflightBun(sandbox, this.options.config.image)
1837
1896
  await bootstrapRuntimes(
1838
1897
  sandbox,
1839
1898
  this.options.config,
@@ -1999,6 +2058,7 @@ export class VercelSandboxProvider implements WorkspaceProvider {
1999
2058
  const installed = await readDistributionVersionMarker(sandbox, this.operationSignal())
2000
2059
  if (installed !== distributionIdentity) {
2001
2060
  try {
2061
+ await ensurePinnedBun(sandbox, this.options.config.image, this.operationSignal())
2002
2062
  const archive = await this.archiveBytes()
2003
2063
  await installDistribution(
2004
2064
  sandbox,
@@ -2122,8 +2182,9 @@ export class VercelSandboxProvider implements WorkspaceProvider {
2122
2182
  }
2123
2183
  }
2124
2184
  this.origins.set(name, origin)
2125
- // Launch: reassert the normal network policy and preflight exactly as the
2126
- // build start path does, then one detached guest runner command.
2185
+ // Launch: reassert the normal network policy, bring Bun to the pin and
2186
+ // preflight exactly as the build start path does, then one detached guest
2187
+ // runner command. A sandbox that cannot reach the pin is reaped.
2127
2188
  const { policy } = await this.normalNetworkPolicy(name)
2128
2189
  await sandbox.update({ networkPolicy: policy }, { signal: this.operationSignal() })
2129
2190
  if (this.uncertain.has(name)) {
@@ -2132,7 +2193,20 @@ export class VercelSandboxProvider implements WorkspaceProvider {
2132
2193
  await sandbox.stop({ signal: this.operationSignal() })
2133
2194
  this.uncertain.delete(name)
2134
2195
  }
2135
- await preflightBun(sandbox, this.options.config.image)
2196
+ try {
2197
+ await ensurePinnedBun(sandbox, this.options.config.image, this.operationSignal())
2198
+ } catch (error) {
2199
+ try {
2200
+ this.sessions.set(name, sandbox)
2201
+ await this.reap(name)
2202
+ } catch (deleteError) {
2203
+ throw new AggregateError(
2204
+ [error, deleteError],
2205
+ `harvest sandbox ${name} Bun pin refresh failed and its environment could not be confirmed deleted`,
2206
+ )
2207
+ }
2208
+ throw error
2209
+ }
2136
2210
  await bootstrapRuntimes(
2137
2211
  sandbox,
2138
2212
  this.options.config,
@@ -2352,8 +2426,8 @@ export class VercelSandboxProvider implements WorkspaceProvider {
2352
2426
  }
2353
2427
 
2354
2428
  /** Provision-or-resume. A persistent sandbox auto-resumes on the first SDK
2355
- * call that needs a running session, so the reuse path re-checks the
2356
- * distribution marker exactly as the build reuse path does and then leaves
2429
+ * call that needs a running session, so the reuse path brings Bun to the
2430
+ * pin and re-checks the distribution marker as the build paths do, then leaves
2357
2431
  * the session running for the tool call. A fresh provision runs the same
2358
2432
  * chain as a build workspace and ends by running the repository's setup
2359
2433
  * command; it leaves the environment running too (the tool call follows
@@ -2378,6 +2452,26 @@ export class VercelSandboxProvider implements WorkspaceProvider {
2378
2452
  await sandbox.delete({ signal: this.operationSignal() })
2379
2453
  sandbox = null
2380
2454
  } else {
2455
+ // Bun is brought to the pin before anything runs with it; a reused
2456
+ // environment that cannot reach the pin is deleted.
2457
+ try {
2458
+ await ensurePinnedBun(sandbox, this.options.config.image, this.operationSignal())
2459
+ } catch (error) {
2460
+ try {
2461
+ this.sessions.set(name, sandbox)
2462
+ await this.reap(name)
2463
+ } catch (deleteError) {
2464
+ throw new AggregateError(
2465
+ [error, deleteError],
2466
+ `operator sandbox ${name} Bun pin refresh failed and its environment could not be confirmed deleted`,
2467
+ )
2468
+ }
2469
+ throw new SandboxOperationError(
2470
+ 'provision',
2471
+ error instanceof Error ? error.message : String(error),
2472
+ { cause: error },
2473
+ )
2474
+ }
2381
2475
  const installed = await readDistributionVersionMarker(sandbox, this.operationSignal())
2382
2476
  if (installed !== distributionIdentity) {
2383
2477
  // A reused environment whose installed distribution disagrees with
@@ -18,7 +18,7 @@ import { contextDirectory } from '../context-directory'
18
18
  import { reportIntegrationFailures } from '../kernel/integration-attention'
19
19
  import type { RuntimeIdentity } from '../events/runtime'
20
20
  import { relaunchTarget } from './execution-relaunch'
21
- import { RUNTIME_IDENTITY } from '../runtime-identity'
21
+ import { runtimeIdentity } from '../runtime-identity'
22
22
  import { publishExact } from '../kernel/publication'
23
23
  import {
24
24
  deferMixedVersion,
@@ -27,7 +27,7 @@ import {
27
27
  } from '../kernel/mixed-version'
28
28
  import { hostname } from 'node:os'
29
29
  import { resumeAgent } from '../ports/runner/native-session'
30
- import type { AgentStartOpts } from '../ports/types'
30
+ import type { AgentStartOpts, StartPromptOpts } from '../ports/types'
31
31
  import { readTerminalGuardBoundary } from '../store/reduced-reads'
32
32
  import type { OpenSession } from '../kernel/reducer'
33
33
  import { nativeSessionHandleSchema } from '../ports/runner/native-session'
@@ -47,7 +47,12 @@ import {
47
47
  requireRewrite,
48
48
  } from '../kernel/reconcile-restack'
49
49
  import { reconcileHead, reconcileRewriteHead } from '../kernel/reconcile-head'
50
- import { readBuildFacts, readBuildSelector, readPhaseFailures } from '../store/reduced-reads'
50
+ import {
51
+ readBuildFacts,
52
+ readBuildSelector,
53
+ readPhaseFailures,
54
+ type CurrentBuildFacts,
55
+ } from '../store/reduced-reads'
51
56
  import { delegateCredential } from '../store/remote/credentials'
52
57
  import { refreshSummaryBoundary } from '../cli/pr-summary-publication'
53
58
  /**
@@ -103,6 +108,7 @@ import { KERNEL, agentActor, type Actor } from '../events/envelope'
103
108
  import type { IdSource } from '../ids'
104
109
  import { decideNextFromFacts, type Decision } from '../kernel/engine'
105
110
  import { defineReducer } from '../kernel/incremental'
111
+ import { continuesVerifyCycle } from '../kernel/pr-summary'
106
112
  import { PHASE_SPECS } from '../kernel/phases'
107
113
  import type { BuildState } from '../kernel/reducer'
108
114
  import { evaluateVerifyApplicability } from '../kernel/verify-applicability'
@@ -343,6 +349,20 @@ function capDiffOutput(output: string): string {
343
349
  return `${output.slice(0, FINALIZE_DIFF_CAPTURE_CAP)}\n... (truncated at ${FINALIZE_DIFF_CAPTURE_CAP} characters)`
344
350
  }
345
351
 
352
+ /** The runtime's own first message for a fresh start, spread onto
353
+ * `session.started`; empty when the runtime cannot report it. */
354
+ function recordedStartPrompt(runner: AgentRunner, opts: StartPromptOpts): { prompt?: string } {
355
+ const prompt = runner.startPrompt?.(opts)
356
+ return typeof prompt === 'string' && prompt !== '' ? { prompt } : {}
357
+ }
358
+
359
+ /** The message a native resume sends after an interruption. */
360
+ function interruptionMessage(
361
+ cause: NonNullable<EventPayload<'session.started'>['continuation']>['cause'],
362
+ ): string {
363
+ return `This session was interrupted (${cause}). Re-check the worktree and re-run anything that was in flight. Continue the current phase and round; run ab context for its durable inputs.`
364
+ }
365
+
346
366
  function sessionBudgetError(seconds: number): string {
347
367
  return `phase session budget expired after ${seconds} seconds`
348
368
  }
@@ -829,6 +849,15 @@ export class BuildRunner {
829
849
  },
830
850
  },
831
851
  }
852
+ // A continuation resumes the native session with the interruption
853
+ // notice, never the caller's start prompt.
854
+ write = {
855
+ ...write,
856
+ payload: {
857
+ ...write.payload,
858
+ prompt: interruptionMessage(write.payload.continuation!.cause),
859
+ },
860
+ }
832
861
  started = await store.appendIfCurrent(slug, facts.cursor, write)
833
862
  if (started) break
834
863
  }
@@ -844,7 +873,7 @@ export class BuildRunner {
844
873
  const continuation = this.continuationIntents.get(opts.env.AB_SESSION!)
845
874
  this.continuationIntents.delete(opts.env.AB_SESSION!)
846
875
  if (!continuation) return runner.start(opts)
847
- const message = `This session was interrupted (${continuation.cause}). Re-check the worktree and re-run anything that was in flight. Continue the current phase and round; run ab context for its durable inputs.`
876
+ const message = interruptionMessage(continuation.cause)
848
877
  this.interruptionPrompts.set(opts.env.AB_SESSION!, message)
849
878
  if (opts.stream)
850
879
  opts.stream.append([
@@ -928,7 +957,7 @@ export class BuildRunner {
928
957
  store: withDrainingExecution(
929
958
  deps.store,
930
959
  deps.instance,
931
- deps.runtimeIdentity ?? RUNTIME_IDENTITY,
960
+ deps.runtimeIdentity ?? runtimeIdentity(),
932
961
  ),
933
962
  }
934
963
  this.maxPhaseAttempts = deps.opts?.maxPhaseAttempts ?? 2
@@ -1070,7 +1099,7 @@ export class BuildRunner {
1070
1099
  payload: {
1071
1100
  instance,
1072
1101
  attachedSeq: attached.seq,
1073
- runtime: this.deps.runtimeIdentity ?? RUNTIME_IDENTITY,
1102
+ runtime: this.deps.runtimeIdentity ?? runtimeIdentity(),
1074
1103
  },
1075
1104
  })
1076
1105
  }
@@ -1125,7 +1154,8 @@ export class BuildRunner {
1125
1154
  }
1126
1155
  const currentFailure = state.setupFailure
1127
1156
  const openSetupEscalation = state.openEscalations.some(
1128
- (escalation) => escalation.phase === 'setup' && escalation.source === 'policy',
1157
+ (escalation) =>
1158
+ escalation.phase === 'setup' && escalation.source === 'policy' && !escalation.janitor,
1129
1159
  )
1130
1160
  const streak = await readBuildSelector(store, slug, 'setupStreak')
1131
1161
 
@@ -1400,7 +1430,7 @@ export class BuildRunner {
1400
1430
  const request = relaunchTarget(
1401
1431
  facts.state,
1402
1432
  this.deps.instance,
1403
- this.deps.runtimeIdentity ?? RUNTIME_IDENTITY,
1433
+ this.deps.runtimeIdentity ?? runtimeIdentity(),
1404
1434
  )
1405
1435
  if (!request) return false
1406
1436
  if (
@@ -1461,7 +1491,7 @@ export class BuildRunner {
1461
1491
  const facts = (await readBuildFacts(this.deps.store, this.deps.slug)).value
1462
1492
  if (await this.requestRelaunch(facts)) break
1463
1493
  if (await deferMixedVersion(this.deps.store, this.deps.slug, KERNEL)) break
1464
- if (await this.refreshSummary()) break
1494
+ if (await this.refreshSummary(facts)) break
1465
1495
  if (facts.publication.pending()) {
1466
1496
  const next = decideNextFromFacts(facts.state, facts.log, await this.captureConfig())
1467
1497
  // Inert controls cannot start more work under unsettled publication.
@@ -1527,21 +1557,38 @@ export class BuildRunner {
1527
1557
  }
1528
1558
  }
1529
1559
 
1530
- private async refreshSummary(): Promise<boolean> {
1560
+ private async refreshSummary(facts: CurrentBuildFacts): Promise<boolean> {
1531
1561
  if (await deferMixedVersion(this.deps.store, this.deps.slug, KERNEL)) return false
1532
1562
  try {
1533
1563
  await this.ensureLease()
1534
1564
  } catch {
1535
1565
  return false
1536
1566
  }
1537
- return refreshSummaryBoundary({
1538
- store: this.deps.store,
1539
- forge: this.deps.forge,
1540
- slug: this.deps.slug,
1541
- workspacePath: this.deps.workspacePath,
1542
- storeRef: this.deps.sessionEnv?.AB_STORE ?? 'local',
1543
- clock: this.deps.clock,
1544
- })
1567
+ return refreshSummaryBoundary(
1568
+ {
1569
+ store: this.deps.store,
1570
+ forge: this.deps.forge,
1571
+ slug: this.deps.slug,
1572
+ workspacePath: this.deps.workspacePath,
1573
+ storeRef: this.deps.sessionEnv?.AB_STORE ?? 'local',
1574
+ clock: this.deps.clock,
1575
+ },
1576
+ { continuesVerifyCycle: this.summaryContinuesVerifyCycle(facts), reassert: true },
1577
+ )
1578
+ }
1579
+
1580
+ /** Pure over the loop's facts and the config that decided the last step;
1581
+ * any doubt publishes as before. */
1582
+ private summaryContinuesVerifyCycle(facts: CurrentBuildFacts): boolean {
1583
+ try {
1584
+ return continuesVerifyCycle(
1585
+ facts.summaryBoundary,
1586
+ facts.log.verifyStarted,
1587
+ decideNextFromFacts(facts.state, facts.log, this.boundaryConfig),
1588
+ )
1589
+ } catch {
1590
+ return false
1591
+ }
1545
1592
  }
1546
1593
 
1547
1594
  /**
@@ -2836,6 +2883,7 @@ export class BuildRunner {
2836
2883
  phase: 'finalize',
2837
2884
  round: 1,
2838
2885
  ...(streamBracket !== undefined ? { stream: streamBracket.streamId } : {}),
2886
+ ...recordedStartPrompt(target.runner, { skill, invocation: slug, buildSlug: slug }),
2839
2887
  ...(substitution !== undefined
2840
2888
  ? { substitution: { failed: substitution, selectedIndex: index } }
2841
2889
  : {}),
@@ -2906,7 +2954,12 @@ export class BuildRunner {
2906
2954
  // The failure-tolerant post-step still records its outcome below.
2907
2955
  }
2908
2956
  }
2909
- if (await this.settleReadDeferral(session)) {
2957
+ if (
2958
+ await this.settleReadDeferral(session, {
2959
+ completed:
2960
+ turn.abortCause === undefined && turnError === undefined && result?.kind !== 'failed',
2961
+ })
2962
+ ) {
2910
2963
  this.closeBracketStream(streamBracket, 'aborted')
2911
2964
  return { actor: agentActor(step, session), failureNote: undefined, cancelled: true }
2912
2965
  }
@@ -2991,6 +3044,7 @@ export class BuildRunner {
2991
3044
  phase: 'finalize',
2992
3045
  round: 1,
2993
3046
  ...(streamBracket !== undefined ? { stream: streamBracket.streamId } : {}),
3047
+ ...recordedStartPrompt(runner, { skill, invocation: slug, buildSlug: slug }),
2994
3048
  },
2995
3049
  } satisfies EventWrite<'session.started'>)
2996
3050
 
@@ -3062,7 +3116,9 @@ export class BuildRunner {
3062
3116
  failureNote === undefined && turn.abortCause !== 'operator' ? 'completed' : 'aborted',
3063
3117
  )
3064
3118
 
3065
- const deferred = await this.settleReadDeferral(session)
3119
+ const deferred = await this.settleReadDeferral(session, {
3120
+ completed: failureNote === undefined && turn.abortCause === undefined,
3121
+ })
3066
3122
  return {
3067
3123
  actor: agentActor(step, session),
3068
3124
  failureNote,
@@ -3616,6 +3672,7 @@ export class BuildRunner {
3616
3672
  round: spec.round,
3617
3673
  })
3618
3674
  const stream = streamBracket?.sink
3675
+ const live = index === 0 ? primaryLive : undefined
3619
3676
  const startedEnvelope = await this.startBracket({
3620
3677
  actor: KERNEL,
3621
3678
  type: 'session.started',
@@ -3632,10 +3689,16 @@ export class BuildRunner {
3632
3689
  ...(substitution !== undefined
3633
3690
  ? { substitution: { failed: substitution, selectedIndex: index } }
3634
3691
  : {}),
3692
+ ...(live !== undefined
3693
+ ? { prompt: continueMessage(spec) }
3694
+ : recordedStartPrompt(target.runner, {
3695
+ skill: spec.skill,
3696
+ invocation: slug,
3697
+ buildSlug: slug,
3698
+ })),
3635
3699
  },
3636
3700
  } satisfies EventWrite<'session.started'>)
3637
3701
  const preSeq = startedEnvelope.seq
3638
- const live = index === 0 ? primaryLive : undefined
3639
3702
 
3640
3703
  let handle: AgentSessionHandle | undefined = live?.handle
3641
3704
  let result: AgentTurnResult | undefined
@@ -3940,6 +4003,9 @@ export class BuildRunner {
3940
4003
  phase: spec.phase,
3941
4004
  round: spec.round,
3942
4005
  ...(streamBracket !== undefined ? { stream: streamBracket.streamId } : {}),
4006
+ ...(live !== undefined
4007
+ ? { prompt: continueMessage(spec) }
4008
+ : recordedStartPrompt(runner, { skill: spec.skill, invocation: slug, buildSlug: slug })),
3943
4009
  },
3944
4010
  } satisfies EventWrite<'session.started'>)
3945
4011
  const preSeq = startedEnvelope.seq
@@ -4384,12 +4450,24 @@ export class BuildRunner {
4384
4450
  * new evidence instead of deadlocking before its recovery session starts.
4385
4451
  */
4386
4452
 
4387
- private async settleReadDeferral(session: string): Promise<boolean> {
4453
+ /**
4454
+ * Settle the session's pending own-build read deferral. Returns true when it
4455
+ * parked the build. A finalize post-step never calls a terminal, so only
4456
+ * durable recovery evidence (`session.build-read-recovered`, newer than the
4457
+ * chain's latest failure) plus a `completed` turn retires its deferral; the
4458
+ * caller's `finalize.step-completed` then clears it.
4459
+ */
4460
+ private async settleReadDeferral(
4461
+ session: string,
4462
+ opts?: { completed?: boolean },
4463
+ ): Promise<boolean> {
4388
4464
  const { store, slug } = this.deps
4389
4465
  const item = (await readBuildFacts(store, slug)).value.log.readDeferrals.find(
4390
4466
  (item) => item.session === session,
4391
4467
  )
4392
4468
  if (!item) return false
4469
+ const recovered =
4470
+ opts?.completed === true && item.phase === 'finalize' && item.recovered && !item.settled
4393
4471
  if (!item.ended) {
4394
4472
  await store.append(slug, {
4395
4473
  actor: KERNEL,
@@ -4404,6 +4482,7 @@ export class BuildRunner {
4404
4482
  },
4405
4483
  })
4406
4484
  }
4485
+ if (recovered) return false
4407
4486
  await this.raiseReadDeferral(item)
4408
4487
  return true
4409
4488
  }