@defrex/autobuild 1.0.0-beta.3 → 1.0.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 (168) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +362 -56
  3. package/bin/ab-dispatch-generation.ts +93 -0
  4. package/docs/agent-runtimes.md +157 -0
  5. package/docs/answering-blocked-builds.md +21 -3
  6. package/docs/architecture.md +166 -7
  7. package/docs/build-store.md +123 -0
  8. package/docs/builds.md +82 -0
  9. package/docs/cli.md +48 -0
  10. package/docs/configuration-overview.md +93 -0
  11. package/docs/configuration.md +1778 -188
  12. package/docs/dispatcher-hosting.md +115 -0
  13. package/docs/dispatcher.md +59 -0
  14. package/docs/forges.md +121 -0
  15. package/docs/getting-started.md +60 -0
  16. package/docs/glossary.md +60 -0
  17. package/docs/hosted-service.md +2 -2
  18. package/docs/intake.md +48 -0
  19. package/docs/integration-overview.md +81 -0
  20. package/docs/integration-tree.md +87 -2
  21. package/docs/integration.md +54 -0
  22. package/docs/operating.md +114 -0
  23. package/docs/operator-api.md +64 -11
  24. package/docs/operator-surfaces.md +90 -0
  25. package/docs/overview.md +49 -0
  26. package/docs/plugin-authoring.md +426 -0
  27. package/docs/remote-store-protocol.md +12 -9
  28. package/docs/restacking.md +4 -1
  29. package/docs/seams.md +66 -0
  30. package/docs/setup.md +28 -6
  31. package/docs/skills.md +119 -0
  32. package/docs/spec-standard.md +23 -5
  33. package/docs/ticket-sources.md +132 -0
  34. package/docs/tickets.md +69 -0
  35. package/docs/troubleshooting.md +111 -0
  36. package/docs/upgrading.md +50 -0
  37. package/docs/verification.md +146 -0
  38. package/docs/website.md +47 -5
  39. package/docs/workspaces.md +152 -0
  40. package/package.json +5 -4
  41. package/packages/core/src/cli/artifact.ts +5 -4
  42. package/packages/core/src/cli/attention.ts +2 -0
  43. package/packages/core/src/cli/binary-direct.ts +190 -0
  44. package/packages/core/src/cli/binary-lifecycle.ts +46 -0
  45. package/packages/core/src/cli/binary.ts +24 -210
  46. package/packages/core/src/cli/build-control.ts +105 -2
  47. package/packages/core/src/cli/context.ts +41 -1
  48. package/packages/core/src/cli/dashboard/hand-pushed.ts +24 -0
  49. package/packages/core/src/cli/dashboard/handoff.ts +64 -0
  50. package/packages/core/src/cli/dashboard/integration-detail.ts +3 -0
  51. package/packages/core/src/cli/dashboard/model.ts +34 -10
  52. package/packages/core/src/cli/dashboard/render.ts +24 -2
  53. package/packages/core/src/cli/dashboard/rollback.ts +30 -0
  54. package/packages/core/src/cli/dispatch-args.ts +53 -0
  55. package/packages/core/src/cli/dispatch-crash-budget.ts +15 -0
  56. package/packages/core/src/cli/dispatch-frontend.ts +52 -5
  57. package/packages/core/src/cli/dispatch-handoff.ts +276 -0
  58. package/packages/core/src/cli/dispatch-launch-contract.ts +170 -0
  59. package/packages/core/src/cli/dispatch-launcher.ts +580 -0
  60. package/packages/core/src/cli/dispatch-parent-watch.ts +44 -0
  61. package/packages/core/src/cli/dispatch-preflight.ts +272 -0
  62. package/packages/core/src/cli/dispatch-presentation-job.ts +46 -0
  63. package/packages/core/src/cli/dispatch-presentation-ownership.ts +9 -0
  64. package/packages/core/src/cli/dispatch-process.ts +22 -90
  65. package/packages/core/src/cli/dispatch-readiness.ts +47 -0
  66. package/packages/core/src/cli/dispatch-repository-feed.ts +5 -1
  67. package/packages/core/src/cli/dispatch-runtime-cache.ts +522 -0
  68. package/packages/core/src/cli/dispatch-runtime-dependencies.ts +291 -0
  69. package/packages/core/src/cli/dispatch-runtime-use.ts +336 -0
  70. package/packages/core/src/cli/dispatch-upgrade-controller.ts +221 -0
  71. package/packages/core/src/cli/dispatch-upgrade-install.ts +258 -0
  72. package/packages/core/src/cli/dispatch-upgrade-source.ts +309 -0
  73. package/packages/core/src/cli/dispatch-upgrade-target.ts +190 -0
  74. package/packages/core/src/cli/dispatch.ts +604 -60
  75. package/packages/core/src/cli/dispatcher-liveness.ts +1 -1
  76. package/packages/core/src/cli/env.ts +1 -1
  77. package/packages/core/src/cli/harvest.ts +28 -11
  78. package/packages/core/src/cli/help.ts +10 -5
  79. package/packages/core/src/cli/installation.ts +5 -3
  80. package/packages/core/src/cli/main-checkout.ts +59 -0
  81. package/packages/core/src/cli/main.ts +15 -45
  82. package/packages/core/src/cli/node-verification-provenance.ts +97 -0
  83. package/packages/core/src/cli/repo-state.ts +3 -58
  84. package/packages/core/src/cli/repository-status.ts +67 -3
  85. package/packages/core/src/cli/runtime-spawn.ts +16 -0
  86. package/packages/core/src/cli/status.ts +57 -3
  87. package/packages/core/src/cli/upgrade-followup.ts +25 -0
  88. package/packages/core/src/cli/wait.ts +3 -0
  89. package/packages/core/src/cli/watch.ts +7 -0
  90. package/packages/core/src/config/landing.ts +8 -0
  91. package/packages/core/src/config/live.ts +1 -0
  92. package/packages/core/src/config/reference-metadata.ts +31 -0
  93. package/packages/core/src/config/reference.ts +342 -0
  94. package/packages/core/src/config/roles.ts +1 -1
  95. package/packages/core/src/config/schema.ts +352 -10
  96. package/packages/core/src/distribution-packaging.ts +116 -0
  97. package/packages/core/src/events/catalog.ts +6 -0
  98. package/packages/core/src/events/payloads.ts +53 -9
  99. package/packages/core/src/events/policy.ts +25 -0
  100. package/packages/core/src/events/repository.ts +184 -4
  101. package/packages/core/src/events/runtime.ts +16 -0
  102. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +2515 -78
  103. package/packages/core/src/kernel/dispatch-drain-recovery.ts +121 -0
  104. package/packages/core/src/kernel/dispatch-status.ts +4 -2
  105. package/packages/core/src/kernel/dispatch-upgrade.ts +171 -0
  106. package/packages/core/src/kernel/dispatcher-liveness.ts +7 -0
  107. package/packages/core/src/kernel/generators/repository-journals.ts +82 -0
  108. package/packages/core/src/kernel/guarded-forge.ts +1 -1
  109. package/packages/core/src/kernel/harvest.ts +98 -4
  110. package/packages/core/src/kernel/integration-attention.ts +20 -0
  111. package/packages/core/src/kernel/integration-state.ts +80 -11
  112. package/packages/core/src/kernel/landing-readiness.ts +6 -1
  113. package/packages/core/src/kernel/mixed-version.ts +34 -0
  114. package/packages/core/src/kernel/node-polling.ts +160 -0
  115. package/packages/core/src/kernel/read-facts.ts +40 -5
  116. package/packages/core/src/kernel/reducer-registry.ts +3 -0
  117. package/packages/core/src/kernel/reducer.ts +75 -14
  118. package/packages/core/src/kernel/service-facts.ts +11 -4
  119. package/packages/core/src/ontology.ts +2 -2
  120. package/packages/core/src/open-map.ts +3 -1
  121. package/packages/core/src/operator/presentation.ts +7 -0
  122. package/packages/core/src/operator/query.ts +6 -2
  123. package/packages/core/src/operator/registry.ts +1 -1
  124. package/packages/core/src/plugins/load.ts +4 -1
  125. package/packages/core/src/plugins/runtime-snapshot.ts +128 -0
  126. package/packages/core/src/ports/forge/contract.ts +29 -0
  127. package/packages/core/src/ports/forge/github.ts +189 -61
  128. package/packages/core/src/ports/forge-failure.ts +1 -0
  129. package/packages/core/src/ports/forge-telemetry.ts +3 -0
  130. package/packages/core/src/ports/runner/session-env.ts +1 -0
  131. package/packages/core/src/ports/types.ts +10 -0
  132. package/packages/core/src/ports/workspace/distribution-archive.ts +22 -149
  133. package/packages/core/src/ports/workspace/distribution-release.ts +56 -0
  134. package/packages/core/src/ports/workspace/git-worktree.ts +2 -1
  135. package/packages/core/src/ports/workspace/local-build-execution.ts +37 -17
  136. package/packages/core/src/processes/build-child-exit.ts +5 -26
  137. package/packages/core/src/processes/build-runner.ts +81 -11
  138. package/packages/core/src/processes/dispatcher.ts +254 -23
  139. package/packages/core/src/processes/execution-no-progress.ts +6 -0
  140. package/packages/core/src/processes/execution-relaunch.ts +30 -0
  141. package/packages/core/src/processes/execution-settlement.ts +16 -7
  142. package/packages/core/src/processes/harvest-runner.ts +328 -292
  143. package/packages/core/src/processes/process-group-reaper.ts +17 -10
  144. package/packages/core/src/runtime-identity.ts +22 -3
  145. package/packages/core/src/store/contract.ts +153 -0
  146. package/packages/core/src/store/local/store.ts +197 -72
  147. package/packages/core/src/store/reduced-reads.ts +8 -0
  148. package/packages/core/src/store/reducer-value-shapes.json +5783 -3305
  149. package/packages/core/src/store/remote/client.ts +43 -0
  150. package/packages/core/src/store/repo-state-events.ts +20 -3
  151. package/packages/core/src/store/types.ts +7 -0
  152. package/skills/finalize/SKILL.md +3 -1
  153. package/skills/guide/SKILL.md +273 -48
  154. package/skills/guide/references/integration-tree.md +87 -2
  155. package/skills/guide/references/operator-api.md +71 -14
  156. package/skills/guide/references/plugin-authoring.md +231 -266
  157. package/skills/guide/references/remote-store-protocol.md +12 -9
  158. package/skills/guide/references/restacking.md +4 -1
  159. package/skills/guide/references/setup.md +28 -6
  160. package/skills/guide/references/spec-standard.md +23 -5
  161. package/skills/harvest/SKILL.md +4 -0
  162. package/skills/harvest-review/SKILL.md +4 -0
  163. package/skills/implement/SKILL.md +4 -2
  164. package/skills/operate/SKILL.md +104 -35
  165. package/skills/plan/SKILL.md +12 -4
  166. package/skills/spec/SKILL.md +20 -2
  167. package/skills/tickets/SKILL.md +20 -1
  168. package/templates/hosted-service/package.json +2 -2
@@ -0,0 +1,56 @@
1
+ import { parseRepoCoordinates } from '../forge/github'
2
+ import {
3
+ createGitHubFetchTransport,
4
+ GitHubApiError,
5
+ githubTokenFromEnv,
6
+ type GitHubRequest,
7
+ } from '../forge/github-transport'
8
+ export const CANONICAL_REPOSITORY_URL = 'https://github.com/defrex/autobuild'
9
+ export function distributionAssetName(version: string): string {
10
+ return `autobuild-${version}.tgz`
11
+ }
12
+ /** Fetch the exact version’s published asset through the authenticated transport. */
13
+ export async function fetchDistributionReleaseAsset(
14
+ version: string,
15
+ env: Readonly<Record<string, string | undefined>> = process.env,
16
+ transport: GitHubRequest = createGitHubFetchTransport({
17
+ token: githubTokenFromEnv(env),
18
+ }),
19
+ ): Promise<Uint8Array> {
20
+ const coordinates = parseRepoCoordinates(CANONICAL_REPOSITORY_URL)
21
+ if (coordinates === null) {
22
+ throw new Error(`the canonical repository URL is not parseable: ${CANONICAL_REPOSITORY_URL}`)
23
+ }
24
+ const repo = `repos/${encodeURIComponent(coordinates.owner)}/${encodeURIComponent(coordinates.name)}`
25
+ const tag = `v${version}`
26
+ const release = await transport('GET', `${repo}/releases/tags/${tag}`).catch((error: unknown) => {
27
+ if (error instanceof GitHubApiError && error.status === 404) {
28
+ throw new Error(
29
+ `Autobuild release ${tag} has no published GitHub release; origin-mode dispatch ` +
30
+ 'installs the guest distribution from the release asset autobuild-' +
31
+ `${version}.tgz — cut a release with tools/release.ts first`,
32
+ { cause: error },
33
+ )
34
+ }
35
+ throw error
36
+ })
37
+ const assets = (
38
+ release.json as { assets?: { name?: unknown; browser_download_url?: unknown }[] } | undefined
39
+ )?.assets
40
+ const assetName = distributionAssetName(version)
41
+ const asset = (assets ?? []).find((candidate) => candidate.name === assetName)
42
+ if (asset === undefined || typeof asset.browser_download_url !== 'string') {
43
+ throw new Error(
44
+ `Autobuild release ${tag} does not carry the ${assetName} distribution asset; ` +
45
+ 'origin-mode dispatch cannot install a guest distribution without it — ' +
46
+ 'cut a release with tools/release.ts first',
47
+ )
48
+ }
49
+ const download = await transport('GET', asset.browser_download_url, {
50
+ headers: { Accept: 'application/octet-stream' },
51
+ })
52
+ if (download.bytes === undefined || download.bytes.byteLength === 0) {
53
+ throw new Error(`the ${assetName} release asset downloaded no bytes`)
54
+ }
55
+ return download.bytes
56
+ }
@@ -45,7 +45,7 @@ export const spawnExec: Exec = async (cmd, opts) => {
45
45
  stdin: 'ignore',
46
46
  stdout: 'pipe',
47
47
  stderr: 'pipe',
48
- ...(opts.env === undefined ? {} : { env: { ...process.env, ...opts.env } }),
48
+ env: { ...process.env, ...opts.env, AB_DISPATCH_GENERATION: undefined },
49
49
  ...(opts.signal === undefined ? {} : { signal: opts.signal }),
50
50
  })
51
51
  const [stdout, stderr, exitCode] = await Promise.all([
@@ -555,6 +555,7 @@ export class GitWorktreeProvider implements WorkspaceProvider {
555
555
  }
556
556
  env[name] = value
557
557
  }
558
+ delete env.AB_DISPATCH_GENERATION
558
559
  return env
559
560
  }
560
561
 
@@ -1,3 +1,6 @@
1
+ import { bunRuntimeArguments } from '../../cli/runtime-spawn'
2
+ import { spawnUsingRuntime } from '../../cli/dispatch-runtime-use'
3
+ import { distributionRoot } from '../../distribution'
1
4
  import { distributionPath } from '../../distribution'
2
5
  import {
3
6
  DEFAULT_PROCESS_GROUP_STOP_TIMEOUT_MS,
@@ -41,22 +44,28 @@ export class LocalBuildExecution implements BuildExecution {
41
44
  ): Promise<BuildExecutionHandle> {
42
45
  if (/^https?:/i.test(input.storeRef) && !auth)
43
46
  throw new Error('remote build launch requires delegated authority')
44
- const child = this.spawn([process.execPath, this.entrypoint], {
45
- env: {
46
- ...this.env,
47
- AB_TOKEN: auth?.token,
48
- [BUILD_RUNNER_OPTIONS_ENV]: JSON.stringify({
49
- ...input,
50
- supervision: { kind: 'local-parent', parentPid: process.pid },
47
+ const { child, release } = spawnUsingRuntime(
48
+ distributionRoot(),
49
+ () =>
50
+ this.spawn(bunRuntimeArguments(this.entrypoint), {
51
+ env: {
52
+ ...this.env,
53
+ AB_DISPATCH_GENERATION: undefined,
54
+ AB_TOKEN: auth?.token,
55
+ [BUILD_RUNNER_OPTIONS_ENV]: JSON.stringify({
56
+ ...input,
57
+ supervision: { kind: 'local-parent', parentPid: process.pid },
58
+ }),
59
+ },
60
+ stdin: 'ignore',
61
+ stdout: 'ignore',
62
+ stderr: 'ignore',
63
+ // On POSIX this makes the build child a new session and process-group
64
+ // leader. Every agent tool descendant inherits that group by default.
65
+ detached: true,
51
66
  }),
52
- },
53
- stdin: 'ignore',
54
- stdout: 'ignore',
55
- stderr: 'ignore',
56
- // On POSIX this makes the build child a new session and process-group
57
- // leader. Every agent tool descendant inherits that group by default.
58
- detached: true,
59
- })
67
+ true,
68
+ )
60
69
  let reaping: Promise<void> | undefined
61
70
  const reap = (): Promise<void> =>
62
71
  (reaping ??= terminateProcessGroup(child.pid, this.stopTimeoutMs))
@@ -69,9 +78,20 @@ export class LocalBuildExecution implements BuildExecution {
69
78
  const completion = leaderExit.then(async (exit) => {
70
79
  // A naturally exited leader may leave inherited descendants behind.
71
80
  await reap()
81
+ release()
72
82
  return exit
73
83
  })
74
84
 
85
+ let stopping: Promise<void> | undefined
86
+ const stop = (): Promise<void> =>
87
+ (stopping ??= (async () => {
88
+ // Signal only the leader: provider descendants must survive until the
89
+ // runner has closed streams and recorded native-session suspension.
90
+ if (child.exitCode === null) child.kill('SIGTERM')
91
+ await leaderExit
92
+ await reap()
93
+ })())
94
+
75
95
  return {
76
96
  pid: child.pid,
77
97
  supervision: 'local-parent',
@@ -82,13 +102,13 @@ export class LocalBuildExecution implements BuildExecution {
82
102
  },
83
103
  completion,
84
104
  stop: async () => {
85
- await Promise.all([reap(), leaderExit])
105
+ await stop()
86
106
  return { outcome: 'confirmed' }
87
107
  },
88
108
  // A local execution cannot outlive its parent's teardown: detach is the
89
109
  // same full reap as stop (the kernel reaps local children on teardown).
90
110
  detach: async () => {
91
- await Promise.all([reap(), leaderExit])
111
+ await stop()
92
112
  },
93
113
  }
94
114
  }
@@ -1,4 +1,3 @@
1
- import { DEFAULT_PROCESS_GROUP_STOP_TIMEOUT_MS } from './process-group'
2
1
  import type { ProcessGroupReaperOptions } from './process-group-reaper'
3
2
  import { launchProcessGroupReaper, processGroupReaperOptions } from './process-group-reaper'
4
3
 
@@ -85,42 +84,22 @@ export class BuildChildExitCoordinator {
85
84
  }
86
85
  }
87
86
 
88
- /** Shares the original process-group stop deadline with agent persistence.
89
- * A repeated signal never restarts the deadline or bypasses the first intent. */
87
+ /** Graceful shutdown waits for the runner's durable suspension boundary.
88
+ * Repeated signals preserve the first intent; only the runner calls finish
89
+ * after persistence. Abnormal parent loss still uses finish directly. */
90
90
  export class BuildChildShutdown {
91
91
  private readonly controller = new AbortController()
92
- private deadline: number | undefined
93
92
  private exitCode: number | undefined
94
- private cancel: (() => void) | undefined
95
- constructor(
96
- private readonly terminal: BuildChildExitCoordinator,
97
- private readonly now: () => number = Date.now,
98
- private readonly schedule: (callback: () => void, delay: number) => () => void = (
99
- callback,
100
- delay,
101
- ) => {
102
- const timer = setTimeout(callback, delay)
103
- return () => clearTimeout(timer)
104
- },
105
- ) {}
93
+ constructor(private readonly terminal: BuildChildExitCoordinator) {}
106
94
  get signal(): AbortSignal {
107
95
  return this.controller.signal
108
96
  }
109
97
  request(exitCode: number): void {
110
98
  if (this.controller.signal.aborted) return
111
99
  this.exitCode = exitCode
112
- this.deadline = this.now() + DEFAULT_PROCESS_GROUP_STOP_TIMEOUT_MS
113
- this.cancel = this.schedule(
114
- () => this.finish(exitCode),
115
- DEFAULT_PROCESS_GROUP_STOP_TIMEOUT_MS - 1_000,
116
- )
117
100
  this.controller.abort(new Error('dispatcher shutdown'))
118
101
  }
119
102
  finish(exitCode: number): void {
120
- this.cancel?.()
121
- this.terminal.terminate(
122
- this.exitCode ?? exitCode,
123
- this.deadline === undefined ? undefined : Math.max(0, this.deadline - this.now()),
124
- )
103
+ this.terminal.terminate(this.exitCode ?? exitCode)
125
104
  }
126
105
  }
@@ -1,5 +1,13 @@
1
+ import { reportIntegrationFailures } from '../kernel/integration-attention'
2
+ import type { RuntimeIdentity } from '../events/runtime'
3
+ import { relaunchTarget } from './execution-relaunch'
4
+ import { RUNTIME_IDENTITY } from '../runtime-identity'
1
5
  import { publishExact } from '../kernel/publication'
2
- import { deferMixedVersion, MixedVersionDeferral } from '../kernel/mixed-version'
6
+ import {
7
+ deferMixedVersion,
8
+ MixedVersionDeferral,
9
+ withDrainingExecution,
10
+ } from '../kernel/mixed-version'
3
11
  import { hostname } from 'node:os'
4
12
  import { resumeAgent } from '../ports/runner/native-session'
5
13
  import type { AgentStartOpts } from '../ports/types'
@@ -185,6 +193,8 @@ export interface BuildRunnerDeps {
185
193
  /** Runtime registry: name → adapter + compatibility data (§9). The resolver
186
194
  * applies `config.roles`, including its reserved `default` entry, to it. */
187
195
  runtimes: RuntimeRegistry
196
+ /** Immutable identity of this execution distribution; defaults to the loaded runtime. */
197
+ runtimeIdentity?: RuntimeIdentity
188
198
  workspacePath: string
189
199
  /** Explicit provider eligibility; never inferred from a matching path. */
190
200
  workspaceProvider?: string
@@ -828,6 +838,14 @@ export class BuildRunner {
828
838
  private boundaryResolver: RuntimeResolver
829
839
 
830
840
  constructor(private readonly deps: BuildRunnerDeps) {
841
+ this.deps = {
842
+ ...deps,
843
+ store: withDrainingExecution(
844
+ deps.store,
845
+ deps.instance,
846
+ deps.runtimeIdentity ?? RUNTIME_IDENTITY,
847
+ ),
848
+ }
831
849
  this.maxPhaseAttempts = deps.opts?.maxPhaseAttempts ?? 2
832
850
  this.heartbeatMs = deps.opts?.heartbeatMs ?? 15_000
833
851
  this.leaseTtlMs = deps.opts?.leaseTtlMs ?? BUILD_EXECUTION_LEASE_TTL_MS
@@ -935,7 +953,7 @@ export class BuildRunner {
935
953
  },
936
954
  } satisfies EventWrite<'session.ended'>)
937
955
  }
938
- await store.append(slug, {
956
+ const attached = await store.append(slug, {
939
957
  actor: KERNEL,
940
958
  type: 'runner.attached',
941
959
  payload: {
@@ -944,6 +962,15 @@ export class BuildRunner {
944
962
  ...(resumedFromSeq > 0 ? { resumedFromSeq } : {}),
945
963
  },
946
964
  } satisfies EventWrite<'runner.attached'>)
965
+ await store.append(slug, {
966
+ actor: KERNEL,
967
+ type: 'runner.runtime-recorded',
968
+ payload: {
969
+ instance,
970
+ attachedSeq: attached.seq,
971
+ runtime: this.deps.runtimeIdentity ?? RUNTIME_IDENTITY,
972
+ },
973
+ })
947
974
  }
948
975
 
949
976
  /**
@@ -1165,9 +1192,11 @@ export class BuildRunner {
1165
1192
  return decision
1166
1193
  case 'run-check':
1167
1194
  await this.runCheck(decision)
1195
+ await reportIntegrationFailures(this.deps.store, this.deps.slug)
1168
1196
  return decision
1169
1197
  case 'run-agent-verify':
1170
1198
  await this.runAgentVerify(decision)
1199
+ await reportIntegrationFailures(this.deps.store, this.deps.slug)
1171
1200
  return decision
1172
1201
  case 'evaluate-verify':
1173
1202
  await this.evaluateVerify(decision)
@@ -1190,6 +1219,31 @@ export class BuildRunner {
1190
1219
  }
1191
1220
  }
1192
1221
 
1222
+ private async requestRelaunch(
1223
+ facts: Awaited<ReturnType<typeof readBuildFacts>>['value'],
1224
+ ): Promise<boolean> {
1225
+ const request = relaunchTarget(
1226
+ facts.state,
1227
+ this.deps.instance,
1228
+ this.deps.runtimeIdentity ?? RUNTIME_IDENTITY,
1229
+ )
1230
+ if (!request) return false
1231
+ if (
1232
+ facts.state.drainingExecutions?.[this.deps.instance]?.relaunch?.correlation ===
1233
+ request.correlation
1234
+ )
1235
+ return true
1236
+ const written = await this.deps.store.appendIfCurrent(this.deps.slug, facts.state.lastSeq, {
1237
+ actor: KERNEL,
1238
+ type: 'execution.relaunch-requested',
1239
+ payload: request,
1240
+ })
1241
+ // A concurrent control or authorization must be re-read before deciding.
1242
+ if (!written)
1243
+ return this.requestRelaunch((await readBuildFacts(this.deps.store, this.deps.slug)).value)
1244
+ return true
1245
+ }
1246
+
1193
1247
  /**
1194
1248
  * The pipeline loop (§8): attach if needed, step until the build parks
1195
1249
  * (`wait/*` — §11), return the final reduced state. Releases nothing on
@@ -1198,9 +1252,14 @@ export class BuildRunner {
1198
1252
  * already deposited — see module doc).
1199
1253
  */
1200
1254
  async run(): Promise<BuildState> {
1255
+ const initialFacts = (await readBuildFacts(this.deps.store, this.deps.slug)).value
1256
+ if (await this.requestRelaunch(initialFacts)) {
1257
+ this.stopHeartbeat()
1258
+ await this.closeProducerSessions()
1259
+ return (await readBuildFacts(this.deps.store, this.deps.slug)).value.state
1260
+ }
1201
1261
  if (await deferMixedVersion(this.deps.store, this.deps.slug, KERNEL))
1202
1262
  return (await readBuildFacts(this.deps.store, this.deps.slug)).value.state
1203
- const initialFacts = (await readBuildFacts(this.deps.store, this.deps.slug)).value
1204
1263
  const initial = initialFacts.state
1205
1264
  if (
1206
1265
  initial.kind === 'node' &&
@@ -1220,14 +1279,14 @@ export class BuildRunner {
1220
1279
  }
1221
1280
  try {
1222
1281
  await this.settleLocalReconcile()
1223
- if (await this.refreshSummary())
1224
- return (await readBuildFacts(this.deps.store, this.deps.slug)).value.state
1225
1282
  for (;;) {
1226
1283
  if (this.deps.shutdownSignal?.aborted) break
1227
- if (await deferMixedVersion(this.deps.store, this.deps.slug, KERNEL)) break
1228
1284
  await this.ensureLease()
1229
1285
  await this.settleLocalReconcile()
1230
1286
  const facts = (await readBuildFacts(this.deps.store, this.deps.slug)).value
1287
+ if (await this.requestRelaunch(facts)) break
1288
+ if (await deferMixedVersion(this.deps.store, this.deps.slug, KERNEL)) break
1289
+ if (await this.refreshSummary()) break
1231
1290
  if (facts.publication.pending()) {
1232
1291
  const next = decideNextFromFacts(facts.state, facts.log, await this.captureConfig())
1233
1292
  // Inert controls cannot start more work under unsettled publication.
@@ -1251,14 +1310,21 @@ export class BuildRunner {
1251
1310
  if (await this.settlePauseInterruption()) continue
1252
1311
  break
1253
1312
  }
1254
- if (await this.refreshSummary()) break
1255
- if (decision.kind === 'wait') break
1313
+ if (decision.kind === 'wait') {
1314
+ if (decision.reason === 'mixed-version')
1315
+ await this.requestRelaunch(
1316
+ (await readBuildFacts(this.deps.store, this.deps.slug)).value,
1317
+ )
1318
+ break
1319
+ }
1256
1320
  }
1257
1321
  return (await readBuildFacts(this.deps.store, this.deps.slug)).value.state
1258
1322
  } catch (error) {
1259
1323
  if (!(error instanceof SessionShutdown) && !(error instanceof MixedVersionDeferral))
1260
1324
  throw error
1261
- return (await readBuildFacts(this.deps.store, this.deps.slug)).value.state
1325
+ const facts = (await readBuildFacts(this.deps.store, this.deps.slug)).value
1326
+ if (error instanceof MixedVersionDeferral) await this.requestRelaunch(facts)
1327
+ return facts.state
1262
1328
  } finally {
1263
1329
  this.stopHeartbeat()
1264
1330
  await this.closeProducerSessions()
@@ -1987,8 +2053,10 @@ export class BuildRunner {
1987
2053
 
1988
2054
  if (decision.action.kind === 'run-check') {
1989
2055
  await this.runCheck(decision.action)
2056
+ await reportIntegrationFailures(this.deps.store, this.deps.slug)
1990
2057
  } else {
1991
2058
  await this.runAgentVerify(decision.action)
2059
+ await reportIntegrationFailures(this.deps.store, this.deps.slug)
1992
2060
  }
1993
2061
  }
1994
2062
 
@@ -2840,7 +2908,6 @@ export class BuildRunner {
2840
2908
  const session = started.payload.session
2841
2909
  const state = (await readBuildFacts(store, slug)).value.state
2842
2910
  const native = state.sessions.open.find((s) => s.session === session)?.nativeHandle
2843
- if (!native && cause === 'shutdown') return
2844
2911
  const producer = [...this.producerSessions.entries()].find(
2845
2912
  ([phase]) => phase === started.payload.phase,
2846
2913
  )
@@ -2855,7 +2922,10 @@ export class BuildRunner {
2855
2922
  if (handle) {
2856
2923
  try {
2857
2924
  const owner = producer?.[1].runner ?? this.deps.runtimes[started.payload.runner]!.runner
2858
- const transcript = await this.boundedCleanup(owner.end(handle))
2925
+ const transcript =
2926
+ cause === 'shutdown'
2927
+ ? await owner.end(handle)
2928
+ : await this.boundedCleanup(owner.end(handle))
2859
2929
  content = transcript?.content
2860
2930
  usage = value?.result?.usage ?? (producer ? undefined : transcript?.metadata.usage)
2861
2931
  } catch {