@defrex/autobuild 1.4.2 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/SPEC.md +512 -101
- package/bin/ab-dispatch-kernel.ts +1 -0
- package/docs/accounts.md +9 -0
- package/docs/agent-runtimes.md +1 -0
- package/docs/answering-blocked-builds.md +7 -3
- package/docs/architecture.md +313 -130
- package/docs/assets/headline-wide.png +0 -0
- package/docs/build-store.md +33 -3
- package/docs/cli.md +2 -1
- package/docs/configuration-overview.md +9 -0
- package/docs/configuration.md +217 -106
- package/docs/dispatcher-hosting.md +19 -3
- package/docs/dispatcher.md +11 -6
- package/docs/glossary.md +1 -1
- package/docs/integration-overview.md +2 -2
- package/docs/integration-tree.md +91 -28
- package/docs/merge-policy.md +28 -9
- package/docs/operating.md +1 -1
- package/docs/operator-api.md +57 -20
- package/docs/operator-surfaces.md +1 -1
- package/docs/plugin-authoring.md +89 -8
- package/docs/remote-store-protocol.md +39 -11
- package/docs/remote-ticket-protocol.md +126 -12
- package/docs/restacking.md +24 -6
- package/docs/seams.md +2 -2
- package/docs/setup.md +19 -13
- package/docs/spec-standard.md +2 -1
- package/docs/ticket-dependencies.md +26 -8
- package/docs/ticket-migration.md +70 -7
- package/docs/ticket-sources.md +82 -5
- package/docs/tickets.md +34 -2
- package/docs/troubleshooting.md +3 -3
- package/docs/verification.md +5 -5
- package/docs/website.md +8 -0
- package/docs/workspaces.md +1 -1
- package/package.json +4 -3
- package/packages/core/src/accounts/hosted-readiness.ts +21 -0
- package/packages/core/src/cli/attention.ts +3 -0
- package/packages/core/src/cli/build-control.ts +36 -12
- package/packages/core/src/cli/connect.ts +9 -18
- package/packages/core/src/cli/context.ts +44 -0
- package/packages/core/src/cli/dashboard/configuration.ts +11 -0
- package/packages/core/src/cli/dashboard/model.ts +51 -11
- package/packages/core/src/cli/dashboard/poll.ts +14 -0
- package/packages/core/src/cli/dashboard/queue.ts +21 -0
- package/packages/core/src/cli/dashboard/render.ts +43 -22
- package/packages/core/src/cli/dispatch-frontend.ts +63 -30
- package/packages/core/src/cli/dispatch-mode.ts +35 -16
- package/packages/core/src/cli/dispatch-preflight.ts +4 -1
- package/packages/core/src/cli/dispatch-repository-feed.ts +40 -11
- 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 +522 -145
- package/packages/core/src/cli/help.ts +63 -24
- package/packages/core/src/cli/init-hosted-accounts.ts +54 -0
- package/packages/core/src/cli/init-readiness-remote.ts +16 -3
- package/packages/core/src/cli/init-validation.ts +144 -42
- package/packages/core/src/cli/issue-links.ts +67 -0
- package/packages/core/src/cli/main.ts +32 -15
- package/packages/core/src/cli/pr-summary-publication.ts +38 -7
- package/packages/core/src/cli/publication-settlement.ts +36 -24
- package/packages/core/src/cli/repo-lease.ts +225 -0
- package/packages/core/src/cli/repository-status.ts +203 -49
- package/packages/core/src/cli/status.ts +42 -4
- package/packages/core/src/cli/terminals.ts +37 -2
- package/packages/core/src/cli/ticket-editor.ts +20 -6
- package/packages/core/src/cli/ticket.ts +264 -46
- package/packages/core/src/cli/triage-count-sampler.ts +59 -0
- package/packages/core/src/cli/wait.ts +4 -1
- package/packages/core/src/cli/watch.ts +19 -4
- package/packages/core/src/config/live.ts +45 -4
- package/packages/core/src/config/load.ts +9 -0
- package/packages/core/src/config/pipeline-source.ts +6 -2
- package/packages/core/src/config/ready-assignee.ts +86 -0
- package/packages/core/src/config/schema.ts +202 -38
- package/packages/core/src/distribution-packaging.ts +1 -1
- package/packages/core/src/events/catalog.ts +7 -0
- package/packages/core/src/events/compatibility.ts +2 -1
- package/packages/core/src/events/payloads.ts +85 -0
- package/packages/core/src/events/policy.ts +10 -0
- package/packages/core/src/events/repository.ts +93 -28
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +237 -230
- package/packages/core/src/kernel/build-identity.ts +12 -0
- package/packages/core/src/kernel/change-presence.ts +139 -6
- package/packages/core/src/kernel/dispatch-capacity.ts +189 -19
- package/packages/core/src/kernel/dispatch-status.ts +10 -1
- package/packages/core/src/kernel/dispatch-upgrade.ts +104 -5
- package/packages/core/src/kernel/engine.ts +17 -8
- package/packages/core/src/kernel/finalize-pr-rejection.ts +95 -0
- package/packages/core/src/kernel/generators/build-log.ts +9 -0
- package/packages/core/src/kernel/generators/repository-journals.ts +15 -1
- package/packages/core/src/kernel/harvest.ts +4 -1
- package/packages/core/src/kernel/incremental-fixtures.ts +1 -0
- package/packages/core/src/kernel/integration-completeness.ts +104 -17
- package/packages/core/src/kernel/integration-landing.ts +17 -0
- package/packages/core/src/kernel/integration-state.ts +17 -0
- package/packages/core/src/kernel/issue-keywords.ts +202 -0
- package/packages/core/src/kernel/janitor-failure.ts +96 -5
- package/packages/core/src/kernel/kernel-git.ts +87 -0
- package/packages/core/src/kernel/landing-readiness.ts +25 -17
- 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-issue-links.ts +142 -0
- package/packages/core/src/kernel/node-landing.ts +2 -1
- package/packages/core/src/kernel/node-parent.ts +6 -0
- package/packages/core/src/kernel/node-restack-transaction.ts +2 -0
- package/packages/core/src/kernel/pr-summary.ts +24 -0
- package/packages/core/src/kernel/read-deferrals.ts +75 -12
- package/packages/core/src/kernel/read-facts.ts +32 -1
- package/packages/core/src/kernel/reconcile-restack.ts +1 -1
- package/packages/core/src/kernel/reducer-registry.ts +37 -2
- package/packages/core/src/kernel/reducer.ts +147 -5
- package/packages/core/src/kernel/ticket-preparation.ts +16 -0
- package/packages/core/src/kernel/verify-budget.ts +43 -0
- package/packages/core/src/operator/index.ts +3 -1
- package/packages/core/src/operator/presentation.ts +3 -0
- package/packages/core/src/operator/protocol.ts +38 -2
- package/packages/core/src/operator/query.ts +69 -29
- package/packages/core/src/operator/registry.ts +47 -26
- package/packages/core/src/operator/tickets.ts +77 -10
- package/packages/core/src/plugin-sdk/index.ts +13 -0
- package/packages/core/src/plugins/manifest.ts +1 -1
- package/packages/core/src/plugins/registry.ts +1 -0
- package/packages/core/src/ports/forge/contract.ts +69 -0
- package/packages/core/src/ports/forge/create.ts +5 -0
- package/packages/core/src/ports/forge/fake.ts +184 -3
- package/packages/core/src/ports/forge/git-rewrite.ts +4 -2
- package/packages/core/src/ports/forge/github.ts +175 -38
- package/packages/core/src/ports/forge/local-git.ts +14 -0
- package/packages/core/src/ports/forge/readiness.ts +10 -0
- package/packages/core/src/ports/forge-failure.ts +43 -0
- package/packages/core/src/ports/runner/claude.ts +7 -1
- package/packages/core/src/ports/runner/codex.ts +7 -2
- package/packages/core/src/ports/runner/native-cli-fixture.ts +2 -1
- package/packages/core/src/ports/runner/pi.ts +7 -1
- package/packages/core/src/ports/runner/runtime.ts +3 -0
- package/packages/core/src/ports/runner/start-prompt.ts +37 -0
- package/packages/core/src/ports/tickets/contract.ts +320 -7
- package/packages/core/src/ports/tickets/create.ts +89 -20
- package/packages/core/src/ports/tickets/fake.ts +18 -0
- package/packages/core/src/ports/tickets/file-codec.ts +20 -0
- package/packages/core/src/ports/tickets/file.ts +43 -1
- package/packages/core/src/ports/tickets/github-fake.ts +1123 -0
- package/packages/core/src/ports/tickets/github-issues.ts +431 -0
- package/packages/core/src/ports/tickets/github-validators.ts +194 -0
- package/packages/core/src/ports/tickets/github.ts +2029 -0
- package/packages/core/src/ports/tickets/hosted-index.ts +34 -3
- package/packages/core/src/ports/tickets/issue-links.ts +86 -0
- package/packages/core/src/ports/tickets/lifecycle.ts +60 -4
- package/packages/core/src/ports/tickets/linear.ts +66 -6
- package/packages/core/src/ports/tickets/migration.ts +290 -68
- package/packages/core/src/ports/tickets/operations.ts +98 -12
- package/packages/core/src/ports/tickets/priority.ts +55 -0
- package/packages/core/src/ports/tickets/remote-protocol.ts +195 -29
- package/packages/core/src/ports/tickets/remote.ts +188 -13
- package/packages/core/src/ports/tickets/revision.ts +22 -1
- package/packages/core/src/ports/tickets/states.ts +43 -0
- package/packages/core/src/ports/tickets/tree.ts +58 -12
- package/packages/core/src/ports/tickets/update.ts +12 -2
- package/packages/core/src/ports/types.ts +194 -9
- package/packages/core/src/ports/workspace/commit-preservation.ts +163 -25
- package/packages/core/src/ports/workspace/git-worktree.ts +6 -2
- package/packages/core/src/ports/workspace/harvest-execution.ts +4 -2
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +121 -27
- package/packages/core/src/processes/build-runner.ts +101 -22
- package/packages/core/src/processes/dispatcher.ts +1046 -372
- package/packages/core/src/processes/execution-no-progress.ts +7 -0
- package/packages/core/src/processes/harvest-child.ts +4 -2
- package/packages/core/src/processes/harvest-execution-state.ts +104 -0
- package/packages/core/src/processes/harvest-runner.ts +263 -25
- package/packages/core/src/processes/harvest.ts +5 -8
- package/packages/core/src/processes/tick-publication.ts +12 -2
- package/packages/core/src/processes/ticket-scan-schedule.ts +78 -0
- package/packages/core/src/processes/workspace-preservation.ts +36 -1
- package/packages/core/src/runtime-identity.ts +10 -2
- package/packages/core/src/scenarios/harness.ts +149 -35
- package/packages/core/src/store/adapter.ts +7 -1
- package/packages/core/src/store/contract.ts +83 -2
- package/packages/core/src/store/digest.ts +32 -1
- package/packages/core/src/store/reduced-reads.ts +10 -0
- package/packages/core/src/store/reducer-value-shapes.json +4471 -3427
- package/packages/core/src/store/remote/protocol.ts +2 -0
- package/packages/core/src/store/remote/released-clients.json +22 -0
- package/packages/core/src/store/remote/released-reducer-values/1.5.0.json +26924 -0
- package/packages/core/src/store/remote/released-reducer-values/1.6.0.json +27173 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +4 -0
- package/packages/core/src/store/repo-state-events.ts +2 -0
- package/packages/core/src/store/types.ts +5 -0
- package/packages/core/src/testing/dispatch-read-budget.ts +729 -123
- package/packages/core/src/testing/index.ts +18 -1
- package/packages/core/src/testing/presence-history.ts +79 -0
- package/packages/core/src/testing/reduced-read-budget.ts +1424 -33
- package/packages/core/src/testing/upgrade-generations.ts +77 -0
- package/skills/code-review/SKILL.md +4 -3
- package/skills/finalize/SKILL.md +18 -2
- package/skills/guide/SKILL.md +417 -143
- package/skills/guide/references/accounts.md +9 -0
- package/skills/guide/references/integration-tree.md +91 -28
- package/skills/guide/references/merge-policy.md +28 -9
- package/skills/guide/references/operator-api.md +57 -20
- package/skills/guide/references/plugin-authoring.md +89 -8
- package/skills/guide/references/remote-store-protocol.md +39 -11
- package/skills/guide/references/remote-ticket-protocol.md +126 -12
- package/skills/guide/references/restacking.md +24 -6
- package/skills/guide/references/setup.md +19 -13
- package/skills/guide/references/spec-standard.md +2 -1
- package/skills/guide/references/ticket-dependencies.md +26 -8
- package/skills/guide/references/ticket-migration.md +70 -7
- package/skills/harvest-review/SKILL.md +4 -3
- package/skills/implement/SKILL.md +20 -1
- package/skills/operate/SKILL.md +149 -35
- package/skills/plan/SKILL.md +1 -1
- package/skills/reconcile/SKILL.md +5 -4
- package/skills/spec/SKILL.md +15 -2
- package/skills/tickets/SKILL.md +116 -37
- package/templates/autobuild.toml +5 -0
- package/templates/hosted-service/package.json +2 -2
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertReadyAssigneeAccepted,
|
|
3
|
+
prepareReadyAssigneeForDispatch,
|
|
4
|
+
} from '../config/ready-assignee'
|
|
1
5
|
import { selectDispatchMode } from './dispatch-mode'
|
|
2
6
|
import { createTerminalModeController } from './terminal-restore'
|
|
3
7
|
import { inspectLocalAccountEnvironment } from '../accounts/local-owner'
|
|
@@ -27,13 +31,15 @@ import { resolveUpgradeTarget } from './dispatch-upgrade-target'
|
|
|
27
31
|
import { prepareUpgrade } from './dispatch-upgrade-install'
|
|
28
32
|
import { readDispatchUpgrade } from '../store/reduced-reads'
|
|
29
33
|
import type { Handoff, UpgradeRun } from '../kernel/dispatch-upgrade'
|
|
30
|
-
import {
|
|
34
|
+
import { formatDispatcherError, runtimeIdentity } from '../runtime-identity'
|
|
31
35
|
|
|
32
36
|
import { isDeepStrictEqual } from 'node:util'
|
|
33
37
|
import { guardForge } from '../kernel/guarded-forge'
|
|
34
38
|
import { dispatchCapacity } from '../kernel/dispatch-capacity'
|
|
35
|
-
import { openTicketSource } from './ticket'
|
|
39
|
+
import { lazyTicketSource, openTicketSource } from './ticket'
|
|
40
|
+
import { ticketLifecycle } from '../ports/tickets/lifecycle'
|
|
36
41
|
import {
|
|
42
|
+
branchGuardWarnings,
|
|
37
43
|
inspectForgeReadiness,
|
|
38
44
|
formatForgeReadiness,
|
|
39
45
|
hardReadinessKeys,
|
|
@@ -55,7 +61,11 @@ import { RemoteBuildStore } from '../store/remote/client'
|
|
|
55
61
|
import { delegateCredential } from '../store/remote/credentials'
|
|
56
62
|
import { isRemoteStoreRef } from './repo-state'
|
|
57
63
|
import { projectToken } from './project-credentials'
|
|
58
|
-
import {
|
|
64
|
+
import {
|
|
65
|
+
readLaunchFence,
|
|
66
|
+
settleSummaryRequests,
|
|
67
|
+
summaryHandoffPending,
|
|
68
|
+
} from './pr-summary-publication'
|
|
59
69
|
import { readDispatcherLiveness, StandbyIdentityResolver } from './dispatcher-liveness'
|
|
60
70
|
import { formatDispatcherIdentity } from '../kernel/dispatcher-liveness'
|
|
61
71
|
/**
|
|
@@ -158,6 +168,7 @@ import { GitHubForge } from '../ports/forge/github'
|
|
|
158
168
|
import { createProductionRuntimes } from '../ports/runner/production'
|
|
159
169
|
import type { RuntimeRegistry } from '../ports/runner/runtime'
|
|
160
170
|
import { createTicketSource } from '../ports/tickets/create'
|
|
171
|
+
import { dispatcherTicketSource } from './dispatch-tickets'
|
|
161
172
|
import type {
|
|
162
173
|
Forge,
|
|
163
174
|
TicketSource,
|
|
@@ -184,7 +195,6 @@ import {
|
|
|
184
195
|
} from '../processes/build-execution-state'
|
|
185
196
|
import { HarvestRunner, type HarvestRunnerResult } from '../processes/harvest-runner'
|
|
186
197
|
import {
|
|
187
|
-
unclaimedObservationCount,
|
|
188
198
|
evaluateHarvestPressureFromStore,
|
|
189
199
|
evaluateHarvestPressureFromDigests,
|
|
190
200
|
} from '../processes/harvest'
|
|
@@ -196,6 +206,7 @@ import {
|
|
|
196
206
|
toggleRepositorySetting,
|
|
197
207
|
} from '../operator/control'
|
|
198
208
|
import {
|
|
209
|
+
defaultTriageState,
|
|
199
210
|
Dispatcher,
|
|
200
211
|
emptyTickReport,
|
|
201
212
|
type LaunchRunnerResult,
|
|
@@ -225,6 +236,15 @@ import {
|
|
|
225
236
|
type RepoTickFinish,
|
|
226
237
|
} from '../store/types'
|
|
227
238
|
import { availableRelease } from './self-update'
|
|
239
|
+
import { TriageCountSampler, triageReader } from './triage-count-sampler'
|
|
240
|
+
import {
|
|
241
|
+
fenceEffects,
|
|
242
|
+
fenceExec,
|
|
243
|
+
fenceForge,
|
|
244
|
+
isRepositoryAuthorityLapse,
|
|
245
|
+
RepositoryAuthorityLapsed,
|
|
246
|
+
resolveLapsedRepoLease,
|
|
247
|
+
} from './repo-lease'
|
|
228
248
|
import {
|
|
229
249
|
startUpgradeNotice,
|
|
230
250
|
type AvailableReleaseProbe,
|
|
@@ -234,11 +254,13 @@ import {
|
|
|
234
254
|
/** Watch-loop default cadence between ticks (§3.3 re-run safety makes this a
|
|
235
255
|
* pure knob — a shorter interval only polls the forge more often). */
|
|
236
256
|
const DEFAULT_INTERVAL_MS = 10_000
|
|
237
|
-
/** Repository supervisor lease (§12 serialization)
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
|
|
241
|
-
|
|
257
|
+
/** Repository supervisor lease (§12 serialization) timing, as stored by the
|
|
258
|
+
* claim that set it: `[policy].dispatchLeaseTimeoutSeconds` and
|
|
259
|
+
* `dispatchLeaseRenewalSeconds`. */
|
|
260
|
+
interface RepoLeaseTiming {
|
|
261
|
+
ttlMs: number
|
|
262
|
+
renewalMs: number
|
|
263
|
+
}
|
|
242
264
|
/** Repository artifact containing the schema-validated composed Config used by
|
|
243
265
|
* one dispatch run. It is the frontend's only config source. Defined in
|
|
244
266
|
* `store/retention.ts` beside the other kind constants and re-exported here
|
|
@@ -262,6 +284,13 @@ export function slugNamingPrompt(spec: string): string {
|
|
|
262
284
|
].join('\n')
|
|
263
285
|
}
|
|
264
286
|
|
|
287
|
+
/** Configuration-level warnings recorded durably as `roleWarnings` on run
|
|
288
|
+
* start and config reload: role-key diagnostics plus forge capability gaps
|
|
289
|
+
* such as missing cross-store branch protection (AUT-1106). */
|
|
290
|
+
function startupWarnings(config: Config, forge: Forge): string[] {
|
|
291
|
+
return [...roleKeyWarnings(config), ...branchGuardWarnings(forge)]
|
|
292
|
+
}
|
|
293
|
+
|
|
265
294
|
function definedEnv(env: Record<string, string | undefined>): Record<string, string> {
|
|
266
295
|
const defined: Record<string, string> = {}
|
|
267
296
|
for (const [key, value] of Object.entries(env)) {
|
|
@@ -456,6 +485,10 @@ export interface DispatchOpts {
|
|
|
456
485
|
/** Private child-kernel correlation. Presence suppresses terminal ownership
|
|
457
486
|
* and enables durable dispatcher status publication. */
|
|
458
487
|
kernelRunId?: string
|
|
488
|
+
/** Private: this dispatcher feeds an interactive Store-only frontend, so it
|
|
489
|
+
* samples the display-only triage count for its published status. Only
|
|
490
|
+
* `bin/ab-dispatch-kernel.ts` sets it; hosted kernels never sample. */
|
|
491
|
+
frontendStatus?: boolean
|
|
459
492
|
/** Durable journaling identity of this dispatcher invocation. Every
|
|
460
493
|
* dispatcher-initiated journal write and the repository lease carry this id,
|
|
461
494
|
* so "who holds this repository?" and "who is writing this journal?" are the
|
|
@@ -533,6 +566,10 @@ async function defaultWire(
|
|
|
533
566
|
env: opts.env,
|
|
534
567
|
repoRoot: state.checkout,
|
|
535
568
|
...(opts.repository !== undefined ? { repository: opts.repository } : {}),
|
|
569
|
+
// Origin mode runs kernel Git through the caller's exec seam (the hosted
|
|
570
|
+
// dispatcher routes it to its shipped Git), as `fetchOriginModeConfig`
|
|
571
|
+
// already does; a checkout dispatcher keeps finding Git on its PATH.
|
|
572
|
+
...(originMode ? { exec: opts.exec } : {}),
|
|
536
573
|
})
|
|
537
574
|
// Checkout-less provider seams: the sandbox provider derives its origin and
|
|
538
575
|
// remote branch heads from these instead of host `git` — every host-exec
|
|
@@ -558,13 +595,18 @@ async function defaultWire(
|
|
|
558
595
|
: {}
|
|
559
596
|
const opened = openStoreForRepoState(state, { env: opts.env })
|
|
560
597
|
|
|
561
|
-
const tickets = await
|
|
598
|
+
const tickets = await dispatcherTicketSource(
|
|
562
599
|
config.tickets,
|
|
563
|
-
opts
|
|
564
|
-
state
|
|
600
|
+
opts,
|
|
601
|
+
state,
|
|
565
602
|
opened.localStateRoot,
|
|
566
603
|
plugins,
|
|
567
604
|
)
|
|
605
|
+
// Once, before the loop: whatever a readyAssignee value needs is resolved
|
|
606
|
+
// here so neither a tick nor a reload ever spends a request on it.
|
|
607
|
+
await prepareReadyAssigneeForDispatch(tickets, config.tickets, (line) => {
|
|
608
|
+
if (opts.silent !== true) opts.stderr(`warning: ${line}`)
|
|
609
|
+
})
|
|
568
610
|
const { runtimes } = createProductionRuntimes()
|
|
569
611
|
if (opts.env.AB_PROJECT_SECRETS_FAILED === '1')
|
|
570
612
|
for (const name of JSON.parse(opts.env.AB_PROJECT_SECRETS_UNAVAILABLE ?? '[]') as string[])
|
|
@@ -712,6 +754,10 @@ class DispatchLoop {
|
|
|
712
754
|
* frontend's tick-path journal reads and writes share. Resident for a
|
|
713
755
|
* watch loop; `--once` builds it cold for its single tick. */
|
|
714
756
|
private readonly repoView: RepoViewStore
|
|
757
|
+
/** This loop's adapters, with every effect fenced on repository authority. */
|
|
758
|
+
private readonly wiring: DispatchWiring
|
|
759
|
+
/** `opts.exec` with `git push` fenced on repository authority. */
|
|
760
|
+
private readonly exec: Exec
|
|
715
761
|
private readonly host = hostname()
|
|
716
762
|
private readonly maxHarvestRecoveryAttempts = DEFAULT_MAX_HARVEST_RECOVERY_ATTEMPTS
|
|
717
763
|
/** In-flight build and harvest runs (fire-and-forget) — awaited before a
|
|
@@ -751,7 +797,15 @@ class DispatchLoop {
|
|
|
751
797
|
}
|
|
752
798
|
/** Settlement-only publications carry the latest standing status instead of
|
|
753
799
|
* manufacturing a zero queue measurement or losing diagnostics. */
|
|
754
|
-
private lastTickStatus
|
|
800
|
+
private lastTickStatus: {
|
|
801
|
+
queued: number
|
|
802
|
+
triage?: number
|
|
803
|
+
blockedDiagnostics: string[]
|
|
804
|
+
janitorDiagnostics: string[]
|
|
805
|
+
ticketDiagnostics: string[]
|
|
806
|
+
creationDiagnostics: string[]
|
|
807
|
+
dependencyDiagnostics: string[]
|
|
808
|
+
} = {
|
|
755
809
|
queued: 0,
|
|
756
810
|
blockedDiagnostics: [] as string[],
|
|
757
811
|
janitorDiagnostics: [] as string[],
|
|
@@ -808,11 +862,14 @@ class DispatchLoop {
|
|
|
808
862
|
private forgePublicationFailed = false
|
|
809
863
|
private readonly startupRootBranch: string
|
|
810
864
|
private configWarnings: readonly string[] = []
|
|
865
|
+
/** Deprecation notices of an autobuild.toml change that is not adopted. */
|
|
866
|
+
private candidateWarnings: readonly string[] = []
|
|
811
867
|
/** Last intake-enabled tick's standing queue depth, for the dashboard header. */
|
|
812
868
|
private queuedCount = 0
|
|
813
|
-
/**
|
|
814
|
-
*
|
|
815
|
-
|
|
869
|
+
/** Display-only triage count, sampled between ticks at most once per
|
|
870
|
+
* `TRIAGE_COUNT_REFRESH_MS`. Present only for interactive dashboards and
|
|
871
|
+
* frontend-status kernels; its value is undefined until a read succeeds. */
|
|
872
|
+
private readonly triageSampler: TriageCountSampler | undefined
|
|
816
873
|
/** A slug/id-bound blocked-resume field. The model receives only slug/value;
|
|
817
874
|
* captured escalation ids stay controller-private. */
|
|
818
875
|
private resumePrompt: ResumePrompt | undefined
|
|
@@ -832,9 +889,20 @@ class DispatchLoop {
|
|
|
832
889
|
private repoLeaseValidUntil = 0
|
|
833
890
|
private repoLeaseHolder: string | undefined
|
|
834
891
|
private repoLeaseHeartbeat: ReturnType<typeof setInterval> | undefined
|
|
835
|
-
/**
|
|
836
|
-
*
|
|
837
|
-
*
|
|
892
|
+
/** The timing pair the last successful repository-lease claim stored. Set
|
|
893
|
+
* only by a claim, so the local deadline, the beat cadence and the store's
|
|
894
|
+
* renewal TTL always agree. */
|
|
895
|
+
private heldLease: RepoLeaseTiming | undefined
|
|
896
|
+
/** Advances whenever the stored lease timing may change or the lease is
|
|
897
|
+
* released. A beat answers for the timing it was sent under, so a response
|
|
898
|
+
* from an older generation is discarded rather than trusted. */
|
|
899
|
+
private leaseGeneration = 0
|
|
900
|
+
/** Serializes lease claims and timing adoption, so a claim never captures a
|
|
901
|
+
* timing pair that a concurrent claim is replacing. */
|
|
902
|
+
private leaseMutation: Promise<unknown> = Promise.resolve()
|
|
903
|
+
/** Set only when the lease resolver proves another run took the repository
|
|
904
|
+
* lease: stop accepting launches, detach/reap, signal continuations, and
|
|
905
|
+
* exit watch mode cleanly. An expired lease of our own is never proof. */
|
|
838
906
|
private superseded = false
|
|
839
907
|
/** Public teardown fact for the durable `dispatcher.run-stopped` reason. */
|
|
840
908
|
get supersededByPeer(): boolean {
|
|
@@ -863,11 +931,62 @@ class DispatchLoop {
|
|
|
863
931
|
|
|
864
932
|
constructor(
|
|
865
933
|
private readonly liveConfig: LiveConfig,
|
|
866
|
-
|
|
934
|
+
wiring: DispatchWiring,
|
|
867
935
|
private readonly opts: DispatchOpts,
|
|
868
936
|
/** The view `abDispatch` already used for its lifecycle appends. */
|
|
869
937
|
view?: RepoViewStore,
|
|
870
938
|
) {
|
|
939
|
+
// Every effect this loop or its Dispatcher calls is fenced where it
|
|
940
|
+
// happens: a continuation that resumes after this run's repository lease
|
|
941
|
+
// lapsed throws `RepositoryAuthorityLapsed` instead of starting it. The
|
|
942
|
+
// caller's wiring object is never mutated, so a second loop over the same
|
|
943
|
+
// wiring cannot inherit this loop's guard.
|
|
944
|
+
const guard = () => this.requireRepoAuthority()
|
|
945
|
+
const fencedWorkspaces = (provider: WorkspaceProvider): WorkspaceProvider =>
|
|
946
|
+
fenceEffects(
|
|
947
|
+
provider,
|
|
948
|
+
{
|
|
949
|
+
methods: ['provision'],
|
|
950
|
+
nested: {
|
|
951
|
+
publication: { methods: ['recoverCandidate', 'preserve', 'rewrite', 'publish'] },
|
|
952
|
+
buildExecution: { methods: ['start'] },
|
|
953
|
+
harvestExecution: { methods: ['start'] },
|
|
954
|
+
},
|
|
955
|
+
},
|
|
956
|
+
guard,
|
|
957
|
+
)
|
|
958
|
+
wiring = {
|
|
959
|
+
...wiring,
|
|
960
|
+
tickets: fenceEffects(
|
|
961
|
+
wiring.tickets,
|
|
962
|
+
{
|
|
963
|
+
methods: [
|
|
964
|
+
'claim',
|
|
965
|
+
'comment',
|
|
966
|
+
'transition',
|
|
967
|
+
'create',
|
|
968
|
+
'update',
|
|
969
|
+
'addBlocker',
|
|
970
|
+
'removeBlocker',
|
|
971
|
+
'addState',
|
|
972
|
+
'mutateIfRevision',
|
|
973
|
+
],
|
|
974
|
+
},
|
|
975
|
+
guard,
|
|
976
|
+
),
|
|
977
|
+
workspaces: fencedWorkspaces(wiring.workspaces),
|
|
978
|
+
buildExecution: fenceEffects(wiring.buildExecution, { methods: ['start'] }, guard),
|
|
979
|
+
...(wiring.retiredWorkspaces === undefined
|
|
980
|
+
? {}
|
|
981
|
+
: {
|
|
982
|
+
retiredWorkspaces: wiring.retiredWorkspaces.map((runtime) => ({
|
|
983
|
+
provider: fencedWorkspaces(runtime.provider),
|
|
984
|
+
execution: fenceEffects(runtime.execution, { methods: ['start'] }, guard),
|
|
985
|
+
})),
|
|
986
|
+
}),
|
|
987
|
+
}
|
|
988
|
+
this.wiring = wiring
|
|
989
|
+
this.exec = fenceExec(opts.exec, guard)
|
|
871
990
|
const config = liveConfig.current().config
|
|
872
991
|
this.startupRootBranch = config.baseBranch
|
|
873
992
|
// Minted exactly once per invocation: `wiring.ids` is `randomIds()` and a
|
|
@@ -876,6 +995,13 @@ class DispatchLoop {
|
|
|
876
995
|
// DispatchLoop constructions (tests).
|
|
877
996
|
this.runId = opts.runId ?? opts.kernelRunId ?? `${this.host}-dispatch-${wiring.ids('inst')}`
|
|
878
997
|
this.dashboard = opts.terminal?.interactive === true && opts.plain !== true
|
|
998
|
+
this.triageSampler =
|
|
999
|
+
this.dashboard || opts.frontendStatus === true
|
|
1000
|
+
? new TriageCountSampler(
|
|
1001
|
+
triageReader(wiring.tickets, () => defaultTriageState(this.currentConfig().config)),
|
|
1002
|
+
wiring.clock,
|
|
1003
|
+
)
|
|
1004
|
+
: undefined
|
|
879
1005
|
this.keyboard =
|
|
880
1006
|
this.dashboard && opts.terminal !== undefined && opts.input !== undefined
|
|
881
1007
|
? createKeyboardProtocol((chunk) => opts.terminal!.write(chunk), opts.terminal.modes)
|
|
@@ -915,13 +1041,18 @@ class DispatchLoop {
|
|
|
915
1041
|
|
|
916
1042
|
// `abDispatch` hands over a view it already used for the lifecycle appends,
|
|
917
1043
|
// so those rows are folded, not re-read, and one flush covers them all.
|
|
918
|
-
this.repoView =
|
|
1044
|
+
this.repoView = fenceEffects(
|
|
919
1045
|
view ??
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
1046
|
+
new RepoViewStore(wiring.store, {
|
|
1047
|
+
repo: this.repoIdentity,
|
|
1048
|
+
resident: opts.once !== true,
|
|
1049
|
+
}),
|
|
1050
|
+
{ methods: ['createBuild', 'claimLease'] },
|
|
1051
|
+
guard,
|
|
1052
|
+
)
|
|
1053
|
+
// The fence sits under the health guard, so the Dispatcher's own
|
|
1054
|
+
// `guardForge` call recognises this object and adds no second wrapper.
|
|
1055
|
+
wiring.forge = guardForge(fenceForge(wiring.forge, guard), {
|
|
925
1056
|
store: this.repoView,
|
|
926
1057
|
repo: this.repoIdentity,
|
|
927
1058
|
name: config.forge,
|
|
@@ -947,7 +1078,8 @@ class DispatchLoop {
|
|
|
947
1078
|
? { repoOrigin: normalizeGitRemoteUrl(opts.repository) }
|
|
948
1079
|
: {}),
|
|
949
1080
|
checkout: opts.targetRepo,
|
|
950
|
-
exec:
|
|
1081
|
+
exec: this.exec,
|
|
1082
|
+
holdsRepoAuthority: () => this.holdsRepoAuthority(),
|
|
951
1083
|
launchRunner: (slug) => this.launchRunner(slug),
|
|
952
1084
|
startHarvest: () => this.launchHarvest(),
|
|
953
1085
|
nameSlug,
|
|
@@ -1002,7 +1134,7 @@ class DispatchLoop {
|
|
|
1002
1134
|
mode: this.opts.repository !== undefined ? 'origin' : 'checkout',
|
|
1003
1135
|
forge: this.wiring.forge,
|
|
1004
1136
|
checkout: this.opts.targetRepo,
|
|
1005
|
-
exec: this.
|
|
1137
|
+
exec: this.exec,
|
|
1006
1138
|
...(workspace !== null ? { workspacePath: workspace.path } : {}),
|
|
1007
1139
|
onFailure: (failure) => failures.push(failure),
|
|
1008
1140
|
})
|
|
@@ -1180,7 +1312,17 @@ class DispatchLoop {
|
|
|
1180
1312
|
)
|
|
1181
1313
|
}
|
|
1182
1314
|
|
|
1315
|
+
/** Status telemetry is new work: a run that held the repository lease
|
|
1316
|
+
* writes none once a peer replaced it, and a lapsed holder resolves its
|
|
1317
|
+
* lease first. A standby that never held it reports as before. */
|
|
1183
1318
|
private async appendStatus(event: RepositoryEventWrite): Promise<void> {
|
|
1319
|
+
if (this.superseded) return
|
|
1320
|
+
if (
|
|
1321
|
+
this.repoLeaseHolder !== undefined &&
|
|
1322
|
+
!this.holdsRepoAuthority() &&
|
|
1323
|
+
!(await this.reconfirmRepoLease())
|
|
1324
|
+
)
|
|
1325
|
+
return
|
|
1184
1326
|
await this.repoView.appendRepo(this.repoIdentity, event)
|
|
1185
1327
|
}
|
|
1186
1328
|
|
|
@@ -1203,7 +1345,10 @@ class DispatchLoop {
|
|
|
1203
1345
|
)
|
|
1204
1346
|
})
|
|
1205
1347
|
: await this.liveConfig.refreshFromDisk()
|
|
1206
|
-
if (outcome.kind === 'unchanged')
|
|
1348
|
+
if (outcome.kind === 'unchanged') {
|
|
1349
|
+
if (this.candidateWarnings.length > 0) this.reportCandidateDeprecations([])
|
|
1350
|
+
return
|
|
1351
|
+
}
|
|
1207
1352
|
if (outcome.kind === 'rejected') {
|
|
1208
1353
|
if (outcome.notify) {
|
|
1209
1354
|
await this.appendStatus({
|
|
@@ -1213,6 +1358,9 @@ class DispatchLoop {
|
|
|
1213
1358
|
})
|
|
1214
1359
|
this.warn(`config reload rejected: ${outcome.error}`)
|
|
1215
1360
|
}
|
|
1361
|
+
// LiveConfig returns these once per distinct candidate content.
|
|
1362
|
+
if (outcome.deprecations !== undefined && outcome.deprecations.length > 0)
|
|
1363
|
+
this.reportCandidateDeprecations(outcome.deprecations)
|
|
1216
1364
|
return
|
|
1217
1365
|
}
|
|
1218
1366
|
if (outcome.kind === 'publication-failed') {
|
|
@@ -1222,6 +1370,7 @@ class DispatchLoop {
|
|
|
1222
1370
|
payload: { run: this.runId, error: outcome.error },
|
|
1223
1371
|
})
|
|
1224
1372
|
this.warn(`config reload not applied because its durable trace failed: ${outcome.error}`)
|
|
1373
|
+
if (outcome.deprecations.length > 0) this.reportCandidateDeprecations(outcome.deprecations)
|
|
1225
1374
|
return
|
|
1226
1375
|
}
|
|
1227
1376
|
|
|
@@ -1233,6 +1382,8 @@ class DispatchLoop {
|
|
|
1233
1382
|
`autobuild.toml reload requires dispatch restart for: ${outcome.restartRequired.join(', ')}`,
|
|
1234
1383
|
)
|
|
1235
1384
|
}
|
|
1385
|
+
// The adopted file's deprecations now arrive as accepted-config notices.
|
|
1386
|
+
if (this.candidateWarnings.length > 0) this.candidateWarnings = []
|
|
1236
1387
|
this.reportRoleDiagnostics()
|
|
1237
1388
|
}
|
|
1238
1389
|
|
|
@@ -1269,34 +1420,25 @@ class DispatchLoop {
|
|
|
1269
1420
|
await this.recordTickYielded()
|
|
1270
1421
|
return emptyTickReport()
|
|
1271
1422
|
}
|
|
1423
|
+
// A reloaded `[policy]` lease pair takes effect here, through a claim.
|
|
1424
|
+
await this.adoptConfiguredLease()
|
|
1425
|
+
if (this.superseded) return emptyTickReport()
|
|
1272
1426
|
// Initialization can read/write the store. Retry it at the tick boundary
|
|
1273
1427
|
// after a transient failure, even while our repository lease stays valid.
|
|
1274
1428
|
await this.initializeAutomaticUpgrade()
|
|
1275
1429
|
await this.reportForgeReadiness()
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1430
|
+
let startedAt = await this.repoView.beginRepoTick(this.repoIdentity, this.runId)
|
|
1431
|
+
// The store refuses a boundary on an expired lease. Ours may only have
|
|
1432
|
+
// lapsed: reclaim it and retry once; the resolver decides supersession.
|
|
1433
|
+
if (startedAt === null && (await this.reconfirmRepoLease()))
|
|
1434
|
+
startedAt = await this.repoView.beginRepoTick(this.repoIdentity, this.runId)
|
|
1435
|
+
if (startedAt === null) return emptyTickReport()
|
|
1281
1436
|
this.tickStartedAt = startedAt
|
|
1282
1437
|
|
|
1283
1438
|
// Refresh inside the serialized tick so claims and the display both see
|
|
1284
1439
|
// the latest repository facts. Shared refresh failures still fail the tick.
|
|
1285
1440
|
await this.repoView.refresh()
|
|
1286
1441
|
const digests = await this.repoView.getRepoBuildDigests(this.repoIdentity)
|
|
1287
|
-
if (this.dashboard) {
|
|
1288
|
-
try {
|
|
1289
|
-
// Display-only sampling reuses the refreshed inputs without backing
|
|
1290
|
-
// reads. Publish only a complete measurement; retain it on failure.
|
|
1291
|
-
const count = unclaimedObservationCount({
|
|
1292
|
-
digests,
|
|
1293
|
-
harvestEvents: this.repoView.repositoryFacts().harvest,
|
|
1294
|
-
})
|
|
1295
|
-
this.observationCount = count
|
|
1296
|
-
} catch {
|
|
1297
|
-
// Retry on the next tick without fabricating a zero.
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1300
1442
|
const executionSlugs = new Set(
|
|
1301
1443
|
[...digests].filter(([, digest]) => digest.executionOpen).map(([slug]) => slug),
|
|
1302
1444
|
)
|
|
@@ -1332,8 +1474,10 @@ class DispatchLoop {
|
|
|
1332
1474
|
ticketDiagnostics: readyObservation?.ticketDiagnostics ?? report.ticketDiagnostics,
|
|
1333
1475
|
}
|
|
1334
1476
|
this.queuedCount = publishedReport.queued
|
|
1477
|
+
const triage = this.triageSampler?.value
|
|
1335
1478
|
this.lastTickStatus = {
|
|
1336
1479
|
queued: publishedReport.queued,
|
|
1480
|
+
...(triage !== undefined ? { triage } : {}),
|
|
1337
1481
|
blockedDiagnostics: [...publishedReport.blockedDiagnostics],
|
|
1338
1482
|
janitorDiagnostics: [...publishedReport.janitorDiagnostics],
|
|
1339
1483
|
ticketDiagnostics: [...publishedReport.ticketDiagnostics],
|
|
@@ -1364,6 +1508,7 @@ class DispatchLoop {
|
|
|
1364
1508
|
// no dependence on emission order relative to `startRendering()`.
|
|
1365
1509
|
const warningLines = [
|
|
1366
1510
|
...this.configWarnings,
|
|
1511
|
+
...this.candidateWarnings,
|
|
1367
1512
|
...this.forgeWarnings,
|
|
1368
1513
|
...(this.warningLine !== undefined ? [this.warningLine] : []),
|
|
1369
1514
|
]
|
|
@@ -1872,6 +2017,7 @@ class DispatchLoop {
|
|
|
1872
2017
|
result = await controlBuild({
|
|
1873
2018
|
store: this.wiring.store,
|
|
1874
2019
|
ticketSource: async () => this.wiring.tickets,
|
|
2020
|
+
rejectedState: async () => ticketLifecycle(this.currentConfig().config.tickets).rejected,
|
|
1875
2021
|
repo: this.repoIdentity,
|
|
1876
2022
|
slug,
|
|
1877
2023
|
env: this.opts.env,
|
|
@@ -2381,6 +2527,7 @@ class DispatchLoop {
|
|
|
2381
2527
|
let tracked: Promise<void>
|
|
2382
2528
|
tracked = this.launchHarvestIfNeeded()
|
|
2383
2529
|
.catch((error: unknown) => {
|
|
2530
|
+
if (isRepositoryAuthorityLapse(error)) return
|
|
2384
2531
|
if (this.stopped || this.localHarvestShutdown.signal.aborted)
|
|
2385
2532
|
this.localHarvestFailure = error
|
|
2386
2533
|
// The gate may read the backing store after tick work dirties the view.
|
|
@@ -2444,11 +2591,14 @@ class DispatchLoop {
|
|
|
2444
2591
|
clock,
|
|
2445
2592
|
instance: `${this.host}-harvest-${ids('inst')}`,
|
|
2446
2593
|
...(this.repoLeaseHolder !== undefined ? { leaseHolder: this.repoLeaseHolder } : {}),
|
|
2594
|
+
holdsAuthority: () => this.holdsRepoAuthority(),
|
|
2447
2595
|
sessionEnv: {
|
|
2448
2596
|
AB_STORE: storeRef,
|
|
2449
2597
|
},
|
|
2450
2598
|
opts: {
|
|
2451
2599
|
maxRecoveryAttempts: this.maxHarvestRecoveryAttempts,
|
|
2600
|
+
// Harvest renews this loop's lease; it must never rewrite its TTL.
|
|
2601
|
+
...(this.heldLease !== undefined ? { leaseTtlMs: this.heldLease.ttlMs } : {}),
|
|
2452
2602
|
},
|
|
2453
2603
|
}
|
|
2454
2604
|
|
|
@@ -2482,6 +2632,7 @@ class DispatchLoop {
|
|
|
2482
2632
|
return prepared
|
|
2483
2633
|
}
|
|
2484
2634
|
preparedRun = { run: prepared.run }
|
|
2635
|
+
this.requireRepoAuthority()
|
|
2485
2636
|
await this.repoView.appendRepo(this.repoIdentity, {
|
|
2486
2637
|
actor: DISPATCHER,
|
|
2487
2638
|
type: 'harvest.execution.authorized',
|
|
@@ -2527,6 +2678,7 @@ class DispatchLoop {
|
|
|
2527
2678
|
this.opts.targetRepo,
|
|
2528
2679
|
undefined,
|
|
2529
2680
|
this.wiring.plugins,
|
|
2681
|
+
this.opts.repository !== undefined ? { repository: this.repoIdentity } : {},
|
|
2530
2682
|
)
|
|
2531
2683
|
const result = await new HarvestRunner({
|
|
2532
2684
|
...harvestDeps,
|
|
@@ -2560,6 +2712,7 @@ class DispatchLoop {
|
|
|
2560
2712
|
if (!/^https?:/i.test(storeRef)) return new HarvestRunner(harvestDeps).run()
|
|
2561
2713
|
const prepared = await new HarvestRunner(harvestDeps).run(true)
|
|
2562
2714
|
if (prepared.outcome !== 'prepared') return prepared
|
|
2715
|
+
this.requireRepoAuthority()
|
|
2563
2716
|
await this.repoView.appendRepo(this.repoIdentity, {
|
|
2564
2717
|
actor: DISPATCHER,
|
|
2565
2718
|
type: 'harvest.execution.authorized',
|
|
@@ -2596,6 +2749,7 @@ class DispatchLoop {
|
|
|
2596
2749
|
storeRef,
|
|
2597
2750
|
}).localStateRoot,
|
|
2598
2751
|
this.wiring.plugins,
|
|
2752
|
+
this.opts.repository !== undefined ? { repository: this.repoIdentity } : {},
|
|
2599
2753
|
)
|
|
2600
2754
|
: harvestDeps.tickets
|
|
2601
2755
|
return await new HarvestRunner({
|
|
@@ -2632,6 +2786,8 @@ class DispatchLoop {
|
|
|
2632
2786
|
this.localHarvestFailure = error
|
|
2633
2787
|
return
|
|
2634
2788
|
}
|
|
2789
|
+
// Nothing started without authority; a later tick retries.
|
|
2790
|
+
if (isRepositoryAuthorityLapse(error)) return
|
|
2635
2791
|
this.pendingHarvest.harvestFailed += 1
|
|
2636
2792
|
await this.appendStatus({
|
|
2637
2793
|
actor: DISPATCHER,
|
|
@@ -2669,7 +2825,11 @@ class DispatchLoop {
|
|
|
2669
2825
|
clock: this.wiring.clock,
|
|
2670
2826
|
instance,
|
|
2671
2827
|
...(this.repoLeaseHolder ? { leaseHolder: this.repoLeaseHolder } : {}),
|
|
2672
|
-
|
|
2828
|
+
holdsAuthority: () => this.holdsRepoAuthority(),
|
|
2829
|
+
opts: {
|
|
2830
|
+
maxRecoveryAttempts: this.maxHarvestRecoveryAttempts,
|
|
2831
|
+
...(this.heldLease !== undefined ? { leaseTtlMs: this.heldLease.ttlMs } : {}),
|
|
2832
|
+
},
|
|
2673
2833
|
}).run(true)
|
|
2674
2834
|
}
|
|
2675
2835
|
|
|
@@ -2727,6 +2887,7 @@ class DispatchLoop {
|
|
|
2727
2887
|
|
|
2728
2888
|
const prepared = await this.prepareHarvest(execution)
|
|
2729
2889
|
if (prepared.outcome !== 'prepared') return
|
|
2890
|
+
this.requireRepoAuthority()
|
|
2730
2891
|
await this.repoView.appendRepo(repo, {
|
|
2731
2892
|
actor: DISPATCHER,
|
|
2732
2893
|
type: 'harvest.execution.authorized',
|
|
@@ -2824,6 +2985,8 @@ class DispatchLoop {
|
|
|
2824
2985
|
if (detached.value) {
|
|
2825
2986
|
// Teardown detached the local wait; the guest keeps running and the
|
|
2826
2987
|
// execution stays open for durable settlement by a later invocation.
|
|
2988
|
+
// Releasing this invocation's lease does not fence the guest: its
|
|
2989
|
+
// authority is the execution's durable authorization.
|
|
2827
2990
|
return
|
|
2828
2991
|
}
|
|
2829
2992
|
// The guest exit code carries no pipeline outcome: classify from the
|
|
@@ -2860,6 +3023,8 @@ class DispatchLoop {
|
|
|
2860
3023
|
await this.dispatcher.holdForMissingAccounts(error)
|
|
2861
3024
|
return
|
|
2862
3025
|
}
|
|
3026
|
+
// Nothing started without authority; a later tick retries.
|
|
3027
|
+
if (isRepositoryAuthorityLapse(error)) return
|
|
2863
3028
|
this.pendingHarvest.harvestFailed += 1
|
|
2864
3029
|
await this.appendStatus({
|
|
2865
3030
|
actor: DISPATCHER,
|
|
@@ -3053,7 +3218,9 @@ class DispatchLoop {
|
|
|
3053
3218
|
const runFacts = recent?.start
|
|
3054
3219
|
? recent
|
|
3055
3220
|
: (await readDispatcherRunFacts(this.repoView, this.repoIdentity, this.runId)).value
|
|
3056
|
-
const publish = shouldPublishTickFromFacts(merged, facts, runFacts, startedAt
|
|
3221
|
+
const publish = shouldPublishTickFromFacts(merged, facts, runFacts, startedAt, {
|
|
3222
|
+
triage: this.lastTickStatus.triage,
|
|
3223
|
+
})
|
|
3057
3224
|
const events: RepositoryEventWrite[] = publish
|
|
3058
3225
|
? [
|
|
3059
3226
|
{
|
|
@@ -3064,11 +3231,10 @@ class DispatchLoop {
|
|
|
3064
3231
|
completed,
|
|
3065
3232
|
]
|
|
3066
3233
|
: []
|
|
3067
|
-
|
|
3068
|
-
if (result === null)
|
|
3069
|
-
this.
|
|
3070
|
-
|
|
3071
|
-
}
|
|
3234
|
+
let result = await this.finishTick({ outcome: 'completed', counters }, events)
|
|
3235
|
+
if (result === null && (await this.reconfirmRepoLease()))
|
|
3236
|
+
result = await this.finishTick({ outcome: 'completed', counters }, events)
|
|
3237
|
+
if (result === null) throw new Error('repository tick lease lost')
|
|
3072
3238
|
this.tickStartedAt = undefined
|
|
3073
3239
|
}
|
|
3074
3240
|
|
|
@@ -3127,6 +3293,15 @@ class DispatchLoop {
|
|
|
3127
3293
|
| { original: string; first: string; last: string; count: number }
|
|
3128
3294
|
| undefined
|
|
3129
3295
|
|
|
3296
|
+
/** A tick stopped by a fenced effect is not a failed tick: publish no
|
|
3297
|
+
* `tick-failed`, abandon the open boundary (a successor's or our own next
|
|
3298
|
+
* `beginRepoTick` overwrites it), and resolve the lease. That either stops
|
|
3299
|
+
* this run as superseded or reclaims so the next tick runs normally. */
|
|
3300
|
+
private async settleAuthorityLapse(): Promise<void> {
|
|
3301
|
+
this.tickStartedAt = undefined
|
|
3302
|
+
await this.reconfirmRepoLease()
|
|
3303
|
+
}
|
|
3304
|
+
|
|
3130
3305
|
/** Reporting is diagnostic: its failure must never replace the operational error. */
|
|
3131
3306
|
private async reportTickFailure(error: unknown): Promise<void> {
|
|
3132
3307
|
const original = formatDispatcherError(error)
|
|
@@ -3177,25 +3352,23 @@ class DispatchLoop {
|
|
|
3177
3352
|
await this.wiring.store.appendRepo(this.repoIdentity, failed)
|
|
3178
3353
|
return
|
|
3179
3354
|
}
|
|
3180
|
-
const
|
|
3355
|
+
const completion: RepoTickCompletion = {
|
|
3356
|
+
outcome: 'failed',
|
|
3357
|
+
error: failed.payload.error,
|
|
3358
|
+
forgeRequests: this.dispatcher.lastForgeRequests,
|
|
3359
|
+
}
|
|
3360
|
+
const events: RepositoryEventWrite[] = [
|
|
3181
3361
|
{
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3362
|
+
actor: DISPATCHER,
|
|
3363
|
+
type: 'dispatcher.tick-started',
|
|
3364
|
+
payload: { run: this.runId, startedAt: this.tickStartedAt },
|
|
3185
3365
|
},
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
failed,
|
|
3193
|
-
],
|
|
3194
|
-
)
|
|
3195
|
-
if (result === null) {
|
|
3196
|
-
this.superseded = true
|
|
3197
|
-
return
|
|
3198
|
-
}
|
|
3366
|
+
failed,
|
|
3367
|
+
]
|
|
3368
|
+
let result = await this.finishTick(completion, events)
|
|
3369
|
+
if (result === null && (await this.reconfirmRepoLease()))
|
|
3370
|
+
result = await this.finishTick(completion, events)
|
|
3371
|
+
if (result === null) return
|
|
3199
3372
|
this.tickStartedAt = undefined
|
|
3200
3373
|
}
|
|
3201
3374
|
|
|
@@ -3236,7 +3409,7 @@ class DispatchLoop {
|
|
|
3236
3409
|
forge: this.wiring.forge,
|
|
3237
3410
|
workspacePath: this.opts.targetRepo,
|
|
3238
3411
|
checkoutless: this.opts.repository !== undefined,
|
|
3239
|
-
exec: this.
|
|
3412
|
+
exec: this.exec,
|
|
3240
3413
|
ids: this.wiring.ids,
|
|
3241
3414
|
runId: this.runId,
|
|
3242
3415
|
clock: this.wiring.clock,
|
|
@@ -3260,7 +3433,9 @@ class DispatchLoop {
|
|
|
3260
3433
|
try {
|
|
3261
3434
|
await this.settlePendingPublication(slug)
|
|
3262
3435
|
} catch (error) {
|
|
3263
|
-
|
|
3436
|
+
// A lapsed run publishes nothing; the successor settles from durable facts.
|
|
3437
|
+
if (!(error instanceof ForgeRequestDeferred) && !isRepositoryAuthorityLapse(error))
|
|
3438
|
+
throw error
|
|
3264
3439
|
}
|
|
3265
3440
|
}
|
|
3266
3441
|
|
|
@@ -3347,6 +3522,9 @@ class DispatchLoop {
|
|
|
3347
3522
|
// reached the durable branch. Reconcile that fact before a replacement
|
|
3348
3523
|
// runner can rerun the phase and create a non-fast-forward successor.
|
|
3349
3524
|
await this.settlePendingPublication(slug, instance)
|
|
3525
|
+
// Before the guest can run: every unsettled summary request above this
|
|
3526
|
+
// fence at completion was written by this execution.
|
|
3527
|
+
const launchFenceSeq = await readLaunchFence(this.repoView, slug)
|
|
3350
3528
|
const launchAuth = /^https?:/i.test(this.wiring.storeRef)
|
|
3351
3529
|
? {
|
|
3352
3530
|
token: await (this.wiring.credentialIssuer ?? delegateCredential)(
|
|
@@ -3411,8 +3589,19 @@ class DispatchLoop {
|
|
|
3411
3589
|
}
|
|
3412
3590
|
|
|
3413
3591
|
await this.repoView.refreshBuild(slug)
|
|
3414
|
-
const
|
|
3592
|
+
const facts = (await readBuildFacts(this.repoView, slug)).value
|
|
3593
|
+
const state = facts.state
|
|
3415
3594
|
if (diagnostic === null && exit.exitCode === 0) {
|
|
3595
|
+
if (!relaunch && summaryHandoffPending(facts, launchFenceSeq)) {
|
|
3596
|
+
// The guest yielded only so this host can publish its summary.
|
|
3597
|
+
await this.appendStatus({
|
|
3598
|
+
actor: DISPATCHER,
|
|
3599
|
+
type: 'dispatcher.summary-handoff',
|
|
3600
|
+
payload: { run: this.runId, slug, status: state.status },
|
|
3601
|
+
})
|
|
3602
|
+
this.routineDiagnostic(`build ${slug} handed off its PR summary`)
|
|
3603
|
+
return
|
|
3604
|
+
}
|
|
3416
3605
|
await this.appendStatus({
|
|
3417
3606
|
actor: DISPATCHER,
|
|
3418
3607
|
type: 'dispatcher.runner-settled',
|
|
@@ -3476,6 +3665,14 @@ class DispatchLoop {
|
|
|
3476
3665
|
this.inFlightKinds.set(tracked, handle.supervision)
|
|
3477
3666
|
return 'scheduled'
|
|
3478
3667
|
} catch (error) {
|
|
3668
|
+
if (isRepositoryAuthorityLapse(error)) {
|
|
3669
|
+
// Nothing was started. Release the execution lease (teardown) so a
|
|
3670
|
+
// successor can launch at once, and record no settlement or failure.
|
|
3671
|
+
if (leaseClaimed) await this.repoView.releaseLease(slug, instance).catch(() => {})
|
|
3672
|
+
if (this.activeBuildRuns.get(slug)?.reservation === reservation)
|
|
3673
|
+
this.activeBuildRuns.delete(slug)
|
|
3674
|
+
return 'already-active'
|
|
3675
|
+
}
|
|
3479
3676
|
if (error instanceof MissingAccountCredentialsError) {
|
|
3480
3677
|
await this.dispatcher.holdForMissingAccounts(error)
|
|
3481
3678
|
if (leaseClaimed) await this.repoView.releaseLease(slug, instance)
|
|
@@ -3752,7 +3949,12 @@ class DispatchLoop {
|
|
|
3752
3949
|
}
|
|
3753
3950
|
|
|
3754
3951
|
private reportRoleDiagnostics(): void {
|
|
3755
|
-
|
|
3952
|
+
// The accepted file's deprecations were collected at parse time, never
|
|
3953
|
+
// written there, so they reach this surface once per startup or adoption.
|
|
3954
|
+
const lines = [
|
|
3955
|
+
...this.liveConfig.deprecations(),
|
|
3956
|
+
...startupWarnings(this.currentConfig().config, this.wiring.forge),
|
|
3957
|
+
]
|
|
3756
3958
|
if (this.dashboard) {
|
|
3757
3959
|
this.configWarnings = lines
|
|
3758
3960
|
this.syncModelControls()
|
|
@@ -3762,6 +3964,24 @@ class DispatchLoop {
|
|
|
3762
3964
|
}
|
|
3763
3965
|
}
|
|
3764
3966
|
|
|
3967
|
+
/**
|
|
3968
|
+
* Deprecation guidance for a changed autobuild.toml that was not adopted
|
|
3969
|
+
* (rejected after parsing, or its publication failed). Labelled as pending
|
|
3970
|
+
* so it cannot be read as the accepted config's state. An empty list clears
|
|
3971
|
+
* the dashboard entry.
|
|
3972
|
+
*/
|
|
3973
|
+
private reportCandidateDeprecations(lines: readonly string[]): void {
|
|
3974
|
+
this.candidateWarnings = lines.map(
|
|
3975
|
+
(line) => `${line} (pending autobuild.toml change, not yet adopted)`,
|
|
3976
|
+
)
|
|
3977
|
+
if (this.dashboard) {
|
|
3978
|
+
this.syncModelControls()
|
|
3979
|
+
this.paint()
|
|
3980
|
+
} else if (!this.presentationReleased && this.opts.silent !== true) {
|
|
3981
|
+
for (const line of this.candidateWarnings) this.opts.stderr(line)
|
|
3982
|
+
}
|
|
3983
|
+
}
|
|
3984
|
+
|
|
3765
3985
|
private printReport(report: Awaited<ReturnType<Dispatcher['tick']>>, printIdle = true): boolean {
|
|
3766
3986
|
// `queued` is a standing depth, not a tick action — the header owns it;
|
|
3767
3987
|
// repeating it in the notice would make every saturated tick look busy.
|
|
@@ -3907,8 +4127,7 @@ class DispatchLoop {
|
|
|
3907
4127
|
configSnapshot.config.tickets.source,
|
|
3908
4128
|
),
|
|
3909
4129
|
),
|
|
3910
|
-
|
|
3911
|
-
observationLimit: configSnapshot.config.policy.harvestThreshold,
|
|
4130
|
+
...(this.triageSampler?.value !== undefined ? { triage: this.triageSampler.value } : {}),
|
|
3912
4131
|
},
|
|
3913
4132
|
repositoryEvents,
|
|
3914
4133
|
)
|
|
@@ -4116,17 +4335,59 @@ class DispatchLoop {
|
|
|
4116
4335
|
|
|
4117
4336
|
// ── Repository supervisor lease (§12 serialization) ────────────────────────
|
|
4118
4337
|
|
|
4338
|
+
/** The timing pair the accepted configuration asks for. */
|
|
4339
|
+
private configuredLease(): RepoLeaseTiming {
|
|
4340
|
+
const policy = this.currentConfig().config.policy
|
|
4341
|
+
return {
|
|
4342
|
+
ttlMs: policy.dispatchLeaseTimeoutSeconds * 1000,
|
|
4343
|
+
renewalMs: policy.dispatchLeaseRenewalSeconds * 1000,
|
|
4344
|
+
}
|
|
4345
|
+
}
|
|
4346
|
+
|
|
4347
|
+
/** Whether this run may start an effect now. No I/O: the deadline is the
|
|
4348
|
+
* claim or beat request time plus the held TTL, never later than the
|
|
4349
|
+
* store's expiry, so no peer can have claimed the lease before it. */
|
|
4350
|
+
private holdsRepoAuthority(): boolean {
|
|
4351
|
+
return (
|
|
4352
|
+
!this.superseded &&
|
|
4353
|
+
this.repoLeaseHolder !== undefined &&
|
|
4354
|
+
this.wiring.clock().getTime() < this.repoLeaseValidUntil
|
|
4355
|
+
)
|
|
4356
|
+
}
|
|
4357
|
+
|
|
4358
|
+
/** The synchronous effect fence: throw instead of starting an effect. */
|
|
4359
|
+
private requireRepoAuthority(): void {
|
|
4360
|
+
if (!this.holdsRepoAuthority()) throw new RepositoryAuthorityLapsed()
|
|
4361
|
+
}
|
|
4362
|
+
|
|
4119
4363
|
/** Claim an unknown or expired repository lease and start the
|
|
4120
|
-
* heartbeat timer. False means
|
|
4121
|
-
*
|
|
4364
|
+
* heartbeat timer. False means this run may not act this tick: another
|
|
4365
|
+
* supervisor holds the lease, or our own lapsed lease could not be
|
|
4366
|
+
* confirmed yet. The caller yields — no claims, launches, or publications. */
|
|
4122
4367
|
private async ensureRepoLease(holder: string): Promise<boolean> {
|
|
4123
4368
|
if (this.superseded) return false
|
|
4124
|
-
if (this.repoLeaseHolder === holder
|
|
4369
|
+
if (this.repoLeaseHolder === holder) {
|
|
4370
|
+
if (this.wiring.clock().getTime() < this.repoLeaseValidUntil) return true
|
|
4371
|
+
// Our own deadline lapsed (a stall, or beats lost to a store outage).
|
|
4372
|
+
// Only the resolver decides between "reclaim" and "replaced".
|
|
4373
|
+
return await this.reconfirmRepoLease()
|
|
4374
|
+
}
|
|
4375
|
+
const claimed = await this.mutateLease(async () => {
|
|
4376
|
+
if (this.superseded) return false
|
|
4377
|
+
if (this.repoLeaseHolder === holder) return this.holdsRepoAuthority()
|
|
4378
|
+
const lease = this.configuredLease()
|
|
4379
|
+
const requestedAt = this.wiring.clock().getTime()
|
|
4380
|
+
const granted = await this.wiring.store
|
|
4381
|
+
.claimRepoLease(this.repoIdentity, holder, lease.ttlMs)
|
|
4382
|
+
.catch(() => false)
|
|
4383
|
+
if (!granted || this.superseded) return false
|
|
4384
|
+
this.leaseGeneration++
|
|
4385
|
+
this.heldLease = lease
|
|
4386
|
+
this.repoLeaseValidUntil = requestedAt + lease.ttlMs
|
|
4387
|
+
this.repoLeaseHolder = holder
|
|
4388
|
+
this.restartRepoLeaseHeartbeat()
|
|
4125
4389
|
return true
|
|
4126
|
-
|
|
4127
|
-
const claimed = await this.wiring.store
|
|
4128
|
-
.claimRepoLease(this.repoIdentity, holder, REPO_LEASE_TTL_MS)
|
|
4129
|
-
.catch(() => false)
|
|
4390
|
+
})
|
|
4130
4391
|
if (this.dashboard && !this.opts.once) {
|
|
4131
4392
|
this.standbyResolver ??= new StandbyIdentityResolver(this.wiring.store, this.repoIdentity)
|
|
4132
4393
|
this.standby = claimed
|
|
@@ -4139,44 +4400,128 @@ class DispatchLoop {
|
|
|
4139
4400
|
this.syncModelControls()
|
|
4140
4401
|
this.paint()
|
|
4141
4402
|
}
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4403
|
+
return claimed
|
|
4404
|
+
}
|
|
4405
|
+
|
|
4406
|
+
/** Run one lease claim or timing change after every earlier one settles. */
|
|
4407
|
+
private mutateLease<T>(mutation: () => Promise<T>): Promise<T> {
|
|
4408
|
+
const result = this.leaseMutation.then(mutation)
|
|
4409
|
+
this.leaseMutation = result.catch(() => {})
|
|
4410
|
+
return result
|
|
4411
|
+
}
|
|
4412
|
+
|
|
4413
|
+
/** Resolve a lease that looks lapsed: reclaim it when the record still
|
|
4414
|
+
* names this run, stop as superseded when another run took it, and do
|
|
4415
|
+
* nothing on a store error (the next beat or tick asks again). True only
|
|
4416
|
+
* when this run holds the lease again. A released lease is never
|
|
4417
|
+
* resurrected. */
|
|
4418
|
+
private reconfirmRepoLease(): Promise<boolean> {
|
|
4419
|
+
return this.mutateLease(() => this.reconfirmHeldLease())
|
|
4420
|
+
}
|
|
4421
|
+
|
|
4422
|
+
/** `reconfirmRepoLease` for a caller already inside `mutateLease`. */
|
|
4423
|
+
private async reconfirmHeldLease(): Promise<boolean> {
|
|
4424
|
+
const holder = this.repoLeaseHolder
|
|
4425
|
+
if (this.superseded || holder === undefined) return false
|
|
4426
|
+
const lease = this.heldLease ?? this.configuredLease()
|
|
4427
|
+
const generation = this.leaseGeneration
|
|
4428
|
+
const requestedAt = this.wiring.clock().getTime()
|
|
4429
|
+
const resolution = await resolveLapsedRepoLease(
|
|
4430
|
+
this.wiring.store,
|
|
4431
|
+
this.repoIdentity,
|
|
4432
|
+
holder,
|
|
4433
|
+
lease.ttlMs,
|
|
4434
|
+
)
|
|
4435
|
+
if (this.superseded || this.repoLeaseHolder !== holder || this.leaseGeneration !== generation)
|
|
4147
4436
|
return false
|
|
4437
|
+
if (resolution === 'held') {
|
|
4438
|
+
this.repoLeaseValidUntil = Math.max(this.repoLeaseValidUntil, requestedAt + lease.ttlMs)
|
|
4439
|
+
return true
|
|
4148
4440
|
}
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4441
|
+
if (resolution === 'superseded') {
|
|
4442
|
+
// A peer holds or held the repository since. Exit watch mode cleanly
|
|
4443
|
+
// after the same teardown every stop takes (detach remote / reap local,
|
|
4444
|
+
// signal continuations, release the lease).
|
|
4445
|
+
this.superseded = true
|
|
4446
|
+
this.inputStop.abort()
|
|
4153
4447
|
}
|
|
4154
|
-
return
|
|
4448
|
+
return false
|
|
4449
|
+
}
|
|
4450
|
+
|
|
4451
|
+
/** Adopt a changed `[policy]` lease pair through a same-holder claim, which
|
|
4452
|
+
* rewrites the stored TTL in every adapter. Unchanged configuration costs
|
|
4453
|
+
* no store request.
|
|
4454
|
+
*
|
|
4455
|
+
* While the claim is in flight the stored TTL may be either pair, so the
|
|
4456
|
+
* beat stops, the generation advances (an in-flight beat's answer is
|
|
4457
|
+
* discarded) and the deadline is held to the shorter TTL. An ambiguous
|
|
4458
|
+
* failure keeps the shorter of both pairs until a later claim settles it. */
|
|
4459
|
+
private adoptConfiguredLease(): Promise<void> {
|
|
4460
|
+
return this.mutateLease(async () => {
|
|
4461
|
+
const holder = this.repoLeaseHolder
|
|
4462
|
+
const held = this.heldLease
|
|
4463
|
+
if (holder === undefined || held === undefined || !this.holdsRepoAuthority()) return
|
|
4464
|
+
const wanted = this.configuredLease()
|
|
4465
|
+
if (wanted.ttlMs === held.ttlMs && wanted.renewalMs === held.renewalMs) return
|
|
4466
|
+
const requestedAt = this.wiring.clock().getTime()
|
|
4467
|
+
this.stopRepoLeaseHeartbeat()
|
|
4468
|
+
this.leaseGeneration++
|
|
4469
|
+
this.repoLeaseValidUntil = Math.min(this.repoLeaseValidUntil, requestedAt + wanted.ttlMs)
|
|
4470
|
+
let claimed: boolean
|
|
4471
|
+
try {
|
|
4472
|
+
claimed = await this.wiring.store.claimRepoLease(this.repoIdentity, holder, wanted.ttlMs)
|
|
4473
|
+
} catch {
|
|
4474
|
+
// The claim may or may not have landed. The next tick retries.
|
|
4475
|
+
claimed = false
|
|
4476
|
+
if (!this.superseded && this.repoLeaseHolder === holder) {
|
|
4477
|
+
this.heldLease = {
|
|
4478
|
+
ttlMs: Math.min(held.ttlMs, wanted.ttlMs),
|
|
4479
|
+
renewalMs: Math.min(held.renewalMs, wanted.renewalMs),
|
|
4480
|
+
}
|
|
4481
|
+
this.restartRepoLeaseHeartbeat()
|
|
4482
|
+
}
|
|
4483
|
+
return
|
|
4484
|
+
}
|
|
4485
|
+
if (this.superseded || this.repoLeaseHolder !== holder) return
|
|
4486
|
+
if (!claimed) {
|
|
4487
|
+
this.restartRepoLeaseHeartbeat()
|
|
4488
|
+
await this.reconfirmHeldLease()
|
|
4489
|
+
return
|
|
4490
|
+
}
|
|
4491
|
+
this.heldLease = wanted
|
|
4492
|
+
this.repoLeaseValidUntil = requestedAt + wanted.ttlMs
|
|
4493
|
+
this.restartRepoLeaseHeartbeat()
|
|
4494
|
+
})
|
|
4155
4495
|
}
|
|
4156
4496
|
|
|
4157
|
-
|
|
4158
|
-
|
|
4497
|
+
/** (Re)start the beat at the held renewal interval. A beat that finds the
|
|
4498
|
+
* lease no longer renewable hands the decision to the resolver; it never
|
|
4499
|
+
* concludes takeover by itself. */
|
|
4500
|
+
private restartRepoLeaseHeartbeat(): void {
|
|
4501
|
+
this.stopRepoLeaseHeartbeat()
|
|
4502
|
+
const holder = this.repoLeaseHolder
|
|
4503
|
+
const lease = this.heldLease
|
|
4504
|
+
if (holder === undefined || lease === undefined) return
|
|
4159
4505
|
this.repoLeaseHeartbeat = setInterval(() => {
|
|
4506
|
+
const generation = this.leaseGeneration
|
|
4160
4507
|
const requestedAt = this.wiring.clock().getTime()
|
|
4161
4508
|
this.wiring.store.heartbeatRepo(this.repoIdentity, holder).then(
|
|
4162
4509
|
(alive) => {
|
|
4163
|
-
|
|
4510
|
+
// Released (retirement, shutdown), or the stored timing may have
|
|
4511
|
+
// changed, since this beat was sent: its answer no longer applies.
|
|
4512
|
+
if (this.repoLeaseHolder !== holder || this.leaseGeneration !== generation) return
|
|
4164
4513
|
if (alive) {
|
|
4165
|
-
this.repoLeaseValidUntil = requestedAt +
|
|
4514
|
+
this.repoLeaseValidUntil = requestedAt + lease.ttlMs
|
|
4166
4515
|
return
|
|
4167
4516
|
}
|
|
4168
|
-
|
|
4169
|
-
// the same teardown every stop takes (detach remote / reap local,
|
|
4170
|
-
// signal continuations, release the lease).
|
|
4171
|
-
this.superseded = true
|
|
4172
|
-
this.inputStop.abort()
|
|
4517
|
+
void this.reconfirmRepoLease()
|
|
4173
4518
|
},
|
|
4174
4519
|
() => {
|
|
4175
|
-
// Store unreachable: retry on the next beat
|
|
4176
|
-
//
|
|
4520
|
+
// Store unreachable: retry on the next beat. Tick start reclaims
|
|
4521
|
+
// once the store answers again.
|
|
4177
4522
|
},
|
|
4178
4523
|
)
|
|
4179
|
-
},
|
|
4524
|
+
}, lease.renewalMs)
|
|
4180
4525
|
this.repoLeaseHeartbeat.unref?.()
|
|
4181
4526
|
}
|
|
4182
4527
|
|
|
@@ -4193,7 +4538,8 @@ class DispatchLoop {
|
|
|
4193
4538
|
try {
|
|
4194
4539
|
const record = await this.wiring.store.getRepo(this.repoIdentity).catch(() => null)
|
|
4195
4540
|
const holder = record?.lease?.holder
|
|
4196
|
-
|
|
4541
|
+
// Never a yield to ourselves: our own lapsed lease is resolved, not yielded to.
|
|
4542
|
+
if (holder === undefined || holder === this.runId || this.yieldedTo === holder) return
|
|
4197
4543
|
this.yieldedTo = holder
|
|
4198
4544
|
await this.repoView.appendRepo(this.repoIdentity, {
|
|
4199
4545
|
actor: DISPATCHER,
|
|
@@ -4213,6 +4559,7 @@ class DispatchLoop {
|
|
|
4213
4559
|
const holder = this.repoLeaseHolder
|
|
4214
4560
|
this.repoLeaseHolder = undefined
|
|
4215
4561
|
this.repoLeaseValidUntil = 0
|
|
4562
|
+
this.leaseGeneration++
|
|
4216
4563
|
if (holder === undefined) return
|
|
4217
4564
|
try {
|
|
4218
4565
|
await this.wiring.store.releaseRepoLease(this.repoIdentity, holder)
|
|
@@ -4290,14 +4637,7 @@ class DispatchLoop {
|
|
|
4290
4637
|
this.abandonUpgradeYield()
|
|
4291
4638
|
return false
|
|
4292
4639
|
}
|
|
4293
|
-
|
|
4294
|
-
if (
|
|
4295
|
-
lease?.holder !== this.runId ||
|
|
4296
|
-
Date.parse(lease.expiresAt) <= this.wiring.clock().getTime()
|
|
4297
|
-
) {
|
|
4298
|
-
this.superseded = true
|
|
4299
|
-
return false
|
|
4300
|
-
}
|
|
4640
|
+
if (!(await this.upgradeLeaseCurrent())) return false
|
|
4301
4641
|
// No launch, claim, tick or target continuation may cross this boundary.
|
|
4302
4642
|
this.yieldPending = true
|
|
4303
4643
|
this.acceptingBuildLaunches = false
|
|
@@ -4314,12 +4654,8 @@ class DispatchLoop {
|
|
|
4314
4654
|
])
|
|
4315
4655
|
}
|
|
4316
4656
|
await this.dispatcher.stopProvisioning()
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
currentLease?.holder !== this.runId ||
|
|
4320
|
-
Date.parse(currentLease.expiresAt) <= this.wiring.clock().getTime()
|
|
4321
|
-
) {
|
|
4322
|
-
this.superseded = true
|
|
4657
|
+
if (!(await this.upgradeLeaseCurrent())) {
|
|
4658
|
+
if (!this.superseded) this.abandonUpgradeYield()
|
|
4323
4659
|
return false
|
|
4324
4660
|
}
|
|
4325
4661
|
const startedAt = this.wiring.clock().toISOString()
|
|
@@ -4399,6 +4735,19 @@ class DispatchLoop {
|
|
|
4399
4735
|
return this.adoptUpgradeYield(accepted)
|
|
4400
4736
|
}
|
|
4401
4737
|
|
|
4738
|
+
/** Repository authority may transfer only from a current holder. A record
|
|
4739
|
+
* naming another run, or no record, means a peer replaced us. An expired
|
|
4740
|
+
* lease that still names us is resolved like any other lapse. */
|
|
4741
|
+
private async upgradeLeaseCurrent(): Promise<boolean> {
|
|
4742
|
+
const lease = (await this.wiring.store.getRepo(this.repoIdentity))?.lease
|
|
4743
|
+
if (lease?.holder !== this.runId) {
|
|
4744
|
+
this.superseded = true
|
|
4745
|
+
return false
|
|
4746
|
+
}
|
|
4747
|
+
if (Date.parse(lease.expiresAt) > this.wiring.clock().getTime()) return true
|
|
4748
|
+
return await this.reconfirmRepoLease()
|
|
4749
|
+
}
|
|
4750
|
+
|
|
4402
4751
|
/** Reopen admission after a yield that did not durably transfer authority. */
|
|
4403
4752
|
private abandonUpgradeYield(): void {
|
|
4404
4753
|
if (!this.yieldPending) return
|
|
@@ -4522,8 +4871,9 @@ class DispatchLoop {
|
|
|
4522
4871
|
break
|
|
4523
4872
|
// Read-only policy supervision: never another tick or config fan-out.
|
|
4524
4873
|
try {
|
|
4525
|
-
|
|
4526
|
-
const
|
|
4874
|
+
// Deprecations were reported at startup/reload; this re-read stays quiet.
|
|
4875
|
+
const path = join(this.opts.targetRepo, 'autobuild.toml')
|
|
4876
|
+
const config = parseConfig(await Bun.file(path).text(), path, () => {})
|
|
4527
4877
|
const { createRuntimeResolver } = await import('../ports/runner/routing')
|
|
4528
4878
|
createRuntimeResolver(
|
|
4529
4879
|
this.wiring.runtimes,
|
|
@@ -4625,7 +4975,7 @@ class DispatchLoop {
|
|
|
4625
4975
|
this.upgradeController = new DispatchUpgradeController({
|
|
4626
4976
|
run: this.runId,
|
|
4627
4977
|
lineage: launch.lineage!,
|
|
4628
|
-
from:
|
|
4978
|
+
from: runtimeIdentity(),
|
|
4629
4979
|
runningBunTag: (await readDistributionIdentity(distributionRoot())).bunTag,
|
|
4630
4980
|
reservationOwner: launch.launcherPid,
|
|
4631
4981
|
resolved: upgrades.runs[this.runId]?.resolved,
|
|
@@ -4653,7 +5003,7 @@ class DispatchLoop {
|
|
|
4653
5003
|
),
|
|
4654
5004
|
enabled: () =>
|
|
4655
5005
|
!this.stopped &&
|
|
4656
|
-
|
|
5006
|
+
this.holdsRepoAuthority() &&
|
|
4657
5007
|
this.currentConfig().config.upgrade.automatic &&
|
|
4658
5008
|
this.upgradeRetirementSettled,
|
|
4659
5009
|
resolve: (signal) =>
|
|
@@ -4663,7 +5013,7 @@ class DispatchLoop {
|
|
|
4663
5013
|
originalInstall: launch.originalInstall!,
|
|
4664
5014
|
sourceLaunch: launch.sourceLaunch,
|
|
4665
5015
|
forge: this.wiring.forge,
|
|
4666
|
-
exec: this.
|
|
5016
|
+
exec: this.exec,
|
|
4667
5017
|
signal,
|
|
4668
5018
|
}),
|
|
4669
5019
|
prepare: (target, signal) =>
|
|
@@ -4746,7 +5096,13 @@ class DispatchLoop {
|
|
|
4746
5096
|
// lease and any provisioning state are released for the next
|
|
4747
5097
|
// invocation.
|
|
4748
5098
|
if (this.pastDeadline()) return
|
|
5099
|
+
// One background triage read before the single tick, never inside it.
|
|
5100
|
+
this.triageSampler?.poke()
|
|
4749
5101
|
const initial = await this.dispatcherTick(true).catch(async (error: unknown) => {
|
|
5102
|
+
if (isRepositoryAuthorityLapse(error)) {
|
|
5103
|
+
await this.settleAuthorityLapse()
|
|
5104
|
+
return emptyTickReport()
|
|
5105
|
+
}
|
|
4750
5106
|
await this.reportTickFailure(error)
|
|
4751
5107
|
throw error
|
|
4752
5108
|
})
|
|
@@ -4789,6 +5145,9 @@ class DispatchLoop {
|
|
|
4789
5145
|
this.startRendering()
|
|
4790
5146
|
this.startUpgradeChecks()
|
|
4791
5147
|
let startup = true
|
|
5148
|
+
// Triage counts are sampled between ticks, never inside one: the read
|
|
5149
|
+
// runs in the background and the next publication carries its value.
|
|
5150
|
+
this.triageSampler?.poke()
|
|
4792
5151
|
while (!this.watchStopped && !this.superseded) {
|
|
4793
5152
|
let failed = false
|
|
4794
5153
|
try {
|
|
@@ -4797,9 +5156,14 @@ class DispatchLoop {
|
|
|
4797
5156
|
startup = false
|
|
4798
5157
|
} catch (error) {
|
|
4799
5158
|
if (this.forgePublicationFailed) throw error
|
|
4800
|
-
|
|
4801
|
-
|
|
5159
|
+
if (isRepositoryAuthorityLapse(error)) {
|
|
5160
|
+
await this.settleAuthorityLapse()
|
|
5161
|
+
} else {
|
|
5162
|
+
failed = true
|
|
5163
|
+
await this.reportTickFailure(error)
|
|
5164
|
+
}
|
|
4802
5165
|
}
|
|
5166
|
+
this.triageSampler?.poke()
|
|
4803
5167
|
if (this.watchStopped || this.superseded) break
|
|
4804
5168
|
await sleep(failed || this.pendingTickFailure ? Math.max(intervalMs, 1000) : intervalMs)
|
|
4805
5169
|
}
|
|
@@ -4844,6 +5208,8 @@ async function fetchOriginModeConfig(
|
|
|
4844
5208
|
): Promise<{
|
|
4845
5209
|
content: string
|
|
4846
5210
|
config: Config
|
|
5211
|
+
/** Deprecation lines of the returned (startup) file, collected unwritten. */
|
|
5212
|
+
deprecations: readonly string[]
|
|
4847
5213
|
}> {
|
|
4848
5214
|
const repository = normalizeGitRemoteUrl(opts.repository!)
|
|
4849
5215
|
const label = `${repository}/autobuild.toml`
|
|
@@ -4866,9 +5232,10 @@ async function fetchOriginModeConfig(
|
|
|
4866
5232
|
}
|
|
4867
5233
|
throw error
|
|
4868
5234
|
})
|
|
4869
|
-
const
|
|
5235
|
+
const deprecations: string[] = []
|
|
5236
|
+
const parsed = parseConfig(content, label, (line) => deprecations.push(line))
|
|
4870
5237
|
if (parsed.baseBranch === undefined || parsed.baseBranch === '') {
|
|
4871
|
-
return { content, config: parsed }
|
|
5238
|
+
return { content, config: parsed, deprecations }
|
|
4872
5239
|
}
|
|
4873
5240
|
const branchContent = await readFile
|
|
4874
5241
|
.call(forge, 'autobuild.toml', parsed.baseBranch)
|
|
@@ -4882,7 +5249,9 @@ async function fetchOriginModeConfig(
|
|
|
4882
5249
|
throw error
|
|
4883
5250
|
})
|
|
4884
5251
|
const branchLabel = `${label}@${parsed.baseBranch}`
|
|
4885
|
-
|
|
5252
|
+
const branchDeprecations: string[] = []
|
|
5253
|
+
const config = parseConfig(branchContent, branchLabel, (line) => branchDeprecations.push(line))
|
|
5254
|
+
return { content: branchContent, config, deprecations: branchDeprecations }
|
|
4886
5255
|
}
|
|
4887
5256
|
|
|
4888
5257
|
/** Loopback hosts where a plain-http store origin is accepted: it names the
|
|
@@ -5003,9 +5372,9 @@ export async function abDispatch(opts: DispatchOpts): Promise<void> {
|
|
|
5003
5372
|
},
|
|
5004
5373
|
input: opts.input ?? { start: () => () => {} },
|
|
5005
5374
|
...(!interactive ? { plainOutput: opts.stdout } : {}),
|
|
5006
|
-
|
|
5007
|
-
(
|
|
5008
|
-
|
|
5375
|
+
controlTickets: () =>
|
|
5376
|
+
lazyTicketSource(() =>
|
|
5377
|
+
openTicketSource(
|
|
5009
5378
|
{
|
|
5010
5379
|
targetRepo: state.checkout,
|
|
5011
5380
|
exec: opts.exec,
|
|
@@ -5014,8 +5383,8 @@ export async function abDispatch(opts: DispatchOpts): Promise<void> {
|
|
|
5014
5383
|
stdout: opts.stdout,
|
|
5015
5384
|
},
|
|
5016
5385
|
'ab merge',
|
|
5017
|
-
)
|
|
5018
|
-
)
|
|
5386
|
+
),
|
|
5387
|
+
),
|
|
5019
5388
|
once: opts.once === true,
|
|
5020
5389
|
...(opts.intervalMs !== undefined ? { intervalMs: opts.intervalMs } : {}),
|
|
5021
5390
|
...(opts.signal !== undefined ? { signal: opts.signal } : {}),
|
|
@@ -5100,9 +5469,9 @@ export async function abDispatch(opts: DispatchOpts): Promise<void> {
|
|
|
5100
5469
|
checkout: state.checkout,
|
|
5101
5470
|
storeRef: opened.storeRef,
|
|
5102
5471
|
store: opened.store,
|
|
5103
|
-
|
|
5104
|
-
(
|
|
5105
|
-
|
|
5472
|
+
controlTickets: () =>
|
|
5473
|
+
lazyTicketSource(() =>
|
|
5474
|
+
openTicketSource(
|
|
5106
5475
|
{
|
|
5107
5476
|
targetRepo: state.checkout,
|
|
5108
5477
|
exec: resolvedOpts.exec,
|
|
@@ -5111,8 +5480,8 @@ export async function abDispatch(opts: DispatchOpts): Promise<void> {
|
|
|
5111
5480
|
stdout: resolvedOpts.stdout,
|
|
5112
5481
|
},
|
|
5113
5482
|
'ab merge',
|
|
5114
|
-
)
|
|
5115
|
-
)
|
|
5483
|
+
),
|
|
5484
|
+
),
|
|
5116
5485
|
env: resolvedOpts.env,
|
|
5117
5486
|
terminal: resolvedOpts.terminal,
|
|
5118
5487
|
input: resolvedOpts.input,
|
|
@@ -5137,12 +5506,16 @@ export async function abDispatch(opts: DispatchOpts): Promise<void> {
|
|
|
5137
5506
|
const configPath = join(resolvedOpts.targetRepo, 'autobuild.toml')
|
|
5138
5507
|
let configContent: string
|
|
5139
5508
|
let config: Config
|
|
5509
|
+
// Collected, never written at parse time: the dispatcher reports them once
|
|
5510
|
+
// with its other configuration notices (`reportRoleDiagnostics`).
|
|
5511
|
+
let startupDeprecations: readonly string[] = []
|
|
5140
5512
|
if (opts.repository !== undefined) {
|
|
5141
5513
|
// Origin mode startup config: the base branch's autobuild.toml, fetched
|
|
5142
5514
|
// through the forge (default branch first — baseBranch itself is config).
|
|
5143
5515
|
const fetched = originConfig!
|
|
5144
5516
|
configContent = fetched.content
|
|
5145
5517
|
config = fetched.config
|
|
5518
|
+
startupDeprecations = fetched.deprecations
|
|
5146
5519
|
if (config.forge !== 'github') {
|
|
5147
5520
|
throw new Error(
|
|
5148
5521
|
`origin-mode dispatch requires the builtin github forge, but the fetched autobuild.toml selects ${JSON.stringify(config.forge)}`,
|
|
@@ -5170,7 +5543,9 @@ export async function abDispatch(opts: DispatchOpts): Promise<void> {
|
|
|
5170
5543
|
} else {
|
|
5171
5544
|
try {
|
|
5172
5545
|
configContent = await Bun.file(configPath).text()
|
|
5173
|
-
|
|
5546
|
+
const deprecations: string[] = []
|
|
5547
|
+
config = parseConfig(configContent, configPath, (line) => deprecations.push(line))
|
|
5548
|
+
startupDeprecations = deprecations
|
|
5174
5549
|
} catch (error) {
|
|
5175
5550
|
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
|
|
5176
5551
|
throw new Error(
|
|
@@ -5279,13 +5654,15 @@ export async function abDispatch(opts: DispatchOpts): Promise<void> {
|
|
|
5279
5654
|
kind: effectiveArtifact.kind,
|
|
5280
5655
|
rev: effectiveArtifact.revision,
|
|
5281
5656
|
},
|
|
5282
|
-
roleWarnings:
|
|
5657
|
+
roleWarnings: startupWarnings(effectiveConfig, wiring.forge),
|
|
5283
5658
|
},
|
|
5284
5659
|
}
|
|
5285
5660
|
},
|
|
5286
5661
|
)
|
|
5287
5662
|
wiring.updateRuntimeReferences?.(effectiveConfig)
|
|
5288
5663
|
},
|
|
5664
|
+
startupDeprecations,
|
|
5665
|
+
(next) => assertReadyAssigneeAccepted(next.tickets, wiring.tickets),
|
|
5289
5666
|
)
|
|
5290
5667
|
|
|
5291
5668
|
// Launch flags are durable repository setters. Omission writes nothing, so
|
|
@@ -5333,7 +5710,7 @@ export async function abDispatch(opts: DispatchOpts): Promise<void> {
|
|
|
5333
5710
|
pid: process.pid,
|
|
5334
5711
|
host: hostname(),
|
|
5335
5712
|
effectiveConfig: { kind: artifact.kind, rev: artifact.revision },
|
|
5336
|
-
roleWarnings:
|
|
5713
|
+
roleWarnings: startupWarnings(config, wiring.forge),
|
|
5337
5714
|
},
|
|
5338
5715
|
}
|
|
5339
5716
|
},
|
|
@@ -5343,7 +5720,7 @@ export async function abDispatch(opts: DispatchOpts): Promise<void> {
|
|
|
5343
5720
|
await view.appendRepo(state.repo, {
|
|
5344
5721
|
actor: DISPATCHER,
|
|
5345
5722
|
type: 'dispatcher.runtime-recorded',
|
|
5346
|
-
payload: { run: runId, startedSeq: started.event.seq, runtime:
|
|
5723
|
+
payload: { run: runId, startedSeq: started.event.seq, runtime: runtimeIdentity() },
|
|
5347
5724
|
})
|
|
5348
5725
|
|
|
5349
5726
|
const loop = new DispatchLoop(liveConfig, wiring, resolvedOpts, view)
|