@defrex/autobuild 1.6.0 → 1.8.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 +423 -57
- package/docs/agent-runtimes.md +1 -1
- package/docs/answering-blocked-builds.md +44 -3
- package/docs/architecture.md +124 -29
- package/docs/cli.md +1 -0
- package/docs/configuration-overview.md +11 -1
- package/docs/configuration.md +334 -14
- package/docs/dispatcher.md +1 -1
- package/docs/forges.md +1 -0
- package/docs/integration-overview.md +2 -2
- package/docs/integration-tree.md +7 -4
- package/docs/merge-policy.md +78 -6
- package/docs/migration-1.0.md +4 -2
- package/docs/operating.md +3 -2
- package/docs/operator-api.md +45 -13
- package/docs/operator-surfaces.md +16 -3
- package/docs/plugin-authoring.md +45 -7
- package/docs/remote-store-protocol.md +28 -7
- package/docs/restacking.md +35 -11
- package/docs/ticket-dependencies.md +9 -4
- package/docs/ticket-sources.md +34 -6
- package/docs/tickets.md +7 -1
- package/docs/troubleshooting.md +1 -1
- package/docs/workspaces.md +1 -1
- package/package.json +3 -3
- package/packages/core/src/cli/attention.ts +2 -0
- package/packages/core/src/cli/binary-direct.ts +1 -0
- package/packages/core/src/cli/build-control.ts +65 -7
- package/packages/core/src/cli/context.ts +55 -14
- package/packages/core/src/cli/dashboard/actions.ts +13 -4
- package/packages/core/src/cli/dashboard/landing-display.ts +32 -8
- package/packages/core/src/cli/dashboard/model.ts +61 -8
- package/packages/core/src/cli/dashboard/render.ts +28 -3
- package/packages/core/src/cli/dashboard/tree.ts +9 -1
- package/packages/core/src/cli/dispatch-frontend.ts +10 -14
- package/packages/core/src/cli/dispatch-preflight.ts +1 -0
- package/packages/core/src/cli/dispatch-repository-feed.ts +145 -109
- package/packages/core/src/cli/dispatch.ts +9 -3
- package/packages/core/src/cli/help.ts +80 -11
- package/packages/core/src/cli/init-validation.ts +14 -1
- package/packages/core/src/cli/landings.ts +1 -1
- package/packages/core/src/cli/main.ts +60 -9
- package/packages/core/src/cli/publication-settlement.ts +10 -0
- package/packages/core/src/cli/repository-status.ts +37 -2
- package/packages/core/src/cli/status.ts +186 -12
- package/packages/core/src/cli/terminals.ts +197 -4
- package/packages/core/src/cli/ticket.ts +22 -4
- package/packages/core/src/cli/wait.ts +1 -0
- package/packages/core/src/cli/watch.ts +73 -0
- package/packages/core/src/config/landing.ts +12 -0
- package/packages/core/src/config/live.ts +4 -0
- package/packages/core/src/config/path-selectors.ts +68 -0
- package/packages/core/src/config/profiles.ts +96 -0
- package/packages/core/src/config/ready-assignee.ts +43 -11
- package/packages/core/src/config/roles.ts +33 -10
- package/packages/core/src/config/schema.ts +205 -81
- package/packages/core/src/events/catalog.ts +17 -3
- package/packages/core/src/events/compatibility.ts +4 -1
- package/packages/core/src/events/forge-degradation-policy.ts +16 -2
- package/packages/core/src/events/head-paths-limits.ts +25 -0
- package/packages/core/src/events/payloads.ts +323 -20
- package/packages/core/src/events/policy.ts +22 -0
- package/packages/core/src/events/repository.ts +47 -1
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +320 -130
- package/packages/core/src/kernel/build-creation.ts +29 -0
- package/packages/core/src/kernel/consent-revocation.ts +72 -0
- package/packages/core/src/kernel/dispatch-capacity.ts +19 -8
- package/packages/core/src/kernel/engine.ts +48 -8
- package/packages/core/src/kernel/forge-health.ts +47 -0
- package/packages/core/src/kernel/guarded-forge.ts +76 -18
- package/packages/core/src/kernel/head-paths-state.ts +63 -0
- package/packages/core/src/kernel/head-paths.ts +401 -0
- package/packages/core/src/kernel/landing-policy-identity.ts +20 -0
- package/packages/core/src/kernel/landing-policy.ts +55 -2
- package/packages/core/src/kernel/landing-readiness.ts +104 -9
- package/packages/core/src/kernel/landing-state.ts +44 -4
- package/packages/core/src/kernel/leaf-restack-state.ts +50 -2
- package/packages/core/src/kernel/log-index.ts +27 -1
- package/packages/core/src/kernel/node-parent.ts +2 -0
- package/packages/core/src/kernel/node-polling.ts +13 -3
- package/packages/core/src/kernel/node-restack-state.ts +8 -1
- package/packages/core/src/kernel/node-restack-transaction.ts +45 -0
- package/packages/core/src/kernel/read-deferrals.ts +3 -1
- package/packages/core/src/kernel/read-facts.ts +37 -2
- package/packages/core/src/kernel/reducer-registry.ts +22 -1
- package/packages/core/src/kernel/reducer.ts +332 -16
- package/packages/core/src/kernel/target-observation.ts +2 -5
- package/packages/core/src/kernel/terminal-guard.ts +52 -3
- package/packages/core/src/kernel/ticket-handbacks.ts +40 -0
- package/packages/core/src/kernel/ticket-preparation.ts +15 -1
- package/packages/core/src/kernel/ticket-wait.ts +345 -0
- package/packages/core/src/kernel/verify-applicability.ts +9 -19
- package/packages/core/src/ontology.ts +1 -0
- package/packages/core/src/operator/annotations.ts +6 -0
- package/packages/core/src/operator/index.ts +3 -0
- package/packages/core/src/operator/protocol.ts +25 -2
- package/packages/core/src/operator/query.ts +1 -1
- package/packages/core/src/operator/registry.ts +122 -10
- package/packages/core/src/operator/repository-events.ts +67 -0
- package/packages/core/src/operator/sandbox-host.ts +3 -0
- package/packages/core/src/operator/tickets.ts +15 -3
- package/packages/core/src/plugin-sdk/index.ts +4 -0
- package/packages/core/src/ports/forge/create.ts +6 -0
- package/packages/core/src/ports/forge/github-transport.ts +40 -3
- package/packages/core/src/ports/forge/github.ts +12 -1
- package/packages/core/src/ports/forge/workspace-ancestry.ts +60 -0
- package/packages/core/src/ports/forge-failure.ts +31 -2
- package/packages/core/src/ports/runner/routing.ts +66 -5
- package/packages/core/src/ports/tickets/assignees.ts +54 -0
- package/packages/core/src/ports/tickets/contract.ts +164 -4
- package/packages/core/src/ports/tickets/create.ts +17 -3
- package/packages/core/src/ports/tickets/fake.ts +5 -0
- package/packages/core/src/ports/tickets/github-fake.ts +18 -2
- package/packages/core/src/ports/tickets/github.ts +247 -29
- package/packages/core/src/ports/tickets/hosted-index.ts +1 -0
- package/packages/core/src/ports/tickets/operations.ts +6 -1
- package/packages/core/src/ports/tickets/tree.ts +12 -2
- package/packages/core/src/ports/tickets/update.ts +6 -2
- package/packages/core/src/ports/types.ts +36 -5
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +9 -0
- package/packages/core/src/processes/build-child.ts +28 -7
- package/packages/core/src/processes/build-execution-state.ts +34 -2
- package/packages/core/src/processes/build-runner.ts +165 -19
- package/packages/core/src/processes/dispatcher.ts +837 -115
- package/packages/core/src/processes/execution-no-progress.ts +22 -2
- package/packages/core/src/processes/harvest-child.ts +4 -0
- package/packages/core/src/processes/harvest-runner.ts +5 -0
- package/packages/core/src/processes/phase-failure-budget.ts +1 -0
- package/packages/core/src/processes/publication-state.ts +6 -1
- package/packages/core/src/processes/repo-view.ts +2 -0
- package/packages/core/src/scenarios/harness.ts +15 -1
- package/packages/core/src/store/digest.ts +41 -2
- package/packages/core/src/store/reduced-reads.ts +4 -1
- package/packages/core/src/store/reducer-value-shapes.json +10310 -8441
- package/packages/core/src/store/remote/client.ts +49 -10
- package/packages/core/src/store/remote/index.ts +4 -0
- package/packages/core/src/store/remote/protocol.ts +18 -1
- package/packages/core/src/store/remote/released-clients.json +22 -0
- package/packages/core/src/store/remote/released-reducer-values/1.7.0.json +27366 -0
- package/packages/core/src/store/remote/released-reducer-values/1.8.0.json +29043 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +4 -0
- package/packages/core/src/store/repo-state-events.ts +3 -0
- package/packages/core/src/store/types.ts +27 -0
- package/packages/core/src/testing/dispatch-read-budget.ts +84 -58
- package/packages/core/src/testing/index.ts +2 -0
- package/packages/core/src/testing/reduced-read-budget.ts +419 -9
- package/skills/code-review/SKILL.md +8 -0
- package/skills/finalize/SKILL.md +4 -0
- package/skills/guide/SKILL.md +241 -47
- package/skills/guide/references/integration-tree.md +7 -4
- package/skills/guide/references/merge-policy.md +78 -6
- package/skills/guide/references/migration-1.0.md +4 -2
- package/skills/guide/references/operator-api.md +45 -13
- package/skills/guide/references/plugin-authoring.md +45 -7
- package/skills/guide/references/remote-store-protocol.md +28 -7
- package/skills/guide/references/restacking.md +35 -11
- package/skills/guide/references/ticket-dependencies.md +9 -4
- package/skills/implement/SKILL.md +15 -1
- package/skills/operate/SKILL.md +133 -16
- package/skills/plan/SKILL.md +17 -2
- package/skills/plan-review/SKILL.md +8 -0
- package/skills/reconcile/SKILL.md +21 -5
- package/skills/tickets/SKILL.md +23 -6
- package/templates/hosted-service/package.json +2 -2
|
@@ -284,6 +284,7 @@ const STATUS_COLOR: Record<DashboardBuild['status'] | DashboardHarvest['status']
|
|
|
284
284
|
suspended: 'yellow',
|
|
285
285
|
resuming: 'cyan',
|
|
286
286
|
blocked: 'red',
|
|
287
|
+
waiting: 'yellow',
|
|
287
288
|
aborting: 'red',
|
|
288
289
|
cleaning: 'yellow',
|
|
289
290
|
escalated: 'yellow',
|
|
@@ -474,6 +475,11 @@ function renderBuild(
|
|
|
474
475
|
if (build.alert)
|
|
475
476
|
for (const line of wrappedText(build.alert.text, Math.max(1, width - 4), ''))
|
|
476
477
|
lines.push(paint(` ! ${line}`, build.alert.tone, color))
|
|
478
|
+
// A ticket wait is held work, not a blocker: one yellow line naming the
|
|
479
|
+
// tickets, never a red question preview.
|
|
480
|
+
if (build.wait)
|
|
481
|
+
for (const line of wrappedText(build.wait.text, Math.max(1, width - 4), ''))
|
|
482
|
+
lines.push(paint(` ! ${line}`, 'yellow', color))
|
|
477
483
|
// Setup failures and blocker questions are dense-list previews. Their model
|
|
478
484
|
// strings remain untouched; newline-aware wrapping and capping happen only
|
|
479
485
|
// at this presentation seam.
|
|
@@ -894,6 +900,19 @@ function detailBody(
|
|
|
894
900
|
body.push(...wrappedText(note, width, ' ').map((line) => paint(line, 'dim', color)))
|
|
895
901
|
}
|
|
896
902
|
}
|
|
903
|
+
if (build.wait !== undefined) {
|
|
904
|
+
body.push('', paint('Waiting', 'bold', color))
|
|
905
|
+
body.push(
|
|
906
|
+
...wrapDisplay(build.wait.text, width, ' ').map((line) => paint(line, 'yellow', color)),
|
|
907
|
+
)
|
|
908
|
+
body.push(...wrappedText(`since ${build.wait.since}`, width, ' '))
|
|
909
|
+
for (const note of [
|
|
910
|
+
'r answers the wait and ends it early',
|
|
911
|
+
`CLI only: ab answer ${build.slug} [text]`,
|
|
912
|
+
]) {
|
|
913
|
+
body.push(...wrappedText(note, width, ' ').map((line) => paint(line, 'dim', color)))
|
|
914
|
+
}
|
|
915
|
+
}
|
|
897
916
|
body.push('', paint('Sessions', 'bold', color))
|
|
898
917
|
const sessions = build.sessions ?? []
|
|
899
918
|
let sessionFocus: number | undefined
|
|
@@ -1453,7 +1472,13 @@ export function resumePanel(
|
|
|
1453
1472
|
// frame did not grant — which is what makes every `fieldWidth` below at
|
|
1454
1473
|
// least 1 without a clamp.
|
|
1455
1474
|
if (width <= 0) return []
|
|
1456
|
-
const
|
|
1475
|
+
const build = model.builds.find((candidate) => candidate.slug === prompt.slug)
|
|
1476
|
+
// Answering a waiting build answers its wait's question, shown in the wait's
|
|
1477
|
+
// yellow beside any red blockers.
|
|
1478
|
+
const questions: Array<{ text: string; tone: 'red' | 'yellow' }> = [
|
|
1479
|
+
...(build?.blockers ?? []).map((text) => ({ text, tone: 'red' as const })),
|
|
1480
|
+
...(build?.wait ? [{ text: build.wait.question, tone: 'yellow' as const }] : []),
|
|
1481
|
+
]
|
|
1457
1482
|
|
|
1458
1483
|
const title = truncate(
|
|
1459
1484
|
paint(paint(`Resume ${displayText(prompt.slug)}`, 'cyan', color), 'bold', color),
|
|
@@ -1467,10 +1492,10 @@ export function resumePanel(
|
|
|
1467
1492
|
// notice accounts for.
|
|
1468
1493
|
const questionRows: string[] = []
|
|
1469
1494
|
for (const question of questions) {
|
|
1470
|
-
const wrapped = wrapDisplay(question, width - 4)
|
|
1495
|
+
const wrapped = wrapDisplay(question.text, width - 4)
|
|
1471
1496
|
for (const [index, line] of wrapped.entries()) {
|
|
1472
1497
|
questionRows.push(
|
|
1473
|
-
truncate(paint(`${index === 0 ? ' ! ' : ' '}${line}`,
|
|
1498
|
+
truncate(paint(`${index === 0 ? ' ! ' : ' '}${line}`, question.tone, color), width),
|
|
1474
1499
|
)
|
|
1475
1500
|
}
|
|
1476
1501
|
}
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
integrationCycleVerified,
|
|
8
8
|
} from '../../kernel/integration-state'
|
|
9
9
|
import { mergeVocabulary } from './landing-display'
|
|
10
|
-
import { awaitsConsent, landingReady } from '../../kernel/landing-readiness'
|
|
10
|
+
import { awaitsConsent, currentCandidateHead, landingReady } from '../../kernel/landing-readiness'
|
|
11
11
|
|
|
12
12
|
export const treeVocabulary = {
|
|
13
13
|
root: 'root',
|
|
@@ -17,6 +17,8 @@ export const treeVocabulary = {
|
|
|
17
17
|
landing: mergeVocabulary.label,
|
|
18
18
|
restack: 'restack',
|
|
19
19
|
consent: 'consent',
|
|
20
|
+
head: 'head',
|
|
21
|
+
consentedAt: 'consented at',
|
|
20
22
|
queue: 'queue',
|
|
21
23
|
work: 'work',
|
|
22
24
|
integrationKind: 'integration',
|
|
@@ -90,6 +92,12 @@ export function projectTree(
|
|
|
90
92
|
: {}),
|
|
91
93
|
ready: landingReady(state, restack),
|
|
92
94
|
consent: awaitsConsent(state, restack),
|
|
95
|
+
/** The live candidate head: what `ab merge --head` must name. */
|
|
96
|
+
currentHead: currentCandidateHead(state) ?? null,
|
|
97
|
+
/** The candidate head consent was given at while merge consent is
|
|
98
|
+
* recorded; null without consent and for legacy consent. */
|
|
99
|
+
consentedHead:
|
|
100
|
+
state.landing?.command?.kind === 'land' ? (state.landing.command.head ?? null) : null,
|
|
93
101
|
reason: awaitsConsent(state, restack)
|
|
94
102
|
? state.landing?.command?.kind === 'hold'
|
|
95
103
|
? ('held' as const)
|
|
@@ -23,7 +23,6 @@ import { DispatchRepositoryFeed } from './dispatch-repository-feed'
|
|
|
23
23
|
import { StandbyIdentityResolver } from './dispatcher-liveness'
|
|
24
24
|
import { configSchema, type Config } from '../config/schema'
|
|
25
25
|
import { humanActor } from '../events/envelope'
|
|
26
|
-
import type { RepositoryEvent } from '../events/repository'
|
|
27
26
|
import { reduceDispatchStatus, type DispatchStatus } from '../kernel/dispatch-status'
|
|
28
27
|
import type { BuildState } from '../kernel/reducer'
|
|
29
28
|
import {
|
|
@@ -210,9 +209,9 @@ export class DispatchFrontend {
|
|
|
210
209
|
|
|
211
210
|
/** Advance the repository cursor exactly once even when polling overlaps an
|
|
212
211
|
* operator action. High-frequency dispatcher status is folded from deltas;
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
private async
|
|
212
|
+
* the feed retains standby identities only, and dashboard facts come from
|
|
213
|
+
* the canonical repository facts. */
|
|
214
|
+
private async advanceRepository(sampledPosition?: string): Promise<void> {
|
|
216
215
|
if (this.opts.viewer) {
|
|
217
216
|
const position = sampledPosition ?? (await this.reader.getRepoChangePosition(this.opts.repo))
|
|
218
217
|
if (
|
|
@@ -224,7 +223,7 @@ export class DispatchFrontend {
|
|
|
224
223
|
this.viewerReadAt = this.clock().getTime()
|
|
225
224
|
}
|
|
226
225
|
this.dispatchStatus = this.viewerFacts!.status ?? reduceDispatchStatus([], this.runId)
|
|
227
|
-
return
|
|
226
|
+
return
|
|
228
227
|
}
|
|
229
228
|
const refresh = this.eventRefreshTail.then(async () => {
|
|
230
229
|
const delta = await this.repositoryFeed.refresh(false)
|
|
@@ -234,7 +233,6 @@ export class DispatchFrontend {
|
|
|
234
233
|
})
|
|
235
234
|
this.eventRefreshTail = refresh.catch(() => {})
|
|
236
235
|
await refresh
|
|
237
|
-
return this.repositoryFeed.events
|
|
238
236
|
}
|
|
239
237
|
|
|
240
238
|
private async report(message: string, level: 'info' | 'warning' = 'info'): Promise<void> {
|
|
@@ -367,7 +365,6 @@ export class DispatchFrontend {
|
|
|
367
365
|
}
|
|
368
366
|
|
|
369
367
|
private readonly repositoryPoll = new RepositoryPollCache<{
|
|
370
|
-
repositoryEvents: RepositoryEvent[]
|
|
371
368
|
upgrades: DispatchUpgradeState
|
|
372
369
|
repositoryFacts: RepositoryReadFacts
|
|
373
370
|
status: DispatchStatus
|
|
@@ -424,7 +421,7 @@ export class DispatchFrontend {
|
|
|
424
421
|
admitted: () => this.refresh === undefined || this.refresh.admitted,
|
|
425
422
|
nextPollMs: this.refresh?.intervalMs ?? 0,
|
|
426
423
|
read: async ({ fullEnrichment }) => {
|
|
427
|
-
|
|
424
|
+
await this.advanceRepository(sampledPosition)
|
|
428
425
|
// Authority and rollback holds need the full durable reduction, not the
|
|
429
426
|
// low-volume replay feed (which deliberately discards per-tick facts).
|
|
430
427
|
const repositoryFacts =
|
|
@@ -433,7 +430,7 @@ export class DispatchFrontend {
|
|
|
433
430
|
await readRepositoryFacts(
|
|
434
431
|
this.reader,
|
|
435
432
|
this.opts.repo,
|
|
436
|
-
|
|
433
|
+
this.repositoryFeed.present ? true : undefined,
|
|
437
434
|
)
|
|
438
435
|
).value
|
|
439
436
|
const upgrades = repositoryFacts.upgrades
|
|
@@ -465,7 +462,6 @@ export class DispatchFrontend {
|
|
|
465
462
|
if (!this.opts.viewer) await this.repositoryFeed.save()
|
|
466
463
|
if (!this.cache.isCurrent(snapshot)) return undefined
|
|
467
464
|
return {
|
|
468
|
-
repositoryEvents,
|
|
469
465
|
repositoryFacts,
|
|
470
466
|
upgrades,
|
|
471
467
|
status,
|
|
@@ -475,7 +471,7 @@ export class DispatchFrontend {
|
|
|
475
471
|
},
|
|
476
472
|
})
|
|
477
473
|
if (frame === undefined) return
|
|
478
|
-
let {
|
|
474
|
+
let { repositoryFacts, upgrades, status } = frame
|
|
479
475
|
const { config, snapshot } = frame
|
|
480
476
|
this.pollViewerTriage(config)
|
|
481
477
|
const standby =
|
|
@@ -495,12 +491,12 @@ export class DispatchFrontend {
|
|
|
495
491
|
const slug = this.abortConfirmation.slug
|
|
496
492
|
if (!validAbortConfirmation(snapshot.states.get(slug))) {
|
|
497
493
|
await this.dismissStaleAbortConfirmation(slug)
|
|
498
|
-
|
|
494
|
+
await this.advanceRepository()
|
|
499
495
|
repositoryFacts = (
|
|
500
496
|
await readRepositoryFacts(
|
|
501
497
|
this.reader,
|
|
502
498
|
this.opts.repo,
|
|
503
|
-
|
|
499
|
+
this.repositoryFeed.present ? true : undefined,
|
|
504
500
|
)
|
|
505
501
|
).value
|
|
506
502
|
upgrades = repositoryFacts.upgrades
|
|
@@ -809,7 +805,7 @@ export class DispatchFrontend {
|
|
|
809
805
|
}
|
|
810
806
|
|
|
811
807
|
private async confirmAbort(slug: string): Promise<void> {
|
|
812
|
-
await this.
|
|
808
|
+
await this.advanceRepository()
|
|
813
809
|
const ref = this.dispatchStatus.effectiveConfig
|
|
814
810
|
if (ref === undefined) throw new Error('effective config is not available')
|
|
815
811
|
const config = await this.loadConfig(ref.kind, ref.rev)
|
|
@@ -179,6 +179,7 @@ async function runGenerationPreflight(
|
|
|
179
179
|
config.roles,
|
|
180
180
|
config.policy.sessionBudgetSeconds,
|
|
181
181
|
config.accounts,
|
|
182
|
+
config.profiles,
|
|
182
183
|
)
|
|
183
184
|
const facts = (await readDispatcherRunFacts(opened.store, opened.repo, handoff.run)).value
|
|
184
185
|
const start = facts.start
|
|
@@ -8,7 +8,9 @@ import type { BuildStore, Clock } from '../store/types'
|
|
|
8
8
|
|
|
9
9
|
const handoffTypes = new Set<string>(DISPATCH_HANDOFF_EVENT_TYPES)
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
/** Dashboard-class facts a version-4 checkpoint cached; only legacy restore
|
|
12
|
+
* validation still recognizes them. */
|
|
13
|
+
function isLegacyDashboardEvent(event: RepositoryEvent): boolean {
|
|
12
14
|
return (
|
|
13
15
|
handoffTypes.has(event.type) ||
|
|
14
16
|
event.type.startsWith('harvest.') ||
|
|
@@ -19,37 +21,36 @@ export function isDashboardRepositoryEvent(event: RepositoryEvent): boolean {
|
|
|
19
21
|
)
|
|
20
22
|
}
|
|
21
23
|
|
|
24
|
+
/** The version-4 checkpoint shape, normalized once on restore. */
|
|
25
|
+
const LEGACY_VERSION = 4
|
|
26
|
+
|
|
22
27
|
export const dispatchFrontendReducer = defineReducer({
|
|
23
|
-
version:
|
|
24
|
-
initial: (): {
|
|
25
|
-
retained: [],
|
|
26
|
-
incompleteIdentities: true,
|
|
27
|
-
}),
|
|
28
|
+
version: 5,
|
|
29
|
+
initial: (): { identities: RepositoryEvent[]; holder?: string } => ({ identities: [] }),
|
|
28
30
|
fold(acc, events: readonly RepositoryEvent[]) {
|
|
29
|
-
const
|
|
31
|
+
const starts = new Map(acc.identities.map((event) => [event.seq, event]))
|
|
30
32
|
for (const event of events) {
|
|
31
|
-
if (
|
|
32
|
-
facts.set(event.seq, event)
|
|
33
|
+
if (event.type === 'dispatcher.run-started') starts.set(event.seq, event)
|
|
33
34
|
}
|
|
34
|
-
const sorted = [...
|
|
35
|
-
const latest = sorted.
|
|
35
|
+
const sorted = [...starts.values()].sort((a, b) => a.seq - b.seq)
|
|
36
|
+
const latest = sorted.at(-1)
|
|
36
37
|
const holder = sorted.findLast(
|
|
37
38
|
(event) => event.type === 'dispatcher.run-started' && event.payload.run === acc.holder,
|
|
38
39
|
)
|
|
39
|
-
acc.
|
|
40
|
-
(event) => event.type !== 'dispatcher.run-started' || event === latest || event === holder,
|
|
41
|
-
)
|
|
42
|
-
acc.incompleteIdentities = true
|
|
40
|
+
acc.identities = sorted.filter((event) => event === latest || event === holder)
|
|
43
41
|
},
|
|
44
|
-
finish: (acc) => acc.
|
|
42
|
+
finish: (acc) => acc.identities,
|
|
45
43
|
})
|
|
46
44
|
|
|
45
|
+
type FrontendState = { identities: RepositoryEvent[]; holder?: string }
|
|
46
|
+
|
|
47
47
|
/** One serialized, frontend-only repository projection. The consumed cursor is
|
|
48
48
|
* independent of retained facts: quiet ticks must never survive in the cache.
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* startup and cursor-expiry recovery seed
|
|
52
|
-
* `repositoryReadFacts` value, never from the
|
|
49
|
+
* The checkpoint holds standby identities only (the latest run start and the
|
|
50
|
+
* selected holder's start); presentation reads canonical repository facts.
|
|
51
|
+
* Without a usable checkpoint, startup and cursor-expiry recovery seed
|
|
52
|
+
* identities from the canonical `repositoryReadFacts` value, never from the
|
|
53
|
+
* journal. */
|
|
53
54
|
export class DispatchRepositoryFeed {
|
|
54
55
|
private cursor = 0
|
|
55
56
|
private ready = false
|
|
@@ -71,11 +72,13 @@ export class DispatchRepositoryFeed {
|
|
|
71
72
|
private readonly clock: Clock,
|
|
72
73
|
) {}
|
|
73
74
|
|
|
74
|
-
get events(): RepositoryEvent[] {
|
|
75
|
-
return this.retained.filter(isDashboardRepositoryEvent)
|
|
76
|
-
}
|
|
77
75
|
get identities(): RepositoryEvent[] {
|
|
78
|
-
return this.retained
|
|
76
|
+
return this.retained
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** A consumed nonzero cursor proves the repository journal exists. */
|
|
80
|
+
get present(): boolean {
|
|
81
|
+
return this.cursor > 0
|
|
79
82
|
}
|
|
80
83
|
|
|
81
84
|
private validate(events: RepositoryEvent[], cursor: number, contiguous: boolean): void {
|
|
@@ -108,15 +111,103 @@ export class DispatchRepositoryFeed {
|
|
|
108
111
|
}
|
|
109
112
|
}
|
|
110
113
|
|
|
114
|
+
/** Validate a version-5 checkpoint; a re-fold that changes nothing is clean. */
|
|
115
|
+
private restoreCurrent(state: unknown, cursor: number): FrontendState & { clean: boolean } {
|
|
116
|
+
const current = state as FrontendState
|
|
117
|
+
if (!current || !Array.isArray(current.identities) || current.identities.length > 2)
|
|
118
|
+
throw new Error('invalid projection')
|
|
119
|
+
this.validate(current.identities, 0, false)
|
|
120
|
+
if (current.identities.some((e) => e.seq > cursor || e.type !== 'dispatcher.run-started'))
|
|
121
|
+
throw new Error('invalid identity')
|
|
122
|
+
if (current.holder !== undefined && typeof current.holder !== 'string')
|
|
123
|
+
throw new Error('invalid holder')
|
|
124
|
+
const identities = dispatchFrontendReducer.advance(
|
|
125
|
+
{ identities: current.identities, holder: current.holder },
|
|
126
|
+
[],
|
|
127
|
+
).identities
|
|
128
|
+
return {
|
|
129
|
+
identities,
|
|
130
|
+
holder: current.holder,
|
|
131
|
+
clean: identities.length === current.identities.length,
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Normalize a version-4 checkpoint: its dashboard-event cache is discarded
|
|
136
|
+
* and only the identities survive. Never clean, so the next save replaces it. */
|
|
137
|
+
private restoreLegacy(state: unknown, cursor: number): FrontendState {
|
|
138
|
+
const legacy = state as {
|
|
139
|
+
retained: RepositoryEvent[]
|
|
140
|
+
incompleteIdentities: boolean
|
|
141
|
+
holder?: string
|
|
142
|
+
}
|
|
143
|
+
if (
|
|
144
|
+
!legacy ||
|
|
145
|
+
!Array.isArray(legacy.retained) ||
|
|
146
|
+
typeof legacy.incompleteIdentities !== 'boolean'
|
|
147
|
+
)
|
|
148
|
+
throw new Error('invalid projection')
|
|
149
|
+
this.validate(legacy.retained, 0, false)
|
|
150
|
+
if (
|
|
151
|
+
legacy.retained.some(
|
|
152
|
+
(e) =>
|
|
153
|
+
e.seq > cursor || !(isLegacyDashboardEvent(e) || e.type === 'dispatcher.run-started'),
|
|
154
|
+
)
|
|
155
|
+
)
|
|
156
|
+
throw new Error('invalid retained fact')
|
|
157
|
+
if (legacy.holder !== undefined && typeof legacy.holder !== 'string')
|
|
158
|
+
throw new Error('invalid holder')
|
|
159
|
+
return {
|
|
160
|
+
identities: dispatchFrontendReducer.advance(
|
|
161
|
+
{ identities: [], holder: legacy.holder },
|
|
162
|
+
legacy.retained,
|
|
163
|
+
).identities,
|
|
164
|
+
holder: legacy.holder,
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** The current checkpoint, or else one read of a legacy version-4 row. */
|
|
169
|
+
private async restore(
|
|
170
|
+
high: number,
|
|
171
|
+
): Promise<(FrontendState & { cursor: number; clean: boolean }) | undefined> {
|
|
172
|
+
const scope = { kind: 'repo', repo: this.repo } as const
|
|
173
|
+
const usable = (cursor: number) => cursor <= high && high - cursor <= REPOSITORY_TAIL_WINDOW
|
|
174
|
+
const snapshot = await loadReducerSnapshot(
|
|
175
|
+
this.store,
|
|
176
|
+
scope,
|
|
177
|
+
'dispatchFrontend',
|
|
178
|
+
dispatchFrontendReducer,
|
|
179
|
+
)
|
|
180
|
+
if (snapshot) {
|
|
181
|
+
if (!usable(snapshot.cursor)) return undefined
|
|
182
|
+
try {
|
|
183
|
+
return { ...this.restoreCurrent(snapshot.state, snapshot.cursor), cursor: snapshot.cursor }
|
|
184
|
+
} catch {
|
|
185
|
+
return undefined
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
const legacy = await loadReducerSnapshot(this.store, scope, 'dispatchFrontend', {
|
|
189
|
+
version: LEGACY_VERSION,
|
|
190
|
+
})
|
|
191
|
+
if (!legacy || !usable(legacy.cursor)) return undefined
|
|
192
|
+
try {
|
|
193
|
+
return {
|
|
194
|
+
...this.restoreLegacy(legacy.state, legacy.cursor),
|
|
195
|
+
cursor: legacy.cursor,
|
|
196
|
+
clean: false,
|
|
197
|
+
}
|
|
198
|
+
} catch {
|
|
199
|
+
return undefined
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
111
203
|
refresh(persist = true): Promise<RepositoryEvent[]> {
|
|
112
204
|
let result: RepositoryEvent[] = []
|
|
113
205
|
const next = this.tail.then(async () => {
|
|
114
206
|
let holder = this.holder
|
|
115
207
|
let cursor = this.cursor
|
|
116
|
-
let
|
|
117
|
-
let incompleteIdentities = this.incompleteIdentities
|
|
208
|
+
let identities = this.retained
|
|
118
209
|
let restoredKey: string | undefined
|
|
119
|
-
let
|
|
210
|
+
let restoredIdentities: RepositoryEvent[] | undefined
|
|
120
211
|
let delta: RepositoryEvent[]
|
|
121
212
|
if (!this.ready) {
|
|
122
213
|
if ((await this.store.getRepo(this.repo)) === null) {
|
|
@@ -125,54 +216,19 @@ export class DispatchRepositoryFeed {
|
|
|
125
216
|
return
|
|
126
217
|
}
|
|
127
218
|
const high = await this.store.getRepoHighWater(this.repo)
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
snapshot.cursor <= high &&
|
|
138
|
-
high - snapshot.cursor <= REPOSITORY_TAIL_WINDOW
|
|
139
|
-
) {
|
|
140
|
-
try {
|
|
141
|
-
const state = snapshot.state as {
|
|
142
|
-
retained: RepositoryEvent[]
|
|
143
|
-
incompleteIdentities: boolean
|
|
144
|
-
holder?: string
|
|
145
|
-
}
|
|
146
|
-
if (!Array.isArray(state.retained) || typeof state.incompleteIdentities !== 'boolean')
|
|
147
|
-
throw new Error('invalid projection')
|
|
148
|
-
this.validate(state.retained, 0, false)
|
|
149
|
-
if (
|
|
150
|
-
state.retained.some(
|
|
151
|
-
(e) =>
|
|
152
|
-
e.seq > snapshot.cursor ||
|
|
153
|
-
!(isDashboardRepositoryEvent(e) || e.type === 'dispatcher.run-started'),
|
|
154
|
-
)
|
|
155
|
-
)
|
|
156
|
-
throw new Error('invalid retained fact')
|
|
157
|
-
if (state.holder !== undefined && typeof state.holder !== 'string')
|
|
158
|
-
throw new Error('invalid holder')
|
|
159
|
-
holder = state.holder
|
|
160
|
-
retained = dispatchFrontendReducer.advance({ ...state }, []).retained
|
|
161
|
-
incompleteIdentities = true
|
|
162
|
-
if (state.incompleteIdentities && retained.length === state.retained.length) {
|
|
163
|
-
restoredKey = `${snapshot.cursor}:${this.generation}`
|
|
164
|
-
restoredRetained = retained
|
|
165
|
-
}
|
|
166
|
-
cursor = snapshot.cursor
|
|
167
|
-
restored = true
|
|
168
|
-
} catch {
|
|
169
|
-
/* A malformed cache uses the canonical seed. */
|
|
219
|
+
// A malformed, stale or missing cache uses the canonical seed.
|
|
220
|
+
const restored = await this.restore(high)
|
|
221
|
+
if (restored) {
|
|
222
|
+
holder = restored.holder
|
|
223
|
+
identities = restored.identities
|
|
224
|
+
cursor = restored.cursor
|
|
225
|
+
if (restored.clean) {
|
|
226
|
+
restoredKey = `${restored.cursor}:${this.generation}`
|
|
227
|
+
restoredIdentities = identities
|
|
170
228
|
}
|
|
171
|
-
}
|
|
172
|
-
if (!restored) {
|
|
229
|
+
} else {
|
|
173
230
|
const seed = await this.canonicalSeed(holder)
|
|
174
|
-
|
|
175
|
-
retained = seed.retained
|
|
231
|
+
identities = seed.identities
|
|
176
232
|
cursor = seed.cursor
|
|
177
233
|
}
|
|
178
234
|
delta = await this.readStartupTail(cursor)
|
|
@@ -192,22 +248,17 @@ export class DispatchRepositoryFeed {
|
|
|
192
248
|
// A standby correlation may have supplied an older identity while the
|
|
193
249
|
// delta read was pending. Keep those memoized facts in this commit.
|
|
194
250
|
holder = this.holder
|
|
195
|
-
|
|
196
|
-
incompleteIdentities = this.incompleteIdentities
|
|
251
|
+
identities = this.retained
|
|
197
252
|
}
|
|
198
253
|
if (delta.length > 0)
|
|
199
|
-
|
|
200
|
-
{ retained, incompleteIdentities, holder },
|
|
201
|
-
delta,
|
|
202
|
-
).retained
|
|
254
|
+
identities = dispatchFrontendReducer.advance({ identities, holder }, delta).identities
|
|
203
255
|
this.holder = holder
|
|
204
256
|
this.cursor = Math.max(cursor, delta.at(-1)?.seq ?? 0)
|
|
205
|
-
this.incompleteIdentities = true
|
|
206
257
|
if (restoredKey !== undefined) {
|
|
207
258
|
this.settled = restoredKey
|
|
208
|
-
this.retained =
|
|
259
|
+
this.retained = restoredIdentities!
|
|
209
260
|
}
|
|
210
|
-
this.
|
|
261
|
+
this.replaceIdentities(identities)
|
|
211
262
|
|
|
212
263
|
this.ready = true
|
|
213
264
|
this.recovery = false
|
|
@@ -220,14 +271,11 @@ export class DispatchRepositoryFeed {
|
|
|
220
271
|
const cursor = seed.cursor
|
|
221
272
|
const delta = await this.readStartupTail(cursor)
|
|
222
273
|
this.validate(delta, cursor, true)
|
|
223
|
-
this.
|
|
224
|
-
dispatchFrontendReducer.advance(
|
|
225
|
-
|
|
226
|
-
delta,
|
|
227
|
-
).retained,
|
|
274
|
+
this.replaceIdentities(
|
|
275
|
+
dispatchFrontendReducer.advance({ identities: seed.identities, holder: this.holder }, delta)
|
|
276
|
+
.identities,
|
|
228
277
|
)
|
|
229
278
|
this.cursor = Math.max(cursor, delta.at(-1)?.seq ?? 0)
|
|
230
|
-
this.incompleteIdentities = true
|
|
231
279
|
this.ready = true
|
|
232
280
|
this.recovery = false
|
|
233
281
|
this.boundary = undefined
|
|
@@ -242,7 +290,7 @@ export class DispatchRepositoryFeed {
|
|
|
242
290
|
* repository value: cost is independent of journal and current-run length. */
|
|
243
291
|
private async canonicalSeed(
|
|
244
292
|
holder: string | undefined,
|
|
245
|
-
): Promise<{ cursor: number;
|
|
293
|
+
): Promise<{ cursor: number; identities: RepositoryEvent[] }> {
|
|
246
294
|
const { cursor, value } = await readRepositoryFacts(this.store, this.repo, true)
|
|
247
295
|
const runs = new Map(value.recentRuns)
|
|
248
296
|
const starts = new Map<number, RepositoryEvent>()
|
|
@@ -258,10 +306,7 @@ export class DispatchRepositoryFeed {
|
|
|
258
306
|
throw new Error('invalid canonical identity')
|
|
259
307
|
return {
|
|
260
308
|
cursor,
|
|
261
|
-
|
|
262
|
-
{ retained: [], incompleteIdentities: true, holder },
|
|
263
|
-
sorted,
|
|
264
|
-
).retained,
|
|
309
|
+
identities: dispatchFrontendReducer.advance({ identities: [], holder }, sorted).identities,
|
|
265
310
|
}
|
|
266
311
|
}
|
|
267
312
|
|
|
@@ -271,7 +316,7 @@ export class DispatchRepositoryFeed {
|
|
|
271
316
|
return this.store.getRepositoryTail(this.repo, cursor)
|
|
272
317
|
}
|
|
273
318
|
|
|
274
|
-
private
|
|
319
|
+
private replaceIdentities(events: RepositoryEvent[]): void {
|
|
275
320
|
// Sequence numbers identify immutable journal facts; no deep serialization on polls.
|
|
276
321
|
const changed =
|
|
277
322
|
events !== this.retained &&
|
|
@@ -285,15 +330,8 @@ export class DispatchRepositoryFeed {
|
|
|
285
330
|
if (this.holder === holder) return
|
|
286
331
|
this.generation++
|
|
287
332
|
this.holder = holder
|
|
288
|
-
this.
|
|
289
|
-
dispatchFrontendReducer.advance(
|
|
290
|
-
{
|
|
291
|
-
retained: this.retained,
|
|
292
|
-
incompleteIdentities: true,
|
|
293
|
-
holder,
|
|
294
|
-
},
|
|
295
|
-
[],
|
|
296
|
-
).retained,
|
|
333
|
+
this.replaceIdentities(
|
|
334
|
+
dispatchFrontendReducer.advance({ identities: this.retained, holder }, []).identities,
|
|
297
335
|
)
|
|
298
336
|
}
|
|
299
337
|
|
|
@@ -304,11 +342,9 @@ export class DispatchRepositoryFeed {
|
|
|
304
342
|
0,
|
|
305
343
|
false,
|
|
306
344
|
)
|
|
307
|
-
this.
|
|
308
|
-
dispatchFrontendReducer.advance(
|
|
309
|
-
|
|
310
|
-
eligible,
|
|
311
|
-
).retained,
|
|
345
|
+
this.replaceIdentities(
|
|
346
|
+
dispatchFrontendReducer.advance({ identities: this.retained, holder: this.holder }, eligible)
|
|
347
|
+
.identities,
|
|
312
348
|
)
|
|
313
349
|
}
|
|
314
350
|
|
|
@@ -321,7 +357,7 @@ export class DispatchRepositoryFeed {
|
|
|
321
357
|
const snapshot = {
|
|
322
358
|
version: dispatchFrontendReducer.version,
|
|
323
359
|
cursor: this.cursor,
|
|
324
|
-
state: {
|
|
360
|
+
state: { identities: this.retained, holder: this.holder },
|
|
325
361
|
}
|
|
326
362
|
this.nextSaveAt = now + 30_000
|
|
327
363
|
this.saving = persistReducerSnapshotOutcome(
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
assertCreateAssigneeAccepted,
|
|
2
3
|
assertReadyAssigneeAccepted,
|
|
3
4
|
prepareReadyAssigneeForDispatch,
|
|
4
5
|
} from '../config/ready-assignee'
|
|
@@ -602,8 +603,9 @@ async function defaultWire(
|
|
|
602
603
|
opened.localStateRoot,
|
|
603
604
|
plugins,
|
|
604
605
|
)
|
|
605
|
-
// Once, before the loop: whatever a readyAssignee
|
|
606
|
-
// here so neither a tick nor a reload ever spends a
|
|
606
|
+
// Once, before the loop: whatever a readyAssignee or createAssignee value
|
|
607
|
+
// needs is resolved here so neither a tick nor a reload ever spends a
|
|
608
|
+
// request on it.
|
|
607
609
|
await prepareReadyAssigneeForDispatch(tickets, config.tickets, (line) => {
|
|
608
610
|
if (opts.silent !== true) opts.stderr(`warning: ${line}`)
|
|
609
611
|
})
|
|
@@ -4880,6 +4882,7 @@ class DispatchLoop {
|
|
|
4880
4882
|
config.roles,
|
|
4881
4883
|
config.policy.sessionBudgetSeconds,
|
|
4882
4884
|
config.accounts,
|
|
4885
|
+
config.profiles,
|
|
4883
4886
|
)
|
|
4884
4887
|
const deadline = new Date(
|
|
4885
4888
|
Date.parse(retirement.startedAt) + config.policy.upgradeDrainSeconds * 1000,
|
|
@@ -5662,7 +5665,10 @@ export async function abDispatch(opts: DispatchOpts): Promise<void> {
|
|
|
5662
5665
|
wiring.updateRuntimeReferences?.(effectiveConfig)
|
|
5663
5666
|
},
|
|
5664
5667
|
startupDeprecations,
|
|
5665
|
-
(next) =>
|
|
5668
|
+
(next) => {
|
|
5669
|
+
assertReadyAssigneeAccepted(next.tickets, wiring.tickets)
|
|
5670
|
+
assertCreateAssigneeAccepted(next.tickets, wiring.tickets)
|
|
5671
|
+
},
|
|
5666
5672
|
)
|
|
5667
5673
|
|
|
5668
5674
|
// Launch flags are durable repository setters. Omission writes nothing, so
|