@defrex/autobuild 1.4.2 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/SPEC.md +512 -101
- package/bin/ab-dispatch-kernel.ts +1 -0
- package/docs/accounts.md +9 -0
- package/docs/agent-runtimes.md +1 -0
- package/docs/answering-blocked-builds.md +7 -3
- package/docs/architecture.md +313 -130
- package/docs/assets/headline-wide.png +0 -0
- package/docs/build-store.md +33 -3
- package/docs/cli.md +2 -1
- package/docs/configuration-overview.md +9 -0
- package/docs/configuration.md +217 -106
- package/docs/dispatcher-hosting.md +19 -3
- package/docs/dispatcher.md +11 -6
- package/docs/glossary.md +1 -1
- package/docs/integration-overview.md +2 -2
- package/docs/integration-tree.md +91 -28
- package/docs/merge-policy.md +28 -9
- package/docs/operating.md +1 -1
- package/docs/operator-api.md +57 -20
- package/docs/operator-surfaces.md +1 -1
- package/docs/plugin-authoring.md +89 -8
- package/docs/remote-store-protocol.md +39 -11
- package/docs/remote-ticket-protocol.md +126 -12
- package/docs/restacking.md +24 -6
- package/docs/seams.md +2 -2
- package/docs/setup.md +19 -13
- package/docs/spec-standard.md +2 -1
- package/docs/ticket-dependencies.md +26 -8
- package/docs/ticket-migration.md +70 -7
- package/docs/ticket-sources.md +82 -5
- package/docs/tickets.md +34 -2
- package/docs/troubleshooting.md +3 -3
- package/docs/verification.md +5 -5
- package/docs/website.md +8 -0
- package/docs/workspaces.md +1 -1
- package/package.json +4 -3
- package/packages/core/src/accounts/hosted-readiness.ts +21 -0
- package/packages/core/src/cli/attention.ts +3 -0
- package/packages/core/src/cli/build-control.ts +36 -12
- package/packages/core/src/cli/connect.ts +9 -18
- package/packages/core/src/cli/context.ts +44 -0
- package/packages/core/src/cli/dashboard/configuration.ts +11 -0
- package/packages/core/src/cli/dashboard/model.ts +51 -11
- package/packages/core/src/cli/dashboard/poll.ts +14 -0
- package/packages/core/src/cli/dashboard/queue.ts +21 -0
- package/packages/core/src/cli/dashboard/render.ts +43 -22
- package/packages/core/src/cli/dispatch-frontend.ts +63 -30
- package/packages/core/src/cli/dispatch-mode.ts +35 -16
- package/packages/core/src/cli/dispatch-preflight.ts +4 -1
- package/packages/core/src/cli/dispatch-repository-feed.ts +40 -11
- package/packages/core/src/cli/dispatch-tickets.ts +47 -0
- package/packages/core/src/cli/dispatch-upgrade-controller.ts +3 -0
- package/packages/core/src/cli/dispatch.ts +522 -145
- package/packages/core/src/cli/help.ts +63 -24
- package/packages/core/src/cli/init-hosted-accounts.ts +54 -0
- package/packages/core/src/cli/init-readiness-remote.ts +16 -3
- package/packages/core/src/cli/init-validation.ts +144 -42
- package/packages/core/src/cli/issue-links.ts +67 -0
- package/packages/core/src/cli/main.ts +32 -15
- package/packages/core/src/cli/pr-summary-publication.ts +38 -7
- package/packages/core/src/cli/publication-settlement.ts +36 -24
- package/packages/core/src/cli/repo-lease.ts +225 -0
- package/packages/core/src/cli/repository-status.ts +203 -49
- package/packages/core/src/cli/status.ts +42 -4
- package/packages/core/src/cli/terminals.ts +37 -2
- package/packages/core/src/cli/ticket-editor.ts +20 -6
- package/packages/core/src/cli/ticket.ts +264 -46
- package/packages/core/src/cli/triage-count-sampler.ts +59 -0
- package/packages/core/src/cli/wait.ts +4 -1
- package/packages/core/src/cli/watch.ts +19 -4
- package/packages/core/src/config/live.ts +45 -4
- package/packages/core/src/config/load.ts +9 -0
- package/packages/core/src/config/pipeline-source.ts +6 -2
- package/packages/core/src/config/ready-assignee.ts +86 -0
- package/packages/core/src/config/schema.ts +202 -38
- package/packages/core/src/distribution-packaging.ts +1 -1
- package/packages/core/src/events/catalog.ts +7 -0
- package/packages/core/src/events/compatibility.ts +2 -1
- package/packages/core/src/events/payloads.ts +85 -0
- package/packages/core/src/events/policy.ts +10 -0
- package/packages/core/src/events/repository.ts +93 -28
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +237 -230
- package/packages/core/src/kernel/build-identity.ts +12 -0
- package/packages/core/src/kernel/change-presence.ts +139 -6
- package/packages/core/src/kernel/dispatch-capacity.ts +189 -19
- package/packages/core/src/kernel/dispatch-status.ts +10 -1
- package/packages/core/src/kernel/dispatch-upgrade.ts +104 -5
- package/packages/core/src/kernel/engine.ts +17 -8
- package/packages/core/src/kernel/finalize-pr-rejection.ts +95 -0
- package/packages/core/src/kernel/generators/build-log.ts +9 -0
- package/packages/core/src/kernel/generators/repository-journals.ts +15 -1
- package/packages/core/src/kernel/harvest.ts +4 -1
- package/packages/core/src/kernel/incremental-fixtures.ts +1 -0
- package/packages/core/src/kernel/integration-completeness.ts +104 -17
- package/packages/core/src/kernel/integration-landing.ts +17 -0
- package/packages/core/src/kernel/integration-state.ts +17 -0
- package/packages/core/src/kernel/issue-keywords.ts +202 -0
- package/packages/core/src/kernel/janitor-failure.ts +96 -5
- package/packages/core/src/kernel/kernel-git.ts +87 -0
- package/packages/core/src/kernel/landing-readiness.ts +25 -17
- package/packages/core/src/kernel/leaf-restack-state.ts +4 -2
- package/packages/core/src/kernel/log-index.ts +1 -1
- package/packages/core/src/kernel/node-issue-links.ts +142 -0
- package/packages/core/src/kernel/node-landing.ts +2 -1
- package/packages/core/src/kernel/node-parent.ts +6 -0
- package/packages/core/src/kernel/node-restack-transaction.ts +2 -0
- package/packages/core/src/kernel/pr-summary.ts +24 -0
- package/packages/core/src/kernel/read-deferrals.ts +75 -12
- package/packages/core/src/kernel/read-facts.ts +32 -1
- package/packages/core/src/kernel/reconcile-restack.ts +1 -1
- package/packages/core/src/kernel/reducer-registry.ts +37 -2
- package/packages/core/src/kernel/reducer.ts +147 -5
- package/packages/core/src/kernel/ticket-preparation.ts +16 -0
- package/packages/core/src/kernel/verify-budget.ts +43 -0
- package/packages/core/src/operator/index.ts +3 -1
- package/packages/core/src/operator/presentation.ts +3 -0
- package/packages/core/src/operator/protocol.ts +38 -2
- package/packages/core/src/operator/query.ts +69 -29
- package/packages/core/src/operator/registry.ts +47 -26
- package/packages/core/src/operator/tickets.ts +77 -10
- package/packages/core/src/plugin-sdk/index.ts +13 -0
- package/packages/core/src/plugins/manifest.ts +1 -1
- package/packages/core/src/plugins/registry.ts +1 -0
- package/packages/core/src/ports/forge/contract.ts +69 -0
- package/packages/core/src/ports/forge/create.ts +5 -0
- package/packages/core/src/ports/forge/fake.ts +184 -3
- package/packages/core/src/ports/forge/git-rewrite.ts +4 -2
- package/packages/core/src/ports/forge/github.ts +175 -38
- package/packages/core/src/ports/forge/local-git.ts +14 -0
- package/packages/core/src/ports/forge/readiness.ts +10 -0
- package/packages/core/src/ports/forge-failure.ts +43 -0
- package/packages/core/src/ports/runner/claude.ts +7 -1
- package/packages/core/src/ports/runner/codex.ts +7 -2
- package/packages/core/src/ports/runner/native-cli-fixture.ts +2 -1
- package/packages/core/src/ports/runner/pi.ts +7 -1
- package/packages/core/src/ports/runner/runtime.ts +3 -0
- package/packages/core/src/ports/runner/start-prompt.ts +37 -0
- package/packages/core/src/ports/tickets/contract.ts +320 -7
- package/packages/core/src/ports/tickets/create.ts +89 -20
- package/packages/core/src/ports/tickets/fake.ts +18 -0
- package/packages/core/src/ports/tickets/file-codec.ts +20 -0
- package/packages/core/src/ports/tickets/file.ts +43 -1
- package/packages/core/src/ports/tickets/github-fake.ts +1123 -0
- package/packages/core/src/ports/tickets/github-issues.ts +431 -0
- package/packages/core/src/ports/tickets/github-validators.ts +194 -0
- package/packages/core/src/ports/tickets/github.ts +2029 -0
- package/packages/core/src/ports/tickets/hosted-index.ts +34 -3
- package/packages/core/src/ports/tickets/issue-links.ts +86 -0
- package/packages/core/src/ports/tickets/lifecycle.ts +60 -4
- package/packages/core/src/ports/tickets/linear.ts +66 -6
- package/packages/core/src/ports/tickets/migration.ts +290 -68
- package/packages/core/src/ports/tickets/operations.ts +98 -12
- package/packages/core/src/ports/tickets/priority.ts +55 -0
- package/packages/core/src/ports/tickets/remote-protocol.ts +195 -29
- package/packages/core/src/ports/tickets/remote.ts +188 -13
- package/packages/core/src/ports/tickets/revision.ts +22 -1
- package/packages/core/src/ports/tickets/states.ts +43 -0
- package/packages/core/src/ports/tickets/tree.ts +58 -12
- package/packages/core/src/ports/tickets/update.ts +12 -2
- package/packages/core/src/ports/types.ts +194 -9
- package/packages/core/src/ports/workspace/commit-preservation.ts +163 -25
- package/packages/core/src/ports/workspace/git-worktree.ts +6 -2
- package/packages/core/src/ports/workspace/harvest-execution.ts +4 -2
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +121 -27
- package/packages/core/src/processes/build-runner.ts +101 -22
- package/packages/core/src/processes/dispatcher.ts +1046 -372
- package/packages/core/src/processes/execution-no-progress.ts +7 -0
- package/packages/core/src/processes/harvest-child.ts +4 -2
- package/packages/core/src/processes/harvest-execution-state.ts +104 -0
- package/packages/core/src/processes/harvest-runner.ts +263 -25
- package/packages/core/src/processes/harvest.ts +5 -8
- package/packages/core/src/processes/tick-publication.ts +12 -2
- package/packages/core/src/processes/ticket-scan-schedule.ts +78 -0
- package/packages/core/src/processes/workspace-preservation.ts +36 -1
- package/packages/core/src/runtime-identity.ts +10 -2
- package/packages/core/src/scenarios/harness.ts +149 -35
- package/packages/core/src/store/adapter.ts +7 -1
- package/packages/core/src/store/contract.ts +83 -2
- package/packages/core/src/store/digest.ts +32 -1
- package/packages/core/src/store/reduced-reads.ts +10 -0
- package/packages/core/src/store/reducer-value-shapes.json +4471 -3427
- package/packages/core/src/store/remote/protocol.ts +2 -0
- package/packages/core/src/store/remote/released-clients.json +22 -0
- package/packages/core/src/store/remote/released-reducer-values/1.5.0.json +26924 -0
- package/packages/core/src/store/remote/released-reducer-values/1.6.0.json +27173 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +4 -0
- package/packages/core/src/store/repo-state-events.ts +2 -0
- package/packages/core/src/store/types.ts +5 -0
- package/packages/core/src/testing/dispatch-read-budget.ts +729 -123
- package/packages/core/src/testing/index.ts +18 -1
- package/packages/core/src/testing/presence-history.ts +79 -0
- package/packages/core/src/testing/reduced-read-budget.ts +1424 -33
- package/packages/core/src/testing/upgrade-generations.ts +77 -0
- package/skills/code-review/SKILL.md +4 -3
- package/skills/finalize/SKILL.md +18 -2
- package/skills/guide/SKILL.md +417 -143
- package/skills/guide/references/accounts.md +9 -0
- package/skills/guide/references/integration-tree.md +91 -28
- package/skills/guide/references/merge-policy.md +28 -9
- package/skills/guide/references/operator-api.md +57 -20
- package/skills/guide/references/plugin-authoring.md +89 -8
- package/skills/guide/references/remote-store-protocol.md +39 -11
- package/skills/guide/references/remote-ticket-protocol.md +126 -12
- package/skills/guide/references/restacking.md +24 -6
- package/skills/guide/references/setup.md +19 -13
- package/skills/guide/references/spec-standard.md +2 -1
- package/skills/guide/references/ticket-dependencies.md +26 -8
- package/skills/guide/references/ticket-migration.md +70 -7
- package/skills/harvest-review/SKILL.md +4 -3
- package/skills/implement/SKILL.md +20 -1
- package/skills/operate/SKILL.md +149 -35
- package/skills/plan/SKILL.md +1 -1
- package/skills/reconcile/SKILL.md +5 -4
- package/skills/spec/SKILL.md +15 -2
- package/skills/tickets/SKILL.md +116 -37
- package/templates/autobuild.toml +5 -0
- package/templates/hosted-service/package.json +2 -2
|
@@ -53,6 +53,18 @@ function splitTrailers(
|
|
|
53
53
|
return { prefix: content.slice(0, start), trailers }
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
/** The message split at its terminal trailer block, by the same rule that
|
|
57
|
+
* reads identity: `body` keeps every byte before the block (including its
|
|
58
|
+
* separator) and `trailers` holds the block's raw lines, or '' when none. */
|
|
59
|
+
export function splitTrailerBlock(
|
|
60
|
+
message: string,
|
|
61
|
+
options: { includesSubject?: boolean } = {},
|
|
62
|
+
): { body: string; trailers: string } {
|
|
63
|
+
const { prefix, trailers } = splitTrailers(message, options.includesSubject !== true)
|
|
64
|
+
if (trailers.length === 0) return { body: message, trailers: '' }
|
|
65
|
+
return { body: prefix, trailers: trailers.map((entry) => entry.raw).join('\n') }
|
|
66
|
+
}
|
|
67
|
+
|
|
56
68
|
export function buildTrailers(message: string): string[] {
|
|
57
69
|
return splitTrailers(message, false)
|
|
58
70
|
.trailers.filter((entry) => entry.key.toLowerCase() === KEY.toLowerCase())
|
|
@@ -106,6 +106,9 @@ export async function observePresence(
|
|
|
106
106
|
return projectPresence(await presenceWitness(git, head), landings, aliases, includeForeign)
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
/** Full reachable history of a sampled head. In-memory only: it is the
|
|
110
|
+
* compaction source for a {@link PresenceProbe} and is never persisted. Older
|
|
111
|
+
* observations may still carry one as historical evidence. */
|
|
109
112
|
export interface PresenceWitness {
|
|
110
113
|
version: 1
|
|
111
114
|
commits: string[]
|
|
@@ -127,14 +130,144 @@ export async function presenceWitness(git: NodeGit, head: string): Promise<Prese
|
|
|
127
130
|
}
|
|
128
131
|
}
|
|
129
132
|
|
|
130
|
-
|
|
131
|
-
|
|
133
|
+
/** Durable, query-scoped presence evidence for one sampled head. It records
|
|
134
|
+
* only the SHAs and direct trailers in the reverse proof closure of
|
|
135
|
+
* `questions`, so its size never depends on the destination's reachable
|
|
136
|
+
* commit count, unrelated landings, or repository history. */
|
|
137
|
+
export interface PresenceProbe {
|
|
138
|
+
version: 1
|
|
139
|
+
/** Sorted unique identities this observation answers. */
|
|
140
|
+
questions: ChangeIdentity[]
|
|
141
|
+
/** Sorted unique SHAs whose reachability from head was tested. */
|
|
142
|
+
commits: string[]
|
|
143
|
+
/** Sorted subset of `commits` reachable from head. */
|
|
144
|
+
reachable: string[]
|
|
145
|
+
/** Sorted build identities whose direct trailer was tested. */
|
|
146
|
+
builds: `build:${string}`[]
|
|
147
|
+
/** Sorted subset of `builds` found as trailers in head's history. */
|
|
148
|
+
trailers: `build:${string}`[]
|
|
149
|
+
}
|
|
150
|
+
export interface PresenceNeeds {
|
|
151
|
+
commits: string[]
|
|
152
|
+
builds: `build:${string}`[]
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const transportedBy = (landing: LandingEvidence): ChangeIdentity[] =>
|
|
156
|
+
landing.contribution ?? [`build:${landing.slug}`]
|
|
157
|
+
|
|
158
|
+
/** The reverse proof closure of `query`: every SHA and direct trailer whose
|
|
159
|
+
* reachability could derive a queried identity. A landing enters only when it
|
|
160
|
+
* transports a closure identity, and contributes only its own two keys. */
|
|
161
|
+
export function presenceNeeds(
|
|
162
|
+
query: Iterable<ChangeIdentity>,
|
|
163
|
+
landings: LandingEvidence[],
|
|
164
|
+
aliases: Map<string, string>,
|
|
165
|
+
): PresenceNeeds {
|
|
166
|
+
const transporters = new Map<ChangeIdentity, LandingEvidence[]>()
|
|
167
|
+
for (const landing of landings)
|
|
168
|
+
for (const item of new Set(transportedBy(landing))) {
|
|
169
|
+
const entries = transporters.get(item) ?? []
|
|
170
|
+
entries.push(landing)
|
|
171
|
+
transporters.set(item, entries)
|
|
172
|
+
}
|
|
173
|
+
const keysOf = new Map<string, string[]>()
|
|
174
|
+
for (const key of aliases.keys()) {
|
|
175
|
+
const original = originalForeign(key, aliases)
|
|
176
|
+
const keys = keysOf.get(original) ?? []
|
|
177
|
+
keys.push(key)
|
|
178
|
+
keysOf.set(original, keys)
|
|
179
|
+
}
|
|
180
|
+
const commits = new Set<string>()
|
|
181
|
+
const builds = new Set<`build:${string}`>()
|
|
182
|
+
const visited = new Set<ChangeIdentity>()
|
|
183
|
+
const pending = [...query]
|
|
184
|
+
while (pending.length) {
|
|
185
|
+
const identity = pending.pop()!
|
|
186
|
+
if (visited.has(identity)) continue
|
|
187
|
+
visited.add(identity)
|
|
188
|
+
if (identity.startsWith('build:')) builds.add(identity as `build:${string}`)
|
|
189
|
+
else {
|
|
190
|
+
const sha = identity.slice('foreign:'.length)
|
|
191
|
+
commits.add(sha)
|
|
192
|
+
for (const key of keysOf.get(sha) ?? []) commits.add(key)
|
|
193
|
+
}
|
|
194
|
+
for (const landing of transporters.get(identity) ?? [])
|
|
195
|
+
pending.push(`build:${landing.slug}`, `foreign:${landing.sha}`)
|
|
196
|
+
}
|
|
197
|
+
return { commits: [...commits].sort(), builds: [...builds].sort() }
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export function covers(probe: PresenceProbe, needs: PresenceNeeds): boolean {
|
|
201
|
+
const commits = new Set(probe.commits)
|
|
202
|
+
const builds = new Set(probe.builds)
|
|
203
|
+
return (
|
|
204
|
+
needs.commits.every((sha) => commits.has(sha)) && needs.builds.every((id) => builds.has(id))
|
|
205
|
+
)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Whether a stored probe can answer `query` under the current landings. The
|
|
209
|
+
* needs of every stored question must be covered, because the persisted
|
|
210
|
+
* answers are recomputed for all of them. */
|
|
211
|
+
export function answers(
|
|
212
|
+
probe: PresenceProbe,
|
|
213
|
+
query: Iterable<ChangeIdentity>,
|
|
214
|
+
landings: LandingEvidence[],
|
|
215
|
+
aliases: Map<string, string>,
|
|
216
|
+
): boolean {
|
|
217
|
+
const questions = new Set(probe.questions)
|
|
218
|
+
for (const id of query) if (!questions.has(id)) return false
|
|
219
|
+
return covers(probe, presenceNeeds(probe.questions, landings, aliases))
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export function compactProbe(
|
|
223
|
+
witness: PresenceWitness,
|
|
224
|
+
questions: Iterable<ChangeIdentity>,
|
|
225
|
+
landings: LandingEvidence[],
|
|
226
|
+
aliases: Map<string, string>,
|
|
227
|
+
): PresenceProbe {
|
|
228
|
+
const normalized = normalizeIdentities(questions)
|
|
229
|
+
const needs = presenceNeeds(normalized, landings, aliases)
|
|
230
|
+
const reachable = new Set(witness.commits)
|
|
231
|
+
const trailers = new Set(witness.identities)
|
|
232
|
+
return {
|
|
233
|
+
version: 1,
|
|
234
|
+
questions: normalized,
|
|
235
|
+
commits: needs.commits,
|
|
236
|
+
reachable: needs.commits.filter((sha) => reachable.has(sha)),
|
|
237
|
+
builds: needs.builds,
|
|
238
|
+
trailers: needs.builds.filter((id) => trailers.has(id)),
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Presence answers for only the probe's questions. The unrestricted
|
|
243
|
+
* expansion is local: it is never returned, persisted, or hashed. */
|
|
244
|
+
export function projectProbe(
|
|
245
|
+
probe: PresenceProbe,
|
|
246
|
+
landings: LandingEvidence[],
|
|
247
|
+
aliases = new Map<string, string>(),
|
|
248
|
+
): ChangeIdentity[] {
|
|
249
|
+
const present = new Set(
|
|
250
|
+
projectPresence(
|
|
251
|
+
{ version: 1, commits: probe.reachable, identities: probe.trailers },
|
|
252
|
+
landings,
|
|
253
|
+
aliases,
|
|
254
|
+
),
|
|
255
|
+
)
|
|
256
|
+
return normalizeIdentities(probe.questions.filter((id) => present.has(id)))
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export function probeEvidence(probe: PresenceProbe, identities: ChangeIdentity[]): string {
|
|
260
|
+
const sorted = <T extends string>(items: Iterable<T>) => [...new Set(items)].sort()
|
|
261
|
+
return `presence-v4:${createHash('sha256')
|
|
132
262
|
.update(
|
|
133
263
|
JSON.stringify([
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
264
|
+
probe.version,
|
|
265
|
+
sorted(probe.questions),
|
|
266
|
+
sorted(probe.commits),
|
|
267
|
+
sorted(probe.reachable),
|
|
268
|
+
sorted(probe.builds),
|
|
269
|
+
sorted(probe.trailers),
|
|
270
|
+
sorted(identities),
|
|
138
271
|
]),
|
|
139
272
|
)
|
|
140
273
|
.digest('hex')}`
|
|
@@ -1,34 +1,143 @@
|
|
|
1
1
|
import type { TicketRef } from '../ontology'
|
|
2
2
|
import type { BuildRecord } from '../store/types'
|
|
3
3
|
import type { BuildState } from './reducer'
|
|
4
|
-
import { integrationNeedsRunner } from './integration-state'
|
|
4
|
+
import { integrationAdmissible, integrationNeedsRunner } from './integration-state'
|
|
5
5
|
|
|
6
|
-
/** Repository-scoped, reduced facts. Provisioning reserves a slot before a workspace exists.
|
|
6
|
+
/** Repository-scoped, reduced facts. Provisioning reserves a slot before a workspace exists.
|
|
7
|
+
*
|
|
8
|
+
* `capacity` counts builds running work. A leaf that has finished its pipeline
|
|
9
|
+
* (settled, see `epilogueLeaf`) and holds no runner is parked: it waits for a
|
|
10
|
+
* merge decision, merge gates or the forge and holds no slot, though it keeps
|
|
11
|
+
* its workspace. Every other unfinished leaf holds a slot, paused or blocked
|
|
12
|
+
* included. Nodes hold a slot only while they need a runner. */
|
|
7
13
|
export interface CapacityBuild {
|
|
8
14
|
record: BuildRecord
|
|
9
15
|
state: BuildState
|
|
10
16
|
workspace: boolean
|
|
11
17
|
provisioning?: boolean
|
|
18
|
+
/** The engine's awaiting-landing restack is due (`landingRestackDue`); omitted means false. */
|
|
19
|
+
restackDue?: boolean
|
|
12
20
|
}
|
|
13
21
|
|
|
22
|
+
/** The runner a node or parked leaf has durably requested and does not yet hold. */
|
|
23
|
+
export type SlotRequest = 'verification' | 'reconcile'
|
|
24
|
+
|
|
14
25
|
export interface DispatchCapacity {
|
|
15
26
|
configured: number
|
|
16
27
|
occupied: number
|
|
17
28
|
effective: number
|
|
18
29
|
borrowingNodes: string[]
|
|
30
|
+
/** Nodes admitted ahead of new ticket claims; omitted when none wait, and by an older server. */
|
|
31
|
+
waitingNodes?: { slug: string; request: SlotRequest }[]
|
|
32
|
+
/** Parked leaves admitted ahead of new ticket claims; omitted when none wait, and by an older server. */
|
|
33
|
+
waitingBuilds?: { slug: string; request: SlotRequest }[]
|
|
19
34
|
}
|
|
20
35
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
36
|
+
/** A provisioning marker or continuation, or a live lease: a runner is working. */
|
|
37
|
+
function runnerAllocated(build: CapacityBuild, now: Date): boolean {
|
|
38
|
+
return (
|
|
39
|
+
!!build.provisioning ||
|
|
40
|
+
(build.record.lease !== undefined && Date.parse(build.record.lease.expiresAt) > now.getTime())
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** A workspace, a provisioning marker or a live lease holds runner capacity. */
|
|
45
|
+
function allocated(build: CapacityBuild, now: Date): boolean {
|
|
46
|
+
return build.workspace || runnerAllocated(build, now)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The position the dispatcher records as settled: the later of the current
|
|
50
|
+
* verify cycle's start and the latest finalize completion. A reconcile,
|
|
51
|
+
* restack or config supersession opens a new cycle and so a new key. */
|
|
52
|
+
export function settlementKey(state: BuildState): number {
|
|
53
|
+
return Math.max(state.verify.cycleSince, state.finalizeCompletedSeq)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function terminal(state: BuildState): boolean {
|
|
57
|
+
return state.status === 'done' || state.status === 'aborted'
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** A nonterminal leaf that finished its pipeline (every verify step and
|
|
61
|
+
* finalize post-step) for the current spec at least once, as recorded by
|
|
62
|
+
* `pipeline.settled`. A spec revision after settlement makes it unfinished. */
|
|
63
|
+
export function epilogueLeaf(state: BuildState): boolean {
|
|
64
|
+
return (
|
|
65
|
+
state.kind !== 'node' && !terminal(state) && (state.pipelineSettled ?? 0) > state.restartSince
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** A provider-observable execution (one with a command id) stays open until
|
|
70
|
+
* supervision records its end on provider proof, so it holds its runner past
|
|
71
|
+
* an expired lease, unknown liveness included. A local execution's liveness
|
|
72
|
+
* is its lease. */
|
|
73
|
+
function executionOpen(state: BuildState): boolean {
|
|
74
|
+
return state.openExecution?.commandId !== undefined
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** A finished leaf with no runner working. It holds no slot; its workspace does not count. */
|
|
78
|
+
export function parkedLeaf(build: CapacityBuild, now: Date): boolean {
|
|
79
|
+
return epilogueLeaf(build.state) && !runnerAllocated(build, now) && !executionOpen(build.state)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** A finished leaf whose latest verify cycle or finalize has not been settled
|
|
83
|
+
* since: it must re-verify before it waits for its merge decision again. */
|
|
84
|
+
export function epilogueUnsettled(state: BuildState): boolean {
|
|
85
|
+
return epilogueLeaf(state) && (state.pipelineSettled ?? 0) < settlementKey(state)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The dispatcher should record a `pipeline.settled` fact when the engine's
|
|
89
|
+
* decision for this leaf is `wait awaiting-pr`. */
|
|
90
|
+
export function settlementDue(state: BuildState): boolean {
|
|
24
91
|
return (
|
|
25
|
-
state.kind !== 'node'
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
92
|
+
state.kind !== 'node' &&
|
|
93
|
+
!terminal(state) &&
|
|
94
|
+
state.finalizeCompletedSeq > state.restartSince &&
|
|
95
|
+
(state.pipelineSettled ?? 0) < settlementKey(state)
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function occupiesCapacity(build: CapacityBuild, now: Date): boolean {
|
|
100
|
+
const { state } = build
|
|
101
|
+
if (terminal(state)) return false
|
|
102
|
+
if (state.kind !== 'node') return !parkedLeaf(build, now)
|
|
103
|
+
return !!state.nodeRestack?.conflict || (integrationNeedsRunner(state) && allocated(build, now))
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** A parked leaf's durable request for a runner, or undefined. */
|
|
107
|
+
function leafSlotRequest(build: CapacityBuild, now: Date): SlotRequest | undefined {
|
|
108
|
+
const { state } = build
|
|
109
|
+
if (
|
|
110
|
+
!parkedLeaf(build, now) ||
|
|
111
|
+
state.status === 'paused' ||
|
|
112
|
+
state.status === 'blocked' ||
|
|
113
|
+
(state.compatibility?.decisiveFacts ?? 0) > 0 ||
|
|
114
|
+
state.targetRewrite !== undefined
|
|
115
|
+
)
|
|
116
|
+
return undefined
|
|
117
|
+
if (state.prState === 'conflicted') return 'reconcile'
|
|
118
|
+
if (build.restackDue || epilogueUnsettled(state)) return 'verification'
|
|
119
|
+
return undefined
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** A node's or parked leaf's durable request for a runner it does not hold
|
|
123
|
+
* yet. Admission outranks new ticket claims, so this never depends on when a
|
|
124
|
+
* tick saw it. */
|
|
125
|
+
export function slotRequest(build: CapacityBuild, now: Date): SlotRequest | undefined {
|
|
126
|
+
const { state } = build
|
|
127
|
+
if (state.kind !== 'node') return leafSlotRequest(build, now)
|
|
128
|
+
if (
|
|
129
|
+
state.status === 'done' ||
|
|
130
|
+
state.status === 'aborted' ||
|
|
131
|
+
state.status === 'paused' ||
|
|
132
|
+
state.status === 'blocked' ||
|
|
133
|
+
// Mixed-version deferral withholds every decision, admission included.
|
|
134
|
+
(state.compatibility?.decisiveFacts ?? 0) > 0 ||
|
|
135
|
+
allocated(build, now)
|
|
31
136
|
)
|
|
137
|
+
return undefined
|
|
138
|
+
if (state.nodeRestack?.conflict) return state.openEscalations.length ? undefined : 'reconcile'
|
|
139
|
+
if (integrationAdmissible(state) && integrationNeedsRunner(state)) return 'verification'
|
|
140
|
+
return undefined
|
|
32
141
|
}
|
|
33
142
|
|
|
34
143
|
type Identity = (ref: TicketRef, build?: string) => string
|
|
@@ -97,12 +206,7 @@ export function dispatchCapacity(
|
|
|
97
206
|
.filter((build) => {
|
|
98
207
|
if (build.state.kind !== 'node' || !occupiesCapacity(build, now)) return false
|
|
99
208
|
// A waiting conflict owns capacity too, but only allocated runner work borrows.
|
|
100
|
-
if (
|
|
101
|
-
!build.workspace &&
|
|
102
|
-
!build.provisioning &&
|
|
103
|
-
!(build.record.lease && Date.parse(build.record.lease.expiresAt) > now.getTime())
|
|
104
|
-
)
|
|
105
|
-
return false
|
|
209
|
+
if (!allocated(build, now)) return false
|
|
106
210
|
const admission = nodeCapacity(unique, build.record.slug, now, identity)
|
|
107
211
|
return (
|
|
108
212
|
occupied > configured &&
|
|
@@ -112,16 +216,82 @@ export function dispatchCapacity(
|
|
|
112
216
|
})
|
|
113
217
|
.map((build) => build.record.slug)
|
|
114
218
|
.sort()
|
|
219
|
+
const waiting = (kind: 'node' | 'leaf') =>
|
|
220
|
+
unique
|
|
221
|
+
.flatMap((build) => {
|
|
222
|
+
if ((build.state.kind === 'node') !== (kind === 'node')) return []
|
|
223
|
+
const request = slotRequest(build, now)
|
|
224
|
+
return request ? [{ slug: build.record.slug, request }] : []
|
|
225
|
+
})
|
|
226
|
+
.sort((a, b) => (a.slug < b.slug ? -1 : a.slug > b.slug ? 1 : 0))
|
|
227
|
+
const waitingNodes = waiting('node')
|
|
228
|
+
const waitingBuilds = waiting('leaf')
|
|
115
229
|
return {
|
|
116
230
|
configured,
|
|
117
231
|
occupied,
|
|
118
232
|
effective: borrowingNodes.length ? Math.max(configured, occupied) : configured,
|
|
119
233
|
borrowingNodes,
|
|
234
|
+
...(waitingNodes.length ? { waitingNodes } : {}),
|
|
235
|
+
...(waitingBuilds.length ? { waitingBuilds } : {}),
|
|
120
236
|
}
|
|
121
237
|
}
|
|
122
238
|
|
|
239
|
+
/** Slots left for new ticket claims. A node verification request reserves one
|
|
240
|
+
* slot until the node holds it; a node reconcile request already occupies one.
|
|
241
|
+
* A parked build's request occupies nothing, so every one reserves a slot.
|
|
242
|
+
* Never more than the configured budget minus occupied builds.
|
|
243
|
+
*
|
|
244
|
+
* The dispatcher refines the projection with its own decisions this tick:
|
|
245
|
+
* `settled` drops waiters it found waiting for their PR, `denied` adds
|
|
246
|
+
* builds its admission gate turned away. Status surfaces omit `adjust`. */
|
|
247
|
+
export function intakeCapacity(
|
|
248
|
+
capacity: DispatchCapacity,
|
|
249
|
+
adjust: { settled?: ReadonlySet<string>; denied?: ReadonlySet<string> } = {},
|
|
250
|
+
): number {
|
|
251
|
+
const nodes = (capacity.waitingNodes ?? []).filter(
|
|
252
|
+
(node) => node.request === 'verification',
|
|
253
|
+
).length
|
|
254
|
+
const builds = new Set(
|
|
255
|
+
(capacity.waitingBuilds ?? [])
|
|
256
|
+
.map((build) => build.slug)
|
|
257
|
+
.filter((slug) => !adjust.settled?.has(slug)),
|
|
258
|
+
)
|
|
259
|
+
for (const slug of adjust.denied ?? []) builds.add(slug)
|
|
260
|
+
return capacity.configured - capacity.occupied - nodes - builds.size
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** Shared wording for one node or parked build waiting on a runner slot. */
|
|
264
|
+
export function slotWaitText(request: SlotRequest): string {
|
|
265
|
+
return `${request} waiting for a slot ahead of new ticket claims`
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** Shared wording for every node and parked build waiting on a runner slot, or `''`. */
|
|
269
|
+
export function waitingExplanation(
|
|
270
|
+
capacity?: DispatchCapacity,
|
|
271
|
+
opts: { requests?: boolean } = {},
|
|
272
|
+
): string {
|
|
273
|
+
const clause = (noun: string, waiting: { slug: string; request: SlotRequest }[]) =>
|
|
274
|
+
waiting.length
|
|
275
|
+
? [
|
|
276
|
+
`${waiting.length} ${noun}${waiting.length === 1 ? '' : 's'} waiting for a slot ahead of new ticket claims: ${waiting.map((entry) => (opts.requests ? `${entry.slug} (${entry.request})` : entry.slug)).join(', ')}`,
|
|
277
|
+
]
|
|
278
|
+
: []
|
|
279
|
+
return [
|
|
280
|
+
...clause('node', capacity?.waitingNodes ?? []),
|
|
281
|
+
...clause('parked build', capacity?.waitingBuilds ?? []),
|
|
282
|
+
].join('; ')
|
|
283
|
+
}
|
|
284
|
+
|
|
123
285
|
/** Shared wording for the terminal and browser control lines. */
|
|
124
286
|
export function capacityExplanation(capacity?: DispatchCapacity): string {
|
|
125
|
-
if (!capacity
|
|
126
|
-
|
|
287
|
+
if (!capacity) return ''
|
|
288
|
+
const clauses: string[] = []
|
|
289
|
+
if (capacity.borrowingNodes.length)
|
|
290
|
+
clauses.push(
|
|
291
|
+
`${capacity.borrowingNodes.length} node${capacity.borrowingNodes.length === 1 ? '' : 's'} using descendant-held slots: ${capacity.borrowingNodes.join(', ')}`,
|
|
292
|
+
)
|
|
293
|
+
const waiting = waitingExplanation(capacity)
|
|
294
|
+
if (waiting) clauses.push(waiting)
|
|
295
|
+
if (!clauses.length) return ''
|
|
296
|
+
return ` (${capacity.configured} configured; ${clauses.join('; ')})`
|
|
127
297
|
}
|
|
@@ -14,9 +14,13 @@ export interface DispatchStatus {
|
|
|
14
14
|
queued?: number
|
|
15
15
|
/** Standing count from newer tick facts; absent for historical events. */
|
|
16
16
|
creationWithheld?: number
|
|
17
|
+
/** Display-only triage-state count from newer interactive tick facts;
|
|
18
|
+
* absent when the dispatcher published none (unknown). */
|
|
19
|
+
triage?: number
|
|
17
20
|
yieldedHolder?: string
|
|
18
21
|
availableUpgrade?: string
|
|
19
22
|
forgeReadinessFailures?: RepositoryEventPayload<'dispatcher.forge-readiness-failed'>[]
|
|
23
|
+
/** Startup configuration warnings, including forge capability gaps. */
|
|
20
24
|
roleWarnings: string[]
|
|
21
25
|
diagnostics: string[]
|
|
22
26
|
/** Latest notice of warning/failure severity, retained independently from routine notices. */
|
|
@@ -111,6 +115,8 @@ export function reduceDispatchStatus(
|
|
|
111
115
|
case 'dispatcher.tick-completed':
|
|
112
116
|
state.queued = event.payload.queued
|
|
113
117
|
state.creationWithheld = event.payload.counters.creationWithheld
|
|
118
|
+
if (event.payload.triage !== undefined) state.triage = event.payload.triage
|
|
119
|
+
else delete state.triage
|
|
114
120
|
state.diagnostics = [
|
|
115
121
|
...event.payload.janitorDiagnostics,
|
|
116
122
|
...event.payload.ticketDiagnostics,
|
|
@@ -134,6 +140,9 @@ export function reduceDispatchStatus(
|
|
|
134
140
|
}
|
|
135
141
|
state.warningNotice = state.notice
|
|
136
142
|
break
|
|
143
|
+
case 'dispatcher.summary-handoff':
|
|
144
|
+
// Routine guest yield for PR-summary publication: no notice at all.
|
|
145
|
+
break
|
|
137
146
|
case 'dispatcher.harvest-runner-failed':
|
|
138
147
|
state.notice = errorNotice('harvest runner failed', event.payload.error)
|
|
139
148
|
state.warningNotice = state.notice
|
|
@@ -165,7 +174,7 @@ export function reduceDispatchStatus(
|
|
|
165
174
|
|
|
166
175
|
/** Bump when `DispatchStatus`'s shape or fold semantics change (it is its own
|
|
167
176
|
* accumulator: `lastSeq` makes the fold skip already-seen events). */
|
|
168
|
-
export const DISPATCH_STATUS_REDUCER_VERSION =
|
|
177
|
+
export const DISPATCH_STATUS_REDUCER_VERSION = 5
|
|
169
178
|
|
|
170
179
|
/** The incremental form of `reduceDispatchStatus` for one run. The run is a
|
|
171
180
|
* parameter, so this is a factory. */
|
|
@@ -25,6 +25,82 @@ export interface DispatchUpgradeState {
|
|
|
25
25
|
lastRollback?: Fact<'dispatcher.runtime-rolled-back'>
|
|
26
26
|
holds: Record<string, Fact<'dispatcher.runtime-rolled-back'>>
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Retention window for every map in the dispatch-upgrade state. The state is
|
|
30
|
+
* read on every dispatch tick, dashboard poll and status read, so it must not
|
|
31
|
+
* grow with the number of dispatcher generations. Every decision reads the
|
|
32
|
+
* authoritative generation, its immediate predecessor, the run that just
|
|
33
|
+
* started, a recently observed lease owner, or the newest handoffs, so recent
|
|
34
|
+
* runs suffice. Eviction never drops the authoritative run, the run holding the
|
|
35
|
+
* newest accepted handoff (each handoff captures every then-open remote
|
|
36
|
+
* execution), or the three newest settled runs (status's latest earlier
|
|
37
|
+
* outcome). Full history stays in the repository journal.
|
|
38
|
+
*/
|
|
39
|
+
export const UPGRADE_HISTORY_LIMIT = 16
|
|
40
|
+
|
|
41
|
+
/** The newest fact sequence recorded on a run, or -1 when it has none. */
|
|
42
|
+
export function upgradeRunRecency(run: UpgradeRun): number {
|
|
43
|
+
return Math.max(
|
|
44
|
+
-1,
|
|
45
|
+
...[
|
|
46
|
+
run.resolved,
|
|
47
|
+
run.detected,
|
|
48
|
+
run.failure,
|
|
49
|
+
run.prepared,
|
|
50
|
+
run.request,
|
|
51
|
+
run.handoff,
|
|
52
|
+
run.released,
|
|
53
|
+
run.takeover,
|
|
54
|
+
run.completed,
|
|
55
|
+
].map((fact) => fact?.seq ?? -1),
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const settledSeq = (run: UpgradeRun) => (run.completed ?? run.failure)?.seq ?? -1
|
|
60
|
+
// Runs without an accepted handoff go first, then completed handoffs; runs
|
|
61
|
+
// still draining an accepted handoff go last.
|
|
62
|
+
const evictionTier = (run: UpgradeRun) => (!run.handoff ? 0 : run.completed ? 1 : 2)
|
|
63
|
+
|
|
64
|
+
function retainRuns(acc: DispatchUpgradeState, touched: string) {
|
|
65
|
+
while (Object.keys(acc.runs).length > UPGRADE_HISTORY_LIMIT) {
|
|
66
|
+
const entries = Object.entries(acc.runs)
|
|
67
|
+
// The newest accepted handoff carries the remote captures authorization needs.
|
|
68
|
+
let newestHandoff: string | undefined
|
|
69
|
+
for (const [id, run] of entries)
|
|
70
|
+
if (
|
|
71
|
+
run.handoff &&
|
|
72
|
+
(!newestHandoff || run.handoff.seq > acc.runs[newestHandoff]!.handoff!.seq)
|
|
73
|
+
)
|
|
74
|
+
newestHandoff = id
|
|
75
|
+
// Status's latest earlier outcome excludes at most the current and
|
|
76
|
+
// live-handoff runs, so the three newest settled runs always contain it.
|
|
77
|
+
const settled = new Set(
|
|
78
|
+
entries
|
|
79
|
+
.filter(([, run]) => settledSeq(run) >= 0)
|
|
80
|
+
.sort(([, a], [, b]) => settledSeq(b) - settledSeq(a))
|
|
81
|
+
.slice(0, 3)
|
|
82
|
+
.map(([id]) => id),
|
|
83
|
+
)
|
|
84
|
+
let victim: string | undefined
|
|
85
|
+
let victimRank: [number, number] = [0, 0]
|
|
86
|
+
for (const [id, run] of entries) {
|
|
87
|
+
if (id === touched || id === acc.authoritativeRun || id === newestHandoff || settled.has(id))
|
|
88
|
+
continue
|
|
89
|
+
const rank: [number, number] = [evictionTier(run), upgradeRunRecency(run)]
|
|
90
|
+
if (
|
|
91
|
+
victim === undefined ||
|
|
92
|
+
rank[0] < victimRank[0] ||
|
|
93
|
+
(rank[0] === victimRank[0] &&
|
|
94
|
+
(rank[1] < victimRank[1] || (rank[1] === victimRank[1] && id < victim)))
|
|
95
|
+
) {
|
|
96
|
+
victim = id
|
|
97
|
+
victimRank = rank
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
delete acc.runs[victim!]
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
28
104
|
function same(a: Handoff, b: Handoff): boolean {
|
|
29
105
|
return (
|
|
30
106
|
a.correlation === b.correlation &&
|
|
@@ -42,20 +118,41 @@ export const dispatchUpgradeReducer = defineReducer<
|
|
|
42
118
|
RepositoryEvent,
|
|
43
119
|
DispatchUpgradeState
|
|
44
120
|
>({
|
|
45
|
-
version:
|
|
121
|
+
version: 7,
|
|
46
122
|
initial: () => ({ runs: {}, holds: {}, lineages: {}, rollbackIds: [] }),
|
|
47
123
|
fold(acc, events) {
|
|
48
124
|
for (const event of events) {
|
|
49
|
-
if (event.type === 'dispatcher.run-started' && event.payload.lineage)
|
|
50
|
-
|
|
125
|
+
if (event.type === 'dispatcher.run-started' && event.payload.lineage) {
|
|
126
|
+
const started = event.payload.run
|
|
127
|
+
// Reinsert so key order is start order. Dispatch run ids are
|
|
128
|
+
// non-integer strings (`<host>-dispatch-<id>`), so JavaScript keeps
|
|
129
|
+
// insertion order; integer-like ids would only change which entry
|
|
130
|
+
// goes first, not the bound.
|
|
131
|
+
delete acc.lineages[started]
|
|
132
|
+
acc.lineages[started] = event.payload.lineage
|
|
133
|
+
for (const run of Object.keys(acc.lineages)) {
|
|
134
|
+
if (Object.keys(acc.lineages).length <= UPGRADE_HISTORY_LIMIT) break
|
|
135
|
+
if (run !== acc.authoritativeRun && run !== started) delete acc.lineages[run]
|
|
136
|
+
}
|
|
137
|
+
}
|
|
51
138
|
// Starts and yielded ticks are not proof of repository authority.
|
|
52
139
|
if (event.type === 'dispatcher.tick-started') acc.authoritativeRun = event.payload.run
|
|
53
140
|
if (event.type === 'dispatcher.runtime-rolled-back') {
|
|
54
141
|
if (acc.rollbackIds.includes(event.payload.correlation)) continue
|
|
55
142
|
acc.rollbackIds.push(event.payload.correlation)
|
|
143
|
+
// Duplicate appends happen only next to the original, so a recent
|
|
144
|
+
// window of correlations still deduplicates them.
|
|
145
|
+
while (acc.rollbackIds.length > UPGRADE_HISTORY_LIMIT) acc.rollbackIds.shift()
|
|
56
146
|
acc.authoritativeRun = event.payload.run
|
|
57
147
|
acc.lastRollback = event
|
|
58
148
|
acc.holds[event.payload.lineage] = event
|
|
149
|
+
const current = acc.lineages[acc.authoritativeRun]
|
|
150
|
+
while (Object.keys(acc.holds).length > UPGRADE_HISTORY_LIMIT) {
|
|
151
|
+
const oldest = Object.entries(acc.holds)
|
|
152
|
+
.filter(([lineage]) => lineage !== current && lineage !== event.payload.lineage)
|
|
153
|
+
.reduce((a, b) => (b[1].seq < a[1].seq ? b : a))
|
|
154
|
+
delete acc.holds[oldest[0]]
|
|
155
|
+
}
|
|
59
156
|
continue
|
|
60
157
|
}
|
|
61
158
|
if (event.type === 'dispatcher.rollback-hold-cleared') {
|
|
@@ -70,8 +167,9 @@ export const dispatchUpgradeReducer = defineReducer<
|
|
|
70
167
|
if (event.type !== 'dispatcher.upgrade-target-resolved' && !('correlation' in event.payload))
|
|
71
168
|
continue
|
|
72
169
|
if (!('run' in event.payload) || typeof event.payload.run !== 'string') continue
|
|
73
|
-
|
|
74
|
-
|
|
170
|
+
const run = event.payload.run
|
|
171
|
+
acc.runs[run] ??= { outstanding: {}, drained: 0, suspended: 0 }
|
|
172
|
+
const state = acc.runs[run]!
|
|
75
173
|
switch (event.type) {
|
|
76
174
|
case 'dispatcher.upgrade-target-resolved':
|
|
77
175
|
state.resolved = event
|
|
@@ -165,6 +263,7 @@ export const dispatchUpgradeReducer = defineReducer<
|
|
|
165
263
|
state.completed ??= event
|
|
166
264
|
break
|
|
167
265
|
}
|
|
266
|
+
retainRuns(acc, run)
|
|
168
267
|
}
|
|
169
268
|
},
|
|
170
269
|
finish: (acc) => structuredClone(acc),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { resolveApprovedVerifySelection } from './plan-verify-selection'
|
|
2
2
|
import { activeVerifyStage } from './verify-stages'
|
|
3
|
+
import { verifyBudgetExhaustedQuestion } from './verify-budget'
|
|
3
4
|
import { verifyMemberKey } from './verify-stage-state'
|
|
4
5
|
import { mixedVersionDeferred } from './mixed-version'
|
|
5
6
|
import { integrationCurrent, integrationConfig, integrationFailed } from './integration-state'
|
|
@@ -575,13 +576,14 @@ function decideNextInternal(state: BuildState, log: LogIndex, config: Config): D
|
|
|
575
576
|
) {
|
|
576
577
|
// Exhaustion escalates once per failure: an exact policy raise for this
|
|
577
578
|
// verify target after the last failure (answered or not) suppresses replay;
|
|
578
|
-
// a NEW failure re-arms it.
|
|
579
|
+
// a NEW failure re-arms it. The question lists the counted failed attempts
|
|
580
|
+
// and their steps; the target stays the last failed step.
|
|
579
581
|
return {
|
|
580
582
|
kind: 'raise-escalation',
|
|
581
583
|
source: 'policy',
|
|
582
584
|
policyCause: 'verify-failure-limit',
|
|
583
585
|
phase: verifyPhase(lastFail.step),
|
|
584
|
-
question:
|
|
586
|
+
question: verifyBudgetExhaustedQuestion(config.policy.maxVerifyAttempts, fails),
|
|
585
587
|
}
|
|
586
588
|
}
|
|
587
589
|
if (pendingFail !== undefined && (stage === undefined || stage.settled)) {
|
|
@@ -780,12 +782,7 @@ function decideNextInternal(state: BuildState, log: LogIndex, config: Config): D
|
|
|
780
782
|
state.reconcileAttempts
|
|
781
783
|
return { kind: 'run-phase', phase: 'reconcile', round: attempt, reconcile: { attempt } }
|
|
782
784
|
}
|
|
783
|
-
if (
|
|
784
|
-
log.restack.target !== undefined &&
|
|
785
|
-
(log.restack.target.sha !== (log.restack.completed?.targetBase ?? log.restack.initialBase) ||
|
|
786
|
-
(state.target !== undefined &&
|
|
787
|
-
(log.restack.postStepAt ?? 0) > (log.restack.completedAt ?? 0)))
|
|
788
|
-
) {
|
|
785
|
+
if (landingRestackDue(state, log)) {
|
|
789
786
|
return { kind: 'restack', trigger: 'awaiting-landing', cycle: cycleBoundary }
|
|
790
787
|
}
|
|
791
788
|
if (state.prState === 'conflicted' && log.lastConflict !== undefined) {
|
|
@@ -839,6 +836,18 @@ function decideNextInternal(state: BuildState, log: LogIndex, config: Config): D
|
|
|
839
836
|
return { kind: 'wait', reason: 'awaiting-pr' }
|
|
840
837
|
}
|
|
841
838
|
|
|
839
|
+
/** The §9 awaiting-landing restack condition: the target moved since the
|
|
840
|
+
* build's last restack base, or a target post-step landed after it. Shared
|
|
841
|
+
* with dispatch capacity, which admits a parked build that must restack. */
|
|
842
|
+
export function landingRestackDue(state: BuildState, log: Pick<LogIndex, 'restack'>): boolean {
|
|
843
|
+
return (
|
|
844
|
+
log.restack.target !== undefined &&
|
|
845
|
+
(log.restack.target.sha !== (log.restack.completed?.targetBase ?? log.restack.initialBase) ||
|
|
846
|
+
(state.target !== undefined &&
|
|
847
|
+
(log.restack.postStepAt ?? 0) > (log.restack.completedAt ?? 0)))
|
|
848
|
+
)
|
|
849
|
+
}
|
|
850
|
+
|
|
842
851
|
// ── Review-loop transition (rules 5 and 6 share one structure — §10) ─────────
|
|
843
852
|
|
|
844
853
|
interface LoopArgs {
|