@defrex/autobuild 1.0.0-beta.2 → 1.0.0-beta.4
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 +342 -23
- package/bin/ab-dispatch-generation.ts +93 -0
- package/docs/answering-blocked-builds.md +21 -3
- package/docs/architecture.md +170 -7
- package/docs/configuration.md +173 -5
- package/docs/integration-tree.md +91 -4
- package/docs/integration.md +54 -0
- package/docs/operator-api.md +58 -5
- package/docs/remote-store-protocol.md +9 -1
- package/docs/remote-ticket-protocol.md +5 -0
- package/docs/restacking.md +4 -1
- package/docs/setup.md +24 -0
- package/docs/spec-standard.md +94 -5
- package/docs/ticket-migration.md +50 -4
- package/package.json +3 -3
- package/packages/core/src/cli/artifact.ts +5 -4
- package/packages/core/src/cli/attention.ts +2 -0
- package/packages/core/src/cli/binary-direct.ts +190 -0
- package/packages/core/src/cli/binary-lifecycle.ts +46 -0
- package/packages/core/src/cli/binary.ts +24 -210
- package/packages/core/src/cli/build-control.ts +108 -5
- package/packages/core/src/cli/context.ts +41 -1
- package/packages/core/src/cli/dashboard/hand-pushed.ts +24 -0
- package/packages/core/src/cli/dashboard/handoff.ts +64 -0
- package/packages/core/src/cli/dashboard/integration-detail.ts +11 -6
- package/packages/core/src/cli/dashboard/integration-row.ts +15 -8
- package/packages/core/src/cli/dashboard/model.ts +41 -10
- package/packages/core/src/cli/dashboard/render.ts +24 -2
- package/packages/core/src/cli/dashboard/rollback.ts +30 -0
- package/packages/core/src/cli/dispatch-args.ts +53 -0
- package/packages/core/src/cli/dispatch-crash-budget.ts +15 -0
- package/packages/core/src/cli/dispatch-frontend.ts +57 -5
- package/packages/core/src/cli/dispatch-handoff.ts +276 -0
- package/packages/core/src/cli/dispatch-launch-contract.ts +170 -0
- package/packages/core/src/cli/dispatch-launcher.ts +580 -0
- package/packages/core/src/cli/dispatch-parent-watch.ts +44 -0
- package/packages/core/src/cli/dispatch-preflight.ts +272 -0
- package/packages/core/src/cli/dispatch-presentation-job.ts +46 -0
- package/packages/core/src/cli/dispatch-presentation-ownership.ts +9 -0
- package/packages/core/src/cli/dispatch-process.ts +22 -90
- package/packages/core/src/cli/dispatch-readiness.ts +47 -0
- package/packages/core/src/cli/dispatch-repository-feed.ts +6 -1
- package/packages/core/src/cli/dispatch-runtime-cache.ts +522 -0
- package/packages/core/src/cli/dispatch-runtime-dependencies.ts +291 -0
- package/packages/core/src/cli/dispatch-runtime-use.ts +336 -0
- package/packages/core/src/cli/dispatch-upgrade-controller.ts +221 -0
- package/packages/core/src/cli/dispatch-upgrade-install.ts +258 -0
- package/packages/core/src/cli/dispatch-upgrade-source.ts +309 -0
- package/packages/core/src/cli/dispatch-upgrade-target.ts +190 -0
- package/packages/core/src/cli/dispatch.ts +609 -60
- package/packages/core/src/cli/dispatcher-liveness.ts +1 -1
- package/packages/core/src/cli/harvest.ts +28 -11
- package/packages/core/src/cli/help.ts +7 -3
- package/packages/core/src/cli/installation.ts +5 -3
- package/packages/core/src/cli/main-checkout.ts +59 -0
- package/packages/core/src/cli/main.ts +26 -53
- package/packages/core/src/cli/node-verification-provenance.ts +97 -0
- package/packages/core/src/cli/repo-state.ts +3 -58
- package/packages/core/src/cli/repository-status.ts +74 -4
- package/packages/core/src/cli/runtime-spawn.ts +16 -0
- package/packages/core/src/cli/status.ts +57 -3
- package/packages/core/src/cli/ticket.ts +35 -11
- package/packages/core/src/cli/upgrade-followup.ts +25 -0
- package/packages/core/src/cli/wait.ts +3 -0
- package/packages/core/src/cli/watch.ts +7 -0
- package/packages/core/src/config/live.ts +1 -0
- package/packages/core/src/config/schema.ts +8 -4
- package/packages/core/src/distribution-packaging.ts +116 -0
- package/packages/core/src/events/catalog.ts +6 -0
- package/packages/core/src/events/payloads.ts +55 -9
- package/packages/core/src/events/policy.ts +26 -0
- package/packages/core/src/events/repository.ts +205 -4
- package/packages/core/src/events/runtime.ts +16 -0
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +6537 -4053
- package/packages/core/src/kernel/change-presence.ts +7 -1
- package/packages/core/src/kernel/dispatch-capacity.ts +12 -4
- package/packages/core/src/kernel/dispatch-drain-recovery.ts +121 -0
- package/packages/core/src/kernel/dispatch-status.ts +4 -2
- package/packages/core/src/kernel/dispatch-upgrade.ts +171 -0
- package/packages/core/src/kernel/dispatcher-liveness.ts +7 -0
- package/packages/core/src/kernel/generators/repository-journals.ts +82 -0
- package/packages/core/src/kernel/guarded-forge.ts +1 -1
- package/packages/core/src/kernel/harvest.ts +98 -4
- package/packages/core/src/kernel/integration-attention.ts +20 -0
- package/packages/core/src/kernel/integration-completeness.ts +54 -16
- package/packages/core/src/kernel/integration-state.ts +80 -11
- package/packages/core/src/kernel/landing-readiness.ts +6 -1
- package/packages/core/src/kernel/mixed-version.ts +34 -0
- package/packages/core/src/kernel/node-parent.ts +35 -10
- package/packages/core/src/kernel/node-polling.ts +160 -0
- package/packages/core/src/kernel/read-facts.ts +47 -5
- package/packages/core/src/kernel/reducer-registry.ts +6 -0
- package/packages/core/src/kernel/reducer.ts +75 -14
- package/packages/core/src/kernel/service-facts.ts +11 -4
- package/packages/core/src/kernel/ticket-migrations.ts +139 -0
- package/packages/core/src/operator/presentation.ts +7 -0
- package/packages/core/src/operator/query.ts +13 -3
- package/packages/core/src/operator/registry.ts +1 -1
- package/packages/core/src/operator/tickets.ts +30 -26
- package/packages/core/src/plugins/load.ts +4 -1
- package/packages/core/src/plugins/runtime-snapshot.ts +128 -0
- package/packages/core/src/ports/forge/contract.ts +29 -0
- package/packages/core/src/ports/forge/github.ts +189 -61
- package/packages/core/src/ports/forge-failure.ts +1 -0
- package/packages/core/src/ports/forge-telemetry.ts +3 -0
- package/packages/core/src/ports/runner/session-env.ts +1 -0
- 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 +17 -0
- package/packages/core/src/ports/workspace/distribution-archive.ts +22 -149
- package/packages/core/src/ports/workspace/distribution-release.ts +56 -0
- package/packages/core/src/ports/workspace/git-worktree.ts +2 -1
- package/packages/core/src/ports/workspace/local-build-execution.ts +37 -17
- package/packages/core/src/processes/build-child-exit.ts +5 -26
- package/packages/core/src/processes/build-runner.ts +81 -11
- package/packages/core/src/processes/dispatcher.ts +418 -59
- package/packages/core/src/processes/execution-no-progress.ts +6 -0
- package/packages/core/src/processes/execution-relaunch.ts +30 -0
- package/packages/core/src/processes/execution-settlement.ts +16 -7
- package/packages/core/src/processes/harvest-runner.ts +328 -292
- package/packages/core/src/processes/process-group-reaper.ts +17 -10
- package/packages/core/src/runtime-identity.ts +22 -3
- package/packages/core/src/store/contract.ts +183 -0
- package/packages/core/src/store/local/store.ts +197 -72
- package/packages/core/src/store/reduced-reads.ts +8 -0
- package/packages/core/src/store/reducer-value-shapes.json +8915 -6344
- package/packages/core/src/store/remote/client.ts +43 -0
- package/packages/core/src/store/repo-state-events.ts +21 -3
- package/packages/core/src/store/types.ts +7 -0
- package/packages/core/src/testing/dispatch-read-budget.ts +3 -2
- package/skills/guide/SKILL.md +234 -24
- package/skills/guide/references/integration-tree.md +91 -4
- package/skills/guide/references/operator-api.md +53 -4
- package/skills/guide/references/plugin-authoring.md +45 -4
- package/skills/guide/references/remote-store-protocol.md +9 -1
- package/skills/guide/references/remote-ticket-protocol.md +5 -0
- package/skills/guide/references/restacking.md +4 -1
- package/skills/guide/references/setup.md +24 -0
- package/skills/guide/references/spec-standard.md +94 -5
- package/skills/guide/references/ticket-migration.md +50 -4
- package/skills/harvest/SKILL.md +4 -0
- package/skills/harvest-review/SKILL.md +4 -0
- package/skills/operate/SKILL.md +78 -8
- package/skills/spec/SKILL.md +35 -5
- package/skills/tickets/SKILL.md +19 -0
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
nodeActivityKey,
|
|
3
|
+
nodePollingSchedule,
|
|
4
|
+
nodePollingUnsettled,
|
|
5
|
+
nodeTicketObservationKey,
|
|
6
|
+
} from '../kernel/node-polling'
|
|
7
|
+
import { reportIntegrationFailures } from '../kernel/integration-attention'
|
|
8
|
+
import {
|
|
9
|
+
resolveTicketRef,
|
|
10
|
+
migrationIdentity,
|
|
11
|
+
historicalTicketIdentity,
|
|
12
|
+
} from '../kernel/ticket-migrations'
|
|
1
13
|
import { nodeRestackDemand, presenceRestackPath } from '../kernel/node-restack-demand'
|
|
2
14
|
import {
|
|
3
15
|
deferMixedVersion,
|
|
@@ -685,7 +697,6 @@ export class Dispatcher {
|
|
|
685
697
|
// and each admitted verification/publication samples the source this pass.
|
|
686
698
|
private integrationInputs?: Promise<IntegrationObservationInputs>
|
|
687
699
|
private integrationPublicationInputs?: Promise<IntegrationObservationInputs>
|
|
688
|
-
private readonly integrationTargets = new Map<string, string | undefined>()
|
|
689
700
|
private readonly integrationPolls = new Map<string, { key: string; at: number }>()
|
|
690
701
|
private readonly integrationLandingPolls = new Map<string, { key: string; at: number }>()
|
|
691
702
|
private integrationPollDue(
|
|
@@ -699,22 +710,61 @@ export class Dispatcher {
|
|
|
699
710
|
polls.set(slug, { key, at: now })
|
|
700
711
|
return true
|
|
701
712
|
}
|
|
702
|
-
|
|
703
|
-
|
|
713
|
+
// Work targets are frozen; settled activity is refreshed only when its
|
|
714
|
+
// compact readiness digest changes. Neither cache decides eligibility.
|
|
715
|
+
private readonly nodePollingBuilds = new Map<
|
|
716
|
+
string,
|
|
717
|
+
{
|
|
718
|
+
target?: string
|
|
719
|
+
activity: Pick<BuildState, 'pollingActivity'>
|
|
720
|
+
settledKey?: string
|
|
721
|
+
}
|
|
722
|
+
>()
|
|
723
|
+
private readonly nodePollingTickReads = new Map<string, Promise<BuildState>>()
|
|
724
|
+
|
|
725
|
+
private async integrationClaimKey(slug: string, state: BuildState): Promise<string> {
|
|
726
|
+
return nodeTicketObservationKey(state, await this.nodePollingChildren(slug))
|
|
727
|
+
}
|
|
728
|
+
private async nodePollingChildren(slug: string, refresh = false) {
|
|
729
|
+
const children: { slug: string; state: Pick<BuildState, 'pollingActivity'> }[] = []
|
|
704
730
|
for (const { record, digest } of await this.repoBuildDigests()) {
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
731
|
+
if (record.slug === slug) continue
|
|
732
|
+
const known = this.nodePollingBuilds.get(record.slug)
|
|
733
|
+
// Only node relationships can move. Unrelated known work never needs
|
|
734
|
+
// another full-facts read, even while it is running.
|
|
735
|
+
if (digest.kind !== 'node' && known && known.target !== slug) continue
|
|
736
|
+
const settledKey =
|
|
737
|
+
digest.terminal && !digest.executionOpen
|
|
738
|
+
? JSON.stringify([
|
|
739
|
+
digest.terminal,
|
|
740
|
+
digest.readinessChangeSeq,
|
|
741
|
+
digest.merged,
|
|
742
|
+
digest.prClosed,
|
|
743
|
+
])
|
|
744
|
+
: undefined
|
|
745
|
+
let current = known
|
|
746
|
+
if (!current || settledKey === undefined || current.settledKey !== settledKey) {
|
|
747
|
+
let read =
|
|
748
|
+
refresh || (known && known.settledKey !== settledKey)
|
|
749
|
+
? undefined
|
|
750
|
+
: this.nodePollingTickReads.get(record.slug)
|
|
751
|
+
if (!read) {
|
|
752
|
+
read = this.store.buildFacts(record.slug).then((facts) => facts.state)
|
|
753
|
+
this.nodePollingTickReads.set(record.slug, read)
|
|
754
|
+
}
|
|
755
|
+
const state = await read
|
|
756
|
+
current = {
|
|
757
|
+
target: state.target?.build,
|
|
758
|
+
activity: { pollingActivity: state.pollingActivity },
|
|
759
|
+
settledKey,
|
|
760
|
+
}
|
|
761
|
+
if (state.lastSeq > 0) this.nodePollingBuilds.set(record.slug, current)
|
|
710
762
|
}
|
|
711
|
-
if (
|
|
712
|
-
children.push(
|
|
713
|
-
`${record.slug}:${digest.terminal ?? ''}:${digest.merged ?? ''}:${digest.prClosed ?? ''}`,
|
|
714
|
-
)
|
|
763
|
+
if (current.target === slug) children.push({ slug: record.slug, state: current.activity })
|
|
715
764
|
}
|
|
716
|
-
return children
|
|
765
|
+
return children
|
|
717
766
|
}
|
|
767
|
+
|
|
718
768
|
private observeIntegration(slug: string, publication = false) {
|
|
719
769
|
return observeIntegration(this.store, this.deps.tickets, slug, () => {
|
|
720
770
|
if (publication) {
|
|
@@ -855,14 +905,21 @@ export class Dispatcher {
|
|
|
855
905
|
const builds = new Map<string, number>()
|
|
856
906
|
let total = 0
|
|
857
907
|
let unattributed = 0
|
|
908
|
+
const categories = { restPrimary: 0, restNotModified: 0, graphql: 0 }
|
|
909
|
+
let classified = this.deps.forge.name === 'github'
|
|
858
910
|
const stop = this.deps.forge.observeRequests?.((request) => {
|
|
859
911
|
const build = request.build ?? forgeRequestContext().build
|
|
860
912
|
total++
|
|
913
|
+
if (request.outcome) {
|
|
914
|
+
categories[request.outcome]++
|
|
915
|
+
classified = true
|
|
916
|
+
}
|
|
861
917
|
if (build) builds.set(build, (builds.get(build) ?? 0) + 1)
|
|
862
918
|
else unattributed++
|
|
863
919
|
})
|
|
864
920
|
const counts = () => ({
|
|
865
921
|
total,
|
|
922
|
+
...(classified ? categories : {}),
|
|
866
923
|
unattributed,
|
|
867
924
|
builds: [...builds]
|
|
868
925
|
.map(([build, requests]) => ({ build, requests }))
|
|
@@ -872,7 +929,9 @@ export class Dispatcher {
|
|
|
872
929
|
})
|
|
873
930
|
this.lastForgeRequests = undefined
|
|
874
931
|
try {
|
|
875
|
-
const report = await this.
|
|
932
|
+
const report = await (this.deps.forge.withReadScope
|
|
933
|
+
? this.deps.forge.withReadScope(() => this.runTick(opts))
|
|
934
|
+
: this.runTick(opts))
|
|
876
935
|
if (stop || this.deps.config.forge === 'local-git') report.forgeRequests = counts()
|
|
877
936
|
return report
|
|
878
937
|
} finally {
|
|
@@ -884,6 +943,7 @@ export class Dispatcher {
|
|
|
884
943
|
private async runTick(opts: TickOpts): Promise<TickReport> {
|
|
885
944
|
this.integrationInputs = undefined
|
|
886
945
|
this.integrationPublicationInputs = undefined
|
|
946
|
+
this.nodePollingTickReads.clear()
|
|
887
947
|
// One immutable config for this complete decision pass. A reload racing the
|
|
888
948
|
// tick is observed by the next tick, never half-way through this one.
|
|
889
949
|
this.deps.config = this.deps.getConfig?.() ?? this.deps.config
|
|
@@ -1131,14 +1191,43 @@ export class Dispatcher {
|
|
|
1131
1191
|
}
|
|
1132
1192
|
}
|
|
1133
1193
|
|
|
1194
|
+
private async currentTicketId(record: BuildRecord): Promise<string> {
|
|
1195
|
+
if (!record.ticket) throw new Error(`build ${record.slug} has no ticket`)
|
|
1196
|
+
return resolveTicketRef(
|
|
1197
|
+
this.store.repositoryFacts().ticketMigrations,
|
|
1198
|
+
record.ticket,
|
|
1199
|
+
this.deps.tickets.name,
|
|
1200
|
+
record.slug,
|
|
1201
|
+
).id
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1134
1204
|
private async activeTicketIdentities(refs: TicketRef[], listed: Ticket[]): Promise<Set<string>> {
|
|
1135
1205
|
const key = (ref: TicketRef) => `${ref.source}:${ref.id}`
|
|
1136
|
-
const
|
|
1206
|
+
const migrations = this.store.repositoryFacts().ticketMigrations
|
|
1207
|
+
const records = await this.repoBuildDigests()
|
|
1208
|
+
const normalized = refs.map((ref) => {
|
|
1209
|
+
try {
|
|
1210
|
+
return resolveTicketRef(
|
|
1211
|
+
migrations,
|
|
1212
|
+
ref,
|
|
1213
|
+
this.deps.tickets.name,
|
|
1214
|
+
records.find(
|
|
1215
|
+
({ record }) => record.ticket?.source === ref.source && record.ticket.id === ref.id,
|
|
1216
|
+
)?.record.slug,
|
|
1217
|
+
)
|
|
1218
|
+
} catch (error) {
|
|
1219
|
+
// An unrelated source remains excluded only in its original namespace.
|
|
1220
|
+
// A recorded cutover that omits a live claim must block admission.
|
|
1221
|
+
if (migrations.migrations.some((m) => m.from === ref.source && m.from !== m.to)) throw error
|
|
1222
|
+
return ref
|
|
1223
|
+
}
|
|
1224
|
+
})
|
|
1225
|
+
const ids = new Set(normalized.map(key))
|
|
1137
1226
|
if (this.deps.tickets.name !== 'hosted' || listed.length === 0) return ids
|
|
1138
1227
|
const listedIds = new Set(listed.map((ticket) => key(ticket.ref)))
|
|
1139
1228
|
const identity = ticketIdentity(this.deps.tickets)
|
|
1140
1229
|
try {
|
|
1141
|
-
for (const ref of
|
|
1230
|
+
for (const ref of normalized) {
|
|
1142
1231
|
if (ref.source === 'hosted' && !listedIds.has(key(ref))) ids.add(await identity(ref))
|
|
1143
1232
|
}
|
|
1144
1233
|
} catch (error) {
|
|
@@ -1872,6 +1961,18 @@ export class Dispatcher {
|
|
|
1872
1961
|
const entries = (await this.repoBuildDigests()).filter(
|
|
1873
1962
|
({ digest }) => isWorkDigest(digest) || digest.integrationAuditPending === true,
|
|
1874
1963
|
)
|
|
1964
|
+
// Receipt reporting requires no forge call, capacity or workspace. Recover
|
|
1965
|
+
// every episode before the transport-budget and janitor-backoff gates.
|
|
1966
|
+
for (const { record, digest } of entries) {
|
|
1967
|
+
if (digest.kind !== 'node' || !digest.nodeOpened || digest.terminal) continue
|
|
1968
|
+
try {
|
|
1969
|
+
await reportIntegrationFailures(this.store, record.slug)
|
|
1970
|
+
} catch (error) {
|
|
1971
|
+
report.janitorDiagnostics.push(
|
|
1972
|
+
`build ${record.slug}: integration attention recovery failed — ${String(error)}`,
|
|
1973
|
+
)
|
|
1974
|
+
}
|
|
1975
|
+
}
|
|
1875
1976
|
for (const { record, digest } of entries) {
|
|
1876
1977
|
// Budget gate: the janitor's per-build path issues forge/store transport
|
|
1877
1978
|
// calls (PR probes, closePr, deleteBranch); once the budget is spent,
|
|
@@ -1886,12 +1987,15 @@ export class Dispatcher {
|
|
|
1886
1987
|
// Once a record is known, contain its complete janitor path: loading
|
|
1887
1988
|
// and reducing facts, cleanup, forge/ticket calls, and store writes.
|
|
1888
1989
|
// Existing partial facts leave the same work due on the next tick.
|
|
1889
|
-
|
|
1990
|
+
const initialFacts = await this.store.buildFacts(record.slug)
|
|
1991
|
+
let { state, workspace, log } = initialFacts
|
|
1890
1992
|
previous = state.janitor
|
|
1891
1993
|
const controlDue =
|
|
1892
1994
|
state.pendingCommands.length > 0 ||
|
|
1893
1995
|
state.discardRequest !== undefined ||
|
|
1894
|
-
(state.
|
|
1996
|
+
(state.pr &&
|
|
1997
|
+
state.landing?.command &&
|
|
1998
|
+
state.landing.command.seq !== state.landing.acknowledgedSeq)
|
|
1895
1999
|
if (
|
|
1896
2000
|
!controlDue &&
|
|
1897
2001
|
previous &&
|
|
@@ -1911,6 +2015,80 @@ export class Dispatcher {
|
|
|
1911
2015
|
loaded ??= (await readBuildFacts(this.store, record.slug)).value
|
|
1912
2016
|
return loaded
|
|
1913
2017
|
}
|
|
2018
|
+
const pollStart = state
|
|
2019
|
+
const pollChildren =
|
|
2020
|
+
state.kind === 'node' ? await this.nodePollingChildren(record.slug) : []
|
|
2021
|
+
const pollKey = nodeActivityKey(state, pollChildren)
|
|
2022
|
+
const pollSchedule =
|
|
2023
|
+
state.kind === 'node' && !nodePollingUnsettled(state)
|
|
2024
|
+
? nodePollingSchedule(
|
|
2025
|
+
state,
|
|
2026
|
+
pollKey,
|
|
2027
|
+
this.deps.config.policy,
|
|
2028
|
+
this.deps.clock(),
|
|
2029
|
+
executionLeaseLive ||
|
|
2030
|
+
initialFacts.open !== null ||
|
|
2031
|
+
initialFacts.publication.pending() ||
|
|
2032
|
+
initialFacts.publication.abandonedPending() ||
|
|
2033
|
+
undefined,
|
|
2034
|
+
)
|
|
2035
|
+
: undefined
|
|
2036
|
+
if (state.kind === 'node' && !controlDue && pollSchedule && !pollSchedule.due) {
|
|
2037
|
+
attempted = false
|
|
2038
|
+
return
|
|
2039
|
+
}
|
|
2040
|
+
let incompleteObservation = false
|
|
2041
|
+
const diagnosticsBefore = report.janitorDiagnostics.length
|
|
2042
|
+
const completeNodePoll = async () => {
|
|
2043
|
+
if (
|
|
2044
|
+
pollStart.kind !== 'node' ||
|
|
2045
|
+
!pollStart.nodeOpened ||
|
|
2046
|
+
incompleteObservation ||
|
|
2047
|
+
executionLeaseLive ||
|
|
2048
|
+
report.janitorDiagnostics.length !== diagnosticsBefore ||
|
|
2049
|
+
this.outOfBudget(opts)
|
|
2050
|
+
)
|
|
2051
|
+
return
|
|
2052
|
+
const current = (await this.store.buildFacts(record.slug)).state
|
|
2053
|
+
if (nodePollingUnsettled(current) && current.status !== 'done') return
|
|
2054
|
+
const children = await this.nodePollingChildren(record.slug, true)
|
|
2055
|
+
const key = nodeActivityKey(current, children)
|
|
2056
|
+
// A command or child event arriving during observation stays due.
|
|
2057
|
+
const commandTypes = [
|
|
2058
|
+
'build.land-requested',
|
|
2059
|
+
'build.hold-requested',
|
|
2060
|
+
'node.restack-requested',
|
|
2061
|
+
'escalation.answered',
|
|
2062
|
+
'node.parent-requested',
|
|
2063
|
+
]
|
|
2064
|
+
if (
|
|
2065
|
+
commandTypes.some(
|
|
2066
|
+
(type) => current.pollingActivity?.[type] !== pollStart.pollingActivity?.[type],
|
|
2067
|
+
) ||
|
|
2068
|
+
nodeActivityKey(pollStart, children) !== pollKey
|
|
2069
|
+
)
|
|
2070
|
+
return
|
|
2071
|
+
const now = this.deps.clock().toISOString()
|
|
2072
|
+
const previousCheck = pollStart.nodePolling
|
|
2073
|
+
await this.store.appendIfCurrent(record.slug, current.lastSeq, {
|
|
2074
|
+
actor: DISPATCHER,
|
|
2075
|
+
type: 'node.poll-checked',
|
|
2076
|
+
payload: {
|
|
2077
|
+
activityKey: key,
|
|
2078
|
+
unchangedSince:
|
|
2079
|
+
previousCheck?.activityKey === key &&
|
|
2080
|
+
previousCheck.nodeIdleAfterSeconds ===
|
|
2081
|
+
this.deps.config.policy.nodeIdleAfterSeconds &&
|
|
2082
|
+
previousCheck.nodeIdlePollSeconds ===
|
|
2083
|
+
this.deps.config.policy.nodeIdlePollSeconds &&
|
|
2084
|
+
Date.parse(previousCheck.unchangedSince) <= Date.parse(now)
|
|
2085
|
+
? previousCheck.unchangedSince
|
|
2086
|
+
: now,
|
|
2087
|
+
nodeIdleAfterSeconds: this.deps.config.policy.nodeIdleAfterSeconds,
|
|
2088
|
+
nodeIdlePollSeconds: this.deps.config.policy.nodeIdlePollSeconds,
|
|
2089
|
+
},
|
|
2090
|
+
})
|
|
2091
|
+
}
|
|
1914
2092
|
let observedPr: Awaited<ReturnType<Forge['getPrState']>> | undefined
|
|
1915
2093
|
// A replacement head is followed first by a forge read and cancellation,
|
|
1916
2094
|
// ahead of node cascade, controls, or any other action for this build.
|
|
@@ -1927,7 +2105,13 @@ export class Dispatcher {
|
|
|
1927
2105
|
if (observed.state !== 'open') {
|
|
1928
2106
|
await this.checkPr(
|
|
1929
2107
|
record,
|
|
1930
|
-
{
|
|
2108
|
+
{
|
|
2109
|
+
history,
|
|
2110
|
+
workspace,
|
|
2111
|
+
observed: (pr) => {
|
|
2112
|
+
incompleteObservation ||= pr.state === 'open' && pr.mergeable === null
|
|
2113
|
+
},
|
|
2114
|
+
},
|
|
1931
2115
|
state,
|
|
1932
2116
|
report,
|
|
1933
2117
|
launched,
|
|
@@ -1989,9 +2173,48 @@ export class Dispatcher {
|
|
|
1989
2173
|
return
|
|
1990
2174
|
}
|
|
1991
2175
|
if (state.nodeOpened) {
|
|
2176
|
+
let primed = false
|
|
2177
|
+
if (
|
|
2178
|
+
record.branch &&
|
|
2179
|
+
state.baseBranch &&
|
|
2180
|
+
!((state.status === 'paused' || state.status === 'blocked') && !state.pr)
|
|
2181
|
+
) {
|
|
2182
|
+
primed = await this.primeNodeReads(record, state, report)
|
|
2183
|
+
}
|
|
2184
|
+
if (
|
|
2185
|
+
primed &&
|
|
2186
|
+
state.pr &&
|
|
2187
|
+
(
|
|
2188
|
+
await this.deps.forge.getPrState(
|
|
2189
|
+
this.deps.checkout ?? this.deps.repo,
|
|
2190
|
+
state.pr.number,
|
|
2191
|
+
)
|
|
2192
|
+
).state !== 'open'
|
|
2193
|
+
) {
|
|
2194
|
+
await this.checkPr(
|
|
2195
|
+
record,
|
|
2196
|
+
{
|
|
2197
|
+
history,
|
|
2198
|
+
workspace,
|
|
2199
|
+
observed: (pr) => {
|
|
2200
|
+
incompleteObservation ||= pr.state === 'open' && pr.mergeable === null
|
|
2201
|
+
},
|
|
2202
|
+
},
|
|
2203
|
+
state,
|
|
2204
|
+
report,
|
|
2205
|
+
launched,
|
|
2206
|
+
executionLeaseLive,
|
|
2207
|
+
)
|
|
2208
|
+
await completeNodePoll()
|
|
2209
|
+
return
|
|
2210
|
+
}
|
|
2211
|
+
const previousParent = state.baseBranch
|
|
1992
2212
|
await this.observeTicketTarget(record, state, report)
|
|
1993
2213
|
loaded = undefined
|
|
1994
2214
|
;({ state, workspace, log } = await this.store.buildFacts(record.slug))
|
|
2215
|
+
if (record.branch && state.baseBranch && previousParent !== state.baseBranch) {
|
|
2216
|
+
await this.primeNodeReads(record, state, report)
|
|
2217
|
+
}
|
|
1995
2218
|
}
|
|
1996
2219
|
if ((state.status === 'paused' || state.status === 'blocked') && !state.pr) return
|
|
1997
2220
|
if (state.nodeOpened && state.baseBranch) {
|
|
@@ -2028,6 +2251,7 @@ export class Dispatcher {
|
|
|
2028
2251
|
}
|
|
2029
2252
|
if (state.nodeOpened !== undefined && state.pr === undefined) {
|
|
2030
2253
|
await this.pollEmptyNode(record, state)
|
|
2254
|
+
await completeNodePoll()
|
|
2031
2255
|
return
|
|
2032
2256
|
}
|
|
2033
2257
|
}
|
|
@@ -2078,7 +2302,13 @@ export class Dispatcher {
|
|
|
2078
2302
|
if (state.pr) {
|
|
2079
2303
|
await this.checkPr(
|
|
2080
2304
|
record,
|
|
2081
|
-
{
|
|
2305
|
+
{
|
|
2306
|
+
history,
|
|
2307
|
+
workspace,
|
|
2308
|
+
observed: (pr) => {
|
|
2309
|
+
incompleteObservation ||= pr.state === 'open' && pr.mergeable === null
|
|
2310
|
+
},
|
|
2311
|
+
},
|
|
2082
2312
|
state,
|
|
2083
2313
|
report,
|
|
2084
2314
|
launched,
|
|
@@ -2086,6 +2316,7 @@ export class Dispatcher {
|
|
|
2086
2316
|
observedPr,
|
|
2087
2317
|
)
|
|
2088
2318
|
}
|
|
2319
|
+
await completeNodePoll()
|
|
2089
2320
|
} catch (error) {
|
|
2090
2321
|
if (error instanceof ForgeCooldown) {
|
|
2091
2322
|
attempted = false
|
|
@@ -2120,6 +2351,34 @@ export class Dispatcher {
|
|
|
2120
2351
|
}
|
|
2121
2352
|
}
|
|
2122
2353
|
|
|
2354
|
+
/** Priming saves requests but must not block parent recovery or ordinary observations. */
|
|
2355
|
+
private async primeNodeReads(
|
|
2356
|
+
record: BuildRecord,
|
|
2357
|
+
state: BuildState,
|
|
2358
|
+
report: TickReport,
|
|
2359
|
+
): Promise<boolean> {
|
|
2360
|
+
if (!this.deps.forge.primeNodeReads || !record.branch || !state.baseBranch) return false
|
|
2361
|
+
try {
|
|
2362
|
+
await this.deps.forge.primeNodeReads({
|
|
2363
|
+
workspacePath: this.deps.checkout ?? this.deps.repo,
|
|
2364
|
+
parent: state.baseBranch,
|
|
2365
|
+
head: record.branch,
|
|
2366
|
+
...(state.pr ? { prNumber: state.pr.number } : {}),
|
|
2367
|
+
})
|
|
2368
|
+
return true
|
|
2369
|
+
} catch (error) {
|
|
2370
|
+
if (
|
|
2371
|
+
error instanceof ForgeRequestDeferred ||
|
|
2372
|
+
(isForgeFailure(error) && error.details.kind === 'rate-limited')
|
|
2373
|
+
)
|
|
2374
|
+
throw error
|
|
2375
|
+
report.janitorDiagnostics.push(
|
|
2376
|
+
`build ${record.slug}: node read priming failed — ${error instanceof Error || isForgeFailure(error) ? error.message : String(error)}`,
|
|
2377
|
+
)
|
|
2378
|
+
return false
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
2381
|
+
|
|
2123
2382
|
private parentContext(): ParentContext {
|
|
2124
2383
|
return {
|
|
2125
2384
|
store: this.store,
|
|
@@ -2173,15 +2432,22 @@ export class Dispatcher {
|
|
|
2173
2432
|
}
|
|
2174
2433
|
|
|
2175
2434
|
private async observeWorkTarget(record: BuildRecord, state: BuildState, report: TickReport) {
|
|
2176
|
-
if (!record.ticket
|
|
2177
|
-
const ticket = await this.deps.tickets.get(record
|
|
2435
|
+
if (!record.ticket) return
|
|
2436
|
+
const ticket = await this.deps.tickets.get(await this.currentTicketId(record))
|
|
2178
2437
|
if (!ticket) {
|
|
2179
2438
|
report.janitorDiagnostics.push(
|
|
2180
2439
|
`build ${record.slug}: claimed ticket cannot be read; frozen work target retained`,
|
|
2181
2440
|
)
|
|
2182
2441
|
return
|
|
2183
2442
|
}
|
|
2184
|
-
const effective = state.target
|
|
2443
|
+
const effective = state.target
|
|
2444
|
+
? resolveTicketRef(
|
|
2445
|
+
this.store.repositoryFacts().ticketMigrations,
|
|
2446
|
+
state.target.ticket,
|
|
2447
|
+
this.deps.tickets.name,
|
|
2448
|
+
record.slug,
|
|
2449
|
+
).id
|
|
2450
|
+
: undefined
|
|
2185
2451
|
const canonical =
|
|
2186
2452
|
effective && this.deps.config.tickets.source === 'hosted'
|
|
2187
2453
|
? ((await this.deps.tickets.get(effective))?.ref.id ?? effective)
|
|
@@ -2199,7 +2465,7 @@ export class Dispatcher {
|
|
|
2199
2465
|
/** Provider edits and interrupted caller writes converge through this same
|
|
2200
2466
|
* durable path, independently of ticket readiness or caller liveness. */
|
|
2201
2467
|
private async observeNodeParent(record: BuildRecord, state: BuildState, report: TickReport) {
|
|
2202
|
-
if (!record.ticket
|
|
2468
|
+
if (!record.ticket) return
|
|
2203
2469
|
if (nodeParentBusy(state)) return
|
|
2204
2470
|
if (
|
|
2205
2471
|
state.pr &&
|
|
@@ -2243,11 +2509,18 @@ export class Dispatcher {
|
|
|
2243
2509
|
this.integrationPublicationInputs = undefined
|
|
2244
2510
|
return
|
|
2245
2511
|
}
|
|
2246
|
-
const ticket = await this.deps.tickets.get(record
|
|
2512
|
+
const ticket = await this.deps.tickets.get(await this.currentTicketId(record))
|
|
2247
2513
|
if (!ticket) throw new Error('node ticket cannot be read; parent observation failed closed')
|
|
2248
2514
|
const desired = ticket.target ?? null
|
|
2249
2515
|
const request = node?.parentRequest
|
|
2250
|
-
const effective = state.target
|
|
2516
|
+
const effective = state.target
|
|
2517
|
+
? resolveTicketRef(
|
|
2518
|
+
this.store.repositoryFacts().ticketMigrations,
|
|
2519
|
+
state.target.ticket,
|
|
2520
|
+
this.deps.tickets.name,
|
|
2521
|
+
record.slug,
|
|
2522
|
+
).id
|
|
2523
|
+
: undefined
|
|
2251
2524
|
const canonical =
|
|
2252
2525
|
effective && this.deps.config.tickets.source === 'hosted'
|
|
2253
2526
|
? ((await this.deps.tickets.get(effective))?.ref.id ?? effective)
|
|
@@ -2269,7 +2542,18 @@ export class Dispatcher {
|
|
|
2269
2542
|
state.nodeRestack?.parentRequest?.id !== request?.id
|
|
2270
2543
|
)
|
|
2271
2544
|
return
|
|
2272
|
-
if (
|
|
2545
|
+
if (
|
|
2546
|
+
request &&
|
|
2547
|
+
desired !==
|
|
2548
|
+
(request.next.target
|
|
2549
|
+
? resolveTicketRef(
|
|
2550
|
+
this.store.repositoryFacts().ticketMigrations,
|
|
2551
|
+
request.next.target.ticket,
|
|
2552
|
+
this.deps.tickets.name,
|
|
2553
|
+
record.slug,
|
|
2554
|
+
).id
|
|
2555
|
+
: null)
|
|
2556
|
+
) {
|
|
2273
2557
|
await this.store.appendIfCurrent(record.slug, state.lastSeq, {
|
|
2274
2558
|
actor: DISPATCHER,
|
|
2275
2559
|
type: 'node.parent-cancelled',
|
|
@@ -2381,7 +2665,14 @@ export class Dispatcher {
|
|
|
2381
2665
|
|
|
2382
2666
|
private async nodeHasCapacity(slug: string): Promise<boolean> {
|
|
2383
2667
|
const builds = await this.capacityBuilds()
|
|
2384
|
-
return
|
|
2668
|
+
return (
|
|
2669
|
+
nodeCapacity(
|
|
2670
|
+
builds,
|
|
2671
|
+
slug,
|
|
2672
|
+
this.deps.clock(),
|
|
2673
|
+
migrationIdentity(this.store.repositoryFacts().ticketMigrations, this.deps.tickets.name),
|
|
2674
|
+
).occupied < this.deps.config.capacity
|
|
2675
|
+
)
|
|
2385
2676
|
}
|
|
2386
2677
|
|
|
2387
2678
|
private hasLiveExecutionLease(record: BuildRecord): boolean {
|
|
@@ -2583,13 +2874,19 @@ export class Dispatcher {
|
|
|
2583
2874
|
if (record.ticket !== undefined && !has('abort.ticket-returned')) {
|
|
2584
2875
|
const label = 'autobuild:aborted'
|
|
2585
2876
|
try {
|
|
2586
|
-
const current = await tickets.get(record
|
|
2877
|
+
const current = await tickets.get(await this.currentTicketId(record))
|
|
2587
2878
|
if (current === null) throw new Error(`ticket no longer exists in ${tickets.name}`)
|
|
2588
2879
|
if (!current.labels.includes(label)) {
|
|
2589
|
-
await tickets.update(record
|
|
2880
|
+
await tickets.update(await this.currentTicketId(record), {
|
|
2881
|
+
labels: [...current.labels, label],
|
|
2882
|
+
})
|
|
2590
2883
|
}
|
|
2591
2884
|
const triageState = this.triageState()
|
|
2592
|
-
await tickets.transition(record
|
|
2885
|
+
await tickets.transition(await this.currentTicketId(record), triageState)
|
|
2886
|
+
await tickets.comment(
|
|
2887
|
+
await this.currentTicketId(record),
|
|
2888
|
+
`build ${record.slug} aborted — returned to ${triageState}`,
|
|
2889
|
+
)
|
|
2593
2890
|
await append({
|
|
2594
2891
|
actor: DISPATCHER,
|
|
2595
2892
|
type: 'abort.ticket-returned',
|
|
@@ -2597,6 +2894,7 @@ export class Dispatcher {
|
|
|
2597
2894
|
})
|
|
2598
2895
|
} catch (error) {
|
|
2599
2896
|
fail('ticket handback', `${tickets.name} ticket ${record.ticket.id}`, error)
|
|
2897
|
+
return
|
|
2600
2898
|
}
|
|
2601
2899
|
}
|
|
2602
2900
|
|
|
@@ -2624,9 +2922,12 @@ export class Dispatcher {
|
|
|
2624
2922
|
await store.releaseLease(record.slug, record.lease.holder)
|
|
2625
2923
|
}
|
|
2626
2924
|
if (record.ticket !== undefined) {
|
|
2627
|
-
await tickets.transition(
|
|
2925
|
+
await tickets.transition(
|
|
2926
|
+
await this.currentTicketId(record),
|
|
2927
|
+
this.deps.config.tickets.readyState,
|
|
2928
|
+
)
|
|
2628
2929
|
await tickets.comment(
|
|
2629
|
-
record
|
|
2930
|
+
await this.currentTicketId(record),
|
|
2630
2931
|
`build ${record.slug} was discarded during dispatch — returned to ${this.deps.config.tickets.readyState}`,
|
|
2631
2932
|
)
|
|
2632
2933
|
}
|
|
@@ -2673,7 +2974,11 @@ export class Dispatcher {
|
|
|
2673
2974
|
record: BuildRecord,
|
|
2674
2975
|
// `workspace` is the open workspace fact; `history` loads the raw log, which
|
|
2675
2976
|
// only the branches that act on a PR transition need.
|
|
2676
|
-
source: {
|
|
2977
|
+
source: {
|
|
2978
|
+
history: () => Promise<CurrentBuildFacts>
|
|
2979
|
+
workspace: OpenBuildWorkspace | null
|
|
2980
|
+
observed?: (pr: Awaited<ReturnType<Forge['getPrState']>>) => void
|
|
2981
|
+
},
|
|
2677
2982
|
state: BuildState,
|
|
2678
2983
|
report: TickReport,
|
|
2679
2984
|
launched: Set<string>,
|
|
@@ -2703,6 +3008,7 @@ export class Dispatcher {
|
|
|
2703
3008
|
if (!recoverLanding && state.prState !== 'merged') throw error
|
|
2704
3009
|
prState = { state: 'open', mergeable: null }
|
|
2705
3010
|
}
|
|
3011
|
+
source.observed?.(prState)
|
|
2706
3012
|
if (state.prState === 'merged' && state.mergedSha)
|
|
2707
3013
|
prState = { state: 'merged', sha: state.mergedSha }
|
|
2708
3014
|
let nativeCancelled = false
|
|
@@ -2785,7 +3091,7 @@ export class Dispatcher {
|
|
|
2785
3091
|
break
|
|
2786
3092
|
}
|
|
2787
3093
|
if (!record.ticket) throw new Error('Landing policy requires a readable source ticket')
|
|
2788
|
-
const ticket = await tickets.get(record
|
|
3094
|
+
const ticket = await tickets.get(await this.currentTicketId(record))
|
|
2789
3095
|
if (!ticket)
|
|
2790
3096
|
throw new Error(
|
|
2791
3097
|
`Landing policy source ticket ${record.ticket.id} is unavailable; retrying on next poll`,
|
|
@@ -2793,7 +3099,15 @@ export class Dispatcher {
|
|
|
2793
3099
|
const input = {
|
|
2794
3100
|
from: integration ? ('node' as const) : ('leaf' as const),
|
|
2795
3101
|
into: current.target
|
|
2796
|
-
? {
|
|
3102
|
+
? {
|
|
3103
|
+
kind: 'node' as const,
|
|
3104
|
+
ticket: resolveTicketRef(
|
|
3105
|
+
this.store.repositoryFacts().ticketMigrations,
|
|
3106
|
+
current.target.ticket,
|
|
3107
|
+
this.deps.tickets.name,
|
|
3108
|
+
record.slug,
|
|
3109
|
+
).id,
|
|
3110
|
+
}
|
|
2797
3111
|
: { kind: 'root' as const },
|
|
2798
3112
|
labels: ticket.labels,
|
|
2799
3113
|
}
|
|
@@ -3225,6 +3539,7 @@ export class Dispatcher {
|
|
|
3225
3539
|
}),
|
|
3226
3540
|
)
|
|
3227
3541
|
state = (await store.buildFacts(record.slug)).state
|
|
3542
|
+
source.observed?.(prState)
|
|
3228
3543
|
if (state.prState === 'merged' && state.mergedSha)
|
|
3229
3544
|
prState = { state: 'merged', sha: state.mergedSha }
|
|
3230
3545
|
}
|
|
@@ -3305,8 +3620,11 @@ export class Dispatcher {
|
|
|
3305
3620
|
}
|
|
3306
3621
|
await this.releaseWorkspace(record.slug, events)
|
|
3307
3622
|
if (record.ticket) {
|
|
3308
|
-
await tickets.transition(record
|
|
3309
|
-
await tickets.comment(
|
|
3623
|
+
await tickets.transition(await this.currentTicketId(record), this.doneState)
|
|
3624
|
+
await tickets.comment(
|
|
3625
|
+
await this.currentTicketId(record),
|
|
3626
|
+
`build ${record.slug} merged: ${pr.url}`,
|
|
3627
|
+
)
|
|
3310
3628
|
}
|
|
3311
3629
|
await store.append(record.slug, {
|
|
3312
3630
|
actor: DISPATCHER,
|
|
@@ -3331,9 +3649,9 @@ export class Dispatcher {
|
|
|
3331
3649
|
await this.releaseWorkspace(record.slug, events)
|
|
3332
3650
|
if (record.ticket) {
|
|
3333
3651
|
const triageState = this.triageState()
|
|
3334
|
-
await tickets.transition(record
|
|
3652
|
+
await tickets.transition(await this.currentTicketId(record), triageState)
|
|
3335
3653
|
await tickets.comment(
|
|
3336
|
-
record
|
|
3654
|
+
await this.currentTicketId(record),
|
|
3337
3655
|
`build ${record.slug} PR closed without merging (${pr.url}) — returned to ${triageState}`,
|
|
3338
3656
|
)
|
|
3339
3657
|
}
|
|
@@ -3749,14 +4067,17 @@ export class Dispatcher {
|
|
|
3749
4067
|
// can only sample the ticket's current assets (SPEC §6.3).
|
|
3750
4068
|
const assets =
|
|
3751
4069
|
seed?.assets ??
|
|
3752
|
-
(await preparePinnedAssets(
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
4070
|
+
(await preparePinnedAssets(
|
|
4071
|
+
this.deps.tickets,
|
|
4072
|
+
store,
|
|
4073
|
+
record.repo,
|
|
4074
|
+
await this.currentTicketId(record),
|
|
4075
|
+
).catch((error) => {
|
|
4076
|
+
// Preserve legacy recovery only without native assets. Native preparation
|
|
4077
|
+
// must never publish an empty pin after losing the source bytes.
|
|
4078
|
+
if (this.deps.tickets.assets || this.deps.tickets.name === 'hosted') throw error
|
|
4079
|
+
return []
|
|
4080
|
+
}))
|
|
3760
4081
|
await store.appendIfCurrent(record.slug, 0, {
|
|
3761
4082
|
actor: DISPATCHER,
|
|
3762
4083
|
type: 'build.created',
|
|
@@ -3932,7 +4253,10 @@ export class Dispatcher {
|
|
|
3932
4253
|
|
|
3933
4254
|
stage = 'comment'
|
|
3934
4255
|
if (record.ticket !== undefined && !events.commentPosted) {
|
|
3935
|
-
await this.deps.tickets.comment(
|
|
4256
|
+
await this.deps.tickets.comment(
|
|
4257
|
+
await this.currentTicketId(record),
|
|
4258
|
+
`build ${record.slug} dispatched`,
|
|
4259
|
+
)
|
|
3936
4260
|
await store.append(record.slug, {
|
|
3937
4261
|
actor: DISPATCHER,
|
|
3938
4262
|
type: 'dispatch.comment-posted',
|
|
@@ -4121,7 +4445,7 @@ export class Dispatcher {
|
|
|
4121
4445
|
if (record.lease) {
|
|
4122
4446
|
if (new Date(record.lease.expiresAt).getTime() > now) continue // healthy
|
|
4123
4447
|
} else if (now - new Date(record.updatedAt).getTime() < this.leaseTtlMs) {
|
|
4124
|
-
continue // absent lease within the first-claim grace (see DispatcherOpts)
|
|
4448
|
+
if ((await this.store.buildFacts(record.slug)).lastExecution !== 'relaunch') continue // absent lease within the first-claim grace (see DispatcherOpts)
|
|
4125
4449
|
}
|
|
4126
4450
|
const facts = await this.store.buildFacts(record.slug)
|
|
4127
4451
|
const state = facts.state
|
|
@@ -4168,7 +4492,7 @@ export class Dispatcher {
|
|
|
4168
4492
|
// place: the guest finished its work, the workspace is still the
|
|
4169
4493
|
// build's, and replacing the environment would discard a healthy
|
|
4170
4494
|
// generation. Only an unproven stale lease or a proved loss reaps.
|
|
4171
|
-
let endedInPlace = facts.lastExecution === 'completed'
|
|
4495
|
+
let endedInPlace = facts.lastExecution === 'completed' || facts.lastExecution === 'relaunch'
|
|
4172
4496
|
if (
|
|
4173
4497
|
foreignExecution !== null &&
|
|
4174
4498
|
foreignExecution.commandId !== undefined &&
|
|
@@ -4368,16 +4692,18 @@ export class Dispatcher {
|
|
|
4368
4692
|
treeEntries.some(({ digest }) => digest.kind === 'node') ||
|
|
4369
4693
|
ready.some((ticket) => ticket.kind === 'node')
|
|
4370
4694
|
let presence: PresenceInputs | undefined
|
|
4695
|
+
const migrations = this.store.repositoryFacts().ticketMigrations
|
|
4696
|
+
const normalizeTicket = historicalTicketIdentity(migrations, this.deps.tickets.name)
|
|
4371
4697
|
const builtTickets = hasNodes
|
|
4372
4698
|
? new Set(
|
|
4373
4699
|
treeEntries.flatMap(({ record }) =>
|
|
4374
|
-
record.ticket ? [
|
|
4700
|
+
record.ticket ? [normalizeTicket(record.ticket, record.slug)] : [],
|
|
4375
4701
|
),
|
|
4376
4702
|
)
|
|
4377
4703
|
: undefined
|
|
4378
4704
|
const needsPresence = (candidate: Ticket) =>
|
|
4379
4705
|
(candidate.blockedBy ?? []).some((id) => {
|
|
4380
|
-
const build = blockerBuild(treeEntries, candidate.ref.source, id)
|
|
4706
|
+
const build = blockerBuild(treeEntries, candidate.ref.source, id, normalizeTicket)
|
|
4381
4707
|
return (
|
|
4382
4708
|
id !== candidate.ref.id &&
|
|
4383
4709
|
build !== undefined &&
|
|
@@ -4424,7 +4750,12 @@ export class Dispatcher {
|
|
|
4424
4750
|
candidate.target !== undefined,
|
|
4425
4751
|
)
|
|
4426
4752
|
.flatMap((candidate) => {
|
|
4427
|
-
const node = blockerBuild(
|
|
4753
|
+
const node = blockerBuild(
|
|
4754
|
+
entries,
|
|
4755
|
+
candidate.ref.source,
|
|
4756
|
+
candidate.target!,
|
|
4757
|
+
normalizeTicket,
|
|
4758
|
+
)
|
|
4428
4759
|
return node && typeof node !== 'string' && node.digest.kind === 'node'
|
|
4429
4760
|
? [node.record.slug]
|
|
4430
4761
|
: []
|
|
@@ -4626,10 +4957,24 @@ export class Dispatcher {
|
|
|
4626
4957
|
)
|
|
4627
4958
|
return `integration requires forge ${forge.name} capabilities createNodeBranch, compareBranches and remoteBranchSha; upgrade the plugin`
|
|
4628
4959
|
if (ticket.target === undefined) return undefined
|
|
4960
|
+
const migrations = this.store.repositoryFacts().ticketMigrations
|
|
4629
4961
|
const entries = (await this.repoBuildDigests())
|
|
4630
4962
|
.filter(
|
|
4631
4963
|
({ record }) =>
|
|
4632
|
-
record.ticket
|
|
4964
|
+
record.ticket &&
|
|
4965
|
+
(() => {
|
|
4966
|
+
try {
|
|
4967
|
+
const ref = resolveTicketRef(
|
|
4968
|
+
migrations,
|
|
4969
|
+
record.ticket,
|
|
4970
|
+
ticket.ref.source,
|
|
4971
|
+
record.slug,
|
|
4972
|
+
)
|
|
4973
|
+
return ref.id === ticket.target
|
|
4974
|
+
} catch {
|
|
4975
|
+
return false
|
|
4976
|
+
}
|
|
4977
|
+
})(),
|
|
4633
4978
|
)
|
|
4634
4979
|
.sort(
|
|
4635
4980
|
(a, b) =>
|
|
@@ -4657,7 +5002,13 @@ export class Dispatcher {
|
|
|
4657
5002
|
if (state.integration?.intent && !state.integration.landing)
|
|
4658
5003
|
return `target node ${ticket.target} is landing`
|
|
4659
5004
|
if (!digest.nodeOpened || !record.branch) return `target node ${ticket.target} is not yet open`
|
|
4660
|
-
return {
|
|
5005
|
+
return {
|
|
5006
|
+
target: {
|
|
5007
|
+
ticket: resolveTicketRef(migrations, record.ticket!, this.deps.tickets.name, record.slug),
|
|
5008
|
+
build: record.slug,
|
|
5009
|
+
},
|
|
5010
|
+
branch: record.branch,
|
|
5011
|
+
}
|
|
4661
5012
|
}
|
|
4662
5013
|
|
|
4663
5014
|
private async openNode(record: BuildRecord, state: BuildState): Promise<void> {
|
|
@@ -5050,14 +5401,14 @@ export class Dispatcher {
|
|
|
5050
5401
|
payload: comparison,
|
|
5051
5402
|
})
|
|
5052
5403
|
state = (await this.store.buildFacts(record.slug)).state
|
|
5053
|
-
const claims = await this.integrationClaimKey(record.slug)
|
|
5404
|
+
const claims = await this.integrationClaimKey(record.slug, state)
|
|
5054
5405
|
const unchangedFailure = integrationFailed(state)
|
|
5055
5406
|
if (
|
|
5056
5407
|
!unchangedFailure &&
|
|
5057
5408
|
this.integrationPollDue(
|
|
5058
5409
|
this.integrationPolls,
|
|
5059
5410
|
record.slug,
|
|
5060
|
-
`${comparison.headSha}:${comparison.parentSha}:${state.nodeRestack?.inventory?.head ?? ''}:${state.landing?.command?.seq ?? state.landing?.decision?.seq ?? ''}:${claims}`,
|
|
5411
|
+
`${state.restartSince}:${comparison.headSha}:${comparison.parentSha}:${state.nodeRestack?.inventory?.head ?? ''}:${state.landing?.command?.seq ?? state.landing?.decision?.seq ?? ''}:${claims}`,
|
|
5061
5412
|
)
|
|
5062
5413
|
) {
|
|
5063
5414
|
await this.observeIntegration(record.slug)
|
|
@@ -5453,7 +5804,15 @@ export class Dispatcher {
|
|
|
5453
5804
|
const required = new Map<string, ChangeIdentity[]>()
|
|
5454
5805
|
const fallback: string[] = []
|
|
5455
5806
|
for (const id of ticket.blockedBy ?? []) {
|
|
5456
|
-
const build = blockerBuild(
|
|
5807
|
+
const build = blockerBuild(
|
|
5808
|
+
inputs.entries,
|
|
5809
|
+
ticket.ref.source,
|
|
5810
|
+
id,
|
|
5811
|
+
historicalTicketIdentity(
|
|
5812
|
+
this.store.repositoryFacts().ticketMigrations,
|
|
5813
|
+
this.deps.tickets.name,
|
|
5814
|
+
),
|
|
5815
|
+
)
|
|
5457
5816
|
if (id === ticket.ref.id || !nodes.get(id)?.exists || build === undefined) {
|
|
5458
5817
|
fallback.push(id)
|
|
5459
5818
|
continue
|