@defrex/autobuild 1.12.0 → 1.13.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 (159) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +435 -160
  3. package/bin/ab-build-runner.ts +8 -0
  4. package/docs/answering-blocked-builds.md +25 -3
  5. package/docs/architecture.md +124 -53
  6. package/docs/cli.md +1 -1
  7. package/docs/configuration.md +110 -15
  8. package/docs/dispatcher.md +19 -8
  9. package/docs/integration-overview.md +1 -1
  10. package/docs/integration-tree.md +12 -9
  11. package/docs/merge-policy.md +7 -2
  12. package/docs/operating.md +5 -3
  13. package/docs/operator-api.md +46 -23
  14. package/docs/operator-surfaces.md +7 -6
  15. package/docs/optimization-nodes.md +7 -6
  16. package/docs/plugin-authoring.md +46 -18
  17. package/docs/remote-store-protocol.md +51 -12
  18. package/docs/remote-ticket-protocol.md +85 -38
  19. package/docs/restacking.md +48 -3
  20. package/docs/setup.md +2 -1
  21. package/docs/ticket-migration.md +2 -2
  22. package/docs/ticket-sources.md +23 -8
  23. package/docs/tickets.md +4 -4
  24. package/docs/troubleshooting.md +17 -2
  25. package/docs/verification.md +3 -1
  26. package/package.json +3 -3
  27. package/packages/core/src/cli/build-control.ts +72 -6
  28. package/packages/core/src/cli/dashboard/actions.ts +4 -0
  29. package/packages/core/src/cli/dashboard/integration-row.ts +43 -19
  30. package/packages/core/src/cli/dashboard/model.ts +14 -8
  31. package/packages/core/src/cli/dashboard/poll.ts +218 -10
  32. package/packages/core/src/cli/dashboard/queue.ts +21 -10
  33. package/packages/core/src/cli/dashboard/row-text.ts +2 -1
  34. package/packages/core/src/cli/dashboard/vocabulary.ts +5 -1
  35. package/packages/core/src/cli/dispatch-frontend.ts +2 -1
  36. package/packages/core/src/cli/dispatch-tickets.ts +33 -12
  37. package/packages/core/src/cli/dispatch.ts +527 -144
  38. package/packages/core/src/cli/help.ts +38 -24
  39. package/packages/core/src/cli/main.ts +7 -5
  40. package/packages/core/src/cli/publication-settlement.ts +4 -0
  41. package/packages/core/src/cli/remote-poll.ts +22 -5
  42. package/packages/core/src/cli/repository-status.ts +19 -9
  43. package/packages/core/src/cli/status.ts +23 -11
  44. package/packages/core/src/cli/store-opening.ts +12 -0
  45. package/packages/core/src/cli/ticket-start.ts +3 -3
  46. package/packages/core/src/cli/ticket.ts +12 -11
  47. package/packages/core/src/cli/wait.ts +8 -28
  48. package/packages/core/src/cli/watch.ts +113 -50
  49. package/packages/core/src/config/reference-metadata.ts +7 -1
  50. package/packages/core/src/config/reference.ts +5 -2
  51. package/packages/core/src/config/schema.ts +51 -16
  52. package/packages/core/src/events/payloads.ts +74 -14
  53. package/packages/core/src/events/repository.ts +14 -3
  54. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +27 -0
  55. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/0a10010ee5cf2e47.json +577 -0
  56. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/227701361be6d1e0.json +490 -0
  57. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/76e5043bae7a80ab.json +86 -0
  58. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/87a917802870bbed.json +87 -0
  59. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/9d85616e5b9e24c1.json +500 -0
  60. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/c7c94fbe7f63cf07.json +84 -0
  61. package/packages/core/src/kernel/clean-restack-policy.ts +40 -0
  62. package/packages/core/src/kernel/dispatch-capacity.ts +243 -107
  63. package/packages/core/src/kernel/done-escalations.ts +269 -0
  64. package/packages/core/src/kernel/engine.ts +28 -9
  65. package/packages/core/src/kernel/integration-landing.ts +24 -4
  66. package/packages/core/src/kernel/integration-stack.ts +39 -0
  67. package/packages/core/src/kernel/janitor-failure.ts +20 -1
  68. package/packages/core/src/kernel/log-index-value.ts +3 -0
  69. package/packages/core/src/kernel/log-index.ts +41 -2
  70. package/packages/core/src/kernel/open-pr-backpressure.ts +3 -3
  71. package/packages/core/src/kernel/reducer-registry.ts +3 -0
  72. package/packages/core/src/kernel/reducer-revisions.ts +15 -0
  73. package/packages/core/src/kernel/reducer.ts +27 -7
  74. package/packages/core/src/kernel/repository-attention.ts +14 -5
  75. package/packages/core/src/kernel/ticket-starts.ts +15 -4
  76. package/packages/core/src/kernel/verify-stages.ts +46 -7
  77. package/packages/core/src/operator/attention.ts +28 -3
  78. package/packages/core/src/operator/done-escalations.ts +38 -0
  79. package/packages/core/src/operator/presentation.ts +1 -1
  80. package/packages/core/src/operator/protocol.ts +8 -5
  81. package/packages/core/src/operator/query.ts +33 -19
  82. package/packages/core/src/operator/registry.ts +17 -13
  83. package/packages/core/src/operator/ticket-start.ts +8 -7
  84. package/packages/core/src/operator/tickets.ts +28 -9
  85. package/packages/core/src/plugin-sdk/index.ts +10 -0
  86. package/packages/core/src/plugins/manifest.ts +14 -1
  87. package/packages/core/src/ports/forge/create.ts +8 -0
  88. package/packages/core/src/ports/forge/github-transport.ts +5 -1
  89. package/packages/core/src/ports/forge/github.ts +3 -0
  90. package/packages/core/src/ports/tickets/contract.ts +147 -76
  91. package/packages/core/src/ports/tickets/create.ts +47 -7
  92. package/packages/core/src/ports/tickets/fake.ts +8 -4
  93. package/packages/core/src/ports/tickets/file-codec.ts +4 -3
  94. package/packages/core/src/ports/tickets/file.ts +7 -3
  95. package/packages/core/src/ports/tickets/github.ts +1 -0
  96. package/packages/core/src/ports/tickets/grants.ts +11 -3
  97. package/packages/core/src/ports/tickets/hosted-index.ts +5 -0
  98. package/packages/core/src/ports/tickets/linear.ts +28 -9
  99. package/packages/core/src/ports/tickets/migration.ts +4 -4
  100. package/packages/core/src/ports/tickets/operations.ts +4 -2
  101. package/packages/core/src/ports/tickets/priority-labels.ts +213 -0
  102. package/packages/core/src/ports/tickets/priority.ts +127 -21
  103. package/packages/core/src/ports/tickets/remote-protocol.ts +10 -0
  104. package/packages/core/src/ports/tickets/remote.ts +104 -11
  105. package/packages/core/src/ports/tickets/revision.ts +5 -3
  106. package/packages/core/src/ports/tickets/search.ts +9 -0
  107. package/packages/core/src/ports/tickets/tree.ts +8 -6
  108. package/packages/core/src/ports/types.ts +30 -15
  109. package/packages/core/src/ports/workspace/build-execution.ts +4 -0
  110. package/packages/core/src/ports/workspace/builtin-capabilities.ts +4 -0
  111. package/packages/core/src/ports/workspace/create.ts +16 -3
  112. package/packages/core/src/ports/workspace/execution-exit-marker.ts +41 -0
  113. package/packages/core/src/ports/workspace/recovery-step.ts +101 -0
  114. package/packages/core/src/ports/workspace/vercel-sandbox.ts +510 -145
  115. package/packages/core/src/processes/build-execution-state.ts +4 -0
  116. package/packages/core/src/processes/build-runner.ts +14 -1
  117. package/packages/core/src/processes/dispatcher.ts +544 -212
  118. package/packages/core/src/processes/execution-settlement.ts +1 -0
  119. package/packages/core/src/processes/harvest-runner.ts +12 -7
  120. package/packages/core/src/processes/infrastructure-failure-budget.ts +7 -2
  121. package/packages/core/src/processes/invocation-budget.ts +176 -0
  122. package/packages/core/src/processes/publication-loss.ts +38 -3
  123. package/packages/core/src/processes/workspace-preservation.ts +86 -15
  124. package/packages/core/src/store/contract.ts +81 -3
  125. package/packages/core/src/store/event-reads.ts +30 -1
  126. package/packages/core/src/store/reduced-reads.ts +23 -0
  127. package/packages/core/src/store/reducer-value-shapes.json +6628 -6469
  128. package/packages/core/src/store/reducer-value-validation.ts +181 -33
  129. package/packages/core/src/store/remote/client.ts +169 -29
  130. package/packages/core/src/store/remote/compatibility.ts +113 -56
  131. package/packages/core/src/store/remote/credentials.ts +4 -1
  132. package/packages/core/src/store/remote/protocol.ts +3 -0
  133. package/packages/core/src/store/remote/released-clients.json +11 -0
  134. package/packages/core/src/store/remote/released-reducer-values/1.13.0.json +35966 -0
  135. package/packages/core/src/store/remote/released-reducer-values/index.ts +18 -16
  136. package/packages/core/src/store/remote/released-value-policy.ts +144 -0
  137. package/packages/core/src/store/remote/retry.ts +406 -0
  138. package/packages/core/src/testing/dispatch-read-budget.ts +144 -10
  139. package/packages/core/src/testing/index.ts +2 -0
  140. package/packages/core/src/testing/invocation-budget.ts +42 -0
  141. package/packages/core/src/testing/reduced-read-budget.ts +381 -18
  142. package/packages/core/src/testing/released-value-coverage.ts +423 -0
  143. package/packages/core/src/web/overview-source.ts +19 -6
  144. package/skills/guide/SKILL.md +138 -67
  145. package/skills/guide/references/integration-tree.md +12 -9
  146. package/skills/guide/references/merge-policy.md +7 -2
  147. package/skills/guide/references/operator-api.md +46 -23
  148. package/skills/guide/references/optimization-nodes.md +7 -6
  149. package/skills/guide/references/plugin-authoring.md +46 -18
  150. package/skills/guide/references/remote-store-protocol.md +51 -12
  151. package/skills/guide/references/remote-ticket-protocol.md +85 -38
  152. package/skills/guide/references/restacking.md +48 -3
  153. package/skills/guide/references/setup.md +2 -1
  154. package/skills/guide/references/ticket-migration.md +2 -2
  155. package/skills/operate/SKILL.md +82 -51
  156. package/skills/plan/SKILL.md +4 -3
  157. package/skills/spec/SKILL.md +9 -5
  158. package/skills/tickets/SKILL.md +25 -17
  159. package/templates/hosted-service/package.json +2 -2
@@ -6,8 +6,8 @@ import {
6
6
  landRefusalReason,
7
7
  } from '../kernel/landing-readiness'
8
8
  import { observeIntegration } from '../kernel/integration-completeness'
9
- import type { TicketPriority, TicketSource } from '../ports/types'
10
- import { ticketPrioritySchema } from '../ports/tickets/priority'
9
+ import type { BuildPriority, TicketSource } from '../ports/types'
10
+ import { buildPrioritySchema, prioritySetPayload } from '../ports/tickets/priority'
11
11
  import { readBuildFacts } from '../store/reduced-reads'
12
12
  /**
13
13
  * Durable operator controls for one build.
@@ -50,6 +50,9 @@ export const DISMISSAL_ANSWER = 'Operator dismissed the cited findings with no f
50
50
  export const SPEC_REVISION_ANSWER = 'Operator replaced the spec; the build restarts from plan'
51
51
  export const ACCEPT_TARGET_ANSWER =
52
52
  "Operator accepted the rewritten target; the build's own commits restack onto it"
53
+ /** A bare answer on a done build closes its open escalations; nothing resumes. */
54
+ export const DONE_ACKNOWLEDGEMENT_ANSWER =
55
+ 'Operator acknowledged the escalation on a completed build'
53
56
 
54
57
  /** Both forms are lazy: completing an earlier authorization must not open the
55
58
  * replacement source supplied to the retrying invocation. */
@@ -71,7 +74,7 @@ export type BuildControlAction =
71
74
  }
72
75
  | { kind: 'land'; head?: string }
73
76
  /** Slot-admission priority for an active build; never changes the ticket. */
74
- | { kind: 'priority'; priority: TicketPriority }
77
+ | { kind: 'priority'; priority: BuildPriority }
75
78
  | { kind: 'pause' }
76
79
  | { kind: 'resume' }
77
80
  | {
@@ -142,6 +145,8 @@ export type BuildControlResult =
142
145
  reviewRoundCeiling?: { loop: 'plan' | 'code'; value: number }
143
146
  /** A durable post-append fact says this build cannot restart. */
144
147
  terminalSignal?: TerminalSignal
148
+ /** The build is done: the answer only closed its open escalations. */
149
+ acknowledged?: true
145
150
  }
146
151
  | {
147
152
  kind: 'reopened'
@@ -643,17 +648,17 @@ export async function controlBuild(opts: ControlBuildOpts): Promise<BuildControl
643
648
 
644
649
  if (opts.action.kind === 'reopen') return reopenBuild(opts, record, user, opts.action)
645
650
  if (opts.action.kind === 'priority') {
646
- const parsed = ticketPrioritySchema.safeParse(opts.action.priority)
651
+ const parsed = buildPrioritySchema.safeParse(opts.action.priority)
647
652
  if (!parsed.success)
648
653
  throw new BuildControlError(
649
654
  'invalid-argument',
650
- `priority must be urgent or normal, got "${String(opts.action.priority)}"; nothing was recorded`,
655
+ `priority must be urgent, high, normal or low, got "${String(opts.action.priority)}"; nothing was recorded`,
651
656
  )
652
657
  activeState(opts.slug, state)
653
658
  const event = await opts.store.appendIfCurrent(opts.slug, state.lastSeq, {
654
659
  actor: humanActor(user, opts.via),
655
660
  type: 'build.priority-set',
656
- payload: { priority: parsed.data },
661
+ payload: prioritySetPayload(parsed.data),
657
662
  })
658
663
  if (event === null) return controlBuild(opts)
659
664
  return { kind: 'command', slug: opts.slug, command: 'priority', event }
@@ -669,6 +674,8 @@ export async function controlBuild(opts: ControlBuildOpts): Promise<BuildControl
669
674
  'invalid-argument',
670
675
  `hold reason must be 1–${HOLD_REASON_LIMIT} characters after trimming; nothing was recorded`,
671
676
  )
677
+ if (opts.action.kind === 'answer' && state.status === 'done')
678
+ return acknowledgeDoneEscalations(opts, opts.action, state, user)
672
679
  activeState(opts.slug, state)
673
680
  switch (opts.action.kind) {
674
681
  case 'pause':
@@ -1199,6 +1206,65 @@ export async function controlBuild(opts: ControlBuildOpts): Promise<BuildControl
1199
1206
  }
1200
1207
  }
1201
1208
 
1209
+ /** An escalation raised after completion, such as a post-landing integration
1210
+ * audit, is closed by guidance or a bare answer. Nothing else is recorded: a
1211
+ * done build never resumes, so modes that change an active build are refused
1212
+ * before any write or spec read. */
1213
+ async function acknowledgeDoneEscalations(
1214
+ opts: ControlBuildOpts,
1215
+ action: Extract<BuildControlAction, { kind: 'answer' }>,
1216
+ state: BuildState,
1217
+ user: string,
1218
+ ): Promise<BuildControlResult> {
1219
+ if (action.resolve !== undefined || action.reviewRoundCeiling !== undefined)
1220
+ throw new BuildControlError(
1221
+ 'inactive',
1222
+ `build "${opts.slug}" is done; an answer can only acknowledge its open escalations ` +
1223
+ 'with guidance text or a bare answer — --revise-spec, --revise-spec-from-ticket, ' +
1224
+ '--dismiss, --accept-target and --review-round-ceiling change an active build; ' +
1225
+ 'nothing was recorded',
1226
+ )
1227
+ const captured = action.escalationIds === undefined ? undefined : new Set(action.escalationIds)
1228
+ const open = selectedAll(state, captured)
1229
+ if (open.length === 0) {
1230
+ if (captured === undefined) activeState(opts.slug, state)
1231
+ throw new BuildControlError(
1232
+ 'no-open-escalations',
1233
+ `build "${opts.slug}" is no longer blocked by the captured escalation(s)`,
1234
+ )
1235
+ }
1236
+ const guidance = (action.text ?? '').trim()
1237
+ const resolution = guidance === '' ? 'retry' : 'guidance'
1238
+ const answer = guidance === '' ? DONE_ACKNOWLEDGEMENT_ANSWER : guidance
1239
+ const actor = humanActor(user, opts.via)
1240
+ let count = 0
1241
+ for (const escalation of open) {
1242
+ for (;;) {
1243
+ const fresh = (await readBuildFacts(opts.store, opts.slug)).value.state
1244
+ if (fresh.status !== 'done') activeState(opts.slug, fresh)
1245
+ if (!fresh.openEscalations.some((item) => item.id === escalation.id)) break
1246
+ if (
1247
+ await opts.store.appendIfCurrent(opts.slug, fresh.lastSeq, {
1248
+ actor,
1249
+ type: 'escalation.answered',
1250
+ payload: { id: escalation.id, answer, resolution },
1251
+ })
1252
+ ) {
1253
+ count += 1
1254
+ break
1255
+ }
1256
+ }
1257
+ }
1258
+ return {
1259
+ kind: 'answered',
1260
+ slug: opts.slug,
1261
+ count,
1262
+ resolution,
1263
+ resumed: false,
1264
+ acknowledged: true,
1265
+ }
1266
+ }
1267
+
1202
1268
  /** Read, validate and deposit a replacement spec body: the supplied file or
1203
1269
  * the build's ticket, which also re-pins the ticket's assets. A supplied body
1204
1270
  * leaves the pinned set alone (`assets` absent). The deposit is inert until a
@@ -34,6 +34,10 @@ export interface DashboardActionAvailability {
34
34
  }
35
35
 
36
36
  export function buildActionAvailability(build: DashboardBuild): DashboardActionAvailability {
37
+ // A completed build with an open escalation: acknowledging it is the only
38
+ // action; the build never resumes, aborts or merges again.
39
+ if (build.statusBasis?.done)
40
+ return { abort: false, discard: false, autoMerge: false, answer: true }
37
41
  return {
38
42
  ...(dashboardBuildControl(build.status)
39
43
  ? { primary: dashboardBuildControl(build.status)!.action }
@@ -1,6 +1,7 @@
1
1
  import { distanceSuffix } from './target-distance'
2
2
  import type { Config } from '../../config/schema'
3
3
  import type { BuildState } from '../../kernel/reducer'
4
+ import { openOnDone } from '../../kernel/done-escalations'
4
5
  import type { LeafRestackState } from '../../kernel/leaf-restack-state'
5
6
  import {
6
7
  integrationComplete,
@@ -98,25 +99,30 @@ export function projectIntegrationRow(
98
99
  state: done ? 'done' : active ? 'current' : 'pending',
99
100
  ...(qualifier ? { qualifier } : {}),
100
101
  })
102
+ const merged = state.status === 'done' && state.outcome === 'merged'
101
103
  const conflicted = state.nodeRestack?.conflict || (restack.active && restack.replay?.conflicted)
102
- const alert: IntegrationRow['alert'] = state.janitor?.attention
103
- ? { tone: 'red', text: `Janitor failing: ${state.janitor.message}` }
104
- : conflicted
105
- ? {
106
- tone: 'red',
107
- text: `restack onto ${destination} conflicted — open the detail view for files`,
108
- }
109
- : failed.length
104
+ // A landed node with an open escalation (the post-landing audit) shows its
105
+ // question: the row exists only until an operator acknowledges it.
106
+ const alert: IntegrationRow['alert'] = openOnDone(state)
107
+ ? { tone: 'red', text: state.openEscalations.map((open) => open.question).join(' ') }
108
+ : state.janitor?.attention
109
+ ? { tone: 'red', text: `Janitor failing: ${state.janitor.message}` }
110
+ : conflicted
110
111
  ? {
111
112
  tone: 'red',
112
- text: `${failed.join(', ')} failed — file a repair child targeting ${record.ticket?.id ?? record.slug}`,
113
+ text: `restack onto ${destination} conflicted — open the detail view for files`,
113
114
  }
114
- : ready && mode === 'consent' && state.landing?.command?.kind !== 'land'
115
+ : failed.length
115
116
  ? {
116
- tone: 'yellow',
117
- text: `ready to merge into ${destination} — press l, or ab merge ${record.slug}`,
117
+ tone: 'red',
118
+ text: `${failed.join(', ')} failed — file a repair child targeting ${record.ticket?.id ?? record.slug}`,
118
119
  }
119
- : undefined
120
+ : ready && mode === 'consent' && state.landing?.command?.kind !== 'land'
121
+ ? {
122
+ tone: 'yellow',
123
+ text: `ready to merge into ${destination} — press l, or ab merge ${record.slug}`,
124
+ }
125
+ : undefined
120
126
  return {
121
127
  destination,
122
128
  parentDistance: nodeParentDistance(state),
@@ -132,20 +138,21 @@ export function projectIntegrationRow(
132
138
  : { known: false },
133
139
  verified,
134
140
  steps: [
135
- step('spec', state.specRev !== undefined, false),
136
- step('open', !!state.nodeOpened, !state.nodeOpened),
137
- step('collect', complete, !!state.nodeOpened && !complete),
141
+ // A merged node's pipeline is over: every step is done.
142
+ step('spec', merged || state.specRev !== undefined, false),
143
+ step('open', merged || !!state.nodeOpened, !merged && !state.nodeOpened),
144
+ step('collect', merged || complete, !merged && !!state.nodeOpened && !complete),
138
145
  step(
139
146
  'verify',
140
- verified,
141
- current && !verified,
147
+ merged || verified,
148
+ !merged && current && !verified,
142
149
  failed.length
143
150
  ? 'failed'
144
151
  : current && !verified
145
152
  ? `${passed}/${expected.length}`
146
153
  : undefined,
147
154
  ),
148
- step('merge', !!state.integration?.landing, ready, mode),
155
+ step('merge', merged || !!state.integration?.landing, !merged && ready, mode),
149
156
  ],
150
157
  ...(alert ? { alert } : {}),
151
158
  }
@@ -153,6 +160,23 @@ export function projectIntegrationRow(
153
160
 
154
161
  /** Recomputed from the whole already-read repository, even on an empty parent delta.
155
162
  * Never mutate cached rows or snapshots; leaf identity is preserved. */
163
+ /** The settled child builds `enrichIntegrationRows` needs records for beyond
164
+ * `listed`: children of the rendered node rows whose ticket identity or title
165
+ * is still unresolved. Bounded by the rendered rows, never by history. */
166
+ export function unresolvedIntegrationRecords(
167
+ rows: readonly DashboardBuild[],
168
+ listed: ReadonlySet<string>,
169
+ ): string[] {
170
+ const wanted = new Set<string>()
171
+ for (const row of rows)
172
+ for (const child of row.integrationDetail?.children ?? []) {
173
+ if (!child.builds?.length) continue
174
+ if (!child.builds.includes(child.id) && child.title !== 'title unavailable') continue
175
+ for (const slug of child.builds) if (!listed.has(slug)) wanted.add(slug)
176
+ }
177
+ return [...wanted]
178
+ }
179
+
156
180
  export function enrichIntegrationRows(
157
181
  rows: readonly DashboardBuild[],
158
182
  records: readonly BuildRecord[] = [],
@@ -1,5 +1,6 @@
1
1
  import { workTargetDistance } from './target-distance'
2
2
  import { openTicketWait, waitingOnLine } from '../../kernel/ticket-wait'
3
+ import { openOnDone } from '../../kernel/done-escalations'
3
4
  import { openPrBackpressureReducer } from '../../kernel/open-pr-backpressure-state'
4
5
  import type { DashboardRollback } from './rollback'
5
6
  import type { DispatchUpgradeState } from '../../kernel/dispatch-upgrade'
@@ -16,7 +17,7 @@ import {
16
17
  epilogueLeaf,
17
18
  slotWaitText,
18
19
  startClaimDemand,
19
- urgentClaimDemand,
20
+ claimDemand,
20
21
  type DispatchCapacity,
21
22
  type SlotState,
22
23
  } from '../../kernel/dispatch-capacity'
@@ -467,9 +468,11 @@ export interface DashboardModel {
467
468
  export function effectiveStatus(state: BuildState): EffectiveStatus | BuildState['status'] {
468
469
  // Terminal outcomes outrank every pending command and visual override. An
469
470
  // acknowledged abort remains in its cleanup display stage, while `done`
470
- // stays filterable as terminal. Only nonterminal abort intent projects as
471
- // `aborting`; blocked and pause/resume overrides follow it.
472
- if (state.status === 'done') return 'done'
471
+ // stays filterable as terminal, unless an escalation raised after
472
+ // completion is still open: that build reads `blocked` until an operator
473
+ // acknowledges it. Only nonterminal abort intent projects as `aborting`;
474
+ // blocked and pause/resume overrides follow it.
475
+ if (state.status === 'done') return openOnDone(state) ? 'blocked' : 'done'
473
476
  if (state.status === 'aborted') return 'cleaning'
474
477
  if (state.pendingCommands.some((command) => command.command === 'abort')) return 'aborting'
475
478
  const resting = restingStatus(state)
@@ -485,7 +488,7 @@ export function effectiveStatus(state: BuildState): EffectiveStatus | BuildState
485
488
  export function restingStatus(
486
489
  state: BuildState,
487
490
  ): Exclude<EffectiveStatus, 'pausing' | 'resuming' | 'aborting'> | 'done' {
488
- if (state.status === 'done') return 'done'
491
+ if (state.status === 'done') return openOnDone(state) ? 'blocked' : 'done'
489
492
  if (state.status === 'aborted') return 'cleaning'
490
493
  if (state.kind === 'node' && integrationFailed(state)) return 'blocked'
491
494
  // A ticket wait whose escalation is the only one open reads as waiting; any
@@ -506,10 +509,13 @@ export function restingStatus(
506
509
  }
507
510
 
508
511
  /** The lifecycle facts a nonterminal build's status word is chosen from
509
- * (`buildStatusText`), or undefined for a `done` build. Display-only. */
512
+ * (`buildStatusText`), or undefined for a `done` build. A `done` build with an
513
+ * open escalation rests `blocked` with the `done` marker and nothing else: no
514
+ * command or merge decision applies to it. Display-only. */
510
515
  export function statusBasis(state: BuildState): StatusBasis | undefined {
511
516
  const resting = restingStatus(state)
512
517
  if (resting === 'done') return undefined
518
+ if (state.status === 'done') return { resting: 'blocked', runner: false, done: true }
513
519
  const pending = (command: string) => state.pendingCommands.some((c) => c.command === command)
514
520
  const settled = epilogueLeaf(state)
515
521
  ? state.landing?.command?.kind === 'hold'
@@ -1080,7 +1086,7 @@ export function projectBuildFromFacts(
1080
1086
  Object.values(state.verifyStage.cancellations)
1081
1087
  .filter((c) => c.seq > cycleSince && c.step === s)
1082
1088
  .map((c) => `not run: cancelled by verify:${c.cause.step}`)
1083
- .at(-1) ?? stepResults.find((r) => r.skipCause === 'post-reconcile-policy')?.reason,
1089
+ .at(-1) ?? stepResults.find((r) => r.skipCause !== undefined)?.reason,
1084
1090
  count,
1085
1091
  timing: timingFor(intervals, phase, cycleSince, frozenNow),
1086
1092
  }),
@@ -1631,7 +1637,7 @@ export function buildDashboard(
1631
1637
  ...(Array.isArray(repositoryEvents)
1632
1638
  ? {}
1633
1639
  : {
1634
- urgentClaims: urgentClaimDemand(repositoryEvents),
1640
+ claims: claimDemand(repositoryEvents),
1635
1641
  startRequests: startClaimDemand(repositoryEvents),
1636
1642
  }),
1637
1643
  openPrs: {
@@ -1,8 +1,8 @@
1
- import { enrichIntegrationRows } from './integration-row'
1
+ import { enrichIntegrationRows, unresolvedIntegrationRecords } from './integration-row'
2
2
  import {
3
3
  dispatchCapacity,
4
4
  startClaimDemand,
5
- urgentClaimDemand,
5
+ claimDemand,
6
6
  type CapacityBuild,
7
7
  } from '../../kernel/dispatch-capacity'
8
8
  import type { DispatchStatus } from '../../kernel/dispatch-status'
@@ -16,6 +16,7 @@ import type { PipelineSourceMeta } from '../../config/pipeline-source'
16
16
  import type { AbEvent } from '../../events/catalog'
17
17
  import { buildReducer, type BuildAcc, type BuildState } from '../../kernel/reducer'
18
18
  import { landingRestackDue } from '../../kernel/engine'
19
+ import { openOnDone } from '../../kernel/done-escalations'
19
20
  import { capacityBuildFromFacts } from '../../kernel/capacity-build'
20
21
  import { leafRestackReducer, type LeafRestackState } from '../../kernel/leaf-restack-state'
21
22
  import {
@@ -30,8 +31,14 @@ import type {
30
31
  StreamRecord,
31
32
  StreamScope,
32
33
  } from '../../store/types'
33
- import { readBuildFacts, type RepositoryReadFacts } from '../../store/reduced-reads'
34
+ import {
35
+ readBuildFacts,
36
+ readDoneEscalations,
37
+ type CurrentBuildFacts,
38
+ type RepositoryReadFacts,
39
+ } from '../../store/reduced-reads'
34
40
  import { dispatchWarningLines, repositoryQueueDepth } from './header'
41
+ import { mapBounded } from '../../web/bounded'
35
42
  import {
36
43
  projectBuild,
37
44
  projectBuildFromFacts,
@@ -45,9 +52,15 @@ import {
45
52
  * row's session history with authoritative stream ids and statuses (SPEC §9).
46
53
  * `getArtifact` is optional: when present, the effective-config artifact's
47
54
  * metadata decorates each row with its pinned pipeline source and revision
48
- * (SPEC §16.1). */
55
+ * (SPEC §16.1). A reader with saved values, the change position, the open
56
+ * builds and the changed-builds feed (every `BuildStore`) takes the bounded
57
+ * path; the listing path serves narrow readers only. */
49
58
  export interface DashboardBuildReader {
50
59
  getReducerValue?: BuildStore['getReducerValue']
60
+ getRepoChangePosition?: BuildStore['getRepoChangePosition']
61
+ listOpenBuilds?: BuildStore['listOpenBuilds']
62
+ listBuildsChangedSince?: BuildStore['listBuildsChangedSince']
63
+ getBuild?: BuildStore['getBuild']
51
64
  listBuildsForRepo(repo: string): Promise<BuildRecord[]>
52
65
  getEvents(slug: string, sinceSeq?: number): Promise<AbEvent[]>
53
66
  listStreams?(scope: StreamScope): Promise<StreamRecord[]>
@@ -101,11 +114,50 @@ interface ReducedEntry {
101
114
 
102
115
  type PollEntry = LiveEntry | TerminalEntry | ReducedEntry
103
116
 
117
+ /** One visible build on the bounded path: its saved facts and row
118
+ * enrichment, so a config change re-projects it without reading events. */
119
+ interface BoundedEntry {
120
+ record: BuildRecord
121
+ facts: CurrentBuildFacts
122
+ enrichment: RowEnrichment
123
+ capacity: CapacityBuild
124
+ build: DashboardBuild | null
125
+ }
126
+
127
+ type BoundedReader = DashboardBuildReader &
128
+ Pick<
129
+ BuildStore,
130
+ | 'getReducerValue'
131
+ | 'getRepoChangePosition'
132
+ | 'listOpenBuilds'
133
+ | 'listBuildsChangedSince'
134
+ | 'getBuild'
135
+ >
136
+
137
+ function boundedReader(reader: DashboardBuildReader): BoundedReader | undefined {
138
+ return reader.getReducerValue !== undefined &&
139
+ reader.getRepoChangePosition !== undefined &&
140
+ reader.listOpenBuilds !== undefined &&
141
+ reader.listBuildsChangedSince !== undefined &&
142
+ reader.getBuild !== undefined
143
+ ? (reader as BoundedReader)
144
+ : undefined
145
+ }
146
+
147
+ /** Whether any visible build is still in flight: a `done` build with an open
148
+ * escalation waits on an operator, never on the pipeline, so it does not hold
149
+ * the fast refresh cadence. */
150
+ export function hasActiveBuilds(snapshot: Pick<DashboardPollSnapshot, 'states'>): boolean {
151
+ for (const state of snapshot.states.values()) if (state.status !== 'done') return true
152
+ return false
153
+ }
154
+
104
155
  /** A build the dashboard no longer shows. `build.aborted` acknowledges
105
156
  * cancellation but begins the checkpointed cleanup saga, so an aborted build
106
- * stays visible until its final `build.completed` fact. */
157
+ * stays visible until its final `build.completed` fact. A `done` build with an
158
+ * open escalation stays visible until an operator acknowledges it. */
107
159
  export function isDashboardTerminal(state: BuildState): boolean {
108
- return state.status === 'done'
160
+ return state.status === 'done' && !openOnDone(state)
109
161
  }
110
162
 
111
163
  export { capacityBuildFromFacts }
@@ -233,7 +285,7 @@ export function repositoryDashboardHeader(input: {
233
285
  ).length,
234
286
  capacity: config.capacity,
235
287
  capacityProjection: dispatchCapacity(input.capacityBuilds, config.capacity, input.now, {
236
- urgentClaims: urgentClaimDemand(repositoryFacts),
288
+ claims: claimDemand(repositoryFacts),
237
289
  openPrs: {
238
290
  policy: config.policy,
239
291
  engaged: repositoryFacts.openPrBackpressure !== undefined,
@@ -269,7 +321,24 @@ function validateDelta(slug: string, sinceSeq: number, events: AbEvent[]): void
269
321
  /**
270
322
  * Process-local, display-only acceleration for the interactive dispatch frame.
271
323
  *
272
- * Every refresh still discovers records with `listBuildsForRepo(repo)`. A first-seen
324
+ * The bounded path (every `BuildStore` reader, so both production frontends)
325
+ * costs the same at 100 and 100,000 builds (SPEC §14):
326
+ *
327
+ * - Cold start (first refresh, or the feed reports a reset): the change
328
+ * position, sampled first as the feed watermark; `listOpenBuilds` (every
329
+ * nonterminal build, aborted cleanup included); the `doneEscalations`
330
+ * rollup; then `getBuild` (escalated done builds only) and the saved
331
+ * `buildReadFacts` value plus row enrichment per candidate.
332
+ * - Refresh: one `listBuildsChangedSince` from the watermark, then `getBuild`,
333
+ * the saved facts and row enrichment per changed build. Nothing changed:
334
+ * the feed read only, zero build reads and zero event rows.
335
+ * - A full enrichment refresh or a config change re-reads row enrichment of
336
+ * the visible builds only and re-projects them from their cached facts.
337
+ *
338
+ * It never lists builds or reads events, and keeps only visible builds.
339
+ *
340
+ * The listing path serves narrow readers (unit tests): every refresh
341
+ * discovers records with `listBuildsForRepo(repo)`. A first-seen
273
342
  * stream uses persisted build facts when available, with no event reads; local
274
343
  * readers without reduced values hydrate from seq 0, then read only after their
275
344
  * reduced `lastSeq`. Empty deltas preserve the exact reduction and
@@ -284,6 +353,12 @@ function validateDelta(slug: string, sinceSeq: number, events: AbEvent[]): void
284
353
  */
285
354
  export class DashboardBuildPollCache {
286
355
  private entries = new Map<string, PollEntry>()
356
+ /** Bounded path: the changed-builds watermark and the visible builds. */
357
+ private feed: string | undefined
358
+ private visible = new Map<string, BoundedEntry>()
359
+ /** Settled child records the visible node rows still resolve titles from;
360
+ * each is read once while a row needs it. */
361
+ private settled = new Map<string, BuildRecord | null>()
287
362
  private committedRevision = 0
288
363
  private refreshTail: Promise<void> = Promise.resolve()
289
364
 
@@ -332,6 +407,9 @@ export class DashboardBuildPollCache {
332
407
  fullEnrichment: boolean,
333
408
  ): Promise<DashboardPollSnapshot> {
334
409
  const configChanged = configRevision !== this.configRevision || config !== this.config
410
+ const bounded = boundedReader(this.reader)
411
+ if (bounded !== undefined)
412
+ return this.refreshBounded(bounded, config, configRevision, configChanged || fullEnrichment)
335
413
  const records = await this.reader.listBuildsForRepo(this.repo)
336
414
  const next = new Map<string, PollEntry>()
337
415
 
@@ -434,12 +512,144 @@ export class DashboardBuildPollCache {
434
512
  return this.snapshot()
435
513
  }
436
514
 
515
+ private async refreshBounded(
516
+ reader: BoundedReader,
517
+ config: Config,
518
+ configRevision: number,
519
+ reenrich: boolean,
520
+ ): Promise<DashboardPollSnapshot> {
521
+ let feed = this.feed
522
+ let next: Map<string, BoundedEntry> | undefined
523
+ if (feed !== undefined) {
524
+ const changed = await reader.listBuildsChangedSince(this.repo, feed)
525
+ // A head below the watermark means the repository was reset.
526
+ if (BigInt(changed.position) >= BigInt(feed)) {
527
+ const visible = new Map(this.visible)
528
+ const changedSlugs = [...new Set(changed.builds.map((build) => build.slug))]
529
+ const reads = await mapBounded(changedSlugs, async (slug) => {
530
+ const record = await reader.getBuild(slug)
531
+ return record === null ? undefined : this.readBounded(reader, record, config)
532
+ })
533
+ changedSlugs.forEach((slug, at) => {
534
+ const entry = reads[at]
535
+ if (entry === undefined) visible.delete(slug)
536
+ else visible.set(slug, entry)
537
+ })
538
+ if (reenrich) {
539
+ const unchanged = [...visible.values()].filter(
540
+ (entry) => !changedSlugs.includes(entry.record.slug),
541
+ )
542
+ const projected = await mapBounded(unchanged, (entry) =>
543
+ this.projectBounded(reader, entry.record, entry.facts, config),
544
+ )
545
+ for (const entry of projected) visible.set(entry.record.slug, entry)
546
+ }
547
+ next = visible
548
+ feed = changed.position
549
+ }
550
+ }
551
+ if (next === undefined) {
552
+ // Cold start. The watermark is sampled before the listings, so a change
553
+ // after it is replayed by the next feed read (a repeat read is harmless).
554
+ feed = await reader.getRepoChangePosition(this.repo)
555
+ const [open, escalated] = await Promise.all([
556
+ reader.listOpenBuilds(this.repo),
557
+ readDoneEscalations(reader, this.repo),
558
+ ])
559
+ const records = new Map(open.map(({ record }) => [record.slug, record]))
560
+ const done = escalated.builds.filter(({ slug }) => !records.has(slug))
561
+ for (const record of await mapBounded(done, ({ slug }) => reader.getBuild(slug)))
562
+ if (record !== null) records.set(record.slug, record)
563
+ const entries = await mapBounded([...records.values()], (record) =>
564
+ this.readBounded(reader, record, config),
565
+ )
566
+ next = new Map()
567
+ for (const entry of entries) if (entry !== undefined) next.set(entry.record.slug, entry)
568
+ }
569
+ const rows = [...next.values()].flatMap((entry) => (entry.build ? [entry.build] : []))
570
+ const settled = new Map<string, BuildRecord | null>()
571
+ const wanted = unresolvedIntegrationRecords(rows, new Set(next.keys()))
572
+ const missing = wanted.filter((slug) => !this.settled.has(slug))
573
+ const read = await mapBounded(missing, (slug) => reader.getBuild(slug))
574
+ missing.forEach((slug, at) => {
575
+ settled.set(slug, read[at] ?? null)
576
+ })
577
+ for (const slug of wanted) if (!settled.has(slug)) settled.set(slug, this.settled.get(slug)!)
578
+ // Publish once, after every read succeeded.
579
+ this.feed = feed
580
+ this.visible = next
581
+ this.settled = settled
582
+ this.config = config
583
+ this.configRevision = configRevision
584
+ this.committedRevision += 1
585
+ return this.boundedSnapshot()
586
+ }
587
+
588
+ /** One build's saved facts, then its row while it is still visible. */
589
+ private async readBounded(
590
+ reader: BoundedReader,
591
+ record: BuildRecord,
592
+ config: Config,
593
+ ): Promise<BoundedEntry | undefined> {
594
+ if (record.repo !== this.repo) return undefined
595
+ const { value: facts } = await readBuildFacts(reader, record.slug)
596
+ if (isDashboardTerminal(facts.state)) return undefined
597
+ return this.projectBounded(reader, record, facts, config)
598
+ }
599
+
600
+ private async projectBounded(
601
+ reader: BoundedReader,
602
+ record: BuildRecord,
603
+ facts: CurrentBuildFacts,
604
+ config: Config,
605
+ ): Promise<BoundedEntry> {
606
+ const enrichment = await readRowEnrichment(reader, record.slug, facts.state.verify.configPin)
607
+ return {
608
+ record,
609
+ facts,
610
+ enrichment,
611
+ capacity: capacityBuildFromFacts(record, facts),
612
+ build: projectRowWithEnrichment(record, facts.state, [], config, enrichment, facts),
613
+ }
614
+ }
615
+
616
+ private boundedSnapshot(): DashboardPollSnapshot {
617
+ const builds: DashboardBuild[] = []
618
+ const states = new Map<string, BuildState>()
619
+ const capacityBuilds: CapacityBuild[] = []
620
+ for (const [slug, entry] of this.visible) {
621
+ // A done build with an open escalation holds no slot.
622
+ if (entry.facts.state.status !== 'done') capacityBuilds.push(entry.capacity)
623
+ states.set(slug, entry.facts.state)
624
+ if (entry.build !== null) builds.push(entry.build)
625
+ }
626
+ builds.sort((a, b) => a.slug.localeCompare(b.slug))
627
+ return {
628
+ revision: this.committedRevision,
629
+ builds: enrichIntegrationRows(
630
+ builds,
631
+ [
632
+ ...[...this.visible.values()].map((entry) => entry.record),
633
+ ...[...this.settled.values()].filter(
634
+ (record): record is BuildRecord => record?.repo === this.repo,
635
+ ),
636
+ ].sort((a, b) => a.createdAt.localeCompare(b.createdAt) || a.slug.localeCompare(b.slug)),
637
+ ),
638
+ states,
639
+ capacityBuilds,
640
+ }
641
+ }
642
+
437
643
  private snapshot(): DashboardPollSnapshot {
438
644
  const builds: DashboardBuild[] = []
439
645
  const states = new Map<string, BuildState>()
440
646
  const capacityBuilds: CapacityBuild[] = []
441
647
  for (const [slug, entry] of this.entries) {
442
648
  if (entry.kind === 'terminal') continue
649
+ states.set(slug, entry.state)
650
+ if (entry.build !== null) builds.push(entry.build)
651
+ // A done build with an open escalation holds no slot.
652
+ if (entry.state.status === 'done') continue
443
653
  capacityBuilds.push({
444
654
  record: entry.record,
445
655
  state: entry.state,
@@ -454,8 +664,6 @@ export class DashboardBuildPollCache {
454
664
  ? entry.restackDue
455
665
  : landingRestackDue(entry.state, { restack: entry.restack }),
456
666
  })
457
- states.set(slug, entry.state)
458
- if (entry.build !== null) builds.push(entry.build)
459
667
  }
460
668
  builds.sort((a, b) => a.slug.localeCompare(b.slug))
461
669
  return {