@defrex/autobuild 1.5.0 → 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 +85 -14
- package/docs/answering-blocked-builds.md +7 -4
- package/docs/architecture.md +38 -10
- package/docs/configuration.md +55 -5
- package/docs/dispatcher.md +2 -2
- package/docs/glossary.md +1 -1
- package/docs/operating.md +1 -1
- package/docs/operator-api.md +14 -2
- package/docs/plugin-authoring.md +4 -0
- package/docs/remote-store-protocol.md +14 -4
- package/docs/restacking.md +4 -0
- package/docs/tickets.md +1 -1
- package/docs/troubleshooting.md +1 -1
- package/package.json +3 -3
- package/packages/core/src/cli/attention.ts +2 -0
- package/packages/core/src/cli/dashboard/model.ts +14 -4
- package/packages/core/src/cli/dashboard/poll.ts +14 -0
- package/packages/core/src/cli/dashboard/render.ts +3 -0
- package/packages/core/src/cli/dispatch-preflight.ts +4 -1
- 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 +368 -98
- package/packages/core/src/cli/help.ts +4 -2
- package/packages/core/src/cli/repo-lease.ts +225 -0
- package/packages/core/src/cli/repository-status.ts +3 -1
- package/packages/core/src/cli/status.ts +13 -13
- package/packages/core/src/cli/wait.ts +4 -1
- package/packages/core/src/cli/watch.ts +15 -4
- package/packages/core/src/config/schema.ts +38 -2
- package/packages/core/src/events/catalog.ts +2 -0
- package/packages/core/src/events/payloads.ts +15 -0
- package/packages/core/src/events/policy.ts +2 -0
- package/packages/core/src/events/repository.ts +2 -0
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +196 -230
- package/packages/core/src/kernel/dispatch-capacity.ts +134 -30
- package/packages/core/src/kernel/engine.ts +13 -6
- package/packages/core/src/kernel/generators/build-log.ts +9 -0
- package/packages/core/src/kernel/incremental-fixtures.ts +1 -0
- package/packages/core/src/kernel/janitor-failure.ts +85 -5
- 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-landing.ts +2 -1
- package/packages/core/src/kernel/reducer-registry.ts +6 -1
- package/packages/core/src/kernel/reducer.ts +58 -4
- package/packages/core/src/kernel/ticket-preparation.ts +11 -7
- package/packages/core/src/operator/query.ts +15 -12
- package/packages/core/src/ports/tickets/create.ts +19 -5
- package/packages/core/src/ports/types.ts +4 -0
- package/packages/core/src/ports/workspace/commit-preservation.ts +28 -12
- package/packages/core/src/ports/workspace/git-worktree.ts +3 -1
- package/packages/core/src/ports/workspace/harvest-execution.ts +4 -2
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +3 -0
- package/packages/core/src/processes/build-runner.ts +2 -1
- package/packages/core/src/processes/dispatcher.ts +231 -41
- package/packages/core/src/processes/execution-no-progress.ts +2 -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 +246 -17
- package/packages/core/src/scenarios/harness.ts +145 -35
- package/packages/core/src/store/reduced-reads.ts +10 -0
- package/packages/core/src/store/reducer-value-shapes.json +1463 -1215
- package/packages/core/src/store/remote/released-clients.json +11 -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 +2 -0
- package/packages/core/src/testing/reduced-read-budget.ts +339 -2
- package/skills/guide/SKILL.md +53 -17
- package/skills/guide/references/operator-api.md +14 -2
- package/skills/guide/references/plugin-authoring.md +4 -0
- package/skills/guide/references/remote-store-protocol.md +14 -4
- package/skills/guide/references/restacking.md +4 -0
- package/skills/operate/SKILL.md +50 -11
- package/skills/tickets/SKILL.md +4 -2
- package/templates/hosted-service/package.json +2 -2
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { proveTargetLineage } from '../kernel/target-lineage'
|
|
2
|
+
import {
|
|
3
|
+
isRepositoryAuthorityLapse,
|
|
4
|
+
RepositoryAuthorityLapsed,
|
|
5
|
+
rethrowAuthorityLapse,
|
|
6
|
+
} from '../cli/repo-lease'
|
|
2
7
|
import { assertTargetOid, observeTarget } from '../kernel/target-observation'
|
|
3
8
|
import {
|
|
4
9
|
MissingAccountCredentialsError,
|
|
@@ -50,7 +55,16 @@ import {
|
|
|
50
55
|
MixedVersionDeferral,
|
|
51
56
|
} from '../kernel/mixed-version'
|
|
52
57
|
import { guardForge, ForgeCooldown } from '../kernel/guarded-forge'
|
|
53
|
-
import {
|
|
58
|
+
import {
|
|
59
|
+
escalationsBeyondJanitor,
|
|
60
|
+
janitorBlocked,
|
|
61
|
+
janitorDeferral,
|
|
62
|
+
janitorDue,
|
|
63
|
+
janitorStatus,
|
|
64
|
+
recordJanitorFailure,
|
|
65
|
+
withoutJanitorEscalation,
|
|
66
|
+
type JanitorOperation,
|
|
67
|
+
} from '../kernel/janitor-failure'
|
|
54
68
|
import { KernelGitUnavailable, kernelGitUnavailableDetail } from '../kernel/kernel-git'
|
|
55
69
|
import { isForgeFailure } from '../ports/forge-failure'
|
|
56
70
|
import {
|
|
@@ -60,8 +74,11 @@ import {
|
|
|
60
74
|
} from '../ports/forge-request-context'
|
|
61
75
|
import {
|
|
62
76
|
dispatchCapacity,
|
|
77
|
+
epilogueLeaf,
|
|
63
78
|
intakeCapacity,
|
|
64
79
|
nodeCapacity,
|
|
80
|
+
settlementDue,
|
|
81
|
+
settlementKey,
|
|
65
82
|
slotRequest,
|
|
66
83
|
type CapacityBuild,
|
|
67
84
|
} from '../kernel/dispatch-capacity'
|
|
@@ -168,7 +185,7 @@ import type { EventPayload, PinnedAsset } from '../events/payloads'
|
|
|
168
185
|
import type { IdSource } from '../ids'
|
|
169
186
|
import { recordAutoMergeDeferralObservation } from '../kernel/auto-merge'
|
|
170
187
|
import type { AutoMergeDefaultFact } from '../kernel/auto-merge-default'
|
|
171
|
-
import { decideNextFromFacts } from '../kernel/engine'
|
|
188
|
+
import { decideNextFromFacts, landingRestackDue } from '../kernel/engine'
|
|
172
189
|
import { composeBuildConfig } from '../config/live'
|
|
173
190
|
import { BUILD_EFFECTIVE_CONFIG_ARTIFACT, parseEffectiveBuildConfig } from './build-execution-state'
|
|
174
191
|
import {
|
|
@@ -680,6 +697,11 @@ export interface TickOpts {
|
|
|
680
697
|
export type LaunchRunnerResult = 'scheduled' | 'already-active'
|
|
681
698
|
|
|
682
699
|
export interface DispatcherDeps {
|
|
700
|
+
/** Whether this process currently holds repository authority (SPEC §12).
|
|
701
|
+
* Synchronous and without I/O. Absent means always true. When false, the
|
|
702
|
+
* tick starts no further unit of work, and its durable new-work writes are
|
|
703
|
+
* refused with `RepositoryAuthorityLapsed`. */
|
|
704
|
+
holdsRepoAuthority?: () => boolean
|
|
683
705
|
/** Current selected-account presence; no store reads. */
|
|
684
706
|
missingAccounts?: () => MissingAccountCredential[]
|
|
685
707
|
accountCredentialSource?: MissingAccountCredential['source']
|
|
@@ -1037,6 +1059,14 @@ export class Dispatcher {
|
|
|
1037
1059
|
/** Process-local background provisioning, keyed by slug. A tick that sees a
|
|
1038
1060
|
* slug here defers to the continuation; it never blocks on it. */
|
|
1039
1061
|
private readonly continuations = new Map<string, ProvisionContinuation>()
|
|
1062
|
+
/** Per tick, rebuilt from durable state: builds launched so far, which
|
|
1063
|
+
* occupy a slot before their runner claims a lease. */
|
|
1064
|
+
private tickLaunched: ReadonlySet<string> = new Set()
|
|
1065
|
+
/** Per tick: finished leaves the admission gate turned away. Intake reserves their slots. */
|
|
1066
|
+
private readonly slotWaiters = new Set<string>()
|
|
1067
|
+
/** Per tick: parked leaves whose sweep decision was `wait awaiting-pr`. A
|
|
1068
|
+
* projected wait for one of these is one tick stale and reserves nothing. */
|
|
1069
|
+
private readonly parkedSettled = new Set<string>()
|
|
1040
1070
|
|
|
1041
1071
|
// Batched confirmed landing evidence is shared across nodes for this tick.
|
|
1042
1072
|
// Only durable availability facts authorize the shortcut after restart. The
|
|
@@ -1098,7 +1128,10 @@ export class Dispatcher {
|
|
|
1098
1128
|
* loops consult this before starting each new forge/store transport call,
|
|
1099
1129
|
* bounding the tick's overrun to the one call already in flight. */
|
|
1100
1130
|
private outOfBudget(opts: TickOpts): boolean {
|
|
1101
|
-
return
|
|
1131
|
+
return (
|
|
1132
|
+
(opts.deadlineAt !== undefined && this.deps.clock().getTime() >= opts.deadlineAt) ||
|
|
1133
|
+
this.deps.holdsRepoAuthority?.() === false
|
|
1134
|
+
)
|
|
1102
1135
|
}
|
|
1103
1136
|
|
|
1104
1137
|
lastForgeRequests?: import('../ports/forge-telemetry').ForgeRequestCounts
|
|
@@ -1175,6 +1208,8 @@ export class Dispatcher {
|
|
|
1175
1208
|
this.integrationInputs = undefined
|
|
1176
1209
|
this.integrationPublicationInputs = undefined
|
|
1177
1210
|
this.nodePollingTickReads.clear()
|
|
1211
|
+
this.slotWaiters.clear()
|
|
1212
|
+
this.parkedSettled.clear()
|
|
1178
1213
|
// One immutable config for this complete decision pass. A reload racing the
|
|
1179
1214
|
// tick is observed by the next tick, never half-way through this one.
|
|
1180
1215
|
this.deps.config = this.deps.getConfig?.() ?? this.deps.config
|
|
@@ -1185,6 +1220,7 @@ export class Dispatcher {
|
|
|
1185
1220
|
/** Builds already launched this tick — a janitor/startup re-attach must
|
|
1186
1221
|
* not be doubled by the sweep, nor a fresh dispatch by anything. */
|
|
1187
1222
|
const launched = new Set<string>()
|
|
1223
|
+
this.tickLaunched = launched
|
|
1188
1224
|
// One journal read for both repository-wide controls: a pause that lands
|
|
1189
1225
|
// mid-tick takes effect on the next tick, matching intake (which the CLI
|
|
1190
1226
|
// likewise samples before calling `tick`); the auto-merge default fact is
|
|
@@ -1655,6 +1691,7 @@ export class Dispatcher {
|
|
|
1655
1691
|
)
|
|
1656
1692
|
return 'already-active'
|
|
1657
1693
|
if (launched.has(slug)) return 'already-active'
|
|
1694
|
+
if (launchState.kind !== 'node' && !(await this.leafAdmission(slug))) return 'already-active'
|
|
1658
1695
|
launched.add(slug)
|
|
1659
1696
|
const facts = (await readBuildFacts(this.store, slug)).value
|
|
1660
1697
|
// Callers reap and reprovision a flagged workspace; an agent never starts
|
|
@@ -1743,8 +1780,10 @@ export class Dispatcher {
|
|
|
1743
1780
|
* execution is not supervised by this process is observed through the
|
|
1744
1781
|
* owning provider. `lost`/`ended` reaps the disposable environment and
|
|
1745
1782
|
* journals the close fact with the snapshot purge outcome; `running`
|
|
1746
|
-
* leaves it — the guest is the live supervisor and
|
|
1747
|
-
*
|
|
1783
|
+
* leaves it — the guest is the live supervisor and its authority is its
|
|
1784
|
+
* durable `harvest.execution.authorized`, not any invocation's repository
|
|
1785
|
+
* lease, which it leaves to dispatch; the next pass reaps it after it
|
|
1786
|
+
* ends. Until the
|
|
1748
1787
|
* release is journaled, an open observable execution also suppresses
|
|
1749
1788
|
* harvest launch (`liveForeignHarvestExecution`). The run itself needs no
|
|
1750
1789
|
* settlement here: an interrupted run stays open in the journal, and the
|
|
@@ -1967,6 +2006,7 @@ export class Dispatcher {
|
|
|
1967
2006
|
report.sandboxIdleStops += 1
|
|
1968
2007
|
}
|
|
1969
2008
|
} catch (error) {
|
|
2009
|
+
rethrowAuthorityLapse(error)
|
|
1970
2010
|
// Contained: the next tick retries this environment.
|
|
1971
2011
|
report.sandboxSettleFailures += 1
|
|
1972
2012
|
report.janitorDiagnostics.push(
|
|
@@ -2012,7 +2052,7 @@ export class Dispatcher {
|
|
|
2012
2052
|
autoMergeDefaultSeq?: number
|
|
2013
2053
|
assets?: PinnedAsset[]
|
|
2014
2054
|
},
|
|
2015
|
-
): Promise<'kicked' | 'in-flight' | 'foreign-live'> {
|
|
2055
|
+
): Promise<'kicked' | 'in-flight' | 'foreign-live' | 'slot-wait'> {
|
|
2016
2056
|
const slug = record.slug
|
|
2017
2057
|
if (!this.accountsAvailable()) return 'in-flight'
|
|
2018
2058
|
if (this.continuations.has(slug)) return 'in-flight'
|
|
@@ -2033,8 +2073,12 @@ export class Dispatcher {
|
|
|
2033
2073
|
}
|
|
2034
2074
|
// Expired lease, failed attempt, or an old lease-less marker: adopt.
|
|
2035
2075
|
}
|
|
2076
|
+
// A finished leaf waits for a slot before its continuation reserves one.
|
|
2077
|
+
// Nothing is written: the wait costs no attempt and raises no attention.
|
|
2078
|
+
if (tail === 'launch' && !(await this.leafAdmission(slug))) return 'slot-wait'
|
|
2036
2079
|
const branch = record.branch ?? `ab/${slug}`
|
|
2037
2080
|
const generation = events.workspaceGenerations
|
|
2081
|
+
if (this.deps.holdsRepoAuthority?.() === false) return 'in-flight'
|
|
2038
2082
|
await this.store.append(slug, {
|
|
2039
2083
|
actor: DISPATCHER,
|
|
2040
2084
|
type: 'workspace.provision-started',
|
|
@@ -2173,8 +2217,13 @@ export class Dispatcher {
|
|
|
2173
2217
|
const queued = (await readBuildFacts(store, slug)).value.state.status === 'queued'
|
|
2174
2218
|
boundary = input.tail === 'dispatch' || queued ? 'dispatch' : 'launch'
|
|
2175
2219
|
if (boundary === 'dispatch') await this.completeDispatchBoundaries(record, input.seed)
|
|
2220
|
+
// Deliberately ungated: admission was decided when this continuation
|
|
2221
|
+
// was kicked, and its lease and map entry have held the slot since.
|
|
2176
2222
|
else if (this.accountsAvailable()) await this.startRunner(slug, emptyTickReport())
|
|
2177
2223
|
} catch (error) {
|
|
2224
|
+
// A lapsed repository lease started nothing: no failure fact. The
|
|
2225
|
+
// finally releases the execution lease; the successor adopts the marker.
|
|
2226
|
+
if (isRepositoryAuthorityLapse(error)) return
|
|
2178
2227
|
// Dispatch boundaries own their failure facts and exhaustion repair.
|
|
2179
2228
|
// A failed tail read/write leaves durable unfinished work for the next
|
|
2180
2229
|
// tick; it is not another provider workspace failure. Replacement
|
|
@@ -2295,6 +2344,7 @@ export class Dispatcher {
|
|
|
2295
2344
|
try {
|
|
2296
2345
|
await reportIntegrationFailures(this.store, record.slug)
|
|
2297
2346
|
} catch (error) {
|
|
2347
|
+
rethrowAuthorityLapse(error)
|
|
2298
2348
|
report.janitorDiagnostics.push(
|
|
2299
2349
|
`build ${record.slug}: integration attention recovery failed — ${String(error)}`,
|
|
2300
2350
|
)
|
|
@@ -2308,6 +2358,8 @@ export class Dispatcher {
|
|
|
2308
2358
|
if (this.outOfBudget(opts)) break
|
|
2309
2359
|
await withForgeRequestContext({ build: record.slug }, async () => {
|
|
2310
2360
|
let previous: BuildState['janitor']
|
|
2361
|
+
// The stage in progress, named if this attempt's failure escalates.
|
|
2362
|
+
let operation: JanitorOperation = 'build state read'
|
|
2311
2363
|
let attempted = false
|
|
2312
2364
|
let failed = false
|
|
2313
2365
|
try {
|
|
@@ -2323,12 +2375,8 @@ export class Dispatcher {
|
|
|
2323
2375
|
(state.pr &&
|
|
2324
2376
|
state.landing?.command &&
|
|
2325
2377
|
state.landing.command.seq !== state.landing.acknowledgedSeq)
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
previous &&
|
|
2329
|
-
Date.parse(previous.nextAttemptAt) > this.deps.clock().getTime()
|
|
2330
|
-
)
|
|
2331
|
-
return
|
|
2378
|
+
// Read the clock only inside an episode, as before episodes could escalate.
|
|
2379
|
+
if (!controlDue && previous && !janitorDue(previous, this.deps.clock())) return
|
|
2332
2380
|
if (mixedVersionDeferred(state)) {
|
|
2333
2381
|
await deferMixedVersion(this.store, record.slug)
|
|
2334
2382
|
return
|
|
@@ -2429,6 +2477,7 @@ export class Dispatcher {
|
|
|
2429
2477
|
state.pr &&
|
|
2430
2478
|
state.landing?.native?.operation
|
|
2431
2479
|
) {
|
|
2480
|
+
operation = 'native auto-merge cancellation'
|
|
2432
2481
|
const path = this.forgeWorkspacePathOf(workspace)
|
|
2433
2482
|
const observed = await this.deps.forge.getPrState(path, state.pr.number)
|
|
2434
2483
|
observedPr = observed
|
|
@@ -2466,6 +2515,7 @@ export class Dispatcher {
|
|
|
2466
2515
|
state.integration?.landing?.operation &&
|
|
2467
2516
|
!state.integration.audit
|
|
2468
2517
|
) {
|
|
2518
|
+
operation = 'integration landing audit'
|
|
2469
2519
|
await this.withKernelRepository((path) =>
|
|
2470
2520
|
auditIntegrationLanding({
|
|
2471
2521
|
store: this.store,
|
|
@@ -2479,6 +2529,7 @@ export class Dispatcher {
|
|
|
2479
2529
|
}
|
|
2480
2530
|
if (state.status === 'done') {
|
|
2481
2531
|
if (digest.reclaimPending === true) {
|
|
2532
|
+
operation = 'PR attachment reclaim'
|
|
2482
2533
|
await this.reclaimPrAttachments(record.slug, await history())
|
|
2483
2534
|
}
|
|
2484
2535
|
return
|
|
@@ -2488,6 +2539,7 @@ export class Dispatcher {
|
|
|
2488
2539
|
state.pendingCommands.find((c) => c.command === 'abort') ??
|
|
2489
2540
|
state.pendingCommands.at(0)
|
|
2490
2541
|
if (command !== undefined && !executionLeaseLive) {
|
|
2542
|
+
operation = 'control command'
|
|
2491
2543
|
await this.store.append(record.slug, {
|
|
2492
2544
|
actor: DISPATCHER,
|
|
2493
2545
|
type:
|
|
@@ -2498,16 +2550,19 @@ export class Dispatcher {
|
|
|
2498
2550
|
: 'build.resumed',
|
|
2499
2551
|
payload: {},
|
|
2500
2552
|
})
|
|
2501
|
-
if (command.command === 'abort')
|
|
2553
|
+
if (command.command === 'abort') {
|
|
2554
|
+
operation = 'abort cleanup'
|
|
2502
2555
|
await this.cleanupAborted(record, await history(), report)
|
|
2556
|
+
}
|
|
2503
2557
|
return
|
|
2504
2558
|
}
|
|
2505
2559
|
if (state.nodeOpened) {
|
|
2560
|
+
operation = 'target observation'
|
|
2506
2561
|
let primed = false
|
|
2507
2562
|
if (
|
|
2508
2563
|
record.branch &&
|
|
2509
2564
|
state.baseBranch &&
|
|
2510
|
-
!((state.status === 'paused' || state
|
|
2565
|
+
!((state.status === 'paused' || janitorBlocked(state)) && !state.pr)
|
|
2511
2566
|
) {
|
|
2512
2567
|
primed = await this.primeNodeReads(record, state, report)
|
|
2513
2568
|
}
|
|
@@ -2521,6 +2576,7 @@ export class Dispatcher {
|
|
|
2521
2576
|
)
|
|
2522
2577
|
).state !== 'open'
|
|
2523
2578
|
) {
|
|
2579
|
+
operation = 'PR check'
|
|
2524
2580
|
await this.checkPr(
|
|
2525
2581
|
record,
|
|
2526
2582
|
{
|
|
@@ -2546,8 +2602,9 @@ export class Dispatcher {
|
|
|
2546
2602
|
await this.primeNodeReads(record, state, report)
|
|
2547
2603
|
}
|
|
2548
2604
|
}
|
|
2549
|
-
if ((state.status === 'paused' || state
|
|
2605
|
+
if ((state.status === 'paused' || janitorBlocked(state)) && !state.pr) return
|
|
2550
2606
|
if (state.nodeOpened && state.baseBranch) {
|
|
2607
|
+
operation = 'target observation'
|
|
2551
2608
|
if (
|
|
2552
2609
|
await this.observeTarget(
|
|
2553
2610
|
record.slug,
|
|
@@ -2563,11 +2620,12 @@ export class Dispatcher {
|
|
|
2563
2620
|
if (
|
|
2564
2621
|
state.nodeOpened &&
|
|
2565
2622
|
state.status !== 'paused' &&
|
|
2566
|
-
(state
|
|
2623
|
+
(!janitorBlocked(state) || integrationFailed(state)) &&
|
|
2567
2624
|
state.prState !== 'merged' &&
|
|
2568
2625
|
state.prState !== 'closed' &&
|
|
2569
2626
|
!executionLeaseLive
|
|
2570
2627
|
) {
|
|
2628
|
+
operation = 'node cascade'
|
|
2571
2629
|
await this.prepareIntegration(record, state, report, launched, { refreshOnly: true })
|
|
2572
2630
|
;({ state, workspace, log } = await this.store.buildFacts(record.slug))
|
|
2573
2631
|
await this.cascadeNode(record, state, report, launched, opts)
|
|
@@ -2575,11 +2633,13 @@ export class Dispatcher {
|
|
|
2575
2633
|
;({ state, workspace, log } = await this.store.buildFacts(record.slug))
|
|
2576
2634
|
}
|
|
2577
2635
|
if (state.nodeOpened && !executionLeaseLive) {
|
|
2636
|
+
operation = 'node integration'
|
|
2578
2637
|
await this.prepareIntegration(record, state, report, launched)
|
|
2579
2638
|
loaded = undefined
|
|
2580
2639
|
;({ state, workspace, log } = await this.store.buildFacts(record.slug))
|
|
2581
2640
|
}
|
|
2582
2641
|
if (state.nodeOpened !== undefined && state.pr === undefined) {
|
|
2642
|
+
operation = 'empty node poll'
|
|
2583
2643
|
await this.pollEmptyNode(record, state)
|
|
2584
2644
|
await completeNodePoll()
|
|
2585
2645
|
return
|
|
@@ -2589,7 +2649,7 @@ export class Dispatcher {
|
|
|
2589
2649
|
// discard when both requests raced into the same stream.
|
|
2590
2650
|
if (
|
|
2591
2651
|
!executionLeaseLive &&
|
|
2592
|
-
state
|
|
2652
|
+
janitorStatus(state) === 'queued' &&
|
|
2593
2653
|
state.pendingCommands.some((command) => command.command === 'abort')
|
|
2594
2654
|
) {
|
|
2595
2655
|
const acknowledged = await this.store.append(record.slug, {
|
|
@@ -2600,6 +2660,7 @@ export class Dispatcher {
|
|
|
2600
2660
|
void acknowledged
|
|
2601
2661
|
// The view folded the acknowledgement it just appended.
|
|
2602
2662
|
loaded = undefined
|
|
2663
|
+
operation = 'abort cleanup'
|
|
2603
2664
|
await this.cleanupAborted(record, await history(), report)
|
|
2604
2665
|
return
|
|
2605
2666
|
}
|
|
@@ -2608,19 +2669,26 @@ export class Dispatcher {
|
|
|
2608
2669
|
// runner's workspace down or return its ticket for a duplicate build.
|
|
2609
2670
|
if (
|
|
2610
2671
|
!executionLeaseLive &&
|
|
2611
|
-
state
|
|
2672
|
+
janitorStatus(state) === 'queued' &&
|
|
2612
2673
|
state.discardRequest !== undefined
|
|
2613
2674
|
) {
|
|
2675
|
+
operation = 'discard cleanup'
|
|
2614
2676
|
await this.cleanupDiscarded(record, await history(), report)
|
|
2615
2677
|
return
|
|
2616
2678
|
}
|
|
2617
2679
|
if (!executionLeaseLive && state.status === 'aborted') {
|
|
2680
|
+
operation = 'abort cleanup'
|
|
2618
2681
|
await this.cleanupAborted(record, await history(), report)
|
|
2619
2682
|
return
|
|
2620
2683
|
}
|
|
2684
|
+
operation = 'target observation'
|
|
2621
2685
|
if (state.kind !== 'node' && state.status !== 'aborted')
|
|
2622
2686
|
await this.observeTicketTarget(record, state, report)
|
|
2623
|
-
if (
|
|
2687
|
+
if (
|
|
2688
|
+
state.kind !== 'node' &&
|
|
2689
|
+
state.status !== 'aborted' &&
|
|
2690
|
+
janitorStatus(state) !== 'queued'
|
|
2691
|
+
) {
|
|
2624
2692
|
const branch = await readBuildSelector(this.store, record.slug, 'baseBranch')
|
|
2625
2693
|
if (branch !== undefined) {
|
|
2626
2694
|
if (await this.observeTarget(record.slug, branch, log.restack.target?.sha, report)) {
|
|
@@ -2631,7 +2699,7 @@ export class Dispatcher {
|
|
|
2631
2699
|
}
|
|
2632
2700
|
if (
|
|
2633
2701
|
state.kind !== 'node' &&
|
|
2634
|
-
state
|
|
2702
|
+
janitorStatus(state) !== 'queued' &&
|
|
2635
2703
|
state.status !== 'aborted' &&
|
|
2636
2704
|
state.prState !== 'merged' &&
|
|
2637
2705
|
state.prState !== 'closed'
|
|
@@ -2656,6 +2724,7 @@ export class Dispatcher {
|
|
|
2656
2724
|
forge: this.deps.forge,
|
|
2657
2725
|
})
|
|
2658
2726
|
} catch (error) {
|
|
2727
|
+
rethrowAuthorityLapse(error)
|
|
2659
2728
|
if (janitorDeferral(error)) throw error
|
|
2660
2729
|
if (facts.log.restack.distance?.count != null)
|
|
2661
2730
|
report.janitorDiagnostics.push(
|
|
@@ -2687,6 +2756,7 @@ export class Dispatcher {
|
|
|
2687
2756
|
}
|
|
2688
2757
|
}
|
|
2689
2758
|
if (state.pr) {
|
|
2759
|
+
operation = 'PR check'
|
|
2690
2760
|
await this.checkPr(
|
|
2691
2761
|
record,
|
|
2692
2762
|
{
|
|
@@ -2705,6 +2775,11 @@ export class Dispatcher {
|
|
|
2705
2775
|
}
|
|
2706
2776
|
await completeNodePoll()
|
|
2707
2777
|
} catch (error) {
|
|
2778
|
+
// A lapsed repository lease is not this build's janitor failure.
|
|
2779
|
+
if (isRepositoryAuthorityLapse(error)) {
|
|
2780
|
+
attempted = false
|
|
2781
|
+
throw error
|
|
2782
|
+
}
|
|
2708
2783
|
// The guarded forge already recorded a classified rate limit as repository
|
|
2709
2784
|
// degradation; like the cooldown that follows it, it neither starts nor ages
|
|
2710
2785
|
// this build's janitor episode.
|
|
@@ -2726,6 +2801,7 @@ export class Dispatcher {
|
|
|
2726
2801
|
message,
|
|
2727
2802
|
this.deps.clock(),
|
|
2728
2803
|
this.deps.config.policy,
|
|
2804
|
+
operation,
|
|
2729
2805
|
)
|
|
2730
2806
|
report.janitorFailed += 1
|
|
2731
2807
|
report.janitorDiagnostics.push(`build ${record.slug}: janitor failed — ${message}`)
|
|
@@ -2757,6 +2833,7 @@ export class Dispatcher {
|
|
|
2757
2833
|
})
|
|
2758
2834
|
return true
|
|
2759
2835
|
} catch (error) {
|
|
2836
|
+
rethrowAuthorityLapse(error)
|
|
2760
2837
|
if (janitorDeferral(error)) throw error
|
|
2761
2838
|
report.janitorDiagnostics.push(
|
|
2762
2839
|
`build ${record.slug}: node read priming failed — ${error instanceof Error || isForgeFailure(error) ? error.message : String(error)}`,
|
|
@@ -2784,6 +2861,7 @@ export class Dispatcher {
|
|
|
2784
2861
|
if (state.kind === 'node') await this.observeNodeParent(record, state, report)
|
|
2785
2862
|
else await this.observeWorkTarget(record, state, report)
|
|
2786
2863
|
} catch (error) {
|
|
2864
|
+
rethrowAuthorityLapse(error)
|
|
2787
2865
|
report.janitorDiagnostics.push(
|
|
2788
2866
|
`build ${record.slug}: ticket target observation failed — ${error instanceof Error || isForgeFailure(error) ? error.message : String(error)}`,
|
|
2789
2867
|
)
|
|
@@ -2956,6 +3034,7 @@ export class Dispatcher {
|
|
|
2956
3034
|
)
|
|
2957
3035
|
throw new Error('destination generation changed; retry target update')
|
|
2958
3036
|
} catch (error) {
|
|
3037
|
+
rethrowAuthorityLapse(error)
|
|
2959
3038
|
if (request)
|
|
2960
3039
|
await this.store.append(record.slug, {
|
|
2961
3040
|
actor: DISPATCHER,
|
|
@@ -3023,6 +3102,7 @@ export class Dispatcher {
|
|
|
3023
3102
|
})) !== 'unchanged'
|
|
3024
3103
|
)
|
|
3025
3104
|
} catch (error) {
|
|
3105
|
+
rethrowAuthorityLapse(error)
|
|
3026
3106
|
const message =
|
|
3027
3107
|
error instanceof Error || isForgeFailure(error) ? error.message : String(error)
|
|
3028
3108
|
report.janitorDiagnostics.push(`build ${slug}: target observation failed — ${message}`)
|
|
@@ -3042,8 +3122,10 @@ export class Dispatcher {
|
|
|
3042
3122
|
return open?.localPath ?? open?.path ?? open?.ref ?? this.deps.checkout ?? this.deps.repo
|
|
3043
3123
|
}
|
|
3044
3124
|
|
|
3045
|
-
/** Deferral withholds decisions, but cannot free an existing capacity reservation.
|
|
3046
|
-
|
|
3125
|
+
/** Deferral withholds decisions, but cannot free an existing capacity reservation.
|
|
3126
|
+
* A leaf's runner reservation is this process's continuation or a launch
|
|
3127
|
+
* this tick; another process's continuation holds a heartbeat lease. */
|
|
3128
|
+
private async capacityBuilds(launched?: ReadonlySet<string>): Promise<CapacityBuild[]> {
|
|
3047
3129
|
const builds: CapacityBuild[] = []
|
|
3048
3130
|
for (const { record, digest } of await this.repoBuildDigests(true)) {
|
|
3049
3131
|
if (digest.terminal) continue
|
|
@@ -3053,13 +3135,41 @@ export class Dispatcher {
|
|
|
3053
3135
|
state: facts.state,
|
|
3054
3136
|
workspace: facts.workspace !== null,
|
|
3055
3137
|
provisioning:
|
|
3056
|
-
digest.kind === 'node'
|
|
3057
|
-
|
|
3138
|
+
digest.kind === 'node'
|
|
3139
|
+
? (await readBuildFacts(this.store, record.slug)).value.provisionMarker !== undefined
|
|
3140
|
+
: this.continuations.has(record.slug) || !!launched?.has(record.slug),
|
|
3141
|
+
restackDue: landingRestackDue(facts.state, facts.log),
|
|
3058
3142
|
})
|
|
3059
3143
|
}
|
|
3060
3144
|
return builds
|
|
3061
3145
|
}
|
|
3062
3146
|
|
|
3147
|
+
/** Whether a leaf may reserve a runner now. A leaf that has not finished its
|
|
3148
|
+
* pipeline already holds its slot, and abort and pause acknowledgements park
|
|
3149
|
+
* at once, so only a finished leaf that must run again is gated: it needs
|
|
3150
|
+
* a free slot among every other build. A denial is recorded only in memory,
|
|
3151
|
+
* for this tick's intake reservation. */
|
|
3152
|
+
private async leafAdmission(slug: string): Promise<boolean> {
|
|
3153
|
+
const { state } = await this.store.buildFacts(slug)
|
|
3154
|
+
if (
|
|
3155
|
+
!epilogueLeaf(state) ||
|
|
3156
|
+
state.pendingCommands.some(
|
|
3157
|
+
(command) => command.command === 'abort' || command.command === 'pause',
|
|
3158
|
+
)
|
|
3159
|
+
)
|
|
3160
|
+
return true
|
|
3161
|
+
const others = (await this.capacityBuilds(this.tickLaunched)).filter(
|
|
3162
|
+
(build) => build.record.slug !== slug,
|
|
3163
|
+
)
|
|
3164
|
+
const capacity = this.deps.config.capacity
|
|
3165
|
+
if (dispatchCapacity(others, capacity, this.deps.clock()).occupied < capacity) {
|
|
3166
|
+
this.slotWaiters.delete(slug)
|
|
3167
|
+
return true
|
|
3168
|
+
}
|
|
3169
|
+
this.slotWaiters.add(slug)
|
|
3170
|
+
return false
|
|
3171
|
+
}
|
|
3172
|
+
|
|
3063
3173
|
/** Admit every node awaiting verification that has a slot, in slug order,
|
|
3064
3174
|
* through the janitor's own admission path. Independent of `acceptNewWork`:
|
|
3065
3175
|
* node admission is existing work, never intake. */
|
|
@@ -3084,7 +3194,7 @@ export class Dispatcher {
|
|
|
3084
3194
|
launched.has(record.slug) ||
|
|
3085
3195
|
this.hasLiveExecutionLease(record) ||
|
|
3086
3196
|
!state.nodeOpened ||
|
|
3087
|
-
(state.janitor
|
|
3197
|
+
!janitorDue(state.janitor, now)
|
|
3088
3198
|
)
|
|
3089
3199
|
continue
|
|
3090
3200
|
await withForgeRequestContext({ build: record.slug }, async () => {
|
|
@@ -3092,6 +3202,7 @@ export class Dispatcher {
|
|
|
3092
3202
|
if (!(await this.nodeHasCapacity(record.slug))) return
|
|
3093
3203
|
await this.prepareIntegration(record, state, report, launched)
|
|
3094
3204
|
} catch (error) {
|
|
3205
|
+
rethrowAuthorityLapse(error)
|
|
3095
3206
|
report.janitorDiagnostics.push(
|
|
3096
3207
|
`build ${record.slug}: node admission failed — ${String(error)}`,
|
|
3097
3208
|
)
|
|
@@ -3209,6 +3320,7 @@ export class Dispatcher {
|
|
|
3209
3320
|
Object.assign(events, (await readBuildFacts(store, record.slug)).value)
|
|
3210
3321
|
}
|
|
3211
3322
|
const fail = (operation: string, identity: string, error: unknown): never => {
|
|
3323
|
+
rethrowAuthorityLapse(error)
|
|
3212
3324
|
if (error instanceof ForgeCooldown || isForgeFailure(error)) throw error
|
|
3213
3325
|
const detail = error instanceof Error || isForgeFailure(error) ? error.message : String(error)
|
|
3214
3326
|
throw new Error(
|
|
@@ -3413,6 +3525,7 @@ export class Dispatcher {
|
|
|
3413
3525
|
const message = await read.call(this.deps.forge, workspacePath, sha)
|
|
3414
3526
|
return { sha, buildTrailerPresent: hasBuildTrailer(message, record.slug) }
|
|
3415
3527
|
} catch (error) {
|
|
3528
|
+
rethrowAuthorityLapse(error)
|
|
3416
3529
|
await this.store.append(record.slug, {
|
|
3417
3530
|
actor: KERNEL,
|
|
3418
3531
|
type: 'observation.recorded',
|
|
@@ -3506,7 +3619,7 @@ export class Dispatcher {
|
|
|
3506
3619
|
candidate.status === 'paused' ||
|
|
3507
3620
|
candidate.status === 'done' ||
|
|
3508
3621
|
candidate.status === 'aborted' ||
|
|
3509
|
-
candidate.
|
|
3622
|
+
escalationsBeyondJanitor(candidate).length ||
|
|
3510
3623
|
candidate.pendingCommands.length
|
|
3511
3624
|
)
|
|
3512
3625
|
return false
|
|
@@ -3521,7 +3634,12 @@ export class Dispatcher {
|
|
|
3521
3634
|
)
|
|
3522
3635
|
}
|
|
3523
3636
|
const facts = await store.buildFacts(record.slug)
|
|
3524
|
-
const decision = await this.decideBuild(
|
|
3637
|
+
const decision = await this.decideBuild(
|
|
3638
|
+
record.slug,
|
|
3639
|
+
withoutJanitorEscalation(facts.state),
|
|
3640
|
+
facts.log,
|
|
3641
|
+
report,
|
|
3642
|
+
)
|
|
3525
3643
|
return decision?.kind === 'wait' && decision.reason === 'awaiting-pr'
|
|
3526
3644
|
}
|
|
3527
3645
|
const candidateOf = async (current: BuildState) =>
|
|
@@ -3664,6 +3782,19 @@ export class Dispatcher {
|
|
|
3664
3782
|
report.conflicted += 1
|
|
3665
3783
|
return
|
|
3666
3784
|
}
|
|
3785
|
+
// A finished build keeps its workspace while parked, even after its
|
|
3786
|
+
// environment was lost; the lease sweep reaps and replaces it once the
|
|
3787
|
+
// build is admitted, never a runner started in the lost environment.
|
|
3788
|
+
const retained = openWorkspace(events)
|
|
3789
|
+
if (
|
|
3790
|
+
retained !== null &&
|
|
3791
|
+
this.workspaceOwner(retained)?.recovery !== undefined &&
|
|
3792
|
+
(events.lastExecution === 'lost' || events.lastExecution === 'stopped') &&
|
|
3793
|
+
epilogueLeaf(events.state)
|
|
3794
|
+
) {
|
|
3795
|
+
report.conflicted += 1
|
|
3796
|
+
return
|
|
3797
|
+
}
|
|
3667
3798
|
// The dispatcher never runs agents (§15.7): re-attach a build-runner,
|
|
3668
3799
|
// which executes the reconcile epilogue phase.
|
|
3669
3800
|
await this.launch(record.slug, launched, report)
|
|
@@ -3692,7 +3823,7 @@ export class Dispatcher {
|
|
|
3692
3823
|
candidate.status === 'paused' ||
|
|
3693
3824
|
candidate.status === 'done' ||
|
|
3694
3825
|
candidate.status === 'aborted' ||
|
|
3695
|
-
candidate.
|
|
3826
|
+
escalationsBeyondJanitor(candidate).length ||
|
|
3696
3827
|
candidate.pendingCommands.length ||
|
|
3697
3828
|
!integrationVerified(
|
|
3698
3829
|
candidate,
|
|
@@ -3711,14 +3842,19 @@ export class Dispatcher {
|
|
|
3711
3842
|
current.status !== 'paused' &&
|
|
3712
3843
|
current.status !== 'aborted' &&
|
|
3713
3844
|
current.status !== 'done' &&
|
|
3714
|
-
!current.
|
|
3845
|
+
!escalationsBeyondJanitor(current).length &&
|
|
3715
3846
|
!current.pendingCommands.length &&
|
|
3716
3847
|
integrationVerified(current, config) &&
|
|
3717
3848
|
cycle?.head === exact.headSha &&
|
|
3718
3849
|
cycle.parent === exact.parentSha
|
|
3719
3850
|
)
|
|
3720
3851
|
}
|
|
3721
|
-
const decision = await this.decideBuild(
|
|
3852
|
+
const decision = await this.decideBuild(
|
|
3853
|
+
record.slug,
|
|
3854
|
+
withoutJanitorEscalation(latest.state),
|
|
3855
|
+
latest.log,
|
|
3856
|
+
report,
|
|
3857
|
+
)
|
|
3722
3858
|
return (
|
|
3723
3859
|
latest.state.pr?.number === pr.number &&
|
|
3724
3860
|
latest.state.prState === 'open' &&
|
|
@@ -4199,6 +4335,7 @@ export class Dispatcher {
|
|
|
4199
4335
|
payload: { hostedSeq: hosted.seq },
|
|
4200
4336
|
})
|
|
4201
4337
|
} catch (error) {
|
|
4338
|
+
rethrowAuthorityLapse(error)
|
|
4202
4339
|
if (error instanceof ForgeCooldown) throw error
|
|
4203
4340
|
try {
|
|
4204
4341
|
await this.store.append(slug, {
|
|
@@ -4236,6 +4373,11 @@ export class Dispatcher {
|
|
|
4236
4373
|
...input,
|
|
4237
4374
|
restoration,
|
|
4238
4375
|
...(facts.replacedHeads.length ? { restorationReplaced: facts.replacedHeads } : {}),
|
|
4376
|
+
// Same predicate preservation archives under: only local-git keeps
|
|
4377
|
+
// archive refs in the local repository.
|
|
4378
|
+
...(restoration?.length
|
|
4379
|
+
? { restorationArchives: this.deps.forge.name === 'local-git' ? 'local' : 'remote' }
|
|
4380
|
+
: {}),
|
|
4239
4381
|
})
|
|
4240
4382
|
const skipped = [
|
|
4241
4383
|
...superseded.map((sha) => ({ sha, reason: 'superseded' as const })),
|
|
@@ -4345,6 +4487,7 @@ export class Dispatcher {
|
|
|
4345
4487
|
reason,
|
|
4346
4488
|
)
|
|
4347
4489
|
} catch (error) {
|
|
4490
|
+
rethrowAuthorityLapse(error)
|
|
4348
4491
|
// Keep this generation and its pending work until forge recovery,
|
|
4349
4492
|
// while allowing the sweep to supervise the remaining builds.
|
|
4350
4493
|
if (error instanceof ForgeRequestDeferred) return false
|
|
@@ -4393,6 +4536,7 @@ export class Dispatcher {
|
|
|
4393
4536
|
Object.assign(events, (await readBuildFacts(this.store, slug)).value)
|
|
4394
4537
|
return true
|
|
4395
4538
|
} catch (error) {
|
|
4539
|
+
rethrowAuthorityLapse(error)
|
|
4396
4540
|
const message =
|
|
4397
4541
|
error instanceof Error || isForgeFailure(error) ? error.message : String(error)
|
|
4398
4542
|
const _failed = await this.store.append(slug, {
|
|
@@ -4477,6 +4621,7 @@ export class Dispatcher {
|
|
|
4477
4621
|
})
|
|
4478
4622
|
Object.assign(events, (await readBuildFacts(this.store, slug)).value)
|
|
4479
4623
|
} catch (error) {
|
|
4624
|
+
rethrowAuthorityLapse(error)
|
|
4480
4625
|
const message =
|
|
4481
4626
|
error instanceof Error || isForgeFailure(error) ? error.message : String(error)
|
|
4482
4627
|
const _failed = await this.store.append(slug, {
|
|
@@ -4710,6 +4855,7 @@ export class Dispatcher {
|
|
|
4710
4855
|
events = (await readBuildFacts(store, record.slug)).value
|
|
4711
4856
|
}
|
|
4712
4857
|
} catch (error) {
|
|
4858
|
+
rethrowAuthorityLapse(error)
|
|
4713
4859
|
if (await this.holdForMissingAccounts(error)) return 'parked'
|
|
4714
4860
|
if (error instanceof MixedVersionDeferral) return 'parked'
|
|
4715
4861
|
const events = (await readBuildFacts(store, record.slug)).value
|
|
@@ -4863,6 +5009,7 @@ export class Dispatcher {
|
|
|
4863
5009
|
if (authored && report !== undefined) report.authored += 1
|
|
4864
5010
|
return 'completed'
|
|
4865
5011
|
} catch (error) {
|
|
5012
|
+
rethrowAuthorityLapse(error)
|
|
4866
5013
|
if (await this.holdForMissingAccounts(error)) return 'parked'
|
|
4867
5014
|
const events = (await readBuildFacts(store, record.slug)).value
|
|
4868
5015
|
const attempt = events.dispatchFailureCount + 1
|
|
@@ -5022,6 +5169,7 @@ export class Dispatcher {
|
|
|
5022
5169
|
try {
|
|
5023
5170
|
await this.sweepBuild(record, report, launched, paused, now)
|
|
5024
5171
|
} catch (error) {
|
|
5172
|
+
rethrowAuthorityLapse(error)
|
|
5025
5173
|
// Per-build containment: one build's failure never stops the sweep
|
|
5026
5174
|
// from advancing the others. Workspace failures are already durable
|
|
5027
5175
|
// against the build; a repository-wide cooldown still ends the tick.
|
|
@@ -5088,6 +5236,18 @@ export class Dispatcher {
|
|
|
5088
5236
|
const decision = await this.decideBuild(record.slug, state, facts.log, report, true)
|
|
5089
5237
|
if (decision === undefined) return
|
|
5090
5238
|
if (state.status === 'done' || state.status === 'aborted') return
|
|
5239
|
+
if (decision.kind === 'wait' && decision.reason === 'awaiting-pr' && state.kind !== 'node') {
|
|
5240
|
+
this.parkedSettled.add(record.slug)
|
|
5241
|
+
// The engine reached the end of the pipeline: record it once per
|
|
5242
|
+
// settlement key so capacity stops counting the parked build. A lost
|
|
5243
|
+
// race is decided again next tick.
|
|
5244
|
+
if (settlementDue(state))
|
|
5245
|
+
await this.store.appendIfCurrent(record.slug, state.lastSeq, {
|
|
5246
|
+
actor: DISPATCHER,
|
|
5247
|
+
type: 'pipeline.settled',
|
|
5248
|
+
payload: { cycle: settlementKey(state) },
|
|
5249
|
+
})
|
|
5250
|
+
}
|
|
5091
5251
|
const orphanEligible = (state: BuildState) =>
|
|
5092
5252
|
!paused &&
|
|
5093
5253
|
state.status === 'running' &&
|
|
@@ -5181,6 +5341,18 @@ export class Dispatcher {
|
|
|
5181
5341
|
// is reaped and replaced by the next generation.
|
|
5182
5342
|
if (endedInPlace && open !== null && cleanupRequiredWorkspace(await history()))
|
|
5183
5343
|
endedInPlace = false
|
|
5344
|
+
const runs = decision.kind !== 'wait' || publicationRecoveryDue || orphanRecoveryDue
|
|
5345
|
+
// A finished leaf with work to run waits for a slot before anything is
|
|
5346
|
+
// reaped, provisioned or launched for it.
|
|
5347
|
+
if (runs && state.kind !== 'node' && !(await this.leafAdmission(record.slug))) return
|
|
5348
|
+
// A finished parked leaf keeps its workspace until merge or close; a
|
|
5349
|
+
// stale environment is reaped only for an admitted replacement.
|
|
5350
|
+
if (
|
|
5351
|
+
!runs &&
|
|
5352
|
+
state.kind !== 'node' &&
|
|
5353
|
+
((decision.kind === 'wait' && decision.reason === 'awaiting-pr') || epilogueLeaf(state))
|
|
5354
|
+
)
|
|
5355
|
+
return
|
|
5184
5356
|
// A provider- or log-proved END in the same generation re-attaches in
|
|
5185
5357
|
// place: the guest finished its work, the workspace is still the
|
|
5186
5358
|
// build's, and replacing the environment would discard a healthy
|
|
@@ -5234,6 +5406,7 @@ export class Dispatcher {
|
|
|
5234
5406
|
const result = await this.launch(record.slug, launched, report)
|
|
5235
5407
|
if (result === 'scheduled') report.swept += 1
|
|
5236
5408
|
} catch (error) {
|
|
5409
|
+
rethrowAuthorityLapse(error)
|
|
5237
5410
|
// Launchers normally record provider failures themselves. Preserve
|
|
5238
5411
|
// durable attention if orphan cleanup fails before that boundary,
|
|
5239
5412
|
// without counting an already-recorded failure twice.
|
|
@@ -5272,6 +5445,7 @@ export class Dispatcher {
|
|
|
5272
5445
|
try {
|
|
5273
5446
|
await this.recoverTicketPreparation(attempt)
|
|
5274
5447
|
} catch (error) {
|
|
5448
|
+
rethrowAuthorityLapse(error)
|
|
5275
5449
|
failures.push(error)
|
|
5276
5450
|
}
|
|
5277
5451
|
}
|
|
@@ -5294,6 +5468,7 @@ export class Dispatcher {
|
|
|
5294
5468
|
ticket: attempt.ticket,
|
|
5295
5469
|
outcome,
|
|
5296
5470
|
...(reason ? { reason: reason.slice(0, 4000) } : {}),
|
|
5471
|
+
...(outcome === 'abandoned' ? { claimed: attempt.claimed } : {}),
|
|
5297
5472
|
},
|
|
5298
5473
|
})
|
|
5299
5474
|
}
|
|
@@ -5369,6 +5544,7 @@ export class Dispatcher {
|
|
|
5369
5544
|
handback === attempt.readyState ? 'handed-back' : 'bounced',
|
|
5370
5545
|
)
|
|
5371
5546
|
} catch (error) {
|
|
5547
|
+
rethrowAuthorityLapse(error)
|
|
5372
5548
|
const message = error instanceof Error ? error.message : String(error)
|
|
5373
5549
|
try {
|
|
5374
5550
|
await this.store.appendRepo(this.deps.repo, {
|
|
@@ -5419,17 +5595,22 @@ export class Dispatcher {
|
|
|
5419
5595
|
report.ticketDiagnostics = []
|
|
5420
5596
|
report.dependencyDiagnostics = []
|
|
5421
5597
|
report.creationDiagnostics = []
|
|
5422
|
-
//
|
|
5423
|
-
//
|
|
5424
|
-
// (§16.1) — another repo's
|
|
5425
|
-
|
|
5426
|
-
|
|
5427
|
-
//
|
|
5598
|
+
// Capacity counts builds running work. An unfinished build holds its slot
|
|
5599
|
+
// even while blocked or paused; a finished build parked for its merge
|
|
5600
|
+
// decision holds none. Capacity is per repo (§16.1) — another repo's
|
|
5601
|
+
// builds never consume this repo's slots.
|
|
5602
|
+
const capacityBuilds = await this.capacityBuilds(launched)
|
|
5603
|
+
// A node awaiting verification, or a parked build that must run again,
|
|
5604
|
+
// reserves its slot ahead of new claims until it is admitted; this only
|
|
5605
|
+
// ever lowers the claim budget.
|
|
5428
5606
|
const projection = dispatchCapacity(capacityBuilds, config.capacity, this.deps.clock())
|
|
5429
5607
|
const activeRefs: TicketRef[] = capacityBuilds
|
|
5430
5608
|
.filter(({ state }) => state.status !== 'done' && state.status !== 'aborted')
|
|
5431
5609
|
.flatMap(({ record }) => (record.ticket ? [record.ticket] : []))
|
|
5432
|
-
let capacity = intakeCapacity(projection
|
|
5610
|
+
let capacity = intakeCapacity(projection, {
|
|
5611
|
+
settled: this.parkedSettled,
|
|
5612
|
+
denied: this.slotWaiters,
|
|
5613
|
+
})
|
|
5433
5614
|
|
|
5434
5615
|
// The ready scan runs even at full capacity: `queued` is the operator's
|
|
5435
5616
|
// standing queue-depth report and must stay honest exactly when the
|
|
@@ -5719,6 +5900,8 @@ export class Dispatcher {
|
|
|
5719
5900
|
claimed: false,
|
|
5720
5901
|
}
|
|
5721
5902
|
await store.ensureRepo(this.deps.repo)
|
|
5903
|
+
// A lapsed run leaves the ticket Ready for whoever holds the repository.
|
|
5904
|
+
if (this.deps.holdsRepoAuthority?.() === false) break
|
|
5722
5905
|
await store.appendRepo(this.deps.repo, {
|
|
5723
5906
|
actor: DISPATCHER,
|
|
5724
5907
|
type: 'ticket-preparation.intended',
|
|
@@ -5831,6 +6014,9 @@ export class Dispatcher {
|
|
|
5831
6014
|
established = true
|
|
5832
6015
|
await this.preparationResolved(attempt, 'owned')
|
|
5833
6016
|
} catch (error) {
|
|
6017
|
+
// A lapse is not a preparation failure: the successor recovers the
|
|
6018
|
+
// intended attempt through `recoverTicketPreparations`.
|
|
6019
|
+
rethrowAuthorityLapse(error)
|
|
5834
6020
|
// Settlement and completion errors after successful creation cannot
|
|
5835
6021
|
// release the claim. A later tick settles the retained creation identity.
|
|
5836
6022
|
if (established) throw error
|
|
@@ -6252,6 +6438,8 @@ export class Dispatcher {
|
|
|
6252
6438
|
beforeReplay,
|
|
6253
6439
|
canWrite: async () => {
|
|
6254
6440
|
if (await deferMixedVersion(this.store, record.slug)) return false
|
|
6441
|
+
// A lapse is not lost writer authority: it must escape unrecorded.
|
|
6442
|
+
if (this.deps.holdsRepoAuthority?.() === false) throw new RepositoryAuthorityLapsed()
|
|
6255
6443
|
if (this.outOfBudget(opts)) return false
|
|
6256
6444
|
if (state.pr && (await forge.getPrState(checkout, state.pr.number)).state !== 'open')
|
|
6257
6445
|
return false
|
|
@@ -6261,7 +6449,7 @@ export class Dispatcher {
|
|
|
6261
6449
|
current.status !== 'done' &&
|
|
6262
6450
|
current.status !== 'aborted' &&
|
|
6263
6451
|
current.status !== 'paused' &&
|
|
6264
|
-
(current
|
|
6452
|
+
(!janitorBlocked(current) || integrationFailed(current)) &&
|
|
6265
6453
|
current.prState !== 'merged' &&
|
|
6266
6454
|
current.prState !== 'closed' &&
|
|
6267
6455
|
current.pendingCommands.length === 0 &&
|
|
@@ -6345,6 +6533,7 @@ export class Dispatcher {
|
|
|
6345
6533
|
}
|
|
6346
6534
|
}
|
|
6347
6535
|
} catch (error) {
|
|
6536
|
+
rethrowAuthorityLapse(error)
|
|
6348
6537
|
if (await this.holdForMissingAccounts(error)) return
|
|
6349
6538
|
const message =
|
|
6350
6539
|
error instanceof Error || isForgeFailure(error) ? error.message : String(error)
|
|
@@ -6357,7 +6546,7 @@ export class Dispatcher {
|
|
|
6357
6546
|
) {
|
|
6358
6547
|
await this.store.refreshBuild(record.slug)
|
|
6359
6548
|
const current = (await this.store.buildFacts(record.slug)).state
|
|
6360
|
-
if (!current.
|
|
6549
|
+
if (!escalationsBeyondJanitor(current).length)
|
|
6361
6550
|
await this.store.append(record.slug, {
|
|
6362
6551
|
actor: KERNEL,
|
|
6363
6552
|
type: 'escalation.raised',
|
|
@@ -6386,7 +6575,8 @@ export class Dispatcher {
|
|
|
6386
6575
|
launched: Set<string>,
|
|
6387
6576
|
sampling: { refreshOnly?: boolean } = {},
|
|
6388
6577
|
): Promise<void> {
|
|
6389
|
-
|
|
6578
|
+
// The janitor's own escalation never skips the preparation that would recover it.
|
|
6579
|
+
if (!integrationAdmissible(withoutJanitorEscalation(state))) return
|
|
6390
6580
|
const forge = this.kernelForge()
|
|
6391
6581
|
if (!record.branch || !state.baseBranch || !forge.compareBranches) return
|
|
6392
6582
|
const comparison = await forge.compareBranches(state.baseBranch!, record.branch!)
|
|
@@ -6426,7 +6616,7 @@ export class Dispatcher {
|
|
|
6426
6616
|
state.nodeRestack?.active ||
|
|
6427
6617
|
state.integration?.intent ||
|
|
6428
6618
|
state.nodeRestack?.contributionBase !== comparison.parentSha ||
|
|
6429
|
-
state.
|
|
6619
|
+
escalationsBeyondJanitor(state).length ||
|
|
6430
6620
|
state.status === 'paused' ||
|
|
6431
6621
|
state.status === 'done' ||
|
|
6432
6622
|
state.status === 'aborted' ||
|