@defrex/autobuild 1.18.0 → 1.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/SPEC.md +97 -18
- package/docs/architecture.md +53 -16
- package/docs/assets/headline-wide.png +0 -0
- package/docs/dispatcher.md +1 -1
- package/docs/merge-policy.md +2 -1
- package/docs/operator-surfaces.md +1 -1
- package/docs/plugin-authoring.md +11 -4
- package/docs/process-ownership.md +43 -0
- package/docs/remote-store-protocol.md +7 -0
- package/docs/restacking.md +11 -2
- package/docs/setup.md +7 -2
- package/docs/verification.md +1 -1
- package/package.json +3 -3
- package/packages/core/src/cli/dashboard/model.ts +1 -0
- package/packages/core/src/cli/dashboard/vocabulary.ts +3 -0
- package/packages/core/src/cli/dispatch.ts +2 -0
- package/packages/core/src/events/catalog-identity.ts +3 -1
- package/packages/core/src/events/payloads.ts +7 -1
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +1 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/3f0c4e6d1d54e5bf.json +92 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/e012e9e8f3e82935.json +424 -0
- package/packages/core/src/kernel/dispatch-capacity.ts +15 -3
- package/packages/core/src/kernel/engine.ts +15 -2
- package/packages/core/src/kernel/janitor-failure.ts +2 -0
- package/packages/core/src/kernel/reducer-revisions.ts +5 -0
- package/packages/core/src/kernel/reducer.ts +6 -0
- package/packages/core/src/kernel/session-settlement.ts +82 -0
- package/packages/core/src/processes/build-runner.ts +167 -36
- package/packages/core/src/processes/check-termination.ts +44 -0
- package/packages/core/src/processes/dispatcher.ts +295 -21
- package/packages/core/src/processes/execution-settlement.ts +30 -0
- package/packages/core/src/processes/publication-loss.ts +29 -0
- package/packages/core/src/processes/repo-view.ts +2 -1
- package/packages/core/src/store/contract.ts +43 -0
- package/packages/core/src/store/digest.ts +19 -1
- package/packages/core/src/store/reducer-value-shapes.json +2742 -2709
- package/packages/core/src/store/remote/protocol.ts +3 -0
- package/packages/core/src/store/remote/released-clients.json +22 -0
- package/packages/core/src/store/remote/released-reducer-values/1.19.0.json +36461 -0
- package/packages/core/src/store/remote/released-reducer-values/1.20.0.json +36469 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +20 -16
- package/packages/core/src/store/types.ts +5 -0
- package/packages/core/src/testing/reduced-read-budget.ts +167 -0
- package/skills/code-review/SKILL.md +5 -0
- package/skills/finalize/SKILL.md +5 -0
- package/skills/guide/SKILL.md +42 -17
- package/skills/guide/references/merge-policy.md +2 -1
- package/skills/guide/references/plugin-authoring.md +11 -4
- package/skills/guide/references/process-ownership.md +43 -0
- package/skills/guide/references/remote-store-protocol.md +7 -0
- package/skills/guide/references/restacking.md +11 -2
- package/skills/guide/references/setup.md +7 -2
- package/skills/harvest/SKILL.md +5 -0
- package/skills/harvest-review/SKILL.md +5 -0
- package/skills/implement/SKILL.md +5 -0
- package/skills/judge/SKILL.md +4 -0
- package/skills/operate/SKILL.md +5 -0
- package/skills/plan/SKILL.md +5 -0
- package/skills/plan-review/SKILL.md +5 -0
- package/skills/propose/SKILL.md +5 -0
- package/skills/reconcile/SKILL.md +5 -0
- package/templates/hosted-service/package.json +2 -2
|
@@ -271,7 +271,12 @@ import { readBuildDigests, readForgeHealth } from '../store/reduced-reads'
|
|
|
271
271
|
import { enforceOptimizationStop } from './optimization-stop'
|
|
272
272
|
import { recordOptimizationActivity } from './optimization-activity'
|
|
273
273
|
import { reconcileMergedAttempts } from './optimization-merges'
|
|
274
|
-
import {
|
|
274
|
+
import {
|
|
275
|
+
readBuildSelector,
|
|
276
|
+
readBuildFacts,
|
|
277
|
+
readTerminalGuardBoundary,
|
|
278
|
+
type CurrentBuildFacts,
|
|
279
|
+
} from '../store/reduced-reads'
|
|
275
280
|
import { ensureExecutionProgress } from './execution-no-progress'
|
|
276
281
|
import { ticketIdentity } from '../ports/tickets/identity'
|
|
277
282
|
import { holdsState, ticketLifecycle } from '../ports/tickets/lifecycle'
|
|
@@ -339,6 +344,10 @@ import type { IdSource } from '../ids'
|
|
|
339
344
|
import { recordAutoMergeDeferralObservation } from '../kernel/auto-merge'
|
|
340
345
|
import type { AutoMergeDefaultFact } from '../kernel/auto-merge-default'
|
|
341
346
|
import { decideNextFromFacts, landingRestackDue } from '../kernel/engine'
|
|
347
|
+
import {
|
|
348
|
+
endedExecutionSessionSettlement,
|
|
349
|
+
settlementTerminalChecks,
|
|
350
|
+
} from '../kernel/session-settlement'
|
|
342
351
|
import { composeBuildConfig } from '../config/live'
|
|
343
352
|
import { profileConflictDiagnostic, selectProfile } from '../config/profiles'
|
|
344
353
|
import {
|
|
@@ -413,6 +422,7 @@ import { settleOpenExecution } from './execution-settlement'
|
|
|
413
422
|
import { isWorkDigest, RepoViewStore } from './repo-view'
|
|
414
423
|
import type { OpenBuildWorkspace, ProvisionMarker } from './dispatcher-selectors'
|
|
415
424
|
import {
|
|
425
|
+
mergedHeadCovers,
|
|
416
426
|
recordPublicationLossBeforeRelease,
|
|
417
427
|
settlePublicationFactsBeforeRelease,
|
|
418
428
|
} from './publication-loss'
|
|
@@ -4034,6 +4044,7 @@ export class Dispatcher {
|
|
|
4034
4044
|
if (
|
|
4035
4045
|
state.status === 'done' &&
|
|
4036
4046
|
digest.reclaimPending !== true &&
|
|
4047
|
+
digest.releasePending !== true &&
|
|
4037
4048
|
digest.integrationAuditPending !== true
|
|
4038
4049
|
)
|
|
4039
4050
|
return
|
|
@@ -4047,6 +4058,32 @@ export class Dispatcher {
|
|
|
4047
4058
|
loaded ??= (await readBuildFacts(this.store, record.slug)).value
|
|
4048
4059
|
return loaded
|
|
4049
4060
|
}
|
|
4061
|
+
// An ended execution's open sessions would hold the leaf's landing
|
|
4062
|
+
// decision; settle them in place before anything below reads it.
|
|
4063
|
+
if (
|
|
4064
|
+
state.kind !== 'node' &&
|
|
4065
|
+
initialFacts.open === null &&
|
|
4066
|
+
!executionLeaseLive &&
|
|
4067
|
+
!launched.has(record.slug) &&
|
|
4068
|
+
state.sessions.open.length > 0 &&
|
|
4069
|
+
state.executions.length > 0
|
|
4070
|
+
) {
|
|
4071
|
+
const prior = operation
|
|
4072
|
+
operation = 'session settlement'
|
|
4073
|
+
const facts = await this.store.buildFacts(record.slug)
|
|
4074
|
+
// A done or aborted build resumes nothing: no decision is needed
|
|
4075
|
+
// to end what its ended execution left open.
|
|
4076
|
+
const terminal = facts.state.status === 'done' || facts.state.status === 'aborted'
|
|
4077
|
+
const decision = terminal
|
|
4078
|
+
? undefined
|
|
4079
|
+
: await this.decideBuild(record.slug, facts.state, facts.log, report)
|
|
4080
|
+
if (
|
|
4081
|
+
(terminal || decision !== undefined) &&
|
|
4082
|
+
(await this.settleEndedExecutionSessions(record.slug, facts, decision))
|
|
4083
|
+
)
|
|
4084
|
+
({ state, log } = await this.store.buildFacts(record.slug))
|
|
4085
|
+
operation = prior
|
|
4086
|
+
}
|
|
4050
4087
|
const pollStart = state
|
|
4051
4088
|
const pollChildren =
|
|
4052
4089
|
state.kind === 'node' ? await this.nodePollingChildren(record.slug) : []
|
|
@@ -4065,7 +4102,13 @@ export class Dispatcher {
|
|
|
4065
4102
|
undefined,
|
|
4066
4103
|
)
|
|
4067
4104
|
: undefined
|
|
4068
|
-
if (
|
|
4105
|
+
if (
|
|
4106
|
+
state.kind === 'node' &&
|
|
4107
|
+
!controlDue &&
|
|
4108
|
+
digest.releasePending !== true &&
|
|
4109
|
+
pollSchedule &&
|
|
4110
|
+
!pollSchedule.due
|
|
4111
|
+
) {
|
|
4069
4112
|
attempted = false
|
|
4070
4113
|
return
|
|
4071
4114
|
}
|
|
@@ -4186,6 +4229,20 @@ export class Dispatcher {
|
|
|
4186
4229
|
)
|
|
4187
4230
|
}
|
|
4188
4231
|
if (state.status === 'done') {
|
|
4232
|
+
// A merged build's workspace release is a post-terminal duty: its
|
|
4233
|
+
// completion never waited on it (§15.7).
|
|
4234
|
+
if (
|
|
4235
|
+
digest.releasePending === true &&
|
|
4236
|
+
state.prState === 'merged' &&
|
|
4237
|
+
!executionLeaseLive
|
|
4238
|
+
) {
|
|
4239
|
+
operation = 'merged workspace release'
|
|
4240
|
+
await this.releaseMergedWorkspace(
|
|
4241
|
+
record,
|
|
4242
|
+
state.mergedSha !== undefined ? { sha: state.mergedSha } : {},
|
|
4243
|
+
this.forgeWorkspacePathOf(workspace),
|
|
4244
|
+
)
|
|
4245
|
+
}
|
|
4189
4246
|
if (digest.reclaimPending === true) {
|
|
4190
4247
|
operation = 'PR attachment reclaim'
|
|
4191
4248
|
await this.reclaimPrAttachments(record.slug, await history())
|
|
@@ -4264,7 +4321,8 @@ export class Dispatcher {
|
|
|
4264
4321
|
}
|
|
4265
4322
|
}
|
|
4266
4323
|
if ((state.status === 'paused' || janitorBlocked(state)) && !state.pr) return
|
|
4267
|
-
|
|
4324
|
+
// A merged PR has nothing left to restack onto the target.
|
|
4325
|
+
if (state.nodeOpened && state.baseBranch && state.prState !== 'merged') {
|
|
4268
4326
|
operation = 'target observation'
|
|
4269
4327
|
if (
|
|
4270
4328
|
await this.observeTarget(
|
|
@@ -4359,7 +4417,9 @@ export class Dispatcher {
|
|
|
4359
4417
|
if (
|
|
4360
4418
|
state.kind !== 'node' &&
|
|
4361
4419
|
state.status !== 'aborted' &&
|
|
4362
|
-
janitorStatus(state) !== 'queued'
|
|
4420
|
+
janitorStatus(state) !== 'queued' &&
|
|
4421
|
+
// A merged PR has nothing left to restack onto the target.
|
|
4422
|
+
state.prState !== 'merged'
|
|
4363
4423
|
) {
|
|
4364
4424
|
const branch = await readBuildSelector(this.store, record.slug, 'baseBranch')
|
|
4365
4425
|
if (branch !== undefined) {
|
|
@@ -5029,6 +5089,10 @@ export class Dispatcher {
|
|
|
5029
5089
|
)
|
|
5030
5090
|
)
|
|
5031
5091
|
return 'admit'
|
|
5092
|
+
// A merged leaf never takes a slot (§12): its completion and cleanup are
|
|
5093
|
+
// the janitor's, and nothing a runner could do remains. Not a slot
|
|
5094
|
+
// waiter either, so it reserves no intake.
|
|
5095
|
+
if (state.prState === 'merged') return 'wait'
|
|
5032
5096
|
const builds = await this.capacityBuilds(this.tickLaunched)
|
|
5033
5097
|
const others = builds.filter((build) => build.record.slug !== slug)
|
|
5034
5098
|
const capacity = this.deps.config.capacity
|
|
@@ -6864,7 +6928,13 @@ export class Dispatcher {
|
|
|
6864
6928
|
}
|
|
6865
6929
|
source.observed?.(prState)
|
|
6866
6930
|
if (state.prState === 'merged' && state.mergedSha)
|
|
6867
|
-
prState = {
|
|
6931
|
+
prState = {
|
|
6932
|
+
state: 'merged',
|
|
6933
|
+
sha: state.mergedSha,
|
|
6934
|
+
...(prState.state === 'merged' && prState.headSha !== undefined
|
|
6935
|
+
? { headSha: prState.headSha }
|
|
6936
|
+
: {}),
|
|
6937
|
+
}
|
|
6868
6938
|
let nativeCancelled = false
|
|
6869
6939
|
if (
|
|
6870
6940
|
nodeTarget &&
|
|
@@ -7712,7 +7782,6 @@ export class Dispatcher {
|
|
|
7712
7782
|
// A merged attempt settles `accepted` with the measurement of the
|
|
7713
7783
|
// head that landed, before the build can become terminal.
|
|
7714
7784
|
if (nodeTarget) await this.settleMergedAttempt(record, state, prState.sha)
|
|
7715
|
-
await this.releaseWorkspace(record.slug, events)
|
|
7716
7785
|
if (record.ticket) {
|
|
7717
7786
|
await tickets.transition(await this.currentTicketId(record), this.doneState)
|
|
7718
7787
|
await tickets.comment(
|
|
@@ -7720,6 +7789,10 @@ export class Dispatcher {
|
|
|
7720
7789
|
`build ${record.slug} merged: ${pr.url}`,
|
|
7721
7790
|
)
|
|
7722
7791
|
}
|
|
7792
|
+
// Complete before any workspace work: the merged commit is on the
|
|
7793
|
+
// target, so a stopped or unreachable workspace never holds the
|
|
7794
|
+
// build open (§15.7). Its release follows and, when it cannot
|
|
7795
|
+
// finish, stays pending on the completed build (`releasePending`).
|
|
7723
7796
|
await store.append(record.slug, {
|
|
7724
7797
|
actor: DISPATCHER,
|
|
7725
7798
|
type: 'build.completed',
|
|
@@ -7727,6 +7800,7 @@ export class Dispatcher {
|
|
|
7727
7800
|
} satisfies EventWrite<'build.completed'>)
|
|
7728
7801
|
await this.reclaimPrAttachments(record.slug, events)
|
|
7729
7802
|
report.merged += 1
|
|
7803
|
+
await this.releaseMergedWorkspace(record, prState, workspacePath)
|
|
7730
7804
|
return
|
|
7731
7805
|
}
|
|
7732
7806
|
case 'closed': {
|
|
@@ -8147,12 +8221,6 @@ export class Dispatcher {
|
|
|
8147
8221
|
// No live provider can act on this ref; leave the fact open rather than
|
|
8148
8222
|
// claim a release that never happened.
|
|
8149
8223
|
if (owner === null) return undefined
|
|
8150
|
-
const handle = {
|
|
8151
|
-
provider: open.provider,
|
|
8152
|
-
ref: open.ref,
|
|
8153
|
-
path: open.path ?? open.ref,
|
|
8154
|
-
branch: open.branch,
|
|
8155
|
-
}
|
|
8156
8224
|
// Last-chance settlement boundary (AUT-328): settle or durably record the
|
|
8157
8225
|
// pending publication BEFORE any provider cleanup call, while the
|
|
8158
8226
|
// workspace still exists. The guard's append failure propagates — the
|
|
@@ -8186,6 +8254,28 @@ export class Dispatcher {
|
|
|
8186
8254
|
reason,
|
|
8187
8255
|
)
|
|
8188
8256
|
}
|
|
8257
|
+
return this.cleanupAndRelease(slug, open, owner, events, reason, { recordFailure: true })
|
|
8258
|
+
}
|
|
8259
|
+
|
|
8260
|
+
/** The provider cleanup every release ends with: reap (recording the
|
|
8261
|
+
* attempt) or release, then `workspace.released`. A deadline deferral
|
|
8262
|
+
* records nothing and propagates. Any other reap failure records the
|
|
8263
|
+
* unknown cleanup attempt, and with `recordFailure` also charges the
|
|
8264
|
+
* build's infrastructure-failure budget, then propagates. */
|
|
8265
|
+
private async cleanupAndRelease(
|
|
8266
|
+
slug: string,
|
|
8267
|
+
open: OpenBuildWorkspace,
|
|
8268
|
+
owner: WorkspaceProvider,
|
|
8269
|
+
events: CurrentBuildFacts,
|
|
8270
|
+
reason: 'completion' | 'abort' | 'pause' | 'blocked' | 'replacement' | 'discard',
|
|
8271
|
+
options: { recordFailure: boolean },
|
|
8272
|
+
): Promise<AbEvent> {
|
|
8273
|
+
const handle = {
|
|
8274
|
+
provider: open.provider,
|
|
8275
|
+
ref: open.ref,
|
|
8276
|
+
path: open.path ?? open.ref,
|
|
8277
|
+
branch: open.branch,
|
|
8278
|
+
}
|
|
8189
8279
|
const recovery = owner.recovery
|
|
8190
8280
|
if (recovery !== undefined) {
|
|
8191
8281
|
const attempt = (events.cleanupCounts[JSON.stringify(open.ref)] ?? 0) + 1
|
|
@@ -8224,13 +8314,14 @@ export class Dispatcher {
|
|
|
8224
8314
|
},
|
|
8225
8315
|
})
|
|
8226
8316
|
Object.assign(events, (await readBuildFacts(this.store, slug)).value)
|
|
8227
|
-
|
|
8228
|
-
|
|
8229
|
-
|
|
8230
|
-
|
|
8231
|
-
|
|
8232
|
-
|
|
8233
|
-
|
|
8317
|
+
if (options.recordFailure)
|
|
8318
|
+
await this.recordInfrastructureFailure(slug, events, {
|
|
8319
|
+
provider: open.provider,
|
|
8320
|
+
workspaceRef: open.ref,
|
|
8321
|
+
operation: 'delete',
|
|
8322
|
+
error: failure,
|
|
8323
|
+
cleanupPending: true,
|
|
8324
|
+
})
|
|
8234
8325
|
throw error
|
|
8235
8326
|
}
|
|
8236
8327
|
} else {
|
|
@@ -8243,6 +8334,63 @@ export class Dispatcher {
|
|
|
8243
8334
|
} satisfies EventWrite<'workspace.released'>)
|
|
8244
8335
|
}
|
|
8245
8336
|
|
|
8337
|
+
/** Release a merged build's workspace (SPEC §15.7). The merged commit is on
|
|
8338
|
+
* the target, so nothing is fenced, preserved or resumed. A pending
|
|
8339
|
+
* publication the merged PR already contains is recorded lost without
|
|
8340
|
+
* settlement; one it does not contain is settled as every release does.
|
|
8341
|
+
* Runs after `build.completed`: a deferral or failure here leaves the build
|
|
8342
|
+
* completed with `releasePending` in its digest, and the janitor retries it
|
|
8343
|
+
* under janitor-failure backoff. Log-deduped, so re-runs are no-ops. */
|
|
8344
|
+
private async releaseMergedWorkspace(
|
|
8345
|
+
record: BuildRecord,
|
|
8346
|
+
merged: { sha?: string; headSha?: string },
|
|
8347
|
+
path: string,
|
|
8348
|
+
): Promise<void> {
|
|
8349
|
+
const slug = record.slug
|
|
8350
|
+
let facts = (await readBuildFacts(this.store, slug)).value
|
|
8351
|
+
const open = openWorkspace(facts)
|
|
8352
|
+
if (open === null) return
|
|
8353
|
+
const owner = this.workspaceOwner(open)
|
|
8354
|
+
if (owner === null)
|
|
8355
|
+
throw new Error(
|
|
8356
|
+
`merged workspace ${open.ref} has no configured provider "${open.provider}"; cleanup stays pending`,
|
|
8357
|
+
)
|
|
8358
|
+
// A live runner still owns the workspace; the next visit releases it.
|
|
8359
|
+
if (this.hasLiveExecutionLease(record)) return
|
|
8360
|
+
const request = facts.publication.latestUncompletedRequest()
|
|
8361
|
+
if (request !== undefined && !facts.publication.lostRecorded(request)) {
|
|
8362
|
+
let headSha = merged.headSha
|
|
8363
|
+
const pr = facts.state.pr
|
|
8364
|
+
if (headSha === undefined && pr !== undefined) {
|
|
8365
|
+
const observed = await this.deps.forge.getPrState(path, pr.number)
|
|
8366
|
+
if (observed.state === 'merged') headSha = observed.headSha
|
|
8367
|
+
}
|
|
8368
|
+
const forge = this.deps.forge
|
|
8369
|
+
const covered = await mergedHeadCovers(
|
|
8370
|
+
request.payload.sha,
|
|
8371
|
+
[headSha, merged.sha],
|
|
8372
|
+
forge.isCommitAncestor
|
|
8373
|
+
? (ancestor, descendant) => forge.isCommitAncestor!(ancestor, descendant)
|
|
8374
|
+
: undefined,
|
|
8375
|
+
)
|
|
8376
|
+
facts = covered
|
|
8377
|
+
? await recordPublicationLossBeforeRelease(
|
|
8378
|
+
{ store: this.store },
|
|
8379
|
+
slug,
|
|
8380
|
+
facts,
|
|
8381
|
+
`completion: merged PR already contains ${request.payload.sha}`,
|
|
8382
|
+
request,
|
|
8383
|
+
)
|
|
8384
|
+
: await settlePublicationFactsBeforeRelease(
|
|
8385
|
+
{ store: this.store, settlePublication: this.settlePublication },
|
|
8386
|
+
slug,
|
|
8387
|
+
facts,
|
|
8388
|
+
'completion',
|
|
8389
|
+
)
|
|
8390
|
+
}
|
|
8391
|
+
await this.cleanupAndRelease(slug, open, owner, facts, 'completion', { recordFailure: false })
|
|
8392
|
+
}
|
|
8393
|
+
|
|
8246
8394
|
/**
|
|
8247
8395
|
* One best-effort preservation attempt ahead of an abort release. Only three
|
|
8248
8396
|
* refusals stop the release: lost repository authority, a mixed-version
|
|
@@ -9768,6 +9916,116 @@ export class Dispatcher {
|
|
|
9768
9916
|
|
|
9769
9917
|
/** `carried` is a deferred-work entry's pass: its facts are already read,
|
|
9770
9918
|
* and the first-claim grace does not apply. */
|
|
9919
|
+
/** Settle, in place and without a runner, every session an ended execution
|
|
9920
|
+
* left open (SPEC §15.6-C), on running, held and terminal builds alike: an
|
|
9921
|
+
* unfinished occurrence with a native handle of a live build is suspended as
|
|
9922
|
+
* resumable, every other session is ended `reclaimed`. A terminal build
|
|
9923
|
+
* needs no `decision`. Each write is conditional on the cursor, so a runner that
|
|
9924
|
+
* attached meanwhile wins; the next visit decides again. Returns whether
|
|
9925
|
+
* anything was written. */
|
|
9926
|
+
private async settleEndedExecutionSessions(
|
|
9927
|
+
slug: string,
|
|
9928
|
+
facts: CurrentBuildFacts,
|
|
9929
|
+
decision: ReturnType<typeof decideNextFromFacts> | undefined,
|
|
9930
|
+
): Promise<boolean> {
|
|
9931
|
+
const { state } = facts
|
|
9932
|
+
if (facts.open !== null) return false
|
|
9933
|
+
// A hold (pause, escalation) keeps the engine waiting, so its decision
|
|
9934
|
+
// cannot say whether an occurrence is finished. Its durable terminal can:
|
|
9935
|
+
// an unfinished one keeps its native continuation through suspension.
|
|
9936
|
+
const unfinished = new Set<string>()
|
|
9937
|
+
for (const session of settlementTerminalChecks(state, decision)) {
|
|
9938
|
+
const postStep = session.phase === 'finalize' && session.role !== 'finalize'
|
|
9939
|
+
const finished = postStep
|
|
9940
|
+
? facts.log.finalizeStepsDone.has(session.role)
|
|
9941
|
+
: (
|
|
9942
|
+
await readTerminalGuardBoundary(
|
|
9943
|
+
this.store,
|
|
9944
|
+
slug,
|
|
9945
|
+
session.phase,
|
|
9946
|
+
session.round ?? 1,
|
|
9947
|
+
session.session,
|
|
9948
|
+
)
|
|
9949
|
+
).value.diagnostic !== undefined
|
|
9950
|
+
if (!finished) unfinished.add(session.session)
|
|
9951
|
+
}
|
|
9952
|
+
const { suspend, end } = endedExecutionSessionSettlement(state, decision, unfinished)
|
|
9953
|
+
if (suspend.length === 0 && end.length === 0) return false
|
|
9954
|
+
const ended = state.executions.at(-1)
|
|
9955
|
+
const outcome = facts.lastExecution
|
|
9956
|
+
if (ended === undefined || outcome === 'open' || outcome === 'none') return false
|
|
9957
|
+
const execution = { instance: ended.instance, outcome }
|
|
9958
|
+
const now = this.deps.clock().getTime()
|
|
9959
|
+
let cursor = state.lastSeq
|
|
9960
|
+
let wrote = false
|
|
9961
|
+
for (const session of end) {
|
|
9962
|
+
const appended = await this.store.appendIfCurrent(slug, cursor, {
|
|
9963
|
+
actor: KERNEL,
|
|
9964
|
+
type: 'session.ended',
|
|
9965
|
+
payload: {
|
|
9966
|
+
session: session.session,
|
|
9967
|
+
outcome: 'reclaimed',
|
|
9968
|
+
reclaimedBy: {
|
|
9969
|
+
instance: this.deps.ids('session-settlement'),
|
|
9970
|
+
resumedFromSeq: state.lastSeq,
|
|
9971
|
+
},
|
|
9972
|
+
},
|
|
9973
|
+
})
|
|
9974
|
+
if (appended === null) return wrote
|
|
9975
|
+
cursor = appended.seq
|
|
9976
|
+
wrote = true
|
|
9977
|
+
}
|
|
9978
|
+
for (const session of suspend) {
|
|
9979
|
+
const { session: id, phase, round, role, runner, model } = session
|
|
9980
|
+
const appended = await this.store.appendWithArtifactsIfCurrent(
|
|
9981
|
+
slug,
|
|
9982
|
+
cursor,
|
|
9983
|
+
[
|
|
9984
|
+
{
|
|
9985
|
+
kind: 'transcript',
|
|
9986
|
+
content: JSON.stringify({ session: id, interrupted: true, execution }),
|
|
9987
|
+
metadata: {
|
|
9988
|
+
session: id,
|
|
9989
|
+
phase,
|
|
9990
|
+
round,
|
|
9991
|
+
role,
|
|
9992
|
+
runner,
|
|
9993
|
+
...(model !== undefined ? { model } : {}),
|
|
9994
|
+
interrupted: true,
|
|
9995
|
+
},
|
|
9996
|
+
},
|
|
9997
|
+
],
|
|
9998
|
+
(deposited) => ({
|
|
9999
|
+
actor: KERNEL,
|
|
10000
|
+
type: 'session.suspended',
|
|
10001
|
+
payload: {
|
|
10002
|
+
session: id,
|
|
10003
|
+
phase,
|
|
10004
|
+
...(round !== undefined ? { round } : {}),
|
|
10005
|
+
handle: session.nativeHandle,
|
|
10006
|
+
cause: 'shutdown',
|
|
10007
|
+
activeMs: Math.max(0, now - Date.parse(session.startedAt)),
|
|
10008
|
+
transcript: { kind: deposited[0]!.kind, rev: deposited[0]!.revision },
|
|
10009
|
+
execution,
|
|
10010
|
+
},
|
|
10011
|
+
}),
|
|
10012
|
+
)
|
|
10013
|
+
if (appended === null) return wrote
|
|
10014
|
+
cursor = appended.event.seq
|
|
10015
|
+
wrote = true
|
|
10016
|
+
}
|
|
10017
|
+
// Settling the last open session can complete a summary boundary the
|
|
10018
|
+
// ended guest never requested. The host's publication settlement repairs
|
|
10019
|
+
// that, as it does before any launch; it is best effort here.
|
|
10020
|
+
if (wrote)
|
|
10021
|
+
try {
|
|
10022
|
+
await this.settlePublication?.(slug)
|
|
10023
|
+
} catch (error) {
|
|
10024
|
+
rethrowAuthorityLapse(error)
|
|
10025
|
+
}
|
|
10026
|
+
return wrote
|
|
10027
|
+
}
|
|
10028
|
+
|
|
9771
10029
|
private async sweepBuildPass(
|
|
9772
10030
|
record: BuildRecord,
|
|
9773
10031
|
report: TickReport,
|
|
@@ -9780,7 +10038,7 @@ export class Dispatcher {
|
|
|
9780
10038
|
if (new Date(record.lease.expiresAt).getTime() > now) return // healthy
|
|
9781
10039
|
}
|
|
9782
10040
|
const facts = carried?.facts ?? (await this.store.buildFacts(record.slug))
|
|
9783
|
-
|
|
10041
|
+
let state = facts.state
|
|
9784
10042
|
if (mixedVersionDeferred(state)) {
|
|
9785
10043
|
return (await deferMixedVersion(this.store, record.slug)) ? 'waiting' : undefined
|
|
9786
10044
|
}
|
|
@@ -9887,6 +10145,16 @@ export class Dispatcher {
|
|
|
9887
10145
|
// proved end settles first (completion facts, lease release, publication)
|
|
9888
10146
|
// and then falls through to the normal decision; a provider-proved loss
|
|
9889
10147
|
// falls through to the existing stale path below.
|
|
10148
|
+
// An ended execution's open sessions are settled in place, without a
|
|
10149
|
+
// runner. Orphan relaunch remains for sessions no recorded execution
|
|
10150
|
+
// opened, and for a settlement that lost a race.
|
|
10151
|
+
if (
|
|
10152
|
+
facts.open === null &&
|
|
10153
|
+
!launched.has(record.slug) &&
|
|
10154
|
+
state.sessions.open.length > 0 &&
|
|
10155
|
+
(await this.settleEndedExecutionSessions(record.slug, facts, decision))
|
|
10156
|
+
)
|
|
10157
|
+
state = (await this.store.buildFacts(record.slug)).state
|
|
9890
10158
|
let orphanRecoveryDue = orphanEligible(state) && facts.open === null
|
|
9891
10159
|
const foreignExecution = facts.open
|
|
9892
10160
|
// A provider- or log-proved end in the same generation re-attaches in
|
|
@@ -9928,7 +10196,13 @@ export class Dispatcher {
|
|
|
9928
10196
|
// Unknown liveness is never proof that an open execution is dead.
|
|
9929
10197
|
// Settlement may itself raise provider attention. Revalidate cleanup
|
|
9930
10198
|
// eligibility from the advanced canonical state before admission.
|
|
9931
|
-
|
|
10199
|
+
let settled = await this.store.buildFacts(record.slug)
|
|
10200
|
+
if (
|
|
10201
|
+
settled.state.sessions.open.length > 0 &&
|
|
10202
|
+
(await this.settleEndedExecutionSessions(record.slug, settled, decision))
|
|
10203
|
+
)
|
|
10204
|
+
settled = await this.store.buildFacts(record.slug)
|
|
10205
|
+
orphanRecoveryDue = orphanEligible(settled.state)
|
|
9932
10206
|
if (settlement === 'settled') {
|
|
9933
10207
|
report.settled += 1
|
|
9934
10208
|
endedInPlace = true
|
|
@@ -28,6 +28,35 @@ import { readBuildFacts } from '../store/reduced-reads'
|
|
|
28
28
|
import { defineReducer } from '../kernel/incremental'
|
|
29
29
|
import type { BuildStore } from '../store/types'
|
|
30
30
|
|
|
31
|
+
/** A done or aborted build resumes nothing, so the sessions an exited
|
|
32
|
+
* execution left open are ended `reclaimed` (SPEC §15.6-C). Callers run this
|
|
33
|
+
* once the provider proves the execution exited and before they record
|
|
34
|
+
* `execution.ended`: a crash in between leaves the execution open, so the
|
|
35
|
+
* build stays visited and the next settlement repeats this. One reduced read
|
|
36
|
+
* per call, and a CAS write per leftover session. */
|
|
37
|
+
export async function endTerminalBuildSessions(
|
|
38
|
+
store: Pick<BuildStore, 'appendIfCurrent'> & Parameters<typeof readBuildFacts>[0],
|
|
39
|
+
slug: string,
|
|
40
|
+
instance: string,
|
|
41
|
+
): Promise<void> {
|
|
42
|
+
for (;;) {
|
|
43
|
+
const facts = await readBuildFacts(store, slug)
|
|
44
|
+
const { state } = facts.value
|
|
45
|
+
if (state.status !== 'done' && state.status !== 'aborted') return
|
|
46
|
+
const session = state.sessions.open[0]
|
|
47
|
+
if (session === undefined) return
|
|
48
|
+
await store.appendIfCurrent(slug, facts.cursor, {
|
|
49
|
+
actor: KERNEL,
|
|
50
|
+
type: 'session.ended',
|
|
51
|
+
payload: {
|
|
52
|
+
session: session.session,
|
|
53
|
+
outcome: 'reclaimed',
|
|
54
|
+
reclaimedBy: { instance, resumedFromSeq: state.lastSeq },
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
31
60
|
export interface OpenExecution {
|
|
32
61
|
instance: string
|
|
33
62
|
workspaceRef: string
|
|
@@ -218,6 +247,7 @@ export async function settleOpenExecution(
|
|
|
218
247
|
const request = (await readBuildFacts(deps.store, slug)).value.state.drainingExecutions?.[
|
|
219
248
|
open.instance
|
|
220
249
|
]?.relaunch
|
|
250
|
+
await endTerminalBuildSessions(deps.store, slug, open.instance)
|
|
221
251
|
const ended: EventWrite<'execution.ended'> =
|
|
222
252
|
observation.state === 'ended'
|
|
223
253
|
? {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PublicationRetryPersistenceError } from '../kernel/publication-retry'
|
|
2
2
|
import { ForgeRequestDeferred } from '../ports/forge-request-context'
|
|
3
3
|
import { isRemoteWorkspace } from '../events/workspace-remote'
|
|
4
|
+
import { isRepositoryAuthorityLapse } from '../cli/repo-lease'
|
|
4
5
|
import { isRecoveryDeferred, recoveryStepOf } from '../ports/workspace/recovery-step'
|
|
5
6
|
/**
|
|
6
7
|
* Last-chance publication settlement at the workspace-release boundary
|
|
@@ -136,3 +137,31 @@ export async function recordPublicationLossBeforeRelease(
|
|
|
136
137
|
})
|
|
137
138
|
return (await readBuildFacts(deps.store, slug)).value
|
|
138
139
|
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Whether a merged PR already contains a pending publication's commit, so its
|
|
143
|
+
* release needs no settlement (merged completion, SPEC §15.7). True when
|
|
144
|
+
* `request` equals a merged head, or a host-side ancestry proof shows it below
|
|
145
|
+
* one. `heads` names the PR's observed head first, then its landing: a squash
|
|
146
|
+
* landing never descends from the PR's commits, but the PR head does. An absent
|
|
147
|
+
* capability, an unknown object or a throwing proof is never coverage. A forge
|
|
148
|
+
* deferral or a lapsed repository lease still propagates.
|
|
149
|
+
*/
|
|
150
|
+
export async function mergedHeadCovers(
|
|
151
|
+
request: string,
|
|
152
|
+
heads: readonly (string | undefined)[],
|
|
153
|
+
isAncestor?: (ancestor: string, descendant: string) => Promise<boolean>,
|
|
154
|
+
): Promise<boolean> {
|
|
155
|
+
const known = heads.filter((head): head is string => head !== undefined && head !== '')
|
|
156
|
+
if (known.includes(request)) return true
|
|
157
|
+
if (isAncestor === undefined) return false
|
|
158
|
+
for (const head of known) {
|
|
159
|
+
try {
|
|
160
|
+
if (await isAncestor(request, head)) return true
|
|
161
|
+
} catch (error) {
|
|
162
|
+
if (error instanceof ForgeRequestDeferred || isRepositoryAuthorityLapse(error)) throw error
|
|
163
|
+
// Unknown ancestry proves nothing; try the next head.
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return false
|
|
167
|
+
}
|
|
@@ -103,7 +103,8 @@ export function isWorkDigest(digest: Omit<BuildDigest, 'slug'>): boolean {
|
|
|
103
103
|
digest.terminal === 'aborted' ||
|
|
104
104
|
digest.reclaimPending === true ||
|
|
105
105
|
digest.executionOpen === true ||
|
|
106
|
-
digest.rejectionsPending === true
|
|
106
|
+
digest.rejectionsPending === true ||
|
|
107
|
+
digest.releasePending === true
|
|
107
108
|
)
|
|
108
109
|
}
|
|
109
110
|
class Chain {
|
|
@@ -1250,6 +1250,49 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
1250
1250
|
})
|
|
1251
1251
|
})
|
|
1252
1252
|
|
|
1253
|
+
test('releasePending marks a completed merged build whose workspace is still open', async () => {
|
|
1254
|
+
await withStore(factory, undefined, async (store) => {
|
|
1255
|
+
const repo = 'acme/dg-release'
|
|
1256
|
+
const pending = async (slug: string) =>
|
|
1257
|
+
(await store.getRepoBuildDigests(repo)).get(slug)!.releasePending
|
|
1258
|
+
const seed = async (slug: string, closing: 'pr.merged' | 'pr.closed') => {
|
|
1259
|
+
await store.createBuild(sampleBuildInput(slug, { repo }))
|
|
1260
|
+
await store.append(slug, buildCreatedWrite())
|
|
1261
|
+
await store.append(slug, {
|
|
1262
|
+
actor: DISPATCHER,
|
|
1263
|
+
type: 'workspace.provisioned',
|
|
1264
|
+
payload: {
|
|
1265
|
+
provider: 'p',
|
|
1266
|
+
ref: 'w',
|
|
1267
|
+
branch: `ab/${slug}`,
|
|
1268
|
+
base: { source: 'remote', sha: 'a'.repeat(40) },
|
|
1269
|
+
},
|
|
1270
|
+
})
|
|
1271
|
+
await store.append(
|
|
1272
|
+
slug,
|
|
1273
|
+
closing === 'pr.merged'
|
|
1274
|
+
? { actor: DISPATCHER, type: 'pr.merged', payload: { sha: 'm' } }
|
|
1275
|
+
: { actor: DISPATCHER, type: 'pr.closed', payload: {} },
|
|
1276
|
+
)
|
|
1277
|
+
await store.append(slug, {
|
|
1278
|
+
actor: DISPATCHER,
|
|
1279
|
+
type: 'build.completed',
|
|
1280
|
+
payload: { outcome: closing === 'pr.merged' ? 'merged' : 'closed-unmerged' },
|
|
1281
|
+
})
|
|
1282
|
+
}
|
|
1283
|
+
await seed('dg-merged', 'pr.merged')
|
|
1284
|
+
await seed('dg-closed', 'pr.closed')
|
|
1285
|
+
expect(await pending('dg-merged')).toBe(true)
|
|
1286
|
+
expect(await pending('dg-closed')).toBeUndefined()
|
|
1287
|
+
await store.append('dg-merged', {
|
|
1288
|
+
actor: DISPATCHER,
|
|
1289
|
+
type: 'workspace.released',
|
|
1290
|
+
payload: { ref: 'w', reason: 'completion' },
|
|
1291
|
+
})
|
|
1292
|
+
expect(await pending('dg-merged')).toBeUndefined()
|
|
1293
|
+
})
|
|
1294
|
+
})
|
|
1295
|
+
|
|
1253
1296
|
test('rejectionsPending follows non-accepted attempt settlements until their ticket moves', async () => {
|
|
1254
1297
|
await withStore(factory, undefined, async (store) => {
|
|
1255
1298
|
const repo = 'acme/dg-opt'
|
|
@@ -50,6 +50,10 @@ export const DIGEST_EVENT_TYPES = [
|
|
|
50
50
|
'pr-attachment.reclaimed',
|
|
51
51
|
'execution.started',
|
|
52
52
|
'execution.ended',
|
|
53
|
+
// The open workspace a merged build's completion still has to release.
|
|
54
|
+
'workspace.provisioned',
|
|
55
|
+
'workspace.cleanup-required',
|
|
56
|
+
'workspace.released',
|
|
53
57
|
'wait.requested',
|
|
54
58
|
'wait.refused',
|
|
55
59
|
'wait.entered',
|
|
@@ -128,6 +132,9 @@ export interface DigestAcc {
|
|
|
128
132
|
executionFacts: number
|
|
129
133
|
/** Sorted unique node slugs any target or parent move has named. */
|
|
130
134
|
nodeTargets: string[]
|
|
135
|
+
/** The latest `workspace.provisioned` / `workspace.cleanup-required` has no
|
|
136
|
+
* later `workspace.released` (the `openBuildWorkspace` rule). */
|
|
137
|
+
workspaceOpen: boolean
|
|
131
138
|
/** The latest ticket-wait fact is a request without its outcome. */
|
|
132
139
|
waitPending?: true
|
|
133
140
|
/** The entered ticket wait that has not ended. */
|
|
@@ -195,6 +202,7 @@ export const buildDigestReducer: IncrementalReducer<
|
|
|
195
202
|
openInstance: null,
|
|
196
203
|
executionFacts: 0,
|
|
197
204
|
nodeTargets: [],
|
|
205
|
+
workspaceOpen: false,
|
|
198
206
|
}),
|
|
199
207
|
fold(acc, events) {
|
|
200
208
|
for (const event of events) {
|
|
@@ -266,7 +274,13 @@ export const buildDigestReducer: IncrementalReducer<
|
|
|
266
274
|
const remaining = acc.pendingRejections.filter((p) => p !== event.attemptProposal)
|
|
267
275
|
acc.pendingRejections = remaining.length > 0 ? remaining : undefined
|
|
268
276
|
}
|
|
269
|
-
} else if (
|
|
277
|
+
} else if (
|
|
278
|
+
event.type === 'workspace.provisioned' ||
|
|
279
|
+
event.type === 'workspace.cleanup-required'
|
|
280
|
+
)
|
|
281
|
+
acc.workspaceOpen = true
|
|
282
|
+
else if (event.type === 'workspace.released') acc.workspaceOpen = false
|
|
283
|
+
else if (event.type === 'execution.started') {
|
|
270
284
|
acc.executionFacts += 1
|
|
271
285
|
acc.openInstance = event.instance ?? null
|
|
272
286
|
} else if (event.type === 'execution.ended') {
|
|
@@ -299,6 +313,7 @@ export const buildDigestReducer: IncrementalReducer<
|
|
|
299
313
|
optimization,
|
|
300
314
|
proposerWakeSeq,
|
|
301
315
|
proposerDeferredSeq,
|
|
316
|
+
workspaceOpen,
|
|
302
317
|
}) => {
|
|
303
318
|
const reclaimedSet = new Set(reclaimed)
|
|
304
319
|
const reclaimPending = hosted.some((seq) => !reclaimedSet.has(seq))
|
|
@@ -322,6 +337,9 @@ export const buildDigestReducer: IncrementalReducer<
|
|
|
322
337
|
...(waitPending ? { waitPending } : {}),
|
|
323
338
|
...(ticketWait !== undefined ? { ticketWait: structuredClone(ticketWait) } : {}),
|
|
324
339
|
...(pendingRejections?.length ? { rejectionsPending: true as const } : {}),
|
|
340
|
+
...(terminal === 'done' && merged !== undefined && workspaceOpen
|
|
341
|
+
? { releasePending: true as const }
|
|
342
|
+
: {}),
|
|
325
343
|
nodeTargets: [...nodeTargets],
|
|
326
344
|
...(kind === 'node'
|
|
327
345
|
? {
|