@defrex/autobuild 1.17.0 → 1.18.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 +41 -2
- package/docs/architecture.md +27 -2
- package/docs/configuration.md +11 -3
- package/docs/dispatcher-hosting.md +5 -3
- package/docs/operator-api.md +14 -1
- package/docs/plugin-authoring.md +29 -1
- package/docs/remote-ticket-protocol.md +34 -1
- package/docs/restacking.md +5 -0
- package/docs/setup.md +9 -3
- package/docs/ticket-sources.md +28 -1
- package/docs/troubleshooting.md +15 -0
- package/docs/workspaces.md +1 -1
- package/package.json +4 -4
- package/packages/core/src/cli/dashboard/refresh.ts +8 -0
- package/packages/core/src/config/schema.ts +2 -1
- package/packages/core/src/events/repository.ts +37 -1
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/d41044cb2e54809c.json +194 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/e0f89f52e48cbf62.json +197 -0
- package/packages/core/src/kernel/reducer-revisions.ts +5 -0
- package/packages/core/src/kernel/repository-read-facts.ts +9 -2
- package/packages/core/src/kernel/ticket-preparation.ts +10 -0
- package/packages/core/src/operator/registry.ts +64 -9
- package/packages/core/src/operator/tickets.ts +139 -25
- package/packages/core/src/plugin-sdk/index.ts +4 -0
- package/packages/core/src/plugins/manifest.ts +1 -1
- package/packages/core/src/ports/tickets/completion.ts +71 -0
- package/packages/core/src/ports/tickets/contract.ts +73 -0
- package/packages/core/src/ports/tickets/github-fake.ts +8 -0
- package/packages/core/src/ports/tickets/github-issues.ts +1 -0
- package/packages/core/src/ports/tickets/github.ts +18 -6
- package/packages/core/src/ports/tickets/hosted-index.ts +8 -0
- package/packages/core/src/ports/tickets/linear.ts +18 -2
- package/packages/core/src/ports/tickets/remote-protocol.ts +37 -8
- package/packages/core/src/ports/tickets/remote.ts +41 -3
- package/packages/core/src/ports/tickets/tree.ts +11 -1
- package/packages/core/src/ports/types.ts +32 -4
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +78 -25
- package/packages/core/src/processes/dispatcher.ts +852 -276
- package/packages/core/src/processes/pass-stages.ts +32 -6
- package/packages/core/src/store/reducer-value-shapes.json +8309 -8240
- package/packages/core/src/store/remote/released-clients.json +11 -0
- package/packages/core/src/store/remote/released-reducer-values/1.18.0.json +36436 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +18 -16
- package/packages/core/src/testing/dispatch-read-budget.ts +143 -16
- package/packages/core/src/testing/index.ts +2 -0
- package/packages/core/src/testing/reduced-read-budget.ts +198 -2
- package/skills/guide/SKILL.md +21 -5
- package/skills/guide/references/operator-api.md +14 -1
- package/skills/guide/references/plugin-authoring.md +29 -1
- package/skills/guide/references/remote-ticket-protocol.md +34 -1
- package/skills/guide/references/restacking.md +5 -0
- package/skills/guide/references/setup.md +9 -3
- package/skills/operate/SKILL.md +18 -1
- package/templates/hosted-service/package.json +2 -2
|
@@ -699,8 +699,15 @@ export interface TickReport {
|
|
|
699
699
|
* is recorded in `dispatcher.work-deferred` and the next tick runs it
|
|
700
700
|
* first. */
|
|
701
701
|
recoveryDeferred: number
|
|
702
|
+
/** Ticket preparations this bounded tick carried to the next invocation
|
|
703
|
+
* (#1431): an admission the work deadline left no time to prepare, or a
|
|
704
|
+
* preparation the deadline cut. Recorded in `dispatcher.work-deferred`;
|
|
705
|
+
* the next tick resumes each first, and none is handed back. Absent when
|
|
706
|
+
* none was carried. */
|
|
707
|
+
preparationsCarried?: number
|
|
702
708
|
/** One line per build whose deadline-gated work (a provision, a cut launch
|
|
703
|
-
* or a recovery step) this tick deferred for budget, naming the step
|
|
709
|
+
* or a recovery step) this tick deferred for budget, naming the step, and
|
|
710
|
+
* one per carried ticket preparation, naming the ticket. */
|
|
704
711
|
deferredDiagnostics: string[]
|
|
705
712
|
/** Dispatch (§12): builds created and launched. With durable supervision
|
|
706
713
|
* this counts ACCEPTED dispatches — durable boundaries recorded — not
|
|
@@ -845,6 +852,11 @@ const IDENTITY_RELEASES_PER_APPEND = 256
|
|
|
845
852
|
// ── Dispatcher ───────────────────────────────────────────────────────────────
|
|
846
853
|
|
|
847
854
|
const DEFAULT_SLUG_NAMING_TIMEOUT_MS = 10_000
|
|
855
|
+
/** What one ticket preparation (claim, asset pin, spec import, the slug
|
|
856
|
+
* naming ceiling and its store writes) needs, with headroom: a bounded pass
|
|
857
|
+
* with less time left before its work deadline carries the admission
|
|
858
|
+
* instead of starting it (#1431). */
|
|
859
|
+
const DEFAULT_PREPARATION_ESTIMATE_MS = 30_000
|
|
848
860
|
/** Bound on -2/-3/… candidates one claim may probe for a free slug. */
|
|
849
861
|
const MAX_SLUG_CANDIDATES = 100
|
|
850
862
|
/** Body of the comment dispatch posts on every claimed ticket. The
|
|
@@ -910,6 +922,10 @@ export interface DispatcherOpts {
|
|
|
910
922
|
/** Internal deadline for the optional pre-build naming seam. Production is
|
|
911
923
|
* fixed; injection exists only so timeout behavior is deterministic in tests. */
|
|
912
924
|
slugNamingTimeoutMs?: number
|
|
925
|
+
/** The time a bounded pass needs left before its work deadline to start a
|
|
926
|
+
* ticket preparation; with less, intake journals the admission and the
|
|
927
|
+
* next invocation prepares it first (#1431). Default 30 s. */
|
|
928
|
+
preparationEstimateMs?: number
|
|
913
929
|
/** Must match the HarvestRunner's durable outer recovery budget. */
|
|
914
930
|
maxHarvestRecoveryAttempts?: number
|
|
915
931
|
/** Backstop for the crash window between a `workspace.provision-started`
|
|
@@ -990,6 +1006,42 @@ interface DeferredWorkEntry {
|
|
|
990
1006
|
/** Most entries one `dispatcher.work-deferred` hint carries. */
|
|
991
1007
|
const MAX_DEFERRED_WORK = 64
|
|
992
1008
|
|
|
1009
|
+
/** One carried ticket-preparation attempt in `dispatcher.work-deferred`. */
|
|
1010
|
+
interface CarriedPreparation {
|
|
1011
|
+
ticket: TicketRef
|
|
1012
|
+
attempt: string
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
/** Most ticket-preparation attempts one hint carries. */
|
|
1016
|
+
const MAX_CARRIED_PREPARATIONS = 8
|
|
1017
|
+
|
|
1018
|
+
/** What one ticket preparation reached: a build `started`; the ticket `left`
|
|
1019
|
+
* the queue without a build (claim refused or bounced); it was `blocked` by
|
|
1020
|
+
* a blocker the claim found; the work deadline `carried` it to the next
|
|
1021
|
+
* invocation; or nothing durable was started and the loop must `stop`. */
|
|
1022
|
+
type PreparationOutcome = 'started' | 'left' | 'blocked' | 'carried' | 'stop'
|
|
1023
|
+
|
|
1024
|
+
/** One ticket preparation's inputs: the ticket sample it prepares from, its
|
|
1025
|
+
* attempt, the node target and claim level admission resolved, and how the
|
|
1026
|
+
* caller records outcomes. `resume` marks a carried attempt the deferred
|
|
1027
|
+
* stage or preparation recovery continues (#1431). */
|
|
1028
|
+
interface PreparationInput {
|
|
1029
|
+
ticket: Ticket
|
|
1030
|
+
attempt: TicketPreparation
|
|
1031
|
+
target:
|
|
1032
|
+
| { target: NonNullable<EventPayload<'build.created'>['target']>; branch: string }
|
|
1033
|
+
| undefined
|
|
1034
|
+
level: BuildPriority
|
|
1035
|
+
report: TickReport
|
|
1036
|
+
launched: Set<string>
|
|
1037
|
+
settle: (outcome: TargetedOutcome) => void
|
|
1038
|
+
/** The pass part a carry is recorded on. */
|
|
1039
|
+
part: PassStagePart
|
|
1040
|
+
resume?: true
|
|
1041
|
+
autoMergeUser?: string
|
|
1042
|
+
autoMergeSeedFact?: AutoMergeDefaultFact
|
|
1043
|
+
}
|
|
1044
|
+
|
|
993
1045
|
/** Process-local launch coordination result. Durable lease acquisition remains
|
|
994
1046
|
* the BuildRunner's responsibility; "scheduled" means only that this process
|
|
995
1047
|
* accepted a runner launch rather than suppressing a known in-flight slug. */
|
|
@@ -1147,6 +1199,14 @@ function errorText(error: unknown): string {
|
|
|
1147
1199
|
return error instanceof Error ? error.message : String(error)
|
|
1148
1200
|
}
|
|
1149
1201
|
|
|
1202
|
+
/** The report and dispatch-log line naming one carried ticket preparation. */
|
|
1203
|
+
function preparationCarryLine(ticket: TicketRef, detail?: string): string {
|
|
1204
|
+
return (
|
|
1205
|
+
`ticket ${ticket.id}: preparation carried by the invocation budget; the next invocation runs it first` +
|
|
1206
|
+
(detail !== undefined ? ` — ${detail}` : '')
|
|
1207
|
+
)
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1150
1210
|
/** The report and dispatch-log line naming one deferral by build and step. */
|
|
1151
1211
|
function deferralLine(slug: string, deferral: { step: DeferredWorkStep; detail?: string }): string {
|
|
1152
1212
|
return (
|
|
@@ -1406,6 +1466,7 @@ export class Dispatcher {
|
|
|
1406
1466
|
)
|
|
1407
1467
|
}
|
|
1408
1468
|
private readonly slugNamingTimeoutMs: number
|
|
1469
|
+
private readonly preparationEstimateMs: number
|
|
1409
1470
|
private readonly maxHarvestRecoveryAttempts: number
|
|
1410
1471
|
private readonly provisionStaleMs: number
|
|
1411
1472
|
/** Process-local background provisioning, keyed by slug. A tick that sees a
|
|
@@ -1438,6 +1499,23 @@ export class Dispatcher {
|
|
|
1438
1499
|
>()
|
|
1439
1500
|
/** The durable hint as last read or written. */
|
|
1440
1501
|
private recordedDeferrals: DeferredWorkEntry[] = []
|
|
1502
|
+
/** Per tick, keyed by attempt: ticket preparations this tick carried to
|
|
1503
|
+
* the next invocation (#1431), with the reason. */
|
|
1504
|
+
private readonly tickPreparationCarries = new Map<
|
|
1505
|
+
string,
|
|
1506
|
+
{ ticket: TicketRef; detail?: string }
|
|
1507
|
+
>()
|
|
1508
|
+
/** Per tick, in carried order: the hint's carried preparation attempts not
|
|
1509
|
+
* yet retired. */
|
|
1510
|
+
private readonly carriedPreparationsOutstanding = new Map<
|
|
1511
|
+
string,
|
|
1512
|
+
{ ticket: TicketRef; visited: boolean }
|
|
1513
|
+
>()
|
|
1514
|
+
/** Per tick: carried attempts the early stage resumed, which preparation
|
|
1515
|
+
* recovery then skips. */
|
|
1516
|
+
private readonly tickResumedAttempts = new Set<string>()
|
|
1517
|
+
/** The hint's preparation entries as last read or written. */
|
|
1518
|
+
private recordedPreparationCarries: CarriedPreparation[] = []
|
|
1441
1519
|
/** The current tick's options, for writes made from deferral sites. */
|
|
1442
1520
|
private tickOpts: TickOpts = {}
|
|
1443
1521
|
/** Serializes hint writes so concurrent deferral notes never race. */
|
|
@@ -1555,6 +1633,7 @@ export class Dispatcher {
|
|
|
1555
1633
|
})
|
|
1556
1634
|
this.leaseTtlMs = deps.opts?.leaseTtlMs ?? 0
|
|
1557
1635
|
this.slugNamingTimeoutMs = deps.opts?.slugNamingTimeoutMs ?? DEFAULT_SLUG_NAMING_TIMEOUT_MS
|
|
1636
|
+
this.preparationEstimateMs = deps.opts?.preparationEstimateMs ?? DEFAULT_PREPARATION_ESTIMATE_MS
|
|
1558
1637
|
this.maxHarvestRecoveryAttempts =
|
|
1559
1638
|
deps.opts?.maxHarvestRecoveryAttempts ?? DEFAULT_MAX_HARVEST_RECOVERY_ATTEMPTS
|
|
1560
1639
|
this.provisionStaleMs = deps.opts?.provisionStaleMs ?? DEFAULT_PROVISION_STALE_MS
|
|
@@ -1768,6 +1847,9 @@ export class Dispatcher {
|
|
|
1768
1847
|
this.deferralsFinished = false
|
|
1769
1848
|
this.tickPrioritized.clear()
|
|
1770
1849
|
this.carriedOutstanding.clear()
|
|
1850
|
+
this.tickPreparationCarries.clear()
|
|
1851
|
+
this.carriedPreparationsOutstanding.clear()
|
|
1852
|
+
this.tickResumedAttempts.clear()
|
|
1771
1853
|
this.deferralWriteFailure = undefined
|
|
1772
1854
|
this.tickOpts = opts
|
|
1773
1855
|
this.admissionBoundary = false
|
|
@@ -1779,13 +1861,19 @@ export class Dispatcher {
|
|
|
1779
1861
|
if (opts.viewRefreshed !== true) await this.store.refresh()
|
|
1780
1862
|
// The durable deferral hint from the previous invocation: zero extra
|
|
1781
1863
|
// reads, it is part of the repository facts the refresh reduced.
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
)
|
|
1864
|
+
const deferredWork = this.store.repositoryFacts().deferredWork
|
|
1865
|
+
this.recordedDeferrals = (deferredWork?.builds ?? []).map(({ slug, step, instance }) => ({
|
|
1866
|
+
slug,
|
|
1867
|
+
step,
|
|
1868
|
+
...(instance !== undefined ? { instance } : {}),
|
|
1869
|
+
}))
|
|
1870
|
+
this.recordedPreparationCarries = (deferredWork?.tickets ?? []).map(({ ticket, attempt }) => ({
|
|
1871
|
+
ticket,
|
|
1872
|
+
attempt,
|
|
1873
|
+
}))
|
|
1874
|
+
for (const { ticket, attempt } of this.recordedPreparationCarries)
|
|
1875
|
+
if (!this.carriedPreparationsOutstanding.has(attempt))
|
|
1876
|
+
this.carriedPreparationsOutstanding.set(attempt, { ticket, visited: false })
|
|
1789
1877
|
// The rotated loops' positions, from the same reduced facts: no read.
|
|
1790
1878
|
this.passCursors =
|
|
1791
1879
|
opts.deadlineAt === undefined
|
|
@@ -1859,7 +1947,7 @@ export class Dispatcher {
|
|
|
1859
1947
|
if (opts.observationOnly) return report
|
|
1860
1948
|
if (this.outOfBudget(opts)) return report
|
|
1861
1949
|
await this.runStage('preparations', opts, (stageOpts) =>
|
|
1862
|
-
this.recoverTicketPreparations(report, stageOpts),
|
|
1950
|
+
this.recoverTicketPreparations(report, launched, paused, stageOpts),
|
|
1863
1951
|
)
|
|
1864
1952
|
if (this.outOfBudget(opts)) return report
|
|
1865
1953
|
await this.runStage('janitor', opts, (stageOpts) => this.janitor(report, launched, stageOpts))
|
|
@@ -2036,11 +2124,16 @@ export class Dispatcher {
|
|
|
2036
2124
|
const report = structuredClone(this.inFlightReport)
|
|
2037
2125
|
// The deferrals so far, counted as the finished tick would count them;
|
|
2038
2126
|
// a finished tick already counted them on its report.
|
|
2039
|
-
if (!this.deferralsFinished)
|
|
2127
|
+
if (!this.deferralsFinished) {
|
|
2040
2128
|
for (const [slug, deferral] of this.tickDeferrals) {
|
|
2041
2129
|
if (deferral.step !== 'provision') report.recoveryDeferred += 1
|
|
2042
2130
|
report.deferredDiagnostics.push(deferralLine(slug, deferral))
|
|
2043
2131
|
}
|
|
2132
|
+
if (this.tickPreparationCarries.size > 0)
|
|
2133
|
+
report.preparationsCarried = this.tickPreparationCarries.size
|
|
2134
|
+
for (const { ticket, detail } of this.tickPreparationCarries.values())
|
|
2135
|
+
report.deferredDiagnostics.push(preparationCarryLine(ticket, detail))
|
|
2136
|
+
}
|
|
2044
2137
|
return { ...report, stages: this.pass.summary() }
|
|
2045
2138
|
}
|
|
2046
2139
|
|
|
@@ -2479,7 +2572,7 @@ export class Dispatcher {
|
|
|
2479
2572
|
// checked, needs the pass.
|
|
2480
2573
|
const now = this.deps.clock()
|
|
2481
2574
|
const measured = await this.capacityBuilds(launched, true)
|
|
2482
|
-
const projection =
|
|
2575
|
+
const projection = this.measureCapacity(measured, config.capacity, now, {
|
|
2483
2576
|
claims: this.claims(),
|
|
2484
2577
|
startRequests: this.startClaims(),
|
|
2485
2578
|
})
|
|
@@ -4944,8 +5037,8 @@ export class Dispatcher {
|
|
|
4944
5037
|
let outcome = this.slotAdmission(
|
|
4945
5038
|
slug,
|
|
4946
5039
|
priority,
|
|
4947
|
-
|
|
4948
|
-
|
|
5040
|
+
this.measureCapacity(others, capacity, now).occupied,
|
|
5041
|
+
this.measureCapacity(builds, capacity, now, {
|
|
4949
5042
|
claims: this.claims(),
|
|
4950
5043
|
startRequests: this.startClaims(),
|
|
4951
5044
|
}),
|
|
@@ -5217,7 +5310,7 @@ export class Dispatcher {
|
|
|
5217
5310
|
(only === undefined || build.record.slug === only),
|
|
5218
5311
|
)
|
|
5219
5312
|
if (proposers.length === 0) return
|
|
5220
|
-
const projection =
|
|
5313
|
+
const projection = this.measureCapacity(builds, this.deps.config.capacity, now, {
|
|
5221
5314
|
claims: this.claims(),
|
|
5222
5315
|
startRequests: this.startClaims(),
|
|
5223
5316
|
})
|
|
@@ -5647,12 +5740,12 @@ export class Dispatcher {
|
|
|
5647
5740
|
const outcome = this.slotAdmission(
|
|
5648
5741
|
slug,
|
|
5649
5742
|
buildPriority(node.state),
|
|
5650
|
-
|
|
5743
|
+
this.measureCapacity(
|
|
5651
5744
|
builds.filter((build) => build.record.slug !== slug),
|
|
5652
5745
|
capacity,
|
|
5653
5746
|
now,
|
|
5654
5747
|
).occupied,
|
|
5655
|
-
|
|
5748
|
+
this.measureCapacity(builds, capacity, now, {
|
|
5656
5749
|
claims: this.claims(),
|
|
5657
5750
|
startRequests: this.startClaims(),
|
|
5658
5751
|
}),
|
|
@@ -9104,13 +9197,54 @@ export class Dispatcher {
|
|
|
9104
9197
|
paused: boolean,
|
|
9105
9198
|
opts: TickOpts,
|
|
9106
9199
|
): Promise<void> {
|
|
9107
|
-
|
|
9200
|
+
const carriedPreparations = this.carriedPreparationsOutstanding.size
|
|
9201
|
+
if (this.carriedOutstanding.size === 0 && carriedPreparations === 0)
|
|
9202
|
+
return this.pass.total('deferred', 0)
|
|
9203
|
+
this.pass.total('deferred', this.carriedOutstanding.size + carriedPreparations)
|
|
9204
|
+
if (this.carriedOutstanding.size > 0)
|
|
9205
|
+
await this.serviceDeferredBuilds(report, launched, paused, opts)
|
|
9206
|
+
// Carried ticket preparations (#1431), after the carried builds: each
|
|
9207
|
+
// attempt resumes from its durable boundaries, with no fleet read.
|
|
9208
|
+
for (const attempt of [...this.carriedPreparationsOutstanding.keys()]) {
|
|
9209
|
+
if (!this.passItem(opts, 'deferred')) break
|
|
9210
|
+
const entry = this.carriedPreparationsOutstanding.get(attempt)!
|
|
9211
|
+
const held = this.store.repositoryFacts().preparation[attempt]
|
|
9212
|
+
if (held === undefined) {
|
|
9213
|
+
this.carriedPreparationsOutstanding.delete(attempt)
|
|
9214
|
+
continue
|
|
9215
|
+
}
|
|
9216
|
+
entry.visited = true
|
|
9217
|
+
this.tickResumedAttempts.add(attempt)
|
|
9218
|
+
let outcome: 'done' | 'waiting' | 'failed'
|
|
9219
|
+
try {
|
|
9220
|
+
outcome = await this.resumeCarriedPreparation(held, report, launched, paused, 'deferred')
|
|
9221
|
+
} catch (error) {
|
|
9222
|
+
rethrowAuthorityLapse(error)
|
|
9223
|
+
// Contained like a recovery failure; the attempt's stamp resumes it
|
|
9224
|
+
// in a later pass.
|
|
9225
|
+
report.janitorFailed += 1
|
|
9226
|
+
report.janitorDiagnostics.push(String(error))
|
|
9227
|
+
outcome = 'failed'
|
|
9228
|
+
}
|
|
9229
|
+
const interrupted = this.budgetSpent(this.tickOpts)
|
|
9230
|
+
if (outcome !== 'waiting' && !interrupted && !this.tickPreparationCarries.has(attempt))
|
|
9231
|
+
this.carriedPreparationsOutstanding.delete(attempt)
|
|
9232
|
+
}
|
|
9233
|
+
await this.persistDeferrals()
|
|
9234
|
+
}
|
|
9235
|
+
|
|
9236
|
+
/** The carried builds of `serviceDeferredWork`. */
|
|
9237
|
+
private async serviceDeferredBuilds(
|
|
9238
|
+
report: TickReport,
|
|
9239
|
+
launched: Set<string>,
|
|
9240
|
+
paused: boolean,
|
|
9241
|
+
opts: TickOpts,
|
|
9242
|
+
): Promise<void> {
|
|
9108
9243
|
// Never the default form: it would run the mixed-version check for every
|
|
9109
9244
|
// compatibility-bearing build. `sweepBuild` checks each carried build.
|
|
9110
9245
|
const entries = new Map(
|
|
9111
9246
|
(await this.repoBuildDigests(true)).map((entry) => [entry.record.slug, entry]),
|
|
9112
9247
|
)
|
|
9113
|
-
this.pass.total('deferred', this.carriedOutstanding.size)
|
|
9114
9248
|
for (const slug of [...this.carriedOutstanding.keys()]) {
|
|
9115
9249
|
if (!this.passItem(opts, 'deferred')) break
|
|
9116
9250
|
const entry = this.carriedOutstanding.get(slug)!
|
|
@@ -9132,7 +9266,6 @@ export class Dispatcher {
|
|
|
9132
9266
|
if (outcome !== 'waiting' && !interrupted && !this.tickDeferrals.has(slug))
|
|
9133
9267
|
this.retireCarried(slug)
|
|
9134
9268
|
}
|
|
9135
|
-
await this.persistDeferrals()
|
|
9136
9269
|
}
|
|
9137
9270
|
|
|
9138
9271
|
/**
|
|
@@ -9347,9 +9480,59 @@ export class Dispatcher {
|
|
|
9347
9480
|
this.reportedDeferrals.add(slug)
|
|
9348
9481
|
lines.push(deferralLine(slug, deferral))
|
|
9349
9482
|
}
|
|
9483
|
+
lines.push(...this.unreportedPreparationCarries())
|
|
9484
|
+
return lines
|
|
9485
|
+
}
|
|
9486
|
+
|
|
9487
|
+
/** This tick's carried preparations not yet named in a report or teardown
|
|
9488
|
+
* line, each marked reported. */
|
|
9489
|
+
private unreportedPreparationCarries(): string[] {
|
|
9490
|
+
const lines: string[] = []
|
|
9491
|
+
for (const [attempt, { ticket, detail }] of this.tickPreparationCarries) {
|
|
9492
|
+
const key = `prep:${attempt}`
|
|
9493
|
+
if (this.reportedDeferrals.has(key)) continue
|
|
9494
|
+
this.reportedDeferrals.add(key)
|
|
9495
|
+
lines.push(preparationCarryLine(ticket, detail))
|
|
9496
|
+
}
|
|
9350
9497
|
return lines
|
|
9351
9498
|
}
|
|
9352
9499
|
|
|
9500
|
+
/** Record that this tick carried `attempt`'s ticket preparation to the
|
|
9501
|
+
* next invocation (#1431), and keep the durable hint current. The first
|
|
9502
|
+
* reason noted wins. */
|
|
9503
|
+
private async notePreparationCarry(
|
|
9504
|
+
attempt: string,
|
|
9505
|
+
ticket: TicketRef,
|
|
9506
|
+
detail?: string,
|
|
9507
|
+
): Promise<void> {
|
|
9508
|
+
if (!this.tickPreparationCarries.has(attempt))
|
|
9509
|
+
this.tickPreparationCarries.set(attempt, {
|
|
9510
|
+
ticket,
|
|
9511
|
+
...(detail !== undefined ? { detail } : {}),
|
|
9512
|
+
})
|
|
9513
|
+
await this.persistDeferrals()
|
|
9514
|
+
}
|
|
9515
|
+
|
|
9516
|
+
/** The hint's preparation entries this tick would write, ordered as
|
|
9517
|
+
* `nextDeferralList` orders builds and capped from the tail. A dropped
|
|
9518
|
+
* entry is still resumed: its attempt carries the work-deadline stamp
|
|
9519
|
+
* preparation recovery resumes from. */
|
|
9520
|
+
private nextPreparationCarryList(): CarriedPreparation[] {
|
|
9521
|
+
const list: CarriedPreparation[] = []
|
|
9522
|
+
const seen = new Set<string>()
|
|
9523
|
+
const push = (attempt: string, ticket: TicketRef) => {
|
|
9524
|
+
if (seen.has(attempt)) return
|
|
9525
|
+
seen.add(attempt)
|
|
9526
|
+
list.push({ ticket, attempt })
|
|
9527
|
+
}
|
|
9528
|
+
for (const [attempt, entry] of this.carriedPreparationsOutstanding)
|
|
9529
|
+
if (!entry.visited) push(attempt, entry.ticket)
|
|
9530
|
+
for (const [attempt, entry] of this.carriedPreparationsOutstanding)
|
|
9531
|
+
if (entry.visited) push(attempt, entry.ticket)
|
|
9532
|
+
for (const [attempt, { ticket }] of this.tickPreparationCarries) push(attempt, ticket)
|
|
9533
|
+
return list.slice(0, MAX_CARRIED_PREPARATIONS)
|
|
9534
|
+
}
|
|
9535
|
+
|
|
9353
9536
|
/** A carried hint entry whose own pass showed it no longer needs priority.
|
|
9354
9537
|
* Never writes: the next hint write simply omits it. */
|
|
9355
9538
|
private retireCarried(slug: string): void {
|
|
@@ -9408,6 +9591,8 @@ export class Dispatcher {
|
|
|
9408
9591
|
const write = this.deferralWrites.then(async () => {
|
|
9409
9592
|
const next = this.nextDeferralList()
|
|
9410
9593
|
const recorded = this.recordedDeferrals
|
|
9594
|
+
const tickets = this.nextPreparationCarryList()
|
|
9595
|
+
const recordedTickets = this.recordedPreparationCarries
|
|
9411
9596
|
if (
|
|
9412
9597
|
next.length === recorded.length &&
|
|
9413
9598
|
next.every(
|
|
@@ -9415,6 +9600,13 @@ export class Dispatcher {
|
|
|
9415
9600
|
entry.slug === recorded[i]!.slug &&
|
|
9416
9601
|
entry.step === recorded[i]!.step &&
|
|
9417
9602
|
entry.instance === recorded[i]!.instance,
|
|
9603
|
+
) &&
|
|
9604
|
+
tickets.length === recordedTickets.length &&
|
|
9605
|
+
tickets.every(
|
|
9606
|
+
(entry, i) =>
|
|
9607
|
+
entry.attempt === recordedTickets[i]!.attempt &&
|
|
9608
|
+
entry.ticket.source === recordedTickets[i]!.ticket.source &&
|
|
9609
|
+
entry.ticket.id === recordedTickets[i]!.ticket.id,
|
|
9418
9610
|
)
|
|
9419
9611
|
)
|
|
9420
9612
|
return
|
|
@@ -9422,11 +9614,14 @@ export class Dispatcher {
|
|
|
9422
9614
|
this.store.appendRepo(this.deps.repo, {
|
|
9423
9615
|
actor: DISPATCHER,
|
|
9424
9616
|
type: 'dispatcher.work-deferred',
|
|
9425
|
-
|
|
9617
|
+
// A hint without carried preparations keeps its earlier payload.
|
|
9618
|
+
payload: { builds: next, ...(tickets.length > 0 ? { tickets } : {}) },
|
|
9426
9619
|
}),
|
|
9427
9620
|
)
|
|
9428
|
-
if (outcome === true)
|
|
9429
|
-
|
|
9621
|
+
if (outcome === true) {
|
|
9622
|
+
this.recordedDeferrals = next
|
|
9623
|
+
this.recordedPreparationCarries = tickets
|
|
9624
|
+
} else if (outcome !== false) this.deferralWriteFailure = outcome
|
|
9430
9625
|
})
|
|
9431
9626
|
this.deferralWrites = write.catch(() => {})
|
|
9432
9627
|
return write
|
|
@@ -9492,6 +9687,9 @@ export class Dispatcher {
|
|
|
9492
9687
|
this.reportedDeferrals.add(slug)
|
|
9493
9688
|
report.deferredDiagnostics.push(deferralLine(slug, deferral))
|
|
9494
9689
|
}
|
|
9690
|
+
if (this.tickPreparationCarries.size > 0)
|
|
9691
|
+
report.preparationsCarried = this.tickPreparationCarries.size
|
|
9692
|
+
report.deferredDiagnostics.push(...this.unreportedPreparationCarries())
|
|
9495
9693
|
if (this.deferralWriteFailure !== undefined)
|
|
9496
9694
|
report.deferredDiagnostics.push(
|
|
9497
9695
|
`deferred work not recorded for the next invocation — ${this.deferralWriteFailure}`,
|
|
@@ -9842,10 +10040,24 @@ export class Dispatcher {
|
|
|
9842
10040
|
|
|
9843
10041
|
/** Retry a fixed batch under the same repository ownership as intake.
|
|
9844
10042
|
* No provider calls for parked deadlines; no history or orphan scans. */
|
|
9845
|
-
private async recoverTicketPreparations(
|
|
9846
|
-
|
|
10043
|
+
private async recoverTicketPreparations(
|
|
10044
|
+
report: TickReport,
|
|
10045
|
+
launched: Set<string>,
|
|
10046
|
+
paused: boolean,
|
|
10047
|
+
opts: TickOpts,
|
|
10048
|
+
): Promise<void> {
|
|
10049
|
+
const attempts = Object.values(this.store.repositoryFacts().preparation)
|
|
10050
|
+
// Read the clock only when an attempt needs scheduling.
|
|
10051
|
+
const now = attempts.length ? this.deps.clock().getTime() : 0
|
|
10052
|
+
const pending = attempts
|
|
9847
10053
|
.filter(
|
|
9848
|
-
(attempt) =>
|
|
10054
|
+
(attempt) =>
|
|
10055
|
+
// The early stage resumed it this tick.
|
|
10056
|
+
!this.tickResumedAttempts.has(attempt.attempt) &&
|
|
10057
|
+
// A deadline stamp not yet passed belongs to an invocation still
|
|
10058
|
+
// running (or a skewed clock): a later pass decides it.
|
|
10059
|
+
!(this.interruptedByDeadline(attempt) && Date.parse(attempt.workDeadlineAt!) > now) &&
|
|
10060
|
+
(!attempt.retryAt || Date.parse(attempt.retryAt) <= now),
|
|
9849
10061
|
)
|
|
9850
10062
|
.sort(
|
|
9851
10063
|
(a, b) =>
|
|
@@ -9859,7 +10071,12 @@ export class Dispatcher {
|
|
|
9859
10071
|
for (const attempt of pending) {
|
|
9860
10072
|
if (!this.passItem(opts, 'preparations')) break
|
|
9861
10073
|
try {
|
|
9862
|
-
|
|
10074
|
+
// A preparation its invocation's work deadline interrupted resumes,
|
|
10075
|
+
// even when its carry hint was lost (#1431); everything else
|
|
10076
|
+
// recovers as before.
|
|
10077
|
+
if (this.interruptedByDeadline(attempt))
|
|
10078
|
+
await this.resumeCarriedPreparation(attempt, report, launched, paused, 'preparations')
|
|
10079
|
+
else await this.recoverTicketPreparation(attempt)
|
|
9863
10080
|
} catch (error) {
|
|
9864
10081
|
rethrowAuthorityLapse(error)
|
|
9865
10082
|
failures.push(error)
|
|
@@ -9947,39 +10164,251 @@ export class Dispatcher {
|
|
|
9947
10164
|
}
|
|
9948
10165
|
}
|
|
9949
10166
|
|
|
9950
|
-
|
|
9951
|
-
|
|
9952
|
-
|
|
9953
|
-
|
|
9954
|
-
|
|
9955
|
-
|
|
9956
|
-
|
|
9957
|
-
|
|
9958
|
-
|
|
9959
|
-
|
|
9960
|
-
|
|
10167
|
+
/** Whether an attempt's selected creation committed: the one build it
|
|
10168
|
+
* owns, `absent` when no build answers it (or it selected no slug), or
|
|
10169
|
+
* `abandoned` once an ambiguous, conflicting or unprovable outcome was
|
|
10170
|
+
* durably abandoned. */
|
|
10171
|
+
private async creationReadback(
|
|
10172
|
+
attempt: TicketPreparation,
|
|
10173
|
+
): Promise<{ owned: BuildRecord } | 'absent' | 'abandoned'> {
|
|
10174
|
+
// A rejected create can have committed. Unavailable or conflicting readback
|
|
10175
|
+
// is never absence and must not authorize a ticket transition. A keyed
|
|
10176
|
+
// attempt's build is at its proposed slug (exact-slug store) or the slug
|
|
10177
|
+
// its own key derives (allocating store): at most two point reads, and
|
|
10178
|
+
// never another attempt's build.
|
|
10179
|
+
if (!attempt.slug) return 'absent'
|
|
10180
|
+
const found = await this.creationCandidates(attempt, attempt.slug)
|
|
10181
|
+
if (found.length > 1) {
|
|
10182
|
+
await this.abandonPreparation(
|
|
10183
|
+
attempt,
|
|
10184
|
+
`Ambiguous creation identity: builds at ${found.map((record) => record.slug).join(' and ')} both answer this attempt; ticket unchanged. Inspect ownership before manually retrying. Original failure: ${attempt.error ?? 'unknown'}`,
|
|
10185
|
+
)
|
|
10186
|
+
return 'abandoned'
|
|
10187
|
+
}
|
|
10188
|
+
const [record] = found
|
|
10189
|
+
if (record) {
|
|
10190
|
+
if (!(await this.preparationOwns(attempt, record))) {
|
|
10191
|
+
await this.abandonPreparation(
|
|
10192
|
+
attempt,
|
|
10193
|
+
`Conflicting build ownership at ${record.slug}; ticket unchanged. Inspect ownership before manually retrying. Original failure: ${attempt.error ?? 'unknown'}`,
|
|
10194
|
+
)
|
|
10195
|
+
return 'abandoned'
|
|
10196
|
+
}
|
|
10197
|
+
return { owned: record }
|
|
10198
|
+
}
|
|
10199
|
+
// Absence is evidence only where the creation slug is known: an
|
|
10200
|
+
// allocating store may have committed an unkeyed create under a slug
|
|
10201
|
+
// no point read can find, and enumerating builds is never a fallback.
|
|
10202
|
+
if (!attempt.creationKey && (await this.store.buildCreationIdentity?.()) !== undefined) {
|
|
10203
|
+
await this.abandonPreparation(
|
|
10204
|
+
attempt,
|
|
10205
|
+
`Creation outcome unknown: the build store allocates canonical slugs and this attempt recorded no creation key, so a build created under an unrecorded slug cannot be ruled out; ticket unchanged. Inspect the repository's builds for ticket ${attempt.ticket.id} before manually retrying. Original failure: ${attempt.error ?? 'unknown'}`,
|
|
10206
|
+
)
|
|
10207
|
+
return 'abandoned'
|
|
10208
|
+
}
|
|
10209
|
+
return 'absent'
|
|
10210
|
+
}
|
|
10211
|
+
|
|
10212
|
+
/** `dispatchCapacity` with every outstanding admitted preparation holding
|
|
10213
|
+
* its slot (#1431). A carried attempt was admitted when its `intended` was
|
|
10214
|
+
* written and finishes without re-measuring capacity, so until it resolves
|
|
10215
|
+
* no later admission (intake, start requests, parked or node slot
|
|
10216
|
+
* admission) may spend its slot, however many passes its resume takes.
|
|
10217
|
+
* In memory over the tick's repository facts: no read. */
|
|
10218
|
+
private measureCapacity(
|
|
10219
|
+
...args: Parameters<typeof dispatchCapacity>
|
|
10220
|
+
): ReturnType<typeof dispatchCapacity> {
|
|
10221
|
+
const capacity = dispatchCapacity(...args)
|
|
10222
|
+
const reserved = this.reservedPreparations()
|
|
10223
|
+
return reserved === 0 ? capacity : { ...capacity, occupied: capacity.occupied + reserved }
|
|
10224
|
+
}
|
|
10225
|
+
|
|
10226
|
+
/** Unresolved ticket preparations a bounded pass admitted and its work
|
|
10227
|
+
* deadline interrupted (or deferred), each holding one slot until it
|
|
10228
|
+
* resolves. A node ticket's attempt reserves too, at most until its next
|
|
10229
|
+
* resume: the attempt does not record the ticket's kind. */
|
|
10230
|
+
private reservedPreparations(): number {
|
|
10231
|
+
let reserved = 0
|
|
10232
|
+
for (const attempt of Object.values(this.store.repositoryFacts().preparation))
|
|
10233
|
+
if (this.interruptedByDeadline(attempt)) reserved++
|
|
10234
|
+
return reserved
|
|
10235
|
+
}
|
|
10236
|
+
|
|
10237
|
+
/** Whether the work deadline of the invocation that wrote this attempt
|
|
10238
|
+
* interrupted it (#1431): stamped by a bounded pass, that deadline passed,
|
|
10239
|
+
* and no failure or bounce was recorded. Such an attempt resumes; it is
|
|
10240
|
+
* never handed back. */
|
|
10241
|
+
private interruptedByDeadline(attempt: TicketPreparation): boolean {
|
|
10242
|
+
return (
|
|
10243
|
+
attempt.workDeadlineAt !== undefined &&
|
|
10244
|
+
attempt.stage === undefined &&
|
|
10245
|
+
attempt.handback === undefined
|
|
10246
|
+
)
|
|
10247
|
+
}
|
|
10248
|
+
|
|
10249
|
+
/**
|
|
10250
|
+
* Continue one carried ticket preparation (#1431) from its last durable
|
|
10251
|
+
* boundary: the claim, the claim confirmation, or the creation readback.
|
|
10252
|
+
* Admission was decided when its `intended` was written, so nothing here
|
|
10253
|
+
* re-measures capacity. Never hands a ticket back for the interruption;
|
|
10254
|
+
* a resumed preparation that fails for real takes the ordinary failure
|
|
10255
|
+
* path, and one the deadline cuts again is carried again under the same
|
|
10256
|
+
* attempt. Reads: one `tickets.get`, plus the existing creation readback
|
|
10257
|
+
* when a slug was selected and a target node's facts for a node child.
|
|
10258
|
+
*/
|
|
10259
|
+
private async resumeCarriedPreparation(
|
|
10260
|
+
held: TicketPreparation,
|
|
10261
|
+
report: TickReport,
|
|
10262
|
+
launched: Set<string>,
|
|
10263
|
+
paused: boolean,
|
|
10264
|
+
part: PassStagePart,
|
|
10265
|
+
): Promise<'done' | 'waiting' | 'failed'> {
|
|
10266
|
+
// Nothing claims while the repository is paused; the entry waits.
|
|
10267
|
+
if (paused) return 'waiting'
|
|
10268
|
+
const attempt: TicketPreparation = structuredClone(held)
|
|
10269
|
+
// A selected bounce is a real outcome: finish it.
|
|
10270
|
+
if (attempt.handback !== undefined) {
|
|
10271
|
+
await this.recoverTicketPreparation(attempt)
|
|
10272
|
+
return 'done'
|
|
10273
|
+
}
|
|
10274
|
+
const readback = await this.creationReadback(attempt)
|
|
10275
|
+
if (readback === 'abandoned') return 'done'
|
|
10276
|
+
if (readback !== 'absent') {
|
|
10277
|
+
await this.preparationResolved(attempt, 'owned')
|
|
10278
|
+
return this.serviceCarriedStart(
|
|
10279
|
+
readback.owned,
|
|
10280
|
+
{ step: 'provision' },
|
|
10281
|
+
report,
|
|
10282
|
+
launched,
|
|
10283
|
+
paused,
|
|
10284
|
+
)
|
|
10285
|
+
}
|
|
10286
|
+
const ref = resolveTicketRef(
|
|
10287
|
+
this.store.repositoryFacts().ticketMigrations,
|
|
10288
|
+
attempt.ticket,
|
|
10289
|
+
this.deps.tickets.name,
|
|
10290
|
+
attempt.slug ?? attempt.attempt,
|
|
10291
|
+
)
|
|
10292
|
+
const ticket = await this.deps.tickets.get(ref.id)
|
|
10293
|
+
if (!ticket) {
|
|
10294
|
+
await this.abandonPreparation(attempt, 'Ticket no longer exists; ticket unchanged.')
|
|
10295
|
+
return 'done'
|
|
10296
|
+
}
|
|
10297
|
+
if (ticket.state === undefined) {
|
|
10298
|
+
await this.abandonPreparation(
|
|
10299
|
+
attempt,
|
|
10300
|
+
'Ticket state is unavailable; ticket unchanged. Inspect the provider record before manually retrying.',
|
|
10301
|
+
)
|
|
10302
|
+
return 'done'
|
|
10303
|
+
}
|
|
10304
|
+
const is = (state: string) => ticket.state!.toLowerCase() === state.toLowerCase()
|
|
10305
|
+
if (!attempt.claimed) {
|
|
10306
|
+
if (is(attempt.readyState)) {
|
|
10307
|
+
// Still Ready: no claim applied. A ticket that no longer qualifies
|
|
10308
|
+
// is released with no tracker write, and intake re-evaluates it.
|
|
10309
|
+
if (!this.tickAcceptsNewWork) {
|
|
10310
|
+
await this.preparationResolved(
|
|
9961
10311
|
attempt,
|
|
9962
|
-
|
|
10312
|
+
'lost-claim',
|
|
10313
|
+
'intake turned off before its carried claim',
|
|
9963
10314
|
)
|
|
9964
|
-
|
|
9965
|
-
if (record) {
|
|
9966
|
-
if (!(await this.preparationOwns(attempt, record)))
|
|
9967
|
-
return await this.abandonPreparation(
|
|
9968
|
-
attempt,
|
|
9969
|
-
`Conflicting build ownership at ${record.slug}; ticket unchanged. Inspect ownership before manually retrying. Original failure: ${attempt.error ?? 'unknown'}`,
|
|
9970
|
-
)
|
|
9971
|
-
await this.preparationResolved(attempt, 'owned')
|
|
9972
|
-
return
|
|
10315
|
+
return 'done'
|
|
9973
10316
|
}
|
|
9974
|
-
|
|
9975
|
-
|
|
9976
|
-
// no point read can find, and enumerating builds is never a fallback.
|
|
9977
|
-
if (!attempt.creationKey && (await this.store.buildCreationIdentity?.()) !== undefined)
|
|
9978
|
-
return await this.abandonPreparation(
|
|
10317
|
+
if (ticket.blockersResolved === false) {
|
|
10318
|
+
await this.preparationResolved(
|
|
9979
10319
|
attempt,
|
|
9980
|
-
|
|
10320
|
+
'lost-claim',
|
|
10321
|
+
'unresolved blockers before its carried claim',
|
|
9981
10322
|
)
|
|
10323
|
+
return 'done'
|
|
10324
|
+
}
|
|
10325
|
+
} else if (attempt.claimDeferred) {
|
|
10326
|
+
// No claim call was ever made: the ticket is not ours.
|
|
10327
|
+
await this.preparationResolved(
|
|
10328
|
+
attempt,
|
|
10329
|
+
'lost-claim',
|
|
10330
|
+
`ticket left ${attempt.readyState} (${ticket.state}) before its carried claim`,
|
|
10331
|
+
)
|
|
10332
|
+
return 'done'
|
|
10333
|
+
} else if (is(attempt.claimedState)) {
|
|
10334
|
+
// The claim applied but its confirmation was cut.
|
|
10335
|
+
await this.store.appendRepo(this.deps.repo, {
|
|
10336
|
+
actor: DISPATCHER,
|
|
10337
|
+
type: 'ticket-preparation.claimed',
|
|
10338
|
+
payload: { attempt: attempt.attempt, ticket: attempt.ticket },
|
|
10339
|
+
})
|
|
10340
|
+
attempt.claimed = true
|
|
10341
|
+
} else {
|
|
10342
|
+
await this.abandonPreparation(
|
|
10343
|
+
attempt,
|
|
10344
|
+
`Claim outcome uncertain: the claim request did not confirm and the provider may have applied it; ticket observed in state ${ticket.state}; ticket unchanged. Inspect ownership before manually retrying. Original failure: ${attempt.error ?? 'unknown'}`,
|
|
10345
|
+
)
|
|
10346
|
+
return 'done'
|
|
10347
|
+
}
|
|
10348
|
+
} else if (!is(attempt.claimedState)) {
|
|
10349
|
+
await this.abandonPreparation(
|
|
10350
|
+
attempt,
|
|
10351
|
+
`Confirmed claim but ticket externally changed to state ${ticket.state}; ticket unchanged. Inspect ownership before manually retrying. Original failure: ${attempt.error ?? 'unknown'}`,
|
|
10352
|
+
)
|
|
10353
|
+
return 'done'
|
|
10354
|
+
}
|
|
10355
|
+
const target = await this.resolveNodeTarget(ticket, {
|
|
10356
|
+
listed: new Set(),
|
|
10357
|
+
foreign: new Map(),
|
|
10358
|
+
generation: ++this.foreignScanGeneration,
|
|
10359
|
+
})
|
|
10360
|
+
if (typeof target === 'string') {
|
|
10361
|
+
if (!attempt.claimed) {
|
|
10362
|
+
await this.preparationResolved(attempt, 'lost-claim', target)
|
|
10363
|
+
return 'done'
|
|
9982
10364
|
}
|
|
10365
|
+
return this.failPreparation(attempt, 'target', new Error(target))
|
|
10366
|
+
}
|
|
10367
|
+
if (!attempt.claimed && attempt.claimDeferred) {
|
|
10368
|
+
// The claim-started boundary: from here on the claim may have applied,
|
|
10369
|
+
// so recovery confirms it from the ticket's state rather than
|
|
10370
|
+
// releasing the ticket. Nothing has reached the tracker yet.
|
|
10371
|
+
try {
|
|
10372
|
+
await this.appendIntended(attempt)
|
|
10373
|
+
} catch (error) {
|
|
10374
|
+
rethrowAuthorityLapse(error)
|
|
10375
|
+
if (!this.budgetSpent(this.tickOpts)) throw error
|
|
10376
|
+
await this.notePreparationCarry(
|
|
10377
|
+
attempt.attempt,
|
|
10378
|
+
attempt.ticket,
|
|
10379
|
+
'the work deadline cut its preparation (claim)',
|
|
10380
|
+
).catch(() => {})
|
|
10381
|
+
this.pass.carry(part, attempt.ticket.id)
|
|
10382
|
+
return 'waiting'
|
|
10383
|
+
}
|
|
10384
|
+
}
|
|
10385
|
+
// The level admission decided (a start request's own level included),
|
|
10386
|
+
// recorded with the attempt. An attempt without one is re-derived as
|
|
10387
|
+
// intake derives an ordinary claim's: an optimization attempt's node
|
|
10388
|
+
// priority, else the ticket's.
|
|
10389
|
+
const level =
|
|
10390
|
+
attempt.level ??
|
|
10391
|
+
(await this.attemptClaimTiers([ticket])).get(ticket.ref.id) ??
|
|
10392
|
+
(this.deps.tickets.priority ? ticketPriority(ticket) : 'normal')
|
|
10393
|
+
const outcome = await this.prepareTicket({
|
|
10394
|
+
ticket,
|
|
10395
|
+
attempt,
|
|
10396
|
+
target,
|
|
10397
|
+
level,
|
|
10398
|
+
report,
|
|
10399
|
+
launched,
|
|
10400
|
+
settle: () => {},
|
|
10401
|
+
part,
|
|
10402
|
+
resume: true,
|
|
10403
|
+
})
|
|
10404
|
+
return outcome === 'started' || outcome === 'left' || outcome === 'blocked' ? 'done' : 'waiting'
|
|
10405
|
+
}
|
|
10406
|
+
|
|
10407
|
+
private async recoverTicketPreparation(attempt: TicketPreparation): Promise<void> {
|
|
10408
|
+
try {
|
|
10409
|
+
const readback = await this.creationReadback(attempt)
|
|
10410
|
+
if (readback === 'abandoned') return
|
|
10411
|
+
if (readback !== 'absent') return await this.preparationResolved(attempt, 'owned')
|
|
9983
10412
|
// A committed `ticket.handed-back` whose acknowledgement or resolution
|
|
9984
10413
|
// was lost means the hand-back already happened, and a watcher may have
|
|
9985
10414
|
// moved the ticket since. Resolve without touching the ticket.
|
|
@@ -10102,7 +10531,7 @@ export class Dispatcher {
|
|
|
10102
10531
|
if (!targeted && this.deferredAdmissions.size > 0) {
|
|
10103
10532
|
deferralBuilds = await this.capacityBuilds(launched)
|
|
10104
10533
|
const key = this.deferralKey(
|
|
10105
|
-
|
|
10534
|
+
this.measureCapacity(deferralBuilds, config.capacity, this.deps.clock()).occupied,
|
|
10106
10535
|
)
|
|
10107
10536
|
if (key !== this.lastForcedDeferralKey) {
|
|
10108
10537
|
force = true
|
|
@@ -10147,7 +10576,7 @@ export class Dispatcher {
|
|
|
10147
10576
|
// tell a reserved request from one filed since.
|
|
10148
10577
|
const pendingStarts = this.store.repositoryFacts().ticketStarts.pending
|
|
10149
10578
|
const startDemand = this.startClaims()
|
|
10150
|
-
const projection =
|
|
10579
|
+
const projection = this.measureCapacity(capacityBuilds, config.capacity, this.deps.clock(), {
|
|
10151
10580
|
openPrs: { policy: config.policy, engaged },
|
|
10152
10581
|
startRequests: startDemand,
|
|
10153
10582
|
})
|
|
@@ -10649,23 +11078,94 @@ export class Dispatcher {
|
|
|
10649
11078
|
}
|
|
10650
11079
|
// Cancellation and a priority change are checked again before claiming.
|
|
10651
11080
|
if (targeted && !(await this.startStillPending(targeted, ticket))) continue
|
|
10652
|
-
|
|
10653
|
-
|
|
10654
|
-
|
|
10655
|
-
|
|
10656
|
-
|
|
10657
|
-
|
|
10658
|
-
|
|
10659
|
-
|
|
10660
|
-
|
|
11081
|
+
// A bounded pass does not start a preparation it cannot finish before
|
|
11082
|
+
// its work deadline (#1431). Intake's admission is journaled and the
|
|
11083
|
+
// next invocation prepares it first; a start request's own pending
|
|
11084
|
+
// request is already its carry. Time only shrinks: stop claiming.
|
|
11085
|
+
if (this.preparationWontFit()) {
|
|
11086
|
+
claimLoopCompleted = false
|
|
11087
|
+
attempt.level = this.claimedLevel(ticket, startTier(ticket), tierOf)
|
|
11088
|
+
if (!targeted && (await this.deferPreparation(attempt, part ?? 'tickets'))) {
|
|
11089
|
+
report.queued -= 1
|
|
11090
|
+
if (ticket.kind !== 'node') for (const entry of TICKET_PRIORITIES) budgets[entry] -= 1
|
|
11091
|
+
}
|
|
11092
|
+
break
|
|
11093
|
+
}
|
|
11094
|
+
const outcome = await this.prepareTicket({
|
|
11095
|
+
ticket,
|
|
11096
|
+
attempt,
|
|
11097
|
+
target,
|
|
11098
|
+
level: this.claimedLevel(ticket, startTier(ticket), tierOf),
|
|
11099
|
+
report,
|
|
11100
|
+
launched,
|
|
11101
|
+
settle: (outcome) => settle(ticket, outcome),
|
|
11102
|
+
part: part ?? 'starts',
|
|
11103
|
+
...(autoMergeUser !== undefined ? { autoMergeUser } : {}),
|
|
11104
|
+
...(autoMergeSeedFact !== undefined ? { autoMergeSeedFact } : {}),
|
|
10661
11105
|
})
|
|
10662
|
-
|
|
10663
|
-
|
|
10664
|
-
|
|
10665
|
-
|
|
10666
|
-
|
|
10667
|
-
|
|
11106
|
+
if (outcome === 'blocked') continue
|
|
11107
|
+
if (outcome === 'stop') {
|
|
11108
|
+
claimLoopCompleted = false
|
|
11109
|
+
break
|
|
11110
|
+
}
|
|
11111
|
+
report.queued -= 1
|
|
11112
|
+
if (outcome === 'left') continue
|
|
11113
|
+
// A carried admission holds its slot until the next invocation
|
|
11114
|
+
// prepares it.
|
|
11115
|
+
if (ticket.kind !== 'node' && targeted) targeted.budgets[startTier(ticket)] -= 1
|
|
11116
|
+
else if (ticket.kind !== 'node') for (const entry of TICKET_PRIORITIES) budgets[entry] -= 1
|
|
11117
|
+
if (outcome === 'carried') {
|
|
11118
|
+
claimLoopCompleted = false
|
|
11119
|
+
break
|
|
11120
|
+
}
|
|
11121
|
+
}
|
|
11122
|
+
if (checkpoint !== undefined && scanSuccessful && !this.outOfBudget(opts)) {
|
|
11123
|
+
await this.completeScan(checkpoint, report, waiting)
|
|
11124
|
+
// The only other place this tick authorizes deferred admissions.
|
|
11125
|
+
if (claimLoopCompleted) this.claimsEvaluated = true
|
|
11126
|
+
}
|
|
11127
|
+
}
|
|
11128
|
+
|
|
11129
|
+
/**
|
|
11130
|
+
* One ticket preparation (SPEC §6.3), from the `intended` append through
|
|
11131
|
+
* the first dispatch: claim → `.claimed` → asset pin → spec → naming →
|
|
11132
|
+
* `.creation-selected` → `createBuild` → `.resolved owned` → first
|
|
11133
|
+
* dispatch. With `resume`, a carried attempt (#1431) continues from its
|
|
11134
|
+
* claim when unclaimed, or from its asset pin when claimed, appending no
|
|
11135
|
+
* `intended`. Tracked as a start in flight, so bounded teardown awaits a
|
|
11136
|
+
* preparation the work deadline cut. A preparation the deadline cuts
|
|
11137
|
+
* before `build.created` is carried to the next invocation: nothing is
|
|
11138
|
+
* marked failed, nothing is handed back and the tracker is not touched.
|
|
11139
|
+
* Every other failure keeps its failure record and recovery.
|
|
11140
|
+
*/
|
|
11141
|
+
private prepareTicket(input: PreparationInput): Promise<PreparationOutcome> {
|
|
11142
|
+
return this.trackStart(this.runPreparation(input))
|
|
11143
|
+
}
|
|
11144
|
+
|
|
11145
|
+
private async runPreparation(input: PreparationInput): Promise<PreparationOutcome> {
|
|
11146
|
+
const { ticket, attempt, target, level, report, launched, settle, resume } = input
|
|
11147
|
+
const { autoMergeUser, autoMergeSeedFact } = input
|
|
11148
|
+
const store = this.store
|
|
11149
|
+
const { tickets } = this.deps
|
|
11150
|
+
if (!resume) {
|
|
11151
|
+
attempt.level = level
|
|
10668
11152
|
try {
|
|
11153
|
+
await this.appendIntended(attempt)
|
|
11154
|
+
} catch (error) {
|
|
11155
|
+
rethrowAuthorityLapse(error)
|
|
11156
|
+
// Nothing durable began: the next scan admits the ticket again.
|
|
11157
|
+
if (this.budgetSpent(this.tickOpts)) return 'stop'
|
|
11158
|
+
throw error
|
|
11159
|
+
}
|
|
11160
|
+
}
|
|
11161
|
+
let stage = attempt.claimed ? 'assets' : 'claim'
|
|
11162
|
+
let established = false
|
|
11163
|
+
let record: BuildRecord
|
|
11164
|
+
let body = ticket.body
|
|
11165
|
+
let authoredSession: string | undefined
|
|
11166
|
+
let createdSeed: Parameters<Dispatcher['buildCreatedPayload']>[2]
|
|
11167
|
+
try {
|
|
11168
|
+
if (!attempt.claimed) {
|
|
10669
11169
|
let claimed: boolean
|
|
10670
11170
|
try {
|
|
10671
11171
|
claimed = await tickets.claim(ticket.ref.id, { blockedBy: ticket.blockedBy ?? [] })
|
|
@@ -10677,18 +11177,17 @@ export class Dispatcher {
|
|
|
10677
11177
|
await this.preparationResolved(attempt, 'lost-claim', error.message)
|
|
10678
11178
|
report.dependencyBlocked += 1
|
|
10679
11179
|
report.dependencyDiagnostics.push(detail)
|
|
10680
|
-
settle(
|
|
10681
|
-
|
|
11180
|
+
settle({ outcome: 'blocked', detail })
|
|
11181
|
+
return 'blocked'
|
|
10682
11182
|
}
|
|
10683
11183
|
if (!claimed) {
|
|
10684
11184
|
await this.preparationResolved(attempt, 'lost-claim')
|
|
10685
|
-
settle(
|
|
11185
|
+
settle({
|
|
10686
11186
|
outcome: 'claim-refused',
|
|
10687
11187
|
detail: `the ${tickets.name} ticket source refused the claim of ${ticket.ref.id}`,
|
|
10688
11188
|
})
|
|
10689
11189
|
report.claimRaces += 1
|
|
10690
|
-
|
|
10691
|
-
continue
|
|
11190
|
+
return 'left'
|
|
10692
11191
|
}
|
|
10693
11192
|
attempt.claimed = true
|
|
10694
11193
|
stage = 'claim-confirmation'
|
|
@@ -10697,220 +11196,297 @@ export class Dispatcher {
|
|
|
10697
11196
|
type: 'ticket-preparation.claimed',
|
|
10698
11197
|
payload: { attempt: attempt.attempt, ticket: attempt.ticket },
|
|
10699
11198
|
})
|
|
10700
|
-
|
|
10701
|
-
|
|
10702
|
-
|
|
10703
|
-
|
|
10704
|
-
|
|
10705
|
-
|
|
10706
|
-
|
|
10707
|
-
|
|
10708
|
-
|
|
10709
|
-
|
|
10710
|
-
|
|
10711
|
-
|
|
10712
|
-
|
|
10713
|
-
|
|
10714
|
-
|
|
10715
|
-
|
|
10716
|
-
|
|
10717
|
-
|
|
10718
|
-
|
|
10719
|
-
|
|
10720
|
-
|
|
10721
|
-
|
|
10722
|
-
|
|
10723
|
-
|
|
10724
|
-
|
|
10725
|
-
|
|
10726
|
-
|
|
10727
|
-
|
|
10728
|
-
|
|
10729
|
-
|
|
11199
|
+
}
|
|
11200
|
+
stage = 'assets'
|
|
11201
|
+
// Freeze the ticket's assets at the claim (SPEC §6.3): sampled before the
|
|
11202
|
+
// spec-authoring interval so edits made during it are never pinned.
|
|
11203
|
+
const assets = await preparePinnedAssets(tickets, store, this.deps.repo, ticket.ref.id)
|
|
11204
|
+
|
|
11205
|
+
// Quality gate (§6.3): import a conforming ticket body as the spec;
|
|
11206
|
+
// author one for thin-but-groomed tickets; otherwise bounce.
|
|
11207
|
+
stage = 'spec'
|
|
11208
|
+
// An objective refusal bounces before any authoring: an authored spec
|
|
11209
|
+
// could strip the block and open a plain node instead (SPEC §13.1).
|
|
11210
|
+
const refusals = objectiveRefusals(body, {
|
|
11211
|
+
kind: ticket.kind ?? 'work',
|
|
11212
|
+
rejectedState: this.rejectedState(),
|
|
11213
|
+
})
|
|
11214
|
+
let conformance =
|
|
11215
|
+
refusals.length > 0 ? { conforms: false, missing: refusals } : specConformance(body)
|
|
11216
|
+
if (
|
|
11217
|
+
!conformance.conforms &&
|
|
11218
|
+
refusals.length === 0 &&
|
|
11219
|
+
objectiveBlocks(body).length === 0 &&
|
|
11220
|
+
this.deps.authorSpec
|
|
11221
|
+
) {
|
|
11222
|
+
const authored = await this.deps.authorSpec(ticket)
|
|
11223
|
+
// An authored spec never gains the marker the ticket did not carry.
|
|
11224
|
+
if (authored !== null && objectiveBlocks(authored).length === 0) {
|
|
11225
|
+
conformance = specConformance(authored)
|
|
11226
|
+
if (conformance.conforms) {
|
|
11227
|
+
body = authored
|
|
11228
|
+
authoredSession = this.deps.ids('s')
|
|
10730
11229
|
}
|
|
10731
11230
|
}
|
|
10732
|
-
|
|
10733
|
-
|
|
10734
|
-
|
|
10735
|
-
|
|
10736
|
-
|
|
10737
|
-
actor: DISPATCHER,
|
|
10738
|
-
type: 'ticket-preparation.handback-selected',
|
|
10739
|
-
payload: {
|
|
10740
|
-
attempt: attempt.attempt,
|
|
10741
|
-
ticket: attempt.ticket,
|
|
10742
|
-
state: attempt.handback,
|
|
10743
|
-
...(missing ? { missing } : {}),
|
|
10744
|
-
},
|
|
10745
|
-
})
|
|
10746
|
-
stage = 'bounce'
|
|
10747
|
-
await this.bounce(ticket, conformance.missing, refusals.length > 0)
|
|
10748
|
-
stage = 'handback-report'
|
|
10749
|
-
await this.reportPreparationHandback(attempt, {
|
|
10750
|
-
ticket: ticket.ref,
|
|
10751
|
-
attempt: attempt.attempt,
|
|
10752
|
-
cause: 'spec-bounce',
|
|
10753
|
-
state: attempt.handback,
|
|
10754
|
-
role: 'triage',
|
|
10755
|
-
...(missing ? { missing } : {}),
|
|
10756
|
-
})
|
|
10757
|
-
await this.preparationResolved(attempt, 'bounced')
|
|
10758
|
-
settle(ticket, {
|
|
10759
|
-
outcome: 'invalid',
|
|
10760
|
-
detail: `bounced to ${attempt.handback}${
|
|
10761
|
-
conformance.missing.length > 0 ? `; missing: ${conformance.missing.join('; ')}` : ''
|
|
10762
|
-
}`,
|
|
10763
|
-
})
|
|
10764
|
-
report.bounced += 1
|
|
10765
|
-
report.queued -= 1
|
|
10766
|
-
continue
|
|
10767
|
-
}
|
|
10768
|
-
|
|
10769
|
-
stage = 'naming'
|
|
10770
|
-
const baseSlug = await this.chooseSlugBase(ticket.title, body)
|
|
10771
|
-
const prefix = ticket.kind === 'node' ? 'ab-node' : 'ab'
|
|
10772
|
-
const slug = await this.uniqueSlug(baseSlug, prefix)
|
|
10773
|
-
const branch = `${prefix}/${slug}`
|
|
10774
|
-
const repoOrigin = await this.resolveRepoOriginOnce()
|
|
10775
|
-
// Recorded only on the store's attestation, so recovery never treats
|
|
10776
|
-
// an unkeyed creation's absence at the derived slug as evidence.
|
|
10777
|
-
const creationKey =
|
|
10778
|
-
(await store.buildCreationIdentity?.()) === 'keyed' ? attempt.attempt : undefined
|
|
10779
|
-
createdSeed = {
|
|
10780
|
-
...(ticket.kind === 'node' ? { kind: ticket.kind } : {}),
|
|
10781
|
-
...(target !== undefined ? { target: target.target, baseBranch: target.branch } : {}),
|
|
10782
|
-
...(autoMergeUser !== undefined ? { autoMergeUser } : {}),
|
|
10783
|
-
// Claim-time provenance: the newest durable default fact that agrees
|
|
10784
|
-
// with the launch sample, recorded on `build.created` so the fan-out's
|
|
10785
|
-
// seq comparison sees the claim as already answering that fact — and
|
|
10786
|
-
// so a newer opposite fact (an interleaved toggle) stays strictly
|
|
10787
|
-
// ahead of it and reconciles this build on the next tick (f_b851c0e8).
|
|
10788
|
-
...(autoMergeSeedFact !== undefined
|
|
10789
|
-
? { autoMergeDefaultSeq: autoMergeSeedFact.seq }
|
|
10790
|
-
: {}),
|
|
10791
|
-
assets,
|
|
10792
|
-
// Frozen from the same claimed ticket sample as the body (SPEC
|
|
10793
|
-
// "Forge issue links"); later ticket edits never reach this build.
|
|
10794
|
-
...(ticket.issueLinks !== undefined ? { issueLinks: ticket.issueLinks } : {}),
|
|
10795
|
-
// Fixed at claim from the same sample: relabelling never changes it.
|
|
10796
|
-
...this.selectedProfile(ticket),
|
|
10797
|
-
// `manual` is admission-only: a build started by any other request
|
|
10798
|
-
// takes the request's level, every other build its ticket's.
|
|
10799
|
-
...createdPriorityFields(this.claimedLevel(ticket, startTier(ticket), tierOf)),
|
|
10800
|
-
}
|
|
10801
|
-
// `build.created` rides with the record so the pinned assets and the
|
|
10802
|
-
// record exist together or not at all.
|
|
10803
|
-
stage = 'creation-identity'
|
|
10804
|
-
attempt.slug = slug
|
|
10805
|
-
if (creationKey !== undefined) attempt.creationKey = creationKey
|
|
11231
|
+
}
|
|
11232
|
+
if (!conformance.conforms) {
|
|
11233
|
+
attempt.handback = this.triageState()
|
|
11234
|
+
const missing = conformance.missing.length > 0 ? conformance.missing : undefined
|
|
11235
|
+
if (missing) attempt.missing = missing
|
|
10806
11236
|
await store.appendRepo(this.deps.repo, {
|
|
10807
11237
|
actor: DISPATCHER,
|
|
10808
|
-
type: 'ticket-preparation.
|
|
11238
|
+
type: 'ticket-preparation.handback-selected',
|
|
10809
11239
|
payload: {
|
|
10810
11240
|
attempt: attempt.attempt,
|
|
10811
11241
|
ticket: attempt.ticket,
|
|
10812
|
-
|
|
10813
|
-
...(
|
|
11242
|
+
state: attempt.handback,
|
|
11243
|
+
...(missing ? { missing } : {}),
|
|
10814
11244
|
},
|
|
10815
11245
|
})
|
|
10816
|
-
stage = '
|
|
10817
|
-
|
|
10818
|
-
|
|
10819
|
-
|
|
10820
|
-
|
|
10821
|
-
|
|
10822
|
-
|
|
10823
|
-
|
|
10824
|
-
|
|
10825
|
-
|
|
10826
|
-
|
|
10827
|
-
|
|
10828
|
-
|
|
10829
|
-
|
|
10830
|
-
|
|
10831
|
-
|
|
10832
|
-
|
|
10833
|
-
|
|
10834
|
-
|
|
10835
|
-
|
|
10836
|
-
// The deadline may have cut only the acknowledgement: a
|
|
10837
|
-
// committed `build.created` admitted the build, so resolve
|
|
10838
|
-
// the preparation and carry its first provision.
|
|
10839
|
-
if (!this.budgetSpent(this.tickOpts)) throw error
|
|
10840
|
-
const owned = await this.cutCreation(attempt, slug)
|
|
10841
|
-
if (owned === undefined) throw error
|
|
10842
|
-
established = true
|
|
10843
|
-
await this.scoped(() => this.preparationResolved(attempt, 'owned')).catch(
|
|
10844
|
-
(resolution: unknown) => rethrowAuthorityLapse(resolution),
|
|
10845
|
-
)
|
|
10846
|
-
return this.carryCutFirstDispatch(owned.slug, error)
|
|
10847
|
-
})
|
|
10848
|
-
established = true
|
|
10849
|
-
await this.preparationResolved(attempt, 'owned').catch((error: unknown) =>
|
|
10850
|
-
this.carryCutFirstDispatch(created.slug, error),
|
|
10851
|
-
)
|
|
10852
|
-
return created
|
|
10853
|
-
})(),
|
|
10854
|
-
)
|
|
10855
|
-
settle(ticket, { outcome: 'started', slug: record.slug })
|
|
10856
|
-
} catch (error) {
|
|
10857
|
-
// A lapse is not a preparation failure: the successor recovers the
|
|
10858
|
-
// intended attempt through `recoverTicketPreparations`.
|
|
10859
|
-
rethrowAuthorityLapse(error)
|
|
10860
|
-
// Settlement and completion errors after successful creation cannot
|
|
10861
|
-
// release the claim. A later tick settles the retained creation identity.
|
|
10862
|
-
if (established) throw error
|
|
10863
|
-
const errors: unknown[] = [error]
|
|
10864
|
-
attempt.error =
|
|
10865
|
-
(error instanceof Error ? error.message : String(error)).slice(0, 4000) ||
|
|
10866
|
-
'unknown preparation failure'
|
|
10867
|
-
attempt.stage = stage
|
|
10868
|
-
try {
|
|
10869
|
-
await store.appendRepo(this.deps.repo, {
|
|
10870
|
-
actor: DISPATCHER,
|
|
10871
|
-
type: 'ticket-preparation.failed',
|
|
10872
|
-
payload: {
|
|
10873
|
-
attempt: attempt.attempt,
|
|
10874
|
-
ticket: attempt.ticket,
|
|
10875
|
-
stage,
|
|
10876
|
-
claimed: attempt.claimed,
|
|
10877
|
-
handback: attempt.handback ?? attempt.readyState,
|
|
10878
|
-
error: attempt.error,
|
|
10879
|
-
},
|
|
10880
|
-
})
|
|
10881
|
-
} catch (diagnosticError) {
|
|
10882
|
-
errors.push(diagnosticError)
|
|
10883
|
-
}
|
|
10884
|
-
try {
|
|
10885
|
-
await this.recoverTicketPreparation(attempt)
|
|
10886
|
-
} catch (recoveryError) {
|
|
10887
|
-
errors.push(recoveryError)
|
|
10888
|
-
}
|
|
10889
|
-
throw new AggregateError(
|
|
10890
|
-
errors,
|
|
10891
|
-
`ticket preparation failed (${stage}): ${errors.map(String).join('; ')}`,
|
|
10892
|
-
)
|
|
11246
|
+
stage = 'bounce'
|
|
11247
|
+
await this.bounce(ticket, conformance.missing, refusals.length > 0)
|
|
11248
|
+
stage = 'handback-report'
|
|
11249
|
+
await this.reportPreparationHandback(attempt, {
|
|
11250
|
+
ticket: ticket.ref,
|
|
11251
|
+
attempt: attempt.attempt,
|
|
11252
|
+
cause: 'spec-bounce',
|
|
11253
|
+
state: attempt.handback,
|
|
11254
|
+
role: 'triage',
|
|
11255
|
+
...(missing ? { missing } : {}),
|
|
11256
|
+
})
|
|
11257
|
+
await this.preparationResolved(attempt, 'bounced')
|
|
11258
|
+
settle({
|
|
11259
|
+
outcome: 'invalid',
|
|
11260
|
+
detail: `bounced to ${attempt.handback}${
|
|
11261
|
+
conformance.missing.length > 0 ? `; missing: ${conformance.missing.join('; ')}` : ''
|
|
11262
|
+
}`,
|
|
11263
|
+
})
|
|
11264
|
+
report.bounced += 1
|
|
11265
|
+
return 'left'
|
|
10893
11266
|
}
|
|
10894
|
-
|
|
10895
|
-
|
|
10896
|
-
|
|
10897
|
-
const
|
|
10898
|
-
|
|
10899
|
-
|
|
10900
|
-
|
|
10901
|
-
|
|
10902
|
-
|
|
10903
|
-
|
|
11267
|
+
|
|
11268
|
+
stage = 'naming'
|
|
11269
|
+
const baseSlug = await this.chooseSlugBase(ticket.title, body)
|
|
11270
|
+
const prefix = ticket.kind === 'node' ? 'ab-node' : 'ab'
|
|
11271
|
+
const slug = await this.uniqueSlug(baseSlug, prefix)
|
|
11272
|
+
const branch = `${prefix}/${slug}`
|
|
11273
|
+
const repoOrigin = await this.resolveRepoOriginOnce()
|
|
11274
|
+
// Recorded only on the store's attestation, so recovery never treats
|
|
11275
|
+
// an unkeyed creation's absence at the derived slug as evidence.
|
|
11276
|
+
const creationKey =
|
|
11277
|
+
(await store.buildCreationIdentity?.()) === 'keyed' ? attempt.attempt : undefined
|
|
11278
|
+
createdSeed = {
|
|
11279
|
+
...(ticket.kind === 'node' ? { kind: ticket.kind } : {}),
|
|
11280
|
+
...(target !== undefined ? { target: target.target, baseBranch: target.branch } : {}),
|
|
11281
|
+
...(autoMergeUser !== undefined ? { autoMergeUser } : {}),
|
|
11282
|
+
// Claim-time provenance: the newest durable default fact that agrees
|
|
11283
|
+
// with the launch sample, recorded on `build.created` so the fan-out's
|
|
11284
|
+
// seq comparison sees the claim as already answering that fact — and
|
|
11285
|
+
// so a newer opposite fact (an interleaved toggle) stays strictly
|
|
11286
|
+
// ahead of it and reconciles this build on the next tick (f_b851c0e8).
|
|
11287
|
+
...(autoMergeSeedFact !== undefined ? { autoMergeDefaultSeq: autoMergeSeedFact.seq } : {}),
|
|
11288
|
+
assets,
|
|
11289
|
+
// Frozen from the same claimed ticket sample as the body (SPEC
|
|
11290
|
+
// "Forge issue links"); later ticket edits never reach this build.
|
|
11291
|
+
...(ticket.issueLinks !== undefined ? { issueLinks: ticket.issueLinks } : {}),
|
|
11292
|
+
// Fixed at claim from the same sample: relabelling never changes it.
|
|
11293
|
+
...this.selectedProfile(ticket),
|
|
11294
|
+
// `manual` is admission-only: a build started by any other request
|
|
11295
|
+
// takes the request's level, every other build its ticket's.
|
|
11296
|
+
...createdPriorityFields(level),
|
|
11297
|
+
}
|
|
11298
|
+
// `build.created` rides with the record so the pinned assets and the
|
|
11299
|
+
// record exist together or not at all.
|
|
11300
|
+
stage = 'creation-identity'
|
|
11301
|
+
attempt.slug = slug
|
|
11302
|
+
if (creationKey !== undefined) attempt.creationKey = creationKey
|
|
11303
|
+
await store.appendRepo(this.deps.repo, {
|
|
11304
|
+
actor: DISPATCHER,
|
|
11305
|
+
type: 'ticket-preparation.creation-selected',
|
|
11306
|
+
payload: {
|
|
11307
|
+
attempt: attempt.attempt,
|
|
11308
|
+
ticket: attempt.ticket,
|
|
11309
|
+
slug,
|
|
11310
|
+
...(creationKey !== undefined ? { creationKey } : {}),
|
|
11311
|
+
},
|
|
11312
|
+
})
|
|
11313
|
+
stage = 'create-build'
|
|
11314
|
+
// Tracked from the creation on: `build.created` admits the build, so
|
|
11315
|
+
// a work deadline that cuts anything after it must carry the start.
|
|
11316
|
+
record = await this.trackStart(
|
|
11317
|
+
(async () => {
|
|
11318
|
+
const created = await store
|
|
11319
|
+
.createBuild({
|
|
11320
|
+
slug,
|
|
11321
|
+
repo: this.deps.repo,
|
|
11322
|
+
ticket: ticket.ref,
|
|
11323
|
+
branch,
|
|
11324
|
+
...(repoOrigin !== undefined ? { repoOrigin } : {}),
|
|
11325
|
+
...(creationKey !== undefined ? { creationKey } : {}),
|
|
11326
|
+
created: {
|
|
11327
|
+
actor: DISPATCHER,
|
|
11328
|
+
type: 'build.created',
|
|
11329
|
+
payload: this.buildCreatedPayload(ticket.ref, this.deps.repo, createdSeed),
|
|
11330
|
+
},
|
|
11331
|
+
})
|
|
11332
|
+
.catch(async (error: unknown) => {
|
|
11333
|
+
// The deadline may have cut only the acknowledgement: a
|
|
11334
|
+
// committed `build.created` admitted the build, so resolve
|
|
11335
|
+
// the preparation and carry its first provision.
|
|
11336
|
+
if (!this.budgetSpent(this.tickOpts)) throw error
|
|
11337
|
+
const owned = await this.cutCreation(attempt, slug)
|
|
11338
|
+
if (owned === undefined) throw error
|
|
11339
|
+
established = true
|
|
11340
|
+
await this.scoped(() => this.preparationResolved(attempt, 'owned')).catch(
|
|
11341
|
+
(resolution: unknown) => rethrowAuthorityLapse(resolution),
|
|
11342
|
+
)
|
|
11343
|
+
return this.carryCutFirstDispatch(owned.slug, error)
|
|
11344
|
+
})
|
|
11345
|
+
established = true
|
|
11346
|
+
await this.preparationResolved(attempt, 'owned').catch((error: unknown) =>
|
|
11347
|
+
this.carryCutFirstDispatch(created.slug, error),
|
|
11348
|
+
)
|
|
11349
|
+
return created
|
|
11350
|
+
})(),
|
|
10904
11351
|
)
|
|
10905
|
-
|
|
10906
|
-
|
|
10907
|
-
|
|
11352
|
+
settle({ outcome: 'started', slug: record.slug })
|
|
11353
|
+
} catch (error) {
|
|
11354
|
+
// A lapse is not a preparation failure: the successor recovers the
|
|
11355
|
+
// intended attempt through `recoverTicketPreparations`.
|
|
11356
|
+
rethrowAuthorityLapse(error)
|
|
11357
|
+
// Settlement and completion errors after successful creation cannot
|
|
11358
|
+
// release the claim. A later tick settles the retained creation identity.
|
|
11359
|
+
if (established) throw error
|
|
11360
|
+
// The work deadline cut the preparation before `build.created`: carry
|
|
11361
|
+
// the attempt, which resumes first next invocation from its durable
|
|
11362
|
+
// boundaries. Its `workDeadlineAt` stamp is the backstop when this
|
|
11363
|
+
// hint write is lost.
|
|
11364
|
+
if (this.budgetSpent(this.tickOpts)) {
|
|
11365
|
+
await this.notePreparationCarry(
|
|
11366
|
+
attempt.attempt,
|
|
11367
|
+
ticket.ref,
|
|
11368
|
+
`the work deadline cut its preparation (${stage})`,
|
|
11369
|
+
).catch(() => {})
|
|
11370
|
+
this.pass.carry(input.part, ticket.ref.id)
|
|
11371
|
+
return 'carried'
|
|
11372
|
+
}
|
|
11373
|
+
return this.failPreparation(attempt, stage, error)
|
|
11374
|
+
}
|
|
11375
|
+
const outcome = await this.trackStart(
|
|
11376
|
+
this.attemptDispatchCompletion(record, launched, report, {
|
|
11377
|
+
ticket,
|
|
11378
|
+
body,
|
|
11379
|
+
...(authoredSession !== undefined ? { authoredSession } : {}),
|
|
11380
|
+
...createdSeed,
|
|
11381
|
+
}).catch((error: unknown) => this.carryCutFirstDispatch(record.slug, error)),
|
|
11382
|
+
)
|
|
11383
|
+
// Accepted dispatches: durable boundaries recorded. A deferred outcome
|
|
11384
|
+
// means the remote provisioning continuation owns the rest.
|
|
11385
|
+
if (outcome === 'completed' || outcome === 'deferred') report.dispatched += 1
|
|
11386
|
+
return 'started'
|
|
11387
|
+
}
|
|
11388
|
+
|
|
11389
|
+
/** A real preparation failure (SPEC §6.3): record it, then recover the
|
|
11390
|
+
* attempt at once, handing a confirmed claim back. Always throws. */
|
|
11391
|
+
private async failPreparation(
|
|
11392
|
+
attempt: TicketPreparation,
|
|
11393
|
+
stage: string,
|
|
11394
|
+
error: unknown,
|
|
11395
|
+
): Promise<never> {
|
|
11396
|
+
const errors: unknown[] = [error]
|
|
11397
|
+
attempt.error =
|
|
11398
|
+
(error instanceof Error ? error.message : String(error)).slice(0, 4000) ||
|
|
11399
|
+
'unknown preparation failure'
|
|
11400
|
+
attempt.stage = stage
|
|
11401
|
+
try {
|
|
11402
|
+
await this.store.appendRepo(this.deps.repo, {
|
|
11403
|
+
actor: DISPATCHER,
|
|
11404
|
+
type: 'ticket-preparation.failed',
|
|
11405
|
+
payload: {
|
|
11406
|
+
attempt: attempt.attempt,
|
|
11407
|
+
ticket: attempt.ticket,
|
|
11408
|
+
stage,
|
|
11409
|
+
claimed: attempt.claimed,
|
|
11410
|
+
handback: attempt.handback ?? attempt.readyState,
|
|
11411
|
+
error: attempt.error,
|
|
11412
|
+
},
|
|
11413
|
+
})
|
|
11414
|
+
} catch (diagnosticError) {
|
|
11415
|
+
errors.push(diagnosticError)
|
|
10908
11416
|
}
|
|
10909
|
-
|
|
10910
|
-
await this.
|
|
10911
|
-
|
|
10912
|
-
|
|
11417
|
+
try {
|
|
11418
|
+
await this.recoverTicketPreparation(attempt)
|
|
11419
|
+
} catch (recoveryError) {
|
|
11420
|
+
errors.push(recoveryError)
|
|
10913
11421
|
}
|
|
11422
|
+
throw new AggregateError(
|
|
11423
|
+
errors,
|
|
11424
|
+
`ticket preparation failed (${stage}): ${errors.map(String).join('; ')}`,
|
|
11425
|
+
)
|
|
11426
|
+
}
|
|
11427
|
+
|
|
11428
|
+
/** Append an attempt's `intended`, stamped with the work deadline in a
|
|
11429
|
+
* bounded pass, with the admitted level (`attempt.level`). `claimDeferred`
|
|
11430
|
+
* journals an admission made without a claim call. */
|
|
11431
|
+
private async appendIntended(attempt: TicketPreparation, claimDeferred = false): Promise<void> {
|
|
11432
|
+
const deadline = this.tickOpts.deadlineAt
|
|
11433
|
+
const workDeadlineAt = deadline !== undefined ? new Date(deadline).toISOString() : undefined
|
|
11434
|
+
await this.store.appendRepo(this.deps.repo, {
|
|
11435
|
+
actor: DISPATCHER,
|
|
11436
|
+
type: 'ticket-preparation.intended',
|
|
11437
|
+
payload: {
|
|
11438
|
+
attempt: attempt.attempt,
|
|
11439
|
+
ticket: attempt.ticket,
|
|
11440
|
+
readyState: attempt.readyState,
|
|
11441
|
+
claimedState: attempt.claimedState,
|
|
11442
|
+
...(workDeadlineAt !== undefined ? { workDeadlineAt } : {}),
|
|
11443
|
+
...(claimDeferred ? { claimDeferred: true as const } : {}),
|
|
11444
|
+
// Admission's level travels with the stamp, so a carried attempt
|
|
11445
|
+
// resumes at the level it was admitted at.
|
|
11446
|
+
...(workDeadlineAt !== undefined && attempt.level !== undefined
|
|
11447
|
+
? { level: attempt.level }
|
|
11448
|
+
: {}),
|
|
11449
|
+
},
|
|
11450
|
+
})
|
|
11451
|
+
if (workDeadlineAt !== undefined) attempt.workDeadlineAt = workDeadlineAt
|
|
11452
|
+
if (claimDeferred) attempt.claimDeferred = true
|
|
11453
|
+
else delete attempt.claimDeferred
|
|
11454
|
+
}
|
|
11455
|
+
|
|
11456
|
+
/** Whether a bounded pass has too little time left before its work
|
|
11457
|
+
* deadline to start a ticket preparation. Pure clock arithmetic. */
|
|
11458
|
+
private preparationWontFit(): boolean {
|
|
11459
|
+
const deadline = this.tickOpts.deadlineAt
|
|
11460
|
+
return (
|
|
11461
|
+
deadline !== undefined && deadline - this.deps.clock().getTime() < this.preparationEstimateMs
|
|
11462
|
+
)
|
|
11463
|
+
}
|
|
11464
|
+
|
|
11465
|
+
/** Journal intake's admission of a ticket it has no time to prepare: one
|
|
11466
|
+
* `intended` with `claimDeferred` and no tracker call (#1431). The
|
|
11467
|
+
* unresolved attempt withholds the ticket from later scans, and the next
|
|
11468
|
+
* invocation claims and prepares it first. True when the admission was
|
|
11469
|
+
* journaled. */
|
|
11470
|
+
private deferPreparation(attempt: TicketPreparation, part: PassStagePart): Promise<boolean> {
|
|
11471
|
+
return this.trackStart(
|
|
11472
|
+
(async () => {
|
|
11473
|
+
const remaining = Math.max(0, (this.tickOpts.deadlineAt ?? 0) - this.deps.clock().getTime())
|
|
11474
|
+
try {
|
|
11475
|
+
await this.appendIntended(attempt, true)
|
|
11476
|
+
} catch (error) {
|
|
11477
|
+
rethrowAuthorityLapse(error)
|
|
11478
|
+
if (this.budgetSpent(this.tickOpts)) return false
|
|
11479
|
+
throw error
|
|
11480
|
+
}
|
|
11481
|
+
await this.notePreparationCarry(
|
|
11482
|
+
attempt.attempt,
|
|
11483
|
+
attempt.ticket,
|
|
11484
|
+
`${remaining} ms remain but a ticket preparation needs about ${this.preparationEstimateMs} ms`,
|
|
11485
|
+
)
|
|
11486
|
+
this.pass.carry(part, attempt.ticket.id)
|
|
11487
|
+
return true
|
|
11488
|
+
})(),
|
|
11489
|
+
)
|
|
10914
11490
|
}
|
|
10915
11491
|
|
|
10916
11492
|
/** Builds whose ticket resolves to `target` under the repository's
|