@defrex/autobuild 1.0.0-beta.0 → 1.0.0-beta.2
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 +9 -4
- package/SPEC.md +295 -62
- package/bin/ab-build-runner.ts +10 -8
- package/docs/architecture.md +179 -25
- package/docs/configuration.md +41 -6
- package/docs/hosted-service.md +35 -0
- package/docs/integration-tree.md +81 -4
- package/docs/landing-policy.md +11 -0
- package/docs/migration-1.0.md +9 -0
- package/docs/operator-api.md +18 -0
- package/docs/remote-store-protocol.md +11 -0
- package/docs/restacking.md +42 -7
- package/docs/setup.md +25 -0
- package/docs/ticket-dependencies.md +6 -45
- package/package.json +3 -3
- package/packages/core/src/cli/attention.ts +4 -1
- package/packages/core/src/cli/binary.ts +17 -1
- package/packages/core/src/cli/context.ts +53 -1
- package/packages/core/src/cli/dashboard/actions.ts +4 -0
- package/packages/core/src/cli/dashboard/detail.ts +45 -1
- package/packages/core/src/cli/dashboard/facts.ts +7 -2
- package/packages/core/src/cli/dashboard/integration-detail.ts +142 -0
- package/packages/core/src/cli/dashboard/integration-row.ts +248 -0
- package/packages/core/src/cli/dashboard/landing-display.ts +64 -0
- package/packages/core/src/cli/dashboard/model.ts +140 -16
- package/packages/core/src/cli/dashboard/poll.ts +40 -4
- package/packages/core/src/cli/dashboard/refresh.ts +20 -13
- package/packages/core/src/cli/dashboard/render.ts +106 -5
- package/packages/core/src/cli/dashboard/transcript.ts +2 -1
- package/packages/core/src/cli/dispatch-frontend.ts +22 -12
- package/packages/core/src/cli/dispatch.ts +59 -25
- package/packages/core/src/cli/help.ts +19 -2
- package/packages/core/src/cli/main.ts +37 -0
- package/packages/core/src/cli/publication-settlement.ts +49 -5
- package/packages/core/src/cli/repository-status.ts +97 -2
- package/packages/core/src/cli/status.ts +24 -1
- package/packages/core/src/cli/terminals.ts +94 -93
- package/packages/core/src/cli/wait.ts +11 -2
- package/packages/core/src/cli/watch.ts +12 -0
- package/packages/core/src/config/schema.ts +3 -0
- package/packages/core/src/events/catalog.ts +38 -0
- package/packages/core/src/events/compatibility.ts +183 -0
- package/packages/core/src/events/native-session.ts +13 -0
- package/packages/core/src/events/payloads.ts +148 -2
- package/packages/core/src/events/policy.ts +209 -0
- package/packages/core/src/events/repository.ts +48 -0
- package/packages/core/src/integration/harness.ts +4 -4
- package/packages/core/src/kernel/__snapshots__/{reducer-registry.test.ts.snap → reducer-accumulator-shapes.json} +771 -538
- package/packages/core/src/kernel/change-presence.ts +4 -2
- package/packages/core/src/kernel/dispatch-capacity.ts +119 -0
- package/packages/core/src/kernel/dispatcher-liveness.ts +5 -1
- package/packages/core/src/kernel/engine.ts +25 -5
- package/packages/core/src/kernel/forge-health.ts +19 -0
- package/packages/core/src/kernel/generators/build-log.ts +18 -0
- package/packages/core/src/kernel/generators/node-restack-log.ts +1 -1
- package/packages/core/src/kernel/generators/repository-journals.ts +10 -0
- package/packages/core/src/kernel/guarded-forge.ts +159 -0
- package/packages/core/src/kernel/incremental.ts +4 -2
- package/packages/core/src/kernel/integration-completeness.ts +61 -0
- package/packages/core/src/kernel/integration-landing.ts +5 -4
- package/packages/core/src/kernel/janitor-failure.ts +36 -0
- package/packages/core/src/kernel/landing-publication.ts +35 -15
- package/packages/core/src/kernel/landing-state.ts +7 -0
- package/packages/core/src/kernel/leaf-restack-state.ts +1 -1
- package/packages/core/src/kernel/log-index.ts +12 -1
- package/packages/core/src/kernel/mixed-version.ts +52 -0
- package/packages/core/src/kernel/node-landing.ts +14 -11
- package/packages/core/src/kernel/node-restack-demand.ts +29 -0
- package/packages/core/src/kernel/node-restack-state.ts +46 -16
- package/packages/core/src/kernel/node-restack-transaction.ts +151 -8
- package/packages/core/src/kernel/node-restack.ts +34 -10
- package/packages/core/src/kernel/publication.ts +22 -0
- package/packages/core/src/kernel/read-deferrals.ts +111 -0
- package/packages/core/src/kernel/read-facts.ts +27 -6
- package/packages/core/src/kernel/reconcile-restack.ts +23 -2
- package/packages/core/src/kernel/reducer-registry.ts +15 -2
- package/packages/core/src/kernel/reducer.ts +196 -10
- package/packages/core/src/kernel/repository-attention.ts +38 -1
- package/packages/core/src/kernel/terminal-guard.ts +11 -4
- package/packages/core/src/operator/annotations.ts +6 -0
- package/packages/core/src/operator/index.ts +2 -0
- package/packages/core/src/operator/presentation.ts +5 -0
- package/packages/core/src/operator/query.ts +45 -11
- package/packages/core/src/operator/registry.ts +17 -1
- package/packages/core/src/operator/restack.ts +51 -0
- package/packages/core/src/plugin-sdk/index.ts +10 -0
- package/packages/core/src/plugins/load.ts +3 -4
- package/packages/core/src/plugins/manifest.ts +1 -1
- package/packages/core/src/ports/forge/contract.ts +23 -0
- package/packages/core/src/ports/forge/fake.ts +6 -2
- package/packages/core/src/ports/forge/git-rewrite.ts +92 -64
- package/packages/core/src/ports/forge/github-transport.ts +45 -2
- package/packages/core/src/ports/forge/github.ts +56 -17
- package/packages/core/src/ports/forge/local-git.ts +7 -2
- package/packages/core/src/ports/forge-failure.ts +40 -0
- package/packages/core/src/ports/forge-request-context.ts +35 -0
- package/packages/core/src/ports/forge-telemetry.ts +16 -0
- package/packages/core/src/ports/runner/claude.ts +136 -9
- package/packages/core/src/ports/runner/codex.ts +112 -7
- package/packages/core/src/ports/runner/contract.ts +78 -0
- package/packages/core/src/ports/runner/fake.ts +59 -1
- package/packages/core/src/ports/runner/native-cli-fixture.ts +86 -0
- package/packages/core/src/ports/runner/native-process-fixture.ts +38 -0
- package/packages/core/src/ports/runner/native-session.ts +110 -0
- package/packages/core/src/ports/runner/pi-rpc.ts +7 -1
- package/packages/core/src/ports/runner/pi.ts +162 -2
- package/packages/core/src/ports/types.ts +53 -5
- package/packages/core/src/ports/workspace/git-worktree.ts +45 -51
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +28 -12
- package/packages/core/src/processes/build-child-exit.ts +50 -2
- package/packages/core/src/processes/build-child.ts +15 -7
- package/packages/core/src/processes/build-runner.ts +909 -213
- package/packages/core/src/processes/dispatcher.ts +652 -334
- package/packages/core/src/processes/execution-no-progress.ts +15 -0
- package/packages/core/src/processes/pause-execution-fixture.ts +37 -0
- package/packages/core/src/processes/phase-failure-budget.ts +2 -1
- package/packages/core/src/processes/publication-loss.ts +7 -3
- package/packages/core/src/processes/repo-view.ts +53 -6
- package/packages/core/src/processes/tick-publication.ts +6 -2
- package/packages/core/src/runtime-identity.ts +37 -0
- package/packages/core/src/store/adapter.ts +4 -2
- package/packages/core/src/store/build-scope.ts +9 -0
- package/packages/core/src/store/contract.ts +203 -16
- package/packages/core/src/store/digest.ts +20 -2
- package/packages/core/src/store/local/schema.ts +6 -0
- package/packages/core/src/store/local/store.ts +57 -4
- package/packages/core/src/store/memory.ts +83 -2
- package/packages/core/src/store/new-build.ts +2 -2
- package/packages/core/src/store/phase-session.ts +13 -0
- package/packages/core/src/store/reduced-reads.ts +43 -4
- package/packages/core/src/store/reducer-value-shapes.json +8238 -5764
- package/packages/core/src/store/reducer-value-validation.ts +103 -3
- package/packages/core/src/store/reducer-values.ts +21 -6
- package/packages/core/src/store/remote/client.ts +146 -20
- package/packages/core/src/store/remote/compatibility.ts +6 -0
- package/packages/core/src/store/remote/index.ts +2 -0
- package/packages/core/src/store/remote/protocol.ts +19 -0
- package/packages/core/src/store/remote/version.ts +2 -0
- package/packages/core/src/store/repo-state-events.ts +3 -1
- package/packages/core/src/store/repo-tick.ts +6 -1
- package/packages/core/src/store/session-handle.ts +8 -0
- package/packages/core/src/store/snapshots.ts +21 -5
- package/packages/core/src/store/types.ts +19 -1
- package/packages/core/src/testing/dispatch-read-budget.ts +17 -2
- package/packages/core/src/testing/index.ts +7 -0
- package/packages/core/src/testing/newer-writer.ts +37 -0
- package/packages/core/src/testing/reduced-read-budget.ts +3 -0
- package/skills/guide/SKILL.md +144 -27
- package/skills/guide/references/integration-tree.md +81 -4
- package/skills/guide/references/landing-policy.md +11 -0
- package/skills/guide/references/migration-1.0.md +9 -0
- package/skills/guide/references/operator-api.md +18 -0
- package/skills/guide/references/plugin-authoring.md +55 -7
- package/skills/guide/references/remote-store-protocol.md +11 -0
- package/skills/guide/references/restacking.md +42 -7
- package/skills/guide/references/setup.md +25 -0
- package/skills/guide/references/ticket-dependencies.md +6 -45
- package/skills/implement/SKILL.md +4 -2
- package/skills/operate/SKILL.md +63 -6
- package/skills/reconcile/SKILL.md +3 -1
- package/skills/spec/SKILL.md +49 -39
- package/skills/tickets/SKILL.md +15 -43
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
import { nodeRestackDemand, presenceRestackPath } from '../kernel/node-restack-demand'
|
|
2
|
+
import {
|
|
3
|
+
deferMixedVersion,
|
|
4
|
+
mixedVersionDeferred,
|
|
5
|
+
MixedVersionDeferral,
|
|
6
|
+
} from '../kernel/mixed-version'
|
|
7
|
+
import { guardForge, ForgeCooldown } from '../kernel/guarded-forge'
|
|
8
|
+
import { recordJanitorFailure } from '../kernel/janitor-failure'
|
|
9
|
+
import { isForgeFailure } from '../ports/forge-failure'
|
|
10
|
+
import {
|
|
11
|
+
ForgeRequestDeferred,
|
|
12
|
+
withForgeRequestContext,
|
|
13
|
+
forgeRequestContext,
|
|
14
|
+
} from '../ports/forge-request-context'
|
|
15
|
+
import { dispatchCapacity, nodeCapacity, type CapacityBuild } from '../kernel/dispatch-capacity'
|
|
1
16
|
import { evaluateLandingPolicy } from '../kernel/landing-policy'
|
|
2
17
|
import {
|
|
3
18
|
landingAuthorized,
|
|
@@ -15,7 +30,6 @@ import {
|
|
|
15
30
|
import {
|
|
16
31
|
integrationComplete,
|
|
17
32
|
integrationCurrent,
|
|
18
|
-
integrationNeedsRunner,
|
|
19
33
|
integrationConfig,
|
|
20
34
|
integrationFailed,
|
|
21
35
|
integrationVerified,
|
|
@@ -37,7 +51,7 @@ import { tmpdir } from 'node:os'
|
|
|
37
51
|
import { join } from 'node:path'
|
|
38
52
|
import { runNodeTransaction } from '../kernel/node-restack-transaction'
|
|
39
53
|
import { hasBuildTrailer } from '../kernel/build-identity'
|
|
40
|
-
import { readBuildDigests } from '../store/reduced-reads'
|
|
54
|
+
import { readBuildDigests, readForgeHealth } from '../store/reduced-reads'
|
|
41
55
|
import { readBuildSelector, readBuildFacts, type CurrentBuildFacts } from '../store/reduced-reads'
|
|
42
56
|
import { ensureExecutionProgress } from './execution-no-progress'
|
|
43
57
|
import { ticketIdentity } from '../ports/tickets/identity'
|
|
@@ -330,6 +344,7 @@ export function validateSlugCandidate(candidate: string | null | undefined): str
|
|
|
330
344
|
* action. They repeat between scans and refresh on completed scans, because that is the only
|
|
331
345
|
* place the source problems are visible without provider inspection. */
|
|
332
346
|
export interface TickReport {
|
|
347
|
+
forgeRequests?: import('../ports/forge-telemetry').ForgeRequestCounts
|
|
333
348
|
/** Janitor (§15.7): builds completed as merged. */
|
|
334
349
|
merged: number
|
|
335
350
|
/** Janitor: builds completed as closed-unmerged. */
|
|
@@ -745,7 +760,7 @@ export class Dispatcher {
|
|
|
745
760
|
return decideNextFromFacts(state, log, composeBuildConfig(pinned, this.deps.config))
|
|
746
761
|
} catch (error) {
|
|
747
762
|
report.blockedDiagnostics.push(
|
|
748
|
-
`build ${slug} pipeline${revision === undefined ? '' : ` revision ${revision}`} unavailable: pipeline decisions withheld; next tick retries. Restore readable build-branch configuration or use a compatible dispatcher version. ${error instanceof Error ? error.message : String(error)}`,
|
|
763
|
+
`build ${slug} pipeline${revision === undefined ? '' : ` revision ${revision}`} unavailable: pipeline decisions withheld; next tick retries. Restore readable build-branch configuration or use a compatible dispatcher version. ${error instanceof Error || isForgeFailure(error) ? error.message : String(error)}`,
|
|
749
764
|
)
|
|
750
765
|
return undefined
|
|
751
766
|
}
|
|
@@ -797,6 +812,7 @@ export class Dispatcher {
|
|
|
797
812
|
const settle = this.deps.settlePublication
|
|
798
813
|
if (settle === undefined) return undefined
|
|
799
814
|
return async (slug) => {
|
|
815
|
+
if (await deferMixedVersion(this.store, slug)) return
|
|
800
816
|
await settle(slug)
|
|
801
817
|
await this.store.refreshBuild(slug)
|
|
802
818
|
}
|
|
@@ -807,6 +823,12 @@ export class Dispatcher {
|
|
|
807
823
|
deps.store instanceof RepoViewStore
|
|
808
824
|
? deps.store
|
|
809
825
|
: new RepoViewStore(deps.store, { repo: deps.repo })
|
|
826
|
+
deps.forge = guardForge(deps.forge, {
|
|
827
|
+
store: this.store,
|
|
828
|
+
repo: deps.repo,
|
|
829
|
+
name: deps.config.forge,
|
|
830
|
+
now: deps.clock,
|
|
831
|
+
})
|
|
810
832
|
this.leaseTtlMs = deps.opts?.leaseTtlMs ?? 0
|
|
811
833
|
this.slugNamingTimeoutMs = deps.opts?.slugNamingTimeoutMs ?? DEFAULT_SLUG_NAMING_TIMEOUT_MS
|
|
812
834
|
this.maxHarvestRecoveryAttempts =
|
|
@@ -828,8 +850,35 @@ export class Dispatcher {
|
|
|
828
850
|
return opts.deadlineAt !== undefined && this.deps.clock().getTime() >= opts.deadlineAt
|
|
829
851
|
}
|
|
830
852
|
|
|
853
|
+
lastForgeRequests?: import('../ports/forge-telemetry').ForgeRequestCounts
|
|
831
854
|
async tick(opts: TickOpts = {}): Promise<TickReport> {
|
|
832
|
-
|
|
855
|
+
const builds = new Map<string, number>()
|
|
856
|
+
let total = 0
|
|
857
|
+
let unattributed = 0
|
|
858
|
+
const stop = this.deps.forge.observeRequests?.((request) => {
|
|
859
|
+
const build = request.build ?? forgeRequestContext().build
|
|
860
|
+
total++
|
|
861
|
+
if (build) builds.set(build, (builds.get(build) ?? 0) + 1)
|
|
862
|
+
else unattributed++
|
|
863
|
+
})
|
|
864
|
+
const counts = () => ({
|
|
865
|
+
total,
|
|
866
|
+
unattributed,
|
|
867
|
+
builds: [...builds]
|
|
868
|
+
.map(([build, requests]) => ({ build, requests }))
|
|
869
|
+
.sort((a, b) => b.requests - a.requests || a.build.localeCompare(b.build))
|
|
870
|
+
.slice(0, 10),
|
|
871
|
+
complete: true,
|
|
872
|
+
})
|
|
873
|
+
this.lastForgeRequests = undefined
|
|
874
|
+
try {
|
|
875
|
+
const report = await this.runTick(opts)
|
|
876
|
+
if (stop || this.deps.config.forge === 'local-git') report.forgeRequests = counts()
|
|
877
|
+
return report
|
|
878
|
+
} finally {
|
|
879
|
+
if (stop || this.deps.config.forge === 'local-git') this.lastForgeRequests = counts()
|
|
880
|
+
stop?.()
|
|
881
|
+
}
|
|
833
882
|
}
|
|
834
883
|
|
|
835
884
|
private async runTick(opts: TickOpts): Promise<TickReport> {
|
|
@@ -961,20 +1010,32 @@ export class Dispatcher {
|
|
|
961
1010
|
* from here so a settled terminal build costs none. Records are read before
|
|
962
1011
|
* digests (as `operator/query.ts` does) so a concurrent create cannot fail
|
|
963
1012
|
* the completeness check. */
|
|
964
|
-
private async repoBuildDigests(
|
|
1013
|
+
private async repoBuildDigests(
|
|
1014
|
+
includeDeferred = false,
|
|
1015
|
+
): Promise<{ record: BuildRecord; digest: BuildDigest }[]> {
|
|
965
1016
|
const store = this.store
|
|
966
1017
|
const { repo } = this.deps
|
|
967
1018
|
const records = (await store.listBuilds()).filter((record) => record.repo === repo)
|
|
968
1019
|
const digests = await readBuildDigests(store, repo)
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
if (
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
1020
|
+
const blocked = new Set<string>()
|
|
1021
|
+
for (const record of records) {
|
|
1022
|
+
if (
|
|
1023
|
+
(digests.get(record.slug)?.compatibility?.decisiveFacts ?? 0) > 0 &&
|
|
1024
|
+
(await deferMixedVersion(store, record.slug))
|
|
1025
|
+
)
|
|
1026
|
+
blocked.add(record.slug)
|
|
1027
|
+
}
|
|
1028
|
+
return records
|
|
1029
|
+
.filter((record) => includeDeferred || !blocked.has(record.slug))
|
|
1030
|
+
.map((record) => {
|
|
1031
|
+
const digest = digests.get(record.slug)
|
|
1032
|
+
if (digest === undefined) {
|
|
1033
|
+
throw new Error(
|
|
1034
|
+
`build digest missing for ${record.slug}: the digest read broke completeness`,
|
|
1035
|
+
)
|
|
1036
|
+
}
|
|
1037
|
+
return { record, digest }
|
|
1038
|
+
})
|
|
978
1039
|
}
|
|
979
1040
|
|
|
980
1041
|
/** Builds with no terminal fact: the only ones whose tick duties change
|
|
@@ -1042,7 +1103,7 @@ export class Dispatcher {
|
|
|
1042
1103
|
error: unknown,
|
|
1043
1104
|
operation: 'ready-scan' | 'dependency-check',
|
|
1044
1105
|
): Promise<void> {
|
|
1045
|
-
const message = error instanceof Error ? error.message : String(error)
|
|
1106
|
+
const message = error instanceof Error || isForgeFailure(error) ? error.message : String(error)
|
|
1046
1107
|
await this.sourceCondition(
|
|
1047
1108
|
error instanceof TicketSourceRateLimitError
|
|
1048
1109
|
? {
|
|
@@ -1216,11 +1277,18 @@ export class Dispatcher {
|
|
|
1216
1277
|
}
|
|
1217
1278
|
}
|
|
1218
1279
|
|
|
1280
|
+
private async forgeCoolingDown(): Promise<boolean> {
|
|
1281
|
+
const active = await readForgeHealth(this.store, this.deps.repo)
|
|
1282
|
+
return !!active && Date.parse(active.resetAt) > this.deps.clock().getTime()
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1219
1285
|
private async launch(
|
|
1220
1286
|
slug: string,
|
|
1221
1287
|
launched: Set<string>,
|
|
1222
1288
|
report: TickReport = emptyTickReport(),
|
|
1223
1289
|
): Promise<LaunchRunnerResult> {
|
|
1290
|
+
if (await this.forgeCoolingDown()) return 'already-active'
|
|
1291
|
+
if (await deferMixedVersion(this.store, slug)) return 'already-active'
|
|
1224
1292
|
const launchState = (await this.store.buildFacts(slug)).state
|
|
1225
1293
|
if (
|
|
1226
1294
|
launchState.kind === 'node' &&
|
|
@@ -1491,7 +1559,7 @@ export class Dispatcher {
|
|
|
1491
1559
|
// Contained: the next tick retries this environment.
|
|
1492
1560
|
report.sandboxSettleFailures += 1
|
|
1493
1561
|
report.janitorDiagnostics.push(
|
|
1494
|
-
`operator sandbox ${environment.environmentId}: idle settlement failed — ${error instanceof Error ? error.message : String(error)}`,
|
|
1562
|
+
`operator sandbox ${environment.environmentId}: idle settlement failed — ${error instanceof Error || isForgeFailure(error) ? error.message : String(error)}`,
|
|
1495
1563
|
)
|
|
1496
1564
|
}
|
|
1497
1565
|
}
|
|
@@ -1621,6 +1689,7 @@ export class Dispatcher {
|
|
|
1621
1689
|
// the marker's lease so the next supervisor adopts immediately.
|
|
1622
1690
|
return
|
|
1623
1691
|
}
|
|
1692
|
+
if (await deferMixedVersion(store, slug)) return
|
|
1624
1693
|
leaseClaimed = await store.claimLease(slug, entry.instance, BUILD_EXECUTION_LEASE_TTL_MS)
|
|
1625
1694
|
if (!leaseClaimed) return // another live holder — the next tick re-evaluates
|
|
1626
1695
|
heartbeat = setInterval(() => {
|
|
@@ -1635,6 +1704,10 @@ export class Dispatcher {
|
|
|
1635
1704
|
return
|
|
1636
1705
|
}
|
|
1637
1706
|
const events = (await readBuildFacts(store, slug)).value
|
|
1707
|
+
if (mixedVersionDeferred(events.state)) {
|
|
1708
|
+
await deferMixedVersion(store, slug)
|
|
1709
|
+
return
|
|
1710
|
+
}
|
|
1638
1711
|
const priorGenerations = events.workspaceGenerations
|
|
1639
1712
|
const handle = await workspaces.provision({
|
|
1640
1713
|
// Local providers provision FROM the physical checkout; remote
|
|
@@ -1647,6 +1720,7 @@ export class Dispatcher {
|
|
|
1647
1720
|
branch: input.branch,
|
|
1648
1721
|
...(priorGenerations > 0 || input.generation > 0
|
|
1649
1722
|
? {
|
|
1723
|
+
publication: await this.confirmedWorkspacePublication(events, slug),
|
|
1650
1724
|
revision: events.state.integration?.cycle?.head ?? this.recoveryCheckpoint(events),
|
|
1651
1725
|
generation: Math.max(priorGenerations, input.generation),
|
|
1652
1726
|
}
|
|
@@ -1708,7 +1782,9 @@ export class Dispatcher {
|
|
|
1708
1782
|
})
|
|
1709
1783
|
}
|
|
1710
1784
|
const attempt = events.dispatchFailureCount + 1
|
|
1711
|
-
const message = (
|
|
1785
|
+
const message = (
|
|
1786
|
+
error instanceof Error || isForgeFailure(error) ? error.message : String(error)
|
|
1787
|
+
).trim()
|
|
1712
1788
|
await store.append(slug, {
|
|
1713
1789
|
actor: DISPATCHER,
|
|
1714
1790
|
type: 'dispatch.failed',
|
|
@@ -1802,196 +1878,245 @@ export class Dispatcher {
|
|
|
1802
1878
|
// stop starting new ones. The remaining builds stay janitor due — the
|
|
1803
1879
|
// next invocation re-runs them (§3.3 idempotency).
|
|
1804
1880
|
if (this.outOfBudget(opts)) break
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
state.status !== 'aborted' &&
|
|
1824
|
-
state.prState === 'open' &&
|
|
1825
|
-
state.pr &&
|
|
1826
|
-
state.landing?.native?.operation
|
|
1827
|
-
) {
|
|
1828
|
-
const path = this.forgeWorkspacePathOf(workspace)
|
|
1829
|
-
const observed = await this.deps.forge.getPrState(path, state.pr.number)
|
|
1830
|
-
observedPr = observed
|
|
1831
|
-
if (observed.state !== 'open') {
|
|
1832
|
-
await this.checkPr(
|
|
1833
|
-
record,
|
|
1834
|
-
{ history, workspace },
|
|
1835
|
-
state,
|
|
1836
|
-
report,
|
|
1837
|
-
launched,
|
|
1838
|
-
executionLeaseLive,
|
|
1839
|
-
observedPr,
|
|
1840
|
-
)
|
|
1841
|
-
continue
|
|
1842
|
-
}
|
|
1843
|
-
const result =
|
|
1844
|
-
observed.nativeAutoMerge === false
|
|
1845
|
-
? { kind: 'applied' as const }
|
|
1846
|
-
: await this.deps.forge.setAutoMerge(path, state.pr.number, false)
|
|
1847
|
-
if (result.kind !== 'applied')
|
|
1848
|
-
throw new Error('Replacement-head native cancellation unconfirmed')
|
|
1849
|
-
observedPr = { ...observed, nativeAutoMerge: false }
|
|
1850
|
-
}
|
|
1851
|
-
// Pipeline/ticket/workspace state is settled, but release-asset cleanup
|
|
1852
|
-
// has its own crash window after build.completed. Revisit only pending
|
|
1853
|
-
// hosted handles; this never relaunches a runner or consumes capacity.
|
|
1854
|
-
if (
|
|
1855
|
-
state.kind === 'node' &&
|
|
1856
|
-
state.integration?.landing?.operation &&
|
|
1857
|
-
!state.integration.audit
|
|
1858
|
-
) {
|
|
1859
|
-
await this.withKernelRepository((path) =>
|
|
1860
|
-
auditIntegrationLanding({
|
|
1861
|
-
store: this.store,
|
|
1862
|
-
forge: this.kernelForge(),
|
|
1863
|
-
exec: this.kernelForge().kernelExec ?? this.deps.exec,
|
|
1864
|
-
workspacePath: path,
|
|
1865
|
-
slug: record.slug,
|
|
1866
|
-
id: this.deps.ids('esc'),
|
|
1867
|
-
}),
|
|
1881
|
+
await withForgeRequestContext({ build: record.slug }, async () => {
|
|
1882
|
+
let previous: BuildState['janitor']
|
|
1883
|
+
let attempted = false
|
|
1884
|
+
let failed = false
|
|
1885
|
+
try {
|
|
1886
|
+
// Once a record is known, contain its complete janitor path: loading
|
|
1887
|
+
// and reducing facts, cleanup, forge/ticket calls, and store writes.
|
|
1888
|
+
// Existing partial facts leave the same work due on the next tick.
|
|
1889
|
+
let { state, workspace, log } = await this.store.buildFacts(record.slug)
|
|
1890
|
+
previous = state.janitor
|
|
1891
|
+
const controlDue =
|
|
1892
|
+
state.pendingCommands.length > 0 ||
|
|
1893
|
+
state.discardRequest !== undefined ||
|
|
1894
|
+
(state.landing?.command && state.landing.command.seq !== state.landing.acknowledgedSeq)
|
|
1895
|
+
if (
|
|
1896
|
+
!controlDue &&
|
|
1897
|
+
previous &&
|
|
1898
|
+
Date.parse(previous.nextAttemptAt) > this.deps.clock().getTime()
|
|
1868
1899
|
)
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
}
|
|
1874
|
-
continue
|
|
1875
|
-
}
|
|
1876
|
-
if (state.kind === 'node' && state.status !== 'aborted') {
|
|
1877
|
-
const command =
|
|
1878
|
-
state.pendingCommands.find((c) => c.command === 'abort') ?? state.pendingCommands.at(0)
|
|
1879
|
-
if (command !== undefined && !executionLeaseLive) {
|
|
1880
|
-
await this.store.append(record.slug, {
|
|
1881
|
-
actor: DISPATCHER,
|
|
1882
|
-
type:
|
|
1883
|
-
command.command === 'abort'
|
|
1884
|
-
? 'build.aborted'
|
|
1885
|
-
: command.command === 'pause'
|
|
1886
|
-
? 'build.paused'
|
|
1887
|
-
: 'build.resumed',
|
|
1888
|
-
payload: {},
|
|
1889
|
-
})
|
|
1890
|
-
if (command.command === 'abort')
|
|
1891
|
-
await this.cleanupAborted(record, await history(), report)
|
|
1892
|
-
continue
|
|
1900
|
+
return
|
|
1901
|
+
if (mixedVersionDeferred(state)) {
|
|
1902
|
+
await deferMixedVersion(this.store, record.slug)
|
|
1903
|
+
return
|
|
1893
1904
|
}
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1905
|
+
const executionLeaseLive = this.hasLiveExecutionLease(record)
|
|
1906
|
+
attempted = !executionLeaseLive
|
|
1907
|
+
// Raw history, read at most once and only by a branch that acts on it:
|
|
1908
|
+
// the facts above answer every quiet-path question without it.
|
|
1909
|
+
let loaded: CurrentBuildFacts | undefined
|
|
1910
|
+
const history = async (): Promise<CurrentBuildFacts> => {
|
|
1911
|
+
loaded ??= (await readBuildFacts(this.store, record.slug)).value
|
|
1912
|
+
return loaded
|
|
1898
1913
|
}
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1914
|
+
let observedPr: Awaited<ReturnType<Forge['getPrState']>> | undefined
|
|
1915
|
+
// A replacement head is followed first by a forge read and cancellation,
|
|
1916
|
+
// ahead of node cascade, controls, or any other action for this build.
|
|
1917
|
+
if (
|
|
1918
|
+
state.status !== 'done' &&
|
|
1919
|
+
state.status !== 'aborted' &&
|
|
1920
|
+
state.prState === 'open' &&
|
|
1921
|
+
state.pr &&
|
|
1922
|
+
state.landing?.native?.operation
|
|
1923
|
+
) {
|
|
1924
|
+
const path = this.forgeWorkspacePathOf(workspace)
|
|
1925
|
+
const observed = await this.deps.forge.getPrState(path, state.pr.number)
|
|
1926
|
+
observedPr = observed
|
|
1927
|
+
if (observed.state !== 'open') {
|
|
1928
|
+
await this.checkPr(
|
|
1929
|
+
record,
|
|
1930
|
+
{ history, workspace },
|
|
1931
|
+
state,
|
|
1906
1932
|
report,
|
|
1933
|
+
launched,
|
|
1934
|
+
executionLeaseLive,
|
|
1935
|
+
observedPr,
|
|
1907
1936
|
)
|
|
1937
|
+
return
|
|
1938
|
+
}
|
|
1939
|
+
const result =
|
|
1940
|
+
observed.nativeAutoMerge === false
|
|
1941
|
+
? { kind: 'applied' as const }
|
|
1942
|
+
: await this.deps.forge.setAutoMerge(path, state.pr.number, false)
|
|
1943
|
+
if (result.kind !== 'applied')
|
|
1944
|
+
throw new Error('Replacement-head native cancellation unconfirmed')
|
|
1945
|
+
observedPr = { ...observed, nativeAutoMerge: false }
|
|
1946
|
+
}
|
|
1947
|
+
// Pipeline/ticket/workspace state is settled, but release-asset cleanup
|
|
1948
|
+
// has its own crash window after build.completed. Revisit only pending
|
|
1949
|
+
// hosted handles; this never relaunches a runner or consumes capacity.
|
|
1950
|
+
if (
|
|
1951
|
+
state.kind === 'node' &&
|
|
1952
|
+
state.integration?.landing?.operation &&
|
|
1953
|
+
!state.integration.audit
|
|
1954
|
+
) {
|
|
1955
|
+
await this.withKernelRepository((path) =>
|
|
1956
|
+
auditIntegrationLanding({
|
|
1957
|
+
store: this.store,
|
|
1958
|
+
forge: this.kernelForge(),
|
|
1959
|
+
exec: this.kernelForge().kernelExec ?? this.deps.exec,
|
|
1960
|
+
workspacePath: path,
|
|
1961
|
+
slug: record.slug,
|
|
1962
|
+
id: this.deps.ids('esc'),
|
|
1963
|
+
}),
|
|
1964
|
+
)
|
|
1965
|
+
}
|
|
1966
|
+
if (state.status === 'done') {
|
|
1967
|
+
if (digest.reclaimPending === true) {
|
|
1968
|
+
await this.reclaimPrAttachments(record.slug, await history())
|
|
1969
|
+
}
|
|
1970
|
+
return
|
|
1971
|
+
}
|
|
1972
|
+
if (state.kind === 'node' && state.status !== 'aborted') {
|
|
1973
|
+
const command =
|
|
1974
|
+
state.pendingCommands.find((c) => c.command === 'abort') ??
|
|
1975
|
+
state.pendingCommands.at(0)
|
|
1976
|
+
if (command !== undefined && !executionLeaseLive) {
|
|
1977
|
+
await this.store.append(record.slug, {
|
|
1978
|
+
actor: DISPATCHER,
|
|
1979
|
+
type:
|
|
1980
|
+
command.command === 'abort'
|
|
1981
|
+
? 'build.aborted'
|
|
1982
|
+
: command.command === 'pause'
|
|
1983
|
+
? 'build.paused'
|
|
1984
|
+
: 'build.resumed',
|
|
1985
|
+
payload: {},
|
|
1986
|
+
})
|
|
1987
|
+
if (command.command === 'abort')
|
|
1988
|
+
await this.cleanupAborted(record, await history(), report)
|
|
1989
|
+
return
|
|
1990
|
+
}
|
|
1991
|
+
if (state.nodeOpened) {
|
|
1992
|
+
await this.observeTicketTarget(record, state, report)
|
|
1993
|
+
loaded = undefined
|
|
1994
|
+
;({ state, workspace, log } = await this.store.buildFacts(record.slug))
|
|
1995
|
+
}
|
|
1996
|
+
if ((state.status === 'paused' || state.status === 'blocked') && !state.pr) return
|
|
1997
|
+
if (state.nodeOpened && state.baseBranch) {
|
|
1998
|
+
if (
|
|
1999
|
+
await this.observeTarget(
|
|
2000
|
+
record.slug,
|
|
2001
|
+
state.baseBranch,
|
|
2002
|
+
log.restack.target?.sha,
|
|
2003
|
+
report,
|
|
2004
|
+
)
|
|
2005
|
+
) {
|
|
2006
|
+
loaded = undefined
|
|
2007
|
+
;({ state, workspace, log } = await this.store.buildFacts(record.slug))
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
if (
|
|
2011
|
+
state.nodeOpened &&
|
|
2012
|
+
state.status !== 'paused' &&
|
|
2013
|
+
(state.status !== 'blocked' || integrationFailed(state)) &&
|
|
2014
|
+
state.prState !== 'merged' &&
|
|
2015
|
+
state.prState !== 'closed' &&
|
|
2016
|
+
!executionLeaseLive
|
|
1908
2017
|
) {
|
|
2018
|
+
await this.prepareIntegration(record, state, report, launched, { refreshOnly: true })
|
|
2019
|
+
;({ state, workspace, log } = await this.store.buildFacts(record.slug))
|
|
2020
|
+
await this.cascadeNode(record, state, report, launched, opts)
|
|
1909
2021
|
loaded = undefined
|
|
1910
2022
|
;({ state, workspace, log } = await this.store.buildFacts(record.slug))
|
|
1911
2023
|
}
|
|
2024
|
+
if (state.nodeOpened && !executionLeaseLive) {
|
|
2025
|
+
await this.prepareIntegration(record, state, report, launched)
|
|
2026
|
+
loaded = undefined
|
|
2027
|
+
;({ state, workspace, log } = await this.store.buildFacts(record.slug))
|
|
2028
|
+
}
|
|
2029
|
+
if (state.nodeOpened !== undefined && state.pr === undefined) {
|
|
2030
|
+
await this.pollEmptyNode(record, state)
|
|
2031
|
+
return
|
|
2032
|
+
}
|
|
1912
2033
|
}
|
|
2034
|
+
// Abort is destructive human judgment and therefore outranks a queued
|
|
2035
|
+
// discard when both requests raced into the same stream.
|
|
1913
2036
|
if (
|
|
1914
|
-
|
|
1915
|
-
state.status
|
|
1916
|
-
|
|
1917
|
-
state.prState !== 'merged' &&
|
|
1918
|
-
state.prState !== 'closed' &&
|
|
1919
|
-
!executionLeaseLive
|
|
2037
|
+
!executionLeaseLive &&
|
|
2038
|
+
state.status === 'queued' &&
|
|
2039
|
+
state.pendingCommands.some((command) => command.command === 'abort')
|
|
1920
2040
|
) {
|
|
1921
|
-
await this.
|
|
2041
|
+
const acknowledged = await this.store.append(record.slug, {
|
|
2042
|
+
actor: DISPATCHER,
|
|
2043
|
+
type: 'build.aborted',
|
|
2044
|
+
payload: {},
|
|
2045
|
+
} satisfies EventWrite<'build.aborted'>)
|
|
2046
|
+
void acknowledged
|
|
2047
|
+
// The view folded the acknowledgement it just appended.
|
|
1922
2048
|
loaded = undefined
|
|
1923
|
-
|
|
2049
|
+
await this.cleanupAborted(record, await history(), report)
|
|
2050
|
+
return
|
|
1924
2051
|
}
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
2052
|
+
// Discard is a queued-only recovery control. A request that raced with
|
|
2053
|
+
// runner attachment is deliberately inert: it must never tear a live
|
|
2054
|
+
// runner's workspace down or return its ticket for a duplicate build.
|
|
2055
|
+
if (
|
|
2056
|
+
!executionLeaseLive &&
|
|
2057
|
+
state.status === 'queued' &&
|
|
2058
|
+
state.discardRequest !== undefined
|
|
2059
|
+
) {
|
|
2060
|
+
await this.cleanupDiscarded(record, await history(), report)
|
|
2061
|
+
return
|
|
1929
2062
|
}
|
|
1930
|
-
if (
|
|
1931
|
-
await this.
|
|
1932
|
-
|
|
2063
|
+
if (!executionLeaseLive && state.status === 'aborted') {
|
|
2064
|
+
await this.cleanupAborted(record, await history(), report)
|
|
2065
|
+
return
|
|
1933
2066
|
}
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
actor: DISPATCHER,
|
|
1944
|
-
type: 'build.aborted',
|
|
1945
|
-
payload: {},
|
|
1946
|
-
} satisfies EventWrite<'build.aborted'>)
|
|
1947
|
-
void acknowledged
|
|
1948
|
-
// The view folded the acknowledgement it just appended.
|
|
1949
|
-
loaded = undefined
|
|
1950
|
-
await this.cleanupAborted(record, await history(), report)
|
|
1951
|
-
continue
|
|
1952
|
-
}
|
|
1953
|
-
// Discard is a queued-only recovery control. A request that raced with
|
|
1954
|
-
// runner attachment is deliberately inert: it must never tear a live
|
|
1955
|
-
// runner's workspace down or return its ticket for a duplicate build.
|
|
1956
|
-
if (
|
|
1957
|
-
!executionLeaseLive &&
|
|
1958
|
-
state.status === 'queued' &&
|
|
1959
|
-
state.discardRequest !== undefined
|
|
1960
|
-
) {
|
|
1961
|
-
await this.cleanupDiscarded(record, await history(), report)
|
|
1962
|
-
continue
|
|
1963
|
-
}
|
|
1964
|
-
if (!executionLeaseLive && state.status === 'aborted') {
|
|
1965
|
-
await this.cleanupAborted(record, await history(), report)
|
|
1966
|
-
continue
|
|
1967
|
-
}
|
|
1968
|
-
if (state.kind !== 'node' && state.status !== 'aborted')
|
|
1969
|
-
await this.observeTicketTarget(record, state, report)
|
|
1970
|
-
if (state.kind !== 'node' && state.status !== 'aborted' && state.status !== 'queued') {
|
|
1971
|
-
const branch = await readBuildSelector(this.store, record.slug, 'baseBranch')
|
|
1972
|
-
if (branch !== undefined) {
|
|
1973
|
-
if (await this.observeTarget(record.slug, branch, log.restack.target?.sha, report)) {
|
|
1974
|
-
loaded = undefined
|
|
1975
|
-
;({ state, workspace, log } = await this.store.buildFacts(record.slug))
|
|
2067
|
+
if (state.kind !== 'node' && state.status !== 'aborted')
|
|
2068
|
+
await this.observeTicketTarget(record, state, report)
|
|
2069
|
+
if (state.kind !== 'node' && state.status !== 'aborted' && state.status !== 'queued') {
|
|
2070
|
+
const branch = await readBuildSelector(this.store, record.slug, 'baseBranch')
|
|
2071
|
+
if (branch !== undefined) {
|
|
2072
|
+
if (await this.observeTarget(record.slug, branch, log.restack.target?.sha, report)) {
|
|
2073
|
+
loaded = undefined
|
|
2074
|
+
;({ state, workspace, log } = await this.store.buildFacts(record.slug))
|
|
2075
|
+
}
|
|
1976
2076
|
}
|
|
1977
2077
|
}
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
2078
|
+
if (state.pr) {
|
|
2079
|
+
await this.checkPr(
|
|
2080
|
+
record,
|
|
2081
|
+
{ history, workspace },
|
|
2082
|
+
state,
|
|
2083
|
+
report,
|
|
2084
|
+
launched,
|
|
2085
|
+
executionLeaseLive,
|
|
2086
|
+
observedPr,
|
|
2087
|
+
)
|
|
2088
|
+
}
|
|
2089
|
+
} catch (error) {
|
|
2090
|
+
if (error instanceof ForgeCooldown) {
|
|
2091
|
+
attempted = false
|
|
2092
|
+
return
|
|
2093
|
+
}
|
|
2094
|
+
if (error instanceof MixedVersionDeferral) {
|
|
2095
|
+
attempted = false
|
|
2096
|
+
return
|
|
2097
|
+
}
|
|
2098
|
+
failed = true
|
|
2099
|
+
const message =
|
|
2100
|
+
error instanceof Error || isForgeFailure(error) ? error.message : String(error)
|
|
2101
|
+
await recordJanitorFailure(
|
|
2102
|
+
this.store,
|
|
2103
|
+
record.slug,
|
|
2104
|
+
previous,
|
|
2105
|
+
message,
|
|
2106
|
+
this.deps.clock(),
|
|
2107
|
+
this.deps.config.policy,
|
|
1988
2108
|
)
|
|
2109
|
+
report.janitorFailed += 1
|
|
2110
|
+
report.janitorDiagnostics.push(`build ${record.slug}: janitor failed — ${message}`)
|
|
2111
|
+
} finally {
|
|
2112
|
+
if (attempted && !failed && previous)
|
|
2113
|
+
await this.store.append(record.slug, {
|
|
2114
|
+
actor: DISPATCHER,
|
|
2115
|
+
type: 'build.janitor-recovered',
|
|
2116
|
+
payload: {},
|
|
2117
|
+
})
|
|
1989
2118
|
}
|
|
1990
|
-
}
|
|
1991
|
-
const message = error instanceof Error ? error.message : String(error)
|
|
1992
|
-
report.janitorFailed += 1
|
|
1993
|
-
report.janitorDiagnostics.push(`build ${record.slug}: janitor failed — ${message}`)
|
|
1994
|
-
}
|
|
2119
|
+
})
|
|
1995
2120
|
}
|
|
1996
2121
|
}
|
|
1997
2122
|
|
|
@@ -2015,7 +2140,7 @@ export class Dispatcher {
|
|
|
2015
2140
|
else await this.observeWorkTarget(record, state, report)
|
|
2016
2141
|
} catch (error) {
|
|
2017
2142
|
report.janitorDiagnostics.push(
|
|
2018
|
-
`build ${record.slug}: ticket target observation failed — ${error instanceof Error ? error.message : String(error)}`,
|
|
2143
|
+
`build ${record.slug}: ticket target observation failed — ${error instanceof Error || isForgeFailure(error) ? error.message : String(error)}`,
|
|
2019
2144
|
)
|
|
2020
2145
|
}
|
|
2021
2146
|
}
|
|
@@ -2170,7 +2295,7 @@ export class Dispatcher {
|
|
|
2170
2295
|
await this.rejectParent(
|
|
2171
2296
|
record,
|
|
2172
2297
|
ticket,
|
|
2173
|
-
error instanceof Error ? error.message : String(error),
|
|
2298
|
+
error instanceof Error || isForgeFailure(error) ? error.message : String(error),
|
|
2174
2299
|
report,
|
|
2175
2300
|
)
|
|
2176
2301
|
return
|
|
@@ -2210,7 +2335,8 @@ export class Dispatcher {
|
|
|
2210
2335
|
try {
|
|
2211
2336
|
sha = await this.baseSha(branch)
|
|
2212
2337
|
} catch (error) {
|
|
2213
|
-
const message =
|
|
2338
|
+
const message =
|
|
2339
|
+
error instanceof Error || isForgeFailure(error) ? error.message : String(error)
|
|
2214
2340
|
report.janitorDiagnostics.push(`build ${slug}: target observation failed — ${message}`)
|
|
2215
2341
|
return false
|
|
2216
2342
|
}
|
|
@@ -2235,6 +2361,29 @@ export class Dispatcher {
|
|
|
2235
2361
|
return open?.localPath ?? open?.path ?? open?.ref ?? this.deps.checkout ?? this.deps.repo
|
|
2236
2362
|
}
|
|
2237
2363
|
|
|
2364
|
+
/** Deferral withholds decisions, but cannot free an existing capacity reservation. */
|
|
2365
|
+
private async capacityBuilds(): Promise<CapacityBuild[]> {
|
|
2366
|
+
const builds: CapacityBuild[] = []
|
|
2367
|
+
for (const { record, digest } of await this.repoBuildDigests(true)) {
|
|
2368
|
+
if (digest.terminal) continue
|
|
2369
|
+
const facts = await this.store.buildFacts(record.slug)
|
|
2370
|
+
builds.push({
|
|
2371
|
+
record,
|
|
2372
|
+
state: facts.state,
|
|
2373
|
+
workspace: facts.workspace !== null,
|
|
2374
|
+
provisioning:
|
|
2375
|
+
digest.kind === 'node' &&
|
|
2376
|
+
(await readBuildFacts(this.store, record.slug)).value.provisionMarker !== undefined,
|
|
2377
|
+
})
|
|
2378
|
+
}
|
|
2379
|
+
return builds
|
|
2380
|
+
}
|
|
2381
|
+
|
|
2382
|
+
private async nodeHasCapacity(slug: string): Promise<boolean> {
|
|
2383
|
+
const builds = await this.capacityBuilds()
|
|
2384
|
+
return nodeCapacity(builds, slug, this.deps.clock()).occupied < this.deps.config.capacity
|
|
2385
|
+
}
|
|
2386
|
+
|
|
2238
2387
|
private hasLiveExecutionLease(record: BuildRecord): boolean {
|
|
2239
2388
|
return (
|
|
2240
2389
|
record.lease !== undefined &&
|
|
@@ -2313,7 +2462,8 @@ export class Dispatcher {
|
|
|
2313
2462
|
Object.assign(events, (await readBuildFacts(store, record.slug)).value)
|
|
2314
2463
|
}
|
|
2315
2464
|
const fail = (operation: string, identity: string, error: unknown): never => {
|
|
2316
|
-
|
|
2465
|
+
if (error instanceof ForgeCooldown || isForgeFailure(error)) throw error
|
|
2466
|
+
const detail = error instanceof Error || isForgeFailure(error) ? error.message : String(error)
|
|
2317
2467
|
throw new Error(
|
|
2318
2468
|
`abort cleanup ${operation} failed for ${identity}; remaining cleanup will retry on next dispatcher tick — ${detail}`,
|
|
2319
2469
|
)
|
|
@@ -2509,7 +2659,7 @@ export class Dispatcher {
|
|
|
2509
2659
|
payload: {
|
|
2510
2660
|
id: this.deps.ids('obs'),
|
|
2511
2661
|
kind: 'followup',
|
|
2512
|
-
summary: `Merged commit ${sha} identity inspection failed; inspect its Autobuild-Build trailer manually: ${error instanceof Error ? error.message : String(error)}`,
|
|
2662
|
+
summary: `Merged commit ${sha} identity inspection failed; inspect its Autobuild-Build trailer manually: ${error instanceof Error || isForgeFailure(error) ? error.message : String(error)}`,
|
|
2513
2663
|
refs: [sha],
|
|
2514
2664
|
},
|
|
2515
2665
|
})
|
|
@@ -2532,6 +2682,7 @@ export class Dispatcher {
|
|
|
2532
2682
|
): Promise<void> {
|
|
2533
2683
|
const store = this.store
|
|
2534
2684
|
const { tickets, forge } = this.deps
|
|
2685
|
+
if (await deferMixedVersion(store, record.slug)) return
|
|
2535
2686
|
const pr = state.pr
|
|
2536
2687
|
if (!pr) return
|
|
2537
2688
|
// Forge calls run from the workspace when it still exists (it does until
|
|
@@ -2885,13 +3036,22 @@ export class Dispatcher {
|
|
|
2885
3036
|
}
|
|
2886
3037
|
}
|
|
2887
3038
|
const native = state.landing?.native
|
|
3039
|
+
const failure = state.landing?.applicationFailure
|
|
3040
|
+
const failureRetry =
|
|
3041
|
+
failure &&
|
|
3042
|
+
failure.decisionSeq === state.landing?.decision?.seq &&
|
|
3043
|
+
failure.commandSeq === state.landing?.command?.seq &&
|
|
3044
|
+
sameLandingCandidate(failure.candidate, state.landing?.decision?.candidate)
|
|
3045
|
+
? failure
|
|
3046
|
+
: undefined
|
|
2888
3047
|
const retry =
|
|
2889
|
-
|
|
3048
|
+
failureRetry ??
|
|
3049
|
+
(native?.retry &&
|
|
2890
3050
|
native.decisionSeq === state.landing?.decision?.seq &&
|
|
2891
3051
|
native.commandSeq === state.landing?.command?.seq &&
|
|
2892
3052
|
sameLandingCandidate(native.candidate, state.landing?.decision?.candidate)
|
|
2893
3053
|
? native.retry
|
|
2894
|
-
: undefined
|
|
3054
|
+
: undefined)
|
|
2895
3055
|
if (
|
|
2896
3056
|
!integration &&
|
|
2897
3057
|
!nodeTarget &&
|
|
@@ -2954,6 +3114,31 @@ export class Dispatcher {
|
|
|
2954
3114
|
},
|
|
2955
3115
|
})
|
|
2956
3116
|
.catch(async (error: unknown) => {
|
|
3117
|
+
if (isForgeFailure(error)) {
|
|
3118
|
+
const attempt = (retry?.attempt ?? 0) + 1
|
|
3119
|
+
await store.append(record.slug, {
|
|
3120
|
+
actor: DISPATCHER,
|
|
3121
|
+
type: 'landing.application-failed',
|
|
3122
|
+
payload: {
|
|
3123
|
+
candidate: decision.candidate,
|
|
3124
|
+
decisionSeq: decision.seq,
|
|
3125
|
+
...(state.landing?.command ? { commandSeq: state.landing.command.seq } : {}),
|
|
3126
|
+
message: error.message,
|
|
3127
|
+
attempt,
|
|
3128
|
+
after: new Date(
|
|
3129
|
+
Math.max(
|
|
3130
|
+
this.deps.clock().getTime() +
|
|
3131
|
+
Math.min(300_000, 30_000 * 2 ** Math.min(attempt - 1, 4)),
|
|
3132
|
+
error.details.kind === 'rate-limited'
|
|
3133
|
+
? Date.parse(error.details.resetAt)
|
|
3134
|
+
: 0,
|
|
3135
|
+
),
|
|
3136
|
+
).toISOString(),
|
|
3137
|
+
},
|
|
3138
|
+
})
|
|
3139
|
+
// An uncertain enable stays pending. Never spend another request during a limit.
|
|
3140
|
+
throw error
|
|
3141
|
+
}
|
|
2957
3142
|
await settleFailedEnable()
|
|
2958
3143
|
throw error
|
|
2959
3144
|
})
|
|
@@ -3194,6 +3379,7 @@ export class Dispatcher {
|
|
|
3194
3379
|
payload: { hostedSeq: hosted.seq },
|
|
3195
3380
|
})
|
|
3196
3381
|
} catch (error) {
|
|
3382
|
+
if (error instanceof ForgeCooldown) throw error
|
|
3197
3383
|
try {
|
|
3198
3384
|
await this.store.append(slug, {
|
|
3199
3385
|
actor: DISPATCHER,
|
|
@@ -3202,8 +3388,10 @@ export class Dispatcher {
|
|
|
3202
3388
|
hostedSeq: hosted.seq,
|
|
3203
3389
|
attempt: priorAttempts + 1,
|
|
3204
3390
|
error:
|
|
3205
|
-
(error instanceof Error
|
|
3206
|
-
|
|
3391
|
+
(error instanceof Error || isForgeFailure(error)
|
|
3392
|
+
? error.message
|
|
3393
|
+
: String(error)
|
|
3394
|
+
).trim() || 'PR attachment reclamation failed without an error message',
|
|
3207
3395
|
},
|
|
3208
3396
|
})
|
|
3209
3397
|
} catch {
|
|
@@ -3214,6 +3402,11 @@ export class Dispatcher {
|
|
|
3214
3402
|
}
|
|
3215
3403
|
}
|
|
3216
3404
|
|
|
3405
|
+
private async confirmedWorkspacePublication(events: CurrentBuildFacts, slug: string) {
|
|
3406
|
+
const sha = await readBuildSelector(this.store, slug, 'publishedBranchHead')
|
|
3407
|
+
return sha === undefined ? undefined : { sha, cacheHeads: events.gitTips }
|
|
3408
|
+
}
|
|
3409
|
+
|
|
3217
3410
|
private recoveryCheckpoint(events: CurrentBuildFacts): string | undefined {
|
|
3218
3411
|
return events.recoveryCheckpoint
|
|
3219
3412
|
}
|
|
@@ -3277,12 +3470,19 @@ export class Dispatcher {
|
|
|
3277
3470
|
// publication's fate BEFORE the destructive reap. The guard's append
|
|
3278
3471
|
// failure propagates — a stale workspace with an unrecorded pending
|
|
3279
3472
|
// request is never reaped (the next tick retries).
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3473
|
+
try {
|
|
3474
|
+
events = await settlePublicationFactsBeforeRelease(
|
|
3475
|
+
{ store: this.store, settlePublication: this.settlePublication },
|
|
3476
|
+
slug,
|
|
3477
|
+
events,
|
|
3478
|
+
reason,
|
|
3479
|
+
)
|
|
3480
|
+
} catch (error) {
|
|
3481
|
+
// Keep this generation and its pending work until forge recovery,
|
|
3482
|
+
// while allowing the sweep to supervise the remaining builds.
|
|
3483
|
+
if (error instanceof ForgeRequestDeferred) return false
|
|
3484
|
+
throw error
|
|
3485
|
+
}
|
|
3286
3486
|
const attempt = (events.cleanupCounts[JSON.stringify(open.ref)] ?? 0) + 1
|
|
3287
3487
|
try {
|
|
3288
3488
|
const outcome = await recovery.reap({
|
|
@@ -3313,7 +3513,8 @@ export class Dispatcher {
|
|
|
3313
3513
|
Object.assign(events, (await readBuildFacts(this.store, slug)).value)
|
|
3314
3514
|
return true
|
|
3315
3515
|
} catch (error) {
|
|
3316
|
-
const message =
|
|
3516
|
+
const message =
|
|
3517
|
+
error instanceof Error || isForgeFailure(error) ? error.message : String(error)
|
|
3317
3518
|
const _failed = await this.store.append(slug, {
|
|
3318
3519
|
actor: DISPATCHER,
|
|
3319
3520
|
type: 'infrastructure.cleanup-attempted',
|
|
@@ -3386,7 +3587,8 @@ export class Dispatcher {
|
|
|
3386
3587
|
})
|
|
3387
3588
|
Object.assign(events, (await readBuildFacts(this.store, slug)).value)
|
|
3388
3589
|
} catch (error) {
|
|
3389
|
-
const message =
|
|
3590
|
+
const message =
|
|
3591
|
+
error instanceof Error || isForgeFailure(error) ? error.message : String(error)
|
|
3390
3592
|
const _failed = await this.store.append(slug, {
|
|
3391
3593
|
actor: DISPATCHER,
|
|
3392
3594
|
type: 'infrastructure.cleanup-attempted',
|
|
@@ -3531,6 +3733,7 @@ export class Dispatcher {
|
|
|
3531
3733
|
): Promise<DispatchOutcome> {
|
|
3532
3734
|
const store = this.store
|
|
3533
3735
|
const { config } = this.deps
|
|
3736
|
+
if (await deferMixedVersion(this.store, record.slug)) return 'parked'
|
|
3534
3737
|
if (!(await this.dispatchBudget(record.slug))) return 'parked'
|
|
3535
3738
|
let stage: EventPayload<'dispatch.failed'>['stage'] = 'create'
|
|
3536
3739
|
try {
|
|
@@ -3590,6 +3793,7 @@ export class Dispatcher {
|
|
|
3590
3793
|
branch: record.branch ?? `ab/${record.slug}`,
|
|
3591
3794
|
...(priorGenerations > 0
|
|
3592
3795
|
? {
|
|
3796
|
+
publication: await this.confirmedWorkspacePublication(events, record.slug),
|
|
3593
3797
|
revision: events.state.integration?.cycle?.head ?? this.recoveryCheckpoint(events),
|
|
3594
3798
|
generation: priorGenerations,
|
|
3595
3799
|
}
|
|
@@ -3611,6 +3815,7 @@ export class Dispatcher {
|
|
|
3611
3815
|
events = (await readBuildFacts(store, record.slug)).value
|
|
3612
3816
|
}
|
|
3613
3817
|
} catch (error) {
|
|
3818
|
+
if (error instanceof MixedVersionDeferral) return 'parked'
|
|
3614
3819
|
const events = (await readBuildFacts(store, record.slug)).value
|
|
3615
3820
|
if (stage === 'workspace' && this.deps.workspaces.recovery !== undefined) {
|
|
3616
3821
|
const open = openWorkspace(events)
|
|
@@ -3623,7 +3828,9 @@ export class Dispatcher {
|
|
|
3623
3828
|
})
|
|
3624
3829
|
}
|
|
3625
3830
|
const attempt = events.dispatchFailureCount + 1
|
|
3626
|
-
const message = (
|
|
3831
|
+
const message = (
|
|
3832
|
+
error instanceof Error || isForgeFailure(error) ? error.message : String(error)
|
|
3833
|
+
).trim()
|
|
3627
3834
|
await store.append(record.slug, {
|
|
3628
3835
|
actor: DISPATCHER,
|
|
3629
3836
|
type: 'dispatch.failed',
|
|
@@ -3658,6 +3865,7 @@ export class Dispatcher {
|
|
|
3658
3865
|
): Promise<Exclude<DispatchOutcome, 'deferred'>> {
|
|
3659
3866
|
const store = this.store
|
|
3660
3867
|
|
|
3868
|
+
if (await deferMixedVersion(this.store, record.slug)) return 'parked'
|
|
3661
3869
|
if (!(await this.dispatchBudget(record.slug))) return 'parked'
|
|
3662
3870
|
let stage: EventPayload<'dispatch.failed'>['stage'] = 'spec'
|
|
3663
3871
|
let authored = false
|
|
@@ -3757,7 +3965,9 @@ export class Dispatcher {
|
|
|
3757
3965
|
} catch (error) {
|
|
3758
3966
|
const events = (await readBuildFacts(store, record.slug)).value
|
|
3759
3967
|
const attempt = events.dispatchFailureCount + 1
|
|
3760
|
-
const message = (
|
|
3968
|
+
const message = (
|
|
3969
|
+
error instanceof Error || isForgeFailure(error) ? error.message : String(error)
|
|
3970
|
+
).trim()
|
|
3761
3971
|
await store.append(record.slug, {
|
|
3762
3972
|
actor: DISPATCHER,
|
|
3763
3973
|
type: 'dispatch.failed',
|
|
@@ -3915,6 +4125,10 @@ export class Dispatcher {
|
|
|
3915
4125
|
}
|
|
3916
4126
|
const facts = await this.store.buildFacts(record.slug)
|
|
3917
4127
|
const state = facts.state
|
|
4128
|
+
if (mixedVersionDeferred(state)) {
|
|
4129
|
+
await deferMixedVersion(this.store, record.slug)
|
|
4130
|
+
continue
|
|
4131
|
+
}
|
|
3918
4132
|
if (
|
|
3919
4133
|
(state.status === 'queued' && state.discardRequest !== undefined) ||
|
|
3920
4134
|
heldByRepositoryPause(state, paused)
|
|
@@ -4050,6 +4264,8 @@ export class Dispatcher {
|
|
|
4050
4264
|
opts: TickOpts = {},
|
|
4051
4265
|
autoMergeSeedFact: AutoMergeDefaultFact | undefined = undefined,
|
|
4052
4266
|
): Promise<void> {
|
|
4267
|
+
const health = this.store.repositoryFacts().forgeHealth
|
|
4268
|
+
if (health && Date.parse(health.resetAt) > this.deps.clock().getTime()) return
|
|
4053
4269
|
const store = this.store
|
|
4054
4270
|
const { tickets, config } = this.deps
|
|
4055
4271
|
const checkpoint = await this.scanCheckpoint('admission')
|
|
@@ -4062,21 +4278,11 @@ export class Dispatcher {
|
|
|
4062
4278
|
// Blocked and paused builds still occupy a slot: their workspaces and
|
|
4063
4279
|
// pending work are live, only waiting on a human. Capacity is per repo
|
|
4064
4280
|
// (§16.1) — another repo's builds never consume this repo's slots.
|
|
4065
|
-
|
|
4066
|
-
const
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
digest.kind !== 'node' ||
|
|
4071
|
-
(await this.store.buildFacts(record.slug)).state.nodeRestack?.conflict ||
|
|
4072
|
-
(integrationNeedsRunner((await this.store.buildFacts(record.slug)).state) &&
|
|
4073
|
-
(this.hasLiveExecutionLease(record) ||
|
|
4074
|
-
(await this.store.buildFacts(record.slug)).workspace !== null))
|
|
4075
|
-
)
|
|
4076
|
-
active += 1
|
|
4077
|
-
if (record.ticket) activeRefs.push(record.ticket)
|
|
4078
|
-
}
|
|
4079
|
-
}
|
|
4281
|
+
const capacityBuilds = await this.capacityBuilds()
|
|
4282
|
+
const active = dispatchCapacity(capacityBuilds, config.capacity, this.deps.clock()).occupied
|
|
4283
|
+
const activeRefs: TicketRef[] = capacityBuilds
|
|
4284
|
+
.filter(({ state }) => state.status !== 'done' && state.status !== 'aborted')
|
|
4285
|
+
.flatMap(({ record }) => (record.ticket ? [record.ticket] : []))
|
|
4080
4286
|
let capacity = config.capacity - active
|
|
4081
4287
|
|
|
4082
4288
|
// The ready scan runs even at full capacity: `queued` is the operator's
|
|
@@ -4126,7 +4332,15 @@ export class Dispatcher {
|
|
|
4126
4332
|
// still runs either way, so the standing queue-depth report stays honest —
|
|
4127
4333
|
// this only declines to claim a ticket into a build that would immediately
|
|
4128
4334
|
// sit held.
|
|
4129
|
-
if (
|
|
4335
|
+
if (
|
|
4336
|
+
paused ||
|
|
4337
|
+
(capacity <= 0 &&
|
|
4338
|
+
!ready.some(
|
|
4339
|
+
(ticket) =>
|
|
4340
|
+
ticket.kind === 'node' ||
|
|
4341
|
+
(ticket.target !== undefined && (ticket.blockedBy?.length ?? 0) > 0),
|
|
4342
|
+
))
|
|
4343
|
+
) {
|
|
4130
4344
|
await this.sourceCondition(undefined, 'ready-scan')
|
|
4131
4345
|
if (!this.outOfBudget(opts)) await this.completeScan(checkpoint, report)
|
|
4132
4346
|
return
|
|
@@ -4176,6 +4390,7 @@ export class Dispatcher {
|
|
|
4176
4390
|
string,
|
|
4177
4391
|
{ branch: string; destination: string; head: string; identities: string[] }
|
|
4178
4392
|
>()
|
|
4393
|
+
const demands: { slug: string; request: EventPayload<'node.restack-requested'> }[] = []
|
|
4179
4394
|
const verdicts = new Map<string, DependencyVerdict>()
|
|
4180
4395
|
const failed = new Set<string>()
|
|
4181
4396
|
const targetBlocked = new Set<string>()
|
|
@@ -4222,7 +4437,14 @@ export class Dispatcher {
|
|
|
4222
4437
|
aliases: new Map(),
|
|
4223
4438
|
landings: [],
|
|
4224
4439
|
}
|
|
4225
|
-
verdict = await this.presenceVerdict(
|
|
4440
|
+
verdict = await this.presenceVerdict(
|
|
4441
|
+
ticket,
|
|
4442
|
+
target,
|
|
4443
|
+
nodes,
|
|
4444
|
+
inputs,
|
|
4445
|
+
demands,
|
|
4446
|
+
destinationHeads,
|
|
4447
|
+
)
|
|
4226
4448
|
} else verdict = analyzeDependencies(ticket.ref.id, ticket.blockedBy ?? [], nodes)
|
|
4227
4449
|
} catch (error) {
|
|
4228
4450
|
if (error instanceof TicketSourceRateLimitError) {
|
|
@@ -4233,14 +4455,38 @@ export class Dispatcher {
|
|
|
4233
4455
|
failed.add(ticket.ref.id)
|
|
4234
4456
|
report.dependencyCheckFailed += 1
|
|
4235
4457
|
report.dependencyDiagnostics.push(
|
|
4236
|
-
`ticket ${ticket.ref.id}: dependency check failed — ${error instanceof Error ? error.message : String(error)}`,
|
|
4458
|
+
`ticket ${ticket.ref.id}: dependency check failed — ${error instanceof Error || isForgeFailure(error) ? error.message : String(error)}`,
|
|
4237
4459
|
)
|
|
4238
4460
|
continue
|
|
4239
4461
|
}
|
|
4240
4462
|
verdicts.set(ticket.ref.id, verdict)
|
|
4241
4463
|
}
|
|
4242
4464
|
if (this.outOfBudget(opts)) return
|
|
4243
|
-
if (failed.size === 0)
|
|
4465
|
+
if (failed.size === 0) {
|
|
4466
|
+
await this.sourceCondition(undefined, 'dependency-check')
|
|
4467
|
+
for (const { slug, request } of demands) {
|
|
4468
|
+
if (this.outOfBudget(opts)) return
|
|
4469
|
+
const current = (await this.store.buildFacts(slug)).state
|
|
4470
|
+
const pending = Object.values(current.nodeRestack?.requests ?? {})
|
|
4471
|
+
if (
|
|
4472
|
+
current.baseBranch !== request.branch ||
|
|
4473
|
+
pending.some(
|
|
4474
|
+
(old) =>
|
|
4475
|
+
old.reason === 'presence' &&
|
|
4476
|
+
old.branch === request.branch &&
|
|
4477
|
+
old.dependent?.source === request.dependent?.source &&
|
|
4478
|
+
old.dependent?.id === request.dependent?.id &&
|
|
4479
|
+
(request.identities ?? []).every((id) => old.identities?.includes(id)),
|
|
4480
|
+
)
|
|
4481
|
+
)
|
|
4482
|
+
continue
|
|
4483
|
+
await this.store.appendIfCurrent(slug, current.lastSeq, {
|
|
4484
|
+
actor: DISPATCHER,
|
|
4485
|
+
type: 'node.restack-requested',
|
|
4486
|
+
payload: request,
|
|
4487
|
+
})
|
|
4488
|
+
}
|
|
4489
|
+
}
|
|
4244
4490
|
for (const verdict of verdicts.values()) {
|
|
4245
4491
|
if (verdict.unresolved.length > 0) {
|
|
4246
4492
|
report.dependencyBlocked += 1
|
|
@@ -4493,6 +4739,7 @@ export class Dispatcher {
|
|
|
4493
4739
|
launched: Set<string>,
|
|
4494
4740
|
opts: TickOpts,
|
|
4495
4741
|
): Promise<void> {
|
|
4742
|
+
if (await deferMixedVersion(this.store, record.slug)) return
|
|
4496
4743
|
if (state.nodeRestack?.parentRequest && !state.nodeRestack.active) return
|
|
4497
4744
|
if (
|
|
4498
4745
|
state.nodeRestack?.parentChange &&
|
|
@@ -4538,8 +4785,11 @@ export class Dispatcher {
|
|
|
4538
4785
|
forge.remoteBranchSha(record.branch),
|
|
4539
4786
|
])
|
|
4540
4787
|
if (
|
|
4541
|
-
parent === state.nodeRestack?.contributionBase &&
|
|
4542
|
-
|
|
4788
|
+
(parent === state.nodeRestack?.contributionBase || !nodeRestackDemand(state)) &&
|
|
4789
|
+
state.nodeRestack?.distance?.parent === parent &&
|
|
4790
|
+
state.nodeRestack.distance.base === state.nodeRestack.contributionBase &&
|
|
4791
|
+
head === state.nodeRestack?.inventory?.head &&
|
|
4792
|
+
!Object.keys(state.nodeRestack?.requests ?? {}).length
|
|
4543
4793
|
)
|
|
4544
4794
|
return
|
|
4545
4795
|
}
|
|
@@ -4616,7 +4866,10 @@ export class Dispatcher {
|
|
|
4616
4866
|
const parentHead = forge.remoteBranchSha
|
|
4617
4867
|
? await forge.remoteBranchSha(state.baseBranch!)
|
|
4618
4868
|
: undefined
|
|
4619
|
-
if (
|
|
4869
|
+
if (
|
|
4870
|
+
state.nodeRestack?.active ||
|
|
4871
|
+
(nodeRestackDemand(state) && parentHead !== state.nodeRestack?.contributionBase)
|
|
4872
|
+
) {
|
|
4620
4873
|
// Upgrade recovery: an old dispatcher may have left a native request
|
|
4621
4874
|
// armed. Cancel every targeting leaf before admitting a node rewrite.
|
|
4622
4875
|
for (const child of await this.repoBuildDigests()) {
|
|
@@ -4644,6 +4897,7 @@ export class Dispatcher {
|
|
|
4644
4897
|
workspacePath,
|
|
4645
4898
|
holder,
|
|
4646
4899
|
canWrite: async () => {
|
|
4900
|
+
if (await deferMixedVersion(this.store, record.slug)) return false
|
|
4647
4901
|
if (this.outOfBudget(opts)) return false
|
|
4648
4902
|
if (state.pr && (await forge.getPrState(checkout, state.pr.number)).state !== 'open')
|
|
4649
4903
|
return false
|
|
@@ -4704,19 +4958,7 @@ export class Dispatcher {
|
|
|
4704
4958
|
}
|
|
4705
4959
|
}
|
|
4706
4960
|
|
|
4707
|
-
|
|
4708
|
-
for (const other of await this.repoBuildDigests()) {
|
|
4709
|
-
if (other.record.slug === record.slug || other.digest.terminal) continue
|
|
4710
|
-
if (
|
|
4711
|
-
other.digest.kind !== 'node' ||
|
|
4712
|
-
(await this.store.buildFacts(other.record.slug)).state.nodeRestack?.conflict ||
|
|
4713
|
-
(integrationNeedsRunner((await this.store.buildFacts(other.record.slug)).state) &&
|
|
4714
|
-
(this.hasLiveExecutionLease(other.record) ||
|
|
4715
|
-
(await this.store.buildFacts(other.record.slug)).workspace !== null))
|
|
4716
|
-
)
|
|
4717
|
-
occupied++
|
|
4718
|
-
}
|
|
4719
|
-
if (occupied >= this.deps.config.capacity) return
|
|
4961
|
+
if (!(await this.nodeHasCapacity(record.slug))) return
|
|
4720
4962
|
if (openWorkspace(facts) === null && this.deps.workspaces.recovery) {
|
|
4721
4963
|
const kicked = await this.ensureProvisionContinuation(record, facts, 'launch')
|
|
4722
4964
|
if (kicked === 'kicked') report.provisioning += 1
|
|
@@ -4745,7 +4987,8 @@ export class Dispatcher {
|
|
|
4745
4987
|
}
|
|
4746
4988
|
}
|
|
4747
4989
|
} catch (error) {
|
|
4748
|
-
const message =
|
|
4990
|
+
const message =
|
|
4991
|
+
error instanceof Error || isForgeFailure(error) ? error.message : String(error)
|
|
4749
4992
|
// Safety refusals require human judgment. Infrastructure failures remain
|
|
4750
4993
|
// retryable dispatch failures and retain their active reservation.
|
|
4751
4994
|
if (
|
|
@@ -4782,6 +5025,7 @@ export class Dispatcher {
|
|
|
4782
5025
|
state: BuildState,
|
|
4783
5026
|
report: TickReport,
|
|
4784
5027
|
launched: Set<string>,
|
|
5028
|
+
sampling: { refreshOnly?: boolean } = {},
|
|
4785
5029
|
): Promise<void> {
|
|
4786
5030
|
if (
|
|
4787
5031
|
state.status === 'paused' ||
|
|
@@ -4813,12 +5057,13 @@ export class Dispatcher {
|
|
|
4813
5057
|
this.integrationPollDue(
|
|
4814
5058
|
this.integrationPolls,
|
|
4815
5059
|
record.slug,
|
|
4816
|
-
`${comparison.headSha}:${comparison.parentSha}:${state.landing?.command?.seq ?? state.landing?.decision?.seq ?? ''}:${claims}`,
|
|
5060
|
+
`${comparison.headSha}:${comparison.parentSha}:${state.nodeRestack?.inventory?.head ?? ''}:${state.landing?.command?.seq ?? state.landing?.decision?.seq ?? ''}:${claims}`,
|
|
4817
5061
|
)
|
|
4818
5062
|
) {
|
|
4819
5063
|
await this.observeIntegration(record.slug)
|
|
4820
5064
|
state = (await this.store.buildFacts(record.slug)).state
|
|
4821
5065
|
}
|
|
5066
|
+
if (sampling.refreshOnly) return
|
|
4822
5067
|
if (
|
|
4823
5068
|
state.integration?.cycle &&
|
|
4824
5069
|
!state.nodeRestack?.active &&
|
|
@@ -4902,20 +5147,7 @@ export class Dispatcher {
|
|
|
4902
5147
|
if (openWorkspace(facts)) await this.releaseWorkspace(record.slug, facts)
|
|
4903
5148
|
return
|
|
4904
5149
|
}
|
|
4905
|
-
|
|
4906
|
-
for (const other of await this.nonterminalBuilds()) {
|
|
4907
|
-
if (other.slug === record.slug) continue
|
|
4908
|
-
const current = (await this.store.buildFacts(other.slug)).state
|
|
4909
|
-
if (
|
|
4910
|
-
current.kind !== 'node' ||
|
|
4911
|
-
current.nodeRestack?.conflict ||
|
|
4912
|
-
(integrationNeedsRunner(current) &&
|
|
4913
|
-
(this.hasLiveExecutionLease(other) ||
|
|
4914
|
-
(await this.store.buildFacts(other.slug)).workspace !== null))
|
|
4915
|
-
)
|
|
4916
|
-
occupied++
|
|
4917
|
-
}
|
|
4918
|
-
if (occupied >= this.deps.config.capacity) return
|
|
5150
|
+
if (!(await this.nodeHasCapacity(record.slug))) return
|
|
4919
5151
|
await this.observeIntegration(record.slug)
|
|
4920
5152
|
state = (await this.store.buildFacts(record.slug)).state
|
|
4921
5153
|
if (!integrationCurrent(state)) return
|
|
@@ -4970,7 +5202,15 @@ export class Dispatcher {
|
|
|
4970
5202
|
return comparison
|
|
4971
5203
|
}
|
|
4972
5204
|
const comparison = await observe()
|
|
4973
|
-
|
|
5205
|
+
// Branch comparison is telemetry, never contribution provenance: a
|
|
5206
|
+
// rewritten parent can make inherited siblings appear "ahead". Only the
|
|
5207
|
+
// inventory of this exact source head proves that the node owns work.
|
|
5208
|
+
const inventory = state.nodeRestack?.inventory
|
|
5209
|
+
if (
|
|
5210
|
+
inventory?.head !== comparison.headSha ||
|
|
5211
|
+
!((inventory.contributions?.length ?? 0) + inventory.foreign.length)
|
|
5212
|
+
)
|
|
5213
|
+
return
|
|
4974
5214
|
let pr: Awaited<ReturnType<typeof forge.openPr>>
|
|
4975
5215
|
try {
|
|
4976
5216
|
pr = await forge.openPr({
|
|
@@ -4981,7 +5221,11 @@ export class Dispatcher {
|
|
|
4981
5221
|
body: `Integration build ${record.slug}. Target: ${state.target?.ticket.id ?? state.baseBranch}. Human landing required.`,
|
|
4982
5222
|
})
|
|
4983
5223
|
} catch (error) {
|
|
4984
|
-
if (
|
|
5224
|
+
if (
|
|
5225
|
+
error instanceof NoCommitsBetweenBranchesError &&
|
|
5226
|
+
(await observe()).headSha === comparison.parentSha
|
|
5227
|
+
)
|
|
5228
|
+
return
|
|
4985
5229
|
throw error
|
|
4986
5230
|
}
|
|
4987
5231
|
await this.store.append(record.slug, { actor: DISPATCHER, type: 'pr.opened', payload: { pr } })
|
|
@@ -5027,8 +5271,12 @@ export class Dispatcher {
|
|
|
5027
5271
|
const head = pr.headSha
|
|
5028
5272
|
const base =
|
|
5029
5273
|
state.nodeRestack?.contributionBoundaries?.[head] ??
|
|
5030
|
-
state.nodeRestack?.
|
|
5031
|
-
|
|
5274
|
+
(state.nodeRestack?.inventory?.head === head
|
|
5275
|
+
? state.nodeRestack.contributionBase
|
|
5276
|
+
: undefined) ??
|
|
5277
|
+
(state.nodeRestack?.contributionBase === state.nodeOpened?.sha
|
|
5278
|
+
? state.nodeOpened?.sha
|
|
5279
|
+
: undefined)
|
|
5032
5280
|
if (!head || !base) throw new Error('missing node contribution source range')
|
|
5033
5281
|
// Fetch retained objects when the kernel repository has not seen
|
|
5034
5282
|
// this source head (including remote guest publication).
|
|
@@ -5098,6 +5346,93 @@ export class Dispatcher {
|
|
|
5098
5346
|
}
|
|
5099
5347
|
}
|
|
5100
5348
|
|
|
5349
|
+
private async sampleDestinationPresence(
|
|
5350
|
+
branch: string,
|
|
5351
|
+
destination: string,
|
|
5352
|
+
target: { target: { build: string } } | undefined,
|
|
5353
|
+
inputs: PresenceInputs,
|
|
5354
|
+
observations: Map<
|
|
5355
|
+
string,
|
|
5356
|
+
{ branch: string; destination: string; head: string; identities: string[] }
|
|
5357
|
+
>,
|
|
5358
|
+
) {
|
|
5359
|
+
let observed = observations.get(destination)
|
|
5360
|
+
if (!observed) {
|
|
5361
|
+
const forge = this.kernelForge()
|
|
5362
|
+
if (!forge.remoteBranchSha || (!forge.snapshotBase && !forge.kernelExec && !forge.rewrite))
|
|
5363
|
+
throw new Error('forge cannot snapshot destination presence')
|
|
5364
|
+
const head = await forge.remoteBranchSha(branch)
|
|
5365
|
+
const evidence = JSON.stringify({
|
|
5366
|
+
version: 2,
|
|
5367
|
+
revisions: [
|
|
5368
|
+
...inputs.entries
|
|
5369
|
+
.filter(({ digest }) => digest.mergedSha || digest.nodeContribution)
|
|
5370
|
+
.map(({ record, digest }) => [record.slug, digest.readinessChangeSeq]),
|
|
5371
|
+
...[...inputs.states].map(([slug, state]) => [slug, state.lastSeq]),
|
|
5372
|
+
].sort(),
|
|
5373
|
+
})
|
|
5374
|
+
const cached = this.store.repositoryFacts().presence[destination]
|
|
5375
|
+
if (cached?.head === head && cached.branch === branch && cached.evidence === evidence)
|
|
5376
|
+
observed = cached
|
|
5377
|
+
else
|
|
5378
|
+
observed = await this.withKernelRepository(async (path) => {
|
|
5379
|
+
const destinationRef = `refs/autobuild/reconcile/${target?.target.build ?? 'presence'}/presence`
|
|
5380
|
+
let sampled: string
|
|
5381
|
+
if (forge.snapshotBase)
|
|
5382
|
+
sampled = await forge.snapshotBase({
|
|
5383
|
+
workspacePath: path,
|
|
5384
|
+
base: branch,
|
|
5385
|
+
destinationRef,
|
|
5386
|
+
})
|
|
5387
|
+
else if (target && forge.rewrite)
|
|
5388
|
+
sampled = await forge.rewrite.snapshot({
|
|
5389
|
+
workspacePath: path,
|
|
5390
|
+
branch,
|
|
5391
|
+
destinationRef,
|
|
5392
|
+
})
|
|
5393
|
+
else {
|
|
5394
|
+
const exec = forge.kernelExec ?? this.deps.exec
|
|
5395
|
+
const fetch = await exec(
|
|
5396
|
+
[
|
|
5397
|
+
'git',
|
|
5398
|
+
'fetch',
|
|
5399
|
+
'--no-tags',
|
|
5400
|
+
'--no-write-fetch-head',
|
|
5401
|
+
'--refmap=',
|
|
5402
|
+
'origin',
|
|
5403
|
+
`+refs/heads/${branch}:${destinationRef}`,
|
|
5404
|
+
],
|
|
5405
|
+
{ cwd: path },
|
|
5406
|
+
)
|
|
5407
|
+
if (fetch.exitCode !== 0) throw new Error(fetch.stderr)
|
|
5408
|
+
const resolved = await exec(
|
|
5409
|
+
['git', 'rev-parse', '--verify', `${destinationRef}^{commit}`],
|
|
5410
|
+
{ cwd: path },
|
|
5411
|
+
)
|
|
5412
|
+
if (resolved.exitCode !== 0) throw new Error(resolved.stderr)
|
|
5413
|
+
sampled = resolved.stdout.trim()
|
|
5414
|
+
}
|
|
5415
|
+
if (sampled !== head) throw new Error('destination moved while sampling presence')
|
|
5416
|
+
const identities = await observePresence(
|
|
5417
|
+
{ exec: forge.kernelExec ?? this.deps.exec, workspacePath: path },
|
|
5418
|
+
head,
|
|
5419
|
+
inputs.landings,
|
|
5420
|
+
inputs.aliases,
|
|
5421
|
+
)
|
|
5422
|
+
const payload = { branch, destination, head, evidence, identities }
|
|
5423
|
+
await this.store.ensureRepo(this.deps.repo)
|
|
5424
|
+
await this.store.appendRepo(this.deps.repo, {
|
|
5425
|
+
actor: DISPATCHER,
|
|
5426
|
+
type: 'change-presence.observed',
|
|
5427
|
+
payload,
|
|
5428
|
+
})
|
|
5429
|
+
return payload
|
|
5430
|
+
})
|
|
5431
|
+
observations.set(destination, observed)
|
|
5432
|
+
}
|
|
5433
|
+
return observed!
|
|
5434
|
+
}
|
|
5435
|
+
|
|
5101
5436
|
private async presenceVerdict(
|
|
5102
5437
|
ticket: Ticket,
|
|
5103
5438
|
target:
|
|
@@ -5105,6 +5440,7 @@ export class Dispatcher {
|
|
|
5105
5440
|
| undefined,
|
|
5106
5441
|
nodes: Map<string, DependencyState>,
|
|
5107
5442
|
inputs: PresenceInputs,
|
|
5443
|
+
demands: { slug: string; request: EventPayload<'node.restack-requested'> }[],
|
|
5108
5444
|
observations: Map<
|
|
5109
5445
|
string,
|
|
5110
5446
|
{ branch: string; destination: string; head: string; identities: string[] }
|
|
@@ -5156,79 +5492,61 @@ export class Dispatcher {
|
|
|
5156
5492
|
diagnostics.push(...lifecycle.diagnostics)
|
|
5157
5493
|
if ([...required.values()].every((ids) => ids.length === 0)) return { unresolved, diagnostics }
|
|
5158
5494
|
try {
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
|
|
5164
|
-
|
|
5165
|
-
|
|
5166
|
-
|
|
5167
|
-
|
|
5168
|
-
|
|
5169
|
-
|
|
5170
|
-
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
|
|
5176
|
-
|
|
5177
|
-
|
|
5178
|
-
|
|
5179
|
-
|
|
5180
|
-
|
|
5181
|
-
|
|
5182
|
-
|
|
5183
|
-
|
|
5184
|
-
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
|
|
5198
|
-
|
|
5199
|
-
|
|
5200
|
-
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
5205
|
-
|
|
5206
|
-
|
|
5207
|
-
|
|
5208
|
-
|
|
5209
|
-
|
|
5210
|
-
|
|
5211
|
-
|
|
5212
|
-
if (resolved.exitCode !== 0) throw new Error(resolved.stderr)
|
|
5213
|
-
sampled = resolved.stdout.trim()
|
|
5214
|
-
}
|
|
5215
|
-
if (sampled !== head) throw new Error('destination moved while sampling presence')
|
|
5216
|
-
const identities = await observePresence(
|
|
5217
|
-
{ exec: forge.kernelExec ?? this.deps.exec, workspacePath: path },
|
|
5218
|
-
head,
|
|
5219
|
-
inputs.landings,
|
|
5220
|
-
inputs.aliases,
|
|
5221
|
-
)
|
|
5222
|
-
const payload = { branch, destination, head, evidence, identities }
|
|
5223
|
-
await this.store.ensureRepo(this.deps.repo)
|
|
5224
|
-
await this.store.appendRepo(this.deps.repo, {
|
|
5225
|
-
actor: DISPATCHER,
|
|
5226
|
-
type: 'change-presence.observed',
|
|
5227
|
-
payload,
|
|
5228
|
-
})
|
|
5229
|
-
return payload
|
|
5495
|
+
const observed = await this.sampleDestinationPresence(
|
|
5496
|
+
branch,
|
|
5497
|
+
destination,
|
|
5498
|
+
target,
|
|
5499
|
+
inputs,
|
|
5500
|
+
observations,
|
|
5501
|
+
)
|
|
5502
|
+
const missing = [
|
|
5503
|
+
...new Set(
|
|
5504
|
+
[...required.values()].flatMap((ids) => missingChanges(ids, observed.identities)),
|
|
5505
|
+
),
|
|
5506
|
+
]
|
|
5507
|
+
if (target && missing.length) {
|
|
5508
|
+
const path: { slug?: string; identities: string[]; branch: string; head: string }[] = [
|
|
5509
|
+
{ slug: target.target.build, ...observed },
|
|
5510
|
+
]
|
|
5511
|
+
const seen = new Set<string>()
|
|
5512
|
+
let slug: string | undefined = target.target.build
|
|
5513
|
+
while (slug) {
|
|
5514
|
+
if (seen.has(slug)) throw new Error('cyclic node ancestry')
|
|
5515
|
+
seen.add(slug)
|
|
5516
|
+
const record = await this.store.getBuild(slug)
|
|
5517
|
+
if (!record || record.repo !== this.deps.repo) throw new Error('missing node ancestry')
|
|
5518
|
+
const state: BuildState = (await this.store.buildFacts(slug)).state
|
|
5519
|
+
if (state.kind !== 'node' || !state.baseBranch || state.nodeRestack?.parentRequest)
|
|
5520
|
+
throw new Error('uncertain node ancestry')
|
|
5521
|
+
slug = state.target?.build
|
|
5522
|
+
const parent = await this.sampleDestinationPresence(
|
|
5523
|
+
state.baseBranch,
|
|
5524
|
+
slug ?? `root:${state.baseBranch}`,
|
|
5525
|
+
slug ? { target: { build: slug } } : undefined,
|
|
5526
|
+
inputs,
|
|
5527
|
+
observations,
|
|
5528
|
+
)
|
|
5529
|
+
path.push({ ...(slug ? { slug } : {}), ...parent })
|
|
5530
|
+
if (missing.every((id) => path.some((entry) => entry.identities.includes(id)))) break
|
|
5531
|
+
}
|
|
5532
|
+
for (const requested of presenceRestackPath(path, missing)) {
|
|
5533
|
+
const index = path.findIndex((entry) => entry.slug === requested)
|
|
5534
|
+
const parent = path[index + 1]!
|
|
5535
|
+
const identities = missing.filter((id) =>
|
|
5536
|
+
path.slice(index + 1).some((entry) => entry.identities.includes(id)),
|
|
5537
|
+
)
|
|
5538
|
+
demands.push({
|
|
5539
|
+
slug: requested,
|
|
5540
|
+
request: {
|
|
5541
|
+
id: this.deps.ids('presence-restack'),
|
|
5542
|
+
reason: 'presence',
|
|
5543
|
+
branch: parent.branch,
|
|
5544
|
+
parent: parent.head,
|
|
5545
|
+
dependent: ticket.ref,
|
|
5546
|
+
identities,
|
|
5547
|
+
},
|
|
5230
5548
|
})
|
|
5231
|
-
|
|
5549
|
+
}
|
|
5232
5550
|
}
|
|
5233
5551
|
for (const [id, identities] of required) {
|
|
5234
5552
|
const missing = missingChanges(identities, observed.identities)
|
|
@@ -5243,7 +5561,7 @@ export class Dispatcher {
|
|
|
5243
5561
|
for (const id of required.keys()) {
|
|
5244
5562
|
unresolved.push(id)
|
|
5245
5563
|
diagnostics.push(
|
|
5246
|
-
`ticket ${ticket.ref.id}: blocker ${id} presence unavailable in ${destination} (${branch}): ${error instanceof Error ? error.message : String(error)}`,
|
|
5564
|
+
`ticket ${ticket.ref.id}: blocker ${id} presence unavailable in ${destination} (${branch}): ${error instanceof Error || isForgeFailure(error) ? error.message : String(error)}`,
|
|
5247
5565
|
)
|
|
5248
5566
|
}
|
|
5249
5567
|
}
|