@defrex/autobuild 1.0.1 → 1.1.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 (186) hide show
  1. package/README.md +6 -6
  2. package/SPEC.md +360 -229
  3. package/docs/answering-blocked-builds.md +2 -2
  4. package/docs/architecture.md +155 -45
  5. package/docs/assets/headline-wide.png +0 -0
  6. package/docs/builds.md +4 -4
  7. package/docs/cli.md +4 -4
  8. package/docs/configuration-overview.md +4 -4
  9. package/docs/configuration.md +245 -210
  10. package/docs/dispatcher-hosting.md +2 -2
  11. package/docs/dispatcher.md +1 -1
  12. package/docs/forges.md +5 -5
  13. package/docs/getting-started.md +2 -2
  14. package/docs/glossary.md +6 -6
  15. package/docs/hosted-dispatcher.md +6 -3
  16. package/docs/hosted-service.md +16 -5
  17. package/docs/integration-overview.md +15 -15
  18. package/docs/integration-tree.md +45 -38
  19. package/docs/integration.md +6 -6
  20. package/docs/mcp.md +16 -15
  21. package/docs/{landing-policy.md → merge-policy.md} +42 -24
  22. package/docs/migration-1.0.md +17 -13
  23. package/docs/operating.md +41 -18
  24. package/docs/operator-api.md +91 -15
  25. package/docs/operator-surfaces.md +8 -4
  26. package/docs/overview.md +3 -3
  27. package/docs/remote-store-protocol.md +76 -11
  28. package/docs/remote-ticket-protocol.md +1 -1
  29. package/docs/restacking.md +54 -15
  30. package/docs/setup.md +41 -6
  31. package/docs/skills.md +1 -1
  32. package/docs/spec-standard.md +6 -6
  33. package/docs/ticket-dependencies.md +7 -7
  34. package/docs/tickets.md +8 -2
  35. package/docs/troubleshooting.md +2 -2
  36. package/docs/upgrading.md +8 -3
  37. package/docs/verification.md +60 -14
  38. package/package.json +7 -5
  39. package/packages/core/src/cli/binary-direct.ts +13 -1
  40. package/packages/core/src/cli/binary-lifecycle.ts +65 -2
  41. package/packages/core/src/cli/build-control.ts +83 -28
  42. package/packages/core/src/cli/context.ts +81 -38
  43. package/packages/core/src/cli/dashboard/facts.ts +2 -1
  44. package/packages/core/src/cli/dashboard/integration-detail.ts +8 -8
  45. package/packages/core/src/cli/dashboard/integration-row.ts +40 -13
  46. package/packages/core/src/cli/dashboard/landing-display.ts +25 -0
  47. package/packages/core/src/cli/dashboard/model.ts +56 -33
  48. package/packages/core/src/cli/dashboard/poll.ts +9 -3
  49. package/packages/core/src/cli/dashboard/render.ts +59 -37
  50. package/packages/core/src/cli/dashboard/target-distance.ts +14 -0
  51. package/packages/core/src/cli/dashboard/tree.ts +3 -2
  52. package/packages/core/src/cli/dispatch-args.ts +1 -1
  53. package/packages/core/src/cli/dispatch-frontend.ts +6 -3
  54. package/packages/core/src/cli/dispatch.ts +35 -9
  55. package/packages/core/src/cli/env.ts +4 -0
  56. package/packages/core/src/cli/help.ts +30 -23
  57. package/packages/core/src/cli/main.ts +24 -8
  58. package/packages/core/src/cli/node-verification-provenance.ts +1 -97
  59. package/packages/core/src/cli/publication-settlement.ts +43 -20
  60. package/packages/core/src/cli/repository-status.ts +20 -9
  61. package/packages/core/src/cli/status.ts +42 -5
  62. package/packages/core/src/cli/store-opening.ts +6 -1
  63. package/packages/core/src/cli/terminal.ts +22 -1
  64. package/packages/core/src/cli/terminals.ts +14 -10
  65. package/packages/core/src/cli/upgrade-landing.ts +70 -30
  66. package/packages/core/src/cli/upgrade.ts +3 -1
  67. package/packages/core/src/cli/wait.ts +15 -7
  68. package/packages/core/src/cli/watch-lifetime.ts +111 -0
  69. package/packages/core/src/cli/watch.ts +634 -511
  70. package/packages/core/src/config/effective-artifact.fixture.ts +27 -0
  71. package/packages/core/src/config/effective-artifact.ts +13 -0
  72. package/packages/core/src/config/landing.ts +1 -1
  73. package/packages/core/src/config/load.ts +21 -1
  74. package/packages/core/src/config/pipeline-source.ts +28 -0
  75. package/packages/core/src/config/reference-metadata.ts +2 -0
  76. package/packages/core/src/config/reference.ts +22 -7
  77. package/packages/core/src/config/schema.ts +86 -162
  78. package/packages/core/src/context-directory.ts +26 -0
  79. package/packages/core/src/distribution-packaging.ts +26 -5
  80. package/packages/core/src/events/catalog.ts +10 -2
  81. package/packages/core/src/events/globs.ts +1 -1
  82. package/packages/core/src/events/payloads.ts +70 -1
  83. package/packages/core/src/events/policy.ts +7 -0
  84. package/packages/core/src/events/repository.ts +2 -4
  85. package/packages/core/src/events/sessions.ts +6 -6
  86. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +571 -0
  87. package/packages/core/src/kernel/auto-merge.ts +2 -2
  88. package/packages/core/src/kernel/engine.ts +255 -26
  89. package/packages/core/src/kernel/generators/leaf-restack-log.ts +10 -0
  90. package/packages/core/src/kernel/integration-landing.ts +3 -3
  91. package/packages/core/src/kernel/integration-state.ts +27 -4
  92. package/packages/core/src/kernel/leaf-restack-state.ts +28 -3
  93. package/packages/core/src/kernel/log-index.ts +13 -1
  94. package/packages/core/src/kernel/node-landing.ts +8 -8
  95. package/packages/core/src/kernel/node-parent.ts +2 -2
  96. package/packages/core/src/kernel/node-restack-transaction.ts +1 -1
  97. package/packages/core/src/kernel/node-verification-context.ts +216 -0
  98. package/packages/core/src/kernel/phases.ts +1 -1
  99. package/packages/core/src/kernel/plan-verify-selection.ts +16 -0
  100. package/packages/core/src/kernel/publication-retry.ts +168 -0
  101. package/packages/core/src/kernel/reconcile-restack.ts +29 -1
  102. package/packages/core/src/kernel/reducer.ts +82 -5
  103. package/packages/core/src/kernel/target-distance.ts +45 -0
  104. package/packages/core/src/kernel/terminal-guard.ts +10 -1
  105. package/packages/core/src/kernel/verify-stage-state.ts +123 -0
  106. package/packages/core/src/kernel/verify-stages.ts +39 -0
  107. package/packages/core/src/ontology.ts +1 -0
  108. package/packages/core/src/operator/annotations.ts +6 -0
  109. package/packages/core/src/operator/control.ts +1 -1
  110. package/packages/core/src/operator/index.ts +1 -7
  111. package/packages/core/src/operator/landings.ts +5 -1
  112. package/packages/core/src/operator/presentation.ts +6 -1
  113. package/packages/core/src/operator/query.ts +14 -18
  114. package/packages/core/src/operator/registry.ts +17 -6
  115. package/packages/core/src/operator/sandbox-host.ts +64 -40
  116. package/packages/core/src/operator/sandbox.ts +3 -0
  117. package/packages/core/src/operator/ticket-source-backend.ts +3 -12
  118. package/packages/core/src/ports/forge/contract.ts +2 -2
  119. package/packages/core/src/ports/forge/git-rewrite.ts +25 -2
  120. package/packages/core/src/ports/forge/github-readiness.ts +2 -2
  121. package/packages/core/src/ports/forge/github.ts +26 -7
  122. package/packages/core/src/ports/forge/local-git.ts +4 -4
  123. package/packages/core/src/ports/forge/readiness.ts +1 -1
  124. package/packages/core/src/ports/forge-failure.ts +24 -0
  125. package/packages/core/src/ports/workspace/build-execution.ts +3 -1
  126. package/packages/core/src/ports/workspace/phase-scratch.ts +4 -3
  127. package/packages/core/src/ports/workspace/vercel-sandbox.ts +59 -39
  128. package/packages/core/src/processes/build-child.ts +6 -8
  129. package/packages/core/src/processes/build-execution-state.ts +8 -5
  130. package/packages/core/src/processes/build-runner.ts +522 -98
  131. package/packages/core/src/processes/dispatcher.ts +186 -101
  132. package/packages/core/src/processes/execution-no-progress.ts +8 -1
  133. package/packages/core/src/processes/phase-failure-budget.ts +1 -0
  134. package/packages/core/src/processes/publication-loss.ts +8 -2
  135. package/packages/core/src/processes/publication-state.ts +42 -4
  136. package/packages/core/src/processes/repo-view.ts +14 -0
  137. package/packages/core/src/processes/verify-cycle-config.ts +96 -0
  138. package/packages/core/src/{integration → scenarios}/harness.ts +330 -317
  139. package/packages/core/src/store/adapter.ts +1 -0
  140. package/packages/core/src/store/build-scope.ts +9 -0
  141. package/packages/core/src/store/contract.ts +113 -1
  142. package/packages/core/src/store/local/schema.ts +13 -0
  143. package/packages/core/src/store/local/store.ts +42 -0
  144. package/packages/core/src/store/memory.ts +47 -0
  145. package/packages/core/src/store/operator-presence.ts +21 -0
  146. package/packages/core/src/store/phase-session.ts +10 -0
  147. package/packages/core/src/store/reducer-value-shapes.json +5081 -4160
  148. package/packages/core/src/store/remote/client.ts +47 -1
  149. package/packages/core/src/store/remote/compatibility.ts +2 -0
  150. package/packages/core/src/store/remote/protocol.ts +4 -0
  151. package/packages/core/src/store/remote/version.ts +3 -1
  152. package/packages/core/src/store/retention.ts +2 -3
  153. package/packages/core/src/store/session-handle.ts +9 -0
  154. package/packages/core/src/store/streams/session-writer.ts +1 -1
  155. package/packages/core/src/store/types.ts +12 -2
  156. package/packages/core/src/testing/index.ts +11 -1
  157. package/packages/core/src/testing/temp-directories.ts +58 -0
  158. package/skills/code-review/SKILL.md +23 -9
  159. package/skills/finalize/SKILL.md +15 -7
  160. package/skills/guide/SKILL.md +253 -118
  161. package/skills/guide/references/integration-tree.md +45 -38
  162. package/skills/guide/references/{landing-policy.md → merge-policy.md} +42 -24
  163. package/skills/guide/references/migration-1.0.md +17 -13
  164. package/skills/guide/references/operator-api.md +91 -15
  165. package/skills/guide/references/remote-store-protocol.md +76 -11
  166. package/skills/guide/references/remote-ticket-protocol.md +1 -1
  167. package/skills/guide/references/restacking.md +54 -15
  168. package/skills/guide/references/setup.md +41 -6
  169. package/skills/guide/references/spec-standard.md +6 -6
  170. package/skills/guide/references/ticket-dependencies.md +7 -7
  171. package/skills/implement/SKILL.md +43 -17
  172. package/skills/operate/SKILL.md +117 -116
  173. package/skills/plan/SKILL.md +39 -13
  174. package/skills/plan-review/SKILL.md +15 -10
  175. package/skills/reconcile/SKILL.md +22 -3
  176. package/skills/spec/SKILL.md +19 -19
  177. package/skills/tickets/SKILL.md +9 -7
  178. package/templates/autobuild.toml +1 -1
  179. package/templates/hosted-service/package.json +2 -2
  180. package/packages/core/src/orchestrator/approvals.ts +0 -115
  181. package/packages/core/src/orchestrator/conversation.ts +0 -167
  182. package/packages/core/src/orchestrator/model.ts +0 -86
  183. package/packages/core/src/orchestrator/prompt.ts +0 -63
  184. package/packages/core/src/orchestrator/tools.ts +0 -117
  185. package/packages/core/src/orchestrator/turn-runner.ts +0 -457
  186. package/packages/core/src/processes/orchestrator-tick.ts +0 -360
@@ -14,7 +14,7 @@
14
14
  * a broken or unsupported config degrades the sandbox tools of one binding,
15
15
  * never the orchestrator itself.
16
16
  */
17
- import { mkdtemp } from 'node:fs/promises'
17
+ import { mkdtemp, rm } from 'node:fs/promises'
18
18
  import { tmpdir } from 'node:os'
19
19
  import { join } from 'node:path'
20
20
  import type { Config } from '../config/schema'
@@ -52,7 +52,8 @@ export interface HostedOperatorSandboxOptions {
52
52
  storeToken: string
53
53
  /** Scratch root for the composition's filesystem seams (worktree root,
54
54
  * repo root, sandbox root). Default: a fresh `mkdtemp` under the OS temp
55
- * directory. The builtin providers only touch these paths through host-git
55
+ * directory, removed on construction failure or dispose(). A supplied root
56
+ * remains caller-owned. The builtin providers only touch these paths through host-git
56
57
  * or local-scratch paths the injected seams bypass; a plugin-provider config
57
58
  * fails construction before any path use. */
58
59
  scratchRoot?: string
@@ -88,6 +89,10 @@ export function remoteBranchHeadFromForge(
88
89
  }
89
90
  }
90
91
 
92
+ export interface HostedOperatorSandboxService extends OperatorSandboxService {
93
+ dispose(): Promise<void>
94
+ }
95
+
91
96
  /** Build the hosted operator-sandbox backend from the effective config and
92
97
  * injected seams. Throws on every construction failure (unknown provider or
93
98
  * forge, missing Vercel SDK credential, forbidden forwarded env name,
@@ -95,46 +100,65 @@ export function remoteBranchHeadFromForge(
95
100
  * contains and degrades to serving without the sandbox tools. */
96
101
  export async function createHostedOperatorSandboxService(
97
102
  options: HostedOperatorSandboxOptions,
98
- ): Promise<OperatorSandboxService> {
103
+ ): Promise<HostedOperatorSandboxService> {
104
+ const ownsScratch = options.scratchRoot === undefined
99
105
  const scratch = options.scratchRoot ?? (await mkdtemp(join(tmpdir(), 'autobuild-sandbox-host-')))
100
- const forge =
101
- options.forge ??
102
- (await createForge({
103
- name: options.config.forge,
106
+ let disposal: Promise<void> | undefined
107
+ const dispose = () => {
108
+ disposal ??= ownsScratch ? rm(scratch, { recursive: true, force: true }) : Promise.resolve()
109
+ return disposal
110
+ }
111
+ try {
112
+ const forge =
113
+ options.forge ??
114
+ (await createForge({
115
+ name: options.config.forge,
116
+ registry: createPluginRegistry(),
117
+ env: options.env,
118
+ repoRoot: scratch,
119
+ repository: options.repo,
120
+ }))
121
+ if (forge.remoteBranchSha === undefined) {
122
+ throw new Error(
123
+ `the configured forge "${options.config.forge}" does not resolve remote branch heads; ` +
124
+ 'the hosted sandbox backend has no checkout to resolve base heads against',
125
+ )
126
+ }
127
+ // Builtin-only registry: a plugin-provider config fails construction here
128
+ // (unknown provider in the empty registry) and the caller contains it.
129
+ const provider = await createWorkspaceProvider(options.config.workspace, {
104
130
  registry: createPluginRegistry(),
105
- env: options.env,
131
+ worktreeRoot: scratch,
106
132
  repoRoot: scratch,
107
- repository: options.repo,
108
- }))
109
- if (forge.remoteBranchSha === undefined) {
110
- throw new Error(
111
- `the configured forge "${options.config.forge}" does not resolve remote branch heads; ` +
112
- 'the hosted sandbox backend has no checkout to resolve base heads against',
113
- )
133
+ env: options.env,
134
+ storeRef: options.storeRef,
135
+ storeToken: options.storeToken,
136
+ origin: async () => options.repo,
137
+ remoteBranchHead: remoteBranchHeadFromForge(forge),
138
+ sandboxSetupCommand: options.config.commands.setup,
139
+ sandboxRoot: join(scratch, 'orchestrator-sandboxes'),
140
+ sandboxEnvironmentVariables: options.config.orchestrator.sandbox.environmentVariables,
141
+ orchestratorSandboxEnabled: true,
142
+ })
143
+ const service = await createOperatorSandboxService({
144
+ store: options.store,
145
+ repo: options.repo,
146
+ provider,
147
+ sandbox: options.config.orchestrator.sandbox,
148
+ baseBranch: options.config.baseBranch,
149
+ forge,
150
+ ...(options.clock !== undefined ? { clock: options.clock } : {}),
151
+ })
152
+ return Object.assign(service, { dispose })
153
+ } catch (error) {
154
+ try {
155
+ await dispose()
156
+ } catch (cleanupError) {
157
+ throw new AggregateError(
158
+ [error, cleanupError],
159
+ 'Hosted sandbox construction and cleanup failed',
160
+ )
161
+ }
162
+ throw error
114
163
  }
115
- // Builtin-only registry: a plugin-provider config fails construction here
116
- // (unknown provider in the empty registry) and the caller contains it.
117
- const provider = await createWorkspaceProvider(options.config.workspace, {
118
- registry: createPluginRegistry(),
119
- worktreeRoot: scratch,
120
- repoRoot: scratch,
121
- env: options.env,
122
- storeRef: options.storeRef,
123
- storeToken: options.storeToken,
124
- origin: async () => options.repo,
125
- remoteBranchHead: remoteBranchHeadFromForge(forge),
126
- sandboxSetupCommand: options.config.commands.setup,
127
- sandboxRoot: join(scratch, 'orchestrator-sandboxes'),
128
- sandboxEnvironmentVariables: options.config.orchestrator.sandbox.environmentVariables,
129
- orchestratorSandboxEnabled: true,
130
- })
131
- return createOperatorSandboxService({
132
- store: options.store,
133
- repo: options.repo,
134
- provider,
135
- sandbox: options.config.orchestrator.sandbox,
136
- baseBranch: options.config.baseBranch,
137
- forge,
138
- ...(options.clock !== undefined ? { clock: options.clock } : {}),
139
- })
140
164
  }
@@ -142,6 +142,9 @@ export interface OperatorSandboxConfig {
142
142
  }
143
143
 
144
144
  export interface OperatorSandboxService {
145
+ /** Dispose local composition resources only; separate from release(identity, repo).
146
+ * Caller-owned static services retain their lifetime across requests. */
147
+ dispose?(): Promise<void>
145
148
  /** True when both a forge and the provider's sandbox publication
146
149
  * capability are present, i.e. `publish` is callable. */
147
150
  readonly canPublish: boolean
@@ -1,16 +1,7 @@
1
1
  import { ticketLifecycle } from '../ports/tickets/lifecycle'
2
- /**
3
- * A dispatcher ticket source as the registry's ticket backend (AUT-342):
4
- * the tick's turn runner takes an `OperatorToolRegistry`, and
5
- * `buildRegistry`'s ticket tools require an `OperatorTicketBackend` — but
6
- * the dispatcher's wiring holds a `TicketSource`, not a backend, and
7
- * `buildMcpTicketBackend` reads a checkout's autobuild.toml, which cannot
8
- * run in origin mode. This adapter hands the dispatcher's
9
- * already-constructed source straight through (it was built by
10
- * `createTicketSource` from the same effective `[tickets]` config the
11
- * `OperatorTicketContext` would derive, for the same repository) and derives
12
- * the workflow-state list from the effective config's lifecycle names.
13
- */
2
+ /** Adapt an already-constructed ticket source to the registry backend without
3
+ * reading a checkout's configuration. Lifecycle names come from the same
4
+ * effective configuration used to construct that source. */
14
5
  import type { Config } from '../config/schema'
15
6
  import type { OperatorTicketBackend, OperatorTicketContext } from './tickets'
16
7
  import type { TicketSource } from '../ports/types'
@@ -265,7 +265,7 @@ export function describeForgeContract(name: string, factory: ForgeContractFactor
265
265
  })
266
266
  })
267
267
 
268
- test('getPrState discriminates a merged PR with its independently observed landing SHA', async () => {
268
+ test('getPrState discriminates a merged PR with its independently observed merge SHA', async () => {
269
269
  await withForge(factory, undefined, async (harness) => {
270
270
  const { pr } = await pushAndOpen(harness)
271
271
  await harness.controls.prepareMergeable(pr.number)
@@ -280,7 +280,7 @@ export function describeForgeContract(name: string, factory: ForgeContractFactor
280
280
  })
281
281
  })
282
282
 
283
- test('identity-aware squash exposes the actual landed trailer when inspection is supported', async () => {
283
+ test('identity-aware squash exposes the actual merged trailer when inspection is supported', async () => {
284
284
  await withForge(factory, undefined, async (harness) => {
285
285
  const { pr } = await pushAndOpen(harness)
286
286
  await harness.controls.prepareMergeable(pr.number)
@@ -1,3 +1,4 @@
1
+ import { classifyGitNetworkFailure } from '../forge-failure'
1
2
  import type { ForgeRewrite, RewriteResult } from '../types'
2
3
  import type { Exec } from '../workspace/git-worktree'
3
4
  import { isValidGitBranchName } from '../../kernel/origin'
@@ -16,7 +17,18 @@ function branchRef(branch: string): string {
16
17
  * never consults a remote, even when the repository happens to have one. */
17
18
  export function gitRewrite(exec: Exec, local: boolean): ForgeRewrite {
18
19
  async function git(cwd: string, args: string[], allowFailure = false) {
19
- const result = await exec(['git', ...args], { cwd })
20
+ const network = !local && ['push', 'fetch', 'ls-remote'].includes(args[0] ?? '')
21
+ let result: Awaited<ReturnType<Exec>>
22
+ try {
23
+ result = await exec(['git', ...args], { cwd })
24
+ } catch (error) {
25
+ throw network ? classifyGitNetworkFailure(error) : error
26
+ }
27
+ if (network && result.exitCode !== 0) {
28
+ const original = new Error(result.stderr || result.stdout)
29
+ const classified = classifyGitNetworkFailure(original)
30
+ if (classified !== original) throw classified
31
+ }
20
32
  if (!allowFailure && result.exitCode !== 0)
21
33
  throw new Error(
22
34
  `reconcile git ${args.join(' ')} failed: ${result.stderr || result.stdout}; enable refs/autobuild/archive/ publication and guarded build-branch rewrites`,
@@ -224,7 +236,18 @@ export async function refreshBranchCache(
224
236
  object(sha)
225
237
  if (!isValidGitBranchName(branch)) throw new Error('invalid publication branch')
226
238
  const run = async (args: string[]) => {
227
- const result = await exec(['git', ...args], { cwd })
239
+ const network = ['push', 'fetch', 'ls-remote'].includes(args[0] ?? '')
240
+ let result: Awaited<ReturnType<Exec>>
241
+ try {
242
+ result = await exec(['git', ...args], { cwd })
243
+ } catch (error) {
244
+ throw network ? classifyGitNetworkFailure(error) : error
245
+ }
246
+ if (network && result.exitCode !== 0) {
247
+ const original = new Error(result.stderr || result.stdout)
248
+ const classified = classifyGitNetworkFailure(original)
249
+ if (classified !== original) throw classified
250
+ }
228
251
  if (result.exitCode !== 0)
229
252
  throw new Error(`publication cache ${args.join(' ')} failed: ${result.stderr}`)
230
253
  }
@@ -404,8 +404,8 @@ export async function inspectGitHubReadiness(opts: {
404
404
  'root-freshness',
405
405
  rootFence ? 'pass' : 'fail',
406
406
  rootFence
407
- ? `Root ${opts.input.rootBranch} enforces strict nonempty checks for all actors: fenced landing.`
408
- : `Root ${opts.input.rootBranch} does not enforce strict nonempty checks for all actors: best-effort landing.`,
407
+ ? `Root ${opts.input.rootBranch} enforces strict nonempty checks for all actors: fenced merge.`
408
+ : `Root ${opts.input.rootBranch} does not enforce strict nonempty checks for all actors: best-effort merge.`,
409
409
  )
410
410
  } catch {
411
411
  /* No vacuous success on incomplete target or policy reads. */
@@ -1,5 +1,10 @@
1
1
  import { AsyncLocalStorage } from 'node:async_hooks'
2
- import { isForgeFailure, type ForgeRequestObserver } from '../forge-failure'
2
+ import {
3
+ classifyGitNetworkFailure,
4
+ ForgeFailure,
5
+ isForgeFailure,
6
+ type ForgeRequestObserver,
7
+ } from '../forge-failure'
3
8
  import {
4
9
  forgeRequestContext,
5
10
  guardedForgeRequest,
@@ -621,9 +626,23 @@ export class GitHubForge implements Forge {
621
626
  GIT_CONFIG_VALUE_6: '',
622
627
  },
623
628
  })
624
- return { ...result, stdout: redact(result.stdout), stderr: redact(result.stderr) }
629
+ const safe = { ...result, stdout: redact(result.stdout), stderr: redact(result.stderr) }
630
+ if (
631
+ result.exitCode !== 0 &&
632
+ cmd.some((arg) => ['push', 'fetch', 'ls-remote'].includes(arg))
633
+ ) {
634
+ const original = new Error(safe.stderr || safe.stdout)
635
+ const classified = classifyGitNetworkFailure(original)
636
+ if (classified !== original) throw classified
637
+ }
638
+ return safe
625
639
  } catch (error) {
626
- if (isForgeFailure(error) || error instanceof ForgeRequestDeferred) throw error
640
+ if (error instanceof ForgeRequestDeferred) throw error
641
+ const classified = cmd.some((arg) => ['push', 'fetch', 'ls-remote'].includes(arg))
642
+ ? classifyGitNetworkFailure(error)
643
+ : error
644
+ if (isForgeFailure(classified))
645
+ throw new ForgeFailure(redact(classified.message), classified.details)
627
646
  throw new Error(redact(error instanceof Error ? error.message : String(error)))
628
647
  }
629
648
  }
@@ -1227,7 +1246,7 @@ export class GitHubForge implements Forge {
1227
1246
  base: z.object({ ref: z.string() }),
1228
1247
  head: z.object({ ref: z.string(), sha: z.string() }),
1229
1248
  })
1230
- const pr = this.parse(schema, response, `node landing PR #${number}`)
1249
+ const pr = this.parse(schema, response, `node merge PR #${number}`)
1231
1250
  return {
1232
1251
  base: pr.base.ref,
1233
1252
  head: pr.head.ref,
@@ -1387,7 +1406,7 @@ export class GitHubForge implements Forge {
1387
1406
  }
1388
1407
  if (requireIdentity && parsed.some((rule) => rule.type === 'merge_queue')) {
1389
1408
  return unproven(
1390
- 'GitHub merge queues ignore squash message overrides; land through a human or change the queue policy to preserve Autobuild-Build identity',
1409
+ 'GitHub merge queues ignore squash message overrides; merge through a human or change the queue policy to preserve Autobuild-Build identity',
1391
1410
  )
1392
1411
  }
1393
1412
  rulesetGate =
@@ -1671,7 +1690,7 @@ export class GitHubForge implements Forge {
1671
1690
  }
1672
1691
  if (data.repository.mergeQueue !== null) {
1673
1692
  throw new Error(
1674
- 'GitHub merge queues ignore squash message overrides; land through a human or change the queue policy to preserve Autobuild-Build identity',
1693
+ 'GitHub merge queues ignore squash message overrides; merge through a human or change the queue policy to preserve Autobuild-Build identity',
1675
1694
  )
1676
1695
  }
1677
1696
  return message
@@ -1756,7 +1775,7 @@ export class GitHubForge implements Forge {
1756
1775
  const view = await this.getJson(
1757
1776
  z.object({ commit: z.object({ message: z.string() }) }),
1758
1777
  `repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}/commits/${encodeURIComponent(sha)}`,
1759
- 'landed commit message',
1778
+ 'merged commit message',
1760
1779
  )
1761
1780
  return view.commit.message
1762
1781
  }
@@ -357,7 +357,7 @@ export class LocalGitForge implements Forge {
357
357
  )
358
358
  if (result.exitCode === 0) return true
359
359
  if (result.exitCode === 1) return false
360
- throw new Error(`local-git could not compare landing ancestry: ${result.stderr.trim()}`)
360
+ throw new Error(`local-git could not compare merge ancestry: ${result.stderr.trim()}`)
361
361
  }
362
362
 
363
363
  /** Apply Git's two-tree fast-forward operation. It carries index/worktree
@@ -402,7 +402,7 @@ export class LocalGitForge implements Forge {
402
402
  throw new Error(`PR #${number} is no longer open`)
403
403
  await this.updateRecord(workspacePath, number, (current) => {
404
404
  if (current.status !== 'open' || current.pendingLanding)
405
- throw new Error(`PR #${number} is landing or terminal`)
405
+ throw new Error(`PR #${number} is merging or terminal`)
406
406
  return { ...current, base }
407
407
  })
408
408
  if ((await this.inspectLandingPr(workspacePath, number)).base !== base)
@@ -412,7 +412,7 @@ export class LocalGitForge implements Forge {
412
412
  async inspectLandingPr(workspacePath: string, number: number) {
413
413
  const { record } = await this.readRecord(workspacePath, number)
414
414
  if (record.status === 'merged' && !record.mergedHeadSha)
415
- throw new Error('historical local-git landing has no frozen source head')
415
+ throw new Error('historical local-git merge has no frozen source head')
416
416
  return {
417
417
  base: record.base,
418
418
  head: record.head,
@@ -697,7 +697,7 @@ export class LocalGitForge implements Forge {
697
697
  true,
698
698
  )
699
699
  if (moved.exitCode !== 0) {
700
- throw new Error(`local-git base ${baseRef} moved before squash landing`)
700
+ throw new Error(`local-git base ${baseRef} moved before squash merge`)
701
701
  }
702
702
  if (checkout !== undefined) {
703
703
  // A racing operator edit can still appear after preflight. Never roll the
@@ -40,7 +40,7 @@ const inventory: readonly [ReadinessKey, string][] = [
40
40
  ['linear-history', 'Enable Require linear history on protected root and node target branches.'],
41
41
  [
42
42
  'root-freshness',
43
- 'Require branches to be up to date before merging on the root, with nonempty required checks enforced for all actors; otherwise root landing is best-effort rather than fenced.',
43
+ 'Require branches to be up to date before merging on the root, with nonempty required checks enforced for all actors; otherwise root merge is best-effort rather than fenced.',
44
44
  ],
45
45
  ]
46
46
  export function readinessChecks(
@@ -39,3 +39,27 @@ export interface ForgeRequestContext {
39
39
  }
40
40
  /** Called once for each actual provider request, including failed requests. */
41
41
  export type ForgeRequestObserver = (context: ForgeRequestContext) => void
42
+
43
+ /** Git's network diagnostics have no structured HTTP response. Keep this
44
+ * deliberately narrow: policy refusals and local validation never qualify. */
45
+ export function classifyGitNetworkFailure(error: unknown): unknown {
46
+ if (isForgeFailure(error)) return error
47
+ const message = error instanceof Error ? error.message : String(error)
48
+ if (
49
+ /\b(?:401|403|429)\b|authentication failed|permission denied|\[rejected\]|stale info|non-fast-forward/i.test(
50
+ message,
51
+ )
52
+ )
53
+ return error
54
+ const code = error && typeof error === 'object' && 'code' in error ? error.code : undefined
55
+ if (
56
+ ['ECONNRESET', 'ETIMEDOUT', 'ESOCKETTIMEDOUT', 'UND_ERR_CONNECT_TIMEOUT'].includes(
57
+ String(code),
58
+ ) ||
59
+ /\b(?:HTTP(?:\/\S+)?\s+|returned error:\s*|HTTP code[ =]+)5\d\d\b|\bService Unavailable\b|connection reset|ECONNRESET|ETIMEDOUT|connection timed out|operation timed out|request timed out/i.test(
60
+ message,
61
+ )
62
+ )
63
+ return new ForgeFailure(message, { kind: 'transient', retry: 'retryable' })
64
+ return error
65
+ }
@@ -102,7 +102,9 @@ export interface BuildExecutionHandle {
102
102
  }
103
103
 
104
104
  /** Provider liveness observation of one recorded execution, derived from
105
- * provider state rather than process memory. `ended` carries the observed
105
+ * provider state rather than process memory. Terminal observations also confirm
106
+ * that the whole execution environment has stopped, including descendants.
107
+ * A command exit without confirmed teardown is not terminal. `ended` carries the observed
106
108
  * exit code; `lost` means the provider proved the environment/command no
107
109
  * longer exists without an exit code. */
108
110
  export type ExecutionObservation =
@@ -74,17 +74,18 @@ export function allocateScratchPath(
74
74
  desired: string,
75
75
  tracked: ReadonlySet<string>,
76
76
  allocated: Set<string>,
77
+ prefix = PHASE_SCRATCH_PREFIX,
77
78
  ): string {
78
79
  const unavailable = new Set([...tracked, ...allocated])
79
- const conventional = `${PHASE_SCRATCH_PREFIX}${desired}`
80
+ const conventional = `${prefix}${desired}`
80
81
  if (!collides(conventional, unavailable)) {
81
82
  allocated.add(conventional)
82
83
  return desired
83
84
  }
84
85
  for (let index = 1; ; index += 1) {
85
86
  const candidate = `generated/${index}/${desired}`
86
- if (!collides(`${PHASE_SCRATCH_PREFIX}${candidate}`, unavailable)) {
87
- allocated.add(`${PHASE_SCRATCH_PREFIX}${candidate}`)
87
+ if (!collides(`${prefix}${candidate}`, unavailable)) {
88
+ allocated.add(`${prefix}${candidate}`)
88
89
  return candidate
89
90
  }
90
91
  }
@@ -1932,17 +1932,10 @@ export class VercelSandboxProvider implements WorkspaceProvider {
1932
1932
  return this.environmentSupervisedHandle(name, sandbox, command)
1933
1933
  }
1934
1934
 
1935
- /** Liveness of a previously recorded execution, from provider state alone:
1936
- * one bounded facade.get, one command lookup, and, when the lookup shows no
1937
- * exit, one bounded wait on that command. A missing sandbox, a session that
1938
- * is no longer running, or a command the current (resumed) session no
1939
- * longer knows is `lost`; a non-null exit code — from the lookup or from
1940
- * the bounded wait it triggered — is `ended`; an interrupted or timed-out
1941
- * wait leaves the execution `running`. The lifetime bound (session expiry
1942
- * plus the shared stop/snapshot margin) runs before the lookup and fails
1943
- * with the environment named instead of waiting. Unknown provider errors
1944
- * propagate — callers treat an unresolvable observation as running and
1945
- * never reap on it. */
1935
+ /** Observe a recovered execution and confirm whole-environment teardown
1936
+ * before exposing a terminal observation. Command exit alone does not prove
1937
+ * descendants have stopped writing to the shared workspace. Stop failures
1938
+ * propagate so settlement retains the execution and lease and retries. */
1946
1939
  private async observeExecution(identity: BuildExecutionIdentity): Promise<ExecutionObservation> {
1947
1940
  if (identity.commandId === undefined) {
1948
1941
  throw new Error(
@@ -1951,13 +1944,40 @@ export class VercelSandboxProvider implements WorkspaceProvider {
1951
1944
  }
1952
1945
  const sandbox = await this.facade.get(identity.workspaceRef, this.operationSignal())
1953
1946
  if (sandbox === null) return { state: 'lost' }
1954
- if (sandbox.sessionStatus !== undefined && sandbox.sessionStatus !== 'running') {
1947
+ const settled = async (observation: ExecutionObservation): Promise<ExecutionObservation> => {
1948
+ try {
1949
+ await sandbox.stop({ signal: this.operationSignal() })
1950
+ } catch (error) {
1951
+ if (!isMissingVercelSandbox(error)) {
1952
+ this.uncertain.add(identity.workspaceRef)
1953
+ this.sessions.delete(identity.workspaceRef)
1954
+ throw error
1955
+ }
1956
+ }
1957
+ this.active.delete(identity.workspaceRef)
1958
+ this.uncertain.delete(identity.workspaceRef)
1959
+ this.sessions.delete(identity.workspaceRef)
1960
+ return observation
1961
+ }
1962
+ const currentSession = sandbox.currentSession?.().sessionId
1963
+ if (
1964
+ identity.sessionId !== undefined &&
1965
+ currentSession !== undefined &&
1966
+ currentSession !== identity.sessionId
1967
+ )
1968
+ return { state: 'lost' }
1969
+ // Terminal provider status proves the recorded incarnation is stopped.
1970
+ // Never stop a newer resumed session or demand a second stop of one that
1971
+ // the provider already confirms stopped.
1972
+ if (
1973
+ sandbox.sessionStatus === 'stopped' ||
1974
+ sandbox.sessionStatus === 'aborted' ||
1975
+ sandbox.sessionStatus === 'failed'
1976
+ )
1955
1977
  return { state: 'lost' }
1978
+ if (sandbox.sessionStatus !== undefined && sandbox.sessionStatus !== 'running') {
1979
+ return settled({ state: 'lost' })
1956
1980
  }
1957
- // Mirrors the command path's VM-lifetime bound: past the environment's
1958
- // session expiry (plus the shared stop/snapshot margin) the execution
1959
- // cannot still be running, so re-issuing the long-poll would only end in
1960
- // a generic transport failure. Fail with the environment named instead.
1961
1981
  if (sandbox.sessionExpiresAt !== undefined) {
1962
1982
  const deadline = sandbox.sessionExpiresAt + VERCEL_LIFETIME_MARGIN_MS
1963
1983
  if (Date.now() > deadline) {
@@ -1968,36 +1988,36 @@ export class VercelSandboxProvider implements WorkspaceProvider {
1968
1988
  )
1969
1989
  }
1970
1990
  }
1991
+ let observation: ExecutionObservation
1971
1992
  try {
1972
1993
  const command = await sandbox.getCommand(identity.commandId, {
1973
1994
  signal: this.operationSignal(),
1974
1995
  })
1975
- if (command.exitCode !== null) return { state: 'ended', exitCode: command.exitCode }
1976
- // The provider's plain lookup reports no exit code for a command that
1977
- // finished while no client was waiting on it, and keeps reporting none
1978
- // until some client waits — so "null" alone proves nothing. One bounded
1979
- // wait turns it into evidence: a resolved wait is a proved end, an
1980
- // interrupted or timed-out wait leaves the guest unobserved (`running`),
1981
- // and a missing sandbox is `lost`. Never re-issued here; the next tick
1982
- // retries. The bound composes the provider operation signal so one
1983
- // observation never approaches the tick's operation timeout.
1984
- try {
1985
- const finished = await command.wait({
1986
- signal: AbortSignal.any([
1987
- AbortSignal.timeout(this.observeWaitMs),
1988
- this.operationSignal(),
1989
- ]),
1990
- })
1991
- return { state: 'ended', exitCode: finished.exitCode }
1992
- } catch (error) {
1993
- if (isMissingVercelSandbox(error)) return { state: 'lost' }
1994
- if (isInterruptedLongPoll(error)) return { state: 'running' }
1995
- throw error
1996
+ if (command.exitCode !== null) {
1997
+ observation = { state: 'ended', exitCode: command.exitCode }
1998
+ } else {
1999
+ try {
2000
+ const finished = await command.wait({
2001
+ signal: AbortSignal.any([
2002
+ AbortSignal.timeout(this.observeWaitMs),
2003
+ this.operationSignal(),
2004
+ ]),
2005
+ })
2006
+ observation = { state: 'ended', exitCode: finished.exitCode }
2007
+ } catch (error) {
2008
+ if (isMissingVercelSandbox(error)) observation = { state: 'lost' }
2009
+ else if (isInterruptedLongPoll(error)) return { state: 'running' }
2010
+ else throw error
2011
+ }
1996
2012
  }
1997
2013
  } catch (error) {
1998
- if (isMissingVercelSandbox(error)) return { state: 'lost' }
1999
- throw error
2014
+ if (isMissingVercelSandbox(error)) observation = { state: 'lost' }
2015
+ else throw error
2000
2016
  }
2017
+ // Deliberately outside the lookup/wait catch: an ambiguous stop must not
2018
+ // become proof of loss or command exit, even when its error resembles a
2019
+ // transport interruption.
2020
+ return settled(observation)
2001
2021
  }
2002
2022
 
2003
2023
  // ── Operator sandbox capability (AUT-340) ─────────────────────────
@@ -1,3 +1,5 @@
1
+ import { composeBuildConfig } from '../config/live'
2
+ import { readVerifyPipeline } from '../config/pipeline-source'
1
3
  import { guardForge } from '../kernel/guarded-forge'
2
4
  import { isRemoteWorkspace } from '../events/workspace-remote'
3
5
  import { readBuildFacts } from '../store/reduced-reads'
@@ -13,7 +15,6 @@ import { openProductionStore } from '../cli/store-opening'
13
15
  import { BuildRunner, LeaseHeldError, SetupFailureError } from './build-runner'
14
16
  import {
15
17
  BUILD_EFFECTIVE_CONFIG_ARTIFACT,
16
- buildOwnedSectionsDiffer,
17
18
  diagnosticArtifact,
18
19
  parseEffectiveBuildConfig,
19
20
  type BuildRunnerDiagnosticOutcome,
@@ -80,13 +81,9 @@ export async function runBuildChild(
80
81
  if (latest === null) return currentConfig
81
82
  try {
82
83
  const parsed = parseEffectiveBuildConfig(latest)
83
- // Defensive guard (SPEC §16.1): after pinning, a boundary deposit may
84
- // move deployment-owned sections only. If build-owned sections change
85
- // without the build's own branch advancing, the artifact was written
86
- // by something other than a launch — keep the last valid boundary.
87
- if (!buildOwnedSectionsDiffer(currentConfig, parsed)) {
88
- currentConfig = parsed
89
- }
84
+ // Deployment reloads may race a runner capture. The runner resolves
85
+ // build-owned sections through the capture's immutable revision.
86
+ currentConfig = composeBuildConfig(currentConfig, parsed)
90
87
  } catch {
91
88
  // The dispatcher publishes only validated snapshots. If storage is
92
89
  // externally corrupted, preserve the child's last valid boundary.
@@ -98,6 +95,7 @@ export async function runBuildChild(
98
95
  store,
99
96
  config: currentConfig,
100
97
  getConfig,
98
+ readVerifyPipeline: () => readVerifyPipeline(workspace.path ?? workspace.ref, spawnExec),
101
99
  runtimes,
102
100
  workspacePath: workspace.path ?? workspace.ref,
103
101
  workspaceProvider: workspace.provider,
@@ -1,3 +1,4 @@
1
+ import { normalizeEffectiveConfigArtifact } from '../config/effective-artifact'
1
2
  import type { Config } from '../config/schema'
2
3
  import { configSchema } from '../config/schema'
3
4
  import { BUILD_OWNED_CONFIG_PATHS } from '../config/live'
@@ -22,7 +23,11 @@ export function effectiveBuildConfigContent(config: Config): string {
22
23
  const { verify, finalize, ...root } = config
23
24
  return JSON.stringify({
24
25
  ...root,
25
- verify: { steps: verify.steps, afterReconcile: verify.afterReconcile, ...verify.stepConfigs },
26
+ verify: {
27
+ steps: verify.stages ?? verify.steps,
28
+ afterReconcile: verify.afterReconcile,
29
+ ...verify.stepConfigs,
30
+ },
26
31
  finalize: { steps: finalize.steps, ...finalize.stepConfigs },
27
32
  })
28
33
  }
@@ -38,7 +43,7 @@ export function parseEffectiveBuildConfig(artifact: Artifact): Config {
38
43
  }`,
39
44
  )
40
45
  }
41
- const result = configSchema.safeParse(value)
46
+ const result = configSchema.safeParse(normalizeEffectiveConfigArtifact(value))
42
47
  if (!result.success) {
43
48
  throw new Error(
44
49
  `invalid ${BUILD_EFFECTIVE_CONFIG_ARTIFACT}: ${result.error.issues
@@ -75,9 +80,7 @@ export function parseBuildConfigMetadata(artifact: Artifact): {
75
80
  }
76
81
  }
77
82
 
78
- /** True when two configs' build-owned sections differ — the guest's defensive
79
- * guard against a deposit that rewrites the pinned pipeline without a recorded
80
- * pipeline-source commit advance. */
83
+ /** Compare only build-owned sections, independently of live deployment settings. */
81
84
  export function buildOwnedSectionsDiffer(a: Config, b: Config): boolean {
82
85
  return BUILD_OWNED_CONFIG_PATHS.some(
83
86
  (path) => JSON.stringify(a[path]) !== JSON.stringify(b[path]),