@defrex/autobuild 1.11.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/SPEC.md +186 -57
- package/docs/answering-blocked-builds.md +10 -2
- package/docs/architecture.md +76 -10
- package/docs/assets/headline-wide.png +0 -0
- package/docs/cli.md +1 -1
- package/docs/configuration.md +13 -11
- package/docs/dispatcher.md +5 -4
- package/docs/integration-tree.md +28 -16
- package/docs/operator-api.md +4 -4
- package/docs/operator-surfaces.md +38 -3
- package/docs/optimization-nodes.md +3 -2
- package/docs/tickets.md +1 -1
- package/docs/troubleshooting.md +1 -1
- package/package.json +3 -3
- package/packages/core/src/cli/ambient-errors.ts +17 -0
- package/packages/core/src/cli/bounded-io.ts +174 -0
- package/packages/core/src/cli/dashboard/header.ts +10 -0
- package/packages/core/src/cli/dashboard/model.ts +81 -23
- package/packages/core/src/cli/dashboard/poll.ts +24 -34
- package/packages/core/src/cli/dashboard/render.ts +44 -37
- package/packages/core/src/cli/dashboard/row-text.ts +24 -7
- package/packages/core/src/cli/dashboard/tone-ansi.ts +39 -0
- package/packages/core/src/cli/dashboard/vocabulary.ts +161 -20
- package/packages/core/src/cli/dispatch-frontend.ts +12 -3
- package/packages/core/src/cli/dispatch-handoff.ts +41 -10
- package/packages/core/src/cli/dispatch-launch-contract.ts +5 -0
- package/packages/core/src/cli/dispatch-launcher-cadence.ts +80 -0
- package/packages/core/src/cli/dispatch-launcher.ts +9 -10
- package/packages/core/src/cli/dispatch-preflight.ts +12 -3
- package/packages/core/src/cli/dispatch-release-observer.ts +53 -0
- package/packages/core/src/cli/dispatch-runtime-cache.ts +204 -82
- package/packages/core/src/cli/dispatch-runtime-dependencies.ts +250 -43
- package/packages/core/src/cli/dispatch-upgrade-install.ts +36 -16
- package/packages/core/src/cli/dispatch-upgrade-source.ts +8 -2
- package/packages/core/src/cli/dispatch-yield-observer.ts +82 -0
- package/packages/core/src/cli/dispatch.ts +70 -9
- package/packages/core/src/cli/env.ts +2 -15
- package/packages/core/src/cli/help.ts +5 -4
- package/packages/core/src/cli/main.ts +4 -2
- package/packages/core/src/cli/production-store.ts +102 -0
- package/packages/core/src/cli/repo-state.ts +2 -3
- package/packages/core/src/cli/repository-status.ts +36 -28
- package/packages/core/src/cli/sessionless-store.ts +26 -0
- package/packages/core/src/cli/status.ts +169 -40
- package/packages/core/src/cli/store-opening.ts +15 -58
- package/packages/core/src/cli/store-ref.ts +6 -1
- package/packages/core/src/config/schema.ts +1 -1
- package/packages/core/src/distribution-packaging.ts +156 -18
- package/packages/core/src/events/catalog-identity.ts +28 -0
- package/packages/core/src/events/catalog.ts +3 -9
- package/packages/core/src/events/compatibility.ts +2 -30
- package/packages/core/src/events/payloads.ts +11 -0
- package/packages/core/src/events/policy.ts +3 -0
- package/packages/core/src/events/repository.ts +1 -1
- package/packages/core/src/events/sessions.ts +1 -1
- package/packages/core/src/events/validation-error.ts +12 -0
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +74 -30
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/3064e337cc75f8d6.json +310 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/46196d8f0076496a.json +97 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a1e90a969d32a367.json +307 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/da3bc91c49211eab.json +310 -0
- package/packages/core/src/kernel/auto-merge-default.ts +2 -1
- package/packages/core/src/kernel/capacity-build.ts +21 -0
- package/packages/core/src/kernel/discard-in-flight.ts +13 -0
- package/packages/core/src/kernel/dispatch-capacity.ts +354 -147
- package/packages/core/src/kernel/dispatch-status.ts +139 -0
- package/packages/core/src/kernel/engine.ts +2 -8
- package/packages/core/src/kernel/measurement.ts +24 -0
- package/packages/core/src/kernel/read-facts.ts +9 -369
- package/packages/core/src/kernel/reducer-registry.ts +40 -125
- package/packages/core/src/kernel/reducer-revisions.ts +5 -0
- package/packages/core/src/kernel/reducer-value-entry.ts +98 -0
- package/packages/core/src/kernel/reducer-value-index.ts +75 -0
- package/packages/core/src/kernel/reducer.ts +57 -9
- package/packages/core/src/kernel/reopen-state.ts +10 -0
- package/packages/core/src/kernel/repository-read-facts.ts +375 -0
- package/packages/core/src/kernel/verify-stage-state.ts +145 -3
- package/packages/core/src/operator/presentation.ts +13 -0
- package/packages/core/src/operator/query.ts +47 -41
- package/packages/core/src/operator/registry.ts +3 -3
- package/packages/core/src/ports/workspace/fake.ts +15 -3
- package/packages/core/src/processes/dispatcher.ts +232 -75
- package/packages/core/src/processes/execution-no-progress.ts +1 -0
- package/packages/core/src/store/local/capabilities.ts +115 -0
- package/packages/core/src/store/local/store.ts +86 -56
- package/packages/core/src/store/reduced-reads.ts +9 -1
- package/packages/core/src/store/reducer-value-read.ts +235 -0
- package/packages/core/src/store/reducer-value-shapes.json +3796 -3670
- package/packages/core/src/store/reducer-values.ts +36 -204
- package/packages/core/src/store/remote/released-clients.json +22 -0
- package/packages/core/src/store/remote/released-reducer-values/1.11.1.json +35718 -0
- package/packages/core/src/store/remote/released-reducer-values/1.12.0.json +35806 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +20 -16
- package/packages/core/src/store/rollup-lease.ts +41 -0
- package/packages/core/src/store/rollups.ts +7 -38
- package/packages/core/src/store/snapshots.ts +1 -1
- package/packages/core/src/testing/dispatch-journals.ts +117 -0
- package/packages/core/src/testing/dispatch-read-budget.ts +265 -4
- package/packages/core/src/testing/import-graph.ts +78 -0
- package/packages/core/src/testing/reduced-read-budget.ts +221 -22
- package/packages/core/src/testing/slot-agreement.ts +52 -0
- package/packages/core/src/web/assets/app.js +5 -5
- package/packages/core/src/web/repository-source.ts +6 -2
- package/skills/guide/SKILL.md +126 -47
- package/skills/guide/references/integration-tree.md +28 -16
- package/skills/guide/references/operator-api.md +4 -4
- package/skills/guide/references/optimization-nodes.md +3 -2
- package/skills/operate/SKILL.md +38 -20
- package/templates/hosted-service/package.json +2 -2
|
@@ -12,43 +12,184 @@
|
|
|
12
12
|
*
|
|
13
13
|
* Tones are presentation-neutral names. The terminal maps them to ANSI colours
|
|
14
14
|
* and the web maps them to `packages/ui` state tones, whose names are the same.
|
|
15
|
+
*
|
|
16
|
+
* Build status words come from one closed word→tone table
|
|
17
|
+
* (`BUILD_STATUS_TONE`, SPEC §14 "Status words"), chosen by
|
|
18
|
+
* `buildStatusText` from the row's slot state and a small `StatusBasis` of
|
|
19
|
+
* lifecycle facts. No frontend keeps its own word or tone map.
|
|
15
20
|
*/
|
|
16
21
|
import { displayText } from './cells'
|
|
17
22
|
import type { DashboardHarvest, EffectiveStatus, PipelineStep, StepState } from './model'
|
|
18
23
|
import type { RosterOutcome } from '../../kernel/build-roster'
|
|
24
|
+
import type { SlotState } from '../../kernel/dispatch-capacity'
|
|
19
25
|
|
|
20
26
|
/** The emphasis a term carries. Never the only carrier of meaning: every toned
|
|
21
27
|
* term also has its literal word or glyph. */
|
|
22
28
|
export type DashboardTone = 'ok' | 'live' | 'held' | 'alert' | 'pending'
|
|
23
29
|
|
|
24
|
-
/** Every lifecycle
|
|
30
|
+
/** Every lifecycle status a dashboard row routes on. */
|
|
25
31
|
export type DashboardStatus = EffectiveStatus | DashboardHarvest['status']
|
|
26
32
|
|
|
33
|
+
/**
|
|
34
|
+
* The closed build status vocabulary (SPEC §14 "Status words"). Each tone
|
|
35
|
+
* falls wholly on one side of the slot line (§12 "What holds a slot"): every
|
|
36
|
+
* `ok` (green) word holds a slot, `live` (teal) requested one, and the rest
|
|
37
|
+
* hold none.
|
|
38
|
+
*/
|
|
39
|
+
export type BuildStatusWord =
|
|
40
|
+
| 'RUNNING'
|
|
41
|
+
| 'STARTING'
|
|
42
|
+
| 'PAUSING'
|
|
43
|
+
| 'ABORTING'
|
|
44
|
+
| 'QUEUED'
|
|
45
|
+
| 'WAITING'
|
|
46
|
+
| 'MERGING'
|
|
47
|
+
| 'PAUSED'
|
|
48
|
+
| 'COLLECTING'
|
|
49
|
+
| 'BLOCKED'
|
|
50
|
+
| 'CLEANING'
|
|
51
|
+
|
|
52
|
+
/** A harvest run's words. A harvest never holds a slot, so none is green. */
|
|
53
|
+
export type HarvestStatusWord = 'HARVESTING' | 'PAUSED' | 'SUSPENDED' | 'ESCALATED' | 'FAILED'
|
|
54
|
+
|
|
55
|
+
export const BUILD_STATUS_TONE: Readonly<Record<BuildStatusWord, DashboardTone>> = {
|
|
56
|
+
RUNNING: 'ok',
|
|
57
|
+
STARTING: 'ok',
|
|
58
|
+
PAUSING: 'ok',
|
|
59
|
+
ABORTING: 'ok',
|
|
60
|
+
QUEUED: 'live',
|
|
61
|
+
WAITING: 'held',
|
|
62
|
+
MERGING: 'held',
|
|
63
|
+
PAUSED: 'held',
|
|
64
|
+
COLLECTING: 'held',
|
|
65
|
+
BLOCKED: 'alert',
|
|
66
|
+
CLEANING: 'pending',
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const HARVEST_STATUS_TONE: Readonly<Record<HarvestStatusWord, DashboardTone>> = {
|
|
70
|
+
HARVESTING: 'live',
|
|
71
|
+
PAUSED: 'held',
|
|
72
|
+
SUSPENDED: 'held',
|
|
73
|
+
ESCALATED: 'alert',
|
|
74
|
+
FAILED: 'alert',
|
|
75
|
+
}
|
|
76
|
+
|
|
27
77
|
export interface StatusText {
|
|
78
|
+
/** The routing value: the build's effective status or the harvest status. */
|
|
28
79
|
status: DashboardStatus
|
|
29
80
|
/** The literal uppercase word (`RUNNING`, `BLOCKED`). */
|
|
30
|
-
word:
|
|
81
|
+
word: BuildStatusWord | HarvestStatusWord
|
|
31
82
|
tone: DashboardTone
|
|
83
|
+
/** Why the build shows its word (`resume`, `merge decision`, `on AUT-1`). */
|
|
84
|
+
note?: string
|
|
32
85
|
}
|
|
33
86
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
87
|
+
/**
|
|
88
|
+
* The lifecycle facts a build's status word is chosen from, projected once
|
|
89
|
+
* from its reduced state. JSON-safe: no member is ever `undefined`.
|
|
90
|
+
*/
|
|
91
|
+
export interface StatusBasis {
|
|
92
|
+
/** The effective status with pending commands ignored. */
|
|
93
|
+
resting: 'queued' | 'running' | 'collecting' | 'paused' | 'blocked' | 'waiting' | 'cleaning'
|
|
94
|
+
/** A pause command is pending. */
|
|
95
|
+
pause?: true
|
|
96
|
+
/** An abort command is pending. */
|
|
97
|
+
abort?: true
|
|
98
|
+
/** A resume command is pending. */
|
|
99
|
+
resume?: true
|
|
100
|
+
/** A runner's execution is open. */
|
|
101
|
+
runner: boolean
|
|
102
|
+
node?: true
|
|
103
|
+
/** A finished pipeline: waiting for a merge decision, on hold, or merging
|
|
104
|
+
* (consent given, waiting for gates or the forge). */
|
|
105
|
+
settled?: 'decision' | 'hold' | 'merging'
|
|
106
|
+
/** A `revise-spec` answer waits for its revision. */
|
|
107
|
+
reviseSpec?: true
|
|
108
|
+
/** The open ticket wait's tickets, when the build rests `waiting`. */
|
|
109
|
+
waitTickets?: string[]
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The basis a hand-built row without one implies from its status alone. */
|
|
113
|
+
function basisFromStatus(status: EffectiveStatus): StatusBasis {
|
|
114
|
+
switch (status) {
|
|
115
|
+
case 'pausing':
|
|
116
|
+
return { resting: 'running', pause: true, runner: true }
|
|
117
|
+
case 'aborting':
|
|
118
|
+
return { resting: 'running', abort: true, runner: true }
|
|
119
|
+
case 'resuming':
|
|
120
|
+
return { resting: 'paused', resume: true, runner: false }
|
|
121
|
+
default:
|
|
122
|
+
return { resting: status, runner: status === 'running' }
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function buildWord(status: EffectiveStatus, word: BuildStatusWord, note?: string): StatusText {
|
|
127
|
+
return {
|
|
128
|
+
status,
|
|
129
|
+
word,
|
|
130
|
+
tone: BUILD_STATUS_TONE[word],
|
|
131
|
+
...(note !== undefined ? { note } : {}),
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* A nonterminal build's status word (SPEC §14 "Status words"): its slot state
|
|
137
|
+
* picks the tone, then lifecycle facts pick the word within it. A build that
|
|
138
|
+
* holds no slot is never green. When the slot is unknown (a value from an
|
|
139
|
+
* older server, or a caller without capacity facts), it is inferred from
|
|
140
|
+
* lifecycle facts.
|
|
141
|
+
*/
|
|
142
|
+
export function buildStatusText(input: {
|
|
143
|
+
status: EffectiveStatus
|
|
144
|
+
slot?: SlotState
|
|
145
|
+
basis?: StatusBasis
|
|
146
|
+
}): StatusText {
|
|
147
|
+
const { status } = input
|
|
148
|
+
const basis = input.basis ?? basisFromStatus(status)
|
|
149
|
+
if (basis.resting === 'cleaning') return buildWord(status, 'CLEANING')
|
|
150
|
+
const slot: SlotState | undefined =
|
|
151
|
+
input.slot ??
|
|
152
|
+
(((basis.resting === 'queued' || basis.resting === 'running') &&
|
|
153
|
+
basis.settled === undefined &&
|
|
154
|
+
basis.reviseSpec === undefined) ||
|
|
155
|
+
(basis.resting === 'collecting' && basis.runner)
|
|
156
|
+
? { state: 'held' }
|
|
157
|
+
: basis.resume && basis.resting === 'paused'
|
|
158
|
+
? { state: 'requested', request: 'resume' }
|
|
159
|
+
: undefined)
|
|
160
|
+
if (slot?.state === 'held') {
|
|
161
|
+
if (basis.abort) return buildWord(status, 'ABORTING')
|
|
162
|
+
if (basis.pause) return buildWord(status, 'PAUSING')
|
|
163
|
+
return buildWord(status, basis.runner ? 'RUNNING' : 'STARTING')
|
|
164
|
+
}
|
|
165
|
+
if (slot?.state === 'requested')
|
|
166
|
+
return buildWord(
|
|
167
|
+
status,
|
|
168
|
+
'QUEUED',
|
|
169
|
+
slot.priority === 'urgent' ? `urgent ${slot.request}` : slot.request,
|
|
170
|
+
)
|
|
171
|
+
// No slot: a pending pause or abort waits for its acknowledgement.
|
|
172
|
+
if (basis.resting === 'blocked') return buildWord(status, 'BLOCKED')
|
|
173
|
+
if (basis.resting === 'waiting')
|
|
174
|
+
return buildWord(
|
|
175
|
+
status,
|
|
176
|
+
'WAITING',
|
|
177
|
+
basis.waitTickets?.length ? `on ${basis.waitTickets.join(', ')}` : undefined,
|
|
178
|
+
)
|
|
179
|
+
if (basis.resting === 'paused') return buildWord(status, 'PAUSED')
|
|
180
|
+
if (basis.reviseSpec) return buildWord(status, 'WAITING', 'spec revision')
|
|
181
|
+
if (basis.settled === 'merging') return buildWord(status, 'MERGING')
|
|
182
|
+
if (basis.settled !== undefined)
|
|
183
|
+
return buildWord(status, 'WAITING', basis.settled === 'hold' ? 'on hold' : 'merge decision')
|
|
184
|
+
if (basis.resting === 'collecting' || basis.node) return buildWord(status, 'COLLECTING')
|
|
185
|
+
return buildWord(status, 'WAITING')
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** A harvest row's word: `HARVESTING` while it works, its stop otherwise. */
|
|
189
|
+
export function harvestStatusText(status: DashboardHarvest['status']): StatusText {
|
|
190
|
+
const word: HarvestStatusWord =
|
|
191
|
+
status === 'running' ? 'HARVESTING' : (status.toUpperCase() as HarvestStatusWord)
|
|
192
|
+
return { status, word, tone: HARVEST_STATUS_TONE[word] }
|
|
52
193
|
}
|
|
53
194
|
|
|
54
195
|
const STEP_MARK: Record<StepState, string> = {
|
|
@@ -53,6 +53,7 @@ import {
|
|
|
53
53
|
detailScrollLimit,
|
|
54
54
|
moveDetailScroll,
|
|
55
55
|
moveTranscriptScroll,
|
|
56
|
+
pinTopLineUrl,
|
|
56
57
|
renderDashboard,
|
|
57
58
|
viewerIndicator,
|
|
58
59
|
renderViewerNotice,
|
|
@@ -109,7 +110,8 @@ export interface DispatchFrontendOptions {
|
|
|
109
110
|
viewer?: { dispatchedBy?: string }
|
|
110
111
|
plainOutput?: (line: string) => void
|
|
111
112
|
/** `--web`: each frame's repository facts are published to the web UI from
|
|
112
|
-
* the read this frontend already made; the web adds no store read.
|
|
113
|
+
* the read this frontend already made; the web adds no store read. A TTY
|
|
114
|
+
* frontend also pins `url` to the right end of every frame's top line. */
|
|
113
115
|
web?: { dispatch: DispatchWeb }
|
|
114
116
|
/** Repository identity (§12): the normalized origin, or the checkout path
|
|
115
117
|
* when there is no origin. Every Store key uses this. */
|
|
@@ -346,7 +348,14 @@ export class DispatchFrontend {
|
|
|
346
348
|
const frame = lines.join('\n')
|
|
347
349
|
if (frame !== this.lastPlainFrame) this.opts.plainOutput(frame)
|
|
348
350
|
this.lastPlainFrame = frame
|
|
349
|
-
} else this.region.update(lines)
|
|
351
|
+
} else this.region.update(this.withWebUrl(lines))
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** Pin the served web UI's URL to the top line of a TTY frame; identity
|
|
355
|
+
* under plain output or without `--web`. */
|
|
356
|
+
private withWebUrl(lines: string[]): string[] {
|
|
357
|
+
if (this.opts.plainOutput !== undefined || this.opts.web === undefined) return lines
|
|
358
|
+
return pinTopLineUrl(lines, this.opts.web.dispatch.url, this.opts.terminal.columns)
|
|
350
359
|
}
|
|
351
360
|
|
|
352
361
|
private contentHeight(): number {
|
|
@@ -459,7 +468,7 @@ export class DispatchFrontend {
|
|
|
459
468
|
),
|
|
460
469
|
)
|
|
461
470
|
} else if (status.health === 'failed' && status.warningNotice !== undefined)
|
|
462
|
-
this.region.update([status.warningNotice])
|
|
471
|
+
this.region.update(this.withWebUrl([status.warningNotice]))
|
|
463
472
|
// Startup is incomplete: retry at the same position.
|
|
464
473
|
return undefined
|
|
465
474
|
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { rollbackRuntimeRetained } from './dispatch-runtime-use'
|
|
2
2
|
import { join, resolve, dirname } from 'node:path'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { spawnExec } from '../ports/workspace/git-worktree'
|
|
6
|
-
import { parseDispatchArgs } from './dispatch-args'
|
|
7
|
-
import { readDispatchUpgrade, readDispatcherRunFacts } from '../store/reduced-reads'
|
|
3
|
+
import type { StoreOpener } from './production-store'
|
|
4
|
+
import type { readDispatcherRunFacts } from '../store/reduced-reads'
|
|
8
5
|
import { cachedRuntime } from './dispatch-runtime-cache'
|
|
9
6
|
import type {
|
|
10
7
|
GenerationLaunch,
|
|
@@ -18,6 +15,11 @@ import type { UpgradeRun } from '../kernel/dispatch-upgrade'
|
|
|
18
15
|
type DispatcherRunFacts = Awaited<ReturnType<typeof readDispatcherRunFacts>>['value']
|
|
19
16
|
import type { Handoff } from '../kernel/dispatch-upgrade'
|
|
20
17
|
|
|
18
|
+
/** Reader commands run in short-lived processes, so they initialize only what
|
|
19
|
+
* their operation needs: store, reducer and argument modules load at first
|
|
20
|
+
* use, and a reader with a journal never resolves repository configuration. */
|
|
21
|
+
const reducedReads = () => import('../store/reduced-reads')
|
|
22
|
+
|
|
21
23
|
/** Once a held run identifies its journal, readers retain that transport
|
|
22
24
|
* identity across rejected configuration edits. It conveys no lifecycle result. */
|
|
23
25
|
export async function openGenerationStore(
|
|
@@ -28,11 +30,21 @@ export async function openGenerationStore(
|
|
|
28
30
|
) {
|
|
29
31
|
if (launch.journal) {
|
|
30
32
|
const { storeRef, repo } = launch.journal
|
|
31
|
-
const token = /^https?:/i.test(storeRef)
|
|
32
|
-
|
|
33
|
+
const token = /^https?:/i.test(storeRef)
|
|
34
|
+
? (await import('./project-credentials')).projectToken(storeRef, repo, env)
|
|
35
|
+
: env.AB_TOKEN
|
|
36
|
+
const store = openStore
|
|
37
|
+
? openStore(storeRef, token)
|
|
38
|
+
: await (await import('./production-store')).openProductionStoreAsync(storeRef, token)
|
|
39
|
+
return { store, storeRef, repo }
|
|
33
40
|
}
|
|
41
|
+
const [{ parseDispatchArgs }, { spawnExec }, { openSessionlessStoreLazily }] = await Promise.all([
|
|
42
|
+
import('./dispatch-args'),
|
|
43
|
+
import('../ports/workspace/git-worktree'),
|
|
44
|
+
import('./sessionless-store'),
|
|
45
|
+
])
|
|
34
46
|
const args = parseDispatchArgs(argv.slice(1), env)
|
|
35
|
-
return
|
|
47
|
+
return openSessionlessStoreLazily({
|
|
36
48
|
targetRepo: launch.checkout,
|
|
37
49
|
exec: spawnExec,
|
|
38
50
|
env,
|
|
@@ -47,8 +59,9 @@ export async function readGenerationJournal(
|
|
|
47
59
|
launch: GenerationLaunch,
|
|
48
60
|
argv: string[],
|
|
49
61
|
env: Record<string, string | undefined>,
|
|
62
|
+
options: { openStore?: StoreOpener } = {},
|
|
50
63
|
) {
|
|
51
|
-
const opened = await openGenerationStore(launch, argv, env)
|
|
64
|
+
const opened = await openGenerationStore(launch, argv, env, options.openStore)
|
|
52
65
|
try {
|
|
53
66
|
await opened.store.ensureRepo(opened.repo)
|
|
54
67
|
return {
|
|
@@ -67,11 +80,13 @@ export async function readHandoff(
|
|
|
67
80
|
argv: string[],
|
|
68
81
|
env: Record<string, string | undefined>,
|
|
69
82
|
live = false,
|
|
83
|
+
options: { openStore?: StoreOpener } = {},
|
|
70
84
|
): Promise<Handoff | undefined> {
|
|
71
85
|
if (!launch.run || !launch.lineage) return undefined
|
|
72
|
-
const opened = await openGenerationStore(launch, argv, env)
|
|
86
|
+
const opened = await openGenerationStore(launch, argv, env, options.openStore)
|
|
73
87
|
try {
|
|
74
88
|
if (!(await opened.store.getRepo(opened.repo))) return undefined
|
|
89
|
+
const { readDispatchUpgrade, readDispatcherRunFacts } = await reducedReads()
|
|
75
90
|
const state = (await readDispatchUpgrade(opened.store, opened.repo)).value.runs[launch.run]
|
|
76
91
|
const selected = live ? state?.prepared : state?.handoff
|
|
77
92
|
if (!selected || (!live && state?.completed) || state?.failure) return undefined
|
|
@@ -169,6 +184,7 @@ export async function readUpgradeProjection(
|
|
|
169
184
|
let projection: UpgradeProjection = { version: 1, handoff: null, takeover: false }
|
|
170
185
|
let guards: UpgradeGuards | undefined
|
|
171
186
|
if (journal) {
|
|
187
|
+
const { readDispatchUpgrade, readDispatcherRunFacts } = await reducedReads()
|
|
172
188
|
const upgrades = (await readDispatchUpgrade(opened.store, opened.repo)).value
|
|
173
189
|
const state = upgrades.runs[launch.run!]
|
|
174
190
|
const facts =
|
|
@@ -177,6 +193,17 @@ export async function readUpgradeProjection(
|
|
|
177
193
|
: undefined
|
|
178
194
|
const rollbackRecorded =
|
|
179
195
|
!!launch.rollback && upgrades.rollbackIds.includes(launch.rollback.correlation)
|
|
196
|
+
// An outstanding preparation only paces launcher observation.
|
|
197
|
+
const detected = state?.detected?.payload
|
|
198
|
+
const preparing =
|
|
199
|
+
detected &&
|
|
200
|
+
detected.lineage === launch.lineage &&
|
|
201
|
+
state.prepared?.payload.correlation !== detected.correlation &&
|
|
202
|
+
state.failure?.payload.correlation !== detected.correlation &&
|
|
203
|
+
!state.request &&
|
|
204
|
+
!state.handoff
|
|
205
|
+
? detected.correlation
|
|
206
|
+
: undefined
|
|
180
207
|
guards = {
|
|
181
208
|
handoff: facts ? selectHandoff(launch, state, facts, true) : null,
|
|
182
209
|
rollbackRecorded,
|
|
@@ -197,6 +224,7 @@ export async function readUpgradeProjection(
|
|
|
197
224
|
accepted: !!state?.handoff,
|
|
198
225
|
successor: state?.request?.payload.successor,
|
|
199
226
|
released: !!state?.released,
|
|
227
|
+
...(preparing ? { preparing } : {}),
|
|
200
228
|
}
|
|
201
229
|
}
|
|
202
230
|
return condition
|
|
@@ -221,6 +249,7 @@ export async function recordPreflightFailure(
|
|
|
221
249
|
) {
|
|
222
250
|
const opened = await openGenerationStore(launch, argv, env)
|
|
223
251
|
try {
|
|
252
|
+
const { readDispatchUpgrade, readDispatcherRunFacts } = await reducedReads()
|
|
224
253
|
const state = (await readDispatchUpgrade(opened.store, opened.repo)).value.runs[launch.run!]
|
|
225
254
|
const facts = (await readDispatcherRunFacts(opened.store, opened.repo, launch.run!)).value
|
|
226
255
|
if (facts.stopRequest) return
|
|
@@ -256,6 +285,7 @@ export async function recoverTerminalRelease(
|
|
|
256
285
|
throw new Error('terminal recovery requires the owning launcher')
|
|
257
286
|
const opened = await openGenerationStore(launch, argv, env)
|
|
258
287
|
try {
|
|
288
|
+
const { readDispatchUpgrade, readDispatcherRunFacts } = await reducedReads()
|
|
259
289
|
const state = (await readDispatchUpgrade(opened.store, opened.repo)).value.runs[launch.run!]
|
|
260
290
|
const facts = (await readDispatcherRunFacts(opened.store, opened.repo, launch.run!)).value
|
|
261
291
|
if (
|
|
@@ -286,6 +316,7 @@ export async function recordRuntimeRollback(
|
|
|
286
316
|
run: string,
|
|
287
317
|
): Promise<void> {
|
|
288
318
|
const context = launch.rollback
|
|
319
|
+
const { readDispatchUpgrade } = await reducedReads()
|
|
289
320
|
if (launch.recovery) {
|
|
290
321
|
const recovery = launch.recovery
|
|
291
322
|
const state = (await readDispatchUpgrade(store, repo)).value.runs[recovery.predecessor]
|
|
@@ -190,6 +190,10 @@ export interface UpgradeProjection {
|
|
|
190
190
|
accepted?: boolean
|
|
191
191
|
successor?: string
|
|
192
192
|
released?: boolean
|
|
193
|
+
/** The active run's detected upgrade correlation while it has no prepared
|
|
194
|
+
* target, failure, request or handoff yet. Advisory scheduling input for
|
|
195
|
+
* the launcher's observation cadence only, never a lifecycle decision. */
|
|
196
|
+
preparing?: string
|
|
193
197
|
}
|
|
194
198
|
export interface UpgradeCondition {
|
|
195
199
|
version: 1
|
|
@@ -252,6 +256,7 @@ function validUpgradeProjection(value: unknown): value is UpgradeProjection {
|
|
|
252
256
|
(p.rollbackVersion === undefined || p.rollbackVersion === 1) &&
|
|
253
257
|
(p.takeoverAt === undefined || typeof p.takeoverAt === 'string') &&
|
|
254
258
|
(p.successor === undefined || typeof p.successor === 'string') &&
|
|
259
|
+
(p.preparing === undefined || (typeof p.preparing === 'string' && p.preparing.length > 0)) &&
|
|
255
260
|
(p.journal === undefined ||
|
|
256
261
|
(!!p.journal && typeof p.journal.storeRef === 'string' && typeof p.journal.repo === 'string'))
|
|
257
262
|
)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Launcher supervision pacing. The launcher observes durable upgrade state
|
|
3
|
+
* through runtime-owned readers between pauses; this module only decides how
|
|
4
|
+
* long each pause lasts and how it ends. It has no imports, so it keeps the
|
|
5
|
+
* launcher's filesystem/process-only import graph.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** Ordinary supervision while no successor is pending. */
|
|
9
|
+
export const SUPERVISION_IDLE_MS = 1_000
|
|
10
|
+
/** Supervision while a successor preflight is pending. */
|
|
11
|
+
export const SUPERVISION_PENDING_MS = 250
|
|
12
|
+
/** Temporary cadence while the active run's detected upgrade is unresolved. */
|
|
13
|
+
export const PREPARATION_OBSERVATION_MS = 50
|
|
14
|
+
/** Fast observations allowed per detection correlation before idle cadence. */
|
|
15
|
+
export const PREPARATION_OBSERVATION_LIMIT = 600
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Returns the delay before the next observation. A durably detected,
|
|
19
|
+
* unresolved preparation (`preparing`, an advisory reader field) earns at most
|
|
20
|
+
* `PREPARATION_OBSERVATION_LIMIT` fast observations per correlation. The
|
|
21
|
+
* budget resets only when a different correlation appears, so a stalled
|
|
22
|
+
* preparation returns to the idle cadence for good. Readers that omit the
|
|
23
|
+
* field keep the ordinary cadence.
|
|
24
|
+
*/
|
|
25
|
+
export function supervisionCadence() {
|
|
26
|
+
let correlation: string | undefined
|
|
27
|
+
let observed = 0
|
|
28
|
+
return (projection: { preparing?: string }, pending: boolean): number => {
|
|
29
|
+
if (pending) return SUPERVISION_PENDING_MS
|
|
30
|
+
const preparing = projection.preparing
|
|
31
|
+
if (typeof preparing !== 'string') return SUPERVISION_IDLE_MS
|
|
32
|
+
if (preparing !== correlation) {
|
|
33
|
+
correlation = preparing
|
|
34
|
+
observed = 0
|
|
35
|
+
}
|
|
36
|
+
if (observed >= PREPARATION_OBSERVATION_LIMIT) return SUPERVISION_IDLE_MS
|
|
37
|
+
observed++
|
|
38
|
+
return PREPARATION_OBSERVATION_MS
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface PauseTimers {
|
|
43
|
+
setTimeout(callback: () => void, ms: number): unknown
|
|
44
|
+
clearTimeout(timer: unknown): void
|
|
45
|
+
}
|
|
46
|
+
const realTimers: PauseTimers = {
|
|
47
|
+
setTimeout: (callback, ms) => setTimeout(callback, ms),
|
|
48
|
+
clearTimeout: (timer) => clearTimeout(timer as ReturnType<typeof setTimeout>),
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Waits `delay` ms, or until any wakeup settles, or until `signal` aborts
|
|
53
|
+
* (immediately when it already has). The timer and abort listener are always
|
|
54
|
+
* released.
|
|
55
|
+
*/
|
|
56
|
+
export async function supervisionPause(
|
|
57
|
+
delay: number,
|
|
58
|
+
wakeups: Promise<unknown>[],
|
|
59
|
+
signal: Pick<AbortSignal, 'aborted' | 'addEventListener' | 'removeEventListener'>,
|
|
60
|
+
timers: PauseTimers = realTimers,
|
|
61
|
+
): Promise<void> {
|
|
62
|
+
if (signal.aborted) return
|
|
63
|
+
let timer: unknown
|
|
64
|
+
let onAbort: (() => void) | undefined
|
|
65
|
+
try {
|
|
66
|
+
await Promise.race([
|
|
67
|
+
new Promise<void>((resolve) => {
|
|
68
|
+
timer = timers.setTimeout(resolve, delay)
|
|
69
|
+
}),
|
|
70
|
+
new Promise<void>((resolve) => {
|
|
71
|
+
onAbort = resolve
|
|
72
|
+
signal.addEventListener('abort', onAbort)
|
|
73
|
+
}),
|
|
74
|
+
...wakeups,
|
|
75
|
+
])
|
|
76
|
+
} finally {
|
|
77
|
+
timers.clearTimeout(timer)
|
|
78
|
+
if (onAbort) signal.removeEventListener('abort', onAbort)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
restoreLauncherTerminal,
|
|
15
15
|
} from './dispatch-launch-stop'
|
|
16
16
|
import { watchPresentationJob } from './dispatch-presentation-job'
|
|
17
|
+
import { supervisionCadence, supervisionPause } from './dispatch-launcher-cadence'
|
|
17
18
|
import { dirname, basename, resolve, join } from 'node:path'
|
|
18
19
|
import { randomUUID } from 'node:crypto'
|
|
19
20
|
import { distributionRoot } from '../distribution'
|
|
@@ -334,6 +335,7 @@ export async function launchDispatcher(launchArgv: string[]): Promise<number> {
|
|
|
334
335
|
bootstrap.rollbackVersion === 1,
|
|
335
336
|
)
|
|
336
337
|
const readerFailures = generationReaderFailures((message) => console.error(message))
|
|
338
|
+
const cadence = supervisionCadence()
|
|
337
339
|
for (;;) {
|
|
338
340
|
if (signal) break
|
|
339
341
|
// Once recovery has expired, a failed child must retain its ordinary
|
|
@@ -361,6 +363,7 @@ export async function launchDispatcher(launchArgv: string[]): Promise<number> {
|
|
|
361
363
|
successor?: string
|
|
362
364
|
accepted?: boolean
|
|
363
365
|
released?: boolean
|
|
366
|
+
preparing?: string
|
|
364
367
|
}
|
|
365
368
|
try {
|
|
366
369
|
projection = await upgradeReader(active)
|
|
@@ -571,18 +574,14 @@ export async function launchDispatcher(launchArgv: string[]): Promise<number> {
|
|
|
571
574
|
if (record !== active && record !== pending?.record && record.result)
|
|
572
575
|
children.delete(record)
|
|
573
576
|
pruneRuntimes(dirname(dirname(runtime.root)))
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
new Promise<void>((resolve) => {
|
|
578
|
-
timer = setTimeout(resolve, pending ? 250 : 1_000)
|
|
579
|
-
}),
|
|
577
|
+
await supervisionPause(
|
|
578
|
+
cadence(projection, !!pending),
|
|
579
|
+
[
|
|
580
580
|
...(!active.result ? [active.exited] : []),
|
|
581
581
|
...(pending && !pending.record.result ? [pending.record.exited] : []),
|
|
582
|
-
]
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
}
|
|
582
|
+
],
|
|
583
|
+
stopping.signal,
|
|
584
|
+
)
|
|
586
585
|
}
|
|
587
586
|
} catch (error) {
|
|
588
587
|
if (!signal) throw error
|
|
@@ -210,10 +210,19 @@ async function runGenerationPreflight(
|
|
|
210
210
|
prepared = true
|
|
211
211
|
// The successor claims with its own configured lease timeout.
|
|
212
212
|
let leaseTtlMs = 60_000
|
|
213
|
+
const { observeSuccessorRelease, releaseObservationCadence } = await import(
|
|
214
|
+
'./dispatch-release-observer'
|
|
215
|
+
)
|
|
216
|
+
const { supervisionPause } = await import('./dispatch-launcher-cadence')
|
|
217
|
+
const cadence = releaseObservationCadence()
|
|
213
218
|
for (;;) {
|
|
214
219
|
signal.throwIfAborted()
|
|
215
|
-
const
|
|
216
|
-
const facts =
|
|
220
|
+
const started = performance.now()
|
|
221
|
+
const { current, facts } = await observeSuccessorRelease(
|
|
222
|
+
opened.store,
|
|
223
|
+
opened.repo,
|
|
224
|
+
handoff.run,
|
|
225
|
+
)
|
|
217
226
|
if (facts.stopRequest || current?.failure) return false
|
|
218
227
|
if (facts.stop && !current?.handoff) return false
|
|
219
228
|
if (
|
|
@@ -257,7 +266,7 @@ async function runGenerationPreflight(
|
|
|
257
266
|
})
|
|
258
267
|
return true
|
|
259
268
|
}
|
|
260
|
-
await
|
|
269
|
+
await supervisionPause(cadence(performance.now() - started), [], signal)
|
|
261
270
|
}
|
|
262
271
|
} finally {
|
|
263
272
|
await opened.store.close()
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { readDispatcherRunFacts, readDispatchUpgrade } from '../store/reduced-reads'
|
|
2
|
+
import type { BuildStore } from '../store/types'
|
|
3
|
+
|
|
4
|
+
/** Pause between the successor's post-yield observations during the fast
|
|
5
|
+
* window. Each observation is the two canonical reduced reads of
|
|
6
|
+
* `observeSuccessorRelease`, which read zero event rows while nothing changed,
|
|
7
|
+
* so a step costs the same at any journal length. */
|
|
8
|
+
export const RELEASE_OBSERVATION_FAST_MS = 25
|
|
9
|
+
|
|
10
|
+
/** Observations of one preflight that use the fast pause: at least six seconds
|
|
11
|
+
* of sleep, which covers a drain-mode release with wide margin. Later
|
|
12
|
+
* observations back off, so the fast observations per handoff are finite. */
|
|
13
|
+
export const RELEASE_OBSERVATION_FAST_LIMIT = 240
|
|
14
|
+
|
|
15
|
+
/** Steady pause after the backoff, for slow drains and for cutovers waiting on
|
|
16
|
+
* the predecessor's stop: two observations per second until takeover, stop,
|
|
17
|
+
* failure, abort or preflight's deadline. */
|
|
18
|
+
export const RELEASE_OBSERVATION_IDLE_MS = 500
|
|
19
|
+
|
|
20
|
+
/** Pause schedule of one preflight's release observation. Each call takes how
|
|
21
|
+
* long the last observation took and returns the next pause: the fast pause
|
|
22
|
+
* for the first `RELEASE_OBSERVATION_FAST_LIMIT` calls, then doubling to the
|
|
23
|
+
* idle pause and staying there. A pause is never shorter than the last
|
|
24
|
+
* observation, so a slow or struggling store is never queried back-to-back. */
|
|
25
|
+
export function releaseObservationCadence(): (lastObservationMs: number) => number {
|
|
26
|
+
let calls = 0
|
|
27
|
+
return (lastObservationMs) => {
|
|
28
|
+
calls++
|
|
29
|
+
const floor =
|
|
30
|
+
Number.isFinite(lastObservationMs) && lastObservationMs > 0 ? lastObservationMs : 0
|
|
31
|
+
const over = calls - RELEASE_OBSERVATION_FAST_LIMIT
|
|
32
|
+
const scheduled =
|
|
33
|
+
over <= 0
|
|
34
|
+
? RELEASE_OBSERVATION_FAST_MS
|
|
35
|
+
: RELEASE_OBSERVATION_FAST_MS * 2 ** over >= RELEASE_OBSERVATION_IDLE_MS
|
|
36
|
+
? RELEASE_OBSERVATION_IDLE_MS
|
|
37
|
+
: RELEASE_OBSERVATION_FAST_MS * 2 ** over
|
|
38
|
+
return Math.max(scheduled, floor)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** One observation step: the predecessor run's durable upgrade state, then its
|
|
43
|
+
* run facts, in that order. Exactly these reduced reads, no event rows while
|
|
44
|
+
* nothing changed. The caller validates every fact itself. */
|
|
45
|
+
export async function observeSuccessorRelease(
|
|
46
|
+
store: Pick<BuildStore, 'getReducerValue'>,
|
|
47
|
+
repo: string,
|
|
48
|
+
run: string,
|
|
49
|
+
) {
|
|
50
|
+
const current = (await readDispatchUpgrade(store, repo)).value.runs[run]
|
|
51
|
+
const facts = (await readDispatcherRunFacts(store, repo, run)).value
|
|
52
|
+
return { current, facts }
|
|
53
|
+
}
|