@defrex/autobuild 1.5.0 → 1.7.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 +192 -24
- package/docs/agent-runtimes.md +1 -1
- package/docs/answering-blocked-builds.md +7 -4
- package/docs/architecture.md +100 -32
- package/docs/configuration-overview.md +10 -0
- package/docs/configuration.md +340 -10
- package/docs/dispatcher.md +2 -2
- package/docs/forges.md +1 -0
- package/docs/glossary.md +1 -1
- package/docs/operating.md +1 -1
- package/docs/operator-api.md +33 -10
- package/docs/operator-surfaces.md +6 -3
- package/docs/plugin-authoring.md +48 -6
- package/docs/remote-store-protocol.md +33 -10
- package/docs/restacking.md +16 -7
- 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 +3 -0
- package/packages/core/src/cli/binary-direct.ts +1 -0
- package/packages/core/src/cli/dashboard/model.ts +14 -4
- package/packages/core/src/cli/dashboard/poll.ts +14 -0
- package/packages/core/src/cli/dashboard/render.ts +3 -0
- package/packages/core/src/cli/dispatch-frontend.ts +10 -14
- package/packages/core/src/cli/dispatch-preflight.ts +5 -1
- package/packages/core/src/cli/dispatch-repository-feed.ts +145 -109
- package/packages/core/src/cli/dispatch-tickets.ts +47 -0
- package/packages/core/src/cli/dispatch-upgrade-controller.ts +3 -0
- package/packages/core/src/cli/dispatch.ts +377 -101
- package/packages/core/src/cli/help.ts +15 -6
- package/packages/core/src/cli/init-validation.ts +14 -1
- package/packages/core/src/cli/repo-lease.ts +225 -0
- package/packages/core/src/cli/repository-status.ts +40 -3
- package/packages/core/src/cli/status.ts +21 -13
- package/packages/core/src/cli/ticket.ts +22 -4
- package/packages/core/src/cli/wait.ts +4 -1
- package/packages/core/src/cli/watch.ts +17 -4
- package/packages/core/src/config/live.ts +4 -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 +204 -26
- package/packages/core/src/events/catalog.ts +2 -0
- package/packages/core/src/events/compatibility.ts +3 -1
- package/packages/core/src/events/forge-degradation-policy.ts +16 -2
- package/packages/core/src/events/payloads.ts +23 -0
- package/packages/core/src/events/policy.ts +3 -0
- package/packages/core/src/events/repository.ts +19 -0
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +267 -352
- package/packages/core/src/kernel/build-creation.ts +29 -0
- package/packages/core/src/kernel/dispatch-capacity.ts +134 -30
- package/packages/core/src/kernel/engine.ts +13 -6
- package/packages/core/src/kernel/forge-health.ts +47 -0
- package/packages/core/src/kernel/generators/build-log.ts +9 -0
- package/packages/core/src/kernel/guarded-forge.ts +76 -18
- package/packages/core/src/kernel/incremental-fixtures.ts +1 -0
- package/packages/core/src/kernel/janitor-failure.ts +85 -5
- package/packages/core/src/kernel/leaf-restack-state.ts +4 -2
- package/packages/core/src/kernel/log-index.ts +1 -1
- package/packages/core/src/kernel/node-landing.ts +2 -1
- package/packages/core/src/kernel/node-parent.ts +2 -0
- package/packages/core/src/kernel/read-facts.ts +9 -1
- package/packages/core/src/kernel/reducer-registry.ts +6 -1
- package/packages/core/src/kernel/reducer.ts +75 -4
- package/packages/core/src/kernel/ticket-preparation.ts +15 -8
- package/packages/core/src/operator/protocol.ts +10 -0
- package/packages/core/src/operator/query.ts +16 -13
- package/packages/core/src/operator/registry.ts +25 -5
- 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 +35 -7
- 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 +37 -3
- package/packages/core/src/ports/workspace/commit-preservation.ts +28 -12
- package/packages/core/src/ports/workspace/git-worktree.ts +3 -1
- package/packages/core/src/ports/workspace/harvest-execution.ts +4 -2
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +12 -0
- package/packages/core/src/processes/build-child.ts +28 -7
- package/packages/core/src/processes/build-execution-state.ts +4 -1
- package/packages/core/src/processes/build-runner.ts +17 -2
- package/packages/core/src/processes/dispatcher.ts +329 -59
- package/packages/core/src/processes/execution-no-progress.ts +2 -0
- package/packages/core/src/processes/harvest-child.ts +8 -2
- package/packages/core/src/processes/harvest-execution-state.ts +104 -0
- package/packages/core/src/processes/harvest-runner.ts +251 -17
- package/packages/core/src/processes/repo-view.ts +2 -0
- package/packages/core/src/scenarios/harness.ts +160 -36
- package/packages/core/src/store/reduced-reads.ts +10 -0
- package/packages/core/src/store/reducer-value-shapes.json +3339 -2898
- package/packages/core/src/store/remote/client.ts +21 -8
- package/packages/core/src/store/remote/index.ts +4 -0
- package/packages/core/src/store/remote/protocol.ts +7 -0
- package/packages/core/src/store/remote/released-clients.json +22 -0
- package/packages/core/src/store/remote/released-reducer-values/1.6.0.json +27173 -0
- package/packages/core/src/store/remote/released-reducer-values/1.7.0.json +27366 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +4 -0
- package/packages/core/src/store/repo-state-events.ts +1 -0
- package/packages/core/src/store/types.ts +11 -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 +411 -11
- package/skills/guide/SKILL.md +166 -35
- package/skills/guide/references/operator-api.md +33 -10
- package/skills/guide/references/plugin-authoring.md +48 -6
- package/skills/guide/references/remote-store-protocol.md +33 -10
- package/skills/guide/references/restacking.md +16 -7
- package/skills/operate/SKILL.md +79 -14
- package/skills/tickets/SKILL.md +22 -4
- package/templates/hosted-service/package.json +2 -2
|
@@ -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
|
|
@@ -207,6 +208,8 @@ async function runGenerationPreflight(
|
|
|
207
208
|
)
|
|
208
209
|
return false
|
|
209
210
|
prepared = true
|
|
211
|
+
// The successor claims with its own configured lease timeout.
|
|
212
|
+
let leaseTtlMs = 60_000
|
|
210
213
|
for (;;) {
|
|
211
214
|
signal.throwIfAborted()
|
|
212
215
|
const current = (await readDispatchUpgrade(opened.store, opened.repo)).value.runs[handoff.run]
|
|
@@ -228,6 +231,7 @@ async function runGenerationPreflight(
|
|
|
228
231
|
facts.stop.payload.outcome === 'normal'))
|
|
229
232
|
if (ready) {
|
|
230
233
|
const config = await loadConfig(join(launch.checkout, 'autobuild.toml'))
|
|
234
|
+
leaseTtlMs = config.policy.dispatchLeaseTimeoutSeconds * 1000
|
|
231
235
|
const accounts = selectedExecutionAccounts(config)
|
|
232
236
|
const available = inspectLocalAccountEnvironment(
|
|
233
237
|
new LocalCredentials(join(launch.checkout, '.autobuild')),
|
|
@@ -245,7 +249,7 @@ async function runGenerationPreflight(
|
|
|
245
249
|
return false
|
|
246
250
|
}
|
|
247
251
|
}
|
|
248
|
-
if (ready && (await opened.store.claimRepoLease(opened.repo, launch.run,
|
|
252
|
+
if (ready && (await opened.store.claimRepoLease(opened.repo, launch.run, leaseTtlMs))) {
|
|
249
253
|
await opened.store.appendRepo(opened.repo, {
|
|
250
254
|
actor: DISPATCHER,
|
|
251
255
|
type: 'dispatcher.takeover',
|
|
@@ -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(
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The dispatcher's ticket source (SPEC §3.2): built once per dispatcher
|
|
3
|
+
* process start, before the loop, against the repository's filesystem
|
|
4
|
+
* location rather than its identity.
|
|
5
|
+
*/
|
|
6
|
+
import type { TicketsConfig } from '../config/schema'
|
|
7
|
+
import { normalizeGitRemoteUrl } from '../kernel/origin'
|
|
8
|
+
import type { PluginRegistry } from '../plugins/registry'
|
|
9
|
+
import type { GitHubRequest } from '../ports/forge/github-transport'
|
|
10
|
+
import { createTicketSource } from '../ports/tickets/create'
|
|
11
|
+
import type { TicketSource } from '../ports/types'
|
|
12
|
+
import type { Exec } from '../ports/workspace/git-worktree'
|
|
13
|
+
import type { RepoStatePaths } from './repo-state'
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Construct the dispatcher's ticket source. `state.checkout` is the checkout
|
|
17
|
+
* (or origin mode's scratch root), never the repository identity, so a
|
|
18
|
+
* `github` source resolves its coordinates from the checkout's `origin`.
|
|
19
|
+
* Origin mode supplies its repository directly: its scratch root is no Git
|
|
20
|
+
* checkout.
|
|
21
|
+
*
|
|
22
|
+
* Cost: in checkout mode the `github` and `hosted` sources spend one
|
|
23
|
+
* `git remote get-url origin` spawn; origin mode spends none. It runs once
|
|
24
|
+
* per dispatcher process start, never per tick or config reload, and makes
|
|
25
|
+
* zero store reads.
|
|
26
|
+
*/
|
|
27
|
+
export function dispatcherTicketSource(
|
|
28
|
+
config: TicketsConfig,
|
|
29
|
+
opts: {
|
|
30
|
+
env: Record<string, string | undefined>
|
|
31
|
+
exec: Exec
|
|
32
|
+
/** Origin mode's repository (`--repository` / `AB_REPOSITORY`). */
|
|
33
|
+
repository?: string
|
|
34
|
+
},
|
|
35
|
+
state: Pick<RepoStatePaths, 'checkout'>,
|
|
36
|
+
localStateRoot: string | undefined,
|
|
37
|
+
plugins: PluginRegistry,
|
|
38
|
+
seams: { transport?: GitHubRequest } = {},
|
|
39
|
+
): Promise<TicketSource> {
|
|
40
|
+
return createTicketSource(config, opts.env, state.checkout, localStateRoot, plugins, {
|
|
41
|
+
exec: opts.exec,
|
|
42
|
+
...(opts.repository !== undefined
|
|
43
|
+
? { repository: normalizeGitRemoteUrl(opts.repository) }
|
|
44
|
+
: {}),
|
|
45
|
+
...seams,
|
|
46
|
+
})
|
|
47
|
+
}
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
} from './dispatch-upgrade-target'
|
|
11
11
|
import type { CachedRuntime } from './dispatch-runtime-cache'
|
|
12
12
|
import { releasePreparedRuntime, reservePreparedRuntime } from './dispatch-runtime-use'
|
|
13
|
+
import { isRepositoryAuthorityLapse } from './repo-lease'
|
|
13
14
|
import { captureRuntimeIdentity } from '../runtime-identity'
|
|
14
15
|
import type { DispatchUpgradeState, Handoff } from '../kernel/dispatch-upgrade'
|
|
15
16
|
|
|
@@ -195,6 +196,8 @@ export class DispatchUpgradeController {
|
|
|
195
196
|
}
|
|
196
197
|
} catch (error) {
|
|
197
198
|
if (preparation.signal.aborted || this.abort.signal.aborted) return
|
|
199
|
+
// A fenced effect during a lapsed repository lease skips the check.
|
|
200
|
+
if (isRepositoryAuthorityLapse(error)) return
|
|
198
201
|
if (error instanceof TargetResolutionError) target = error.target
|
|
199
202
|
if (target && !this.failed.has(target.key)) {
|
|
200
203
|
await this.input.append({
|