@defrex/autobuild 1.0.0-beta.1 → 1.0.0-beta.3
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/SPEC.md +310 -56
- package/bin/ab-build-runner.ts +10 -8
- package/docs/architecture.md +177 -23
- package/docs/configuration.md +35 -4
- package/docs/hosted-service.md +35 -0
- package/docs/integration-tree.md +83 -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 +16 -0
- package/docs/remote-ticket-protocol.md +5 -0
- package/docs/restacking.md +42 -7
- package/docs/setup.md +25 -0
- package/docs/spec-standard.md +71 -0
- package/docs/ticket-dependencies.md +6 -45
- package/docs/ticket-migration.md +50 -4
- 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/build-control.ts +3 -3
- 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 +144 -0
- package/packages/core/src/cli/dashboard/integration-row.ts +255 -0
- package/packages/core/src/cli/dashboard/landing-display.ts +64 -0
- package/packages/core/src/cli/dashboard/model.ts +147 -16
- package/packages/core/src/cli/dashboard/poll.ts +40 -4
- 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 +11 -0
- package/packages/core/src/cli/dispatch-repository-feed.ts +2 -1
- package/packages/core/src/cli/dispatch.ts +49 -14
- package/packages/core/src/cli/help.ts +17 -1
- package/packages/core/src/cli/main.ts +48 -8
- package/packages/core/src/cli/publication-settlement.ts +49 -5
- package/packages/core/src/cli/repository-status.ts +103 -2
- package/packages/core/src/cli/status.ts +24 -1
- package/packages/core/src/cli/terminals.ts +94 -93
- package/packages/core/src/cli/ticket.ts +35 -11
- 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 +150 -2
- package/packages/core/src/events/policy.ts +210 -0
- package/packages/core/src/events/repository.ts +69 -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} +4286 -4006
- package/packages/core/src/kernel/change-presence.ts +11 -3
- package/packages/core/src/kernel/dispatch-capacity.ts +127 -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 +108 -9
- 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-parent.ts +35 -10
- 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 +34 -6
- package/packages/core/src/kernel/reconcile-restack.ts +23 -2
- package/packages/core/src/kernel/reducer-registry.ts +18 -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/kernel/ticket-migrations.ts +139 -0
- 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 +51 -11
- package/packages/core/src/operator/registry.ts +17 -1
- package/packages/core/src/operator/restack.ts +51 -0
- package/packages/core/src/operator/tickets.ts +30 -26
- package/packages/core/src/plugin-sdk/index.ts +10 -0
- 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/tickets/linear.ts +180 -12
- package/packages/core/src/ports/tickets/migration.ts +92 -9
- package/packages/core/src/ports/types.ts +60 -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 +815 -369
- 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 +233 -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 +8911 -6344
- 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 +145 -20
- 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 +5 -2
- 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 +17 -1
- package/packages/core/src/testing/dispatch-read-budget.ts +18 -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 +140 -25
- package/skills/guide/references/integration-tree.md +83 -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 +47 -4
- package/skills/guide/references/remote-store-protocol.md +16 -0
- package/skills/guide/references/remote-ticket-protocol.md +5 -0
- package/skills/guide/references/restacking.md +42 -7
- package/skills/guide/references/setup.md +25 -0
- package/skills/guide/references/spec-standard.md +71 -0
- package/skills/guide/references/ticket-dependencies.md +6 -45
- package/skills/guide/references/ticket-migration.md +50 -4
- 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 +62 -40
- package/skills/tickets/SKILL.md +15 -43
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolveTicketRef,
|
|
3
|
+
migrationIdentity,
|
|
4
|
+
historicalTicketIdentity,
|
|
5
|
+
} from '../kernel/ticket-migrations'
|
|
6
|
+
import { nodeRestackDemand, presenceRestackPath } from '../kernel/node-restack-demand'
|
|
7
|
+
import {
|
|
8
|
+
deferMixedVersion,
|
|
9
|
+
mixedVersionDeferred,
|
|
10
|
+
MixedVersionDeferral,
|
|
11
|
+
} from '../kernel/mixed-version'
|
|
12
|
+
import { guardForge, ForgeCooldown } from '../kernel/guarded-forge'
|
|
13
|
+
import { recordJanitorFailure } from '../kernel/janitor-failure'
|
|
14
|
+
import { isForgeFailure } from '../ports/forge-failure'
|
|
15
|
+
import {
|
|
16
|
+
ForgeRequestDeferred,
|
|
17
|
+
withForgeRequestContext,
|
|
18
|
+
forgeRequestContext,
|
|
19
|
+
} from '../ports/forge-request-context'
|
|
20
|
+
import { dispatchCapacity, nodeCapacity, type CapacityBuild } from '../kernel/dispatch-capacity'
|
|
1
21
|
import { evaluateLandingPolicy } from '../kernel/landing-policy'
|
|
2
22
|
import {
|
|
3
23
|
landingAuthorized,
|
|
@@ -15,7 +35,6 @@ import {
|
|
|
15
35
|
import {
|
|
16
36
|
integrationComplete,
|
|
17
37
|
integrationCurrent,
|
|
18
|
-
integrationNeedsRunner,
|
|
19
38
|
integrationConfig,
|
|
20
39
|
integrationFailed,
|
|
21
40
|
integrationVerified,
|
|
@@ -37,7 +56,7 @@ import { tmpdir } from 'node:os'
|
|
|
37
56
|
import { join } from 'node:path'
|
|
38
57
|
import { runNodeTransaction } from '../kernel/node-restack-transaction'
|
|
39
58
|
import { hasBuildTrailer } from '../kernel/build-identity'
|
|
40
|
-
import { readBuildDigests } from '../store/reduced-reads'
|
|
59
|
+
import { readBuildDigests, readForgeHealth } from '../store/reduced-reads'
|
|
41
60
|
import { readBuildSelector, readBuildFacts, type CurrentBuildFacts } from '../store/reduced-reads'
|
|
42
61
|
import { ensureExecutionProgress } from './execution-no-progress'
|
|
43
62
|
import { ticketIdentity } from '../ports/tickets/identity'
|
|
@@ -330,6 +349,7 @@ export function validateSlugCandidate(candidate: string | null | undefined): str
|
|
|
330
349
|
* action. They repeat between scans and refresh on completed scans, because that is the only
|
|
331
350
|
* place the source problems are visible without provider inspection. */
|
|
332
351
|
export interface TickReport {
|
|
352
|
+
forgeRequests?: import('../ports/forge-telemetry').ForgeRequestCounts
|
|
333
353
|
/** Janitor (§15.7): builds completed as merged. */
|
|
334
354
|
merged: number
|
|
335
355
|
/** Janitor: builds completed as closed-unmerged. */
|
|
@@ -745,7 +765,7 @@ export class Dispatcher {
|
|
|
745
765
|
return decideNextFromFacts(state, log, composeBuildConfig(pinned, this.deps.config))
|
|
746
766
|
} catch (error) {
|
|
747
767
|
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)}`,
|
|
768
|
+
`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
769
|
)
|
|
750
770
|
return undefined
|
|
751
771
|
}
|
|
@@ -797,6 +817,7 @@ export class Dispatcher {
|
|
|
797
817
|
const settle = this.deps.settlePublication
|
|
798
818
|
if (settle === undefined) return undefined
|
|
799
819
|
return async (slug) => {
|
|
820
|
+
if (await deferMixedVersion(this.store, slug)) return
|
|
800
821
|
await settle(slug)
|
|
801
822
|
await this.store.refreshBuild(slug)
|
|
802
823
|
}
|
|
@@ -807,6 +828,12 @@ export class Dispatcher {
|
|
|
807
828
|
deps.store instanceof RepoViewStore
|
|
808
829
|
? deps.store
|
|
809
830
|
: new RepoViewStore(deps.store, { repo: deps.repo })
|
|
831
|
+
deps.forge = guardForge(deps.forge, {
|
|
832
|
+
store: this.store,
|
|
833
|
+
repo: deps.repo,
|
|
834
|
+
name: deps.config.forge,
|
|
835
|
+
now: deps.clock,
|
|
836
|
+
})
|
|
810
837
|
this.leaseTtlMs = deps.opts?.leaseTtlMs ?? 0
|
|
811
838
|
this.slugNamingTimeoutMs = deps.opts?.slugNamingTimeoutMs ?? DEFAULT_SLUG_NAMING_TIMEOUT_MS
|
|
812
839
|
this.maxHarvestRecoveryAttempts =
|
|
@@ -828,8 +855,35 @@ export class Dispatcher {
|
|
|
828
855
|
return opts.deadlineAt !== undefined && this.deps.clock().getTime() >= opts.deadlineAt
|
|
829
856
|
}
|
|
830
857
|
|
|
858
|
+
lastForgeRequests?: import('../ports/forge-telemetry').ForgeRequestCounts
|
|
831
859
|
async tick(opts: TickOpts = {}): Promise<TickReport> {
|
|
832
|
-
|
|
860
|
+
const builds = new Map<string, number>()
|
|
861
|
+
let total = 0
|
|
862
|
+
let unattributed = 0
|
|
863
|
+
const stop = this.deps.forge.observeRequests?.((request) => {
|
|
864
|
+
const build = request.build ?? forgeRequestContext().build
|
|
865
|
+
total++
|
|
866
|
+
if (build) builds.set(build, (builds.get(build) ?? 0) + 1)
|
|
867
|
+
else unattributed++
|
|
868
|
+
})
|
|
869
|
+
const counts = () => ({
|
|
870
|
+
total,
|
|
871
|
+
unattributed,
|
|
872
|
+
builds: [...builds]
|
|
873
|
+
.map(([build, requests]) => ({ build, requests }))
|
|
874
|
+
.sort((a, b) => b.requests - a.requests || a.build.localeCompare(b.build))
|
|
875
|
+
.slice(0, 10),
|
|
876
|
+
complete: true,
|
|
877
|
+
})
|
|
878
|
+
this.lastForgeRequests = undefined
|
|
879
|
+
try {
|
|
880
|
+
const report = await this.runTick(opts)
|
|
881
|
+
if (stop || this.deps.config.forge === 'local-git') report.forgeRequests = counts()
|
|
882
|
+
return report
|
|
883
|
+
} finally {
|
|
884
|
+
if (stop || this.deps.config.forge === 'local-git') this.lastForgeRequests = counts()
|
|
885
|
+
stop?.()
|
|
886
|
+
}
|
|
833
887
|
}
|
|
834
888
|
|
|
835
889
|
private async runTick(opts: TickOpts): Promise<TickReport> {
|
|
@@ -961,20 +1015,32 @@ export class Dispatcher {
|
|
|
961
1015
|
* from here so a settled terminal build costs none. Records are read before
|
|
962
1016
|
* digests (as `operator/query.ts` does) so a concurrent create cannot fail
|
|
963
1017
|
* the completeness check. */
|
|
964
|
-
private async repoBuildDigests(
|
|
1018
|
+
private async repoBuildDigests(
|
|
1019
|
+
includeDeferred = false,
|
|
1020
|
+
): Promise<{ record: BuildRecord; digest: BuildDigest }[]> {
|
|
965
1021
|
const store = this.store
|
|
966
1022
|
const { repo } = this.deps
|
|
967
1023
|
const records = (await store.listBuilds()).filter((record) => record.repo === repo)
|
|
968
1024
|
const digests = await readBuildDigests(store, repo)
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
if (
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
1025
|
+
const blocked = new Set<string>()
|
|
1026
|
+
for (const record of records) {
|
|
1027
|
+
if (
|
|
1028
|
+
(digests.get(record.slug)?.compatibility?.decisiveFacts ?? 0) > 0 &&
|
|
1029
|
+
(await deferMixedVersion(store, record.slug))
|
|
1030
|
+
)
|
|
1031
|
+
blocked.add(record.slug)
|
|
1032
|
+
}
|
|
1033
|
+
return records
|
|
1034
|
+
.filter((record) => includeDeferred || !blocked.has(record.slug))
|
|
1035
|
+
.map((record) => {
|
|
1036
|
+
const digest = digests.get(record.slug)
|
|
1037
|
+
if (digest === undefined) {
|
|
1038
|
+
throw new Error(
|
|
1039
|
+
`build digest missing for ${record.slug}: the digest read broke completeness`,
|
|
1040
|
+
)
|
|
1041
|
+
}
|
|
1042
|
+
return { record, digest }
|
|
1043
|
+
})
|
|
978
1044
|
}
|
|
979
1045
|
|
|
980
1046
|
/** Builds with no terminal fact: the only ones whose tick duties change
|
|
@@ -1042,7 +1108,7 @@ export class Dispatcher {
|
|
|
1042
1108
|
error: unknown,
|
|
1043
1109
|
operation: 'ready-scan' | 'dependency-check',
|
|
1044
1110
|
): Promise<void> {
|
|
1045
|
-
const message = error instanceof Error ? error.message : String(error)
|
|
1111
|
+
const message = error instanceof Error || isForgeFailure(error) ? error.message : String(error)
|
|
1046
1112
|
await this.sourceCondition(
|
|
1047
1113
|
error instanceof TicketSourceRateLimitError
|
|
1048
1114
|
? {
|
|
@@ -1070,14 +1136,43 @@ export class Dispatcher {
|
|
|
1070
1136
|
}
|
|
1071
1137
|
}
|
|
1072
1138
|
|
|
1139
|
+
private async currentTicketId(record: BuildRecord): Promise<string> {
|
|
1140
|
+
if (!record.ticket) throw new Error(`build ${record.slug} has no ticket`)
|
|
1141
|
+
return resolveTicketRef(
|
|
1142
|
+
this.store.repositoryFacts().ticketMigrations,
|
|
1143
|
+
record.ticket,
|
|
1144
|
+
this.deps.tickets.name,
|
|
1145
|
+
record.slug,
|
|
1146
|
+
).id
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1073
1149
|
private async activeTicketIdentities(refs: TicketRef[], listed: Ticket[]): Promise<Set<string>> {
|
|
1074
1150
|
const key = (ref: TicketRef) => `${ref.source}:${ref.id}`
|
|
1075
|
-
const
|
|
1151
|
+
const migrations = this.store.repositoryFacts().ticketMigrations
|
|
1152
|
+
const records = await this.repoBuildDigests()
|
|
1153
|
+
const normalized = refs.map((ref) => {
|
|
1154
|
+
try {
|
|
1155
|
+
return resolveTicketRef(
|
|
1156
|
+
migrations,
|
|
1157
|
+
ref,
|
|
1158
|
+
this.deps.tickets.name,
|
|
1159
|
+
records.find(
|
|
1160
|
+
({ record }) => record.ticket?.source === ref.source && record.ticket.id === ref.id,
|
|
1161
|
+
)?.record.slug,
|
|
1162
|
+
)
|
|
1163
|
+
} catch (error) {
|
|
1164
|
+
// An unrelated source remains excluded only in its original namespace.
|
|
1165
|
+
// A recorded cutover that omits a live claim must block admission.
|
|
1166
|
+
if (migrations.migrations.some((m) => m.from === ref.source && m.from !== m.to)) throw error
|
|
1167
|
+
return ref
|
|
1168
|
+
}
|
|
1169
|
+
})
|
|
1170
|
+
const ids = new Set(normalized.map(key))
|
|
1076
1171
|
if (this.deps.tickets.name !== 'hosted' || listed.length === 0) return ids
|
|
1077
1172
|
const listedIds = new Set(listed.map((ticket) => key(ticket.ref)))
|
|
1078
1173
|
const identity = ticketIdentity(this.deps.tickets)
|
|
1079
1174
|
try {
|
|
1080
|
-
for (const ref of
|
|
1175
|
+
for (const ref of normalized) {
|
|
1081
1176
|
if (ref.source === 'hosted' && !listedIds.has(key(ref))) ids.add(await identity(ref))
|
|
1082
1177
|
}
|
|
1083
1178
|
} catch (error) {
|
|
@@ -1216,11 +1311,18 @@ export class Dispatcher {
|
|
|
1216
1311
|
}
|
|
1217
1312
|
}
|
|
1218
1313
|
|
|
1314
|
+
private async forgeCoolingDown(): Promise<boolean> {
|
|
1315
|
+
const active = await readForgeHealth(this.store, this.deps.repo)
|
|
1316
|
+
return !!active && Date.parse(active.resetAt) > this.deps.clock().getTime()
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1219
1319
|
private async launch(
|
|
1220
1320
|
slug: string,
|
|
1221
1321
|
launched: Set<string>,
|
|
1222
1322
|
report: TickReport = emptyTickReport(),
|
|
1223
1323
|
): Promise<LaunchRunnerResult> {
|
|
1324
|
+
if (await this.forgeCoolingDown()) return 'already-active'
|
|
1325
|
+
if (await deferMixedVersion(this.store, slug)) return 'already-active'
|
|
1224
1326
|
const launchState = (await this.store.buildFacts(slug)).state
|
|
1225
1327
|
if (
|
|
1226
1328
|
launchState.kind === 'node' &&
|
|
@@ -1491,7 +1593,7 @@ export class Dispatcher {
|
|
|
1491
1593
|
// Contained: the next tick retries this environment.
|
|
1492
1594
|
report.sandboxSettleFailures += 1
|
|
1493
1595
|
report.janitorDiagnostics.push(
|
|
1494
|
-
`operator sandbox ${environment.environmentId}: idle settlement failed — ${error instanceof Error ? error.message : String(error)}`,
|
|
1596
|
+
`operator sandbox ${environment.environmentId}: idle settlement failed — ${error instanceof Error || isForgeFailure(error) ? error.message : String(error)}`,
|
|
1495
1597
|
)
|
|
1496
1598
|
}
|
|
1497
1599
|
}
|
|
@@ -1621,6 +1723,7 @@ export class Dispatcher {
|
|
|
1621
1723
|
// the marker's lease so the next supervisor adopts immediately.
|
|
1622
1724
|
return
|
|
1623
1725
|
}
|
|
1726
|
+
if (await deferMixedVersion(store, slug)) return
|
|
1624
1727
|
leaseClaimed = await store.claimLease(slug, entry.instance, BUILD_EXECUTION_LEASE_TTL_MS)
|
|
1625
1728
|
if (!leaseClaimed) return // another live holder — the next tick re-evaluates
|
|
1626
1729
|
heartbeat = setInterval(() => {
|
|
@@ -1635,6 +1738,10 @@ export class Dispatcher {
|
|
|
1635
1738
|
return
|
|
1636
1739
|
}
|
|
1637
1740
|
const events = (await readBuildFacts(store, slug)).value
|
|
1741
|
+
if (mixedVersionDeferred(events.state)) {
|
|
1742
|
+
await deferMixedVersion(store, slug)
|
|
1743
|
+
return
|
|
1744
|
+
}
|
|
1638
1745
|
const priorGenerations = events.workspaceGenerations
|
|
1639
1746
|
const handle = await workspaces.provision({
|
|
1640
1747
|
// Local providers provision FROM the physical checkout; remote
|
|
@@ -1647,6 +1754,7 @@ export class Dispatcher {
|
|
|
1647
1754
|
branch: input.branch,
|
|
1648
1755
|
...(priorGenerations > 0 || input.generation > 0
|
|
1649
1756
|
? {
|
|
1757
|
+
publication: await this.confirmedWorkspacePublication(events, slug),
|
|
1650
1758
|
revision: events.state.integration?.cycle?.head ?? this.recoveryCheckpoint(events),
|
|
1651
1759
|
generation: Math.max(priorGenerations, input.generation),
|
|
1652
1760
|
}
|
|
@@ -1708,7 +1816,9 @@ export class Dispatcher {
|
|
|
1708
1816
|
})
|
|
1709
1817
|
}
|
|
1710
1818
|
const attempt = events.dispatchFailureCount + 1
|
|
1711
|
-
const message = (
|
|
1819
|
+
const message = (
|
|
1820
|
+
error instanceof Error || isForgeFailure(error) ? error.message : String(error)
|
|
1821
|
+
).trim()
|
|
1712
1822
|
await store.append(slug, {
|
|
1713
1823
|
actor: DISPATCHER,
|
|
1714
1824
|
type: 'dispatch.failed',
|
|
@@ -1802,196 +1912,245 @@ export class Dispatcher {
|
|
|
1802
1912
|
// stop starting new ones. The remaining builds stay janitor due — the
|
|
1803
1913
|
// next invocation re-runs them (§3.3 idempotency).
|
|
1804
1914
|
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
|
-
}),
|
|
1915
|
+
await withForgeRequestContext({ build: record.slug }, async () => {
|
|
1916
|
+
let previous: BuildState['janitor']
|
|
1917
|
+
let attempted = false
|
|
1918
|
+
let failed = false
|
|
1919
|
+
try {
|
|
1920
|
+
// Once a record is known, contain its complete janitor path: loading
|
|
1921
|
+
// and reducing facts, cleanup, forge/ticket calls, and store writes.
|
|
1922
|
+
// Existing partial facts leave the same work due on the next tick.
|
|
1923
|
+
let { state, workspace, log } = await this.store.buildFacts(record.slug)
|
|
1924
|
+
previous = state.janitor
|
|
1925
|
+
const controlDue =
|
|
1926
|
+
state.pendingCommands.length > 0 ||
|
|
1927
|
+
state.discardRequest !== undefined ||
|
|
1928
|
+
(state.landing?.command && state.landing.command.seq !== state.landing.acknowledgedSeq)
|
|
1929
|
+
if (
|
|
1930
|
+
!controlDue &&
|
|
1931
|
+
previous &&
|
|
1932
|
+
Date.parse(previous.nextAttemptAt) > this.deps.clock().getTime()
|
|
1868
1933
|
)
|
|
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
|
|
1934
|
+
return
|
|
1935
|
+
if (mixedVersionDeferred(state)) {
|
|
1936
|
+
await deferMixedVersion(this.store, record.slug)
|
|
1937
|
+
return
|
|
1893
1938
|
}
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1939
|
+
const executionLeaseLive = this.hasLiveExecutionLease(record)
|
|
1940
|
+
attempted = !executionLeaseLive
|
|
1941
|
+
// Raw history, read at most once and only by a branch that acts on it:
|
|
1942
|
+
// the facts above answer every quiet-path question without it.
|
|
1943
|
+
let loaded: CurrentBuildFacts | undefined
|
|
1944
|
+
const history = async (): Promise<CurrentBuildFacts> => {
|
|
1945
|
+
loaded ??= (await readBuildFacts(this.store, record.slug)).value
|
|
1946
|
+
return loaded
|
|
1898
1947
|
}
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1948
|
+
let observedPr: Awaited<ReturnType<Forge['getPrState']>> | undefined
|
|
1949
|
+
// A replacement head is followed first by a forge read and cancellation,
|
|
1950
|
+
// ahead of node cascade, controls, or any other action for this build.
|
|
1951
|
+
if (
|
|
1952
|
+
state.status !== 'done' &&
|
|
1953
|
+
state.status !== 'aborted' &&
|
|
1954
|
+
state.prState === 'open' &&
|
|
1955
|
+
state.pr &&
|
|
1956
|
+
state.landing?.native?.operation
|
|
1957
|
+
) {
|
|
1958
|
+
const path = this.forgeWorkspacePathOf(workspace)
|
|
1959
|
+
const observed = await this.deps.forge.getPrState(path, state.pr.number)
|
|
1960
|
+
observedPr = observed
|
|
1961
|
+
if (observed.state !== 'open') {
|
|
1962
|
+
await this.checkPr(
|
|
1963
|
+
record,
|
|
1964
|
+
{ history, workspace },
|
|
1965
|
+
state,
|
|
1906
1966
|
report,
|
|
1967
|
+
launched,
|
|
1968
|
+
executionLeaseLive,
|
|
1969
|
+
observedPr,
|
|
1907
1970
|
)
|
|
1971
|
+
return
|
|
1972
|
+
}
|
|
1973
|
+
const result =
|
|
1974
|
+
observed.nativeAutoMerge === false
|
|
1975
|
+
? { kind: 'applied' as const }
|
|
1976
|
+
: await this.deps.forge.setAutoMerge(path, state.pr.number, false)
|
|
1977
|
+
if (result.kind !== 'applied')
|
|
1978
|
+
throw new Error('Replacement-head native cancellation unconfirmed')
|
|
1979
|
+
observedPr = { ...observed, nativeAutoMerge: false }
|
|
1980
|
+
}
|
|
1981
|
+
// Pipeline/ticket/workspace state is settled, but release-asset cleanup
|
|
1982
|
+
// has its own crash window after build.completed. Revisit only pending
|
|
1983
|
+
// hosted handles; this never relaunches a runner or consumes capacity.
|
|
1984
|
+
if (
|
|
1985
|
+
state.kind === 'node' &&
|
|
1986
|
+
state.integration?.landing?.operation &&
|
|
1987
|
+
!state.integration.audit
|
|
1988
|
+
) {
|
|
1989
|
+
await this.withKernelRepository((path) =>
|
|
1990
|
+
auditIntegrationLanding({
|
|
1991
|
+
store: this.store,
|
|
1992
|
+
forge: this.kernelForge(),
|
|
1993
|
+
exec: this.kernelForge().kernelExec ?? this.deps.exec,
|
|
1994
|
+
workspacePath: path,
|
|
1995
|
+
slug: record.slug,
|
|
1996
|
+
id: this.deps.ids('esc'),
|
|
1997
|
+
}),
|
|
1998
|
+
)
|
|
1999
|
+
}
|
|
2000
|
+
if (state.status === 'done') {
|
|
2001
|
+
if (digest.reclaimPending === true) {
|
|
2002
|
+
await this.reclaimPrAttachments(record.slug, await history())
|
|
2003
|
+
}
|
|
2004
|
+
return
|
|
2005
|
+
}
|
|
2006
|
+
if (state.kind === 'node' && state.status !== 'aborted') {
|
|
2007
|
+
const command =
|
|
2008
|
+
state.pendingCommands.find((c) => c.command === 'abort') ??
|
|
2009
|
+
state.pendingCommands.at(0)
|
|
2010
|
+
if (command !== undefined && !executionLeaseLive) {
|
|
2011
|
+
await this.store.append(record.slug, {
|
|
2012
|
+
actor: DISPATCHER,
|
|
2013
|
+
type:
|
|
2014
|
+
command.command === 'abort'
|
|
2015
|
+
? 'build.aborted'
|
|
2016
|
+
: command.command === 'pause'
|
|
2017
|
+
? 'build.paused'
|
|
2018
|
+
: 'build.resumed',
|
|
2019
|
+
payload: {},
|
|
2020
|
+
})
|
|
2021
|
+
if (command.command === 'abort')
|
|
2022
|
+
await this.cleanupAborted(record, await history(), report)
|
|
2023
|
+
return
|
|
2024
|
+
}
|
|
2025
|
+
if (state.nodeOpened) {
|
|
2026
|
+
await this.observeTicketTarget(record, state, report)
|
|
2027
|
+
loaded = undefined
|
|
2028
|
+
;({ state, workspace, log } = await this.store.buildFacts(record.slug))
|
|
2029
|
+
}
|
|
2030
|
+
if ((state.status === 'paused' || state.status === 'blocked') && !state.pr) return
|
|
2031
|
+
if (state.nodeOpened && state.baseBranch) {
|
|
2032
|
+
if (
|
|
2033
|
+
await this.observeTarget(
|
|
2034
|
+
record.slug,
|
|
2035
|
+
state.baseBranch,
|
|
2036
|
+
log.restack.target?.sha,
|
|
2037
|
+
report,
|
|
2038
|
+
)
|
|
2039
|
+
) {
|
|
2040
|
+
loaded = undefined
|
|
2041
|
+
;({ state, workspace, log } = await this.store.buildFacts(record.slug))
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2044
|
+
if (
|
|
2045
|
+
state.nodeOpened &&
|
|
2046
|
+
state.status !== 'paused' &&
|
|
2047
|
+
(state.status !== 'blocked' || integrationFailed(state)) &&
|
|
2048
|
+
state.prState !== 'merged' &&
|
|
2049
|
+
state.prState !== 'closed' &&
|
|
2050
|
+
!executionLeaseLive
|
|
1908
2051
|
) {
|
|
2052
|
+
await this.prepareIntegration(record, state, report, launched, { refreshOnly: true })
|
|
2053
|
+
;({ state, workspace, log } = await this.store.buildFacts(record.slug))
|
|
2054
|
+
await this.cascadeNode(record, state, report, launched, opts)
|
|
1909
2055
|
loaded = undefined
|
|
1910
2056
|
;({ state, workspace, log } = await this.store.buildFacts(record.slug))
|
|
1911
2057
|
}
|
|
2058
|
+
if (state.nodeOpened && !executionLeaseLive) {
|
|
2059
|
+
await this.prepareIntegration(record, state, report, launched)
|
|
2060
|
+
loaded = undefined
|
|
2061
|
+
;({ state, workspace, log } = await this.store.buildFacts(record.slug))
|
|
2062
|
+
}
|
|
2063
|
+
if (state.nodeOpened !== undefined && state.pr === undefined) {
|
|
2064
|
+
await this.pollEmptyNode(record, state)
|
|
2065
|
+
return
|
|
2066
|
+
}
|
|
1912
2067
|
}
|
|
2068
|
+
// Abort is destructive human judgment and therefore outranks a queued
|
|
2069
|
+
// discard when both requests raced into the same stream.
|
|
1913
2070
|
if (
|
|
1914
|
-
|
|
1915
|
-
state.status
|
|
1916
|
-
|
|
1917
|
-
state.prState !== 'merged' &&
|
|
1918
|
-
state.prState !== 'closed' &&
|
|
1919
|
-
!executionLeaseLive
|
|
2071
|
+
!executionLeaseLive &&
|
|
2072
|
+
state.status === 'queued' &&
|
|
2073
|
+
state.pendingCommands.some((command) => command.command === 'abort')
|
|
1920
2074
|
) {
|
|
1921
|
-
await this.
|
|
2075
|
+
const acknowledged = await this.store.append(record.slug, {
|
|
2076
|
+
actor: DISPATCHER,
|
|
2077
|
+
type: 'build.aborted',
|
|
2078
|
+
payload: {},
|
|
2079
|
+
} satisfies EventWrite<'build.aborted'>)
|
|
2080
|
+
void acknowledged
|
|
2081
|
+
// The view folded the acknowledgement it just appended.
|
|
1922
2082
|
loaded = undefined
|
|
1923
|
-
|
|
2083
|
+
await this.cleanupAborted(record, await history(), report)
|
|
2084
|
+
return
|
|
1924
2085
|
}
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
2086
|
+
// Discard is a queued-only recovery control. A request that raced with
|
|
2087
|
+
// runner attachment is deliberately inert: it must never tear a live
|
|
2088
|
+
// runner's workspace down or return its ticket for a duplicate build.
|
|
2089
|
+
if (
|
|
2090
|
+
!executionLeaseLive &&
|
|
2091
|
+
state.status === 'queued' &&
|
|
2092
|
+
state.discardRequest !== undefined
|
|
2093
|
+
) {
|
|
2094
|
+
await this.cleanupDiscarded(record, await history(), report)
|
|
2095
|
+
return
|
|
1929
2096
|
}
|
|
1930
|
-
if (
|
|
1931
|
-
await this.
|
|
1932
|
-
|
|
2097
|
+
if (!executionLeaseLive && state.status === 'aborted') {
|
|
2098
|
+
await this.cleanupAborted(record, await history(), report)
|
|
2099
|
+
return
|
|
1933
2100
|
}
|
|
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))
|
|
2101
|
+
if (state.kind !== 'node' && state.status !== 'aborted')
|
|
2102
|
+
await this.observeTicketTarget(record, state, report)
|
|
2103
|
+
if (state.kind !== 'node' && state.status !== 'aborted' && state.status !== 'queued') {
|
|
2104
|
+
const branch = await readBuildSelector(this.store, record.slug, 'baseBranch')
|
|
2105
|
+
if (branch !== undefined) {
|
|
2106
|
+
if (await this.observeTarget(record.slug, branch, log.restack.target?.sha, report)) {
|
|
2107
|
+
loaded = undefined
|
|
2108
|
+
;({ state, workspace, log } = await this.store.buildFacts(record.slug))
|
|
2109
|
+
}
|
|
1976
2110
|
}
|
|
1977
2111
|
}
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
2112
|
+
if (state.pr) {
|
|
2113
|
+
await this.checkPr(
|
|
2114
|
+
record,
|
|
2115
|
+
{ history, workspace },
|
|
2116
|
+
state,
|
|
2117
|
+
report,
|
|
2118
|
+
launched,
|
|
2119
|
+
executionLeaseLive,
|
|
2120
|
+
observedPr,
|
|
2121
|
+
)
|
|
2122
|
+
}
|
|
2123
|
+
} catch (error) {
|
|
2124
|
+
if (error instanceof ForgeCooldown) {
|
|
2125
|
+
attempted = false
|
|
2126
|
+
return
|
|
2127
|
+
}
|
|
2128
|
+
if (error instanceof MixedVersionDeferral) {
|
|
2129
|
+
attempted = false
|
|
2130
|
+
return
|
|
2131
|
+
}
|
|
2132
|
+
failed = true
|
|
2133
|
+
const message =
|
|
2134
|
+
error instanceof Error || isForgeFailure(error) ? error.message : String(error)
|
|
2135
|
+
await recordJanitorFailure(
|
|
2136
|
+
this.store,
|
|
2137
|
+
record.slug,
|
|
2138
|
+
previous,
|
|
2139
|
+
message,
|
|
2140
|
+
this.deps.clock(),
|
|
2141
|
+
this.deps.config.policy,
|
|
1988
2142
|
)
|
|
2143
|
+
report.janitorFailed += 1
|
|
2144
|
+
report.janitorDiagnostics.push(`build ${record.slug}: janitor failed — ${message}`)
|
|
2145
|
+
} finally {
|
|
2146
|
+
if (attempted && !failed && previous)
|
|
2147
|
+
await this.store.append(record.slug, {
|
|
2148
|
+
actor: DISPATCHER,
|
|
2149
|
+
type: 'build.janitor-recovered',
|
|
2150
|
+
payload: {},
|
|
2151
|
+
})
|
|
1989
2152
|
}
|
|
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
|
-
}
|
|
2153
|
+
})
|
|
1995
2154
|
}
|
|
1996
2155
|
}
|
|
1997
2156
|
|
|
@@ -2015,7 +2174,7 @@ export class Dispatcher {
|
|
|
2015
2174
|
else await this.observeWorkTarget(record, state, report)
|
|
2016
2175
|
} catch (error) {
|
|
2017
2176
|
report.janitorDiagnostics.push(
|
|
2018
|
-
`build ${record.slug}: ticket target observation failed — ${error instanceof Error ? error.message : String(error)}`,
|
|
2177
|
+
`build ${record.slug}: ticket target observation failed — ${error instanceof Error || isForgeFailure(error) ? error.message : String(error)}`,
|
|
2019
2178
|
)
|
|
2020
2179
|
}
|
|
2021
2180
|
}
|
|
@@ -2048,15 +2207,22 @@ export class Dispatcher {
|
|
|
2048
2207
|
}
|
|
2049
2208
|
|
|
2050
2209
|
private async observeWorkTarget(record: BuildRecord, state: BuildState, report: TickReport) {
|
|
2051
|
-
if (!record.ticket
|
|
2052
|
-
const ticket = await this.deps.tickets.get(record
|
|
2210
|
+
if (!record.ticket) return
|
|
2211
|
+
const ticket = await this.deps.tickets.get(await this.currentTicketId(record))
|
|
2053
2212
|
if (!ticket) {
|
|
2054
2213
|
report.janitorDiagnostics.push(
|
|
2055
2214
|
`build ${record.slug}: claimed ticket cannot be read; frozen work target retained`,
|
|
2056
2215
|
)
|
|
2057
2216
|
return
|
|
2058
2217
|
}
|
|
2059
|
-
const effective = state.target
|
|
2218
|
+
const effective = state.target
|
|
2219
|
+
? resolveTicketRef(
|
|
2220
|
+
this.store.repositoryFacts().ticketMigrations,
|
|
2221
|
+
state.target.ticket,
|
|
2222
|
+
this.deps.tickets.name,
|
|
2223
|
+
record.slug,
|
|
2224
|
+
).id
|
|
2225
|
+
: undefined
|
|
2060
2226
|
const canonical =
|
|
2061
2227
|
effective && this.deps.config.tickets.source === 'hosted'
|
|
2062
2228
|
? ((await this.deps.tickets.get(effective))?.ref.id ?? effective)
|
|
@@ -2074,7 +2240,7 @@ export class Dispatcher {
|
|
|
2074
2240
|
/** Provider edits and interrupted caller writes converge through this same
|
|
2075
2241
|
* durable path, independently of ticket readiness or caller liveness. */
|
|
2076
2242
|
private async observeNodeParent(record: BuildRecord, state: BuildState, report: TickReport) {
|
|
2077
|
-
if (!record.ticket
|
|
2243
|
+
if (!record.ticket) return
|
|
2078
2244
|
if (nodeParentBusy(state)) return
|
|
2079
2245
|
if (
|
|
2080
2246
|
state.pr &&
|
|
@@ -2118,11 +2284,18 @@ export class Dispatcher {
|
|
|
2118
2284
|
this.integrationPublicationInputs = undefined
|
|
2119
2285
|
return
|
|
2120
2286
|
}
|
|
2121
|
-
const ticket = await this.deps.tickets.get(record
|
|
2287
|
+
const ticket = await this.deps.tickets.get(await this.currentTicketId(record))
|
|
2122
2288
|
if (!ticket) throw new Error('node ticket cannot be read; parent observation failed closed')
|
|
2123
2289
|
const desired = ticket.target ?? null
|
|
2124
2290
|
const request = node?.parentRequest
|
|
2125
|
-
const effective = state.target
|
|
2291
|
+
const effective = state.target
|
|
2292
|
+
? resolveTicketRef(
|
|
2293
|
+
this.store.repositoryFacts().ticketMigrations,
|
|
2294
|
+
state.target.ticket,
|
|
2295
|
+
this.deps.tickets.name,
|
|
2296
|
+
record.slug,
|
|
2297
|
+
).id
|
|
2298
|
+
: undefined
|
|
2126
2299
|
const canonical =
|
|
2127
2300
|
effective && this.deps.config.tickets.source === 'hosted'
|
|
2128
2301
|
? ((await this.deps.tickets.get(effective))?.ref.id ?? effective)
|
|
@@ -2144,7 +2317,18 @@ export class Dispatcher {
|
|
|
2144
2317
|
state.nodeRestack?.parentRequest?.id !== request?.id
|
|
2145
2318
|
)
|
|
2146
2319
|
return
|
|
2147
|
-
if (
|
|
2320
|
+
if (
|
|
2321
|
+
request &&
|
|
2322
|
+
desired !==
|
|
2323
|
+
(request.next.target
|
|
2324
|
+
? resolveTicketRef(
|
|
2325
|
+
this.store.repositoryFacts().ticketMigrations,
|
|
2326
|
+
request.next.target.ticket,
|
|
2327
|
+
this.deps.tickets.name,
|
|
2328
|
+
record.slug,
|
|
2329
|
+
).id
|
|
2330
|
+
: null)
|
|
2331
|
+
) {
|
|
2148
2332
|
await this.store.appendIfCurrent(record.slug, state.lastSeq, {
|
|
2149
2333
|
actor: DISPATCHER,
|
|
2150
2334
|
type: 'node.parent-cancelled',
|
|
@@ -2170,7 +2354,7 @@ export class Dispatcher {
|
|
|
2170
2354
|
await this.rejectParent(
|
|
2171
2355
|
record,
|
|
2172
2356
|
ticket,
|
|
2173
|
-
error instanceof Error ? error.message : String(error),
|
|
2357
|
+
error instanceof Error || isForgeFailure(error) ? error.message : String(error),
|
|
2174
2358
|
report,
|
|
2175
2359
|
)
|
|
2176
2360
|
return
|
|
@@ -2210,7 +2394,8 @@ export class Dispatcher {
|
|
|
2210
2394
|
try {
|
|
2211
2395
|
sha = await this.baseSha(branch)
|
|
2212
2396
|
} catch (error) {
|
|
2213
|
-
const message =
|
|
2397
|
+
const message =
|
|
2398
|
+
error instanceof Error || isForgeFailure(error) ? error.message : String(error)
|
|
2214
2399
|
report.janitorDiagnostics.push(`build ${slug}: target observation failed — ${message}`)
|
|
2215
2400
|
return false
|
|
2216
2401
|
}
|
|
@@ -2235,6 +2420,36 @@ export class Dispatcher {
|
|
|
2235
2420
|
return open?.localPath ?? open?.path ?? open?.ref ?? this.deps.checkout ?? this.deps.repo
|
|
2236
2421
|
}
|
|
2237
2422
|
|
|
2423
|
+
/** Deferral withholds decisions, but cannot free an existing capacity reservation. */
|
|
2424
|
+
private async capacityBuilds(): Promise<CapacityBuild[]> {
|
|
2425
|
+
const builds: CapacityBuild[] = []
|
|
2426
|
+
for (const { record, digest } of await this.repoBuildDigests(true)) {
|
|
2427
|
+
if (digest.terminal) continue
|
|
2428
|
+
const facts = await this.store.buildFacts(record.slug)
|
|
2429
|
+
builds.push({
|
|
2430
|
+
record,
|
|
2431
|
+
state: facts.state,
|
|
2432
|
+
workspace: facts.workspace !== null,
|
|
2433
|
+
provisioning:
|
|
2434
|
+
digest.kind === 'node' &&
|
|
2435
|
+
(await readBuildFacts(this.store, record.slug)).value.provisionMarker !== undefined,
|
|
2436
|
+
})
|
|
2437
|
+
}
|
|
2438
|
+
return builds
|
|
2439
|
+
}
|
|
2440
|
+
|
|
2441
|
+
private async nodeHasCapacity(slug: string): Promise<boolean> {
|
|
2442
|
+
const builds = await this.capacityBuilds()
|
|
2443
|
+
return (
|
|
2444
|
+
nodeCapacity(
|
|
2445
|
+
builds,
|
|
2446
|
+
slug,
|
|
2447
|
+
this.deps.clock(),
|
|
2448
|
+
migrationIdentity(this.store.repositoryFacts().ticketMigrations, this.deps.tickets.name),
|
|
2449
|
+
).occupied < this.deps.config.capacity
|
|
2450
|
+
)
|
|
2451
|
+
}
|
|
2452
|
+
|
|
2238
2453
|
private hasLiveExecutionLease(record: BuildRecord): boolean {
|
|
2239
2454
|
return (
|
|
2240
2455
|
record.lease !== undefined &&
|
|
@@ -2313,7 +2528,8 @@ export class Dispatcher {
|
|
|
2313
2528
|
Object.assign(events, (await readBuildFacts(store, record.slug)).value)
|
|
2314
2529
|
}
|
|
2315
2530
|
const fail = (operation: string, identity: string, error: unknown): never => {
|
|
2316
|
-
|
|
2531
|
+
if (error instanceof ForgeCooldown || isForgeFailure(error)) throw error
|
|
2532
|
+
const detail = error instanceof Error || isForgeFailure(error) ? error.message : String(error)
|
|
2317
2533
|
throw new Error(
|
|
2318
2534
|
`abort cleanup ${operation} failed for ${identity}; remaining cleanup will retry on next dispatcher tick — ${detail}`,
|
|
2319
2535
|
)
|
|
@@ -2433,13 +2649,19 @@ export class Dispatcher {
|
|
|
2433
2649
|
if (record.ticket !== undefined && !has('abort.ticket-returned')) {
|
|
2434
2650
|
const label = 'autobuild:aborted'
|
|
2435
2651
|
try {
|
|
2436
|
-
const current = await tickets.get(record
|
|
2652
|
+
const current = await tickets.get(await this.currentTicketId(record))
|
|
2437
2653
|
if (current === null) throw new Error(`ticket no longer exists in ${tickets.name}`)
|
|
2438
2654
|
if (!current.labels.includes(label)) {
|
|
2439
|
-
await tickets.update(record
|
|
2655
|
+
await tickets.update(await this.currentTicketId(record), {
|
|
2656
|
+
labels: [...current.labels, label],
|
|
2657
|
+
})
|
|
2440
2658
|
}
|
|
2441
2659
|
const triageState = this.triageState()
|
|
2442
|
-
await tickets.transition(record
|
|
2660
|
+
await tickets.transition(await this.currentTicketId(record), triageState)
|
|
2661
|
+
await tickets.comment(
|
|
2662
|
+
await this.currentTicketId(record),
|
|
2663
|
+
`build ${record.slug} aborted — returned to ${triageState}`,
|
|
2664
|
+
)
|
|
2443
2665
|
await append({
|
|
2444
2666
|
actor: DISPATCHER,
|
|
2445
2667
|
type: 'abort.ticket-returned',
|
|
@@ -2447,6 +2669,7 @@ export class Dispatcher {
|
|
|
2447
2669
|
})
|
|
2448
2670
|
} catch (error) {
|
|
2449
2671
|
fail('ticket handback', `${tickets.name} ticket ${record.ticket.id}`, error)
|
|
2672
|
+
return
|
|
2450
2673
|
}
|
|
2451
2674
|
}
|
|
2452
2675
|
|
|
@@ -2474,9 +2697,12 @@ export class Dispatcher {
|
|
|
2474
2697
|
await store.releaseLease(record.slug, record.lease.holder)
|
|
2475
2698
|
}
|
|
2476
2699
|
if (record.ticket !== undefined) {
|
|
2477
|
-
await tickets.transition(
|
|
2700
|
+
await tickets.transition(
|
|
2701
|
+
await this.currentTicketId(record),
|
|
2702
|
+
this.deps.config.tickets.readyState,
|
|
2703
|
+
)
|
|
2478
2704
|
await tickets.comment(
|
|
2479
|
-
record
|
|
2705
|
+
await this.currentTicketId(record),
|
|
2480
2706
|
`build ${record.slug} was discarded during dispatch — returned to ${this.deps.config.tickets.readyState}`,
|
|
2481
2707
|
)
|
|
2482
2708
|
}
|
|
@@ -2509,7 +2735,7 @@ export class Dispatcher {
|
|
|
2509
2735
|
payload: {
|
|
2510
2736
|
id: this.deps.ids('obs'),
|
|
2511
2737
|
kind: 'followup',
|
|
2512
|
-
summary: `Merged commit ${sha} identity inspection failed; inspect its Autobuild-Build trailer manually: ${error instanceof Error ? error.message : String(error)}`,
|
|
2738
|
+
summary: `Merged commit ${sha} identity inspection failed; inspect its Autobuild-Build trailer manually: ${error instanceof Error || isForgeFailure(error) ? error.message : String(error)}`,
|
|
2513
2739
|
refs: [sha],
|
|
2514
2740
|
},
|
|
2515
2741
|
})
|
|
@@ -2532,6 +2758,7 @@ export class Dispatcher {
|
|
|
2532
2758
|
): Promise<void> {
|
|
2533
2759
|
const store = this.store
|
|
2534
2760
|
const { tickets, forge } = this.deps
|
|
2761
|
+
if (await deferMixedVersion(store, record.slug)) return
|
|
2535
2762
|
const pr = state.pr
|
|
2536
2763
|
if (!pr) return
|
|
2537
2764
|
// Forge calls run from the workspace when it still exists (it does until
|
|
@@ -2634,7 +2861,7 @@ export class Dispatcher {
|
|
|
2634
2861
|
break
|
|
2635
2862
|
}
|
|
2636
2863
|
if (!record.ticket) throw new Error('Landing policy requires a readable source ticket')
|
|
2637
|
-
const ticket = await tickets.get(record
|
|
2864
|
+
const ticket = await tickets.get(await this.currentTicketId(record))
|
|
2638
2865
|
if (!ticket)
|
|
2639
2866
|
throw new Error(
|
|
2640
2867
|
`Landing policy source ticket ${record.ticket.id} is unavailable; retrying on next poll`,
|
|
@@ -2642,7 +2869,15 @@ export class Dispatcher {
|
|
|
2642
2869
|
const input = {
|
|
2643
2870
|
from: integration ? ('node' as const) : ('leaf' as const),
|
|
2644
2871
|
into: current.target
|
|
2645
|
-
? {
|
|
2872
|
+
? {
|
|
2873
|
+
kind: 'node' as const,
|
|
2874
|
+
ticket: resolveTicketRef(
|
|
2875
|
+
this.store.repositoryFacts().ticketMigrations,
|
|
2876
|
+
current.target.ticket,
|
|
2877
|
+
this.deps.tickets.name,
|
|
2878
|
+
record.slug,
|
|
2879
|
+
).id,
|
|
2880
|
+
}
|
|
2646
2881
|
: { kind: 'root' as const },
|
|
2647
2882
|
labels: ticket.labels,
|
|
2648
2883
|
}
|
|
@@ -2885,13 +3120,22 @@ export class Dispatcher {
|
|
|
2885
3120
|
}
|
|
2886
3121
|
}
|
|
2887
3122
|
const native = state.landing?.native
|
|
3123
|
+
const failure = state.landing?.applicationFailure
|
|
3124
|
+
const failureRetry =
|
|
3125
|
+
failure &&
|
|
3126
|
+
failure.decisionSeq === state.landing?.decision?.seq &&
|
|
3127
|
+
failure.commandSeq === state.landing?.command?.seq &&
|
|
3128
|
+
sameLandingCandidate(failure.candidate, state.landing?.decision?.candidate)
|
|
3129
|
+
? failure
|
|
3130
|
+
: undefined
|
|
2888
3131
|
const retry =
|
|
2889
|
-
|
|
3132
|
+
failureRetry ??
|
|
3133
|
+
(native?.retry &&
|
|
2890
3134
|
native.decisionSeq === state.landing?.decision?.seq &&
|
|
2891
3135
|
native.commandSeq === state.landing?.command?.seq &&
|
|
2892
3136
|
sameLandingCandidate(native.candidate, state.landing?.decision?.candidate)
|
|
2893
3137
|
? native.retry
|
|
2894
|
-
: undefined
|
|
3138
|
+
: undefined)
|
|
2895
3139
|
if (
|
|
2896
3140
|
!integration &&
|
|
2897
3141
|
!nodeTarget &&
|
|
@@ -2954,6 +3198,31 @@ export class Dispatcher {
|
|
|
2954
3198
|
},
|
|
2955
3199
|
})
|
|
2956
3200
|
.catch(async (error: unknown) => {
|
|
3201
|
+
if (isForgeFailure(error)) {
|
|
3202
|
+
const attempt = (retry?.attempt ?? 0) + 1
|
|
3203
|
+
await store.append(record.slug, {
|
|
3204
|
+
actor: DISPATCHER,
|
|
3205
|
+
type: 'landing.application-failed',
|
|
3206
|
+
payload: {
|
|
3207
|
+
candidate: decision.candidate,
|
|
3208
|
+
decisionSeq: decision.seq,
|
|
3209
|
+
...(state.landing?.command ? { commandSeq: state.landing.command.seq } : {}),
|
|
3210
|
+
message: error.message,
|
|
3211
|
+
attempt,
|
|
3212
|
+
after: new Date(
|
|
3213
|
+
Math.max(
|
|
3214
|
+
this.deps.clock().getTime() +
|
|
3215
|
+
Math.min(300_000, 30_000 * 2 ** Math.min(attempt - 1, 4)),
|
|
3216
|
+
error.details.kind === 'rate-limited'
|
|
3217
|
+
? Date.parse(error.details.resetAt)
|
|
3218
|
+
: 0,
|
|
3219
|
+
),
|
|
3220
|
+
).toISOString(),
|
|
3221
|
+
},
|
|
3222
|
+
})
|
|
3223
|
+
// An uncertain enable stays pending. Never spend another request during a limit.
|
|
3224
|
+
throw error
|
|
3225
|
+
}
|
|
2957
3226
|
await settleFailedEnable()
|
|
2958
3227
|
throw error
|
|
2959
3228
|
})
|
|
@@ -3120,8 +3389,11 @@ export class Dispatcher {
|
|
|
3120
3389
|
}
|
|
3121
3390
|
await this.releaseWorkspace(record.slug, events)
|
|
3122
3391
|
if (record.ticket) {
|
|
3123
|
-
await tickets.transition(record
|
|
3124
|
-
await tickets.comment(
|
|
3392
|
+
await tickets.transition(await this.currentTicketId(record), this.doneState)
|
|
3393
|
+
await tickets.comment(
|
|
3394
|
+
await this.currentTicketId(record),
|
|
3395
|
+
`build ${record.slug} merged: ${pr.url}`,
|
|
3396
|
+
)
|
|
3125
3397
|
}
|
|
3126
3398
|
await store.append(record.slug, {
|
|
3127
3399
|
actor: DISPATCHER,
|
|
@@ -3146,9 +3418,9 @@ export class Dispatcher {
|
|
|
3146
3418
|
await this.releaseWorkspace(record.slug, events)
|
|
3147
3419
|
if (record.ticket) {
|
|
3148
3420
|
const triageState = this.triageState()
|
|
3149
|
-
await tickets.transition(record
|
|
3421
|
+
await tickets.transition(await this.currentTicketId(record), triageState)
|
|
3150
3422
|
await tickets.comment(
|
|
3151
|
-
record
|
|
3423
|
+
await this.currentTicketId(record),
|
|
3152
3424
|
`build ${record.slug} PR closed without merging (${pr.url}) — returned to ${triageState}`,
|
|
3153
3425
|
)
|
|
3154
3426
|
}
|
|
@@ -3194,6 +3466,7 @@ export class Dispatcher {
|
|
|
3194
3466
|
payload: { hostedSeq: hosted.seq },
|
|
3195
3467
|
})
|
|
3196
3468
|
} catch (error) {
|
|
3469
|
+
if (error instanceof ForgeCooldown) throw error
|
|
3197
3470
|
try {
|
|
3198
3471
|
await this.store.append(slug, {
|
|
3199
3472
|
actor: DISPATCHER,
|
|
@@ -3202,8 +3475,10 @@ export class Dispatcher {
|
|
|
3202
3475
|
hostedSeq: hosted.seq,
|
|
3203
3476
|
attempt: priorAttempts + 1,
|
|
3204
3477
|
error:
|
|
3205
|
-
(error instanceof Error
|
|
3206
|
-
|
|
3478
|
+
(error instanceof Error || isForgeFailure(error)
|
|
3479
|
+
? error.message
|
|
3480
|
+
: String(error)
|
|
3481
|
+
).trim() || 'PR attachment reclamation failed without an error message',
|
|
3207
3482
|
},
|
|
3208
3483
|
})
|
|
3209
3484
|
} catch {
|
|
@@ -3214,6 +3489,11 @@ export class Dispatcher {
|
|
|
3214
3489
|
}
|
|
3215
3490
|
}
|
|
3216
3491
|
|
|
3492
|
+
private async confirmedWorkspacePublication(events: CurrentBuildFacts, slug: string) {
|
|
3493
|
+
const sha = await readBuildSelector(this.store, slug, 'publishedBranchHead')
|
|
3494
|
+
return sha === undefined ? undefined : { sha, cacheHeads: events.gitTips }
|
|
3495
|
+
}
|
|
3496
|
+
|
|
3217
3497
|
private recoveryCheckpoint(events: CurrentBuildFacts): string | undefined {
|
|
3218
3498
|
return events.recoveryCheckpoint
|
|
3219
3499
|
}
|
|
@@ -3277,12 +3557,19 @@ export class Dispatcher {
|
|
|
3277
3557
|
// publication's fate BEFORE the destructive reap. The guard's append
|
|
3278
3558
|
// failure propagates — a stale workspace with an unrecorded pending
|
|
3279
3559
|
// request is never reaped (the next tick retries).
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3560
|
+
try {
|
|
3561
|
+
events = await settlePublicationFactsBeforeRelease(
|
|
3562
|
+
{ store: this.store, settlePublication: this.settlePublication },
|
|
3563
|
+
slug,
|
|
3564
|
+
events,
|
|
3565
|
+
reason,
|
|
3566
|
+
)
|
|
3567
|
+
} catch (error) {
|
|
3568
|
+
// Keep this generation and its pending work until forge recovery,
|
|
3569
|
+
// while allowing the sweep to supervise the remaining builds.
|
|
3570
|
+
if (error instanceof ForgeRequestDeferred) return false
|
|
3571
|
+
throw error
|
|
3572
|
+
}
|
|
3286
3573
|
const attempt = (events.cleanupCounts[JSON.stringify(open.ref)] ?? 0) + 1
|
|
3287
3574
|
try {
|
|
3288
3575
|
const outcome = await recovery.reap({
|
|
@@ -3313,7 +3600,8 @@ export class Dispatcher {
|
|
|
3313
3600
|
Object.assign(events, (await readBuildFacts(this.store, slug)).value)
|
|
3314
3601
|
return true
|
|
3315
3602
|
} catch (error) {
|
|
3316
|
-
const message =
|
|
3603
|
+
const message =
|
|
3604
|
+
error instanceof Error || isForgeFailure(error) ? error.message : String(error)
|
|
3317
3605
|
const _failed = await this.store.append(slug, {
|
|
3318
3606
|
actor: DISPATCHER,
|
|
3319
3607
|
type: 'infrastructure.cleanup-attempted',
|
|
@@ -3386,7 +3674,8 @@ export class Dispatcher {
|
|
|
3386
3674
|
})
|
|
3387
3675
|
Object.assign(events, (await readBuildFacts(this.store, slug)).value)
|
|
3388
3676
|
} catch (error) {
|
|
3389
|
-
const message =
|
|
3677
|
+
const message =
|
|
3678
|
+
error instanceof Error || isForgeFailure(error) ? error.message : String(error)
|
|
3390
3679
|
const _failed = await this.store.append(slug, {
|
|
3391
3680
|
actor: DISPATCHER,
|
|
3392
3681
|
type: 'infrastructure.cleanup-attempted',
|
|
@@ -3531,6 +3820,7 @@ export class Dispatcher {
|
|
|
3531
3820
|
): Promise<DispatchOutcome> {
|
|
3532
3821
|
const store = this.store
|
|
3533
3822
|
const { config } = this.deps
|
|
3823
|
+
if (await deferMixedVersion(this.store, record.slug)) return 'parked'
|
|
3534
3824
|
if (!(await this.dispatchBudget(record.slug))) return 'parked'
|
|
3535
3825
|
let stage: EventPayload<'dispatch.failed'>['stage'] = 'create'
|
|
3536
3826
|
try {
|
|
@@ -3546,14 +3836,17 @@ export class Dispatcher {
|
|
|
3546
3836
|
// can only sample the ticket's current assets (SPEC §6.3).
|
|
3547
3837
|
const assets =
|
|
3548
3838
|
seed?.assets ??
|
|
3549
|
-
(await preparePinnedAssets(
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3839
|
+
(await preparePinnedAssets(
|
|
3840
|
+
this.deps.tickets,
|
|
3841
|
+
store,
|
|
3842
|
+
record.repo,
|
|
3843
|
+
await this.currentTicketId(record),
|
|
3844
|
+
).catch((error) => {
|
|
3845
|
+
// Preserve legacy recovery only without native assets. Native preparation
|
|
3846
|
+
// must never publish an empty pin after losing the source bytes.
|
|
3847
|
+
if (this.deps.tickets.assets || this.deps.tickets.name === 'hosted') throw error
|
|
3848
|
+
return []
|
|
3849
|
+
}))
|
|
3557
3850
|
await store.appendIfCurrent(record.slug, 0, {
|
|
3558
3851
|
actor: DISPATCHER,
|
|
3559
3852
|
type: 'build.created',
|
|
@@ -3590,6 +3883,7 @@ export class Dispatcher {
|
|
|
3590
3883
|
branch: record.branch ?? `ab/${record.slug}`,
|
|
3591
3884
|
...(priorGenerations > 0
|
|
3592
3885
|
? {
|
|
3886
|
+
publication: await this.confirmedWorkspacePublication(events, record.slug),
|
|
3593
3887
|
revision: events.state.integration?.cycle?.head ?? this.recoveryCheckpoint(events),
|
|
3594
3888
|
generation: priorGenerations,
|
|
3595
3889
|
}
|
|
@@ -3611,6 +3905,7 @@ export class Dispatcher {
|
|
|
3611
3905
|
events = (await readBuildFacts(store, record.slug)).value
|
|
3612
3906
|
}
|
|
3613
3907
|
} catch (error) {
|
|
3908
|
+
if (error instanceof MixedVersionDeferral) return 'parked'
|
|
3614
3909
|
const events = (await readBuildFacts(store, record.slug)).value
|
|
3615
3910
|
if (stage === 'workspace' && this.deps.workspaces.recovery !== undefined) {
|
|
3616
3911
|
const open = openWorkspace(events)
|
|
@@ -3623,7 +3918,9 @@ export class Dispatcher {
|
|
|
3623
3918
|
})
|
|
3624
3919
|
}
|
|
3625
3920
|
const attempt = events.dispatchFailureCount + 1
|
|
3626
|
-
const message = (
|
|
3921
|
+
const message = (
|
|
3922
|
+
error instanceof Error || isForgeFailure(error) ? error.message : String(error)
|
|
3923
|
+
).trim()
|
|
3627
3924
|
await store.append(record.slug, {
|
|
3628
3925
|
actor: DISPATCHER,
|
|
3629
3926
|
type: 'dispatch.failed',
|
|
@@ -3658,6 +3955,7 @@ export class Dispatcher {
|
|
|
3658
3955
|
): Promise<Exclude<DispatchOutcome, 'deferred'>> {
|
|
3659
3956
|
const store = this.store
|
|
3660
3957
|
|
|
3958
|
+
if (await deferMixedVersion(this.store, record.slug)) return 'parked'
|
|
3661
3959
|
if (!(await this.dispatchBudget(record.slug))) return 'parked'
|
|
3662
3960
|
let stage: EventPayload<'dispatch.failed'>['stage'] = 'spec'
|
|
3663
3961
|
let authored = false
|
|
@@ -3724,7 +4022,10 @@ export class Dispatcher {
|
|
|
3724
4022
|
|
|
3725
4023
|
stage = 'comment'
|
|
3726
4024
|
if (record.ticket !== undefined && !events.commentPosted) {
|
|
3727
|
-
await this.deps.tickets.comment(
|
|
4025
|
+
await this.deps.tickets.comment(
|
|
4026
|
+
await this.currentTicketId(record),
|
|
4027
|
+
`build ${record.slug} dispatched`,
|
|
4028
|
+
)
|
|
3728
4029
|
await store.append(record.slug, {
|
|
3729
4030
|
actor: DISPATCHER,
|
|
3730
4031
|
type: 'dispatch.comment-posted',
|
|
@@ -3757,7 +4058,9 @@ export class Dispatcher {
|
|
|
3757
4058
|
} catch (error) {
|
|
3758
4059
|
const events = (await readBuildFacts(store, record.slug)).value
|
|
3759
4060
|
const attempt = events.dispatchFailureCount + 1
|
|
3760
|
-
const message = (
|
|
4061
|
+
const message = (
|
|
4062
|
+
error instanceof Error || isForgeFailure(error) ? error.message : String(error)
|
|
4063
|
+
).trim()
|
|
3761
4064
|
await store.append(record.slug, {
|
|
3762
4065
|
actor: DISPATCHER,
|
|
3763
4066
|
type: 'dispatch.failed',
|
|
@@ -3915,6 +4218,10 @@ export class Dispatcher {
|
|
|
3915
4218
|
}
|
|
3916
4219
|
const facts = await this.store.buildFacts(record.slug)
|
|
3917
4220
|
const state = facts.state
|
|
4221
|
+
if (mixedVersionDeferred(state)) {
|
|
4222
|
+
await deferMixedVersion(this.store, record.slug)
|
|
4223
|
+
continue
|
|
4224
|
+
}
|
|
3918
4225
|
if (
|
|
3919
4226
|
(state.status === 'queued' && state.discardRequest !== undefined) ||
|
|
3920
4227
|
heldByRepositoryPause(state, paused)
|
|
@@ -4050,6 +4357,8 @@ export class Dispatcher {
|
|
|
4050
4357
|
opts: TickOpts = {},
|
|
4051
4358
|
autoMergeSeedFact: AutoMergeDefaultFact | undefined = undefined,
|
|
4052
4359
|
): Promise<void> {
|
|
4360
|
+
const health = this.store.repositoryFacts().forgeHealth
|
|
4361
|
+
if (health && Date.parse(health.resetAt) > this.deps.clock().getTime()) return
|
|
4053
4362
|
const store = this.store
|
|
4054
4363
|
const { tickets, config } = this.deps
|
|
4055
4364
|
const checkpoint = await this.scanCheckpoint('admission')
|
|
@@ -4062,21 +4371,11 @@ export class Dispatcher {
|
|
|
4062
4371
|
// Blocked and paused builds still occupy a slot: their workspaces and
|
|
4063
4372
|
// pending work are live, only waiting on a human. Capacity is per repo
|
|
4064
4373
|
// (§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
|
-
}
|
|
4374
|
+
const capacityBuilds = await this.capacityBuilds()
|
|
4375
|
+
const active = dispatchCapacity(capacityBuilds, config.capacity, this.deps.clock()).occupied
|
|
4376
|
+
const activeRefs: TicketRef[] = capacityBuilds
|
|
4377
|
+
.filter(({ state }) => state.status !== 'done' && state.status !== 'aborted')
|
|
4378
|
+
.flatMap(({ record }) => (record.ticket ? [record.ticket] : []))
|
|
4080
4379
|
let capacity = config.capacity - active
|
|
4081
4380
|
|
|
4082
4381
|
// The ready scan runs even at full capacity: `queued` is the operator's
|
|
@@ -4126,7 +4425,15 @@ export class Dispatcher {
|
|
|
4126
4425
|
// still runs either way, so the standing queue-depth report stays honest —
|
|
4127
4426
|
// this only declines to claim a ticket into a build that would immediately
|
|
4128
4427
|
// sit held.
|
|
4129
|
-
if (
|
|
4428
|
+
if (
|
|
4429
|
+
paused ||
|
|
4430
|
+
(capacity <= 0 &&
|
|
4431
|
+
!ready.some(
|
|
4432
|
+
(ticket) =>
|
|
4433
|
+
ticket.kind === 'node' ||
|
|
4434
|
+
(ticket.target !== undefined && (ticket.blockedBy?.length ?? 0) > 0),
|
|
4435
|
+
))
|
|
4436
|
+
) {
|
|
4130
4437
|
await this.sourceCondition(undefined, 'ready-scan')
|
|
4131
4438
|
if (!this.outOfBudget(opts)) await this.completeScan(checkpoint, report)
|
|
4132
4439
|
return
|
|
@@ -4154,16 +4461,18 @@ export class Dispatcher {
|
|
|
4154
4461
|
treeEntries.some(({ digest }) => digest.kind === 'node') ||
|
|
4155
4462
|
ready.some((ticket) => ticket.kind === 'node')
|
|
4156
4463
|
let presence: PresenceInputs | undefined
|
|
4464
|
+
const migrations = this.store.repositoryFacts().ticketMigrations
|
|
4465
|
+
const normalizeTicket = historicalTicketIdentity(migrations, this.deps.tickets.name)
|
|
4157
4466
|
const builtTickets = hasNodes
|
|
4158
4467
|
? new Set(
|
|
4159
4468
|
treeEntries.flatMap(({ record }) =>
|
|
4160
|
-
record.ticket ? [
|
|
4469
|
+
record.ticket ? [normalizeTicket(record.ticket, record.slug)] : [],
|
|
4161
4470
|
),
|
|
4162
4471
|
)
|
|
4163
4472
|
: undefined
|
|
4164
4473
|
const needsPresence = (candidate: Ticket) =>
|
|
4165
4474
|
(candidate.blockedBy ?? []).some((id) => {
|
|
4166
|
-
const build = blockerBuild(treeEntries, candidate.ref.source, id)
|
|
4475
|
+
const build = blockerBuild(treeEntries, candidate.ref.source, id, normalizeTicket)
|
|
4167
4476
|
return (
|
|
4168
4477
|
id !== candidate.ref.id &&
|
|
4169
4478
|
build !== undefined &&
|
|
@@ -4176,6 +4485,7 @@ export class Dispatcher {
|
|
|
4176
4485
|
string,
|
|
4177
4486
|
{ branch: string; destination: string; head: string; identities: string[] }
|
|
4178
4487
|
>()
|
|
4488
|
+
const demands: { slug: string; request: EventPayload<'node.restack-requested'> }[] = []
|
|
4179
4489
|
const verdicts = new Map<string, DependencyVerdict>()
|
|
4180
4490
|
const failed = new Set<string>()
|
|
4181
4491
|
const targetBlocked = new Set<string>()
|
|
@@ -4209,7 +4519,12 @@ export class Dispatcher {
|
|
|
4209
4519
|
candidate.target !== undefined,
|
|
4210
4520
|
)
|
|
4211
4521
|
.flatMap((candidate) => {
|
|
4212
|
-
const node = blockerBuild(
|
|
4522
|
+
const node = blockerBuild(
|
|
4523
|
+
entries,
|
|
4524
|
+
candidate.ref.source,
|
|
4525
|
+
candidate.target!,
|
|
4526
|
+
normalizeTicket,
|
|
4527
|
+
)
|
|
4213
4528
|
return node && typeof node !== 'string' && node.digest.kind === 'node'
|
|
4214
4529
|
? [node.record.slug]
|
|
4215
4530
|
: []
|
|
@@ -4222,7 +4537,14 @@ export class Dispatcher {
|
|
|
4222
4537
|
aliases: new Map(),
|
|
4223
4538
|
landings: [],
|
|
4224
4539
|
}
|
|
4225
|
-
verdict = await this.presenceVerdict(
|
|
4540
|
+
verdict = await this.presenceVerdict(
|
|
4541
|
+
ticket,
|
|
4542
|
+
target,
|
|
4543
|
+
nodes,
|
|
4544
|
+
inputs,
|
|
4545
|
+
demands,
|
|
4546
|
+
destinationHeads,
|
|
4547
|
+
)
|
|
4226
4548
|
} else verdict = analyzeDependencies(ticket.ref.id, ticket.blockedBy ?? [], nodes)
|
|
4227
4549
|
} catch (error) {
|
|
4228
4550
|
if (error instanceof TicketSourceRateLimitError) {
|
|
@@ -4233,14 +4555,38 @@ export class Dispatcher {
|
|
|
4233
4555
|
failed.add(ticket.ref.id)
|
|
4234
4556
|
report.dependencyCheckFailed += 1
|
|
4235
4557
|
report.dependencyDiagnostics.push(
|
|
4236
|
-
`ticket ${ticket.ref.id}: dependency check failed — ${error instanceof Error ? error.message : String(error)}`,
|
|
4558
|
+
`ticket ${ticket.ref.id}: dependency check failed — ${error instanceof Error || isForgeFailure(error) ? error.message : String(error)}`,
|
|
4237
4559
|
)
|
|
4238
4560
|
continue
|
|
4239
4561
|
}
|
|
4240
4562
|
verdicts.set(ticket.ref.id, verdict)
|
|
4241
4563
|
}
|
|
4242
4564
|
if (this.outOfBudget(opts)) return
|
|
4243
|
-
if (failed.size === 0)
|
|
4565
|
+
if (failed.size === 0) {
|
|
4566
|
+
await this.sourceCondition(undefined, 'dependency-check')
|
|
4567
|
+
for (const { slug, request } of demands) {
|
|
4568
|
+
if (this.outOfBudget(opts)) return
|
|
4569
|
+
const current = (await this.store.buildFacts(slug)).state
|
|
4570
|
+
const pending = Object.values(current.nodeRestack?.requests ?? {})
|
|
4571
|
+
if (
|
|
4572
|
+
current.baseBranch !== request.branch ||
|
|
4573
|
+
pending.some(
|
|
4574
|
+
(old) =>
|
|
4575
|
+
old.reason === 'presence' &&
|
|
4576
|
+
old.branch === request.branch &&
|
|
4577
|
+
old.dependent?.source === request.dependent?.source &&
|
|
4578
|
+
old.dependent?.id === request.dependent?.id &&
|
|
4579
|
+
(request.identities ?? []).every((id) => old.identities?.includes(id)),
|
|
4580
|
+
)
|
|
4581
|
+
)
|
|
4582
|
+
continue
|
|
4583
|
+
await this.store.appendIfCurrent(slug, current.lastSeq, {
|
|
4584
|
+
actor: DISPATCHER,
|
|
4585
|
+
type: 'node.restack-requested',
|
|
4586
|
+
payload: request,
|
|
4587
|
+
})
|
|
4588
|
+
}
|
|
4589
|
+
}
|
|
4244
4590
|
for (const verdict of verdicts.values()) {
|
|
4245
4591
|
if (verdict.unresolved.length > 0) {
|
|
4246
4592
|
report.dependencyBlocked += 1
|
|
@@ -4380,10 +4726,24 @@ export class Dispatcher {
|
|
|
4380
4726
|
)
|
|
4381
4727
|
return `integration requires forge ${forge.name} capabilities createNodeBranch, compareBranches and remoteBranchSha; upgrade the plugin`
|
|
4382
4728
|
if (ticket.target === undefined) return undefined
|
|
4729
|
+
const migrations = this.store.repositoryFacts().ticketMigrations
|
|
4383
4730
|
const entries = (await this.repoBuildDigests())
|
|
4384
4731
|
.filter(
|
|
4385
4732
|
({ record }) =>
|
|
4386
|
-
record.ticket
|
|
4733
|
+
record.ticket &&
|
|
4734
|
+
(() => {
|
|
4735
|
+
try {
|
|
4736
|
+
const ref = resolveTicketRef(
|
|
4737
|
+
migrations,
|
|
4738
|
+
record.ticket,
|
|
4739
|
+
ticket.ref.source,
|
|
4740
|
+
record.slug,
|
|
4741
|
+
)
|
|
4742
|
+
return ref.id === ticket.target
|
|
4743
|
+
} catch {
|
|
4744
|
+
return false
|
|
4745
|
+
}
|
|
4746
|
+
})(),
|
|
4387
4747
|
)
|
|
4388
4748
|
.sort(
|
|
4389
4749
|
(a, b) =>
|
|
@@ -4411,7 +4771,13 @@ export class Dispatcher {
|
|
|
4411
4771
|
if (state.integration?.intent && !state.integration.landing)
|
|
4412
4772
|
return `target node ${ticket.target} is landing`
|
|
4413
4773
|
if (!digest.nodeOpened || !record.branch) return `target node ${ticket.target} is not yet open`
|
|
4414
|
-
return {
|
|
4774
|
+
return {
|
|
4775
|
+
target: {
|
|
4776
|
+
ticket: resolveTicketRef(migrations, record.ticket!, this.deps.tickets.name, record.slug),
|
|
4777
|
+
build: record.slug,
|
|
4778
|
+
},
|
|
4779
|
+
branch: record.branch,
|
|
4780
|
+
}
|
|
4415
4781
|
}
|
|
4416
4782
|
|
|
4417
4783
|
private async openNode(record: BuildRecord, state: BuildState): Promise<void> {
|
|
@@ -4493,6 +4859,7 @@ export class Dispatcher {
|
|
|
4493
4859
|
launched: Set<string>,
|
|
4494
4860
|
opts: TickOpts,
|
|
4495
4861
|
): Promise<void> {
|
|
4862
|
+
if (await deferMixedVersion(this.store, record.slug)) return
|
|
4496
4863
|
if (state.nodeRestack?.parentRequest && !state.nodeRestack.active) return
|
|
4497
4864
|
if (
|
|
4498
4865
|
state.nodeRestack?.parentChange &&
|
|
@@ -4538,8 +4905,11 @@ export class Dispatcher {
|
|
|
4538
4905
|
forge.remoteBranchSha(record.branch),
|
|
4539
4906
|
])
|
|
4540
4907
|
if (
|
|
4541
|
-
parent === state.nodeRestack?.contributionBase &&
|
|
4542
|
-
|
|
4908
|
+
(parent === state.nodeRestack?.contributionBase || !nodeRestackDemand(state)) &&
|
|
4909
|
+
state.nodeRestack?.distance?.parent === parent &&
|
|
4910
|
+
state.nodeRestack.distance.base === state.nodeRestack.contributionBase &&
|
|
4911
|
+
head === state.nodeRestack?.inventory?.head &&
|
|
4912
|
+
!Object.keys(state.nodeRestack?.requests ?? {}).length
|
|
4543
4913
|
)
|
|
4544
4914
|
return
|
|
4545
4915
|
}
|
|
@@ -4616,7 +4986,10 @@ export class Dispatcher {
|
|
|
4616
4986
|
const parentHead = forge.remoteBranchSha
|
|
4617
4987
|
? await forge.remoteBranchSha(state.baseBranch!)
|
|
4618
4988
|
: undefined
|
|
4619
|
-
if (
|
|
4989
|
+
if (
|
|
4990
|
+
state.nodeRestack?.active ||
|
|
4991
|
+
(nodeRestackDemand(state) && parentHead !== state.nodeRestack?.contributionBase)
|
|
4992
|
+
) {
|
|
4620
4993
|
// Upgrade recovery: an old dispatcher may have left a native request
|
|
4621
4994
|
// armed. Cancel every targeting leaf before admitting a node rewrite.
|
|
4622
4995
|
for (const child of await this.repoBuildDigests()) {
|
|
@@ -4644,6 +5017,7 @@ export class Dispatcher {
|
|
|
4644
5017
|
workspacePath,
|
|
4645
5018
|
holder,
|
|
4646
5019
|
canWrite: async () => {
|
|
5020
|
+
if (await deferMixedVersion(this.store, record.slug)) return false
|
|
4647
5021
|
if (this.outOfBudget(opts)) return false
|
|
4648
5022
|
if (state.pr && (await forge.getPrState(checkout, state.pr.number)).state !== 'open')
|
|
4649
5023
|
return false
|
|
@@ -4704,19 +5078,7 @@ export class Dispatcher {
|
|
|
4704
5078
|
}
|
|
4705
5079
|
}
|
|
4706
5080
|
|
|
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
|
|
5081
|
+
if (!(await this.nodeHasCapacity(record.slug))) return
|
|
4720
5082
|
if (openWorkspace(facts) === null && this.deps.workspaces.recovery) {
|
|
4721
5083
|
const kicked = await this.ensureProvisionContinuation(record, facts, 'launch')
|
|
4722
5084
|
if (kicked === 'kicked') report.provisioning += 1
|
|
@@ -4745,7 +5107,8 @@ export class Dispatcher {
|
|
|
4745
5107
|
}
|
|
4746
5108
|
}
|
|
4747
5109
|
} catch (error) {
|
|
4748
|
-
const message =
|
|
5110
|
+
const message =
|
|
5111
|
+
error instanceof Error || isForgeFailure(error) ? error.message : String(error)
|
|
4749
5112
|
// Safety refusals require human judgment. Infrastructure failures remain
|
|
4750
5113
|
// retryable dispatch failures and retain their active reservation.
|
|
4751
5114
|
if (
|
|
@@ -4782,6 +5145,7 @@ export class Dispatcher {
|
|
|
4782
5145
|
state: BuildState,
|
|
4783
5146
|
report: TickReport,
|
|
4784
5147
|
launched: Set<string>,
|
|
5148
|
+
sampling: { refreshOnly?: boolean } = {},
|
|
4785
5149
|
): Promise<void> {
|
|
4786
5150
|
if (
|
|
4787
5151
|
state.status === 'paused' ||
|
|
@@ -4813,12 +5177,13 @@ export class Dispatcher {
|
|
|
4813
5177
|
this.integrationPollDue(
|
|
4814
5178
|
this.integrationPolls,
|
|
4815
5179
|
record.slug,
|
|
4816
|
-
`${comparison.headSha}:${comparison.parentSha}:${state.landing?.command?.seq ?? state.landing?.decision?.seq ?? ''}:${claims}`,
|
|
5180
|
+
`${comparison.headSha}:${comparison.parentSha}:${state.nodeRestack?.inventory?.head ?? ''}:${state.landing?.command?.seq ?? state.landing?.decision?.seq ?? ''}:${claims}`,
|
|
4817
5181
|
)
|
|
4818
5182
|
) {
|
|
4819
5183
|
await this.observeIntegration(record.slug)
|
|
4820
5184
|
state = (await this.store.buildFacts(record.slug)).state
|
|
4821
5185
|
}
|
|
5186
|
+
if (sampling.refreshOnly) return
|
|
4822
5187
|
if (
|
|
4823
5188
|
state.integration?.cycle &&
|
|
4824
5189
|
!state.nodeRestack?.active &&
|
|
@@ -4902,20 +5267,7 @@ export class Dispatcher {
|
|
|
4902
5267
|
if (openWorkspace(facts)) await this.releaseWorkspace(record.slug, facts)
|
|
4903
5268
|
return
|
|
4904
5269
|
}
|
|
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
|
|
5270
|
+
if (!(await this.nodeHasCapacity(record.slug))) return
|
|
4919
5271
|
await this.observeIntegration(record.slug)
|
|
4920
5272
|
state = (await this.store.buildFacts(record.slug)).state
|
|
4921
5273
|
if (!integrationCurrent(state)) return
|
|
@@ -4970,7 +5322,15 @@ export class Dispatcher {
|
|
|
4970
5322
|
return comparison
|
|
4971
5323
|
}
|
|
4972
5324
|
const comparison = await observe()
|
|
4973
|
-
|
|
5325
|
+
// Branch comparison is telemetry, never contribution provenance: a
|
|
5326
|
+
// rewritten parent can make inherited siblings appear "ahead". Only the
|
|
5327
|
+
// inventory of this exact source head proves that the node owns work.
|
|
5328
|
+
const inventory = state.nodeRestack?.inventory
|
|
5329
|
+
if (
|
|
5330
|
+
inventory?.head !== comparison.headSha ||
|
|
5331
|
+
!((inventory.contributions?.length ?? 0) + inventory.foreign.length)
|
|
5332
|
+
)
|
|
5333
|
+
return
|
|
4974
5334
|
let pr: Awaited<ReturnType<typeof forge.openPr>>
|
|
4975
5335
|
try {
|
|
4976
5336
|
pr = await forge.openPr({
|
|
@@ -4981,7 +5341,11 @@ export class Dispatcher {
|
|
|
4981
5341
|
body: `Integration build ${record.slug}. Target: ${state.target?.ticket.id ?? state.baseBranch}. Human landing required.`,
|
|
4982
5342
|
})
|
|
4983
5343
|
} catch (error) {
|
|
4984
|
-
if (
|
|
5344
|
+
if (
|
|
5345
|
+
error instanceof NoCommitsBetweenBranchesError &&
|
|
5346
|
+
(await observe()).headSha === comparison.parentSha
|
|
5347
|
+
)
|
|
5348
|
+
return
|
|
4985
5349
|
throw error
|
|
4986
5350
|
}
|
|
4987
5351
|
await this.store.append(record.slug, { actor: DISPATCHER, type: 'pr.opened', payload: { pr } })
|
|
@@ -5027,8 +5391,12 @@ export class Dispatcher {
|
|
|
5027
5391
|
const head = pr.headSha
|
|
5028
5392
|
const base =
|
|
5029
5393
|
state.nodeRestack?.contributionBoundaries?.[head] ??
|
|
5030
|
-
state.nodeRestack?.
|
|
5031
|
-
|
|
5394
|
+
(state.nodeRestack?.inventory?.head === head
|
|
5395
|
+
? state.nodeRestack.contributionBase
|
|
5396
|
+
: undefined) ??
|
|
5397
|
+
(state.nodeRestack?.contributionBase === state.nodeOpened?.sha
|
|
5398
|
+
? state.nodeOpened?.sha
|
|
5399
|
+
: undefined)
|
|
5032
5400
|
if (!head || !base) throw new Error('missing node contribution source range')
|
|
5033
5401
|
// Fetch retained objects when the kernel repository has not seen
|
|
5034
5402
|
// this source head (including remote guest publication).
|
|
@@ -5098,6 +5466,93 @@ export class Dispatcher {
|
|
|
5098
5466
|
}
|
|
5099
5467
|
}
|
|
5100
5468
|
|
|
5469
|
+
private async sampleDestinationPresence(
|
|
5470
|
+
branch: string,
|
|
5471
|
+
destination: string,
|
|
5472
|
+
target: { target: { build: string } } | undefined,
|
|
5473
|
+
inputs: PresenceInputs,
|
|
5474
|
+
observations: Map<
|
|
5475
|
+
string,
|
|
5476
|
+
{ branch: string; destination: string; head: string; identities: string[] }
|
|
5477
|
+
>,
|
|
5478
|
+
) {
|
|
5479
|
+
let observed = observations.get(destination)
|
|
5480
|
+
if (!observed) {
|
|
5481
|
+
const forge = this.kernelForge()
|
|
5482
|
+
if (!forge.remoteBranchSha || (!forge.snapshotBase && !forge.kernelExec && !forge.rewrite))
|
|
5483
|
+
throw new Error('forge cannot snapshot destination presence')
|
|
5484
|
+
const head = await forge.remoteBranchSha(branch)
|
|
5485
|
+
const evidence = JSON.stringify({
|
|
5486
|
+
version: 2,
|
|
5487
|
+
revisions: [
|
|
5488
|
+
...inputs.entries
|
|
5489
|
+
.filter(({ digest }) => digest.mergedSha || digest.nodeContribution)
|
|
5490
|
+
.map(({ record, digest }) => [record.slug, digest.readinessChangeSeq]),
|
|
5491
|
+
...[...inputs.states].map(([slug, state]) => [slug, state.lastSeq]),
|
|
5492
|
+
].sort(),
|
|
5493
|
+
})
|
|
5494
|
+
const cached = this.store.repositoryFacts().presence[destination]
|
|
5495
|
+
if (cached?.head === head && cached.branch === branch && cached.evidence === evidence)
|
|
5496
|
+
observed = cached
|
|
5497
|
+
else
|
|
5498
|
+
observed = await this.withKernelRepository(async (path) => {
|
|
5499
|
+
const destinationRef = `refs/autobuild/reconcile/${target?.target.build ?? 'presence'}/presence`
|
|
5500
|
+
let sampled: string
|
|
5501
|
+
if (forge.snapshotBase)
|
|
5502
|
+
sampled = await forge.snapshotBase({
|
|
5503
|
+
workspacePath: path,
|
|
5504
|
+
base: branch,
|
|
5505
|
+
destinationRef,
|
|
5506
|
+
})
|
|
5507
|
+
else if (target && forge.rewrite)
|
|
5508
|
+
sampled = await forge.rewrite.snapshot({
|
|
5509
|
+
workspacePath: path,
|
|
5510
|
+
branch,
|
|
5511
|
+
destinationRef,
|
|
5512
|
+
})
|
|
5513
|
+
else {
|
|
5514
|
+
const exec = forge.kernelExec ?? this.deps.exec
|
|
5515
|
+
const fetch = await exec(
|
|
5516
|
+
[
|
|
5517
|
+
'git',
|
|
5518
|
+
'fetch',
|
|
5519
|
+
'--no-tags',
|
|
5520
|
+
'--no-write-fetch-head',
|
|
5521
|
+
'--refmap=',
|
|
5522
|
+
'origin',
|
|
5523
|
+
`+refs/heads/${branch}:${destinationRef}`,
|
|
5524
|
+
],
|
|
5525
|
+
{ cwd: path },
|
|
5526
|
+
)
|
|
5527
|
+
if (fetch.exitCode !== 0) throw new Error(fetch.stderr)
|
|
5528
|
+
const resolved = await exec(
|
|
5529
|
+
['git', 'rev-parse', '--verify', `${destinationRef}^{commit}`],
|
|
5530
|
+
{ cwd: path },
|
|
5531
|
+
)
|
|
5532
|
+
if (resolved.exitCode !== 0) throw new Error(resolved.stderr)
|
|
5533
|
+
sampled = resolved.stdout.trim()
|
|
5534
|
+
}
|
|
5535
|
+
if (sampled !== head) throw new Error('destination moved while sampling presence')
|
|
5536
|
+
const identities = await observePresence(
|
|
5537
|
+
{ exec: forge.kernelExec ?? this.deps.exec, workspacePath: path },
|
|
5538
|
+
head,
|
|
5539
|
+
inputs.landings,
|
|
5540
|
+
inputs.aliases,
|
|
5541
|
+
)
|
|
5542
|
+
const payload = { branch, destination, head, evidence, identities }
|
|
5543
|
+
await this.store.ensureRepo(this.deps.repo)
|
|
5544
|
+
await this.store.appendRepo(this.deps.repo, {
|
|
5545
|
+
actor: DISPATCHER,
|
|
5546
|
+
type: 'change-presence.observed',
|
|
5547
|
+
payload,
|
|
5548
|
+
})
|
|
5549
|
+
return payload
|
|
5550
|
+
})
|
|
5551
|
+
observations.set(destination, observed)
|
|
5552
|
+
}
|
|
5553
|
+
return observed!
|
|
5554
|
+
}
|
|
5555
|
+
|
|
5101
5556
|
private async presenceVerdict(
|
|
5102
5557
|
ticket: Ticket,
|
|
5103
5558
|
target:
|
|
@@ -5105,6 +5560,7 @@ export class Dispatcher {
|
|
|
5105
5560
|
| undefined,
|
|
5106
5561
|
nodes: Map<string, DependencyState>,
|
|
5107
5562
|
inputs: PresenceInputs,
|
|
5563
|
+
demands: { slug: string; request: EventPayload<'node.restack-requested'> }[],
|
|
5108
5564
|
observations: Map<
|
|
5109
5565
|
string,
|
|
5110
5566
|
{ branch: string; destination: string; head: string; identities: string[] }
|
|
@@ -5117,7 +5573,15 @@ export class Dispatcher {
|
|
|
5117
5573
|
const required = new Map<string, ChangeIdentity[]>()
|
|
5118
5574
|
const fallback: string[] = []
|
|
5119
5575
|
for (const id of ticket.blockedBy ?? []) {
|
|
5120
|
-
const build = blockerBuild(
|
|
5576
|
+
const build = blockerBuild(
|
|
5577
|
+
inputs.entries,
|
|
5578
|
+
ticket.ref.source,
|
|
5579
|
+
id,
|
|
5580
|
+
historicalTicketIdentity(
|
|
5581
|
+
this.store.repositoryFacts().ticketMigrations,
|
|
5582
|
+
this.deps.tickets.name,
|
|
5583
|
+
),
|
|
5584
|
+
)
|
|
5121
5585
|
if (id === ticket.ref.id || !nodes.get(id)?.exists || build === undefined) {
|
|
5122
5586
|
fallback.push(id)
|
|
5123
5587
|
continue
|
|
@@ -5156,79 +5620,61 @@ export class Dispatcher {
|
|
|
5156
5620
|
diagnostics.push(...lifecycle.diagnostics)
|
|
5157
5621
|
if ([...required.values()].every((ids) => ids.length === 0)) return { unresolved, diagnostics }
|
|
5158
5622
|
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
|
|
5623
|
+
const observed = await this.sampleDestinationPresence(
|
|
5624
|
+
branch,
|
|
5625
|
+
destination,
|
|
5626
|
+
target,
|
|
5627
|
+
inputs,
|
|
5628
|
+
observations,
|
|
5629
|
+
)
|
|
5630
|
+
const missing = [
|
|
5631
|
+
...new Set(
|
|
5632
|
+
[...required.values()].flatMap((ids) => missingChanges(ids, observed.identities)),
|
|
5633
|
+
),
|
|
5634
|
+
]
|
|
5635
|
+
if (target && missing.length) {
|
|
5636
|
+
const path: { slug?: string; identities: string[]; branch: string; head: string }[] = [
|
|
5637
|
+
{ slug: target.target.build, ...observed },
|
|
5638
|
+
]
|
|
5639
|
+
const seen = new Set<string>()
|
|
5640
|
+
let slug: string | undefined = target.target.build
|
|
5641
|
+
while (slug) {
|
|
5642
|
+
if (seen.has(slug)) throw new Error('cyclic node ancestry')
|
|
5643
|
+
seen.add(slug)
|
|
5644
|
+
const record = await this.store.getBuild(slug)
|
|
5645
|
+
if (!record || record.repo !== this.deps.repo) throw new Error('missing node ancestry')
|
|
5646
|
+
const state: BuildState = (await this.store.buildFacts(slug)).state
|
|
5647
|
+
if (state.kind !== 'node' || !state.baseBranch || state.nodeRestack?.parentRequest)
|
|
5648
|
+
throw new Error('uncertain node ancestry')
|
|
5649
|
+
slug = state.target?.build
|
|
5650
|
+
const parent = await this.sampleDestinationPresence(
|
|
5651
|
+
state.baseBranch,
|
|
5652
|
+
slug ?? `root:${state.baseBranch}`,
|
|
5653
|
+
slug ? { target: { build: slug } } : undefined,
|
|
5654
|
+
inputs,
|
|
5655
|
+
observations,
|
|
5656
|
+
)
|
|
5657
|
+
path.push({ ...(slug ? { slug } : {}), ...parent })
|
|
5658
|
+
if (missing.every((id) => path.some((entry) => entry.identities.includes(id)))) break
|
|
5659
|
+
}
|
|
5660
|
+
for (const requested of presenceRestackPath(path, missing)) {
|
|
5661
|
+
const index = path.findIndex((entry) => entry.slug === requested)
|
|
5662
|
+
const parent = path[index + 1]!
|
|
5663
|
+
const identities = missing.filter((id) =>
|
|
5664
|
+
path.slice(index + 1).some((entry) => entry.identities.includes(id)),
|
|
5665
|
+
)
|
|
5666
|
+
demands.push({
|
|
5667
|
+
slug: requested,
|
|
5668
|
+
request: {
|
|
5669
|
+
id: this.deps.ids('presence-restack'),
|
|
5670
|
+
reason: 'presence',
|
|
5671
|
+
branch: parent.branch,
|
|
5672
|
+
parent: parent.head,
|
|
5673
|
+
dependent: ticket.ref,
|
|
5674
|
+
identities,
|
|
5675
|
+
},
|
|
5230
5676
|
})
|
|
5231
|
-
|
|
5677
|
+
}
|
|
5232
5678
|
}
|
|
5233
5679
|
for (const [id, identities] of required) {
|
|
5234
5680
|
const missing = missingChanges(identities, observed.identities)
|
|
@@ -5243,7 +5689,7 @@ export class Dispatcher {
|
|
|
5243
5689
|
for (const id of required.keys()) {
|
|
5244
5690
|
unresolved.push(id)
|
|
5245
5691
|
diagnostics.push(
|
|
5246
|
-
`ticket ${ticket.ref.id}: blocker ${id} presence unavailable in ${destination} (${branch}): ${error instanceof Error ? error.message : String(error)}`,
|
|
5692
|
+
`ticket ${ticket.ref.id}: blocker ${id} presence unavailable in ${destination} (${branch}): ${error instanceof Error || isForgeFailure(error) ? error.message : String(error)}`,
|
|
5247
5693
|
)
|
|
5248
5694
|
}
|
|
5249
5695
|
}
|