@defrex/autobuild 1.20.0 → 1.21.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 +35 -2
- package/docs/architecture.md +25 -1
- package/docs/dispatcher-hosting.md +6 -1
- package/docs/dispatcher.md +1 -1
- package/docs/troubleshooting.md +6 -0
- package/package.json +3 -3
- package/packages/core/src/cli/dispatch.ts +3 -0
- package/packages/core/src/events/repository.ts +45 -1
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/b440840a01ea216f.json +115 -0
- package/packages/core/src/kernel/dispatch-capacity.ts +32 -3
- package/packages/core/src/kernel/reducer-revisions.ts +2 -0
- package/packages/core/src/kernel/repository-read-facts.ts +6 -1
- package/packages/core/src/processes/dispatcher.ts +341 -39
- package/packages/core/src/processes/pass-stages.ts +94 -4
- package/packages/core/src/processes/repo-view.ts +48 -9
- package/packages/core/src/store/reducer-value-shapes.json +5597 -5454
- package/packages/core/src/store/remote/released-clients.json +11 -0
- package/packages/core/src/store/remote/released-reducer-values/1.21.0.json +36612 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +16 -14
- package/packages/core/src/testing/reduced-read-budget.ts +281 -2
- package/skills/guide/SKILL.md +18 -2
- package/skills/operate/SKILL.md +7 -0
- package/templates/hosted-service/package.json +2 -2
|
@@ -146,7 +146,10 @@ import {
|
|
|
146
146
|
nodeHoldsSlot,
|
|
147
147
|
nodeRunnerWork,
|
|
148
148
|
nodeSlotNeed,
|
|
149
|
+
nodeSlotTimeDependent,
|
|
150
|
+
occupiesCapacity,
|
|
149
151
|
reservedAhead,
|
|
152
|
+
slotRequest,
|
|
150
153
|
settlementDue,
|
|
151
154
|
settlementKey,
|
|
152
155
|
startCapacity,
|
|
@@ -404,6 +407,7 @@ import type {
|
|
|
404
407
|
BuildStore,
|
|
405
408
|
Clock,
|
|
406
409
|
} from '../store/types'
|
|
410
|
+
import { compareChangePositions, type ChangedBuilds } from '../store/build-feed'
|
|
407
411
|
import { creationBuildSlug } from '../kernel/build-creation'
|
|
408
412
|
import { preparePinnedAssets } from '../store/ticket-assets'
|
|
409
413
|
import { resolveRepoOrigin } from '../cli/repo-state'
|
|
@@ -1025,6 +1029,36 @@ interface CarriedPreparation {
|
|
|
1025
1029
|
/** Most ticket-preparation attempts one hint carries. */
|
|
1026
1030
|
const MAX_CARRIED_PREPARATIONS = 8
|
|
1027
1031
|
|
|
1032
|
+
/** The occupancy a bounded pass measured when it deferred a parked
|
|
1033
|
+
* admission (#1435): the repository change position read before the
|
|
1034
|
+
* measurement, the builds holding a slot, those requesting one with their
|
|
1035
|
+
* level, and the open nodes whose slot state can change without an event
|
|
1036
|
+
* (`nodeSlotTimeDependent`). The next pass rebuilds occupancy from it and
|
|
1037
|
+
* the builds changed since, without measuring the fleet. */
|
|
1038
|
+
interface ParkedWitness {
|
|
1039
|
+
position: string
|
|
1040
|
+
holders: string[]
|
|
1041
|
+
waiters: { slug: string; level: BuildPriority }[]
|
|
1042
|
+
volatile: string[]
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
/** The hint's carried parked admissions (#1435). */
|
|
1046
|
+
interface ParkedCarry {
|
|
1047
|
+
slugs: string[]
|
|
1048
|
+
witness?: ParkedWitness
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
/** Most parked admissions one hint carries, and the witness bounds past
|
|
1052
|
+
* which the next pass falls back to the ordinary sweep visit. */
|
|
1053
|
+
const MAX_CARRIED_ADMISSIONS = 64
|
|
1054
|
+
const MAX_WITNESS_HOLDERS = 256
|
|
1055
|
+
const MAX_WITNESS_WAITERS = 64
|
|
1056
|
+
const MAX_WITNESS_VOLATILE = 64
|
|
1057
|
+
|
|
1058
|
+
function parkedCarryLine(slug: string, level: BuildPriority): string {
|
|
1059
|
+
return `build ${slug} (${level}): parked admission carried to the next pass — this pass's intake did not decide claims`
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1028
1062
|
/** What one ticket preparation reached: a build `started`; the ticket `left`
|
|
1029
1063
|
* the queue without a build (claim refused or bounced); it was `blocked` by
|
|
1030
1064
|
* a blocker the claim found; the work deadline `carried` it to the next
|
|
@@ -1552,6 +1586,26 @@ export class Dispatcher {
|
|
|
1552
1586
|
* "Slot admission order"). Nothing was written for them;
|
|
1553
1587
|
* `admitDeferredParked` retries each through its generic path. */
|
|
1554
1588
|
private readonly deferredAdmissions = new Map<string, 'leaf' | 'node' | 'proposer'>()
|
|
1589
|
+
/** Per bounded tick: parked leaves this tick deferred whose retry has not
|
|
1590
|
+
* run, with their level (#1435). Whatever remains when the pass ends is
|
|
1591
|
+
* carried to the next pass (`finalizeParkedCarries`). */
|
|
1592
|
+
private readonly pendingParkedRetries = new Map<string, BuildPriority>()
|
|
1593
|
+
/** Per bounded tick: parked leaves this tick carried to the next pass. */
|
|
1594
|
+
private readonly tickParkedCarries = new Map<string, BuildPriority>()
|
|
1595
|
+
/** Per bounded tick: the repository change position, read once before the
|
|
1596
|
+
* first parked admission's capacity measurement. */
|
|
1597
|
+
private tickPosition: string | undefined
|
|
1598
|
+
/** Per bounded tick: the occupancy the latest deferring measurement saw. */
|
|
1599
|
+
private tickWitness: ParkedWitness | undefined
|
|
1600
|
+
/** Per bounded tick, in carried order: the hint's carried parked
|
|
1601
|
+
* admissions. Their admission boundary stays closed for the whole pass;
|
|
1602
|
+
* one is `decided` once admission evaluated it this pass. */
|
|
1603
|
+
private readonly carriedParked = new Map<string, { decided: boolean }>()
|
|
1604
|
+
/** Per bounded tick: the hint's witness for the carried admissions. */
|
|
1605
|
+
private carriedWitness: ParkedWitness | undefined
|
|
1606
|
+
private parkedCarriesFinalized = false
|
|
1607
|
+
/** The hint's `parked` entry as last read or written. */
|
|
1608
|
+
private recordedParked: ParkedCarry | undefined
|
|
1555
1609
|
/** Nodes `admitWaitingNodes` admitted in its current verification pass, so
|
|
1556
1610
|
* proposer admission counts them even when provisioning or launch failed. */
|
|
1557
1611
|
private passNodeAdmissions: Set<string> | undefined
|
|
@@ -1793,8 +1847,13 @@ export class Dispatcher {
|
|
|
1793
1847
|
? this.deps.forge.withReadScope(() => this.runTick(opts))
|
|
1794
1848
|
: this.runTick(opts))
|
|
1795
1849
|
if (stop || this.deps.config.forge === 'local-git') report.forgeRequests = counts()
|
|
1796
|
-
// Every early return of `runTick`
|
|
1797
|
-
|
|
1850
|
+
// Every early return of `runTick` carries the parked admissions it
|
|
1851
|
+
// deferred and did not retry, and leaves its positions.
|
|
1852
|
+
if (opts.deadlineAt !== undefined) {
|
|
1853
|
+
this.finalizeParkedCarries()
|
|
1854
|
+
await this.persistDeferrals()
|
|
1855
|
+
await this.persistPassCursors()
|
|
1856
|
+
}
|
|
1798
1857
|
this.finishDeferrals(report)
|
|
1799
1858
|
report.janitorDiagnostics.push(...this.tickAbandonments)
|
|
1800
1859
|
const stages = opts.deadlineAt === undefined ? [] : this.pass.summary()
|
|
@@ -1852,6 +1911,13 @@ export class Dispatcher {
|
|
|
1852
1911
|
this.startBarrier = undefined
|
|
1853
1912
|
this.parkedSettled.clear()
|
|
1854
1913
|
this.deferredAdmissions.clear()
|
|
1914
|
+
this.pendingParkedRetries.clear()
|
|
1915
|
+
this.tickParkedCarries.clear()
|
|
1916
|
+
this.tickPosition = undefined
|
|
1917
|
+
this.tickWitness = undefined
|
|
1918
|
+
this.carriedParked.clear()
|
|
1919
|
+
this.carriedWitness = undefined
|
|
1920
|
+
this.parkedCarriesFinalized = false
|
|
1855
1921
|
this.tickDeferrals.clear()
|
|
1856
1922
|
this.reportedDeferrals.clear()
|
|
1857
1923
|
this.deferralsFinished = false
|
|
@@ -1884,6 +1950,15 @@ export class Dispatcher {
|
|
|
1884
1950
|
for (const { ticket, attempt } of this.recordedPreparationCarries)
|
|
1885
1951
|
if (!this.carriedPreparationsOutstanding.has(attempt))
|
|
1886
1952
|
this.carriedPreparationsOutstanding.set(attempt, { ticket, visited: false })
|
|
1953
|
+
// Carried parked admissions (#1435): only a bounded pass decides them;
|
|
1954
|
+
// an unbounded one keeps the entry as it is.
|
|
1955
|
+
this.recordedParked =
|
|
1956
|
+
deferredWork?.parked === undefined ? undefined : structuredClone(deferredWork.parked)
|
|
1957
|
+
if (opts.deadlineAt !== undefined && this.recordedParked !== undefined) {
|
|
1958
|
+
for (const slug of this.recordedParked.slugs)
|
|
1959
|
+
if (!this.carriedParked.has(slug)) this.carriedParked.set(slug, { decided: false })
|
|
1960
|
+
this.carriedWitness = this.recordedParked.witness
|
|
1961
|
+
}
|
|
1887
1962
|
// The rotated loops' positions, from the same reduced facts: no read.
|
|
1888
1963
|
this.passCursors =
|
|
1889
1964
|
opts.deadlineAt === undefined
|
|
@@ -2143,6 +2218,8 @@ export class Dispatcher {
|
|
|
2143
2218
|
report.preparationsCarried = this.tickPreparationCarries.size
|
|
2144
2219
|
for (const { ticket, detail } of this.tickPreparationCarries.values())
|
|
2145
2220
|
report.deferredDiagnostics.push(preparationCarryLine(ticket, detail))
|
|
2221
|
+
for (const [slug, level] of this.tickParkedCarries)
|
|
2222
|
+
report.deferredDiagnostics.push(parkedCarryLine(slug, level))
|
|
2146
2223
|
}
|
|
2147
2224
|
return { ...report, stages: this.pass.summary() }
|
|
2148
2225
|
}
|
|
@@ -4946,30 +5023,41 @@ export class Dispatcher {
|
|
|
4946
5023
|
? ((allocatedLeaf ? this.store.retainedBuildFacts(record.slug) : undefined) ??
|
|
4947
5024
|
(await this.store.servedBuildFacts(record.slug)))
|
|
4948
5025
|
: await this.store.buildFacts(record.slug)
|
|
4949
|
-
|
|
4950
|
-
// workspace release, the proposer skip and the anchor of a runner an
|
|
4951
|
-
// older dispatcher launched (`legacyNodeRunner`).
|
|
4952
|
-
const marker =
|
|
4953
|
-
digest.kind === 'node'
|
|
4954
|
-
? served
|
|
4955
|
-
? facts.provisionMarker
|
|
4956
|
-
: (await readBuildFacts(this.store, record.slug)).value.provisionMarker
|
|
4957
|
-
: undefined
|
|
4958
|
-
builds.push({
|
|
4959
|
-
record,
|
|
4960
|
-
state: facts.state,
|
|
4961
|
-
workspace: facts.workspace !== null,
|
|
4962
|
-
provisioning:
|
|
4963
|
-
digest.kind === 'node'
|
|
4964
|
-
? marker !== undefined
|
|
4965
|
-
: this.continuations.has(record.slug) || !!launched?.has(record.slug),
|
|
4966
|
-
...(marker !== undefined ? { provisioningSeq: marker.seq } : {}),
|
|
4967
|
-
restackDue: landingRestackDue(facts.state, facts.log),
|
|
4968
|
-
})
|
|
5026
|
+
builds.push(await this.capacityBuildOf(record, digest, facts, launched, served))
|
|
4969
5027
|
}
|
|
4970
5028
|
return builds
|
|
4971
5029
|
}
|
|
4972
5030
|
|
|
5031
|
+
/** One nonterminal build's `CapacityBuild` from facts already read. */
|
|
5032
|
+
private async capacityBuildOf(
|
|
5033
|
+
record: BuildRecord,
|
|
5034
|
+
digest: BuildDigest,
|
|
5035
|
+
facts: CurrentBuildFacts,
|
|
5036
|
+
launched?: ReadonlySet<string>,
|
|
5037
|
+
served = false,
|
|
5038
|
+
): Promise<CapacityBuild> {
|
|
5039
|
+
// A node's marker no longer holds a slot: it feeds the stranded
|
|
5040
|
+
// workspace release, the proposer skip and the anchor of a runner an
|
|
5041
|
+
// older dispatcher launched (`legacyNodeRunner`).
|
|
5042
|
+
const marker =
|
|
5043
|
+
digest.kind === 'node'
|
|
5044
|
+
? served
|
|
5045
|
+
? facts.provisionMarker
|
|
5046
|
+
: (await readBuildFacts(this.store, record.slug)).value.provisionMarker
|
|
5047
|
+
: undefined
|
|
5048
|
+
return {
|
|
5049
|
+
record,
|
|
5050
|
+
state: facts.state,
|
|
5051
|
+
workspace: facts.workspace !== null,
|
|
5052
|
+
provisioning:
|
|
5053
|
+
digest.kind === 'node'
|
|
5054
|
+
? marker !== undefined
|
|
5055
|
+
: this.continuations.has(record.slug) || !!launched?.has(record.slug),
|
|
5056
|
+
...(marker !== undefined ? { provisioningSeq: marker.seq } : {}),
|
|
5057
|
+
restackDue: landingRestackDue(facts.state, facts.log),
|
|
5058
|
+
}
|
|
5059
|
+
}
|
|
5060
|
+
|
|
4973
5061
|
/** Whether this tick's start barrier holds back admission of this kind at
|
|
4974
5062
|
* this level (`admissionBarred`): the one guard waiting work (parked
|
|
4975
5063
|
* leaves, nodes and proposers through `slotAdmission`), ordinary claims and
|
|
@@ -5030,7 +5118,9 @@ export class Dispatcher {
|
|
|
5030
5118
|
* order"): for each level, urgent first, its parked work and then its
|
|
5031
5119
|
* claims. `occupied` counts every other build holding a slot. A waiter
|
|
5032
5120
|
* defers while claims can run, this tick's dispatch has not yet evaluated
|
|
5033
|
-
* them, and a higher-level claim can exist (`higherClaimsPossible`).
|
|
5121
|
+
* them, and a higher-level claim can exist (`higherClaimsPossible`). A
|
|
5122
|
+
* parked admission an earlier bounded pass carried never defers again
|
|
5123
|
+
* (#1435): it is decided against the latest durable claim demand. */
|
|
5034
5124
|
private slotAdmission(
|
|
5035
5125
|
slug: string,
|
|
5036
5126
|
priority: BuildPriority,
|
|
@@ -5043,6 +5133,7 @@ export class Dispatcher {
|
|
|
5043
5133
|
return 'wait'
|
|
5044
5134
|
const boundary =
|
|
5045
5135
|
this.admissionBoundary &&
|
|
5136
|
+
!this.carriedParked.has(slug) &&
|
|
5046
5137
|
this.claimsCanRun({ acceptNewWork: this.tickAcceptsNewWork }, this.tickPaused) &&
|
|
5047
5138
|
this.higherClaimsPossible(priority, builds)
|
|
5048
5139
|
return boundary ? 'defer' : 'admit'
|
|
@@ -5060,8 +5151,18 @@ export class Dispatcher {
|
|
|
5060
5151
|
* unless one is already in flight or another runner's live lease will
|
|
5061
5152
|
* refuse this launch; an acknowledgement appends none. A denial or
|
|
5062
5153
|
* deferral is recorded only in memory, for this tick's intake reservation;
|
|
5063
|
-
* a deferral is retried after this tick's dispatch
|
|
5064
|
-
|
|
5154
|
+
* a deferral is retried after this tick's dispatch, and a bounded pass
|
|
5155
|
+
* whose retry does not run carries it to the next pass (#1435).
|
|
5156
|
+
* `measured` is the occupancy a carried admission rebuilt
|
|
5157
|
+
* (`serviceCarriedAdmissions`), used instead of measuring the fleet; an
|
|
5158
|
+
* admission updates its own entry in place. */
|
|
5159
|
+
private async leafAdmission(
|
|
5160
|
+
slug: string,
|
|
5161
|
+
measured?: CapacityBuild[],
|
|
5162
|
+
): Promise<'admit' | 'wait' | 'defer'> {
|
|
5163
|
+
const carried = this.carriedParked.get(slug)
|
|
5164
|
+
if (carried !== undefined) carried.decided = true
|
|
5165
|
+
this.pendingParkedRetries.delete(slug)
|
|
5065
5166
|
const facts = await this.store.buildFacts(slug)
|
|
5066
5167
|
const { state } = facts
|
|
5067
5168
|
const self = { state, restackDue: landingRestackDue(state, facts.log) }
|
|
@@ -5093,7 +5194,12 @@ export class Dispatcher {
|
|
|
5093
5194
|
// the janitor's, and nothing a runner could do remains. Not a slot
|
|
5094
5195
|
// waiter either, so it reserves no intake.
|
|
5095
5196
|
if (state.prState === 'merged') return 'wait'
|
|
5096
|
-
const
|
|
5197
|
+
const bounded = this.tickOpts.deadlineAt !== undefined
|
|
5198
|
+
// The position precedes the measurement, so the next pass's
|
|
5199
|
+
// changed-builds feed covers every change the measurement could miss.
|
|
5200
|
+
if (bounded && measured === undefined && this.tickPosition === undefined)
|
|
5201
|
+
this.tickPosition = await this.store.getRepoChangePosition(this.deps.repo)
|
|
5202
|
+
const builds = measured ?? (await this.capacityBuilds(this.tickLaunched))
|
|
5097
5203
|
const others = builds.filter((build) => build.record.slug !== slug)
|
|
5098
5204
|
const capacity = this.deps.config.capacity
|
|
5099
5205
|
const now = this.deps.clock()
|
|
@@ -5117,20 +5223,55 @@ export class Dispatcher {
|
|
|
5117
5223
|
})
|
|
5118
5224
|
if (admitted !== null) {
|
|
5119
5225
|
this.slotWaiters.delete(slug)
|
|
5226
|
+
this.pass.admission('admitted', slug, priority)
|
|
5120
5227
|
// Retain the admitted facts, so this tick's capacity counts the
|
|
5121
5228
|
// build as holding its slot from here on.
|
|
5122
|
-
await this.store.servedBuildFacts(slug)
|
|
5229
|
+
const served = await this.store.servedBuildFacts(slug)
|
|
5230
|
+
const entry = measured?.find((build) => build.record.slug === slug)
|
|
5231
|
+
if (entry !== undefined) entry.state = served.state
|
|
5123
5232
|
return 'admit'
|
|
5124
5233
|
}
|
|
5125
5234
|
// The state moved under the decision: decide again next tick.
|
|
5126
5235
|
outcome = 'wait'
|
|
5127
5236
|
}
|
|
5128
5237
|
this.slotWaiters.set(slug, priority)
|
|
5129
|
-
if (outcome === 'defer'
|
|
5130
|
-
this.deferredAdmissions.set(slug, 'leaf')
|
|
5238
|
+
if (outcome === 'defer') {
|
|
5239
|
+
if (!this.deferredAdmissions.has(slug)) this.deferredAdmissions.set(slug, 'leaf')
|
|
5240
|
+
this.pass.admission('deferred', slug, priority)
|
|
5241
|
+
if (bounded) {
|
|
5242
|
+
this.pendingParkedRetries.set(slug, priority)
|
|
5243
|
+
this.tickWitness = this.witnessOf(builds, now)
|
|
5244
|
+
}
|
|
5245
|
+
}
|
|
5131
5246
|
return outcome
|
|
5132
5247
|
}
|
|
5133
5248
|
|
|
5249
|
+
/** The occupancy one capacity measurement saw, as the carry hint records
|
|
5250
|
+
* it (#1435); undefined without a position or past the witness bounds. */
|
|
5251
|
+
private witnessOf(builds: readonly CapacityBuild[], now: Date): ParkedWitness | undefined {
|
|
5252
|
+
const position = this.tickPosition
|
|
5253
|
+
if (position === undefined) return undefined
|
|
5254
|
+
const bySlug = (a: string, b: string) => (a < b ? -1 : a > b ? 1 : 0)
|
|
5255
|
+
const holders: string[] = []
|
|
5256
|
+
const waiters: ParkedWitness['waiters'] = []
|
|
5257
|
+
const volatile: string[] = []
|
|
5258
|
+
for (const build of builds) {
|
|
5259
|
+
const slug = build.record.slug
|
|
5260
|
+
if (occupiesCapacity(build, now)) holders.push(slug)
|
|
5261
|
+
else if (slotRequest(build, now) !== undefined)
|
|
5262
|
+
waiters.push({ slug, level: buildPriority(build.state) })
|
|
5263
|
+
else if (nodeSlotTimeDependent(build.state)) volatile.push(slug)
|
|
5264
|
+
}
|
|
5265
|
+
if (
|
|
5266
|
+
holders.length > MAX_WITNESS_HOLDERS ||
|
|
5267
|
+
waiters.length > MAX_WITNESS_WAITERS ||
|
|
5268
|
+
volatile.length > MAX_WITNESS_VOLATILE
|
|
5269
|
+
)
|
|
5270
|
+
return undefined
|
|
5271
|
+
waiters.sort((a, b) => priorityRank(a.level) - priorityRank(b.level) || bySlug(a.slug, b.slug))
|
|
5272
|
+
return { position, holders: holders.sort(bySlug), waiters, volatile: volatile.sort(bySlug) }
|
|
5273
|
+
}
|
|
5274
|
+
|
|
5134
5275
|
/**
|
|
5135
5276
|
* Retry every admission deferred this tick, once this tick's admission scan
|
|
5136
5277
|
* has evaluated claims at every level. Each retry re-enters its generic path with
|
|
@@ -5160,10 +5301,15 @@ export class Dispatcher {
|
|
|
5160
5301
|
this.pass.total('parked', deferred.length)
|
|
5161
5302
|
for (const [slug, kind] of deferred) {
|
|
5162
5303
|
if (!this.passItem(opts, 'parked')) return
|
|
5163
|
-
if (launched.has(slug))
|
|
5304
|
+
if (launched.has(slug)) {
|
|
5305
|
+
this.pendingParkedRetries.delete(slug)
|
|
5306
|
+
continue
|
|
5307
|
+
}
|
|
5164
5308
|
try {
|
|
5165
5309
|
const record = await this.store.getBuild(slug)
|
|
5166
5310
|
if (record === null) continue
|
|
5311
|
+
// The retry runs: nothing is carried for it (#1435).
|
|
5312
|
+
this.pendingParkedRetries.delete(slug)
|
|
5167
5313
|
if (kind === 'leaf')
|
|
5168
5314
|
await this.sweepBuild(record, report, launched, paused, this.deps.clock().getTime())
|
|
5169
5315
|
else if (kind === 'node') {
|
|
@@ -9285,7 +9431,7 @@ export class Dispatcher {
|
|
|
9285
9431
|
launched: Set<string>,
|
|
9286
9432
|
paused: boolean,
|
|
9287
9433
|
now: number,
|
|
9288
|
-
carried?: { facts: CurrentBuildFacts },
|
|
9434
|
+
carried?: { facts: CurrentBuildFacts; measured?: CapacityBuild[] },
|
|
9289
9435
|
): Promise<'done' | 'waiting' | 'failed'> {
|
|
9290
9436
|
try {
|
|
9291
9437
|
return await this.sweepBuild(record, report, launched, paused, now, carried)
|
|
@@ -9346,11 +9492,17 @@ export class Dispatcher {
|
|
|
9346
9492
|
opts: TickOpts,
|
|
9347
9493
|
): Promise<void> {
|
|
9348
9494
|
const carriedPreparations = this.carriedPreparationsOutstanding.size
|
|
9349
|
-
|
|
9495
|
+
const carriedAdmissions = this.carriedParked.size
|
|
9496
|
+
if (this.carriedOutstanding.size === 0 && carriedPreparations === 0 && carriedAdmissions === 0)
|
|
9350
9497
|
return this.pass.total('deferred', 0)
|
|
9351
|
-
this.pass.total(
|
|
9498
|
+
this.pass.total(
|
|
9499
|
+
'deferred',
|
|
9500
|
+
this.carriedOutstanding.size + carriedPreparations + carriedAdmissions,
|
|
9501
|
+
)
|
|
9352
9502
|
if (this.carriedOutstanding.size > 0)
|
|
9353
9503
|
await this.serviceDeferredBuilds(report, launched, paused, opts)
|
|
9504
|
+
// Carried parked admissions (#1435), decided before any stage can be cut.
|
|
9505
|
+
if (carriedAdmissions > 0) await this.serviceCarriedAdmissions(report, launched, paused, opts)
|
|
9354
9506
|
// Carried ticket preparations (#1431), after the carried builds: each
|
|
9355
9507
|
// attempt resumes from its durable boundaries, with no fleet read.
|
|
9356
9508
|
for (const attempt of [...this.carriedPreparationsOutstanding.keys()]) {
|
|
@@ -9381,6 +9533,90 @@ export class Dispatcher {
|
|
|
9381
9533
|
await this.persistDeferrals()
|
|
9382
9534
|
}
|
|
9383
9535
|
|
|
9536
|
+
/**
|
|
9537
|
+
* Decide the parked admissions the previous bounded pass deferred and did
|
|
9538
|
+
* not retry (#1435), first and without deferring again, against the latest
|
|
9539
|
+
* durable claim demand, start requests and higher-level waiters. Occupancy
|
|
9540
|
+
* is rebuilt from that pass's witness, never by measuring the fleet: one
|
|
9541
|
+
* changed-builds feed call since the witness position (no event rows),
|
|
9542
|
+
* then one reduced read for each witness holder, waiter and time-dependent
|
|
9543
|
+
* node, each build changed since, and each carried waiter. Every other
|
|
9544
|
+
* open build is unchanged since the measurement and its slot state takes
|
|
9545
|
+
* no clock (`nodeSlotTimeDependent`), so it still holds and requests
|
|
9546
|
+
* nothing. An admitted waiter launches through the ordinary sweep pass and
|
|
9547
|
+
* the lease sweep skips it. Without a usable witness (none recorded, or
|
|
9548
|
+
* the feed reports a reset or rejects) nothing is read here: each carried
|
|
9549
|
+
* waiter keeps only its closed boundary, and the sweep decides it on its
|
|
9550
|
+
* ordinary visit.
|
|
9551
|
+
*/
|
|
9552
|
+
private async serviceCarriedAdmissions(
|
|
9553
|
+
report: TickReport,
|
|
9554
|
+
launched: Set<string>,
|
|
9555
|
+
paused: boolean,
|
|
9556
|
+
opts: TickOpts,
|
|
9557
|
+
): Promise<void> {
|
|
9558
|
+
const witness = this.carriedWitness
|
|
9559
|
+
const pending = [...this.carriedParked].filter(([, entry]) => !entry.decided)
|
|
9560
|
+
if (witness === undefined || pending.length === 0) return
|
|
9561
|
+
let changed: ChangedBuilds
|
|
9562
|
+
try {
|
|
9563
|
+
changed = await this.store.listBuildsChangedSince(this.deps.repo, witness.position)
|
|
9564
|
+
} catch (error) {
|
|
9565
|
+
rethrowAuthorityLapse(error)
|
|
9566
|
+
return
|
|
9567
|
+
}
|
|
9568
|
+
if (compareChangePositions(changed.position, witness.position) < 0) return
|
|
9569
|
+
const entries = new Map(
|
|
9570
|
+
(await this.repoBuildDigests(true)).map((entry) => [entry.record.slug, entry]),
|
|
9571
|
+
)
|
|
9572
|
+
const read = new Set([
|
|
9573
|
+
...witness.holders,
|
|
9574
|
+
...witness.waiters.map((waiter) => waiter.slug),
|
|
9575
|
+
...witness.volatile,
|
|
9576
|
+
...changed.builds.map((build) => build.slug),
|
|
9577
|
+
...pending.map(([slug]) => slug),
|
|
9578
|
+
])
|
|
9579
|
+
const measured: CapacityBuild[] = []
|
|
9580
|
+
const facts = new Map<string, CurrentBuildFacts>()
|
|
9581
|
+
for (const slug of read) {
|
|
9582
|
+
const entry = entries.get(slug)
|
|
9583
|
+
if (entry === undefined || entry.digest.terminal !== undefined) continue
|
|
9584
|
+
const current = await this.store.buildFacts(slug)
|
|
9585
|
+
facts.set(slug, current)
|
|
9586
|
+
measured.push(await this.capacityBuildOf(entry.record, entry.digest, current, launched))
|
|
9587
|
+
}
|
|
9588
|
+
const order = pending.map(([slug]) => slug)
|
|
9589
|
+
const waiting: CapacityBuild[] = []
|
|
9590
|
+
for (const slug of order) {
|
|
9591
|
+
const build = measured.find((candidate) => candidate.record.slug === slug)
|
|
9592
|
+
// Terminal or gone: retired.
|
|
9593
|
+
if (build === undefined || build.state.kind === 'node') this.carriedParked.delete(slug)
|
|
9594
|
+
else waiting.push(build)
|
|
9595
|
+
}
|
|
9596
|
+
waiting.sort(
|
|
9597
|
+
(a, b) =>
|
|
9598
|
+
priorityRank(buildPriority(a.state)) - priorityRank(buildPriority(b.state)) ||
|
|
9599
|
+
order.indexOf(a.record.slug) - order.indexOf(b.record.slug),
|
|
9600
|
+
)
|
|
9601
|
+
for (const build of waiting) {
|
|
9602
|
+
const slug = build.record.slug
|
|
9603
|
+
const entry = this.carriedParked.get(slug)
|
|
9604
|
+
if (entry === undefined || entry.decided) continue
|
|
9605
|
+
if (!this.passItem(opts, 'deferred')) break
|
|
9606
|
+
entry.decided = true
|
|
9607
|
+
if (launched.has(slug)) continue
|
|
9608
|
+
this.tickPrioritized.add(slug)
|
|
9609
|
+
await this.sweepContained(
|
|
9610
|
+
build.record,
|
|
9611
|
+
report,
|
|
9612
|
+
launched,
|
|
9613
|
+
paused,
|
|
9614
|
+
this.deps.clock().getTime(),
|
|
9615
|
+
{ facts: facts.get(slug)!, measured },
|
|
9616
|
+
)
|
|
9617
|
+
}
|
|
9618
|
+
}
|
|
9619
|
+
|
|
9384
9620
|
/** The carried builds of `serviceDeferredWork`. */
|
|
9385
9621
|
private async serviceDeferredBuilds(
|
|
9386
9622
|
report: TickReport,
|
|
@@ -9621,6 +9857,12 @@ export class Dispatcher {
|
|
|
9621
9857
|
* tick report would. No reads; never rejects. */
|
|
9622
9858
|
async settleCutStarts(): Promise<string[]> {
|
|
9623
9859
|
while (this.startsInFlight.size > 0) await Promise.allSettled([...this.startsInFlight])
|
|
9860
|
+
// An abandoned pass carries the parked admissions it deferred (#1435);
|
|
9861
|
+
// the write goes through the teardown scope.
|
|
9862
|
+
if (this.tickOpts.deadlineAt !== undefined && this.inFlightReport !== undefined) {
|
|
9863
|
+
this.finalizeParkedCarries()
|
|
9864
|
+
await this.persistDeferrals().catch(() => {})
|
|
9865
|
+
}
|
|
9624
9866
|
await this.deferralWrites
|
|
9625
9867
|
const lines: string[] = []
|
|
9626
9868
|
for (const [slug, deferral] of this.tickDeferrals) {
|
|
@@ -9629,9 +9871,55 @@ export class Dispatcher {
|
|
|
9629
9871
|
lines.push(deferralLine(slug, deferral))
|
|
9630
9872
|
}
|
|
9631
9873
|
lines.push(...this.unreportedPreparationCarries())
|
|
9874
|
+
lines.push(...this.unreportedParkedCarries())
|
|
9632
9875
|
return lines
|
|
9633
9876
|
}
|
|
9634
9877
|
|
|
9878
|
+
/** This tick's carried parked admissions not yet named in a report or
|
|
9879
|
+
* teardown line, each marked reported. */
|
|
9880
|
+
private unreportedParkedCarries(): string[] {
|
|
9881
|
+
const lines: string[] = []
|
|
9882
|
+
for (const [slug, level] of this.tickParkedCarries) {
|
|
9883
|
+
const key = `parked:${slug}`
|
|
9884
|
+
if (this.reportedDeferrals.has(key)) continue
|
|
9885
|
+
this.reportedDeferrals.add(key)
|
|
9886
|
+
lines.push(parkedCarryLine(slug, level))
|
|
9887
|
+
}
|
|
9888
|
+
return lines
|
|
9889
|
+
}
|
|
9890
|
+
|
|
9891
|
+
/** Carry every parked admission this bounded pass deferred and did not
|
|
9892
|
+
* retry to the next pass (#1435): named on the stage record and the tick
|
|
9893
|
+
* report, and written with the hint. Once per pass. */
|
|
9894
|
+
private finalizeParkedCarries(): void {
|
|
9895
|
+
if (this.tickOpts.deadlineAt === undefined || this.parkedCarriesFinalized) return
|
|
9896
|
+
this.parkedCarriesFinalized = true
|
|
9897
|
+
for (const [slug, level] of this.pendingParkedRetries) {
|
|
9898
|
+
this.tickParkedCarries.set(slug, level)
|
|
9899
|
+
this.pass.carriedAdmission(slug, level)
|
|
9900
|
+
}
|
|
9901
|
+
this.pendingParkedRetries.clear()
|
|
9902
|
+
}
|
|
9903
|
+
|
|
9904
|
+
/** The hint's `parked` entry this tick would write: carried admissions
|
|
9905
|
+
* this pass has not decided, in carried order, then this pass's carries,
|
|
9906
|
+
* capped. A dropped slug is still a waiter, which a later pass defers and
|
|
9907
|
+
* carries again. The witness is this pass's measurement when it carried
|
|
9908
|
+
* anything new (it describes the fleet, so it serves every slug), else the
|
|
9909
|
+
* carried one. An unbounded tick keeps the entry as read. */
|
|
9910
|
+
private nextParked(): ParkedCarry | undefined {
|
|
9911
|
+
if (this.tickOpts.deadlineAt === undefined) return this.recordedParked
|
|
9912
|
+
const slugs = new Set<string>()
|
|
9913
|
+
for (const [slug, entry] of this.carriedParked) if (!entry.decided) slugs.add(slug)
|
|
9914
|
+
for (const slug of this.tickParkedCarries.keys()) slugs.add(slug)
|
|
9915
|
+
if (slugs.size === 0) return undefined
|
|
9916
|
+
const witness = this.tickParkedCarries.size > 0 ? this.tickWitness : this.carriedWitness
|
|
9917
|
+
return {
|
|
9918
|
+
slugs: [...slugs].slice(0, MAX_CARRIED_ADMISSIONS),
|
|
9919
|
+
...(witness !== undefined ? { witness } : {}),
|
|
9920
|
+
}
|
|
9921
|
+
}
|
|
9922
|
+
|
|
9635
9923
|
/** This tick's carried preparations not yet named in a report or teardown
|
|
9636
9924
|
* line, each marked reported. */
|
|
9637
9925
|
private unreportedPreparationCarries(): string[] {
|
|
@@ -9741,7 +10029,9 @@ export class Dispatcher {
|
|
|
9741
10029
|
const recorded = this.recordedDeferrals
|
|
9742
10030
|
const tickets = this.nextPreparationCarryList()
|
|
9743
10031
|
const recordedTickets = this.recordedPreparationCarries
|
|
10032
|
+
const parked = this.nextParked()
|
|
9744
10033
|
if (
|
|
10034
|
+
JSON.stringify(parked ?? null) === JSON.stringify(this.recordedParked ?? null) &&
|
|
9745
10035
|
next.length === recorded.length &&
|
|
9746
10036
|
next.every(
|
|
9747
10037
|
(entry, i) =>
|
|
@@ -9763,12 +10053,17 @@ export class Dispatcher {
|
|
|
9763
10053
|
actor: DISPATCHER,
|
|
9764
10054
|
type: 'dispatcher.work-deferred',
|
|
9765
10055
|
// A hint without carried preparations keeps its earlier payload.
|
|
9766
|
-
payload: {
|
|
10056
|
+
payload: {
|
|
10057
|
+
builds: next,
|
|
10058
|
+
...(tickets.length > 0 ? { tickets } : {}),
|
|
10059
|
+
...(parked !== undefined ? { parked } : {}),
|
|
10060
|
+
},
|
|
9767
10061
|
}),
|
|
9768
10062
|
)
|
|
9769
10063
|
if (outcome === true) {
|
|
9770
10064
|
this.recordedDeferrals = next
|
|
9771
10065
|
this.recordedPreparationCarries = tickets
|
|
10066
|
+
this.recordedParked = parked
|
|
9772
10067
|
} else if (outcome !== false) this.deferralWriteFailure = outcome
|
|
9773
10068
|
})
|
|
9774
10069
|
this.deferralWrites = write.catch(() => {})
|
|
@@ -9838,6 +10133,7 @@ export class Dispatcher {
|
|
|
9838
10133
|
if (this.tickPreparationCarries.size > 0)
|
|
9839
10134
|
report.preparationsCarried = this.tickPreparationCarries.size
|
|
9840
10135
|
report.deferredDiagnostics.push(...this.unreportedPreparationCarries())
|
|
10136
|
+
report.deferredDiagnostics.push(...this.unreportedParkedCarries())
|
|
9841
10137
|
if (this.deferralWriteFailure !== undefined)
|
|
9842
10138
|
report.deferredDiagnostics.push(
|
|
9843
10139
|
`deferred work not recorded for the next invocation — ${this.deferralWriteFailure}`,
|
|
@@ -9909,13 +10205,11 @@ export class Dispatcher {
|
|
|
9909
10205
|
launched: Set<string>,
|
|
9910
10206
|
paused: boolean,
|
|
9911
10207
|
now: number,
|
|
9912
|
-
carried?: { facts: CurrentBuildFacts },
|
|
10208
|
+
carried?: { facts: CurrentBuildFacts; measured?: CapacityBuild[] },
|
|
9913
10209
|
): Promise<'done' | 'waiting'> {
|
|
9914
10210
|
return (await this.sweepBuildPass(record, report, launched, paused, now, carried)) ?? 'done'
|
|
9915
10211
|
}
|
|
9916
10212
|
|
|
9917
|
-
/** `carried` is a deferred-work entry's pass: its facts are already read,
|
|
9918
|
-
* and the first-claim grace does not apply. */
|
|
9919
10213
|
/** Settle, in place and without a runner, every session an ended execution
|
|
9920
10214
|
* left open (SPEC §15.6-C), on running, held and terminal builds alike: an
|
|
9921
10215
|
* unfinished occurrence with a native handle of a live build is suspended as
|
|
@@ -10026,13 +10320,16 @@ export class Dispatcher {
|
|
|
10026
10320
|
return wrote
|
|
10027
10321
|
}
|
|
10028
10322
|
|
|
10323
|
+
/** `carried` is a deferred-work entry's pass: its facts are already read,
|
|
10324
|
+
* and the first-claim grace does not apply. A carried parked admission
|
|
10325
|
+
* (#1435) also brings the occupancy it rebuilt (`measured`). */
|
|
10029
10326
|
private async sweepBuildPass(
|
|
10030
10327
|
record: BuildRecord,
|
|
10031
10328
|
report: TickReport,
|
|
10032
10329
|
launched: Set<string>,
|
|
10033
10330
|
paused: boolean,
|
|
10034
10331
|
now: number,
|
|
10035
|
-
carried?: { facts: CurrentBuildFacts },
|
|
10332
|
+
carried?: { facts: CurrentBuildFacts; measured?: CapacityBuild[] },
|
|
10036
10333
|
): Promise<'waiting' | undefined> {
|
|
10037
10334
|
if (record.lease) {
|
|
10038
10335
|
if (new Date(record.lease.expiresAt).getTime() > now) return // healthy
|
|
@@ -10221,7 +10518,12 @@ export class Dispatcher {
|
|
|
10221
10518
|
const runs = decision.kind !== 'wait' || publicationRecoveryDue || orphanRecoveryDue
|
|
10222
10519
|
// A finished leaf with work to run waits for a slot before anything is
|
|
10223
10520
|
// reaped, provisioned or launched for it.
|
|
10224
|
-
if (
|
|
10521
|
+
if (
|
|
10522
|
+
runs &&
|
|
10523
|
+
state.kind !== 'node' &&
|
|
10524
|
+
(await this.leafAdmission(record.slug, carried?.measured)) !== 'admit'
|
|
10525
|
+
)
|
|
10526
|
+
return
|
|
10225
10527
|
// A node relaunches only for work it holds a slot for: a retained
|
|
10226
10528
|
// workspace confers none. Abort and pause acknowledgements are ungated.
|
|
10227
10529
|
if (runs && state.kind === 'node' && !this.nodeRelaunchAdmitted(record, facts)) return
|