@defrex/autobuild 0.13.0 → 1.0.0-beta.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 +5 -3
- package/SPEC.md +673 -99
- package/bin/ab-dispatch-kernel.ts +4 -6
- package/docs/architecture.md +322 -75
- package/docs/assets/headline-wide.png +0 -0
- package/docs/configuration.md +112 -12
- package/docs/hosted-service.md +20 -2
- package/docs/integration-tree.md +117 -0
- package/docs/landing-policy.md +150 -0
- package/docs/mcp.md +24 -0
- package/docs/migration-1.0.md +68 -0
- package/docs/operator-api.md +20 -9
- package/docs/remote-store-protocol.md +114 -9
- package/docs/remote-ticket-protocol.md +26 -5
- package/docs/restacking.md +79 -0
- package/docs/setup.md +49 -6
- package/docs/ticket-dependencies.md +69 -0
- package/docs/ticket-migration.md +8 -0
- package/package.json +4 -3
- package/packages/core/src/cli/attention.ts +40 -163
- package/packages/core/src/cli/build-control.ts +75 -55
- package/packages/core/src/cli/bulk-control.ts +3 -2
- package/packages/core/src/cli/context.ts +68 -78
- package/packages/core/src/cli/dashboard/actions.ts +6 -3
- package/packages/core/src/cli/dashboard/landing-display.ts +6 -0
- package/packages/core/src/cli/dashboard/live.ts +5 -0
- package/packages/core/src/cli/dashboard/model.ts +178 -40
- package/packages/core/src/cli/dashboard/poll.ts +15 -9
- package/packages/core/src/cli/dashboard/refresh.ts +176 -0
- package/packages/core/src/cli/dashboard/render.ts +78 -28
- package/packages/core/src/cli/dashboard/repository-poll.ts +57 -0
- package/packages/core/src/cli/dashboard/selection.ts +7 -1
- package/packages/core/src/cli/dashboard/tree.ts +107 -0
- package/packages/core/src/cli/dispatch-frontend.ts +173 -169
- package/packages/core/src/cli/dispatch-process.ts +14 -7
- package/packages/core/src/cli/dispatch-repository-feed.ts +196 -0
- package/packages/core/src/cli/dispatch.ts +397 -214
- package/packages/core/src/cli/dispatcher-liveness.ts +41 -21
- package/packages/core/src/cli/harvest.ts +71 -39
- package/packages/core/src/cli/help.ts +49 -32
- package/packages/core/src/cli/historical-build-state.ts +27 -0
- package/packages/core/src/cli/init-validation.ts +43 -2
- package/packages/core/src/cli/keyboard.ts +6 -0
- package/packages/core/src/cli/landings.ts +18 -0
- package/packages/core/src/cli/main.ts +52 -18
- package/packages/core/src/cli/mcp.ts +9 -0
- package/packages/core/src/cli/pr-attachments.ts +10 -13
- package/packages/core/src/cli/pr-summary-publication.ts +27 -60
- package/packages/core/src/cli/pr-summary.ts +43 -13
- package/packages/core/src/cli/publication-settlement.ts +177 -21
- package/packages/core/src/cli/repository-status.ts +49 -2
- package/packages/core/src/cli/status.ts +133 -36
- package/packages/core/src/cli/terminal-restore.ts +54 -0
- package/packages/core/src/cli/terminal.ts +16 -2
- package/packages/core/src/cli/terminals.ts +121 -219
- package/packages/core/src/cli/ticket-editor.ts +10 -3
- package/packages/core/src/cli/ticket.ts +115 -20
- package/packages/core/src/cli/upgrade-commit.ts +4 -0
- package/packages/core/src/cli/upgrade-compatibility.ts +2 -2
- package/packages/core/src/cli/upgrade-landing.ts +69 -0
- package/packages/core/src/cli/upgrade.ts +16 -0
- package/packages/core/src/cli/wait.ts +194 -91
- package/packages/core/src/cli/watch.ts +111 -109
- package/packages/core/src/config/landing.ts +22 -0
- package/packages/core/src/config/live.ts +1 -0
- package/packages/core/src/config/pipeline-source.ts +4 -3
- package/packages/core/src/config/schema.ts +3 -0
- package/packages/core/src/events/catalog.ts +48 -3
- package/packages/core/src/events/payloads.ts +295 -6
- package/packages/core/src/events/repository.ts +38 -3
- package/packages/core/src/integration/harness.ts +11 -2
- package/packages/core/src/kernel/__snapshots__/reducer-registry.test.ts.snap +3330 -119
- package/packages/core/src/kernel/auto-merge-default.ts +1 -0
- package/packages/core/src/kernel/auto-merge.ts +29 -4
- package/packages/core/src/kernel/build-identity.ts +94 -0
- package/packages/core/src/kernel/change-presence.ts +179 -0
- package/packages/core/src/kernel/dispatch-status.ts +17 -1
- package/packages/core/src/kernel/dispatcher-liveness.ts +10 -4
- package/packages/core/src/kernel/engine.ts +89 -2
- package/packages/core/src/kernel/generators/build-log.ts +23 -0
- package/packages/core/src/kernel/generators/leaf-restack-log.ts +110 -0
- package/packages/core/src/kernel/generators/node-restack-log.ts +94 -0
- package/packages/core/src/kernel/generators/repository-journals.ts +25 -3
- package/packages/core/src/kernel/harvest.ts +25 -23
- package/packages/core/src/kernel/integration-completeness.ts +81 -0
- package/packages/core/src/kernel/integration-landing.ts +263 -0
- package/packages/core/src/kernel/integration-stack.ts +36 -0
- package/packages/core/src/kernel/integration-state.ts +135 -0
- package/packages/core/src/kernel/landing-policy.ts +47 -0
- package/packages/core/src/kernel/landing-publication.ts +41 -0
- package/packages/core/src/kernel/landing-readiness.ts +67 -0
- package/packages/core/src/kernel/landing-state.ts +96 -0
- package/packages/core/src/kernel/leaf-restack-completion.ts +24 -0
- package/packages/core/src/kernel/leaf-restack-state.ts +73 -0
- package/packages/core/src/kernel/log-index-value.ts +38 -0
- package/packages/core/src/kernel/log-index.ts +35 -5
- package/packages/core/src/kernel/node-landing.ts +439 -0
- package/packages/core/src/kernel/node-parent.ts +184 -0
- package/packages/core/src/kernel/node-restack-state.ts +191 -0
- package/packages/core/src/kernel/node-restack-transaction.ts +210 -0
- package/packages/core/src/kernel/node-restack.ts +274 -0
- package/packages/core/src/kernel/read-facts.ts +704 -0
- package/packages/core/src/kernel/reconcile-head.ts +51 -0
- package/packages/core/src/kernel/reconcile-restack.ts +560 -0
- package/packages/core/src/kernel/reducer-registry.ts +153 -3
- package/packages/core/src/kernel/reducer.ts +121 -6
- package/packages/core/src/kernel/repository-attention.ts +179 -0
- package/packages/core/src/kernel/service-facts.ts +135 -0
- package/packages/core/src/kernel/snapshot-parent.ts +33 -0
- package/packages/core/src/kernel/terminal-guard.ts +133 -0
- package/packages/core/src/ontology.ts +9 -1
- package/packages/core/src/operator/annotations.ts +12 -0
- package/packages/core/src/operator/control.ts +11 -6
- package/packages/core/src/operator/index.ts +6 -0
- package/packages/core/src/operator/landings.ts +35 -0
- package/packages/core/src/operator/presentation.ts +1 -0
- package/packages/core/src/operator/protocol.ts +12 -3
- package/packages/core/src/operator/query.ts +40 -21
- package/packages/core/src/operator/read-view.ts +4 -13
- package/packages/core/src/operator/registry.ts +48 -19
- package/packages/core/src/operator/requests.ts +3 -22
- package/packages/core/src/operator/sandbox.ts +10 -9
- package/packages/core/src/operator/tickets.ts +57 -11
- package/packages/core/src/plugin-sdk/index.ts +13 -0
- package/packages/core/src/ports/forge/contract.ts +91 -3
- package/packages/core/src/ports/forge/fake.ts +142 -4
- package/packages/core/src/ports/forge/git-rewrite.ts +232 -0
- package/packages/core/src/ports/forge/github-readiness.ts +421 -0
- package/packages/core/src/ports/forge/github.ts +631 -35
- package/packages/core/src/ports/forge/local-git.ts +119 -5
- package/packages/core/src/ports/forge/readiness.ts +99 -0
- package/packages/core/src/ports/tickets/contract.ts +41 -0
- package/packages/core/src/ports/tickets/create.ts +8 -1
- package/packages/core/src/ports/tickets/fake.ts +32 -1
- package/packages/core/src/ports/tickets/file-codec.ts +7 -0
- package/packages/core/src/ports/tickets/file.ts +18 -1
- package/packages/core/src/ports/tickets/hosted-index.ts +2 -0
- package/packages/core/src/ports/tickets/linear.ts +124 -4
- package/packages/core/src/ports/tickets/migration.ts +25 -1
- package/packages/core/src/ports/tickets/operations.ts +7 -2
- package/packages/core/src/ports/tickets/remote-protocol.ts +19 -0
- package/packages/core/src/ports/tickets/remote.ts +10 -1
- package/packages/core/src/ports/tickets/revision.ts +3 -1
- package/packages/core/src/ports/tickets/tree.ts +148 -0
- package/packages/core/src/ports/tickets/update.ts +15 -2
- package/packages/core/src/ports/types.ts +135 -5
- package/packages/core/src/ports/workspace/git-worktree.ts +2 -1
- package/packages/core/src/ports/workspace/provider-capabilities.ts +1 -1
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +60 -3
- package/packages/core/src/processes/build-child.ts +6 -6
- package/packages/core/src/processes/build-runner.ts +586 -87
- package/packages/core/src/processes/dispatch-failure-budget.ts +5 -4
- package/packages/core/src/processes/dispatcher-selectors.ts +15 -9
- package/packages/core/src/processes/dispatcher.ts +2239 -357
- package/packages/core/src/processes/execution-no-progress.ts +46 -1
- package/packages/core/src/processes/harvest-execution-state.ts +15 -9
- package/packages/core/src/processes/harvest-runner.ts +34 -70
- package/packages/core/src/processes/harvest.ts +38 -15
- package/packages/core/src/processes/infrastructure-failure-budget.ts +13 -15
- package/packages/core/src/processes/orchestrator-tick.ts +2 -2
- package/packages/core/src/processes/publication-loss.ts +35 -21
- package/packages/core/src/processes/publication-state.ts +30 -5
- package/packages/core/src/processes/repo-view.ts +244 -1130
- package/packages/core/src/processes/tick-publication.ts +110 -0
- package/packages/core/src/store/adapter.ts +23 -0
- package/packages/core/src/store/build-scope.ts +35 -0
- package/packages/core/src/store/contract.ts +909 -0
- package/packages/core/src/store/digest.ts +52 -4
- package/packages/core/src/store/local/schema.ts +26 -13
- package/packages/core/src/store/local/store.ts +296 -55
- package/packages/core/src/store/memory.ts +181 -30
- package/packages/core/src/store/phase-session.ts +34 -0
- package/packages/core/src/store/reduced-reads.ts +240 -0
- package/packages/core/src/store/reducer-value-shapes.json +18323 -0
- package/packages/core/src/store/reducer-value-validation.ts +96 -0
- package/packages/core/src/store/reducer-values.ts +145 -0
- package/packages/core/src/store/remote/client.ts +85 -0
- package/packages/core/src/store/remote/compatibility.ts +21 -9
- package/packages/core/src/store/remote/index.ts +19 -0
- package/packages/core/src/store/remote/protocol.ts +27 -0
- package/packages/core/src/store/remote/version.ts +3 -1
- package/packages/core/src/store/repo-state-events.ts +3 -1
- package/packages/core/src/store/repo-tick.ts +72 -0
- package/packages/core/src/store/session-handle.ts +34 -0
- package/packages/core/src/store/snapshots.ts +10 -0
- package/packages/core/src/store/subscribe.ts +1 -1
- package/packages/core/src/store/ticket-assets.ts +4 -4
- package/packages/core/src/store/types.ts +71 -6
- package/packages/core/src/testing/dispatch-read-budget.ts +215 -0
- package/packages/core/src/testing/index.ts +10 -0
- package/packages/core/src/testing/reduced-read-budget.ts +502 -0
- package/packages/core/src/testing/refresh-scheduler.ts +32 -0
- package/skills/guide/SKILL.md +116 -62
- package/skills/guide/references/integration-tree.md +117 -0
- package/skills/guide/references/landing-policy.md +150 -0
- package/skills/guide/references/migration-1.0.md +68 -0
- package/skills/guide/references/operator-api.md +13 -6
- package/skills/guide/references/plugin-authoring.md +34 -0
- package/skills/guide/references/remote-store-protocol.md +114 -9
- package/skills/guide/references/remote-ticket-protocol.md +26 -5
- package/skills/guide/references/restacking.md +79 -0
- package/skills/guide/references/setup.md +49 -6
- package/skills/guide/references/ticket-dependencies.md +69 -0
- package/skills/guide/references/ticket-migration.md +8 -0
- package/skills/operate/SKILL.md +55 -5
- package/skills/reconcile/SKILL.md +55 -48
- package/skills/spec/SKILL.md +67 -1
- package/skills/tickets/SKILL.md +55 -2
- package/templates/autobuild.toml +3 -0
- package/templates/hosted-service/package.json +2 -2
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
import { openTicketSource } from './ticket'
|
|
2
|
+
import {
|
|
3
|
+
inspectForgeReadiness,
|
|
4
|
+
formatForgeReadiness,
|
|
5
|
+
hardReadinessKeys,
|
|
6
|
+
} from '../ports/forge/readiness'
|
|
7
|
+
import { createReadinessRedactor } from './init-readiness-shared'
|
|
8
|
+
import { RepositoryPollCache } from './dashboard/repository-poll'
|
|
9
|
+
import { DashboardRefresh, interactionRead, presentationReader } from './dashboard/refresh'
|
|
10
|
+
import { FOCUS_REPORTING_MODE, installPresentationSuspension } from './terminal-restore'
|
|
11
|
+
import type { BuildState } from '../kernel/reducer'
|
|
12
|
+
import {
|
|
13
|
+
readBuildFacts,
|
|
14
|
+
readRepositoryFacts,
|
|
15
|
+
readBuildSelector,
|
|
16
|
+
readDispatcherRunFacts,
|
|
17
|
+
} from '../store/reduced-reads'
|
|
18
|
+
import { shouldPublishTickFromFacts } from '../processes/tick-publication'
|
|
1
19
|
import { issueTicketGrant, ticketGrantRequest } from '../ports/tickets/grants'
|
|
2
20
|
import { RemoteBuildStore } from '../store/remote/client'
|
|
3
21
|
import { delegateCredential } from '../store/remote/credentials'
|
|
@@ -54,17 +72,14 @@ import { loadPlugins, pluginResolutionKind } from '../plugins/load'
|
|
|
54
72
|
import type { PluginRegistry } from '../plugins/registry'
|
|
55
73
|
import { materializePluginRuntimes } from '../plugins/runtimes'
|
|
56
74
|
import { DISPATCHER, KERNEL, humanActor } from '../events/envelope'
|
|
57
|
-
import type { AbEvent } from '../events/catalog'
|
|
58
75
|
import type { RepositoryEventWrite } from '../events/repository'
|
|
59
76
|
import { randomIds, randomUuids, type IdSource, type UuidSource } from '../ids'
|
|
60
|
-
import { reduceDispatchSettings } from '../kernel/dispatch-settings'
|
|
77
|
+
import type { reduceDispatchSettings } from '../kernel/dispatch-settings'
|
|
61
78
|
import {
|
|
62
79
|
DEFAULT_MAX_HARVEST_RECOVERY_ATTEMPTS,
|
|
63
80
|
actionableHarvestRun,
|
|
64
81
|
decideHarvestControl,
|
|
65
|
-
reduceHarvest,
|
|
66
82
|
} from '../kernel/harvest'
|
|
67
|
-
import { reduceBuild } from '../kernel/reducer'
|
|
68
83
|
import { dashboardBuildControl } from './dashboard/actions'
|
|
69
84
|
import {
|
|
70
85
|
buildDashboardFromProjected,
|
|
@@ -127,13 +142,12 @@ import {
|
|
|
127
142
|
parseBuildConfigMetadata,
|
|
128
143
|
parseDiagnostic,
|
|
129
144
|
parseEffectiveBuildConfig,
|
|
130
|
-
selectOpenWorkspace,
|
|
131
145
|
} from '../processes/build-execution-state'
|
|
132
146
|
import { HarvestRunner, type HarvestRunnerResult } from '../processes/harvest-runner'
|
|
133
147
|
import {
|
|
134
148
|
sampleUnclaimedObservationCount,
|
|
135
|
-
readRepoEventsIfRecorded,
|
|
136
149
|
evaluateHarvestPressureFromStore,
|
|
150
|
+
evaluateHarvestPressureFromDigests,
|
|
137
151
|
} from '../processes/harvest'
|
|
138
152
|
import { classifyHarvestOutcome } from '../processes/harvest-execution-state'
|
|
139
153
|
import type { HarvestExecution } from '../ports/workspace/harvest-execution'
|
|
@@ -164,7 +178,13 @@ import {
|
|
|
164
178
|
} from './repo-state'
|
|
165
179
|
import { openStoreForRepoState } from './store-opening'
|
|
166
180
|
import { DispatchFrontend } from './dispatch-frontend'
|
|
167
|
-
import {
|
|
181
|
+
import {
|
|
182
|
+
systemClock,
|
|
183
|
+
type BuildStore,
|
|
184
|
+
type Clock,
|
|
185
|
+
type RepoTickCompletion,
|
|
186
|
+
type RepoTickFinish,
|
|
187
|
+
} from '../store/types'
|
|
168
188
|
import { availableRelease } from './self-update'
|
|
169
189
|
import {
|
|
170
190
|
startUpgradeNotice,
|
|
@@ -212,15 +232,6 @@ function definedEnv(env: Record<string, string | undefined>): Record<string, str
|
|
|
212
232
|
return defined
|
|
213
233
|
}
|
|
214
234
|
|
|
215
|
-
/** Dashboard store-read cadence. `listBuilds` remains the discovery read;
|
|
216
|
-
* the process-local display cache then polls dashboard-visible streams with
|
|
217
|
-
* `getEvents(lastSeq)`, retaining abort cleanup until final completion and reusing unchanged
|
|
218
|
-
* reductions/timing projections. Repository controls and Harvest are still
|
|
219
|
-
* read fresh through the bounded journal read (AUT-489 subset; AUT-545). The
|
|
220
|
-
* identical-frame check in `live.ts` makes an unchanged paint cost zero
|
|
221
|
-
* terminal writes. */
|
|
222
|
-
const DASHBOARD_POLL_MS = 500
|
|
223
|
-
|
|
224
235
|
/** Dashboard repaint (not re-read) cadence in watch mode. A running step's
|
|
225
236
|
* elapsed must advance ~1×/s even if the store poll is raised for a slow remote
|
|
226
237
|
* store, so paint is decoupled from the store read and driven from this cheaper
|
|
@@ -236,6 +247,7 @@ type DashboardAction =
|
|
|
236
247
|
| 'left'
|
|
237
248
|
| 'right'
|
|
238
249
|
| 'enter'
|
|
250
|
+
| 'hold'
|
|
239
251
|
| 'auto-merge'
|
|
240
252
|
| 'intake'
|
|
241
253
|
| 'pause'
|
|
@@ -648,6 +660,7 @@ class DispatchLoop {
|
|
|
648
660
|
* manufacturing a zero queue measurement or losing diagnostics. */
|
|
649
661
|
private lastTickStatus = {
|
|
650
662
|
queued: 0,
|
|
663
|
+
blockedDiagnostics: [] as string[],
|
|
651
664
|
janitorDiagnostics: [] as string[],
|
|
652
665
|
ticketDiagnostics: [] as string[],
|
|
653
666
|
creationDiagnostics: [] as string[],
|
|
@@ -664,15 +677,9 @@ class DispatchLoop {
|
|
|
664
677
|
private readonly region: LiveRegion | undefined
|
|
665
678
|
/** One display-only incremental build cache for this dispatch process. */
|
|
666
679
|
private readonly dashboardBuilds: DashboardBuildPollCache
|
|
667
|
-
|
|
668
|
-
private
|
|
669
|
-
|
|
670
|
-
* before selecting the final frame. */
|
|
671
|
-
private renderInFlight: Promise<void> | undefined
|
|
672
|
-
/** Cleared at the rendering stop boundary so an already-queued timer callback
|
|
673
|
-
* cannot open a new store read after teardown begins. */
|
|
674
|
-
private acceptingRenderPolls = false
|
|
675
|
-
private timer: ReturnType<typeof setInterval> | undefined
|
|
680
|
+
private refresh: DashboardRefresh | undefined
|
|
681
|
+
private suspension: ReturnType<typeof installPresentationSuspension> | undefined
|
|
682
|
+
private readonly presentationStore: BuildStore
|
|
676
683
|
/** Watch-mode paint timer (AC 8): repaints the CACHED model against a fresh
|
|
677
684
|
* clock so running elapsed ticks between store reads. Absent in `--once`. */
|
|
678
685
|
private tickTimer: ReturnType<typeof setInterval> | undefined
|
|
@@ -700,6 +707,10 @@ class DispatchLoop {
|
|
|
700
707
|
* process. Rendered ABOVE the transient warning line and never overwritten by
|
|
701
708
|
* it: `setWarning` replaces the transient slot outright, so sharing it would
|
|
702
709
|
* let the first tick's janitor notice erase a startup diagnostic for good. */
|
|
710
|
+
private forgeWarnings: string[] = []
|
|
711
|
+
private forgeInspected = false
|
|
712
|
+
private forgePublicationFailed = false
|
|
713
|
+
private readonly startupRootBranch: string
|
|
703
714
|
private configWarnings: readonly string[] = []
|
|
704
715
|
/** Last intake-enabled tick's standing queue depth, for the dashboard header. */
|
|
705
716
|
private queuedCount = 0
|
|
@@ -722,6 +733,7 @@ class DispatchLoop {
|
|
|
722
733
|
* id while it holds the repo lease, else undefined. A losing invocation
|
|
723
734
|
* records `dispatcher.tick-yielded` and performs no claims, launches, or
|
|
724
735
|
* publications. */
|
|
736
|
+
private repoLeaseValidUntil = 0
|
|
725
737
|
private repoLeaseHolder: string | undefined
|
|
726
738
|
private repoLeaseHeartbeat: ReturnType<typeof setInterval> | undefined
|
|
727
739
|
/** Set when the store reports this supervisor's repo lease was taken over:
|
|
@@ -761,6 +773,7 @@ class DispatchLoop {
|
|
|
761
773
|
view?: RepoViewStore,
|
|
762
774
|
) {
|
|
763
775
|
const config = liveConfig.current().config
|
|
776
|
+
this.startupRootBranch = config.baseBranch
|
|
764
777
|
// Minted exactly once per invocation: `wiring.ids` is `randomIds()` and a
|
|
765
778
|
// fresh id per access would split the journal run from the lease holder.
|
|
766
779
|
// abDispatch always passes `runId`, so the fallback only covers direct
|
|
@@ -775,7 +788,15 @@ class DispatchLoop {
|
|
|
775
788
|
this.dashboard && opts.terminal !== undefined
|
|
776
789
|
? new LiveRegion(opts.terminal, this.keyboard)
|
|
777
790
|
: undefined
|
|
778
|
-
this.
|
|
791
|
+
this.presentationStore = presentationReader(
|
|
792
|
+
wiring.store,
|
|
793
|
+
() => this.opts.once === true || (this.refresh?.admitted ?? true),
|
|
794
|
+
)
|
|
795
|
+
this.dashboardBuilds = new DashboardBuildPollCache(
|
|
796
|
+
this.presentationStore,
|
|
797
|
+
this.repoIdentity,
|
|
798
|
+
config,
|
|
799
|
+
)
|
|
779
800
|
|
|
780
801
|
// `slug` is an internal pre-build role on the same runtime/model resolver. A
|
|
781
802
|
// runtime without the optional capability is normal: omit the seam and let
|
|
@@ -850,7 +871,7 @@ class DispatchLoop {
|
|
|
850
871
|
private async resolveBuildPipeline(slug: string): Promise<{
|
|
851
872
|
source: Awaited<ReturnType<typeof resolvePipelineSource>>
|
|
852
873
|
failures: PipelineSourceFailure[]
|
|
853
|
-
|
|
874
|
+
observations: BuildState['observations']
|
|
854
875
|
}> {
|
|
855
876
|
const failures: PipelineSourceFailure[] = []
|
|
856
877
|
try {
|
|
@@ -858,12 +879,12 @@ class DispatchLoop {
|
|
|
858
879
|
// the record's `branch` (when present) is the same fact. Using the event
|
|
859
880
|
// keeps this read to the events the caller already needs and avoids an
|
|
860
881
|
// extra build-record lookup on the hot launch path.
|
|
861
|
-
const
|
|
862
|
-
const workspace =
|
|
882
|
+
const facts = (await readBuildFacts(this.repoView, slug)).value
|
|
883
|
+
const workspace = facts.workspace
|
|
863
884
|
const source = await resolvePipelineSource({
|
|
864
885
|
slug,
|
|
865
886
|
record: { ...(workspace !== null ? { branch: workspace.branch } : {}) },
|
|
866
|
-
|
|
887
|
+
recordedBase: await readBuildSelector(this.repoView, slug, 'recordedBaseSha'),
|
|
867
888
|
mode: this.opts.repository !== undefined ? 'origin' : 'checkout',
|
|
868
889
|
forge: this.wiring.forge,
|
|
869
890
|
checkout: this.opts.targetRepo,
|
|
@@ -871,13 +892,13 @@ class DispatchLoop {
|
|
|
871
892
|
...(workspace !== null ? { workspacePath: workspace.path } : {}),
|
|
872
893
|
onFailure: (failure) => failures.push(failure),
|
|
873
894
|
})
|
|
874
|
-
return { source, failures,
|
|
895
|
+
return { source, failures, observations: facts.observations }
|
|
875
896
|
} catch (error) {
|
|
876
897
|
failures.push({
|
|
877
898
|
kind: 'store',
|
|
878
899
|
detail: `build-event read failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
879
900
|
})
|
|
880
|
-
return { source: undefined, failures,
|
|
901
|
+
return { source: undefined, failures, observations: [] }
|
|
881
902
|
}
|
|
882
903
|
}
|
|
883
904
|
|
|
@@ -901,7 +922,7 @@ class DispatchLoop {
|
|
|
901
922
|
* naming the failed attempts; the documented fallbacks (an unpublished
|
|
902
923
|
* branch, an unreadable legacy base) stay quiet. */
|
|
903
924
|
private async publishBuildConfig(slug: string, snapshot = this.currentConfig()): Promise<void> {
|
|
904
|
-
const { source, failures,
|
|
925
|
+
const { source, failures, observations } = await this.resolveBuildPipeline(slug)
|
|
905
926
|
if (source !== undefined) {
|
|
906
927
|
await this.depositBuildConfig(
|
|
907
928
|
slug,
|
|
@@ -931,7 +952,7 @@ class DispatchLoop {
|
|
|
931
952
|
// option left that keeps the launch alive.
|
|
932
953
|
await this.depositBuildConfig(slug, snapshot, snapshot.config)
|
|
933
954
|
}
|
|
934
|
-
await this.filePipelineFallbackObservation(slug, reused, failures,
|
|
955
|
+
await this.filePipelineFallbackObservation(slug, reused, failures, observations)
|
|
935
956
|
}
|
|
936
957
|
|
|
937
958
|
/** File a build-scoped observation when a deposit hit an actionable
|
|
@@ -944,7 +965,7 @@ class DispatchLoop {
|
|
|
944
965
|
slug: string,
|
|
945
966
|
reused: PipelineSourceMeta | undefined,
|
|
946
967
|
failures: PipelineSourceFailure[],
|
|
947
|
-
|
|
968
|
+
observations: BuildState['observations'],
|
|
948
969
|
): Promise<void> {
|
|
949
970
|
const actionable = failures.filter(isActionablePipelineFailure)
|
|
950
971
|
if (actionable.length === 0) return
|
|
@@ -961,11 +982,7 @@ class DispatchLoop {
|
|
|
961
982
|
}`
|
|
962
983
|
// Deduplicated against the build's log: a parked build re-attaches every
|
|
963
984
|
// sweep, and an outage must not harvest one identical diagnostic per tick.
|
|
964
|
-
if (
|
|
965
|
-
events.some(
|
|
966
|
-
(event) => event.type === 'observation.recorded' && event.payload.summary === summary,
|
|
967
|
-
)
|
|
968
|
-
) {
|
|
985
|
+
if (observations.some((observation) => observation.summary === summary)) {
|
|
969
986
|
return
|
|
970
987
|
}
|
|
971
988
|
try {
|
|
@@ -1106,26 +1123,30 @@ class DispatchLoop {
|
|
|
1106
1123
|
// The view's bounded subset (AUT-489): the settings reducer consumes
|
|
1107
1124
|
// durable types only. `refresh()` ran first in the tick, so this is the
|
|
1108
1125
|
// delta-current journal, never a store read.
|
|
1109
|
-
return
|
|
1126
|
+
return this.repoView.repositoryFacts().settings
|
|
1110
1127
|
}
|
|
1111
1128
|
|
|
1129
|
+
private tickStartedAt: string | undefined
|
|
1130
|
+
|
|
1112
1131
|
private dispatcherTick(resumeCurrent: boolean): Promise<Awaited<ReturnType<Dispatcher['tick']>>> {
|
|
1113
1132
|
return this.serialize(async () => {
|
|
1114
1133
|
// Refresh before every watch decision. The owner publishes atomically;
|
|
1115
1134
|
// everything below captures the resulting one snapshot for this tick.
|
|
1116
1135
|
await this.refreshConfig()
|
|
1117
|
-
// Every tick
|
|
1136
|
+
// Every tick verifies local lease currency, reclaiming when necessary. Without it,
|
|
1118
1137
|
// this invocation records the yield and performs no claims, launches,
|
|
1119
1138
|
// or publications — including no tick-completed status publication.
|
|
1120
1139
|
if (!(await this.ensureRepoLease(this.repoLeaseHolder ?? this.runId))) {
|
|
1121
1140
|
await this.recordTickYielded()
|
|
1122
1141
|
return emptyTickReport()
|
|
1123
1142
|
}
|
|
1124
|
-
await this.
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1143
|
+
await this.reportForgeReadiness()
|
|
1144
|
+
const startedAt = await this.repoView.beginRepoTick(this.repoIdentity, this.runId)
|
|
1145
|
+
if (startedAt === null) {
|
|
1146
|
+
this.superseded = true
|
|
1147
|
+
return emptyTickReport()
|
|
1148
|
+
}
|
|
1149
|
+
this.tickStartedAt = startedAt
|
|
1129
1150
|
|
|
1130
1151
|
// Unclaimed observations are display-only and sampled once per interactive
|
|
1131
1152
|
// dispatcher tick from the journal and one repo-scoped digest read
|
|
@@ -1152,7 +1173,7 @@ class DispatchLoop {
|
|
|
1152
1173
|
const readyObservation =
|
|
1153
1174
|
settings.intake || (!this.dashboard && this.opts.kernelRunId === undefined)
|
|
1154
1175
|
? undefined
|
|
1155
|
-
: await this.dispatcher.observeReady()
|
|
1176
|
+
: await this.dispatcher.observeReady({ viewRefreshed: true })
|
|
1156
1177
|
const report = await this.dispatcher.tick({
|
|
1157
1178
|
resumeCurrent,
|
|
1158
1179
|
viewRefreshed: true,
|
|
@@ -1174,6 +1195,7 @@ class DispatchLoop {
|
|
|
1174
1195
|
this.queuedCount = publishedReport.queued
|
|
1175
1196
|
this.lastTickStatus = {
|
|
1176
1197
|
queued: publishedReport.queued,
|
|
1198
|
+
blockedDiagnostics: [...publishedReport.blockedDiagnostics],
|
|
1177
1199
|
janitorDiagnostics: [...publishedReport.janitorDiagnostics],
|
|
1178
1200
|
ticketDiagnostics: [...publishedReport.ticketDiagnostics],
|
|
1179
1201
|
creationDiagnostics: [...publishedReport.creationDiagnostics],
|
|
@@ -1203,6 +1225,7 @@ class DispatchLoop {
|
|
|
1203
1225
|
// no dependence on emission order relative to `startRendering()`.
|
|
1204
1226
|
const warningLines = [
|
|
1205
1227
|
...this.configWarnings,
|
|
1228
|
+
...this.forgeWarnings,
|
|
1206
1229
|
...(this.warningLine !== undefined ? [this.warningLine] : []),
|
|
1207
1230
|
]
|
|
1208
1231
|
let effective: DashboardModel = {
|
|
@@ -1311,6 +1334,7 @@ class DispatchLoop {
|
|
|
1311
1334
|
* last read failed). The apply goes through the serialize queue under the
|
|
1312
1335
|
* feed's identity+cursor fence, mirroring the transcript read's pattern. */
|
|
1313
1336
|
private pollSessionFeed(): void {
|
|
1337
|
+
if (this.refresh !== undefined && !this.refresh.admitted) return
|
|
1314
1338
|
const view = this.view
|
|
1315
1339
|
if (view?.kind !== 'session') return
|
|
1316
1340
|
if (view.status !== 'open' && view.error === undefined) {
|
|
@@ -1481,6 +1505,7 @@ class DispatchLoop {
|
|
|
1481
1505
|
try {
|
|
1482
1506
|
result = await controlBuild({
|
|
1483
1507
|
store: this.wiring.store,
|
|
1508
|
+
ticketSource: async () => this.wiring.tickets,
|
|
1484
1509
|
repo: this.repoIdentity,
|
|
1485
1510
|
slug,
|
|
1486
1511
|
env: this.opts.env,
|
|
@@ -1510,6 +1535,7 @@ class DispatchLoop {
|
|
|
1510
1535
|
try {
|
|
1511
1536
|
result = await controlBuild({
|
|
1512
1537
|
store: this.wiring.store,
|
|
1538
|
+
ticketSource: async () => this.wiring.tickets,
|
|
1513
1539
|
repo: this.repoIdentity,
|
|
1514
1540
|
slug,
|
|
1515
1541
|
env: this.opts.env,
|
|
@@ -1546,6 +1572,7 @@ class DispatchLoop {
|
|
|
1546
1572
|
try {
|
|
1547
1573
|
const result = await controlBuild({
|
|
1548
1574
|
store: this.wiring.store,
|
|
1575
|
+
ticketSource: async () => this.wiring.tickets,
|
|
1549
1576
|
repo: this.repoIdentity,
|
|
1550
1577
|
slug: confirmation.slug,
|
|
1551
1578
|
env: this.opts.env,
|
|
@@ -1568,6 +1595,7 @@ class DispatchLoop {
|
|
|
1568
1595
|
try {
|
|
1569
1596
|
const result = await controlBuild({
|
|
1570
1597
|
store: this.wiring.store,
|
|
1598
|
+
ticketSource: async () => this.wiring.tickets,
|
|
1571
1599
|
repo: this.repoIdentity,
|
|
1572
1600
|
slug,
|
|
1573
1601
|
env: this.opts.env,
|
|
@@ -1610,8 +1638,8 @@ class DispatchLoop {
|
|
|
1610
1638
|
const { store } = this.wiring
|
|
1611
1639
|
const repo = this.repoIdentity
|
|
1612
1640
|
await store.ensureRepo(repo)
|
|
1613
|
-
const events = await store
|
|
1614
|
-
const state =
|
|
1641
|
+
const events = (await readRepositoryFacts(store, repo)).value
|
|
1642
|
+
const state = events.harvest
|
|
1615
1643
|
const projected = projectHarvest(events)
|
|
1616
1644
|
if (expectedRun === undefined || projected === undefined || projected.run !== expectedRun) {
|
|
1617
1645
|
this.say('harvest run action ignored: selected run is no longer active')
|
|
@@ -1666,6 +1694,7 @@ class DispatchLoop {
|
|
|
1666
1694
|
try {
|
|
1667
1695
|
result = await controlBuild({
|
|
1668
1696
|
store: this.wiring.store,
|
|
1697
|
+
ticketSource: async () => this.wiring.tickets,
|
|
1669
1698
|
repo: this.repoIdentity,
|
|
1670
1699
|
slug: prompt.slug,
|
|
1671
1700
|
env: this.opts.env,
|
|
@@ -1695,19 +1724,7 @@ class DispatchLoop {
|
|
|
1695
1724
|
await this.renderOnce()
|
|
1696
1725
|
}
|
|
1697
1726
|
|
|
1698
|
-
private async toggleAutoMerge(): Promise<void> {
|
|
1699
|
-
if (this.view === undefined && this.selection?.kind === 'global') {
|
|
1700
|
-
const event = await toggleRepositorySetting({
|
|
1701
|
-
store: this.wiring.store,
|
|
1702
|
-
repo: this.repoIdentity,
|
|
1703
|
-
user: buildControlUser(this.opts.env),
|
|
1704
|
-
setting: 'auto-merge-default',
|
|
1705
|
-
run: this.runId,
|
|
1706
|
-
})
|
|
1707
|
-
this.say(`dispatcher auto-merge default ${event.enabled ? 'ON' : 'OFF'}`)
|
|
1708
|
-
await this.renderOnce()
|
|
1709
|
-
return
|
|
1710
|
-
}
|
|
1727
|
+
private async toggleAutoMerge(kind: 'hold' | 'land' = 'land'): Promise<void> {
|
|
1711
1728
|
const slug = this.selectedBuildSlug('auto-merge')
|
|
1712
1729
|
if (slug === undefined) return
|
|
1713
1730
|
|
|
@@ -1715,24 +1732,22 @@ class DispatchLoop {
|
|
|
1715
1732
|
try {
|
|
1716
1733
|
result = await controlBuild({
|
|
1717
1734
|
store: this.wiring.store,
|
|
1735
|
+
ticketSource: async () => this.wiring.tickets,
|
|
1718
1736
|
repo: this.repoIdentity,
|
|
1719
1737
|
slug,
|
|
1720
1738
|
env: this.opts.env,
|
|
1721
|
-
action: { kind
|
|
1739
|
+
action: { kind },
|
|
1722
1740
|
})
|
|
1723
1741
|
} catch (error) {
|
|
1724
1742
|
if (await this.ignoreControlError('action', error)) return
|
|
1725
1743
|
throw error
|
|
1726
1744
|
}
|
|
1727
|
-
if (
|
|
1728
|
-
result.kind !== 'command' ||
|
|
1729
|
-
(result.command !== 'auto-merge-on' && result.command !== 'auto-merge-off')
|
|
1730
|
-
) {
|
|
1745
|
+
if (result.kind !== 'command' || (result.command !== 'land' && result.command !== 'hold')) {
|
|
1731
1746
|
throw new Error('build-control returned an invalid auto-merge toggle result')
|
|
1732
1747
|
}
|
|
1733
1748
|
this.say(
|
|
1734
|
-
`build ${slug}:
|
|
1735
|
-
result.command === '
|
|
1749
|
+
`build ${slug}: landing ${
|
|
1750
|
+
result.command === 'hold' ? 'hold requested' : 'consent requested'
|
|
1736
1751
|
}`,
|
|
1737
1752
|
)
|
|
1738
1753
|
await this.renderOnce()
|
|
@@ -1834,7 +1849,7 @@ class DispatchLoop {
|
|
|
1834
1849
|
follow: true,
|
|
1835
1850
|
scroll: 0,
|
|
1836
1851
|
}
|
|
1837
|
-
this.sessionFeed = new SessionStreamFeed(this.
|
|
1852
|
+
this.sessionFeed = new SessionStreamFeed(this.presentationStore, captured.slug)
|
|
1838
1853
|
this.syncModelControls()
|
|
1839
1854
|
this.paint()
|
|
1840
1855
|
// Kick the first read immediately rather than waiting one interval.
|
|
@@ -1970,6 +1985,9 @@ class DispatchLoop {
|
|
|
1970
1985
|
case 'bulk-resume':
|
|
1971
1986
|
await this.bulkControl('resume')
|
|
1972
1987
|
return
|
|
1988
|
+
case 'hold':
|
|
1989
|
+
await this.toggleAutoMerge('hold')
|
|
1990
|
+
return
|
|
1973
1991
|
case 'auto-merge':
|
|
1974
1992
|
await this.toggleAutoMerge()
|
|
1975
1993
|
return
|
|
@@ -1986,12 +2004,14 @@ class DispatchLoop {
|
|
|
1986
2004
|
}
|
|
1987
2005
|
|
|
1988
2006
|
private queueAction(action: DashboardAction): void {
|
|
1989
|
-
void this.serialize(() => this.handleAction(action)).catch(
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
2007
|
+
void this.serialize(() => interactionRead(() => this.handleAction(action))).catch(
|
|
2008
|
+
(error: unknown) => {
|
|
2009
|
+
const name = typeof action === 'string' ? action : action.kind
|
|
2010
|
+
this.warn(
|
|
2011
|
+
`dashboard ${name} action failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
2012
|
+
)
|
|
2013
|
+
},
|
|
2014
|
+
)
|
|
1995
2015
|
}
|
|
1996
2016
|
|
|
1997
2017
|
/** Modal edits are synchronous and never enter the dispatcher operation
|
|
@@ -2038,7 +2058,7 @@ class DispatchLoop {
|
|
|
2038
2058
|
return
|
|
2039
2059
|
case 'enter':
|
|
2040
2060
|
this.resumeSubmitting = true
|
|
2041
|
-
void this.serialize(() => this.submitResume(prompt))
|
|
2061
|
+
void this.serialize(() => interactionRead(() => this.submitResume(prompt)))
|
|
2042
2062
|
.catch((error: unknown) => {
|
|
2043
2063
|
this.warn(
|
|
2044
2064
|
`dashboard resume action failed: ${
|
|
@@ -2058,6 +2078,7 @@ class DispatchLoop {
|
|
|
2058
2078
|
}
|
|
2059
2079
|
|
|
2060
2080
|
private onInput(input: TerminalInputEvent): void {
|
|
2081
|
+
this.refresh?.interaction()
|
|
2061
2082
|
if (!this.acceptingKeys) return
|
|
2062
2083
|
if (input.type === 'interrupt') {
|
|
2063
2084
|
this.acceptingKeys = false
|
|
@@ -2116,7 +2137,10 @@ class DispatchLoop {
|
|
|
2116
2137
|
// directional motions were routed above.
|
|
2117
2138
|
if (input.type !== 'text') return
|
|
2118
2139
|
switch (input.text.toLowerCase()) {
|
|
2119
|
-
case '
|
|
2140
|
+
case 'o':
|
|
2141
|
+
this.queueAction('hold')
|
|
2142
|
+
return
|
|
2143
|
+
case 'l':
|
|
2120
2144
|
// Defense in depth: the session-view gate above already returns for a
|
|
2121
2145
|
// session view, and the transcript guard below predates it.
|
|
2122
2146
|
if (this.view?.kind !== 'transcript') {
|
|
@@ -2187,6 +2211,11 @@ class DispatchLoop {
|
|
|
2187
2211
|
onListening: () => this.keyboard?.query(),
|
|
2188
2212
|
onKeyboardFlags: (flags) => this.keyboard?.reported(flags),
|
|
2189
2213
|
onDeviceAttributes: () => this.keyboard?.deviceAttributes(),
|
|
2214
|
+
onFocus: (focused) => {
|
|
2215
|
+
if (this.opts.once !== true) this.refresh?.focus(focused)
|
|
2216
|
+
},
|
|
2217
|
+
onInteraction: () => this.refresh?.interaction(),
|
|
2218
|
+
onSuspend: () => this.suspension?.suspend(),
|
|
2190
2219
|
})
|
|
2191
2220
|
}
|
|
2192
2221
|
|
|
@@ -2212,18 +2241,46 @@ class DispatchLoop {
|
|
|
2212
2241
|
// dispatch process is independently excluded by the repository lease.
|
|
2213
2242
|
if (this.harvestInFlight !== undefined) return
|
|
2214
2243
|
|
|
2244
|
+
let tracked: Promise<void>
|
|
2245
|
+
tracked = this.launchHarvestIfNeeded()
|
|
2246
|
+
.catch((error: unknown) => {
|
|
2247
|
+
// The gate may read the backing store after tick work dirties the view.
|
|
2248
|
+
// Contain that failure too, without relying on another store write.
|
|
2249
|
+
if (!this.stopped) {
|
|
2250
|
+
this.warn(
|
|
2251
|
+
`harvest launch failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
2252
|
+
)
|
|
2253
|
+
}
|
|
2254
|
+
})
|
|
2255
|
+
.finally(() => {
|
|
2256
|
+
this.inFlight.delete(tracked)
|
|
2257
|
+
if (this.harvestInFlight === tracked) this.harvestInFlight = undefined
|
|
2258
|
+
})
|
|
2259
|
+
this.harvestInFlight = tracked
|
|
2260
|
+
this.inFlight.add(tracked)
|
|
2261
|
+
}
|
|
2262
|
+
|
|
2263
|
+
private async launchHarvestIfNeeded(): Promise<void> {
|
|
2264
|
+
const state = this.repoView.repositoryFacts().harvest
|
|
2265
|
+
const control = decideHarvestControl(state, this.maxHarvestRecoveryAttempts)
|
|
2266
|
+
if (control.kind === 'park') return
|
|
2267
|
+
if (control.kind === 'proceed' && actionableHarvestRun(state) === undefined) {
|
|
2268
|
+
const pressure = evaluateHarvestPressureFromDigests({
|
|
2269
|
+
digests: await this.repoView.getRepoBuildDigests(this.repoIdentity),
|
|
2270
|
+
harvestEvents: state,
|
|
2271
|
+
policy: this.currentConfig().config.policy,
|
|
2272
|
+
})
|
|
2273
|
+
if (pressure.trigger === undefined) return
|
|
2274
|
+
}
|
|
2215
2275
|
const hosted = this.wiring.workspaces.harvestExecution
|
|
2216
2276
|
if (hosted !== undefined) {
|
|
2217
2277
|
const execution = `${this.host}-harvest-${this.wiring.ids('inst')}`
|
|
2218
2278
|
this.hostedHarvestExecutions.add(execution)
|
|
2219
|
-
|
|
2220
|
-
|
|
2279
|
+
try {
|
|
2280
|
+
await this.launchHostedHarvest(hosted, execution)
|
|
2281
|
+
} finally {
|
|
2221
2282
|
this.hostedHarvestExecutions.delete(execution)
|
|
2222
|
-
|
|
2223
|
-
if (this.harvestInFlight === tracked) this.harvestInFlight = undefined
|
|
2224
|
-
})
|
|
2225
|
-
this.harvestInFlight = tracked
|
|
2226
|
-
this.inFlight.add(tracked)
|
|
2283
|
+
}
|
|
2227
2284
|
return
|
|
2228
2285
|
}
|
|
2229
2286
|
|
|
@@ -2249,8 +2306,7 @@ class DispatchLoop {
|
|
|
2249
2306
|
},
|
|
2250
2307
|
}
|
|
2251
2308
|
|
|
2252
|
-
|
|
2253
|
-
tracked = (async () => {
|
|
2309
|
+
await (async () => {
|
|
2254
2310
|
const ticketUrl =
|
|
2255
2311
|
harvestDeps.config.tickets.source === 'hosted'
|
|
2256
2312
|
? (harvestDeps.config.tickets.url ?? (/^https?:/i.test(storeRef) ? storeRef : undefined))
|
|
@@ -2441,12 +2497,6 @@ class DispatchLoop {
|
|
|
2441
2497
|
)
|
|
2442
2498
|
}
|
|
2443
2499
|
})
|
|
2444
|
-
.finally(() => {
|
|
2445
|
-
this.inFlight.delete(tracked)
|
|
2446
|
-
if (this.harvestInFlight === tracked) this.harvestInFlight = undefined
|
|
2447
|
-
})
|
|
2448
|
-
this.harvestInFlight = tracked
|
|
2449
|
-
this.inFlight.add(tracked)
|
|
2450
2500
|
}
|
|
2451
2501
|
|
|
2452
2502
|
/** Hosted harvest lifecycle: threshold gate → provision + launch in the
|
|
@@ -2502,8 +2552,8 @@ class DispatchLoop {
|
|
|
2502
2552
|
// reduces durable types only. Take the journal delta first — guests and
|
|
2503
2553
|
// other dispatchers write harvest facts between ticks.
|
|
2504
2554
|
await this.repoView.refreshJournal()
|
|
2505
|
-
const events = this.repoView.
|
|
2506
|
-
const state =
|
|
2555
|
+
const events = this.repoView.repositoryFacts().harvest
|
|
2556
|
+
const state = events
|
|
2507
2557
|
const control = decideHarvestControl(state, this.maxHarvestRecoveryAttempts)
|
|
2508
2558
|
const resumePending =
|
|
2509
2559
|
actionableHarvestRun(state) !== undefined ||
|
|
@@ -2692,7 +2742,7 @@ class DispatchLoop {
|
|
|
2692
2742
|
// Bounded subset (AUT-489): classifyHarvestOutcome reduces harvest facts
|
|
2693
2743
|
// only. A guest wrote the facts through its own handle, so read the delta.
|
|
2694
2744
|
await this.repoView.refreshJournal()
|
|
2695
|
-
const events = this.repoView.
|
|
2745
|
+
const events = this.repoView.repositoryFacts()
|
|
2696
2746
|
const record = await store.getRepo(repo)
|
|
2697
2747
|
return classifyHarvestOutcome(events, {
|
|
2698
2748
|
executionStartedSeq: startedSeq,
|
|
@@ -2831,15 +2881,38 @@ class DispatchLoop {
|
|
|
2831
2881
|
dependencyDiagnostics: _dependencyDiagnostics,
|
|
2832
2882
|
...counters
|
|
2833
2883
|
} = merged
|
|
2834
|
-
|
|
2884
|
+
const completed = {
|
|
2835
2885
|
actor: DISPATCHER,
|
|
2836
|
-
type: 'dispatcher.tick-completed',
|
|
2837
|
-
payload: {
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2886
|
+
type: 'dispatcher.tick-completed' as const,
|
|
2887
|
+
payload: { run: this.runId, ...this.lastTickStatus, counters },
|
|
2888
|
+
}
|
|
2889
|
+
if (settlementOnly) {
|
|
2890
|
+
await this.appendStatus(completed)
|
|
2891
|
+
} else {
|
|
2892
|
+
const startedAt = this.tickStartedAt!
|
|
2893
|
+
const facts = this.repoView.repositoryFacts()
|
|
2894
|
+
const recent = facts.recentRuns.find(([run]) => run === this.runId)?.[1]
|
|
2895
|
+
const runFacts = recent?.start
|
|
2896
|
+
? recent
|
|
2897
|
+
: (await readDispatcherRunFacts(this.repoView, this.repoIdentity, this.runId)).value
|
|
2898
|
+
const publish = shouldPublishTickFromFacts(merged, facts, runFacts, startedAt)
|
|
2899
|
+
const events: RepositoryEventWrite[] = publish
|
|
2900
|
+
? [
|
|
2901
|
+
{
|
|
2902
|
+
actor: DISPATCHER,
|
|
2903
|
+
type: 'dispatcher.tick-started',
|
|
2904
|
+
payload: { run: this.runId, startedAt },
|
|
2905
|
+
},
|
|
2906
|
+
completed,
|
|
2907
|
+
]
|
|
2908
|
+
: []
|
|
2909
|
+
const result = await this.finishTick({ outcome: 'completed', counters }, events)
|
|
2910
|
+
if (result === null) {
|
|
2911
|
+
this.superseded = true
|
|
2912
|
+
throw new Error('repository tick lease lost')
|
|
2913
|
+
}
|
|
2914
|
+
this.tickStartedAt = undefined
|
|
2915
|
+
}
|
|
2843
2916
|
|
|
2844
2917
|
this.pendingHarvest.harvestStarted -= snapshot.harvestStarted
|
|
2845
2918
|
this.pendingHarvest.harvestResumed -= snapshot.harvestResumed
|
|
@@ -2849,10 +2922,72 @@ class DispatchLoop {
|
|
|
2849
2922
|
return merged
|
|
2850
2923
|
}
|
|
2851
2924
|
|
|
2925
|
+
/** A remote finish can commit before its response is lost. Confirm that
|
|
2926
|
+
* exact tick through durable telemetry before acknowledging its counters;
|
|
2927
|
+
* never try to close an already committed boundary as a second failure. */
|
|
2928
|
+
private async finishTick(
|
|
2929
|
+
completion: RepoTickCompletion,
|
|
2930
|
+
events: RepositoryEventWrite[],
|
|
2931
|
+
): Promise<RepoTickFinish | null> {
|
|
2932
|
+
try {
|
|
2933
|
+
return await this.repoView.finishRepoTick(this.repoIdentity, this.runId, completion, events)
|
|
2934
|
+
} catch (error) {
|
|
2935
|
+
const observation = (await this.wiring.store.getRepo(this.repoIdentity).catch(() => null))
|
|
2936
|
+
?.tick
|
|
2937
|
+
const finished = observation?.finished
|
|
2938
|
+
if (
|
|
2939
|
+
observation?.run !== this.runId ||
|
|
2940
|
+
observation.open ||
|
|
2941
|
+
finished?.run !== this.runId ||
|
|
2942
|
+
finished.startedAt !== this.tickStartedAt ||
|
|
2943
|
+
finished.outcome !== completion.outcome ||
|
|
2944
|
+
(finished.outcome === 'failed' &&
|
|
2945
|
+
completion.outcome === 'failed' &&
|
|
2946
|
+
finished.error !== completion.error) ||
|
|
2947
|
+
(finished.outcome === 'completed' &&
|
|
2948
|
+
completion.outcome === 'completed' &&
|
|
2949
|
+
Object.entries(completion.counters).some(
|
|
2950
|
+
([key, value]) => finished.counters[key as keyof typeof finished.counters] !== value,
|
|
2951
|
+
))
|
|
2952
|
+
)
|
|
2953
|
+
throw error
|
|
2954
|
+
// The failed response bypassed the view's own-write fold. Refresh its
|
|
2955
|
+
// cursor from the journal, including any committed boundary pair.
|
|
2956
|
+
await this.repoView.refresh()
|
|
2957
|
+
return { observation, events: [] }
|
|
2958
|
+
}
|
|
2959
|
+
}
|
|
2960
|
+
|
|
2961
|
+
private async publishTickFailure(error: unknown): Promise<void> {
|
|
2962
|
+
const failed = {
|
|
2963
|
+
actor: DISPATCHER,
|
|
2964
|
+
type: 'dispatcher.tick-failed' as const,
|
|
2965
|
+
payload: { run: this.runId, error: error instanceof Error ? error.message : String(error) },
|
|
2966
|
+
}
|
|
2967
|
+
if (this.tickStartedAt === undefined) {
|
|
2968
|
+
await this.appendStatus(failed)
|
|
2969
|
+
return
|
|
2970
|
+
}
|
|
2971
|
+
const result = await this.finishTick({ outcome: 'failed', error: failed.payload.error }, [
|
|
2972
|
+
{
|
|
2973
|
+
actor: DISPATCHER,
|
|
2974
|
+
type: 'dispatcher.tick-started',
|
|
2975
|
+
payload: { run: this.runId, startedAt: this.tickStartedAt },
|
|
2976
|
+
},
|
|
2977
|
+
failed,
|
|
2978
|
+
])
|
|
2979
|
+
if (result === null) {
|
|
2980
|
+
this.superseded = true
|
|
2981
|
+
return
|
|
2982
|
+
}
|
|
2983
|
+
this.tickStartedAt = undefined
|
|
2984
|
+
}
|
|
2985
|
+
|
|
2852
2986
|
/** Settlement-only completions are serialized after operational ticks. Loop
|
|
2853
2987
|
* so a result arriving during an awaited status append gets its own report. */
|
|
2854
2988
|
private publishSettlementReports(): Promise<TickReport[]> {
|
|
2855
2989
|
return this.serialize(async () => {
|
|
2990
|
+
if (this.superseded) return []
|
|
2856
2991
|
const reports: TickReport[] = []
|
|
2857
2992
|
while (this.hasPendingHarvestResults()) {
|
|
2858
2993
|
const report = await this.publishTickReport(emptyTickReport(), true)
|
|
@@ -2918,7 +3053,7 @@ class DispatchLoop {
|
|
|
2918
3053
|
{ store: this.repoView, ids: this.wiring.ids },
|
|
2919
3054
|
{
|
|
2920
3055
|
slug: input.slug,
|
|
2921
|
-
events: await this.repoView
|
|
3056
|
+
events: (await readBuildFacts(this.repoView, input.slug)).value,
|
|
2922
3057
|
maxAttempts: this.currentConfig().config.policy.maxInfrastructureAttempts,
|
|
2923
3058
|
provider: input.identity?.provider ?? this.wiring.workspaces.name,
|
|
2924
3059
|
workspaceRef: input.workspaceRef,
|
|
@@ -2960,18 +3095,9 @@ class DispatchLoop {
|
|
|
2960
3095
|
this.failureNotice(`build ${slug} already held by another runner — skipped`)
|
|
2961
3096
|
return 'already-active'
|
|
2962
3097
|
}
|
|
2963
|
-
const
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
for (const event of launchEvents) {
|
|
2967
|
-
if (event.type === 'workspace.provisioned') {
|
|
2968
|
-
workspaceRef = event.payload.ref
|
|
2969
|
-
workspaceProvider = event.payload.provider
|
|
2970
|
-
} else if (event.type === 'workspace.released') {
|
|
2971
|
-
workspaceRef = undefined
|
|
2972
|
-
workspaceProvider = undefined
|
|
2973
|
-
}
|
|
2974
|
-
}
|
|
3098
|
+
const workspace = (await readBuildFacts(this.repoView, slug)).value.workspace
|
|
3099
|
+
const workspaceRef = workspace?.ref
|
|
3100
|
+
const workspaceProvider = workspace?.provider
|
|
2975
3101
|
if (workspaceRef === undefined) throw new Error(`build ${slug} has no open workspace`)
|
|
2976
3102
|
// Execute through the runtime that owns the workspace: a build
|
|
2977
3103
|
// provisioned before a provider switch still runs where it lives.
|
|
@@ -3054,7 +3180,7 @@ class DispatchLoop {
|
|
|
3054
3180
|
}
|
|
3055
3181
|
|
|
3056
3182
|
await this.repoView.refreshBuild(slug)
|
|
3057
|
-
const state =
|
|
3183
|
+
const state = (await readBuildFacts(this.repoView, slug)).value.state
|
|
3058
3184
|
if (diagnostic === null && exit.exitCode === 0) {
|
|
3059
3185
|
await this.appendStatus({
|
|
3060
3186
|
actor: DISPATCHER,
|
|
@@ -3121,12 +3247,7 @@ class DispatchLoop {
|
|
|
3121
3247
|
if (leaseClaimed) {
|
|
3122
3248
|
// The runner appended through its own handle: take the delta.
|
|
3123
3249
|
await this.repoView.refreshBuild(slug)
|
|
3124
|
-
const
|
|
3125
|
-
let workspaceRef = ''
|
|
3126
|
-
for (const event of events) {
|
|
3127
|
-
if (event.type === 'workspace.provisioned') workspaceRef = event.payload.ref
|
|
3128
|
-
else if (event.type === 'workspace.released') workspaceRef = ''
|
|
3129
|
-
}
|
|
3250
|
+
const workspaceRef = (await readBuildFacts(this.repoView, slug)).value.workspace?.ref ?? ''
|
|
3130
3251
|
if (workspaceRef !== '') {
|
|
3131
3252
|
await this.recordInfrastructureFailure({
|
|
3132
3253
|
slug,
|
|
@@ -3327,6 +3448,49 @@ class DispatchLoop {
|
|
|
3327
3448
|
* stderr writes each one, the dashboard wraps them into its warning region.
|
|
3328
3449
|
* No surface gets a digest, a cap, or a truncated tail.
|
|
3329
3450
|
*/
|
|
3451
|
+
private async reportForgeReadiness(): Promise<void> {
|
|
3452
|
+
if (this.forgeInspected) return
|
|
3453
|
+
const checks = await inspectForgeReadiness(this.wiring.forge, {
|
|
3454
|
+
rootBranch: this.startupRootBranch,
|
|
3455
|
+
})
|
|
3456
|
+
const redact = createReadinessRedactor(this.opts.env)
|
|
3457
|
+
const status = this.repoView.repositoryFacts().status
|
|
3458
|
+
const recorded = new Set(
|
|
3459
|
+
status?.run === this.runId
|
|
3460
|
+
? status.forgeReadinessFailures?.map((failure) => failure.check)
|
|
3461
|
+
: [],
|
|
3462
|
+
)
|
|
3463
|
+
for (const check of checks) {
|
|
3464
|
+
if (check.status === 'fail' && check.requirement === 'hard') {
|
|
3465
|
+
const key = hardReadinessKeys.find((key) => key === check.check)!
|
|
3466
|
+
if (!recorded.has(key)) {
|
|
3467
|
+
this.forgePublicationFailed = true
|
|
3468
|
+
await this.appendStatus({
|
|
3469
|
+
actor: DISPATCHER,
|
|
3470
|
+
type: 'dispatcher.forge-readiness-failed',
|
|
3471
|
+
payload: {
|
|
3472
|
+
run: this.runId,
|
|
3473
|
+
forge: redact(this.currentConfig().config.forge),
|
|
3474
|
+
rootBranch: redact(this.startupRootBranch),
|
|
3475
|
+
check: key,
|
|
3476
|
+
detail: redact(check.detail),
|
|
3477
|
+
remediation: redact(check.remediation),
|
|
3478
|
+
},
|
|
3479
|
+
})
|
|
3480
|
+
this.forgePublicationFailed = false
|
|
3481
|
+
recorded.add(key)
|
|
3482
|
+
}
|
|
3483
|
+
}
|
|
3484
|
+
if (check.status !== 'pass') {
|
|
3485
|
+
const line = redact(formatForgeReadiness(check))
|
|
3486
|
+
this.forgeWarnings.push(line)
|
|
3487
|
+
if (!this.dashboard) this.opts.stderr(line)
|
|
3488
|
+
}
|
|
3489
|
+
}
|
|
3490
|
+
this.forgeInspected = true
|
|
3491
|
+
this.syncModelControls()
|
|
3492
|
+
}
|
|
3493
|
+
|
|
3330
3494
|
private reportRoleDiagnostics(): void {
|
|
3331
3495
|
const lines = roleKeyWarnings(this.currentConfig().config)
|
|
3332
3496
|
if (this.dashboard) {
|
|
@@ -3388,26 +3552,53 @@ class DispatchLoop {
|
|
|
3388
3552
|
* repaint cached timing against a moving clock without re-reading.
|
|
3389
3553
|
*/
|
|
3390
3554
|
private async renderOnce(): Promise<void> {
|
|
3555
|
+
if (this.opts.once !== true && this.refresh !== undefined) return this.refresh.request(true)
|
|
3556
|
+
return this.readFrame()
|
|
3557
|
+
}
|
|
3558
|
+
|
|
3559
|
+
private readonly repositoryPoll = new RepositoryPollCache<{
|
|
3560
|
+
buildSnapshot: Awaited<ReturnType<DashboardBuildPollCache['refresh']>>
|
|
3561
|
+
repositoryEvents: Awaited<ReturnType<typeof readRepositoryFacts>>['value']
|
|
3562
|
+
}>()
|
|
3563
|
+
|
|
3564
|
+
private async readFrame(): Promise<void> {
|
|
3565
|
+
if (this.opts.once !== true && this.refresh !== undefined && !this.refresh.admitted) return
|
|
3391
3566
|
const { terminal } = this.opts
|
|
3392
3567
|
if (this.region === undefined || terminal === undefined) return
|
|
3393
3568
|
const configSnapshot = this.currentConfig()
|
|
3394
|
-
const
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3569
|
+
const snapshot = await this.repositoryPoll.refresh({
|
|
3570
|
+
position: () => this.presentationStore.getRepoChangePosition(this.repoIdentity),
|
|
3571
|
+
now: () => this.wiring.clock().getTime(),
|
|
3572
|
+
revision: configSnapshot.revision,
|
|
3573
|
+
enabled: this.opts.once !== true,
|
|
3574
|
+
valid: (frame) => this.dashboardBuilds.isCurrent(frame.buildSnapshot),
|
|
3575
|
+
admitted: () =>
|
|
3576
|
+
this.opts.once === true || this.refresh === undefined || this.refresh.admitted,
|
|
3577
|
+
nextPollMs: this.refresh?.intervalMs ?? 0,
|
|
3578
|
+
read: async ({ fullEnrichment }) => {
|
|
3579
|
+
const buildSnapshot = await this.dashboardBuilds.refresh(
|
|
3580
|
+
configSnapshot.config,
|
|
3581
|
+
configSnapshot.revision,
|
|
3582
|
+
fullEnrichment,
|
|
3583
|
+
)
|
|
3584
|
+
const repositoryEvents = (
|
|
3585
|
+
await readRepositoryFacts(this.presentationStore, this.repoIdentity)
|
|
3586
|
+
).value
|
|
3587
|
+
return { buildSnapshot, repositoryEvents }
|
|
3588
|
+
},
|
|
3589
|
+
})
|
|
3590
|
+
if (snapshot === undefined) return
|
|
3591
|
+
const { buildSnapshot, repositoryEvents } = snapshot
|
|
3406
3592
|
|
|
3407
3593
|
// Action-triggered and timer refreshes share the cache but may finish their
|
|
3408
3594
|
// repository reads out of order. Never let an older build snapshot replace
|
|
3409
3595
|
// one that committed later.
|
|
3410
|
-
if (
|
|
3596
|
+
if (
|
|
3597
|
+
!this.dashboardBuilds.isCurrent(buildSnapshot) ||
|
|
3598
|
+
(this.opts.once !== true && this.refresh !== undefined && !this.refresh.admitted)
|
|
3599
|
+
)
|
|
3600
|
+
return
|
|
3601
|
+
if (this.opts.once !== true) this.refresh?.activity(buildSnapshot.states.size > 0)
|
|
3411
3602
|
|
|
3412
3603
|
// Polling continues while the operator types. Keep the prompt bound to the
|
|
3413
3604
|
// captured build/escalations, shrink it around externally answered ids, and
|
|
@@ -3428,7 +3619,7 @@ class DispatchLoop {
|
|
|
3428
3619
|
const state = buildSnapshot.states.get(this.abortConfirmation.slug)
|
|
3429
3620
|
if (
|
|
3430
3621
|
state === undefined ||
|
|
3431
|
-
!['queued', 'running', 'paused', 'blocked'].includes(state.status) ||
|
|
3622
|
+
!['queued', 'running', 'collecting', 'paused', 'blocked'].includes(state.status) ||
|
|
3432
3623
|
state.pendingCommands.some((command) => command.command === 'abort')
|
|
3433
3624
|
) {
|
|
3434
3625
|
// Another process may have durably requested the abort while this
|
|
@@ -3444,7 +3635,7 @@ class DispatchLoop {
|
|
|
3444
3635
|
repo: this.repoIdentity,
|
|
3445
3636
|
queued: this.queuedCount,
|
|
3446
3637
|
activeCount: [...buildSnapshot.states.values()].filter(
|
|
3447
|
-
(state) => state.status !== 'done' && state.status !== 'aborted',
|
|
3638
|
+
(state) => state.kind !== 'node' && state.status !== 'done' && state.status !== 'aborted',
|
|
3448
3639
|
).length,
|
|
3449
3640
|
capacity: configSnapshot.config.capacity,
|
|
3450
3641
|
observationCount: this.observationCount,
|
|
@@ -3508,6 +3699,7 @@ class DispatchLoop {
|
|
|
3508
3699
|
* displayed second is unchanged to zero writes. No store I/O.
|
|
3509
3700
|
*/
|
|
3510
3701
|
private paint(): void {
|
|
3702
|
+
if (this.refresh !== undefined && !this.refresh.painting) return
|
|
3511
3703
|
const { terminal } = this.opts
|
|
3512
3704
|
if (this.region === undefined || terminal === undefined || this.model === undefined) return
|
|
3513
3705
|
const renderer = this.opts.resolveDashboardRenderer?.() ?? renderDashboard
|
|
@@ -3562,63 +3754,47 @@ class DispatchLoop {
|
|
|
3562
3754
|
}
|
|
3563
3755
|
|
|
3564
3756
|
private startRendering(): void {
|
|
3565
|
-
if (!this.dashboard || this.
|
|
3566
|
-
this.
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
handled = this.renderOnce()
|
|
3572
|
-
.catch((error: unknown) => {
|
|
3573
|
-
// A transient store error must never kill dispatch — the dashboard
|
|
3574
|
-
// is a view, and a view that throws is a bug in the view.
|
|
3757
|
+
if (!this.dashboard || this.refresh !== undefined) return
|
|
3758
|
+
this.refresh = new DashboardRefresh(async () => {
|
|
3759
|
+
try {
|
|
3760
|
+
await this.readFrame()
|
|
3761
|
+
} catch (error) {
|
|
3762
|
+
if (this.refresh?.isFocused)
|
|
3575
3763
|
this.warn(
|
|
3576
3764
|
`dashboard render failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
3577
3765
|
)
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
// an older completion must not clear a replacement poll's guard.
|
|
3582
|
-
if (this.renderInFlight !== handled) return
|
|
3583
|
-
this.renderInFlight = undefined
|
|
3584
|
-
this.rendering = false
|
|
3585
|
-
})
|
|
3586
|
-
this.renderInFlight = handled
|
|
3587
|
-
}
|
|
3588
|
-
this.timer = setInterval(tick, DASHBOARD_POLL_MS)
|
|
3589
|
-
// Never hold the process open for a redraw.
|
|
3590
|
-
this.timer.unref?.()
|
|
3591
|
-
// Watch mode only: a second, cheap timer repaints the cached model so a
|
|
3592
|
-
// running step's elapsed advances ~1×/s decoupled from the store poll
|
|
3593
|
-
// (AC 8). `--once` renders a single snapshot per state, so it gets no ticker.
|
|
3766
|
+
throw error
|
|
3767
|
+
}
|
|
3768
|
+
})
|
|
3594
3769
|
if (this.opts.once !== true) {
|
|
3770
|
+
if (this.opts.input !== undefined) this.opts.terminal?.modes.enter(FOCUS_REPORTING_MODE)
|
|
3771
|
+
if (this.opts.terminal !== undefined && this.opts.input !== undefined) {
|
|
3772
|
+
this.suspension = installPresentationSuspension(
|
|
3773
|
+
this.opts.terminal.modes,
|
|
3774
|
+
() => {
|
|
3775
|
+
this.refresh?.suspend()
|
|
3776
|
+
this.stopInput()
|
|
3777
|
+
},
|
|
3778
|
+
() => {
|
|
3779
|
+
this.startInput()
|
|
3780
|
+
this.region?.invalidate()
|
|
3781
|
+
this.refresh?.resume()
|
|
3782
|
+
},
|
|
3783
|
+
)
|
|
3784
|
+
}
|
|
3595
3785
|
this.tickTimer = setInterval(() => this.paint(), DASHBOARD_TICK_MS)
|
|
3596
3786
|
this.tickTimer.unref?.()
|
|
3597
3787
|
}
|
|
3598
|
-
|
|
3788
|
+
void this.refresh.request()
|
|
3599
3789
|
}
|
|
3600
3790
|
|
|
3601
3791
|
private async stopRendering(): Promise<void> {
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
this.timer = undefined
|
|
3792
|
+
this.refresh?.stop()
|
|
3793
|
+
this.suspension?.close()
|
|
3794
|
+
this.opts.terminal?.modes.leave(FOCUS_REPORTING_MODE)
|
|
3606
3795
|
if (this.tickTimer !== undefined) clearInterval(this.tickTimer)
|
|
3607
3796
|
this.tickTimer = undefined
|
|
3608
|
-
this.
|
|
3609
|
-
|
|
3610
|
-
// The poll owns model/controller mutation as well as terminal painting, so
|
|
3611
|
-
// join it rather than merely suppressing a late LiveRegion.update(). Its
|
|
3612
|
-
// normal rejection is warning-handled above; the catch keeps teardown safe
|
|
3613
|
-
// even if reporting that warning itself throws.
|
|
3614
|
-
const inFlight = this.renderInFlight
|
|
3615
|
-
if (inFlight !== undefined) {
|
|
3616
|
-
try {
|
|
3617
|
-
await inFlight
|
|
3618
|
-
} catch {
|
|
3619
|
-
// Dashboard rendering remains best-effort during teardown.
|
|
3620
|
-
}
|
|
3621
|
-
}
|
|
3797
|
+
await this.refresh?.join()
|
|
3622
3798
|
}
|
|
3623
3799
|
|
|
3624
3800
|
/** Stop polling, paint the truth one last time, release the region. Every
|
|
@@ -3636,6 +3812,7 @@ class DispatchLoop {
|
|
|
3636
3812
|
// considered released.
|
|
3637
3813
|
try {
|
|
3638
3814
|
try {
|
|
3815
|
+
this.opts.terminal?.modes.leave(FOCUS_REPORTING_MODE)
|
|
3639
3816
|
this.stopInput()
|
|
3640
3817
|
} catch (error) {
|
|
3641
3818
|
// Cursor restoration must not be skipped just because stdin restoration
|
|
@@ -3652,7 +3829,8 @@ class DispatchLoop {
|
|
|
3652
3829
|
await this.stopRendering()
|
|
3653
3830
|
await this.operationTail
|
|
3654
3831
|
try {
|
|
3655
|
-
await this.
|
|
3832
|
+
if (this.opts.once === true) await this.readFrame()
|
|
3833
|
+
else await this.refresh?.finalRefresh()
|
|
3656
3834
|
} catch {
|
|
3657
3835
|
// Best-effort: a failed final frame must not mask the run's outcome.
|
|
3658
3836
|
}
|
|
@@ -3665,11 +3843,14 @@ class DispatchLoop {
|
|
|
3665
3843
|
|
|
3666
3844
|
// ── Repository supervisor lease (§12 serialization) ────────────────────────
|
|
3667
3845
|
|
|
3668
|
-
/** Claim
|
|
3846
|
+
/** Claim an unknown or expired repository lease and start the
|
|
3669
3847
|
* heartbeat timer. False means another supervisor holds it: the caller
|
|
3670
3848
|
* yields — no claims, launches, or publications. */
|
|
3671
3849
|
private async ensureRepoLease(holder: string): Promise<boolean> {
|
|
3672
3850
|
if (this.superseded) return false
|
|
3851
|
+
if (this.repoLeaseHolder === holder && this.wiring.clock().getTime() < this.repoLeaseValidUntil)
|
|
3852
|
+
return true
|
|
3853
|
+
const requestedAt = this.wiring.clock().getTime()
|
|
3673
3854
|
const claimed = await this.wiring.store
|
|
3674
3855
|
.claimRepoLease(this.repoIdentity, holder, REPO_LEASE_TTL_MS)
|
|
3675
3856
|
.catch(() => false)
|
|
@@ -3692,6 +3873,7 @@ class DispatchLoop {
|
|
|
3692
3873
|
}
|
|
3693
3874
|
return false
|
|
3694
3875
|
}
|
|
3876
|
+
this.repoLeaseValidUntil = requestedAt + REPO_LEASE_TTL_MS
|
|
3695
3877
|
if (this.repoLeaseHolder === undefined) {
|
|
3696
3878
|
this.repoLeaseHolder = holder
|
|
3697
3879
|
this.startRepoLeaseHeartbeat(holder)
|
|
@@ -3702,9 +3884,13 @@ class DispatchLoop {
|
|
|
3702
3884
|
private startRepoLeaseHeartbeat(holder: string): void {
|
|
3703
3885
|
if (this.repoLeaseHeartbeat !== undefined) return
|
|
3704
3886
|
this.repoLeaseHeartbeat = setInterval(() => {
|
|
3887
|
+
const requestedAt = this.wiring.clock().getTime()
|
|
3705
3888
|
this.wiring.store.heartbeatRepo(this.repoIdentity, holder).then(
|
|
3706
3889
|
(alive) => {
|
|
3707
|
-
if (alive)
|
|
3890
|
+
if (alive) {
|
|
3891
|
+
this.repoLeaseValidUntil = requestedAt + REPO_LEASE_TTL_MS
|
|
3892
|
+
return
|
|
3893
|
+
}
|
|
3708
3894
|
// A peer holds the repository now. Exit watch mode cleanly after
|
|
3709
3895
|
// the same teardown every stop takes (detach remote / reap local,
|
|
3710
3896
|
// signal continuations, release the lease).
|
|
@@ -3752,6 +3938,7 @@ class DispatchLoop {
|
|
|
3752
3938
|
this.stopRepoLeaseHeartbeat()
|
|
3753
3939
|
const holder = this.repoLeaseHolder
|
|
3754
3940
|
this.repoLeaseHolder = undefined
|
|
3941
|
+
this.repoLeaseValidUntil = 0
|
|
3755
3942
|
if (holder === undefined) return
|
|
3756
3943
|
try {
|
|
3757
3944
|
await this.wiring.store.releaseRepoLease(this.repoIdentity, holder)
|
|
@@ -3802,14 +3989,7 @@ class DispatchLoop {
|
|
|
3802
3989
|
// invocation.
|
|
3803
3990
|
if (this.pastDeadline()) return
|
|
3804
3991
|
const initial = await this.dispatcherTick(true).catch(async (error: unknown) => {
|
|
3805
|
-
await this.
|
|
3806
|
-
actor: DISPATCHER,
|
|
3807
|
-
type: 'dispatcher.tick-failed',
|
|
3808
|
-
payload: {
|
|
3809
|
-
run: this.runId,
|
|
3810
|
-
error: error instanceof Error ? error.message : String(error),
|
|
3811
|
-
},
|
|
3812
|
-
})
|
|
3992
|
+
await this.publishTickFailure(error)
|
|
3813
3993
|
throw error
|
|
3814
3994
|
})
|
|
3815
3995
|
const initialPrinted = this.printReport(initial, false)
|
|
@@ -3855,12 +4035,9 @@ class DispatchLoop {
|
|
|
3855
4035
|
this.printReport(report, this.harvestInFlight === undefined)
|
|
3856
4036
|
startup = false
|
|
3857
4037
|
} catch (error) {
|
|
4038
|
+
if (this.forgePublicationFailed) throw error
|
|
3858
4039
|
const message = error instanceof Error ? error.message : String(error)
|
|
3859
|
-
await this.
|
|
3860
|
-
actor: DISPATCHER,
|
|
3861
|
-
type: 'dispatcher.tick-failed',
|
|
3862
|
-
payload: { run: this.runId, error: message },
|
|
3863
|
-
})
|
|
4040
|
+
await this.publishTickFailure(error)
|
|
3864
4041
|
this.warn(`tick failed: ${message}`)
|
|
3865
4042
|
}
|
|
3866
4043
|
if (this.stopped || this.superseded) break
|
|
@@ -4060,7 +4237,8 @@ export async function abDispatch(opts: DispatchOpts): Promise<void> {
|
|
|
4060
4237
|
|
|
4061
4238
|
// Interactive production dispatch is two programs. Resolve/open only the
|
|
4062
4239
|
// Store in the terminal owner; config, plugins, adapters, runners, and ticket
|
|
4063
|
-
// I/O are constructed
|
|
4240
|
+
// I/O are constructed by the supervised private child. Explicit node-land
|
|
4241
|
+
// actions lazily open the ticket source to recheck completeness. Injected
|
|
4064
4242
|
// wiring remains the direct test/embedding seam, and every plain/non-TTY
|
|
4065
4243
|
// invocation stays on the byte-compatible in-process kernel path below.
|
|
4066
4244
|
if (
|
|
@@ -4084,6 +4262,19 @@ export async function abDispatch(opts: DispatchOpts): Promise<void> {
|
|
|
4084
4262
|
checkout: state.checkout,
|
|
4085
4263
|
storeRef: opened.storeRef,
|
|
4086
4264
|
store: opened.store,
|
|
4265
|
+
ticketSource: async () =>
|
|
4266
|
+
(
|
|
4267
|
+
await openTicketSource(
|
|
4268
|
+
{
|
|
4269
|
+
targetRepo: state.checkout,
|
|
4270
|
+
exec: resolvedOpts.exec,
|
|
4271
|
+
env: resolvedOpts.env,
|
|
4272
|
+
storeRef: opened.storeRef,
|
|
4273
|
+
stdout: resolvedOpts.stdout,
|
|
4274
|
+
},
|
|
4275
|
+
'ab land',
|
|
4276
|
+
)
|
|
4277
|
+
).source,
|
|
4087
4278
|
env: resolvedOpts.env,
|
|
4088
4279
|
terminal: resolvedOpts.terminal,
|
|
4089
4280
|
input: resolvedOpts.input,
|
|
@@ -4277,13 +4468,6 @@ export async function abDispatch(opts: DispatchOpts): Promise<void> {
|
|
|
4277
4468
|
payload: { enabled: resolvedOpts.intake, run: runId },
|
|
4278
4469
|
})
|
|
4279
4470
|
}
|
|
4280
|
-
if (resolvedOpts.defaultAutoMerge !== undefined) {
|
|
4281
|
-
await view.appendRepo(state.repo, {
|
|
4282
|
-
actor,
|
|
4283
|
-
type: 'dispatcher.auto-merge-default-set',
|
|
4284
|
-
payload: { enabled: resolvedOpts.defaultAutoMerge, run: runId },
|
|
4285
|
-
})
|
|
4286
|
-
}
|
|
4287
4471
|
|
|
4288
4472
|
await view.appendRepoWithArtifacts(
|
|
4289
4473
|
state.repo,
|
|
@@ -4314,11 +4498,10 @@ export async function abDispatch(opts: DispatchOpts): Promise<void> {
|
|
|
4314
4498
|
const loop = new DispatchLoop(liveConfig, wiring, resolvedOpts, view)
|
|
4315
4499
|
try {
|
|
4316
4500
|
await loop.run()
|
|
4317
|
-
const stopRequest =
|
|
4501
|
+
const stopRequest =
|
|
4318
4502
|
resolvedOpts.kernelRunId && resolvedOpts.signal?.aborted
|
|
4319
|
-
? await wiring.store
|
|
4320
|
-
:
|
|
4321
|
-
).find((event) => event.type === 'dispatcher.stop-requested' && event.payload.run === runId)
|
|
4503
|
+
? (await readDispatcherRunFacts(wiring.store, state.repo, runId)).value.stopRequest
|
|
4504
|
+
: undefined
|
|
4322
4505
|
const stoppedSignal =
|
|
4323
4506
|
stopRequest?.type === 'dispatcher.stop-requested'
|
|
4324
4507
|
? stopRequest.payload.signal
|
|
@@ -4356,7 +4539,7 @@ export async function abDispatch(opts: DispatchOpts): Promise<void> {
|
|
|
4356
4539
|
// Every append this invocation made, `run-stopped` included, is in the
|
|
4357
4540
|
// view; leave the reduced state behind so the next cold process reads
|
|
4358
4541
|
// only what is newer than it.
|
|
4359
|
-
|
|
4542
|
+
|
|
4360
4543
|
if (resolvedOpts.wire === undefined) await wiring.store.close()
|
|
4361
4544
|
}
|
|
4362
4545
|
}
|