@defrex/autobuild 1.11.0 → 1.12.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 +186 -57
- package/docs/answering-blocked-builds.md +10 -2
- package/docs/architecture.md +76 -10
- package/docs/assets/headline-wide.png +0 -0
- package/docs/cli.md +1 -1
- package/docs/configuration.md +13 -11
- package/docs/dispatcher.md +5 -4
- package/docs/integration-tree.md +28 -16
- package/docs/operator-api.md +4 -4
- package/docs/operator-surfaces.md +38 -3
- package/docs/optimization-nodes.md +3 -2
- package/docs/tickets.md +1 -1
- package/docs/troubleshooting.md +1 -1
- package/package.json +3 -3
- package/packages/core/src/cli/ambient-errors.ts +17 -0
- package/packages/core/src/cli/bounded-io.ts +174 -0
- package/packages/core/src/cli/dashboard/header.ts +10 -0
- package/packages/core/src/cli/dashboard/model.ts +81 -23
- package/packages/core/src/cli/dashboard/poll.ts +24 -34
- package/packages/core/src/cli/dashboard/render.ts +44 -37
- package/packages/core/src/cli/dashboard/row-text.ts +24 -7
- package/packages/core/src/cli/dashboard/tone-ansi.ts +39 -0
- package/packages/core/src/cli/dashboard/vocabulary.ts +161 -20
- package/packages/core/src/cli/dispatch-frontend.ts +12 -3
- package/packages/core/src/cli/dispatch-handoff.ts +41 -10
- package/packages/core/src/cli/dispatch-launch-contract.ts +5 -0
- package/packages/core/src/cli/dispatch-launcher-cadence.ts +80 -0
- package/packages/core/src/cli/dispatch-launcher.ts +9 -10
- package/packages/core/src/cli/dispatch-preflight.ts +12 -3
- package/packages/core/src/cli/dispatch-release-observer.ts +53 -0
- package/packages/core/src/cli/dispatch-runtime-cache.ts +204 -82
- package/packages/core/src/cli/dispatch-runtime-dependencies.ts +250 -43
- package/packages/core/src/cli/dispatch-upgrade-install.ts +36 -16
- package/packages/core/src/cli/dispatch-upgrade-source.ts +8 -2
- package/packages/core/src/cli/dispatch-yield-observer.ts +82 -0
- package/packages/core/src/cli/dispatch.ts +70 -9
- package/packages/core/src/cli/env.ts +2 -15
- package/packages/core/src/cli/help.ts +5 -4
- package/packages/core/src/cli/main.ts +4 -2
- package/packages/core/src/cli/production-store.ts +102 -0
- package/packages/core/src/cli/repo-state.ts +2 -3
- package/packages/core/src/cli/repository-status.ts +36 -28
- package/packages/core/src/cli/sessionless-store.ts +26 -0
- package/packages/core/src/cli/status.ts +169 -40
- package/packages/core/src/cli/store-opening.ts +15 -58
- package/packages/core/src/cli/store-ref.ts +6 -1
- package/packages/core/src/config/schema.ts +1 -1
- package/packages/core/src/distribution-packaging.ts +156 -18
- package/packages/core/src/events/catalog-identity.ts +28 -0
- package/packages/core/src/events/catalog.ts +3 -9
- package/packages/core/src/events/compatibility.ts +2 -30
- package/packages/core/src/events/payloads.ts +11 -0
- package/packages/core/src/events/policy.ts +3 -0
- package/packages/core/src/events/repository.ts +1 -1
- package/packages/core/src/events/sessions.ts +1 -1
- package/packages/core/src/events/validation-error.ts +12 -0
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +74 -30
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/3064e337cc75f8d6.json +310 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/46196d8f0076496a.json +97 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a1e90a969d32a367.json +307 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/da3bc91c49211eab.json +310 -0
- package/packages/core/src/kernel/auto-merge-default.ts +2 -1
- package/packages/core/src/kernel/capacity-build.ts +21 -0
- package/packages/core/src/kernel/discard-in-flight.ts +13 -0
- package/packages/core/src/kernel/dispatch-capacity.ts +354 -147
- package/packages/core/src/kernel/dispatch-status.ts +139 -0
- package/packages/core/src/kernel/engine.ts +2 -8
- package/packages/core/src/kernel/measurement.ts +24 -0
- package/packages/core/src/kernel/read-facts.ts +9 -369
- package/packages/core/src/kernel/reducer-registry.ts +40 -125
- package/packages/core/src/kernel/reducer-revisions.ts +5 -0
- package/packages/core/src/kernel/reducer-value-entry.ts +98 -0
- package/packages/core/src/kernel/reducer-value-index.ts +75 -0
- package/packages/core/src/kernel/reducer.ts +57 -9
- package/packages/core/src/kernel/reopen-state.ts +10 -0
- package/packages/core/src/kernel/repository-read-facts.ts +375 -0
- package/packages/core/src/kernel/verify-stage-state.ts +145 -3
- package/packages/core/src/operator/presentation.ts +13 -0
- package/packages/core/src/operator/query.ts +47 -41
- package/packages/core/src/operator/registry.ts +3 -3
- package/packages/core/src/ports/workspace/fake.ts +15 -3
- package/packages/core/src/processes/dispatcher.ts +232 -75
- package/packages/core/src/processes/execution-no-progress.ts +1 -0
- package/packages/core/src/store/local/capabilities.ts +115 -0
- package/packages/core/src/store/local/store.ts +86 -56
- package/packages/core/src/store/reduced-reads.ts +9 -1
- package/packages/core/src/store/reducer-value-read.ts +235 -0
- package/packages/core/src/store/reducer-value-shapes.json +3796 -3670
- package/packages/core/src/store/reducer-values.ts +36 -204
- package/packages/core/src/store/remote/released-clients.json +22 -0
- package/packages/core/src/store/remote/released-reducer-values/1.11.1.json +35718 -0
- package/packages/core/src/store/remote/released-reducer-values/1.12.0.json +35806 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +20 -16
- package/packages/core/src/store/rollup-lease.ts +41 -0
- package/packages/core/src/store/rollups.ts +7 -38
- package/packages/core/src/store/snapshots.ts +1 -1
- package/packages/core/src/testing/dispatch-journals.ts +117 -0
- package/packages/core/src/testing/dispatch-read-budget.ts +265 -4
- package/packages/core/src/testing/import-graph.ts +78 -0
- package/packages/core/src/testing/reduced-read-budget.ts +221 -22
- package/packages/core/src/testing/slot-agreement.ts +52 -0
- package/packages/core/src/web/assets/app.js +5 -5
- package/packages/core/src/web/repository-source.ts +6 -2
- package/skills/guide/SKILL.md +126 -47
- package/skills/guide/references/integration-tree.md +28 -16
- package/skills/guide/references/operator-api.md +4 -4
- package/skills/guide/references/optimization-nodes.md +3 -2
- package/skills/operate/SKILL.md +38 -20
- package/templates/hosted-service/package.json +2 -2
|
@@ -111,19 +111,27 @@ import {
|
|
|
111
111
|
dispatchCapacity,
|
|
112
112
|
epilogueLeaf,
|
|
113
113
|
intakeCapacity,
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
leafHoldsSlot,
|
|
115
|
+
escalationCarryInput,
|
|
116
|
+
leafOutsideWait,
|
|
117
|
+
leafSlotRequest,
|
|
118
|
+
legacyNodeRunner,
|
|
119
|
+
legacyNodeRunnerNeed,
|
|
120
|
+
nodeHoldsSlot,
|
|
121
|
+
nodeRunnerWork,
|
|
122
|
+
nodeSlotNeed,
|
|
116
123
|
reservedAhead,
|
|
117
124
|
settlementDue,
|
|
118
125
|
settlementKey,
|
|
119
|
-
slotRequest,
|
|
120
126
|
startCapacity,
|
|
121
127
|
startClaimDemand,
|
|
122
128
|
strandedNodeWorkspace,
|
|
123
129
|
urgentClaimDemand,
|
|
124
130
|
type CapacityBuild,
|
|
125
131
|
type DispatchCapacity,
|
|
132
|
+
type NodeSlotNeed,
|
|
126
133
|
} from '../kernel/dispatch-capacity'
|
|
134
|
+
import { launchInFlight } from '../kernel/verify-stage-state'
|
|
127
135
|
import { attemptCreationKey } from '../kernel/attempt-creation-key'
|
|
128
136
|
import {
|
|
129
137
|
ExecutionFactsMissingError,
|
|
@@ -1290,6 +1298,9 @@ export class Dispatcher {
|
|
|
1290
1298
|
* "Slot admission order"). Nothing was written for them;
|
|
1291
1299
|
* `admitDeferredParked` retries each through its generic path. */
|
|
1292
1300
|
private readonly deferredAdmissions = new Map<string, 'leaf' | 'node' | 'proposer'>()
|
|
1301
|
+
/** Nodes `admitWaitingNodes` admitted in its current verification pass, so
|
|
1302
|
+
* proposer admission counts them even when provisioning or launch failed. */
|
|
1303
|
+
private passNodeAdmissions: Set<string> | undefined
|
|
1293
1304
|
/** Per tick: admission may defer normal parked work. Opened by `runTick`
|
|
1294
1305
|
* when claims can run, closed once urgent claims were evaluated. */
|
|
1295
1306
|
private admissionBoundary = false
|
|
@@ -1992,7 +2003,7 @@ export class Dispatcher {
|
|
|
1992
2003
|
// checked, needs the pass.
|
|
1993
2004
|
const now = this.deps.clock()
|
|
1994
2005
|
const measured = await this.capacityBuilds(launched, true)
|
|
1995
|
-
const projection = dispatchCapacity(measured, config.capacity, now,
|
|
2006
|
+
const projection = dispatchCapacity(measured, config.capacity, now, {
|
|
1996
2007
|
urgentClaims: this.urgentClaims(),
|
|
1997
2008
|
startRequests: this.startClaims(),
|
|
1998
2009
|
})
|
|
@@ -2487,7 +2498,8 @@ export class Dispatcher {
|
|
|
2487
2498
|
if (!this.accountsAvailable()) return 'already-active'
|
|
2488
2499
|
if (await this.forgeCoolingDown()) return 'already-active'
|
|
2489
2500
|
if (await deferMixedVersion(this.store, slug)) return 'already-active'
|
|
2490
|
-
const
|
|
2501
|
+
const launchFacts = await this.store.buildFacts(slug)
|
|
2502
|
+
const launchState = launchFacts.state
|
|
2491
2503
|
// A landed node has nothing left to run; the janitor settles it.
|
|
2492
2504
|
if (nodeLanded(launchState)) return 'already-active'
|
|
2493
2505
|
if (launchState.kind === 'node' && !launchState.nodeRestack?.conflict) {
|
|
@@ -2508,6 +2520,14 @@ export class Dispatcher {
|
|
|
2508
2520
|
if (launched.has(slug)) return 'already-active'
|
|
2509
2521
|
if (launchState.kind !== 'node' && (await this.leafAdmission(slug)) !== 'admit')
|
|
2510
2522
|
return 'already-active'
|
|
2523
|
+
// Every node launch path (cascade, admission, sweep, startup resume) runs
|
|
2524
|
+
// only work the node holds a slot for (SPEC §12); abort and pause
|
|
2525
|
+
// acknowledgements stay ungated.
|
|
2526
|
+
if (launchState.kind === 'node') {
|
|
2527
|
+
const record = await this.store.getBuild(slug)
|
|
2528
|
+
if (record === null || !this.nodeRelaunchAdmitted(record, launchFacts))
|
|
2529
|
+
return 'already-active'
|
|
2530
|
+
}
|
|
2511
2531
|
launched.add(slug)
|
|
2512
2532
|
const facts = (await readBuildFacts(this.store, slug)).value
|
|
2513
2533
|
// Callers reap and reprovision a flagged workspace; an agent never starts
|
|
@@ -4081,8 +4101,9 @@ export class Dispatcher {
|
|
|
4081
4101
|
const builds: CapacityBuild[] = []
|
|
4082
4102
|
for (const { record, digest } of await this.repoBuildDigests(true)) {
|
|
4083
4103
|
if (digest.terminal) continue
|
|
4084
|
-
// A leaf with a runner provisioning
|
|
4085
|
-
//
|
|
4104
|
+
// A leaf with a runner provisioning or launched this tick has an
|
|
4105
|
+
// admission or launch record its served facts already include, so any
|
|
4106
|
+
// read this tick serves it, launch or not.
|
|
4086
4107
|
const allocatedLeaf =
|
|
4087
4108
|
digest.kind !== 'node' &&
|
|
4088
4109
|
(this.continuations.has(record.slug) || !!launched?.has(record.slug))
|
|
@@ -4090,17 +4111,24 @@ export class Dispatcher {
|
|
|
4090
4111
|
? ((allocatedLeaf ? this.store.retainedBuildFacts(record.slug) : undefined) ??
|
|
4091
4112
|
(await this.store.servedBuildFacts(record.slug)))
|
|
4092
4113
|
: await this.store.buildFacts(record.slug)
|
|
4114
|
+
// A node's marker no longer holds a slot: it feeds the stranded
|
|
4115
|
+
// workspace release, the proposer skip and the anchor of a runner an
|
|
4116
|
+
// older dispatcher launched (`legacyNodeRunner`).
|
|
4117
|
+
const marker =
|
|
4118
|
+
digest.kind === 'node'
|
|
4119
|
+
? served
|
|
4120
|
+
? facts.provisionMarker
|
|
4121
|
+
: (await readBuildFacts(this.store, record.slug)).value.provisionMarker
|
|
4122
|
+
: undefined
|
|
4093
4123
|
builds.push({
|
|
4094
4124
|
record,
|
|
4095
4125
|
state: facts.state,
|
|
4096
4126
|
workspace: facts.workspace !== null,
|
|
4097
4127
|
provisioning:
|
|
4098
4128
|
digest.kind === 'node'
|
|
4099
|
-
?
|
|
4100
|
-
? facts.provisionMarker
|
|
4101
|
-
: (await readBuildFacts(this.store, record.slug)).value.provisionMarker) !==
|
|
4102
|
-
undefined
|
|
4129
|
+
? marker !== undefined
|
|
4103
4130
|
: this.continuations.has(record.slug) || !!launched?.has(record.slug),
|
|
4131
|
+
...(marker !== undefined ? { provisioningSeq: marker.seq } : {}),
|
|
4104
4132
|
restackDue: landingRestackDue(facts.state, facts.log),
|
|
4105
4133
|
})
|
|
4106
4134
|
}
|
|
@@ -4162,16 +4190,42 @@ export class Dispatcher {
|
|
|
4162
4190
|
return priority === 'normal' && this.urgentBoundaryOpen() ? 'defer' : 'admit'
|
|
4163
4191
|
}
|
|
4164
4192
|
|
|
4165
|
-
/** Whether a leaf may reserve a runner now
|
|
4166
|
-
*
|
|
4167
|
-
*
|
|
4168
|
-
*
|
|
4169
|
-
*
|
|
4170
|
-
*
|
|
4193
|
+
/** Whether a leaf may reserve a runner now (SPEC §12 "What holds a slot").
|
|
4194
|
+
* A leaf that holds its slot is admitted at once, and so are a leaf waiting
|
|
4195
|
+
* on the outside world and abort and pause acknowledgements, which are never
|
|
4196
|
+
* gated and confer no slot. Every other
|
|
4197
|
+
* leaf needs a free slot among every other build, after the work ahead of
|
|
4198
|
+
* it. Admission is the durable `slot.admitted` fact, appended on the state
|
|
4199
|
+
* this decision read before any lease claim, provisioning or launch, so a
|
|
4200
|
+
* crash after it keeps the slot; runner liveness never admits. A holding
|
|
4201
|
+
* leaf's launch appends one too, its launch record (`launchInFlight`),
|
|
4202
|
+
* unless one is already in flight or another runner's live lease will
|
|
4203
|
+
* refuse this launch; an acknowledgement appends none. A denial or
|
|
4204
|
+
* deferral is recorded only in memory, for this tick's intake reservation;
|
|
4205
|
+
* a deferral is retried after this tick's dispatch. */
|
|
4171
4206
|
private async leafAdmission(slug: string): Promise<'admit' | 'wait' | 'defer'> {
|
|
4172
|
-
const
|
|
4207
|
+
const facts = await this.store.buildFacts(slug)
|
|
4208
|
+
const { state } = facts
|
|
4209
|
+
const self = { state, restackDue: landingRestackDue(state, facts.log) }
|
|
4210
|
+
if (leafHoldsSlot(self)) {
|
|
4211
|
+
if (launchInFlight(escalationCarryInput(state))) return 'admit'
|
|
4212
|
+
// A live runner (a restarted dispatcher re-attempting a running build)
|
|
4213
|
+
// wins the lease claim, so this attempt launches nothing to record.
|
|
4214
|
+
const record = await this.store.getBuild(slug)
|
|
4215
|
+
if (record !== null && this.hasLiveExecutionLease(record)) return 'admit'
|
|
4216
|
+
const recorded = await this.store.appendIfCurrent(slug, state.lastSeq, {
|
|
4217
|
+
actor: DISPATCHER,
|
|
4218
|
+
type: 'slot.admitted',
|
|
4219
|
+
payload: {},
|
|
4220
|
+
})
|
|
4221
|
+
if (recorded === null) return 'wait'
|
|
4222
|
+
await this.store.servedBuildFacts(slug)
|
|
4223
|
+
return 'admit'
|
|
4224
|
+
}
|
|
4225
|
+
// A leaf waiting on the outside world can hold no slot, so what runs for
|
|
4226
|
+
// it (an acknowledgement) is neither gated nor admitted.
|
|
4173
4227
|
if (
|
|
4174
|
-
|
|
4228
|
+
leafOutsideWait(self) ||
|
|
4175
4229
|
state.pendingCommands.some(
|
|
4176
4230
|
(command) => command.command === 'abort' || command.command === 'pause',
|
|
4177
4231
|
)
|
|
@@ -4182,18 +4236,31 @@ export class Dispatcher {
|
|
|
4182
4236
|
const capacity = this.deps.config.capacity
|
|
4183
4237
|
const now = this.deps.clock()
|
|
4184
4238
|
const priority = buildPriority(state)
|
|
4185
|
-
|
|
4239
|
+
let outcome = this.slotAdmission(
|
|
4186
4240
|
slug,
|
|
4187
4241
|
priority,
|
|
4188
4242
|
dispatchCapacity(others, capacity, now).occupied,
|
|
4189
|
-
dispatchCapacity(builds, capacity, now,
|
|
4243
|
+
dispatchCapacity(builds, capacity, now, {
|
|
4190
4244
|
urgentClaims: this.urgentClaims(),
|
|
4191
4245
|
startRequests: this.startClaims(),
|
|
4192
4246
|
}),
|
|
4193
4247
|
)
|
|
4194
4248
|
if (outcome === 'admit') {
|
|
4195
|
-
|
|
4196
|
-
|
|
4249
|
+
const request = leafSlotRequest(self)
|
|
4250
|
+
const admitted = await this.store.appendIfCurrent(slug, state.lastSeq, {
|
|
4251
|
+
actor: DISPATCHER,
|
|
4252
|
+
type: 'slot.admitted',
|
|
4253
|
+
payload: request === undefined ? {} : { request },
|
|
4254
|
+
})
|
|
4255
|
+
if (admitted !== null) {
|
|
4256
|
+
this.slotWaiters.delete(slug)
|
|
4257
|
+
// Retain the admitted facts, so this tick's capacity counts the
|
|
4258
|
+
// build as holding its slot from here on.
|
|
4259
|
+
await this.store.servedBuildFacts(slug)
|
|
4260
|
+
return 'admit'
|
|
4261
|
+
}
|
|
4262
|
+
// The state moved under the decision: decide again next tick.
|
|
4263
|
+
outcome = 'wait'
|
|
4197
4264
|
}
|
|
4198
4265
|
this.slotWaiters.set(slug, priority)
|
|
4199
4266
|
if (outcome === 'defer' && !this.deferredAdmissions.has(slug))
|
|
@@ -4234,10 +4301,13 @@ export class Dispatcher {
|
|
|
4234
4301
|
else if (kind === 'node') {
|
|
4235
4302
|
const builds = await this.capacityBuilds()
|
|
4236
4303
|
const build = builds.find((entry) => entry.record.slug === slug)
|
|
4237
|
-
|
|
4304
|
+
// A deferred reconcile launches only through the cascade.
|
|
4305
|
+
if (build && nodeSlotNeed(build, this.deps.clock())?.request === 'reconcile')
|
|
4306
|
+
await this.cascadeNode(record, build.state, report, launched, opts)
|
|
4307
|
+
else if (build) await this.admitNode(build, this.deps.clock(), report, launched)
|
|
4238
4308
|
} else {
|
|
4239
4309
|
const builds = await this.capacityBuilds()
|
|
4240
|
-
await this.admitProposers(builds, this.deps.clock(),
|
|
4310
|
+
await this.admitProposers(builds, this.deps.clock(), report, launched, opts, slug)
|
|
4241
4311
|
}
|
|
4242
4312
|
} catch (error) {
|
|
4243
4313
|
rethrowAuthorityLapse(error)
|
|
@@ -4282,19 +4352,58 @@ export class Dispatcher {
|
|
|
4282
4352
|
)
|
|
4283
4353
|
await this.releaseStrandedNodeWorkspaces(builds, now, launched, report, opts)
|
|
4284
4354
|
if (this.outOfBudget(opts)) return
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
|
|
4292
|
-
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
|
|
4355
|
+
await this.adoptLegacyNodeRunners(builds, now, report)
|
|
4356
|
+
// A node asking for a verification slot, and one admitted for
|
|
4357
|
+
// verification whose runner never started or was lost: nothing else
|
|
4358
|
+
// relaunches it.
|
|
4359
|
+
const waiting = builds.filter((build) => nodeRunnerWork(build, now)?.request === 'verification')
|
|
4360
|
+
const admitted = new Set<string>()
|
|
4361
|
+
this.passNodeAdmissions = admitted
|
|
4362
|
+
try {
|
|
4363
|
+
for (const build of waiting) {
|
|
4364
|
+
if (this.outOfBudget(opts)) return
|
|
4365
|
+
await this.admitNode(build, now, report, launched)
|
|
4366
|
+
}
|
|
4367
|
+
} finally {
|
|
4368
|
+
this.passNodeAdmissions = undefined
|
|
4369
|
+
}
|
|
4370
|
+
// A node admitted this pass holds its slot whatever its provisioning or
|
|
4371
|
+
// launch did: the proposers' capacity counts it from its durable facts,
|
|
4372
|
+
// and a holder that merely relaunched is already counted.
|
|
4373
|
+
for (const build of waiting)
|
|
4374
|
+
if (admitted.has(build.record.slug))
|
|
4375
|
+
build.state = (await this.store.servedBuildFacts(build.record.slug)).state
|
|
4376
|
+
await this.admitProposers(builds, now, report, launched, opts)
|
|
4377
|
+
}
|
|
4378
|
+
|
|
4379
|
+
/**
|
|
4380
|
+
* The version transition (SPEC §15 `slot.admitted`): record, once, the
|
|
4381
|
+
* admission of every node runner an older dispatcher launched without one
|
|
4382
|
+
* (`legacyNodeRunner`). The predicate counts such a runner as holding its
|
|
4383
|
+
* slot from the first tick, before this write; the fact keeps the slot
|
|
4384
|
+
* through a later crash or expired lease until that work is done. Pure over
|
|
4385
|
+
* the states this pass loaded, so nothing is read once no legacy runner
|
|
4386
|
+
* remains. An adopted entry is updated in place; a lost race is decided
|
|
4387
|
+
* again next pass.
|
|
4388
|
+
*/
|
|
4389
|
+
private async adoptLegacyNodeRunners(
|
|
4390
|
+
builds: CapacityBuild[],
|
|
4391
|
+
now: Date,
|
|
4392
|
+
report: TickReport,
|
|
4393
|
+
): Promise<void> {
|
|
4394
|
+
for (const build of builds) {
|
|
4395
|
+
const need = legacyNodeRunnerNeed(build, now)
|
|
4396
|
+
if (need === undefined) continue
|
|
4397
|
+
try {
|
|
4398
|
+
if (await this.admitNodeNeed(build.record.slug, build.state, need))
|
|
4399
|
+
build.state = (await this.store.servedBuildFacts(build.record.slug)).state
|
|
4400
|
+
} catch (error) {
|
|
4401
|
+
rethrowAuthorityLapse(error)
|
|
4402
|
+
report.janitorDiagnostics.push(
|
|
4403
|
+
`build ${build.record.slug}: node runner adoption failed — ${String(error)}`,
|
|
4404
|
+
)
|
|
4405
|
+
}
|
|
4296
4406
|
}
|
|
4297
|
-
await this.admitProposers(builds, now, launched.size - before, report, launched, opts)
|
|
4298
4407
|
}
|
|
4299
4408
|
|
|
4300
4409
|
/** One waiting node's admission: a measurement or its integration
|
|
@@ -4314,7 +4423,7 @@ export class Dispatcher {
|
|
|
4314
4423
|
return
|
|
4315
4424
|
await withForgeRequestContext({ build: record.slug }, async () => {
|
|
4316
4425
|
try {
|
|
4317
|
-
if ((await this.
|
|
4426
|
+
if ((await this.nodeAdmission(record.slug)) !== 'admit') return
|
|
4318
4427
|
if (nodeMeasurementDue(state)) await this.prepareNodeMeasurement(record, report, launched)
|
|
4319
4428
|
else await this.prepareIntegration(record, state, report, launched)
|
|
4320
4429
|
} catch (error) {
|
|
@@ -4374,7 +4483,6 @@ export class Dispatcher {
|
|
|
4374
4483
|
private async admitProposers(
|
|
4375
4484
|
builds: CapacityBuild[],
|
|
4376
4485
|
now: Date,
|
|
4377
|
-
admittedThisPass: number,
|
|
4378
4486
|
report: TickReport,
|
|
4379
4487
|
launched: Set<string>,
|
|
4380
4488
|
opts: TickOpts,
|
|
@@ -4387,11 +4495,11 @@ export class Dispatcher {
|
|
|
4387
4495
|
(only === undefined || build.record.slug === only),
|
|
4388
4496
|
)
|
|
4389
4497
|
if (proposers.length === 0) return
|
|
4390
|
-
const projection = dispatchCapacity(builds, this.deps.config.capacity, now,
|
|
4498
|
+
const projection = dispatchCapacity(builds, this.deps.config.capacity, now, {
|
|
4391
4499
|
urgentClaims: this.urgentClaims(),
|
|
4392
4500
|
startRequests: this.startClaims(),
|
|
4393
4501
|
})
|
|
4394
|
-
let occupied = projection.occupied
|
|
4502
|
+
let occupied = projection.occupied
|
|
4395
4503
|
for (const build of proposers) {
|
|
4396
4504
|
if (this.outOfBudget(opts)) return
|
|
4397
4505
|
const { record, state } = build
|
|
@@ -4418,18 +4526,19 @@ export class Dispatcher {
|
|
|
4418
4526
|
await this.releaseWorkspace(record.slug, facts)
|
|
4419
4527
|
return
|
|
4420
4528
|
}
|
|
4421
|
-
//
|
|
4422
|
-
//
|
|
4423
|
-
const holding = build
|
|
4529
|
+
// An admitted proposer holds its slot (one that lost its runner
|
|
4530
|
+
// relaunches); otherwise it needs a free one.
|
|
4531
|
+
const holding = nodeHoldsSlot(build, now) || legacyNodeRunner(build, now)
|
|
4532
|
+
const need = holding ? undefined : nodeSlotNeed(build, now)
|
|
4424
4533
|
if (
|
|
4425
4534
|
(holding
|
|
4426
4535
|
? state.status === 'paused' || state.status === 'blocked'
|
|
4427
|
-
:
|
|
4536
|
+
: need?.request !== 'propose') ||
|
|
4428
4537
|
!state.nodeOpened ||
|
|
4429
4538
|
!janitorDue(state.janitor, now)
|
|
4430
4539
|
)
|
|
4431
4540
|
return
|
|
4432
|
-
if (
|
|
4541
|
+
if (need !== undefined) {
|
|
4433
4542
|
if (!this.accountsAvailable()) return
|
|
4434
4543
|
const outcome = this.slotAdmission(
|
|
4435
4544
|
record.slug,
|
|
@@ -4439,6 +4548,7 @@ export class Dispatcher {
|
|
|
4439
4548
|
)
|
|
4440
4549
|
if (outcome === 'defer') this.deferredAdmissions.set(record.slug, 'proposer')
|
|
4441
4550
|
if (outcome !== 'admit') return
|
|
4551
|
+
if (!(await this.admitNodeNeed(record.slug, state, need))) return
|
|
4442
4552
|
occupied++
|
|
4443
4553
|
}
|
|
4444
4554
|
await this.launchProposer(record, report, launched)
|
|
@@ -4782,40 +4892,87 @@ export class Dispatcher {
|
|
|
4782
4892
|
await this.recordExhausted(record.slug)
|
|
4783
4893
|
}
|
|
4784
4894
|
|
|
4785
|
-
/**
|
|
4786
|
-
*
|
|
4787
|
-
*
|
|
4788
|
-
*
|
|
4789
|
-
* a
|
|
4790
|
-
*
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
4895
|
+
/** Whether a node may start runner work now (SPEC §12 "What holds a
|
|
4896
|
+
* slot"). A node that holds its slot is admitted at once: a relaunch after
|
|
4897
|
+
* a crashed runner or an expired lease, or continued provisioning. Every
|
|
4898
|
+
* other node's current request (`verification`, `reconcile` or `propose`)
|
|
4899
|
+
* needs a free slot among every other build, after the work ahead of it,
|
|
4900
|
+
* under the same tiers and urgent ordering as parked leaves. Admission is
|
|
4901
|
+
* the durable `slot.admitted {request, need}` fact, appended on the state
|
|
4902
|
+
* this decision read before anything is provisioned or launched, so a
|
|
4903
|
+
* crash or restart after it keeps the slot until that need is done. A
|
|
4904
|
+
* denial is recorded nowhere; a deferral is retried after this tick's
|
|
4905
|
+
* dispatch. */
|
|
4906
|
+
private async nodeAdmission(slug: string): Promise<'admit' | 'wait' | 'defer'> {
|
|
4795
4907
|
const builds = await this.capacityBuilds()
|
|
4796
4908
|
const now = this.deps.clock()
|
|
4797
|
-
const identity = migrationIdentity(
|
|
4798
|
-
this.store.repositoryFacts().ticketMigrations,
|
|
4799
|
-
this.deps.tickets.name,
|
|
4800
|
-
)
|
|
4801
|
-
const { occupied } = nodeCapacity(builds, slug, now, identity)
|
|
4802
4909
|
const node = builds.find((build) => build.record.slug === slug)
|
|
4803
|
-
if (
|
|
4804
|
-
|
|
4910
|
+
if (node === undefined) return 'wait'
|
|
4911
|
+
if (nodeHoldsSlot(node, now) || legacyNodeRunner(node, now)) return 'admit'
|
|
4912
|
+
const need = nodeSlotNeed(node, now)
|
|
4913
|
+
if (need === undefined) return 'wait'
|
|
4914
|
+
const capacity = this.deps.config.capacity
|
|
4805
4915
|
const outcome = this.slotAdmission(
|
|
4806
4916
|
slug,
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
|
|
4917
|
+
buildPriority(node.state),
|
|
4918
|
+
dispatchCapacity(
|
|
4919
|
+
builds.filter((build) => build.record.slug !== slug),
|
|
4920
|
+
capacity,
|
|
4921
|
+
now,
|
|
4922
|
+
).occupied,
|
|
4923
|
+
dispatchCapacity(builds, capacity, now, {
|
|
4810
4924
|
urgentClaims: this.urgentClaims(),
|
|
4811
4925
|
startRequests: this.startClaims(),
|
|
4812
4926
|
}),
|
|
4813
4927
|
)
|
|
4928
|
+
if (outcome === 'admit')
|
|
4929
|
+
return (await this.admitNodeNeed(slug, node.state, need)) ? 'admit' : 'wait'
|
|
4814
4930
|
if (outcome === 'defer' && !this.deferredAdmissions.has(slug))
|
|
4815
4931
|
this.deferredAdmissions.set(slug, 'node')
|
|
4816
4932
|
return outcome
|
|
4817
4933
|
}
|
|
4818
4934
|
|
|
4935
|
+
/** Record a node's admission for one runner need on the state the decision
|
|
4936
|
+
* read; false when the state moved under it (decided again next tick).
|
|
4937
|
+
* The admitted facts are retained so this tick's capacity counts the node
|
|
4938
|
+
* as holding its slot. */
|
|
4939
|
+
private async admitNodeNeed(
|
|
4940
|
+
slug: string,
|
|
4941
|
+
state: BuildState,
|
|
4942
|
+
need: NodeSlotNeed,
|
|
4943
|
+
): Promise<boolean> {
|
|
4944
|
+
const admitted = await this.store.appendIfCurrent(slug, state.lastSeq, {
|
|
4945
|
+
actor: DISPATCHER,
|
|
4946
|
+
type: 'slot.admitted',
|
|
4947
|
+
payload: { request: need.request, need: need.key },
|
|
4948
|
+
} satisfies EventWrite<'slot.admitted'>)
|
|
4949
|
+
if (admitted === null) return false
|
|
4950
|
+
this.passNodeAdmissions?.add(slug)
|
|
4951
|
+
await this.store.servedBuildFacts(slug)
|
|
4952
|
+
return true
|
|
4953
|
+
}
|
|
4954
|
+
|
|
4955
|
+
/** A node's runner may be relaunched by the sweep: it holds its slot (or is
|
|
4956
|
+
* a legacy runner counted as holding one), or an abort or pause awaits its
|
|
4957
|
+
* acknowledgement. */
|
|
4958
|
+
private nodeRelaunchAdmitted(record: BuildRecord, facts: CurrentBuildFacts): boolean {
|
|
4959
|
+
const { state } = facts
|
|
4960
|
+
if (
|
|
4961
|
+
state.pendingCommands.some(
|
|
4962
|
+
(command) => command.command === 'abort' || command.command === 'pause',
|
|
4963
|
+
)
|
|
4964
|
+
)
|
|
4965
|
+
return true
|
|
4966
|
+
const now = this.deps.clock()
|
|
4967
|
+
const build: CapacityBuild = {
|
|
4968
|
+
record,
|
|
4969
|
+
state,
|
|
4970
|
+
workspace: facts.workspace !== null,
|
|
4971
|
+
restackDue: landingRestackDue(state, facts.log),
|
|
4972
|
+
}
|
|
4973
|
+
return nodeHoldsSlot(build, now) || legacyNodeRunner(build, now)
|
|
4974
|
+
}
|
|
4975
|
+
|
|
4819
4976
|
private hasLiveExecutionLease(record: BuildRecord): boolean {
|
|
4820
4977
|
return (
|
|
4821
4978
|
record.lease !== undefined &&
|
|
@@ -8257,6 +8414,9 @@ export class Dispatcher {
|
|
|
8257
8414
|
// A finished leaf with work to run waits for a slot before anything is
|
|
8258
8415
|
// reaped, provisioned or launched for it.
|
|
8259
8416
|
if (runs && state.kind !== 'node' && (await this.leafAdmission(record.slug)) !== 'admit') return
|
|
8417
|
+
// A node relaunches only for work it holds a slot for: a retained
|
|
8418
|
+
// workspace confers none. Abort and pause acknowledgements are ungated.
|
|
8419
|
+
if (runs && state.kind === 'node' && !this.nodeRelaunchAdmitted(record, facts)) return
|
|
8260
8420
|
// A finished parked leaf keeps its workspace until merge or close; a
|
|
8261
8421
|
// stale environment is reaped only for an admitted replacement.
|
|
8262
8422
|
// A leaf waiting on tickets, or on the dispatcher's check of its wait,
|
|
@@ -8612,13 +8772,10 @@ export class Dispatcher {
|
|
|
8612
8772
|
engaged,
|
|
8613
8773
|
)
|
|
8614
8774
|
// Pending start requests reserve ahead of the ordinary claims they outrank.
|
|
8615
|
-
const projection = dispatchCapacity(
|
|
8616
|
-
|
|
8617
|
-
|
|
8618
|
-
|
|
8619
|
-
undefined,
|
|
8620
|
-
{ openPrs: { policy: config.policy, engaged }, startRequests: this.startClaims() },
|
|
8621
|
-
)
|
|
8775
|
+
const projection = dispatchCapacity(capacityBuilds, config.capacity, this.deps.clock(), {
|
|
8776
|
+
openPrs: { policy: config.policy, engaged },
|
|
8777
|
+
startRequests: this.startClaims(),
|
|
8778
|
+
})
|
|
8622
8779
|
const transition = backpressureTransition(
|
|
8623
8780
|
backpressure,
|
|
8624
8781
|
engaged,
|
|
@@ -9846,7 +10003,7 @@ export class Dispatcher {
|
|
|
9846
10003
|
}
|
|
9847
10004
|
|
|
9848
10005
|
if (!this.accountsAvailable()) return
|
|
9849
|
-
if ((await this.
|
|
10006
|
+
if ((await this.nodeAdmission(record.slug)) !== 'admit') return
|
|
9850
10007
|
// `launch()` refuses a flagged workspace and leaves the reap to its
|
|
9851
10008
|
// callers; this is the node's caller for conflict work.
|
|
9852
10009
|
const current = await this.replaceFlaggedWorkspace(record, facts, launched)
|
|
@@ -10149,7 +10306,7 @@ export class Dispatcher {
|
|
|
10149
10306
|
await this.releaseWorkspace(record.slug, facts)
|
|
10150
10307
|
return
|
|
10151
10308
|
}
|
|
10152
|
-
if ((await this.
|
|
10309
|
+
if ((await this.nodeAdmission(record.slug)) !== 'admit') return
|
|
10153
10310
|
await this.observeIntegration(record.slug)
|
|
10154
10311
|
state = (await this.store.buildFacts(record.slug)).state
|
|
10155
10312
|
if (!integrationCurrent(state)) return
|
|
@@ -34,6 +34,7 @@ export const executionProgress = {
|
|
|
34
34
|
'landing.native-applied': 'bookkeeping',
|
|
35
35
|
'target.distance': 'bookkeeping',
|
|
36
36
|
'pipeline.settled': 'bookkeeping',
|
|
37
|
+
'slot.admitted': 'bookkeeping',
|
|
37
38
|
'target.rewritten': 'bookkeeping',
|
|
38
39
|
'target.rewrite-cleared': 'bookkeeping',
|
|
39
40
|
'target.moved': 'bookkeeping',
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Store capabilities a short-lived reader may never use, initialized on first
|
|
3
|
+
* need. A process that only reads its repository record and change position
|
|
4
|
+
* never evaluates the event catalogs, the write validators or the reducers.
|
|
5
|
+
*
|
|
6
|
+
* Rule for every use: take `capability.value ?? (await capability.load())` as
|
|
7
|
+
* the method's first statement, before any transaction, read or mutation, and
|
|
8
|
+
* use the resolved functions synchronously where they were used before. Every
|
|
9
|
+
* write is therefore still validated before it mutates anything, and once a
|
|
10
|
+
* capability is loaded a method runs with no added await at all. A failed load
|
|
11
|
+
* is not remembered: the next use retries it, and the error reaches the caller.
|
|
12
|
+
*/
|
|
13
|
+
export class Capability<T> {
|
|
14
|
+
value: T | undefined
|
|
15
|
+
private pending: Promise<T> | undefined
|
|
16
|
+
|
|
17
|
+
constructor(private readonly initialize: () => Promise<T>) {}
|
|
18
|
+
|
|
19
|
+
load(): Promise<T> {
|
|
20
|
+
this.pending ??= this.initialize().then(
|
|
21
|
+
(value) => {
|
|
22
|
+
this.value = value
|
|
23
|
+
return value
|
|
24
|
+
},
|
|
25
|
+
(error: unknown) => {
|
|
26
|
+
this.pending = undefined
|
|
27
|
+
throw error
|
|
28
|
+
},
|
|
29
|
+
)
|
|
30
|
+
return this.pending
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Build, repository and session event validation, plus the build-creation and
|
|
35
|
+
* tick-finish checks. */
|
|
36
|
+
export const writeValidation = new Capability(async () => {
|
|
37
|
+
const [catalog, repository, sessions, newBuild, repoTick] = await Promise.all([
|
|
38
|
+
import('../../events/catalog'),
|
|
39
|
+
import('../../events/repository'),
|
|
40
|
+
import('../../events/sessions'),
|
|
41
|
+
import('../new-build'),
|
|
42
|
+
import('../repo-tick'),
|
|
43
|
+
])
|
|
44
|
+
return {
|
|
45
|
+
validateEventWrite: catalog.prepareEventWrite,
|
|
46
|
+
validateRepositoryEventWrite: repository.prepareRepositoryEventWrite,
|
|
47
|
+
validateSessionEventWrite: sessions.validateSessionEventWrite,
|
|
48
|
+
validateCreatedEvent: newBuild.validateCreatedEvent,
|
|
49
|
+
validateTickFinish: repoTick.validateTickFinish,
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
/** Strict build-event payload schemas. */
|
|
54
|
+
export const payloadSchemas = new Capability(async () => {
|
|
55
|
+
const { eventPayloadSchemas } = await import('../../events/payloads')
|
|
56
|
+
return { eventPayloadSchemas }
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
/** Named reducer values over the selective index: only the requested reducer's
|
|
60
|
+
* module initializes. Never the complete catalog unless a request names a
|
|
61
|
+
* reducer outside the index. */
|
|
62
|
+
export const reducedValues = new Capability(async () => {
|
|
63
|
+
const [read, index] = await Promise.all([
|
|
64
|
+
import('../reducer-value-read'),
|
|
65
|
+
import('../../kernel/reducer-value-index'),
|
|
66
|
+
])
|
|
67
|
+
return {
|
|
68
|
+
parseValueRequest: read.parseValueRequest,
|
|
69
|
+
resolveRegisteredValue: read.resolveRegisteredValue,
|
|
70
|
+
readResolvedReducerValue: read.readResolvedReducerValue,
|
|
71
|
+
loadValueRegistration: index.loadValueRegistration,
|
|
72
|
+
loadedValueRegistration: index.loadedValueRegistration,
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
/** Saved build digests for open-build and repository digest listings. */
|
|
77
|
+
export const buildDigests = new Capability(async () => {
|
|
78
|
+
const { readPersistedBuildDigests } = await import('../reduced-reads')
|
|
79
|
+
return { readPersistedBuildDigests }
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
/** Repository rollups (the derived-reducer engine). */
|
|
83
|
+
export const rollups = new Capability(async () => {
|
|
84
|
+
const { readRollupValue } = await import('../rollups')
|
|
85
|
+
return { readRollupValue }
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
/** The repository state-event selection. */
|
|
89
|
+
export const repositoryStateEvents = new Capability(async () => {
|
|
90
|
+
const module = await import('../repo-state-events')
|
|
91
|
+
return {
|
|
92
|
+
REPOSITORY_STATE_EVENT_TYPES: module.REPOSITORY_STATE_EVENT_TYPES,
|
|
93
|
+
REPOSITORY_LATEST_EVENT_TYPES: module.REPOSITORY_LATEST_EVENT_TYPES,
|
|
94
|
+
readRepoStateEventsWithAnchorRecheck: module.readRepoStateEventsWithAnchorRecheck,
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
/** Ticket asset storage and pinning. */
|
|
99
|
+
export const ticketAssetCapability = new Capability(async () => {
|
|
100
|
+
const module = await import('../ticket-assets')
|
|
101
|
+
return {
|
|
102
|
+
DEFAULT_TICKET_ASSET_LIMITS: module.DEFAULT_TICKET_ASSET_LIMITS,
|
|
103
|
+
loadTicketAsset: module.loadTicketAsset,
|
|
104
|
+
storeTicketAssetBlobs: module.storeTicketAssetBlobs,
|
|
105
|
+
resolvePinnedAsset: module.resolvePinnedAsset,
|
|
106
|
+
summarizeTicketAsset: module.summarizeTicketAsset,
|
|
107
|
+
validateTicketAssetInput: module.validateTicketAssetInput,
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
/** UI message stream assembly at close. */
|
|
112
|
+
export const streamAssembly = new Capability(async () => {
|
|
113
|
+
const { assembleUIMessageDocument } = await import('../streams/assemble')
|
|
114
|
+
return { assembleUIMessageDocument }
|
|
115
|
+
})
|