@defrex/autobuild 1.6.0 → 1.8.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 (165) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +423 -57
  3. package/docs/agent-runtimes.md +1 -1
  4. package/docs/answering-blocked-builds.md +44 -3
  5. package/docs/architecture.md +124 -29
  6. package/docs/cli.md +1 -0
  7. package/docs/configuration-overview.md +11 -1
  8. package/docs/configuration.md +334 -14
  9. package/docs/dispatcher.md +1 -1
  10. package/docs/forges.md +1 -0
  11. package/docs/integration-overview.md +2 -2
  12. package/docs/integration-tree.md +7 -4
  13. package/docs/merge-policy.md +78 -6
  14. package/docs/migration-1.0.md +4 -2
  15. package/docs/operating.md +3 -2
  16. package/docs/operator-api.md +45 -13
  17. package/docs/operator-surfaces.md +16 -3
  18. package/docs/plugin-authoring.md +45 -7
  19. package/docs/remote-store-protocol.md +28 -7
  20. package/docs/restacking.md +35 -11
  21. package/docs/ticket-dependencies.md +9 -4
  22. package/docs/ticket-sources.md +34 -6
  23. package/docs/tickets.md +7 -1
  24. package/docs/troubleshooting.md +1 -1
  25. package/docs/workspaces.md +1 -1
  26. package/package.json +3 -3
  27. package/packages/core/src/cli/attention.ts +2 -0
  28. package/packages/core/src/cli/binary-direct.ts +1 -0
  29. package/packages/core/src/cli/build-control.ts +65 -7
  30. package/packages/core/src/cli/context.ts +55 -14
  31. package/packages/core/src/cli/dashboard/actions.ts +13 -4
  32. package/packages/core/src/cli/dashboard/landing-display.ts +32 -8
  33. package/packages/core/src/cli/dashboard/model.ts +61 -8
  34. package/packages/core/src/cli/dashboard/render.ts +28 -3
  35. package/packages/core/src/cli/dashboard/tree.ts +9 -1
  36. package/packages/core/src/cli/dispatch-frontend.ts +10 -14
  37. package/packages/core/src/cli/dispatch-preflight.ts +1 -0
  38. package/packages/core/src/cli/dispatch-repository-feed.ts +145 -109
  39. package/packages/core/src/cli/dispatch.ts +9 -3
  40. package/packages/core/src/cli/help.ts +80 -11
  41. package/packages/core/src/cli/init-validation.ts +14 -1
  42. package/packages/core/src/cli/landings.ts +1 -1
  43. package/packages/core/src/cli/main.ts +60 -9
  44. package/packages/core/src/cli/publication-settlement.ts +10 -0
  45. package/packages/core/src/cli/repository-status.ts +37 -2
  46. package/packages/core/src/cli/status.ts +186 -12
  47. package/packages/core/src/cli/terminals.ts +197 -4
  48. package/packages/core/src/cli/ticket.ts +22 -4
  49. package/packages/core/src/cli/wait.ts +1 -0
  50. package/packages/core/src/cli/watch.ts +73 -0
  51. package/packages/core/src/config/landing.ts +12 -0
  52. package/packages/core/src/config/live.ts +4 -0
  53. package/packages/core/src/config/path-selectors.ts +68 -0
  54. package/packages/core/src/config/profiles.ts +96 -0
  55. package/packages/core/src/config/ready-assignee.ts +43 -11
  56. package/packages/core/src/config/roles.ts +33 -10
  57. package/packages/core/src/config/schema.ts +205 -81
  58. package/packages/core/src/events/catalog.ts +17 -3
  59. package/packages/core/src/events/compatibility.ts +4 -1
  60. package/packages/core/src/events/forge-degradation-policy.ts +16 -2
  61. package/packages/core/src/events/head-paths-limits.ts +25 -0
  62. package/packages/core/src/events/payloads.ts +323 -20
  63. package/packages/core/src/events/policy.ts +22 -0
  64. package/packages/core/src/events/repository.ts +47 -1
  65. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +320 -130
  66. package/packages/core/src/kernel/build-creation.ts +29 -0
  67. package/packages/core/src/kernel/consent-revocation.ts +72 -0
  68. package/packages/core/src/kernel/dispatch-capacity.ts +19 -8
  69. package/packages/core/src/kernel/engine.ts +48 -8
  70. package/packages/core/src/kernel/forge-health.ts +47 -0
  71. package/packages/core/src/kernel/guarded-forge.ts +76 -18
  72. package/packages/core/src/kernel/head-paths-state.ts +63 -0
  73. package/packages/core/src/kernel/head-paths.ts +401 -0
  74. package/packages/core/src/kernel/landing-policy-identity.ts +20 -0
  75. package/packages/core/src/kernel/landing-policy.ts +55 -2
  76. package/packages/core/src/kernel/landing-readiness.ts +104 -9
  77. package/packages/core/src/kernel/landing-state.ts +44 -4
  78. package/packages/core/src/kernel/leaf-restack-state.ts +50 -2
  79. package/packages/core/src/kernel/log-index.ts +27 -1
  80. package/packages/core/src/kernel/node-parent.ts +2 -0
  81. package/packages/core/src/kernel/node-polling.ts +13 -3
  82. package/packages/core/src/kernel/node-restack-state.ts +8 -1
  83. package/packages/core/src/kernel/node-restack-transaction.ts +45 -0
  84. package/packages/core/src/kernel/read-deferrals.ts +3 -1
  85. package/packages/core/src/kernel/read-facts.ts +37 -2
  86. package/packages/core/src/kernel/reducer-registry.ts +22 -1
  87. package/packages/core/src/kernel/reducer.ts +332 -16
  88. package/packages/core/src/kernel/target-observation.ts +2 -5
  89. package/packages/core/src/kernel/terminal-guard.ts +52 -3
  90. package/packages/core/src/kernel/ticket-handbacks.ts +40 -0
  91. package/packages/core/src/kernel/ticket-preparation.ts +15 -1
  92. package/packages/core/src/kernel/ticket-wait.ts +345 -0
  93. package/packages/core/src/kernel/verify-applicability.ts +9 -19
  94. package/packages/core/src/ontology.ts +1 -0
  95. package/packages/core/src/operator/annotations.ts +6 -0
  96. package/packages/core/src/operator/index.ts +3 -0
  97. package/packages/core/src/operator/protocol.ts +25 -2
  98. package/packages/core/src/operator/query.ts +1 -1
  99. package/packages/core/src/operator/registry.ts +122 -10
  100. package/packages/core/src/operator/repository-events.ts +67 -0
  101. package/packages/core/src/operator/sandbox-host.ts +3 -0
  102. package/packages/core/src/operator/tickets.ts +15 -3
  103. package/packages/core/src/plugin-sdk/index.ts +4 -0
  104. package/packages/core/src/ports/forge/create.ts +6 -0
  105. package/packages/core/src/ports/forge/github-transport.ts +40 -3
  106. package/packages/core/src/ports/forge/github.ts +12 -1
  107. package/packages/core/src/ports/forge/workspace-ancestry.ts +60 -0
  108. package/packages/core/src/ports/forge-failure.ts +31 -2
  109. package/packages/core/src/ports/runner/routing.ts +66 -5
  110. package/packages/core/src/ports/tickets/assignees.ts +54 -0
  111. package/packages/core/src/ports/tickets/contract.ts +164 -4
  112. package/packages/core/src/ports/tickets/create.ts +17 -3
  113. package/packages/core/src/ports/tickets/fake.ts +5 -0
  114. package/packages/core/src/ports/tickets/github-fake.ts +18 -2
  115. package/packages/core/src/ports/tickets/github.ts +247 -29
  116. package/packages/core/src/ports/tickets/hosted-index.ts +1 -0
  117. package/packages/core/src/ports/tickets/operations.ts +6 -1
  118. package/packages/core/src/ports/tickets/tree.ts +12 -2
  119. package/packages/core/src/ports/tickets/update.ts +6 -2
  120. package/packages/core/src/ports/types.ts +36 -5
  121. package/packages/core/src/ports/workspace/vercel-sandbox.ts +9 -0
  122. package/packages/core/src/processes/build-child.ts +28 -7
  123. package/packages/core/src/processes/build-execution-state.ts +34 -2
  124. package/packages/core/src/processes/build-runner.ts +165 -19
  125. package/packages/core/src/processes/dispatcher.ts +837 -115
  126. package/packages/core/src/processes/execution-no-progress.ts +22 -2
  127. package/packages/core/src/processes/harvest-child.ts +4 -0
  128. package/packages/core/src/processes/harvest-runner.ts +5 -0
  129. package/packages/core/src/processes/phase-failure-budget.ts +1 -0
  130. package/packages/core/src/processes/publication-state.ts +6 -1
  131. package/packages/core/src/processes/repo-view.ts +2 -0
  132. package/packages/core/src/scenarios/harness.ts +15 -1
  133. package/packages/core/src/store/digest.ts +41 -2
  134. package/packages/core/src/store/reduced-reads.ts +4 -1
  135. package/packages/core/src/store/reducer-value-shapes.json +10310 -8441
  136. package/packages/core/src/store/remote/client.ts +49 -10
  137. package/packages/core/src/store/remote/index.ts +4 -0
  138. package/packages/core/src/store/remote/protocol.ts +18 -1
  139. package/packages/core/src/store/remote/released-clients.json +22 -0
  140. package/packages/core/src/store/remote/released-reducer-values/1.7.0.json +27366 -0
  141. package/packages/core/src/store/remote/released-reducer-values/1.8.0.json +29043 -0
  142. package/packages/core/src/store/remote/released-reducer-values/index.ts +4 -0
  143. package/packages/core/src/store/repo-state-events.ts +3 -0
  144. package/packages/core/src/store/types.ts +27 -0
  145. package/packages/core/src/testing/dispatch-read-budget.ts +84 -58
  146. package/packages/core/src/testing/index.ts +2 -0
  147. package/packages/core/src/testing/reduced-read-budget.ts +419 -9
  148. package/skills/code-review/SKILL.md +8 -0
  149. package/skills/finalize/SKILL.md +4 -0
  150. package/skills/guide/SKILL.md +241 -47
  151. package/skills/guide/references/integration-tree.md +7 -4
  152. package/skills/guide/references/merge-policy.md +78 -6
  153. package/skills/guide/references/migration-1.0.md +4 -2
  154. package/skills/guide/references/operator-api.md +45 -13
  155. package/skills/guide/references/plugin-authoring.md +45 -7
  156. package/skills/guide/references/remote-store-protocol.md +28 -7
  157. package/skills/guide/references/restacking.md +35 -11
  158. package/skills/guide/references/ticket-dependencies.md +9 -4
  159. package/skills/implement/SKILL.md +15 -1
  160. package/skills/operate/SKILL.md +133 -16
  161. package/skills/plan/SKILL.md +17 -2
  162. package/skills/plan-review/SKILL.md +8 -0
  163. package/skills/reconcile/SKILL.md +21 -5
  164. package/skills/tickets/SKILL.md +23 -6
  165. package/templates/hosted-service/package.json +2 -2
@@ -7,6 +7,7 @@ import { inspectGitCandidate, preserveGitCommits, restoreGitCommits } from './co
7
7
  import { accountPolicy, accountGuestEnvironment } from './account-policy'
8
8
  import { HOSTED_ACCOUNT_READINESS_ENV } from '../../accounts/hosted-readiness'
9
9
  import { gitRewrite, parseRemoteHead } from '../forge/git-rewrite'
10
+ import { GITHUB_REQUIRE_CREDENTIAL_ENV } from '../forge/github-transport'
10
11
  import { delegateCredential } from '../../store/remote/credentials'
11
12
  import type { ExecutionLaunchAuth } from './build-execution'
12
13
  import { createHash } from 'node:crypto'
@@ -1910,6 +1911,10 @@ export class VercelSandboxProvider implements WorkspaceProvider {
1910
1911
  }),
1911
1912
  }
1912
1913
  Object.assign(env, this.guestEnvironment())
1914
+ // Guests hold no forge credential: their GitHub API requests fail typed
1915
+ // instead of going out anonymously. Applied last so no forwarded value
1916
+ // can disable it.
1917
+ env[GITHUB_REQUIRE_CREDENTIAL_ENV] = '1'
1913
1918
  const command = (await sandbox.runCommand({
1914
1919
  cmd: 'sh',
1915
1920
  args: [
@@ -2234,6 +2239,10 @@ export class VercelSandboxProvider implements WorkspaceProvider {
2234
2239
  [HARVEST_RUNNER_OPTIONS_ENV]: JSON.stringify(envelope),
2235
2240
  }
2236
2241
  Object.assign(env, this.guestEnvironment())
2242
+ // Guests hold no forge credential: their GitHub API requests fail typed
2243
+ // instead of going out anonymously. Applied last so no forwarded value
2244
+ // can disable it.
2245
+ env[GITHUB_REQUIRE_CREDENTIAL_ENV] = '1'
2237
2246
  const command = (await sandbox.runCommand({
2238
2247
  cmd: 'sh',
2239
2248
  args: [
@@ -5,6 +5,8 @@ import { isRemoteWorkspace } from '../events/workspace-remote'
5
5
  import { readBuildFacts } from '../store/reduced-reads'
6
6
  import { hostname } from 'node:os'
7
7
  import { createForge } from '../ports/forge/create'
8
+ import { GITHUB_REQUIRE_CREDENTIAL_ENV } from '../ports/forge/github-transport'
9
+ import { withWorkspaceAncestry } from '../ports/forge/workspace-ancestry'
8
10
  import { createProductionRuntimes } from '../ports/runner/production'
9
11
  import { spawnExec } from '../ports/workspace/git-worktree'
10
12
  import { loadPlugins } from '../plugins/load'
@@ -67,14 +69,30 @@ export async function runBuildChild(
67
69
  repoRoot: workspace.path ?? workspace.ref,
68
70
  env,
69
71
  })
72
+ const workspaceRemote = opts.guest === true || isRemoteWorkspace(workspace)
73
+ const created = await createForge({
74
+ name: currentConfig.forge,
75
+ registry: plugins,
76
+ env,
77
+ repoRoot: workspace.path ?? workspace.ref,
78
+ })
79
+ // A remote guest holds no forge credential: ancestry proofs run through the
80
+ // workspace's own Git read channel instead of an anonymous API request.
81
+ // The runner's limits are its own; only the dispatcher pauses the repository.
70
82
  const forge = guardForge(
71
- await createForge({
83
+ workspaceRemote
84
+ ? withWorkspaceAncestry(created, {
85
+ exec: spawnExec,
86
+ workspacePath: workspace.path ?? workspace.ref,
87
+ })
88
+ : created,
89
+ {
90
+ store: fullStore,
91
+ repo: record.repo,
72
92
  name: currentConfig.forge,
73
- registry: plugins,
74
- env,
75
- repoRoot: workspace.path ?? workspace.ref,
76
- }),
77
- { store: fullStore, repo: record.repo, name: currentConfig.forge, wait: true },
93
+ wait: true,
94
+ scope: { process: `build-runner ${input.slug}` },
95
+ },
78
96
  )
79
97
  const getConfig = async () => {
80
98
  const latest = await store.getArtifact(input.slug, BUILD_EFFECTIVE_CONFIG_ARTIFACT)
@@ -99,7 +117,7 @@ export async function runBuildChild(
99
117
  runtimes,
100
118
  workspacePath: workspace.path ?? workspace.ref,
101
119
  workspaceProvider: workspace.provider,
102
- workspaceRemote: opts.guest === true || isRemoteWorkspace(workspace),
120
+ workspaceRemote,
103
121
  shutdownSignal: opts.shutdownSignal,
104
122
  branch: workspace.branch,
105
123
  slug: input.slug,
@@ -112,6 +130,9 @@ export async function runBuildChild(
112
130
  sessionEnv: {
113
131
  AB_STORE: input.storeRef,
114
132
  ...(env.AB_TOKEN !== undefined && env.AB_TOKEN !== '' ? { AB_TOKEN: env.AB_TOKEN } : {}),
133
+ ...(env[GITHUB_REQUIRE_CREDENTIAL_ENV] === '1'
134
+ ? { [GITHUB_REQUIRE_CREDENTIAL_ENV]: '1' }
135
+ : {}),
115
136
  },
116
137
  })
117
138
  await runner.run()
@@ -5,7 +5,7 @@ import { BUILD_OWNED_CONFIG_PATHS } from '../config/live'
5
5
  import { isPipelineSourceRef, type PipelineSourceMeta } from '../config/pipeline-source'
6
6
  import type { AbEvent } from '../events/catalog'
7
7
  import { defineReducer } from '../kernel/incremental'
8
- import type { Artifact, ArtifactInput } from '../store/types'
8
+ import type { Artifact, ArtifactInput, BuildStore } from '../store/types'
9
9
 
10
10
  export const BUILD_EFFECTIVE_CONFIG_ARTIFACT = 'build-runner-effective-config'
11
11
  export const BUILD_RUNNER_DIAGNOSTIC_ARTIFACT = 'build-runner-diagnostic'
@@ -20,9 +20,12 @@ export interface BuildRunnerDiagnostic {
20
20
 
21
21
  /** JSON form of the normalized config's strict declarative input shape. */
22
22
  export function effectiveBuildConfigContent(config: Config): string {
23
- const { verify, finalize, ...root } = config
23
+ const { verify, finalize, profiles, ...root } = config
24
24
  return JSON.stringify({
25
25
  ...root,
26
+ // Omitted when empty so repositories without profiles keep byte-identical
27
+ // artifacts that an older client's strict root parse still accepts.
28
+ ...(profiles !== undefined && Object.keys(profiles).length > 0 ? { profiles } : {}),
26
29
  verify: {
27
30
  steps: verify.stages ?? verify.steps,
28
31
  afterReconcile: verify.afterReconcile,
@@ -54,6 +57,35 @@ export function parseEffectiveBuildConfig(artifact: Artifact): Config {
54
57
  return result.data
55
58
  }
56
59
 
60
+ /** The latest deposited pipeline exists but cannot be parsed. */
61
+ export class EffectivePipelineUnreadable extends Error {
62
+ constructor(
63
+ readonly revision: number,
64
+ cause: unknown,
65
+ ) {
66
+ super(cause instanceof Error ? cause.message : String(cause))
67
+ this.name = 'EffectivePipelineUnreadable'
68
+ }
69
+ }
70
+
71
+ /** The dispatcher's first pipeline read: the latest deposited
72
+ * `build-runner-effective-config`, parsed. `null` when none is deposited (the
73
+ * dispatcher then decides with its deployment config); throws when the read
74
+ * fails, or `EffectivePipelineUnreadable` when the deposit does not parse.
75
+ * `ab build status` uses the same definition of readable. */
76
+ export async function readEffectivePipeline(
77
+ store: Pick<BuildStore, 'getArtifact'>,
78
+ slug: string,
79
+ ): Promise<{ config: Config; revision: number } | null> {
80
+ const artifact = await store.getArtifact(slug, BUILD_EFFECTIVE_CONFIG_ARTIFACT)
81
+ if (artifact === null) return null
82
+ try {
83
+ return { config: parseEffectiveBuildConfig(artifact), revision: artifact.meta.revision }
84
+ } catch (error) {
85
+ throw new EffectivePipelineUnreadable(artifact.meta.revision, error)
86
+ }
87
+ }
88
+
57
89
  /** Read the artifact metadata's revision + pipeline-source projection. Old
58
90
  * deposits (and externally written ones) carry no `pipelineSource`; status and
59
91
  * the dashboard render that as "unknown (pre-pin)" instead of guessing. */
@@ -1,3 +1,4 @@
1
+ import { leafLandingBase, parseNulChangedPaths, recordHeadPaths } from '../kernel/head-paths'
1
2
  import { StoreWriteTooLargeError } from '../store/remote/errors'
2
3
  import { observeTarget } from '../kernel/target-observation'
3
4
  import { readBuildRange } from '../store/event-reads'
@@ -20,6 +21,7 @@ import type { RuntimeIdentity } from '../events/runtime'
20
21
  import { relaunchTarget } from './execution-relaunch'
21
22
  import { runtimeIdentity } from '../runtime-identity'
22
23
  import { publishExact } from '../kernel/publication'
24
+ import { waitResumeSupersedes } from '../kernel/ticket-wait'
23
25
  import {
24
26
  deferMixedVersion,
25
27
  MixedVersionDeferral,
@@ -461,6 +463,9 @@ export function phaseFailuresReducer(phase: Phase, round: number) {
461
463
  deferral: 'own-build-read',
462
464
  }
463
465
  break
466
+ // A ticket wait's escalation (`wait.entered`) is deliberately not
467
+ // registered: ending a wait is not a failure retry, so its answer
468
+ // re-arms no budget.
464
469
  case 'escalation.raised':
465
470
  acc.raised[event.payload.id] = {
466
471
  phase: event.payload.phase,
@@ -541,7 +546,7 @@ export const setupStreakReducer = defineReducer<
541
546
  finish: (acc) => acc.failures.filter((seq) => seq > acc.boundary).length,
542
547
  })
543
548
 
544
- export const PUBLISHED_BRANCH_HEAD_REDUCER_VERSION = 4
549
+ export const PUBLISHED_BRANCH_HEAD_REDUCER_VERSION = 5
545
550
 
546
551
  /** Latest event-checkpointed branch head that kernel plumbing published;
547
552
  * undefined while the build has none. */
@@ -565,6 +570,13 @@ export const publishedBranchHeadReducer = defineReducer<
565
570
  acc.head = reconcileRewriteHead(event.payload)
566
571
  } else if (event.type === 'reconcile.completed') {
567
572
  acc.head = reconcileHead(event.payload)
573
+ } else if (
574
+ event.type === 'wait.requested' &&
575
+ event.payload.publication?.settlement === 'published'
576
+ ) {
577
+ acc.head = event.payload.publication.sha
578
+ } else if (event.type === 'wait.published') {
579
+ acc.head = event.payload.sha
568
580
  } else if (
569
581
  event.type === 'finalize.step-completed' &&
570
582
  event.payload.ok &&
@@ -589,7 +601,7 @@ export function selectPublishedBranchHead(events: readonly AbEvent[]): string {
589
601
  return head
590
602
  }
591
603
 
592
- export const VERIFY_DIFF_BASE_REDUCER_VERSION = 2
604
+ export const VERIFY_DIFF_BASE_REDUCER_VERSION = 3
593
605
 
594
606
  /**
595
607
  * The durable tree against which a conditional verifier evaluates the
@@ -611,6 +623,11 @@ export const verifyDiffBaseReducer = defineReducer<
611
623
  if (acc.provisioned === undefined) acc.provisioned = event.payload.base.sha
612
624
  } else if (event.type === 'restack.completed') {
613
625
  acc.promoted = event.payload.targetBase
626
+ } else if (event.type === 'restack.advanced') {
627
+ acc.promoted = event.payload.to
628
+ } else if (event.type === 'reconcile.superseded') {
629
+ // An abandoned occurrence's base never promotes.
630
+ delete acc.pendingReconcileBase
614
631
  } else if (event.type === 'reconcile.started') {
615
632
  acc.pendingReconcileBase = event.payload.baseSha
616
633
  } else if (event.type === 'reconcile.completed') {
@@ -638,18 +655,7 @@ export function selectVerifyDiffBase(events: readonly AbEvent[]): string {
638
655
  return base
639
656
  }
640
657
 
641
- /** Parse `git diff --name-only -z`; malformed output fails closed. */
642
- export function parseNulChangedPaths(output: string): string[] {
643
- if (output.length === 0) return []
644
- if (!output.endsWith('\0')) {
645
- throw new Error('git diff --name-only -z returned non-NUL-terminated output')
646
- }
647
- const paths = output.slice(0, -1).split('\0')
648
- if (paths.some((path) => path.length === 0)) {
649
- throw new Error('git diff --name-only -z returned an empty path entry')
650
- }
651
- return paths
652
- }
658
+ export { parseNulChangedPaths }
653
659
 
654
660
  /** Terminal events of loop phases carry `round`; finalize.completed and
655
661
  * reconcile.completed do not (§15.3). Payloads are schema-validated at
@@ -787,6 +793,8 @@ export class BuildRunner {
787
793
 
788
794
  private async startBracket(write: EventWrite<'session.started'>) {
789
795
  const { store, slug } = this.deps
796
+ if (this.boundaryProfile !== undefined)
797
+ write = { ...write, payload: { ...write.payload, profile: { ...this.boundaryProfile } } }
790
798
  const old = this.recovery
791
799
  const budgetMs = this.resolveSessionRole(write.payload.role).sessionBudgetSeconds * 1000
792
800
  if (
@@ -941,6 +949,8 @@ export class BuildRunner {
941
949
  * consults the mutable owner again. */
942
950
  private boundaryConfig: Config
943
951
  private boundaryResolver: RuntimeResolver
952
+ /** The build's profile and whether the boundary config still defines it. */
953
+ private boundaryProfile: { name: string; configured: boolean } | undefined
944
954
 
945
955
  constructor(private readonly deps: BuildRunnerDeps) {
946
956
  const redactor = accountRedactor(
@@ -979,12 +989,22 @@ export class BuildRunner {
979
989
  const state = (await readBuildFacts(this.deps.store, this.deps.slug)).value.state
980
990
  const config = await capturedBuildConfig(this.deps.store, this.deps.slug, state, deployment)
981
991
  this.boundaryConfig = config
982
- this.boundaryResolver = createRuntimeResolver(
992
+ const base = createRuntimeResolver(
983
993
  this.deps.runtimes,
984
994
  config.roles,
985
995
  config.policy.sessionBudgetSeconds,
986
996
  config.accounts,
997
+ config.profiles,
987
998
  )
999
+ // The build's profile was fixed at claim; its contents come from the
1000
+ // boundary-current config. A profile a reload removed falls back to the
1001
+ // repository roles, and the next session.started records that.
1002
+ const profile = state.profile === undefined ? undefined : base.profile(state.profile.name)
1003
+ this.boundaryResolver = profile ?? base
1004
+ this.boundaryProfile =
1005
+ state.profile === undefined
1006
+ ? undefined
1007
+ : { name: state.profile.name, configured: profile !== undefined }
988
1008
  return config
989
1009
  }
990
1010
 
@@ -2083,6 +2103,12 @@ export class BuildRunner {
2083
2103
  }
2084
2104
  try {
2085
2105
  await this.assertAutomaticRewriteOwnership()
2106
+ // A reconcile session that waited left its occurrence frozen onto the
2107
+ // old target. Abandon it so the resume replays onto the current one.
2108
+ if (decision.trigger === 'wait-resume' && waitResumeSupersedes(facts.state, facts.log)) {
2109
+ await this.supersedeReconcile(decision)
2110
+ facts = (await readBuildFacts(store, slug)).value
2111
+ }
2086
2112
  if (facts.log.restack.intent)
2087
2113
  await publicationRetryGate(
2088
2114
  { ...this.deps, actor: KERNEL },
@@ -2096,6 +2122,14 @@ export class BuildRunner {
2096
2122
  >
2097
2123
  let id: string
2098
2124
  let targetBase: string
2125
+ if (
2126
+ transaction === undefined &&
2127
+ decision.trigger === 'wait-resume' &&
2128
+ (await readBuildSelector(store, slug, 'publishedBranchHead')) === undefined
2129
+ ) {
2130
+ await this.advanceWaitResume(decision)
2131
+ return
2132
+ }
2099
2133
  if (transaction === undefined) {
2100
2134
  targetBase = await this.refreshReconcileBase(true)
2101
2135
  const branch = facts.lastCreated?.payload.baseBranch
@@ -2176,6 +2210,21 @@ export class BuildRunner {
2176
2210
  throw new Error('recovered automatic replay differs from its frozen publication intent')
2177
2211
  await retainReplay(deps, headSha, transaction.targetBase)
2178
2212
  const intent = { ...transaction, headSha }
2213
+ await recordHeadPaths(
2214
+ {
2215
+ store,
2216
+ slug,
2217
+ exec: this.deps.exec,
2218
+ workspacePath: this.deps.workspacePath,
2219
+ actor: KERNEL,
2220
+ },
2221
+ {
2222
+ source: 'restack',
2223
+ head: headSha,
2224
+ destination: transaction.targetBase,
2225
+ state: facts.state,
2226
+ },
2227
+ )
2179
2228
  if (facts.log.restack.intent === undefined)
2180
2229
  await store.append(slug, {
2181
2230
  actor: KERNEL,
@@ -2241,6 +2290,90 @@ export class BuildRunner {
2241
2290
  }
2242
2291
  }
2243
2292
 
2293
+ /** Abandon the open reconcile occurrence whose session declared a ticket
2294
+ * wait: abort its workspace operation, then record `reconcile.superseded`.
2295
+ * Only the resolver's undeposited, uncommitted resolution is discarded;
2296
+ * every published head and recorded transaction stays. Idempotent up to
2297
+ * the append, so a crash before it repeats harmlessly. */
2298
+ private async supersedeReconcile(
2299
+ decision: Extract<Decision, { kind: 'restack' }>,
2300
+ ): Promise<void> {
2301
+ const { store, slug, workspacePath } = this.deps
2302
+ await this.assertAutomaticRewriteOwnership()
2303
+ const facts = (await readBuildFacts(store, slug)).value
2304
+ const open = facts.log.openReconcile
2305
+ if (open === undefined) throw new Error('no open reconcile occurrence to supersede')
2306
+ const head = await readBuildSelector(store, slug, 'publishedBranchHead')
2307
+ if (head === undefined) throw new Error('a reconcile occurrence has no published head')
2308
+ const git = async (args: string[]) => {
2309
+ const result = await this.deps.exec(['git', ...args], { cwd: workspacePath })
2310
+ if (result.exitCode !== 0)
2311
+ throw new Error(`git ${args.join(' ')} exited ${result.exitCode}: ${result.stderr.trim()}`)
2312
+ }
2313
+ const picking = await this.deps.exec(
2314
+ ['git', 'rev-parse', '-q', '--verify', 'CHERRY_PICK_HEAD'],
2315
+ { cwd: workspacePath },
2316
+ )
2317
+ if (picking.exitCode === 0) await git(['cherry-pick', '--abort'])
2318
+ await git(['reset', '-q', '--hard'])
2319
+ await git(['checkout', '-q', '--detach', head])
2320
+ await store.append(slug, {
2321
+ actor: KERNEL,
2322
+ type: 'reconcile.superseded',
2323
+ payload: {
2324
+ attempt: open.attempt,
2325
+ cycle: decision.cycle,
2326
+ cause: 'wait-resume',
2327
+ ...(open.restackId === undefined ? {} : { restackId: open.restackId }),
2328
+ },
2329
+ })
2330
+ }
2331
+
2332
+ /** A wait-resume restack with nothing published: the local branch has no
2333
+ * commits beyond its contribution base, so it fast-forwards to the fresh
2334
+ * target snapshot and records `restack.advanced`. No remote write; no
2335
+ * conflict is possible. */
2336
+ private async advanceWaitResume(decision: Extract<Decision, { kind: 'restack' }>): Promise<void> {
2337
+ const { store, slug, workspacePath, branch } = this.deps
2338
+ const targetBase = await this.refreshReconcileBase(true)
2339
+ const facts = (await readBuildFacts(store, slug)).value
2340
+ const oldBase = await readBuildSelector(store, slug, 'verifyDiffBase')
2341
+ if (oldBase === undefined) throw new Error('missing contribution base')
2342
+ const git = async (args: string[], allowFailure = false) => {
2343
+ const result = await this.deps.exec(['git', ...args], { cwd: workspacePath })
2344
+ if (result.exitCode !== 0 && !allowFailure)
2345
+ throw new Error(
2346
+ `git ${args.join(' ')} exited ${result.exitCode}: ${result.stderr.trim() || '(no output)'}`,
2347
+ )
2348
+ return result
2349
+ }
2350
+ const local = (await git(['rev-parse', '--verify', `refs/heads/${branch}`])).stdout.trim()
2351
+ if (local !== targetBase) {
2352
+ // Every commit the target already contains is safe to move past; that
2353
+ // also covers a crash after an earlier fast-forward.
2354
+ if ((await git(['merge-base', '--is-ancestor', local, targetBase], true)).exitCode !== 0)
2355
+ throw new Error(
2356
+ `local branch ${branch} has unpublished commits at ${local}; a wait-resume restack replays only published work`,
2357
+ )
2358
+ const status = (await git(['status', '--porcelain', '--untracked-files=no'])).stdout.trim()
2359
+ if (status !== '') throw new Error(`workspace has uncommitted tracked changes:\n${status}`)
2360
+ await this.assertAutomaticRewriteOwnership()
2361
+ await git(['checkout', '-q', '-B', branch, targetBase])
2362
+ }
2363
+ await store.append(slug, {
2364
+ actor: KERNEL,
2365
+ type: 'restack.advanced',
2366
+ payload: {
2367
+ trigger: 'wait-resume',
2368
+ cycle: decision.cycle,
2369
+ observation: facts.log.restack.target!.seq,
2370
+ branch,
2371
+ from: oldBase,
2372
+ to: targetBase,
2373
+ },
2374
+ })
2375
+ }
2376
+
2244
2377
  /** Snapshot the frozen target in a build-private ref without tracking-ref updates. */
2245
2378
  private async refreshReconcileBase(recordAccepted = false): Promise<string> {
2246
2379
  const baseBranch = await readBuildSelector(this.deps.store, this.deps.slug, 'baseBranch')
@@ -2798,8 +2931,21 @@ export class BuildRunner {
2798
2931
  head,
2799
2932
  )
2800
2933
  if (scratchPaths.length > 0) throw phaseScratchRejection(scratchPaths)
2801
- const remote = (await readBuildFacts(this.deps.store, this.deps.slug)).value
2802
- .remoteWorkspace
2934
+ const facts = (await readBuildFacts(this.deps.store, this.deps.slug)).value
2935
+ await recordHeadPaths(
2936
+ { ...this.deps, actor: KERNEL },
2937
+ {
2938
+ source: 'finalize-step',
2939
+ head,
2940
+ destination: await leafLandingBase(
2941
+ this.deps.store,
2942
+ this.deps.slug,
2943
+ facts.log.restack,
2944
+ ),
2945
+ state: facts.state,
2946
+ },
2947
+ )
2948
+ const remote = facts.remoteWorkspace
2803
2949
  if (remote) {
2804
2950
  await this.deps.store.append(this.deps.slug, {
2805
2951
  actor,
@@ -3744,7 +3890,7 @@ export class BuildRunner {
3744
3890
  (event) =>
3745
3891
  spec.isTerminal(event) ||
3746
3892
  isPublicationBoundary(event, spec, session) ||
3747
- (event.type === 'escalation.raised' &&
3893
+ ((event.type === 'escalation.raised' || event.type === 'wait.requested') &&
3748
3894
  event.actor.kind === 'agent' &&
3749
3895
  event.actor.session === session),
3750
3896
  )
@@ -4066,7 +4212,7 @@ export class BuildRunner {
4066
4212
  (event) =>
4067
4213
  spec.isTerminal(event) ||
4068
4214
  isPublicationBoundary(event, spec, session) ||
4069
- (event.type === 'escalation.raised' &&
4215
+ ((event.type === 'escalation.raised' || event.type === 'wait.requested') &&
4070
4216
  event.actor.kind === 'agent' &&
4071
4217
  event.actor.session === session),
4072
4218
  )