@defrex/autobuild 1.12.0 → 1.13.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 +435 -160
- package/bin/ab-build-runner.ts +8 -0
- package/docs/answering-blocked-builds.md +25 -3
- package/docs/architecture.md +124 -53
- package/docs/cli.md +1 -1
- package/docs/configuration.md +110 -15
- package/docs/dispatcher.md +19 -8
- package/docs/integration-overview.md +1 -1
- package/docs/integration-tree.md +12 -9
- package/docs/merge-policy.md +7 -2
- package/docs/operating.md +5 -3
- package/docs/operator-api.md +46 -23
- package/docs/operator-surfaces.md +7 -6
- package/docs/optimization-nodes.md +7 -6
- package/docs/plugin-authoring.md +46 -18
- package/docs/remote-store-protocol.md +51 -12
- package/docs/remote-ticket-protocol.md +85 -38
- package/docs/restacking.md +48 -3
- package/docs/setup.md +2 -1
- package/docs/ticket-migration.md +2 -2
- package/docs/ticket-sources.md +23 -8
- package/docs/tickets.md +4 -4
- package/docs/troubleshooting.md +17 -2
- package/docs/verification.md +3 -1
- package/package.json +3 -3
- package/packages/core/src/cli/build-control.ts +72 -6
- package/packages/core/src/cli/dashboard/actions.ts +4 -0
- package/packages/core/src/cli/dashboard/integration-row.ts +43 -19
- package/packages/core/src/cli/dashboard/model.ts +14 -8
- package/packages/core/src/cli/dashboard/poll.ts +218 -10
- package/packages/core/src/cli/dashboard/queue.ts +21 -10
- package/packages/core/src/cli/dashboard/row-text.ts +2 -1
- package/packages/core/src/cli/dashboard/vocabulary.ts +5 -1
- package/packages/core/src/cli/dispatch-frontend.ts +2 -1
- package/packages/core/src/cli/dispatch-tickets.ts +33 -12
- package/packages/core/src/cli/dispatch.ts +527 -144
- package/packages/core/src/cli/help.ts +38 -24
- package/packages/core/src/cli/main.ts +7 -5
- package/packages/core/src/cli/publication-settlement.ts +4 -0
- package/packages/core/src/cli/remote-poll.ts +22 -5
- package/packages/core/src/cli/repository-status.ts +19 -9
- package/packages/core/src/cli/status.ts +23 -11
- package/packages/core/src/cli/store-opening.ts +12 -0
- package/packages/core/src/cli/ticket-start.ts +3 -3
- package/packages/core/src/cli/ticket.ts +12 -11
- package/packages/core/src/cli/wait.ts +8 -28
- package/packages/core/src/cli/watch.ts +113 -50
- package/packages/core/src/config/reference-metadata.ts +7 -1
- package/packages/core/src/config/reference.ts +5 -2
- package/packages/core/src/config/schema.ts +51 -16
- package/packages/core/src/events/payloads.ts +74 -14
- package/packages/core/src/events/repository.ts +14 -3
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +27 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/0a10010ee5cf2e47.json +577 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/227701361be6d1e0.json +490 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/76e5043bae7a80ab.json +86 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/87a917802870bbed.json +87 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/9d85616e5b9e24c1.json +500 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/c7c94fbe7f63cf07.json +84 -0
- package/packages/core/src/kernel/clean-restack-policy.ts +40 -0
- package/packages/core/src/kernel/dispatch-capacity.ts +243 -107
- package/packages/core/src/kernel/done-escalations.ts +269 -0
- package/packages/core/src/kernel/engine.ts +28 -9
- package/packages/core/src/kernel/integration-landing.ts +24 -4
- package/packages/core/src/kernel/integration-stack.ts +39 -0
- package/packages/core/src/kernel/janitor-failure.ts +20 -1
- package/packages/core/src/kernel/log-index-value.ts +3 -0
- package/packages/core/src/kernel/log-index.ts +41 -2
- package/packages/core/src/kernel/open-pr-backpressure.ts +3 -3
- package/packages/core/src/kernel/reducer-registry.ts +3 -0
- package/packages/core/src/kernel/reducer-revisions.ts +15 -0
- package/packages/core/src/kernel/reducer.ts +27 -7
- package/packages/core/src/kernel/repository-attention.ts +14 -5
- package/packages/core/src/kernel/ticket-starts.ts +15 -4
- package/packages/core/src/kernel/verify-stages.ts +46 -7
- package/packages/core/src/operator/attention.ts +28 -3
- package/packages/core/src/operator/done-escalations.ts +38 -0
- package/packages/core/src/operator/presentation.ts +1 -1
- package/packages/core/src/operator/protocol.ts +8 -5
- package/packages/core/src/operator/query.ts +33 -19
- package/packages/core/src/operator/registry.ts +17 -13
- package/packages/core/src/operator/ticket-start.ts +8 -7
- package/packages/core/src/operator/tickets.ts +28 -9
- package/packages/core/src/plugin-sdk/index.ts +10 -0
- package/packages/core/src/plugins/manifest.ts +14 -1
- package/packages/core/src/ports/forge/create.ts +8 -0
- package/packages/core/src/ports/forge/github-transport.ts +5 -1
- package/packages/core/src/ports/forge/github.ts +3 -0
- package/packages/core/src/ports/tickets/contract.ts +147 -76
- package/packages/core/src/ports/tickets/create.ts +47 -7
- package/packages/core/src/ports/tickets/fake.ts +8 -4
- package/packages/core/src/ports/tickets/file-codec.ts +4 -3
- package/packages/core/src/ports/tickets/file.ts +7 -3
- package/packages/core/src/ports/tickets/github.ts +1 -0
- package/packages/core/src/ports/tickets/grants.ts +11 -3
- package/packages/core/src/ports/tickets/hosted-index.ts +5 -0
- package/packages/core/src/ports/tickets/linear.ts +28 -9
- package/packages/core/src/ports/tickets/migration.ts +4 -4
- package/packages/core/src/ports/tickets/operations.ts +4 -2
- package/packages/core/src/ports/tickets/priority-labels.ts +213 -0
- package/packages/core/src/ports/tickets/priority.ts +127 -21
- package/packages/core/src/ports/tickets/remote-protocol.ts +10 -0
- package/packages/core/src/ports/tickets/remote.ts +104 -11
- package/packages/core/src/ports/tickets/revision.ts +5 -3
- package/packages/core/src/ports/tickets/search.ts +9 -0
- package/packages/core/src/ports/tickets/tree.ts +8 -6
- package/packages/core/src/ports/types.ts +30 -15
- package/packages/core/src/ports/workspace/build-execution.ts +4 -0
- package/packages/core/src/ports/workspace/builtin-capabilities.ts +4 -0
- package/packages/core/src/ports/workspace/create.ts +16 -3
- package/packages/core/src/ports/workspace/execution-exit-marker.ts +41 -0
- package/packages/core/src/ports/workspace/recovery-step.ts +101 -0
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +510 -145
- package/packages/core/src/processes/build-execution-state.ts +4 -0
- package/packages/core/src/processes/build-runner.ts +14 -1
- package/packages/core/src/processes/dispatcher.ts +544 -212
- package/packages/core/src/processes/execution-settlement.ts +1 -0
- package/packages/core/src/processes/harvest-runner.ts +12 -7
- package/packages/core/src/processes/infrastructure-failure-budget.ts +7 -2
- package/packages/core/src/processes/invocation-budget.ts +176 -0
- package/packages/core/src/processes/publication-loss.ts +38 -3
- package/packages/core/src/processes/workspace-preservation.ts +86 -15
- package/packages/core/src/store/contract.ts +81 -3
- package/packages/core/src/store/event-reads.ts +30 -1
- package/packages/core/src/store/reduced-reads.ts +23 -0
- package/packages/core/src/store/reducer-value-shapes.json +6628 -6469
- package/packages/core/src/store/reducer-value-validation.ts +181 -33
- package/packages/core/src/store/remote/client.ts +169 -29
- package/packages/core/src/store/remote/compatibility.ts +113 -56
- package/packages/core/src/store/remote/credentials.ts +4 -1
- package/packages/core/src/store/remote/protocol.ts +3 -0
- package/packages/core/src/store/remote/released-clients.json +11 -0
- package/packages/core/src/store/remote/released-reducer-values/1.13.0.json +35966 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +18 -16
- package/packages/core/src/store/remote/released-value-policy.ts +144 -0
- package/packages/core/src/store/remote/retry.ts +406 -0
- package/packages/core/src/testing/dispatch-read-budget.ts +144 -10
- package/packages/core/src/testing/index.ts +2 -0
- package/packages/core/src/testing/invocation-budget.ts +42 -0
- package/packages/core/src/testing/reduced-read-budget.ts +381 -18
- package/packages/core/src/testing/released-value-coverage.ts +423 -0
- package/packages/core/src/web/overview-source.ts +19 -6
- package/skills/guide/SKILL.md +138 -67
- package/skills/guide/references/integration-tree.md +12 -9
- package/skills/guide/references/merge-policy.md +7 -2
- package/skills/guide/references/operator-api.md +46 -23
- package/skills/guide/references/optimization-nodes.md +7 -6
- package/skills/guide/references/plugin-authoring.md +46 -18
- package/skills/guide/references/remote-store-protocol.md +51 -12
- package/skills/guide/references/remote-ticket-protocol.md +85 -38
- package/skills/guide/references/restacking.md +48 -3
- package/skills/guide/references/setup.md +2 -1
- package/skills/guide/references/ticket-migration.md +2 -2
- package/skills/operate/SKILL.md +82 -51
- package/skills/plan/SKILL.md +4 -3
- package/skills/spec/SKILL.md +9 -5
- package/skills/tickets/SKILL.md +25 -17
- package/templates/hosted-service/package.json +2 -2
|
@@ -18,6 +18,7 @@ import { LocalAccountOwner, renewLocalAccounts } from '../accounts/local-owner'
|
|
|
18
18
|
import { accountRedactor, redactAccountStore } from '../store/account-redaction'
|
|
19
19
|
import { capturedBuildConfig } from '../processes/verify-cycle-config'
|
|
20
20
|
import { ForgeRequestDeferred } from '../ports/forge-request-context'
|
|
21
|
+
import { isRecoveryDeferred } from '../ports/workspace/recovery-step'
|
|
21
22
|
import { recordRuntimeRollback } from './dispatch-handoff'
|
|
22
23
|
import { syncRollbackRetention } from './dispatch-runtime-use'
|
|
23
24
|
import { dirname as runtimeDirname } from 'node:path'
|
|
@@ -41,7 +42,7 @@ import { formatDispatcherError, runtimeIdentity } from '../runtime-identity'
|
|
|
41
42
|
|
|
42
43
|
import { isDeepStrictEqual } from 'node:util'
|
|
43
44
|
import { guardForge } from '../kernel/guarded-forge'
|
|
44
|
-
import { dispatchCapacity, startClaimDemand,
|
|
45
|
+
import { dispatchCapacity, startClaimDemand, claimDemand } from '../kernel/dispatch-capacity'
|
|
45
46
|
import { lazyTicketSource, openTicketSource } from './ticket'
|
|
46
47
|
import { ticketLifecycle } from '../ports/tickets/lifecycle'
|
|
47
48
|
import {
|
|
@@ -158,7 +159,7 @@ import {
|
|
|
158
159
|
type DashboardSelection,
|
|
159
160
|
type DashboardView,
|
|
160
161
|
} from './dashboard/model'
|
|
161
|
-
import { DashboardBuildPollCache } from './dashboard/poll'
|
|
162
|
+
import { DashboardBuildPollCache, hasActiveBuilds } from './dashboard/poll'
|
|
162
163
|
import { repositoryQueueDepth } from './dashboard/header'
|
|
163
164
|
import {
|
|
164
165
|
dashboardContentWidth,
|
|
@@ -189,6 +190,7 @@ import { GitHubForge, refusedArchiveFallback } from '../ports/forge/github'
|
|
|
189
190
|
import type { RuntimeRegistry } from '../ports/runner/runtime'
|
|
190
191
|
import { createTicketSource } from '../ports/tickets/create'
|
|
191
192
|
import { dispatcherTicketSource } from './dispatch-tickets'
|
|
193
|
+
import { isTransientRemoteFailure, withRemoteRetryDeadline } from '../store/remote/retry'
|
|
192
194
|
import type {
|
|
193
195
|
Forge,
|
|
194
196
|
TicketSource,
|
|
@@ -246,7 +248,17 @@ import {
|
|
|
246
248
|
resolveRepoStatePaths,
|
|
247
249
|
type RepoStatePaths,
|
|
248
250
|
} from './repo-state'
|
|
249
|
-
import { openStoreForRepoState } from './store-opening'
|
|
251
|
+
import { budgetedProductionStore, openStoreForRepoState } from './store-opening'
|
|
252
|
+
import {
|
|
253
|
+
budgetedFetch,
|
|
254
|
+
DEFAULT_TIMERS,
|
|
255
|
+
InvocationBudgetExhaustedError,
|
|
256
|
+
invocationSignal,
|
|
257
|
+
untilAborted,
|
|
258
|
+
withInvocationSignal,
|
|
259
|
+
type InvocationBudget,
|
|
260
|
+
type TimerScheduler,
|
|
261
|
+
} from '../processes/invocation-budget'
|
|
250
262
|
import { DispatchFrontend } from './dispatch-frontend'
|
|
251
263
|
import {
|
|
252
264
|
systemClock,
|
|
@@ -367,8 +379,21 @@ export interface DispatchWiring {
|
|
|
367
379
|
releaseAccounts?: () => Promise<void>
|
|
368
380
|
|
|
369
381
|
credentialIssuer?: typeof delegateCredential
|
|
382
|
+
/** Bounded invocation only: the cancelling host fetch and ambient signal
|
|
383
|
+
* reader `defaultWire` gives the primary adapters. The loop applies them to
|
|
384
|
+
* the requests it makes itself (credential delegation, ticket grants) and
|
|
385
|
+
* to the secondary store and ticket adapters it builds for a harvest.
|
|
386
|
+
* Absent ⇒ global `fetch`, unchanged. */
|
|
387
|
+
budgetSeams?: {
|
|
388
|
+
fetchFn: typeof fetch
|
|
389
|
+
invocationSignal: () => AbortSignal | undefined
|
|
390
|
+
}
|
|
370
391
|
store: BuildStore
|
|
371
392
|
tickets: TicketSource
|
|
393
|
+
/** The ticket source's deferred preparation (a hosted source's policy
|
|
394
|
+
* synchronization and targeting negotiation), run at the first tick
|
|
395
|
+
* boundary until it succeeds. Absent, the source needs none. */
|
|
396
|
+
prepareTickets?: () => Promise<void>
|
|
372
397
|
forge: Forge
|
|
373
398
|
workspaces: WorkspaceProvider
|
|
374
399
|
/** Provider and executor pairs for workspaces recorded before a
|
|
@@ -402,28 +427,18 @@ export interface DispatchWiring {
|
|
|
402
427
|
|
|
403
428
|
export type DispatchNonStoreWiring = Omit<DispatchWiring, 'store' | 'storeRef' | 'token'>
|
|
404
429
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
const DEFAULT_TIMERS: TimerScheduler = {
|
|
418
|
-
setTimeout(handler, ms) {
|
|
419
|
-
const timer = setTimeout(handler, ms)
|
|
420
|
-
;(timer as { unref?: () => void }).unref?.()
|
|
421
|
-
return timer
|
|
422
|
-
},
|
|
423
|
-
clearTimeout(handle) {
|
|
424
|
-
clearTimeout(handle as ReturnType<typeof setTimeout>)
|
|
425
|
-
},
|
|
426
|
-
}
|
|
430
|
+
export type { TimerScheduler } from '../processes/invocation-budget'
|
|
431
|
+
export {
|
|
432
|
+
createInvocationBudget,
|
|
433
|
+
teardownReserveMs,
|
|
434
|
+
untilAborted,
|
|
435
|
+
withInvocationSignal,
|
|
436
|
+
invocationSignal,
|
|
437
|
+
budgetedFetch,
|
|
438
|
+
InvocationDeadlineError,
|
|
439
|
+
InvocationBudgetExhaustedError,
|
|
440
|
+
type InvocationBudget,
|
|
441
|
+
} from '../processes/invocation-budget'
|
|
427
442
|
|
|
428
443
|
export interface DispatchOpts {
|
|
429
444
|
takeover?: boolean
|
|
@@ -528,13 +543,22 @@ export interface DispatchOpts {
|
|
|
528
543
|
/** Private child mode: preserve kernel behavior while routing no legacy
|
|
529
544
|
* line output into the terminal-owning parent. */
|
|
530
545
|
silent?: boolean
|
|
531
|
-
/** Invocation bound (epoch ms, measured against `wiring.clock`). `--once`
|
|
546
|
+
/** Invocation WORK bound (epoch ms, measured against `wiring.clock`). `--once`
|
|
532
547
|
* only: an already-passed deadline skips the tick and the drain entirely
|
|
533
548
|
* (teardown still runs), and a deadline reached mid-drain stops awaiting
|
|
534
549
|
* `local-parent` executions, which teardown then stops and reaps — so one
|
|
535
550
|
* invocation always returns and unfinished work resumes next invocation.
|
|
536
551
|
* Watch mode is unaffected; absent ⇒ unbounded (today's exact behavior). */
|
|
537
552
|
deadlineAt?: number
|
|
553
|
+
/** Bounded `--once` invocation (hosted cron): an enforced wall-time budget
|
|
554
|
+
* with teardown headroom. The caller creates it with its own clock and
|
|
555
|
+
* timers and owns its disposal. Startup and the work pass run under its
|
|
556
|
+
* `work` signal, so every builtin adapter request is cancelled at the work
|
|
557
|
+
* deadline; teardown runs under `cleanup` and `final`, and a budget stop
|
|
558
|
+
* records a normal `dispatcher.run-stopped`. Requires `once: true`.
|
|
559
|
+
* `deadlineAt` defaults to `invocationBudget.workDeadlineAt`; a different
|
|
560
|
+
* explicit `deadlineAt` is a wiring error. */
|
|
561
|
+
invocationBudget?: InvocationBudget
|
|
538
562
|
/** Timer seam for the `deadlineAt` drain race. Absent ⇒ `DEFAULT_TIMERS`
|
|
539
563
|
* (real, unref'd timers); tests inject a manual scheduler to drive both
|
|
540
564
|
* race outcomes deterministically and to assert no expiry handle outlives
|
|
@@ -626,6 +650,11 @@ async function defaultWire(
|
|
|
626
650
|
// Origin mode: no checkout exists, so the provider's host git seams are
|
|
627
651
|
// replaced by the injected origin and the forge's remote reads.
|
|
628
652
|
const originMode = opts.repository !== undefined
|
|
653
|
+
// Bounded invocation (hosted cron): every builtin adapter request, and the
|
|
654
|
+
// plugin factory context's fetch, is cancelled at the current phase's
|
|
655
|
+
// deadline. Unbounded dispatch passes nothing and keeps global fetch.
|
|
656
|
+
const budgetSeams =
|
|
657
|
+
opts.invocationBudget !== undefined ? { fetchFn: budgetedFetch(), invocationSignal } : undefined
|
|
629
658
|
await validateWorkspaceDispatchConfiguration(config, opts, plugins)
|
|
630
659
|
// The builtin GitHub forge resolves its credential lazily on its first
|
|
631
660
|
// request (GITHUB_TOKEN, GH_TOKEN, then the gh CLI login) and names the
|
|
@@ -641,6 +670,7 @@ async function defaultWire(
|
|
|
641
670
|
// dispatcher routes it to its shipped Git), as `fetchOriginModeConfig`
|
|
642
671
|
// already does; a checkout dispatcher keeps finding Git on its PATH.
|
|
643
672
|
...(originMode ? { exec: opts.exec } : {}),
|
|
673
|
+
...budgetSeams,
|
|
644
674
|
})
|
|
645
675
|
// Checkout-less provider seams: the sandbox provider derives its origin and
|
|
646
676
|
// remote branch heads from these instead of host `git` — every host-exec
|
|
@@ -667,14 +697,20 @@ async function defaultWire(
|
|
|
667
697
|
// A guest whose archive push is refused falls back to the forge's REST
|
|
668
698
|
// creation on the host, in checkout and origin mode alike.
|
|
669
699
|
const refusedArchive = refusedArchiveFallback(forge)
|
|
670
|
-
const opened = openStoreForRepoState(state, {
|
|
700
|
+
const opened = openStoreForRepoState(state, {
|
|
701
|
+
env: opts.env,
|
|
702
|
+
...(budgetSeams !== undefined
|
|
703
|
+
? { openStore: budgetedProductionStore(budgetSeams.fetchFn) }
|
|
704
|
+
: {}),
|
|
705
|
+
})
|
|
671
706
|
|
|
672
|
-
const tickets = await dispatcherTicketSource(
|
|
707
|
+
const { tickets, prepare: prepareTickets } = await dispatcherTicketSource(
|
|
673
708
|
config.tickets,
|
|
674
709
|
opts,
|
|
675
710
|
state,
|
|
676
711
|
opened.localStateRoot,
|
|
677
712
|
plugins,
|
|
713
|
+
budgetSeams ?? {},
|
|
678
714
|
)
|
|
679
715
|
// Once, before the loop: whatever a readyAssignee or createAssignee value
|
|
680
716
|
// needs is resolved here so neither a tick nor a reload ever spends a
|
|
@@ -761,6 +797,8 @@ async function defaultWire(
|
|
|
761
797
|
...providerSeams,
|
|
762
798
|
...(refusedArchive !== undefined ? { refusedArchive } : {}),
|
|
763
799
|
...(opened.token !== undefined ? { storeToken: opened.token } : {}),
|
|
800
|
+
...budgetSeams,
|
|
801
|
+
...(opts.deadlineAt !== undefined ? { invocationDeadlineAt: opts.deadlineAt } : {}),
|
|
764
802
|
})
|
|
765
803
|
|
|
766
804
|
// Builds provisioned before this repository switched providers still hold
|
|
@@ -795,6 +833,7 @@ async function defaultWire(
|
|
|
795
833
|
inspectLocalAccountEnvironment(credentials, accounts, opts.env, undefined, true),
|
|
796
834
|
releaseAccounts,
|
|
797
835
|
tickets,
|
|
836
|
+
...(prepareTickets !== undefined ? { prepareTickets } : {}),
|
|
798
837
|
forge,
|
|
799
838
|
workspaces: workspaceRuntime.provider,
|
|
800
839
|
retiredWorkspaces,
|
|
@@ -809,6 +848,7 @@ async function defaultWire(
|
|
|
809
848
|
uuids: randomUuids(),
|
|
810
849
|
clock: systemClock,
|
|
811
850
|
plugins,
|
|
851
|
+
...(budgetSeams !== undefined ? { budgetSeams } : {}),
|
|
812
852
|
updateRuntimeReferences: (effectiveConfig) => {
|
|
813
853
|
allAccounts = effectiveConfig.accounts
|
|
814
854
|
accounts = selectedExecutionAccounts(effectiveConfig)
|
|
@@ -843,6 +883,25 @@ interface ActiveBuildExecution {
|
|
|
843
883
|
/** The dispatch loop owns deterministic decisions and supervises one
|
|
844
884
|
* workspace-adjacent process per build. Build outcomes flow only through the
|
|
845
885
|
* Store; child completion is liveness evidence used for reaping/single-flight. */
|
|
886
|
+
/** A ticket preparation failure that is not transient (authentication, a
|
|
887
|
+
* service predating the policy, validation): the run stops abnormally with
|
|
888
|
+
* `cause`, exactly as a construction-time failure always did. */
|
|
889
|
+
export class FatalTicketPreparationError extends Error {
|
|
890
|
+
override readonly name = 'FatalTicketPreparationError'
|
|
891
|
+
constructor(override readonly cause: unknown) {
|
|
892
|
+
super(cause instanceof Error ? cause.message : String(cause), { cause })
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
/** A `--once` tick failed and its `dispatcher.tick-failed` is durable: the run
|
|
897
|
+
* records a normal stop with exit code 1 and `abDispatch` rethrows `cause`. */
|
|
898
|
+
export class DispatchTickFailedError extends Error {
|
|
899
|
+
override readonly name = 'DispatchTickFailedError'
|
|
900
|
+
constructor(override readonly cause: unknown) {
|
|
901
|
+
super(cause instanceof Error ? cause.message : String(cause), { cause })
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
|
|
846
905
|
class DispatchLoop {
|
|
847
906
|
private readonly dispatcher: Dispatcher
|
|
848
907
|
/** The incremental repository view (AUT-647) the dispatcher and this
|
|
@@ -1006,9 +1065,40 @@ class DispatchLoop {
|
|
|
1006
1065
|
* absent deadline is never past, so every existing caller is unchanged. */
|
|
1007
1066
|
private pastDeadline(): boolean {
|
|
1008
1067
|
return (
|
|
1009
|
-
this.opts.deadlineAt !== undefined &&
|
|
1068
|
+
(this.opts.deadlineAt !== undefined &&
|
|
1069
|
+
this.wiring.clock().getTime() >= this.opts.deadlineAt) ||
|
|
1070
|
+
this.budgetStopped()
|
|
1010
1071
|
)
|
|
1011
1072
|
}
|
|
1073
|
+
|
|
1074
|
+
/** Bounded invocation: true once the budget's work deadline has passed. */
|
|
1075
|
+
private budgetStopped(): boolean {
|
|
1076
|
+
return this.opts.invocationBudget?.work.aborted === true
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
private deadlineStop = false
|
|
1080
|
+
/** True when a bounded invocation stopped its work pass at the deadline. */
|
|
1081
|
+
get stoppedAtDeadline(): boolean {
|
|
1082
|
+
return this.deadlineStop
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
/** Set when an initial repository-lease claim request failed: the server
|
|
1086
|
+
* may have committed it, so a bounded invocation releases exactly its own
|
|
1087
|
+
* holder before exiting. Cleared by a later successful claim. */
|
|
1088
|
+
private repoLeaseClaimAmbiguous = false
|
|
1089
|
+
|
|
1090
|
+
/** The work-deadline listener: synchronously stop launches, mark every
|
|
1091
|
+
* environment-supervised execution and the hosted harvest as detaching,
|
|
1092
|
+
* and signal provisioning continuations, so a request the deadline aborts
|
|
1093
|
+
* is classified as teardown, never as a wait or provisioning failure. */
|
|
1094
|
+
private readonly onWorkDeadline = (): void => {
|
|
1095
|
+
this.acceptingBuildLaunches = false
|
|
1096
|
+
for (const entry of this.activeBuildRuns.values()) {
|
|
1097
|
+
if (entry.handle?.supervision === 'environment') entry.detaching = true
|
|
1098
|
+
}
|
|
1099
|
+
if (this.hostedHarvest !== undefined) this.hostedHarvest.detached.value = true
|
|
1100
|
+
this.dispatcher.abortProvisioning()
|
|
1101
|
+
}
|
|
1012
1102
|
/** The holder id this invocation already recorded a `tick-yielded` for. */
|
|
1013
1103
|
private yieldedTo: string | undefined
|
|
1014
1104
|
/** The invocation's durable journaling identity: every repository-lease
|
|
@@ -1570,6 +1660,9 @@ class DispatchLoop {
|
|
|
1570
1660
|
// remaining budget cannot cover them (bounded overrun, one in-flight
|
|
1571
1661
|
// transport call). Watch mode has no deadline ⇒ absent ⇒ unbounded.
|
|
1572
1662
|
...(this.opts.deadlineAt !== undefined ? { deadlineAt: this.opts.deadlineAt } : {}),
|
|
1663
|
+
...(this.opts.invocationBudget !== undefined
|
|
1664
|
+
? { workSignal: this.opts.invocationBudget.work }
|
|
1665
|
+
: {}),
|
|
1573
1666
|
})
|
|
1574
1667
|
const publishedReport: TickReport = {
|
|
1575
1668
|
...report,
|
|
@@ -2675,6 +2768,7 @@ class DispatchLoop {
|
|
|
2675
2768
|
}
|
|
2676
2769
|
|
|
2677
2770
|
const { store, tickets, runtimes, ids, uuids, clock, storeRef, token } = this.wiring
|
|
2771
|
+
const fetchFn = this.wiring.budgetSeams?.fetchFn
|
|
2678
2772
|
const harvestDeps = {
|
|
2679
2773
|
shutdownSignal: AbortSignal.any([
|
|
2680
2774
|
this.localHarvestShutdown.signal,
|
|
@@ -2693,6 +2787,7 @@ class DispatchLoop {
|
|
|
2693
2787
|
uuids,
|
|
2694
2788
|
clock,
|
|
2695
2789
|
instance: `${this.host}-harvest-${ids('inst')}`,
|
|
2790
|
+
...(fetchFn !== undefined ? { fetchFn } : {}),
|
|
2696
2791
|
...(this.repoLeaseHolder !== undefined ? { leaseHolder: this.repoLeaseHolder } : {}),
|
|
2697
2792
|
holdsAuthority: () => this.holdsRepoAuthority(),
|
|
2698
2793
|
sessionEnv: {
|
|
@@ -2723,6 +2818,7 @@ class DispatchLoop {
|
|
|
2723
2818
|
this.repoIdentity,
|
|
2724
2819
|
harvestDeps.instance,
|
|
2725
2820
|
'runner',
|
|
2821
|
+
fetchFn,
|
|
2726
2822
|
)
|
|
2727
2823
|
let remoteRunnerStore: RemoteBuildStore | undefined
|
|
2728
2824
|
let preparedRun: { run: string } | undefined
|
|
@@ -2756,8 +2852,13 @@ class DispatchLoop {
|
|
|
2756
2852
|
id: prepared.run,
|
|
2757
2853
|
leaseHolder: this.repoLeaseHolder ?? harvestDeps.instance,
|
|
2758
2854
|
},
|
|
2855
|
+
fetchFn,
|
|
2759
2856
|
)
|
|
2760
|
-
remoteRunnerStore = new RemoteBuildStore({
|
|
2857
|
+
remoteRunnerStore = new RemoteBuildStore({
|
|
2858
|
+
url: storeRef,
|
|
2859
|
+
token: buildScoped,
|
|
2860
|
+
...(fetchFn !== undefined ? { fetchFn } : {}),
|
|
2861
|
+
})
|
|
2761
2862
|
}
|
|
2762
2863
|
const sessionEnv = {
|
|
2763
2864
|
...harvestDeps.sessionEnv,
|
|
@@ -2767,11 +2868,12 @@ class DispatchLoop {
|
|
|
2767
2868
|
}
|
|
2768
2869
|
let renewalFailure: unknown
|
|
2769
2870
|
renew = setInterval(() => {
|
|
2770
|
-
void ticketGrantRequest(
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
id: issued.grant.id,
|
|
2774
|
-
|
|
2871
|
+
void ticketGrantRequest(
|
|
2872
|
+
ticketUrl,
|
|
2873
|
+
issued.token,
|
|
2874
|
+
{ action: 'renew', repo: this.repoIdentity, id: issued.grant.id },
|
|
2875
|
+
fetchFn,
|
|
2876
|
+
).catch((error) => {
|
|
2775
2877
|
renewalFailure = error
|
|
2776
2878
|
})
|
|
2777
2879
|
}, 60_000)
|
|
@@ -2781,7 +2883,10 @@ class DispatchLoop {
|
|
|
2781
2883
|
this.opts.targetRepo,
|
|
2782
2884
|
undefined,
|
|
2783
2885
|
this.wiring.plugins,
|
|
2784
|
-
|
|
2886
|
+
{
|
|
2887
|
+
...(this.opts.repository !== undefined ? { repository: this.repoIdentity } : {}),
|
|
2888
|
+
...this.wiring.budgetSeams,
|
|
2889
|
+
},
|
|
2785
2890
|
)
|
|
2786
2891
|
const result = await new HarvestRunner({
|
|
2787
2892
|
...harvestDeps,
|
|
@@ -2804,6 +2909,9 @@ class DispatchLoop {
|
|
|
2804
2909
|
await remoteRunnerStore.close()
|
|
2805
2910
|
}
|
|
2806
2911
|
} finally {
|
|
2912
|
+
// Revocation is compensation, not new work: it keeps global fetch
|
|
2913
|
+
// and its own 15 s bound so a work-deadline stop still releases
|
|
2914
|
+
// the grant rather than leaving it to expiry.
|
|
2807
2915
|
await ticketGrantRequest(ticketUrl, ticketToken, {
|
|
2808
2916
|
action: 'revoke',
|
|
2809
2917
|
repo: this.repoIdentity,
|
|
@@ -2826,14 +2934,23 @@ class DispatchLoop {
|
|
|
2826
2934
|
leaseHolder: this.repoLeaseHolder ?? harvestDeps.instance,
|
|
2827
2935
|
},
|
|
2828
2936
|
})
|
|
2829
|
-
const scoped = await (this.wiring.credentialIssuer ?? delegateCredential)(
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2937
|
+
const scoped = await (this.wiring.credentialIssuer ?? delegateCredential)(
|
|
2938
|
+
storeRef,
|
|
2939
|
+
token,
|
|
2940
|
+
{
|
|
2941
|
+
kind: 'harvest-runner',
|
|
2942
|
+
execution: harvestDeps.instance,
|
|
2943
|
+
repo: this.repoIdentity,
|
|
2944
|
+
id: prepared.run,
|
|
2945
|
+
leaseHolder: this.repoLeaseHolder ?? harvestDeps.instance,
|
|
2946
|
+
},
|
|
2947
|
+
fetchFn,
|
|
2948
|
+
)
|
|
2949
|
+
const runnerStore = new RemoteBuildStore({
|
|
2950
|
+
url: storeRef,
|
|
2951
|
+
token: scoped,
|
|
2952
|
+
...(fetchFn !== undefined ? { fetchFn } : {}),
|
|
2835
2953
|
})
|
|
2836
|
-
const runnerStore = new RemoteBuildStore({ url: storeRef, token: scoped })
|
|
2837
2954
|
try {
|
|
2838
2955
|
const runnerTickets =
|
|
2839
2956
|
harvestDeps.config.tickets.source === 'hosted'
|
|
@@ -2852,7 +2969,10 @@ class DispatchLoop {
|
|
|
2852
2969
|
storeRef,
|
|
2853
2970
|
}).localStateRoot,
|
|
2854
2971
|
this.wiring.plugins,
|
|
2855
|
-
|
|
2972
|
+
{
|
|
2973
|
+
...(this.opts.repository !== undefined ? { repository: this.repoIdentity } : {}),
|
|
2974
|
+
...this.wiring.budgetSeams,
|
|
2975
|
+
},
|
|
2856
2976
|
)
|
|
2857
2977
|
: harvestDeps.tickets
|
|
2858
2978
|
return await new HarvestRunner({
|
|
@@ -3013,6 +3133,7 @@ class DispatchLoop {
|
|
|
3013
3133
|
id: prepared.run,
|
|
3014
3134
|
leaseHolder: this.repoLeaseHolder ?? execution,
|
|
3015
3135
|
},
|
|
3136
|
+
this.wiring.budgetSeams?.fetchFn,
|
|
3016
3137
|
),
|
|
3017
3138
|
}
|
|
3018
3139
|
: undefined
|
|
@@ -3034,14 +3155,16 @@ class DispatchLoop {
|
|
|
3034
3155
|
repo,
|
|
3035
3156
|
execution,
|
|
3036
3157
|
'runner',
|
|
3158
|
+
this.wiring.budgetSeams?.fetchFn,
|
|
3037
3159
|
)
|
|
3038
3160
|
ticketAuthority = { url: ticketConfig.url, token: issued.token, id: issued.grant.id }
|
|
3039
3161
|
renewTickets = setInterval(() => {
|
|
3040
|
-
void ticketGrantRequest(
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
id: issued.grant.id,
|
|
3044
|
-
|
|
3162
|
+
void ticketGrantRequest(
|
|
3163
|
+
ticketConfig.url!,
|
|
3164
|
+
issued.token,
|
|
3165
|
+
{ action: 'renew', repo, id: issued.grant.id },
|
|
3166
|
+
this.wiring.budgetSeams?.fetchFn,
|
|
3167
|
+
).catch(() => {
|
|
3045
3168
|
// Expiry fails subsequent reads closed; the guest cannot regain project authority.
|
|
3046
3169
|
})
|
|
3047
3170
|
}, 60_000)
|
|
@@ -3144,6 +3267,7 @@ class DispatchLoop {
|
|
|
3144
3267
|
}
|
|
3145
3268
|
} finally {
|
|
3146
3269
|
if (renewTickets) clearInterval(renewTickets)
|
|
3270
|
+
// Compensation keeps global fetch and its own 15 s bound (see above).
|
|
3147
3271
|
if (ticketAuthority && !detached.value)
|
|
3148
3272
|
await ticketGrantRequest(ticketAuthority.url, ticketAuthority.token, {
|
|
3149
3273
|
action: 'revoke',
|
|
@@ -3397,6 +3521,25 @@ class DispatchLoop {
|
|
|
3397
3521
|
| { original: string; first: string; last: string; count: number }
|
|
3398
3522
|
| undefined
|
|
3399
3523
|
|
|
3524
|
+
private ticketsPrepared = false
|
|
3525
|
+
|
|
3526
|
+
/** The ticket source's deferred preparation, at the tick boundary until it
|
|
3527
|
+
* succeeds once. A transient failure is an ordinary tick failure (the next
|
|
3528
|
+
* tick retries it); any other failure is fatal to the run. */
|
|
3529
|
+
private async prepareTickets(): Promise<void> {
|
|
3530
|
+
if (this.ticketsPrepared) return
|
|
3531
|
+
const prepare = this.wiring.prepareTickets
|
|
3532
|
+
if (prepare !== undefined) {
|
|
3533
|
+
try {
|
|
3534
|
+
await prepare()
|
|
3535
|
+
} catch (error) {
|
|
3536
|
+
if (isTransientRemoteFailure(error)) throw error
|
|
3537
|
+
throw new FatalTicketPreparationError(error)
|
|
3538
|
+
}
|
|
3539
|
+
}
|
|
3540
|
+
this.ticketsPrepared = true
|
|
3541
|
+
}
|
|
3542
|
+
|
|
3400
3543
|
/** A tick stopped by a fenced effect is not a failed tick: publish no
|
|
3401
3544
|
* `tick-failed`, abandon the open boundary (a successor's or our own next
|
|
3402
3545
|
* `beginRepoTick` overwrites it), and resolve the lease. That either stops
|
|
@@ -3538,7 +3681,12 @@ class DispatchLoop {
|
|
|
3538
3681
|
await this.settlePendingPublication(slug)
|
|
3539
3682
|
} catch (error) {
|
|
3540
3683
|
// A lapsed run publishes nothing; the successor settles from durable facts.
|
|
3541
|
-
|
|
3684
|
+
// A deadline-deferred recovery parks the request for a later invocation.
|
|
3685
|
+
if (
|
|
3686
|
+
!(error instanceof ForgeRequestDeferred) &&
|
|
3687
|
+
!isRecoveryDeferred(error) &&
|
|
3688
|
+
!isRepositoryAuthorityLapse(error)
|
|
3689
|
+
)
|
|
3542
3690
|
throw error
|
|
3543
3691
|
}
|
|
3544
3692
|
}
|
|
@@ -3552,6 +3700,10 @@ class DispatchLoop {
|
|
|
3552
3700
|
cleanupPending: boolean
|
|
3553
3701
|
identity?: BuildExecutionHandle['identity']
|
|
3554
3702
|
}): Promise<void> {
|
|
3703
|
+
// Work abandoned at a bounded invocation's deadline records no failure:
|
|
3704
|
+
// the write would be cancelled anyway, and the abort is not a failure.
|
|
3705
|
+
const work = this.opts.invocationBudget?.work
|
|
3706
|
+
if (work?.aborted && invocationSignal() === work) return
|
|
3555
3707
|
if (await this.dispatcher.holdForMissingAccounts(input.error)) return
|
|
3556
3708
|
// The failed executor may have appended through its own handle.
|
|
3557
3709
|
await this.repoView.refreshBuild(input.slug)
|
|
@@ -3635,6 +3787,7 @@ class DispatchLoop {
|
|
|
3635
3787
|
this.wiring.storeRef,
|
|
3636
3788
|
this.wiring.token,
|
|
3637
3789
|
{ kind: 'build-runner', id: slug },
|
|
3790
|
+
this.wiring.budgetSeams?.fetchFn,
|
|
3638
3791
|
),
|
|
3639
3792
|
}
|
|
3640
3793
|
: undefined
|
|
@@ -3786,7 +3939,7 @@ class DispatchLoop {
|
|
|
3786
3939
|
if (this.activeBuildRuns.get(slug)?.reservation === reservation) {
|
|
3787
3940
|
this.activeBuildRuns.delete(slug)
|
|
3788
3941
|
}
|
|
3789
|
-
if (error instanceof ForgeRequestDeferred) {
|
|
3942
|
+
if (error instanceof ForgeRequestDeferred || isRecoveryDeferred(error)) {
|
|
3790
3943
|
if (leaseClaimed) await this.repoView.releaseLease(slug, instance)
|
|
3791
3944
|
await this.repoView.refreshBuild(slug)
|
|
3792
3945
|
return 'already-active'
|
|
@@ -4273,7 +4426,7 @@ class DispatchLoop {
|
|
|
4273
4426
|
(this.opts.once !== true && this.refresh !== undefined && !this.refresh.admitted)
|
|
4274
4427
|
)
|
|
4275
4428
|
return
|
|
4276
|
-
if (this.opts.once !== true) this.refresh?.activity(buildSnapshot
|
|
4429
|
+
if (this.opts.once !== true) this.refresh?.activity(hasActiveBuilds(buildSnapshot))
|
|
4277
4430
|
|
|
4278
4431
|
// Polling continues while the operator types. Keep the prompt bound to the
|
|
4279
4432
|
// captured build/escalations, shrink it around externally answered ids, and
|
|
@@ -4318,7 +4471,7 @@ class DispatchLoop {
|
|
|
4318
4471
|
configSnapshot.config.capacity,
|
|
4319
4472
|
this.wiring.clock(),
|
|
4320
4473
|
{
|
|
4321
|
-
|
|
4474
|
+
claims: claimDemand(repositoryEvents),
|
|
4322
4475
|
openPrs: {
|
|
4323
4476
|
policy: configSnapshot.config.policy,
|
|
4324
4477
|
engaged: repositoryEvents.openPrBackpressure !== undefined,
|
|
@@ -4578,8 +4731,13 @@ class DispatchLoop {
|
|
|
4578
4731
|
const requestedAt = this.wiring.clock().getTime()
|
|
4579
4732
|
const granted = await this.wiring.store
|
|
4580
4733
|
.claimRepoLease(this.repoIdentity, holder, lease.ttlMs)
|
|
4581
|
-
.catch(() =>
|
|
4734
|
+
.catch(() => {
|
|
4735
|
+
// A rejected claim request may still have committed server-side.
|
|
4736
|
+
this.repoLeaseClaimAmbiguous = true
|
|
4737
|
+
return false
|
|
4738
|
+
})
|
|
4582
4739
|
if (!granted || this.superseded) return false
|
|
4740
|
+
this.repoLeaseClaimAmbiguous = false
|
|
4583
4741
|
this.leaseGeneration++
|
|
4584
4742
|
this.heldLease = lease
|
|
4585
4743
|
this.repoLeaseValidUntil = requestedAt + lease.ttlMs
|
|
@@ -4697,6 +4855,10 @@ class DispatchLoop {
|
|
|
4697
4855
|
* lease no longer renewable hands the decision to the resolver; it never
|
|
4698
4856
|
* concludes takeover by itself. */
|
|
4699
4857
|
private restartRepoLeaseHeartbeat(): void {
|
|
4858
|
+
// In a bounded invocation the timer is created inside the work phase, so
|
|
4859
|
+
// its beats inherit the work signal and fail after the work deadline. The
|
|
4860
|
+
// unreachable-store branch below tolerates that, the lease TTL far
|
|
4861
|
+
// exceeds the teardown reserve, and the release runs under `final`.
|
|
4700
4862
|
this.stopRepoLeaseHeartbeat()
|
|
4701
4863
|
const holder = this.repoLeaseHolder
|
|
4702
4864
|
const lease = this.heldLease
|
|
@@ -5320,6 +5482,99 @@ class DispatchLoop {
|
|
|
5320
5482
|
this.upgradeController.start()
|
|
5321
5483
|
}
|
|
5322
5484
|
|
|
5485
|
+
/** The single `--once` pass: one tick, its drain, settlement publication,
|
|
5486
|
+
* and one delivery pass per configured hook. */
|
|
5487
|
+
private async onePass(): Promise<void> {
|
|
5488
|
+
// Prepare tickets before the background triage read and single tick.
|
|
5489
|
+
const initial = await this.prepareTickets()
|
|
5490
|
+
.then(() => {
|
|
5491
|
+
this.triageSampler?.poke()
|
|
5492
|
+
return this.dispatcherTick(true)
|
|
5493
|
+
})
|
|
5494
|
+
.catch(async (error: unknown) => {
|
|
5495
|
+
if (isRepositoryAuthorityLapse(error)) {
|
|
5496
|
+
await this.settleAuthorityLapse()
|
|
5497
|
+
return emptyTickReport()
|
|
5498
|
+
}
|
|
5499
|
+
// A bounded invocation's work deadline cancelled the tick: a budget
|
|
5500
|
+
// stop, never a tick failure.
|
|
5501
|
+
if (this.budgetStopped()) return emptyTickReport()
|
|
5502
|
+
if (error instanceof FatalTicketPreparationError) throw error.cause
|
|
5503
|
+
await this.reportTickFailure(error)
|
|
5504
|
+
if (this.forgePublicationFailed || this.pendingTickFailure !== undefined) throw error
|
|
5505
|
+
throw new DispatchTickFailedError(error)
|
|
5506
|
+
})
|
|
5507
|
+
const initialPrinted = this.printReport(initial, false)
|
|
5508
|
+
await this.drainInFlight()
|
|
5509
|
+
// Tail stage: a spent invocation budget publishes nothing new; the next
|
|
5510
|
+
// invocation reports these settlements.
|
|
5511
|
+
const settledReports =
|
|
5512
|
+
this.opts.invocationBudget !== undefined && this.pastDeadline()
|
|
5513
|
+
? []
|
|
5514
|
+
: await this.publishSettlementReports()
|
|
5515
|
+
let settledPrinted = false
|
|
5516
|
+
for (const report of settledReports) {
|
|
5517
|
+
settledPrinted = this.printReport(report, false) || settledPrinted
|
|
5518
|
+
}
|
|
5519
|
+
if (!initialPrinted && !settledPrinted) {
|
|
5520
|
+
this.printReport(emptyTickReport())
|
|
5521
|
+
}
|
|
5522
|
+
// One delivery pass per configured hook; the next invocation retries.
|
|
5523
|
+
if (!this.pastDeadline()) await this.drainHooksOnce()
|
|
5524
|
+
}
|
|
5525
|
+
|
|
5526
|
+
/** The bounded `--once` pass (hosted cron). The work pass runs under the
|
|
5527
|
+
* budget's work signal and is abandoned, not awaited, at the work deadline.
|
|
5528
|
+
* Teardown then runs as two independent racers bounded by the cleanup
|
|
5529
|
+
* deadline — durable provisioning abandonment beside the optional steps,
|
|
5530
|
+
* so a stall in one cannot skip the other — and the repository lease
|
|
5531
|
+
* release is bounded by the hard deadline. */
|
|
5532
|
+
private async boundedPass(budget: InvocationBudget): Promise<void> {
|
|
5533
|
+
try {
|
|
5534
|
+
this.startInput()
|
|
5535
|
+
this.startRendering()
|
|
5536
|
+
if (this.pastDeadline()) {
|
|
5537
|
+
this.deadlineStop = true
|
|
5538
|
+
return
|
|
5539
|
+
}
|
|
5540
|
+
const pass = await untilAborted(
|
|
5541
|
+
withInvocationSignal(budget.work, () => this.onePass()),
|
|
5542
|
+
budget.work,
|
|
5543
|
+
)
|
|
5544
|
+
if (!pass.settled || this.pastDeadline()) this.deadlineStop = true
|
|
5545
|
+
} finally {
|
|
5546
|
+
await this.boundedTeardown(budget)
|
|
5547
|
+
}
|
|
5548
|
+
}
|
|
5549
|
+
|
|
5550
|
+
private async boundedTeardown(budget: InvocationBudget): Promise<void> {
|
|
5551
|
+
// Whether or not the deadline fired, no launch may start during
|
|
5552
|
+
// teardown: provisioning abandonment runs beside execution teardown.
|
|
5553
|
+
this.onWorkDeadline()
|
|
5554
|
+
const provisioning = untilAborted(
|
|
5555
|
+
withInvocationSignal(budget.cleanup, () => this.dispatcher.stopProvisioning()),
|
|
5556
|
+
budget.cleanup,
|
|
5557
|
+
)
|
|
5558
|
+
const optional = untilAborted(
|
|
5559
|
+
withInvocationSignal(budget.cleanup, async () => {
|
|
5560
|
+
this.localHarvestShutdown.abort()
|
|
5561
|
+
await this.stopHooks()
|
|
5562
|
+
await this.stopBuildExecutions()
|
|
5563
|
+
await this.stopLocalHarvest()
|
|
5564
|
+
await this.stopHostedHarvest()
|
|
5565
|
+
await this.finishRendering()
|
|
5566
|
+
}),
|
|
5567
|
+
budget.cleanup,
|
|
5568
|
+
)
|
|
5569
|
+
const cleanup = await Promise.allSettled([provisioning, optional])
|
|
5570
|
+
await untilAborted(
|
|
5571
|
+
withInvocationSignal(budget.final, () => this.releaseRepoLease()),
|
|
5572
|
+
budget.final,
|
|
5573
|
+
)
|
|
5574
|
+
const failed = cleanup.find((result) => result.status === 'rejected')
|
|
5575
|
+
if (failed !== undefined) throw failed.reason
|
|
5576
|
+
}
|
|
5577
|
+
|
|
5323
5578
|
async run(): Promise<void> {
|
|
5324
5579
|
// Before the `--once` branch, so both modes report it exactly once.
|
|
5325
5580
|
this.reportRoleDiagnostics()
|
|
@@ -5327,12 +5582,40 @@ class DispatchLoop {
|
|
|
5327
5582
|
const missing = this.missingAccounts(this.wiring.inspectAccounts?.() ?? this.opts.env)
|
|
5328
5583
|
if (missing.length) throw new MissingAccountCredentialsError(missing)
|
|
5329
5584
|
}
|
|
5585
|
+
const budget = this.opts.once === true ? this.opts.invocationBudget : undefined
|
|
5586
|
+
if (budget === undefined) return this.supervise()
|
|
5587
|
+
if (budget.work.aborted) this.onWorkDeadline()
|
|
5588
|
+
else budget.work.addEventListener('abort', this.onWorkDeadline, { once: true })
|
|
5589
|
+
try {
|
|
5590
|
+
await this.supervise(budget)
|
|
5591
|
+
} finally {
|
|
5592
|
+
budget.work.removeEventListener('abort', this.onWorkDeadline)
|
|
5593
|
+
// The initial claim request failed, possibly after the server committed
|
|
5594
|
+
// it. The release is exact-holder, so it is harmless when nothing was
|
|
5595
|
+
// committed and never touches a peer's lease.
|
|
5596
|
+
if (this.repoLeaseClaimAmbiguous && this.repoLeaseHolder === undefined) {
|
|
5597
|
+
await untilAborted(
|
|
5598
|
+
withInvocationSignal(budget.final, () =>
|
|
5599
|
+
this.wiring.store.releaseRepoLease(this.repoIdentity, this.runId).catch(() => {}),
|
|
5600
|
+
),
|
|
5601
|
+
budget.final,
|
|
5602
|
+
)
|
|
5603
|
+
}
|
|
5604
|
+
}
|
|
5605
|
+
}
|
|
5606
|
+
|
|
5607
|
+
private async supervise(budget?: InvocationBudget): Promise<void> {
|
|
5330
5608
|
// Repository supervisor lease (§12): two invocations for one repository
|
|
5331
5609
|
// never both act. A losing invocation records the yield and performs no
|
|
5332
5610
|
// claims, launches, or publications. The holder is the invocation's
|
|
5333
5611
|
// journaling run id — the same string every journal payload carries.
|
|
5334
5612
|
const holder = this.runId
|
|
5335
5613
|
if (!(await this.ensureRepoLease(holder))) {
|
|
5614
|
+
if (budget !== undefined && this.budgetStopped()) {
|
|
5615
|
+
// The claim was cut off by the work deadline, not refused by a peer.
|
|
5616
|
+
this.deadlineStop = true
|
|
5617
|
+
return
|
|
5618
|
+
}
|
|
5336
5619
|
await this.recordTickYielded()
|
|
5337
5620
|
if ((!this.dashboard && this.opts.kernelRunId === undefined) || this.opts.once) {
|
|
5338
5621
|
const peer = (await this.wiring.store.getRepo(this.repoIdentity).catch(() => null))?.lease
|
|
@@ -5353,6 +5636,7 @@ class DispatchLoop {
|
|
|
5353
5636
|
if (!this.dashboard) {
|
|
5354
5637
|
this.say(`ab dispatch — one pass over ${this.opts.targetRepo} (capacity ${capacity})`)
|
|
5355
5638
|
}
|
|
5639
|
+
if (budget !== undefined) return this.boundedPass(budget)
|
|
5356
5640
|
// Render BEFORE the tick and until the drain finishes, so the operator
|
|
5357
5641
|
// watches the initial pass's builds change state while they run. The
|
|
5358
5642
|
// render loop only reads: `--once` still calls tick() exactly ONCE, so
|
|
@@ -5365,28 +5649,7 @@ class DispatchLoop {
|
|
|
5365
5649
|
// lease and any provisioning state are released for the next
|
|
5366
5650
|
// invocation.
|
|
5367
5651
|
if (this.pastDeadline()) return
|
|
5368
|
-
|
|
5369
|
-
this.triageSampler?.poke()
|
|
5370
|
-
const initial = await this.dispatcherTick(true).catch(async (error: unknown) => {
|
|
5371
|
-
if (isRepositoryAuthorityLapse(error)) {
|
|
5372
|
-
await this.settleAuthorityLapse()
|
|
5373
|
-
return emptyTickReport()
|
|
5374
|
-
}
|
|
5375
|
-
await this.reportTickFailure(error)
|
|
5376
|
-
throw error
|
|
5377
|
-
})
|
|
5378
|
-
const initialPrinted = this.printReport(initial, false)
|
|
5379
|
-
await this.drainInFlight()
|
|
5380
|
-
const settledReports = await this.publishSettlementReports()
|
|
5381
|
-
let settledPrinted = false
|
|
5382
|
-
for (const report of settledReports) {
|
|
5383
|
-
settledPrinted = this.printReport(report, false) || settledPrinted
|
|
5384
|
-
}
|
|
5385
|
-
if (!initialPrinted && !settledPrinted) {
|
|
5386
|
-
this.printReport(emptyTickReport())
|
|
5387
|
-
}
|
|
5388
|
-
// One delivery pass per configured hook; the next invocation retries.
|
|
5389
|
-
if (!this.pastDeadline()) await this.drainHooksOnce()
|
|
5652
|
+
await this.onePass()
|
|
5390
5653
|
} finally {
|
|
5391
5654
|
this.localHarvestShutdown.abort()
|
|
5392
5655
|
await this.stopHooks()
|
|
@@ -5419,15 +5682,19 @@ class DispatchLoop {
|
|
|
5419
5682
|
let startup = true
|
|
5420
5683
|
// Triage counts are sampled between ticks, never inside one: the read
|
|
5421
5684
|
// runs in the background and the next publication carries its value.
|
|
5422
|
-
|
|
5685
|
+
// Both wait until the ticket source is prepared.
|
|
5686
|
+
if (this.ticketsPrepared || this.wiring.prepareTickets === undefined)
|
|
5687
|
+
this.triageSampler?.poke()
|
|
5423
5688
|
while (!this.watchStopped && !this.superseded) {
|
|
5424
5689
|
let failed = false
|
|
5425
5690
|
try {
|
|
5691
|
+
await this.prepareTickets()
|
|
5426
5692
|
const report = await this.dispatcherTick(startup)
|
|
5427
5693
|
this.printReport(report, this.harvestInFlight === undefined)
|
|
5428
5694
|
startup = false
|
|
5429
5695
|
} catch (error) {
|
|
5430
5696
|
if (this.forgePublicationFailed) throw error
|
|
5697
|
+
if (error instanceof FatalTicketPreparationError) throw error.cause
|
|
5431
5698
|
if (isRepositoryAuthorityLapse(error)) {
|
|
5432
5699
|
await this.settleAuthorityLapse()
|
|
5433
5700
|
} else {
|
|
@@ -5435,7 +5702,7 @@ class DispatchLoop {
|
|
|
5435
5702
|
await this.reportTickFailure(error)
|
|
5436
5703
|
}
|
|
5437
5704
|
}
|
|
5438
|
-
this.triageSampler?.poke()
|
|
5705
|
+
if (this.ticketsPrepared) this.triageSampler?.poke()
|
|
5439
5706
|
await this.syncHooks()
|
|
5440
5707
|
if (this.watchStopped || this.superseded) break
|
|
5441
5708
|
await sleep(failed || this.pendingTickFailure ? Math.max(intervalMs, 1000) : intervalMs)
|
|
@@ -5492,7 +5759,11 @@ async function fetchOriginModeConfig(
|
|
|
5492
5759
|
env: opts.env,
|
|
5493
5760
|
repository,
|
|
5494
5761
|
exec: opts.exec,
|
|
5495
|
-
...(transport !== undefined
|
|
5762
|
+
...(transport !== undefined
|
|
5763
|
+
? { transport }
|
|
5764
|
+
: opts.invocationBudget !== undefined
|
|
5765
|
+
? { fetchFn: budgetedFetch() }
|
|
5766
|
+
: {}),
|
|
5496
5767
|
})
|
|
5497
5768
|
const readFile = forge.readFile
|
|
5498
5769
|
if (readFile === undefined) {
|
|
@@ -5602,6 +5873,12 @@ async function resolveOriginModeState(
|
|
|
5602
5873
|
* path — is the served repository.
|
|
5603
5874
|
*/
|
|
5604
5875
|
export async function abDispatch(opts: DispatchOpts): Promise<void> {
|
|
5876
|
+
// The invocation deadline also bounds every hosted retry this run causes.
|
|
5877
|
+
if (opts.deadlineAt === undefined) return abDispatchInScope(opts)
|
|
5878
|
+
return withRemoteRetryDeadline(opts.deadlineAt, () => abDispatchInScope(opts))
|
|
5879
|
+
}
|
|
5880
|
+
|
|
5881
|
+
async function abDispatchInScope(opts: DispatchOpts): Promise<void> {
|
|
5605
5882
|
if (opts.kernelRunId === undefined && !launchContext(opts.env)) {
|
|
5606
5883
|
opts = { ...opts, ...(await selectDispatchMode(opts)) }
|
|
5607
5884
|
}
|
|
@@ -5682,6 +5959,33 @@ export async function abDispatch(opts: DispatchOpts): Promise<void> {
|
|
|
5682
5959
|
return
|
|
5683
5960
|
}
|
|
5684
5961
|
if (opts.dispatchedBy !== undefined) throw new Error('--dispatched-by requires --viewer')
|
|
5962
|
+
const budget = opts.invocationBudget
|
|
5963
|
+
if (budget === undefined) return dispatchKernelPath(opts)
|
|
5964
|
+
if (opts.once !== true) throw new Error('invocationBudget requires a one-pass (--once) dispatch')
|
|
5965
|
+
if (opts.deadlineAt !== undefined && opts.deadlineAt !== budget.workDeadlineAt) {
|
|
5966
|
+
throw new Error('invocationBudget: an explicit deadlineAt must equal its work deadline')
|
|
5967
|
+
}
|
|
5968
|
+
if (budget.work.aborted) throw new InvocationBudgetExhaustedError()
|
|
5969
|
+
const bounded: DispatchOpts = { ...opts, deadlineAt: budget.workDeadlineAt }
|
|
5970
|
+
try {
|
|
5971
|
+
// Startup and the whole work pass carry the work signal: every builtin
|
|
5972
|
+
// adapter request they make is cancelled at the work deadline. Teardown
|
|
5973
|
+
// re-enters with its own signals.
|
|
5974
|
+
await withInvocationSignal(budget.work, () => dispatchKernelPath(bounded))
|
|
5975
|
+
} catch (error) {
|
|
5976
|
+
// A budget stop after `run-started` returns normally from the kernel, so
|
|
5977
|
+
// an error escaping here past the work deadline happened before the run
|
|
5978
|
+
// started: nothing durable was claimed.
|
|
5979
|
+
if (budget.work.aborted && !(error instanceof InvocationBudgetExhaustedError)) {
|
|
5980
|
+
throw new InvocationBudgetExhaustedError(undefined, { cause: error })
|
|
5981
|
+
}
|
|
5982
|
+
throw error
|
|
5983
|
+
}
|
|
5984
|
+
}
|
|
5985
|
+
|
|
5986
|
+
/** `abDispatch` after the viewer branch: origin config, repository state,
|
|
5987
|
+
* the interactive frontend, or the in-process kernel. */
|
|
5988
|
+
async function dispatchKernelPath(opts: DispatchOpts): Promise<void> {
|
|
5685
5989
|
if (opts.wire !== undefined && opts.nonStoreWire !== undefined) {
|
|
5686
5990
|
throw new Error('dispatch wire and nonStoreWire are mutually exclusive')
|
|
5687
5991
|
}
|
|
@@ -5917,8 +6221,12 @@ async function runDispatchKernel(
|
|
|
5917
6221
|
// wiring or production wiring can open state or perform side effects.
|
|
5918
6222
|
resolveForgeRegistration(config.forge, plugins)
|
|
5919
6223
|
let wired: DispatchWiring
|
|
6224
|
+
const budget = resolvedOpts.invocationBudget
|
|
5920
6225
|
if (resolvedOpts.nonStoreWire !== undefined) {
|
|
5921
|
-
const opened = openStoreForRepoState(state, {
|
|
6226
|
+
const opened = openStoreForRepoState(state, {
|
|
6227
|
+
env: resolvedOpts.env,
|
|
6228
|
+
...(budget !== undefined ? { openStore: budgetedProductionStore(budgetedFetch()) } : {}),
|
|
6229
|
+
})
|
|
5922
6230
|
const ports = await resolvedOpts.nonStoreWire(config, resolvedOpts, state, plugins)
|
|
5923
6231
|
wired = {
|
|
5924
6232
|
...ports,
|
|
@@ -6020,10 +6328,6 @@ async function runDispatchKernel(
|
|
|
6020
6328
|
},
|
|
6021
6329
|
)
|
|
6022
6330
|
|
|
6023
|
-
// Launch flags are durable repository setters. Omission writes nothing, so
|
|
6024
|
-
// another dispatcher cannot clobber the latest operator choice with a value
|
|
6025
|
-
// it inferred at startup. Fresh-repository fallbacks live in the reducer.
|
|
6026
|
-
await wiring.store.ensureRepo(state.repo)
|
|
6027
6331
|
// Every own lifecycle append goes through one view, restored from snapshots
|
|
6028
6332
|
// before the first of them, so a quiet invocation reads none of its own
|
|
6029
6333
|
// rows back and the final flush covers `run-stopped` too.
|
|
@@ -6037,48 +6341,71 @@ async function runDispatchKernel(
|
|
|
6037
6341
|
...(web !== undefined ? { onRepositoryFacts: (facts) => web.publishFacts(facts) } : {}),
|
|
6038
6342
|
})
|
|
6039
6343
|
web?.attachStore(wiring.store)
|
|
6040
|
-
|
|
6041
|
-
|
|
6042
|
-
|
|
6043
|
-
|
|
6044
|
-
|
|
6045
|
-
|
|
6046
|
-
|
|
6047
|
-
|
|
6048
|
-
|
|
6344
|
+
let started: Awaited<ReturnType<RepoViewStore['appendRepoWithArtifacts']>>
|
|
6345
|
+
try {
|
|
6346
|
+
// Launch flags are durable repository setters. Omission writes nothing, so
|
|
6347
|
+
// another dispatcher cannot clobber the latest operator choice with a value
|
|
6348
|
+
// it inferred at startup. Fresh-repository fallbacks live in the reducer.
|
|
6349
|
+
await wiring.store.ensureRepo(state.repo)
|
|
6350
|
+
await view.startJournal()
|
|
6351
|
+
const actor = humanActor(buildControlUser(resolvedOpts.env))
|
|
6352
|
+
if (resolvedOpts.intake !== undefined) {
|
|
6353
|
+
await view.appendRepo(state.repo, {
|
|
6354
|
+
actor,
|
|
6355
|
+
type: 'dispatcher.intake-set',
|
|
6356
|
+
payload: { enabled: resolvedOpts.intake, run: runId },
|
|
6357
|
+
})
|
|
6358
|
+
}
|
|
6049
6359
|
|
|
6050
|
-
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
|
|
6056
|
-
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6360
|
+
started = await view.appendRepoWithArtifacts(
|
|
6361
|
+
state.repo,
|
|
6362
|
+
[
|
|
6363
|
+
{
|
|
6364
|
+
kind: _effectiveConfigKind,
|
|
6365
|
+
content: effectiveBuildConfigContent(config),
|
|
6366
|
+
metadata: {
|
|
6367
|
+
run: runId,
|
|
6368
|
+
revision: 0,
|
|
6369
|
+
...(startupLocalOverrides ? { localOverrides: startupLocalOverrides } : {}),
|
|
6370
|
+
},
|
|
6060
6371
|
},
|
|
6372
|
+
],
|
|
6373
|
+
(deposited) => {
|
|
6374
|
+
const artifact = deposited[0]
|
|
6375
|
+
if (artifact === undefined) throw new Error('startup config deposit returned no artifact')
|
|
6376
|
+
return {
|
|
6377
|
+
actor: DISPATCHER,
|
|
6378
|
+
type: 'dispatcher.run-started',
|
|
6379
|
+
payload: {
|
|
6380
|
+
run: runId,
|
|
6381
|
+
...(launchContext(resolvedOpts.env)?.lineage
|
|
6382
|
+
? { lineage: launchContext(resolvedOpts.env)!.lineage }
|
|
6383
|
+
: {}),
|
|
6384
|
+
pid: process.pid,
|
|
6385
|
+
host: hostname(),
|
|
6386
|
+
effectiveConfig: { kind: artifact.kind, rev: artifact.revision },
|
|
6387
|
+
roleWarnings: startupWarnings(config, wiring.forge),
|
|
6388
|
+
},
|
|
6389
|
+
}
|
|
6061
6390
|
},
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
|
|
6068
|
-
|
|
6069
|
-
|
|
6070
|
-
|
|
6071
|
-
|
|
6072
|
-
|
|
6073
|
-
|
|
6074
|
-
|
|
6075
|
-
|
|
6076
|
-
|
|
6077
|
-
|
|
6078
|
-
|
|
6079
|
-
|
|
6080
|
-
},
|
|
6081
|
-
)
|
|
6391
|
+
)
|
|
6392
|
+
} catch (error) {
|
|
6393
|
+
if (budget === undefined || !budget.work.aborted) throw error
|
|
6394
|
+
// The work deadline cut a startup write off. The `run-started` deposit
|
|
6395
|
+
// may still have committed with its response lost, so the bounded
|
|
6396
|
+
// canonical repository value decides whether this run exists.
|
|
6397
|
+
const recordedStart = await stopAmbiguousStart(budget, wiring.store, state.repo, runId)
|
|
6398
|
+
await finalStep(budget, async () => {
|
|
6399
|
+
await wiring.releaseAccounts?.()
|
|
6400
|
+
if (resolvedOpts.wire === undefined) await wiring.store.close()
|
|
6401
|
+
}).catch(() => {})
|
|
6402
|
+
if (!recordedStart) throw new InvocationBudgetExhaustedError(undefined, { cause: error })
|
|
6403
|
+
if (resolvedOpts.silent !== true)
|
|
6404
|
+
resolvedOpts.stdout(
|
|
6405
|
+
'ab dispatch — invocation work deadline reached during startup; the run stopped, remaining work resumes next invocation',
|
|
6406
|
+
)
|
|
6407
|
+
return
|
|
6408
|
+
}
|
|
6082
6409
|
|
|
6083
6410
|
try {
|
|
6084
6411
|
await view.appendRepo(state.repo, {
|
|
@@ -6089,6 +6416,11 @@ async function runDispatchKernel(
|
|
|
6089
6416
|
|
|
6090
6417
|
const loop = new DispatchLoop(liveConfig, wiring, resolvedOpts, view)
|
|
6091
6418
|
await loop.run()
|
|
6419
|
+
if (loop.stoppedAtDeadline && resolvedOpts.silent !== true) {
|
|
6420
|
+
resolvedOpts.stdout(
|
|
6421
|
+
'ab dispatch — invocation work deadline reached; teardown complete, remaining work resumes next invocation',
|
|
6422
|
+
)
|
|
6423
|
+
}
|
|
6092
6424
|
const stopRequest =
|
|
6093
6425
|
resolvedOpts.kernelRunId && resolvedOpts.signal?.aborted
|
|
6094
6426
|
? (await readDispatcherRunFacts(wiring.store, state.repo, runId)).value.stopRequest
|
|
@@ -6099,39 +6431,90 @@ async function runDispatchKernel(
|
|
|
6099
6431
|
: typeof resolvedOpts.signal?.reason === 'string'
|
|
6100
6432
|
? resolvedOpts.signal.reason
|
|
6101
6433
|
: undefined
|
|
6102
|
-
await
|
|
6103
|
-
|
|
6104
|
-
type: 'dispatcher.run-stopped',
|
|
6105
|
-
payload: {
|
|
6106
|
-
run: runId,
|
|
6107
|
-
outcome: 'normal',
|
|
6108
|
-
exitCode: 0,
|
|
6109
|
-
...(stoppedSignal === undefined ? {} : { signal: stoppedSignal }),
|
|
6110
|
-
...(loop.supersededByPeer ? { reason: 'superseded' as const } : {}),
|
|
6111
|
-
},
|
|
6112
|
-
})
|
|
6113
|
-
} catch (error) {
|
|
6114
|
-
try {
|
|
6115
|
-
await view.appendRepo(state.repo, {
|
|
6434
|
+
await finalStep(budget, () =>
|
|
6435
|
+
view.appendRepo(state.repo, {
|
|
6116
6436
|
actor: DISPATCHER,
|
|
6117
6437
|
type: 'dispatcher.run-stopped',
|
|
6118
6438
|
payload: {
|
|
6119
6439
|
run: runId,
|
|
6120
|
-
outcome: '
|
|
6121
|
-
exitCode:
|
|
6122
|
-
|
|
6440
|
+
outcome: 'normal',
|
|
6441
|
+
exitCode: 0,
|
|
6442
|
+
...(stoppedSignal === undefined ? {} : { signal: stoppedSignal }),
|
|
6443
|
+
...(loop.supersededByPeer ? { reason: 'superseded' as const } : {}),
|
|
6123
6444
|
},
|
|
6124
|
-
})
|
|
6445
|
+
}),
|
|
6446
|
+
)
|
|
6447
|
+
} catch (error) {
|
|
6448
|
+
// A bounded invocation past its work deadline stopped on budget, however
|
|
6449
|
+
// the adapter wrapped the abort: a clean stop, not a loss.
|
|
6450
|
+
const budgetStop = budget?.work.aborted === true
|
|
6451
|
+
const tickFailed = error instanceof DispatchTickFailedError
|
|
6452
|
+
const original = tickFailed ? error.cause : error
|
|
6453
|
+
try {
|
|
6454
|
+
await finalStep(budget, () =>
|
|
6455
|
+
view.appendRepo(state.repo, {
|
|
6456
|
+
actor: DISPATCHER,
|
|
6457
|
+
type: 'dispatcher.run-stopped',
|
|
6458
|
+
payload: budgetStop
|
|
6459
|
+
? { run: runId, outcome: 'normal', exitCode: 0 }
|
|
6460
|
+
: {
|
|
6461
|
+
run: runId,
|
|
6462
|
+
outcome: tickFailed ? 'normal' : 'abnormal',
|
|
6463
|
+
exitCode: 1,
|
|
6464
|
+
error: original instanceof Error ? original.message : String(original),
|
|
6465
|
+
},
|
|
6466
|
+
}),
|
|
6467
|
+
)
|
|
6125
6468
|
} catch {
|
|
6126
6469
|
// Preserve the kernel failure; the supervising frontend records exit.
|
|
6127
6470
|
}
|
|
6128
|
-
throw
|
|
6471
|
+
if (!budgetStop) throw original
|
|
6129
6472
|
} finally {
|
|
6130
6473
|
// Every append this invocation made, `run-stopped` included, is in the
|
|
6131
6474
|
// view; leave the reduced state behind so the next cold process reads
|
|
6132
6475
|
// only what is newer than it.
|
|
6476
|
+
await finalStep(budget, async () => {
|
|
6477
|
+
await wiring.releaseAccounts?.()
|
|
6478
|
+
if (resolvedOpts.wire === undefined) await wiring.store.close()
|
|
6479
|
+
})
|
|
6480
|
+
}
|
|
6481
|
+
}
|
|
6482
|
+
|
|
6483
|
+
/** A bounded invocation whose startup the work deadline cut off: when the
|
|
6484
|
+
* `run-started` deposit committed anyway, record this run's normal stop so
|
|
6485
|
+
* the journal never holds a start without a stop. One read of the reduced
|
|
6486
|
+
* `repositoryReadFacts` value (its recent runs), never history, then at most
|
|
6487
|
+
* one append, all under the final signal. True when the run had started. */
|
|
6488
|
+
async function stopAmbiguousStart(
|
|
6489
|
+
budget: InvocationBudget,
|
|
6490
|
+
store: BuildStore,
|
|
6491
|
+
repo: string,
|
|
6492
|
+
run: string,
|
|
6493
|
+
): Promise<boolean> {
|
|
6494
|
+
let started = false
|
|
6495
|
+
await finalStep(budget, async () => {
|
|
6496
|
+
const recorded = await readDispatcherRunFacts(store, repo, run, false)
|
|
6497
|
+
if (recorded.value.start === undefined) return
|
|
6498
|
+
started = true
|
|
6499
|
+
await store.appendRepo(repo, {
|
|
6500
|
+
actor: DISPATCHER,
|
|
6501
|
+
type: 'dispatcher.run-stopped',
|
|
6502
|
+
payload: { run, outcome: 'normal', exitCode: 0 },
|
|
6503
|
+
})
|
|
6504
|
+
}).catch(() => {})
|
|
6505
|
+
return started
|
|
6506
|
+
}
|
|
6133
6507
|
|
|
6134
|
-
|
|
6135
|
-
|
|
6508
|
+
/** Run a final teardown step: under the budget's `final` signal and bounded
|
|
6509
|
+
* by it when the invocation is bounded, else exactly as before. A step that
|
|
6510
|
+
* misses the hard deadline is abandoned, never awaited past it. */
|
|
6511
|
+
async function finalStep(
|
|
6512
|
+
budget: InvocationBudget | undefined,
|
|
6513
|
+
step: () => Promise<unknown>,
|
|
6514
|
+
): Promise<void> {
|
|
6515
|
+
if (budget === undefined) {
|
|
6516
|
+
await step()
|
|
6517
|
+
return
|
|
6136
6518
|
}
|
|
6519
|
+
await untilAborted(withInvocationSignal(budget.final, step), budget.final)
|
|
6137
6520
|
}
|