@defrex/autobuild 1.2.0 → 1.4.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 +416 -36
- package/docs/accounts.md +50 -1
- package/docs/answering-blocked-builds.md +4 -1
- package/docs/architecture.md +298 -17
- package/docs/build-store.md +18 -0
- package/docs/builds.md +7 -1
- package/docs/cli.md +1 -1
- package/docs/configuration-overview.md +6 -0
- package/docs/configuration.md +44 -19
- package/docs/dispatcher-hosting.md +42 -0
- package/docs/dispatcher.md +41 -0
- package/docs/forges.md +5 -0
- package/docs/integration-tree.md +24 -5
- package/docs/operating.md +11 -3
- package/docs/operator-api.md +81 -10
- package/docs/operator-surfaces.md +29 -0
- package/docs/plugin-authoring.md +51 -2
- package/docs/remote-store-protocol.md +321 -46
- package/docs/remote-ticket-protocol.md +12 -10
- package/docs/restacking.md +105 -3
- package/docs/setup.md +37 -8
- package/docs/skills.md +1 -1
- package/docs/spec-standard.md +41 -5
- package/docs/ticket-dependencies.md +8 -0
- package/docs/troubleshooting.md +9 -0
- package/docs/workspaces.md +1 -1
- package/package.json +4 -3
- package/packages/core/src/accounts/availability.ts +96 -0
- package/packages/core/src/accounts/local-owner.ts +49 -2
- package/packages/core/src/cli/attention.ts +2 -0
- package/packages/core/src/cli/binary.ts +17 -1
- package/packages/core/src/cli/context.ts +62 -0
- package/packages/core/src/cli/dashboard/model.ts +12 -3
- package/packages/core/src/cli/dashboard/poll.ts +65 -8
- package/packages/core/src/cli/dashboard/refresh.ts +2 -0
- package/packages/core/src/cli/dashboard/render.ts +46 -5
- package/packages/core/src/cli/dispatch-args.ts +27 -3
- package/packages/core/src/cli/dispatch-frontend.ts +179 -52
- package/packages/core/src/cli/dispatch-mode.ts +94 -0
- package/packages/core/src/cli/dispatch-preflight.ts +43 -0
- package/packages/core/src/cli/dispatch-repository-feed.ts +150 -33
- package/packages/core/src/cli/dispatch.ts +209 -36
- package/packages/core/src/cli/dispatcher-liveness.ts +6 -1
- package/packages/core/src/cli/forge-clear.ts +30 -0
- package/packages/core/src/cli/harvest.ts +2 -1
- package/packages/core/src/cli/help.ts +17 -3
- package/packages/core/src/cli/historical-build-state.ts +6 -0
- package/packages/core/src/cli/main.ts +43 -2
- package/packages/core/src/cli/publication-settlement.ts +17 -0
- package/packages/core/src/cli/remote-poll.ts +11 -1
- package/packages/core/src/cli/repository-status.ts +11 -0
- package/packages/core/src/cli/status.ts +7 -1
- package/packages/core/src/cli/wait.ts +9 -2
- package/packages/core/src/cli/watch.ts +47 -16
- package/packages/core/src/config/roles.ts +16 -1
- package/packages/core/src/events/catalog.ts +8 -0
- package/packages/core/src/events/forge-degradation-policy.ts +11 -0
- package/packages/core/src/events/payloads.ts +95 -2
- package/packages/core/src/events/policy.ts +19 -0
- package/packages/core/src/events/repository.ts +108 -2
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +464 -0
- package/packages/core/src/kernel/change-presence.ts +74 -8
- package/packages/core/src/kernel/dispatch-placement.ts +30 -0
- package/packages/core/src/kernel/engine.ts +27 -12
- package/packages/core/src/kernel/generators/leaf-restack-log.ts +17 -1
- package/packages/core/src/kernel/generators/node-restack-log.ts +14 -0
- package/packages/core/src/kernel/leaf-restack-state.ts +24 -2
- package/packages/core/src/kernel/log-index.ts +1 -1
- package/packages/core/src/kernel/node-landing.ts +27 -10
- package/packages/core/src/kernel/node-polling.ts +40 -7
- package/packages/core/src/kernel/node-restack-demand.ts +75 -0
- package/packages/core/src/kernel/node-restack-state.ts +20 -1
- package/packages/core/src/kernel/node-restack-transaction.ts +47 -1
- package/packages/core/src/kernel/read-facts.ts +120 -9
- package/packages/core/src/kernel/reconcile-head.ts +34 -11
- package/packages/core/src/kernel/reconcile-restack.ts +106 -72
- package/packages/core/src/kernel/reducer-registry.ts +6 -0
- package/packages/core/src/kernel/reducer.ts +20 -2
- package/packages/core/src/kernel/replay-retention.ts +176 -0
- package/packages/core/src/kernel/target-lineage.ts +65 -0
- package/packages/core/src/kernel/target-observation.ts +117 -0
- package/packages/core/src/kernel/ticket-preparation.ts +66 -0
- package/packages/core/src/operator/annotations.ts +6 -0
- package/packages/core/src/operator/control.ts +20 -0
- package/packages/core/src/operator/index.ts +2 -0
- package/packages/core/src/operator/registry.ts +25 -13
- package/packages/core/src/operator/tickets.ts +8 -2
- package/packages/core/src/plugin-sdk/index.ts +1 -0
- package/packages/core/src/ports/forge/fake.ts +22 -0
- package/packages/core/src/ports/forge/git-rewrite.ts +49 -12
- package/packages/core/src/ports/forge/github.ts +42 -10
- package/packages/core/src/ports/forge/local-git.ts +16 -1
- package/packages/core/src/ports/runner/account-env.ts +60 -9
- package/packages/core/src/ports/runner/claude.ts +49 -45
- package/packages/core/src/ports/types.ts +58 -4
- package/packages/core/src/ports/workspace/account-policy.ts +2 -1
- package/packages/core/src/ports/workspace/commit-preservation.ts +175 -0
- package/packages/core/src/ports/workspace/create.ts +2 -0
- package/packages/core/src/ports/workspace/fake.ts +4 -0
- package/packages/core/src/ports/workspace/git-worktree.ts +22 -1
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +304 -56
- package/packages/core/src/processes/build-runner.ts +240 -111
- package/packages/core/src/processes/dispatcher-selectors.ts +3 -2
- package/packages/core/src/processes/dispatcher.ts +732 -201
- package/packages/core/src/processes/execution-no-progress.ts +8 -0
- package/packages/core/src/processes/harvest-runner.ts +6 -7
- package/packages/core/src/processes/harvest.ts +11 -16
- package/packages/core/src/processes/publication-state.ts +2 -1
- package/packages/core/src/processes/repo-view.ts +25 -0
- package/packages/core/src/processes/workspace-preservation.ts +164 -0
- package/packages/core/src/scenarios/harness.ts +7 -0
- package/packages/core/src/store/adapter.ts +9 -0
- package/packages/core/src/store/artifact-meta.ts +7 -0
- package/packages/core/src/store/build-scope.ts +28 -0
- package/packages/core/src/store/contract.ts +182 -0
- package/packages/core/src/store/event-reads.ts +156 -0
- package/packages/core/src/store/local/schema.ts +11 -0
- package/packages/core/src/store/local/store.ts +117 -2
- package/packages/core/src/store/memory.ts +241 -0
- package/packages/core/src/store/phase-session.ts +47 -0
- package/packages/core/src/store/reduced-reads.ts +8 -0
- package/packages/core/src/store/reducer-value-shapes.json +10546 -8877
- package/packages/core/src/store/reducer-value-validation.ts +109 -6
- package/packages/core/src/store/reducer-values.ts +62 -2
- package/packages/core/src/store/remote/client.ts +208 -23
- package/packages/core/src/store/remote/compatibility.ts +195 -25
- package/packages/core/src/store/remote/errors.ts +16 -0
- package/packages/core/src/store/remote/index.ts +17 -0
- package/packages/core/src/store/remote/protocol.ts +30 -1
- package/packages/core/src/store/remote/released-clients.json +37 -0
- package/packages/core/src/store/remote/released-clients.ts +88 -0
- package/packages/core/src/store/remote/released-reducer-values/1.2.0.json +8129 -0
- package/packages/core/src/store/remote/released-reducer-values/1.3.0.json +25093 -0
- package/packages/core/src/store/remote/released-reducer-values/1.4.0.json +26128 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +13 -0
- package/packages/core/src/store/remote/version.ts +8 -1
- package/packages/core/src/store/repo-state-events.ts +6 -3
- package/packages/core/src/store/scan-cadence.ts +15 -0
- package/packages/core/src/store/session-handle.ts +18 -0
- package/packages/core/src/store/snapshots.ts +16 -3
- package/packages/core/src/store/types.ts +29 -6
- package/packages/core/src/testing/dispatch-read-budget.ts +457 -7
- package/packages/core/src/testing/index.ts +6 -1
- package/packages/core/src/testing/reduced-read-budget.ts +1240 -9
- package/skills/guide/SKILL.md +220 -22
- package/skills/guide/references/accounts.md +50 -1
- package/skills/guide/references/integration-tree.md +24 -5
- package/skills/guide/references/operator-api.md +81 -10
- package/skills/guide/references/plugin-authoring.md +51 -2
- package/skills/guide/references/remote-store-protocol.md +321 -46
- package/skills/guide/references/remote-ticket-protocol.md +12 -10
- package/skills/guide/references/restacking.md +105 -3
- package/skills/guide/references/setup.md +37 -8
- package/skills/guide/references/spec-standard.md +41 -5
- package/skills/guide/references/ticket-dependencies.md +8 -0
- package/skills/implement/SKILL.md +12 -3
- package/skills/operate/SKILL.md +85 -12
- package/skills/plan/SKILL.md +27 -4
- package/skills/plan-review/SKILL.md +22 -2
- package/skills/reconcile/SKILL.md +16 -1
- package/skills/spec/SKILL.md +7 -4
- package/skills/tickets/SKILL.md +7 -3
- package/templates/hosted-service/package.json +2 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { nodeRestackDemand } from './node-restack-demand'
|
|
1
|
+
import { nodeRestackDemand, restackAvailabilityFingerprint } from './node-restack-demand'
|
|
2
|
+
import { observeTarget } from './target-observation'
|
|
2
3
|
import { deferMixedVersion, MixedVersionDeferral } from './mixed-version'
|
|
3
4
|
import { suspendNativeLanding } from './landing-publication'
|
|
4
5
|
import { observePresence, presenceInputs } from './change-presence'
|
|
@@ -18,6 +19,9 @@ import {
|
|
|
18
19
|
} from './node-restack'
|
|
19
20
|
|
|
20
21
|
export interface NodeTransactionDeps extends RestackDeps {
|
|
22
|
+
/** Confirm targeting-leaf native landing suspension before reservation and
|
|
23
|
+
* again when recovering a frozen replay. Operation identities survive restart. */
|
|
24
|
+
beforeReplay?: (operation: string) => Promise<void>
|
|
21
25
|
holder: string
|
|
22
26
|
/** Lifecycle and writer authority are rechecked at each effect boundary. */
|
|
23
27
|
canWrite: () => Promise<boolean>
|
|
@@ -88,6 +92,19 @@ export async function runNodeTransaction(
|
|
|
88
92
|
const oldBase = source ? boundaries[source]! : state.nodeOpened?.sha
|
|
89
93
|
if (!oldBase) throw new Error('node source provenance unavailable; operator review required')
|
|
90
94
|
const parent = await snapshotParent(deps, input.parentBranch, `${destinationRef}-parent-head`)
|
|
95
|
+
const admission = await observeTarget({
|
|
96
|
+
store: deps.store,
|
|
97
|
+
forge: deps.forge,
|
|
98
|
+
slug: deps.slug,
|
|
99
|
+
branch: input.parentBranch,
|
|
100
|
+
sha: parent,
|
|
101
|
+
enforceUsedBaseline: true,
|
|
102
|
+
actor: KERNEL,
|
|
103
|
+
})
|
|
104
|
+
if (admission === 'rejected') return 'idle'
|
|
105
|
+
state = await current(deps.store, deps.slug)
|
|
106
|
+
revision = state.lastSeq
|
|
107
|
+
node = state.nodeRestack
|
|
91
108
|
// Observe immutable Git distance even while the node intentionally trails.
|
|
92
109
|
const base = node?.contributionBase ?? oldBase
|
|
93
110
|
if (
|
|
@@ -162,6 +179,29 @@ export async function runNodeTransaction(
|
|
|
162
179
|
request.branch === input.parentBranch &&
|
|
163
180
|
(request.identities ?? []).every((id) => new Set<string>(upstream).has(id)),
|
|
164
181
|
)
|
|
182
|
+
const fingerprint = restackAvailabilityFingerprint(
|
|
183
|
+
state,
|
|
184
|
+
input.branch,
|
|
185
|
+
input.parentBranch,
|
|
186
|
+
expected,
|
|
187
|
+
parent,
|
|
188
|
+
evidence,
|
|
189
|
+
)
|
|
190
|
+
if (node?.availability?.fingerprint !== fingerprint)
|
|
191
|
+
await append({
|
|
192
|
+
actor: KERNEL,
|
|
193
|
+
type: 'node.restack-availability-observed',
|
|
194
|
+
payload: {
|
|
195
|
+
version: 1,
|
|
196
|
+
fingerprint,
|
|
197
|
+
branch: input.branch,
|
|
198
|
+
parentBranch: input.parentBranch,
|
|
199
|
+
head: expected,
|
|
200
|
+
parent,
|
|
201
|
+
base,
|
|
202
|
+
available: availableRequests.map((r) => r.id).sort(),
|
|
203
|
+
},
|
|
204
|
+
})
|
|
165
205
|
const demanded = nodeRestackDemand({
|
|
166
206
|
...state,
|
|
167
207
|
nodeRestack: {
|
|
@@ -183,6 +223,10 @@ export async function runNodeTransaction(
|
|
|
183
223
|
})
|
|
184
224
|
return 'idle'
|
|
185
225
|
}
|
|
226
|
+
await deps.beforeReplay?.(input.id)
|
|
227
|
+
await authority(deps)
|
|
228
|
+
if ((await current(deps.store, deps.slug)).lastSeq !== revision)
|
|
229
|
+
throw new Error('node inputs changed during native cancellation')
|
|
186
230
|
const frozen = await prepareNodeReplay(deps, { oldBase, oldHead: expected, parent }, evidence)
|
|
187
231
|
// Preserve frozen source objects before the reservation can survive a
|
|
188
232
|
// workspace loss. Archives also retain the previous boundary's history.
|
|
@@ -236,6 +280,8 @@ export async function runNodeTransaction(
|
|
|
236
280
|
})
|
|
237
281
|
return runNodeTransaction(deps, input)
|
|
238
282
|
}
|
|
283
|
+
await deps.beforeReplay?.(active.id)
|
|
284
|
+
await authority(deps)
|
|
239
285
|
const frozen = { ...active, oldHead: active.expected }
|
|
240
286
|
assertSafeNodeReplay(frozen)
|
|
241
287
|
const replayEvidence = {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ticketPreparationReducer } from './ticket-preparation'
|
|
1
2
|
import { ticketMigrationsReducer } from './ticket-migrations'
|
|
2
3
|
import { dispatchUpgradeReducer } from './dispatch-upgrade'
|
|
3
4
|
import {
|
|
@@ -9,7 +10,7 @@ import {
|
|
|
9
10
|
import { awaitsConsent } from './landing-readiness'
|
|
10
11
|
import { leafRestackReducer, type LeafRestackState } from './leaf-restack-state'
|
|
11
12
|
import { landingCandidateId } from './landing-policy'
|
|
12
|
-
import { referencedGitTips } from './reconcile-head'
|
|
13
|
+
import { referencesGitHistory, referencedGitTips } from './reconcile-head'
|
|
13
14
|
import { encodeLog } from './log-index-value'
|
|
14
15
|
import { summaryBoundaryReducer, summaryRequestsReducer } from './pr-summary'
|
|
15
16
|
import { infrastructureFailureResetReducer } from '../processes/infrastructure-failure-budget'
|
|
@@ -155,7 +156,13 @@ export interface BuildReadAcc {
|
|
|
155
156
|
summaryRequested: Record<string, Extract<AbEvent, { type: 'pr-summary.requested' }>>
|
|
156
157
|
summaryEligibleAfter?: string
|
|
157
158
|
finalizePublicationRequested: boolean
|
|
158
|
-
|
|
159
|
+
workspaceFence?: Extract<AbEvent, { type: 'workspace.fenced' }>
|
|
160
|
+
workspacePreservation?: Extract<AbEvent, { type: 'workspace.commits-preserved' }>
|
|
161
|
+
workspaceLoss?: Extract<AbEvent, { type: 'workspace.commits-lost' }>
|
|
162
|
+
latestWorkspace?: Extract<
|
|
163
|
+
AbEvent,
|
|
164
|
+
{ type: 'workspace.provisioned' | 'workspace.cleanup-required' }
|
|
165
|
+
>
|
|
159
166
|
findings: Record<string, import('../ontology').Finding>
|
|
160
167
|
planFeedback: Record<string, import('../ontology').Feedback | null>
|
|
161
168
|
feedback: Record<string, import('../ontology').Feedback | null>
|
|
@@ -165,6 +172,16 @@ export interface BuildReadAcc {
|
|
|
165
172
|
{ type: `reconcile.${string}` | 'workspace.provisioned' | 'phase.failed' }
|
|
166
173
|
>[]
|
|
167
174
|
restackHistory: Extract<AbEvent, { type: `restack.${string}` }>[]
|
|
175
|
+
candidateRecoveries: Partial<
|
|
176
|
+
Record<
|
|
177
|
+
'reconcile' | 'restack',
|
|
178
|
+
import('../events/payloads').EventPayload<'publication.candidate-retired'>
|
|
179
|
+
>
|
|
180
|
+
>
|
|
181
|
+
candidateRecoverySeqs: Partial<Record<'reconcile' | 'restack', number>>
|
|
182
|
+
/** The two latest logical session starts; continuations keep their root's start. */
|
|
183
|
+
sessionStarts: Array<{ session: string; seq: number }>
|
|
184
|
+
tipSources: Record<string, string[]>
|
|
168
185
|
gitTips: string[]
|
|
169
186
|
reconcileTransaction?: import('../events/payloads').EventPayload<'reconcile.prepared'>
|
|
170
187
|
reconcileReplay?: import('../events/payloads').EventPayload<'reconcile.replayed'>
|
|
@@ -200,7 +217,7 @@ export interface BuildReadAcc {
|
|
|
200
217
|
}
|
|
201
218
|
export const buildReadFactsReducer = defineReducer({
|
|
202
219
|
rawEvents: true,
|
|
203
|
-
version:
|
|
220
|
+
version: 6 + Object.values(parts).reduce((sum, reducer) => sum + reducer.version, 0),
|
|
204
221
|
initial: (): BuildReadAcc => ({
|
|
205
222
|
runnerAttaches: [],
|
|
206
223
|
summaryRequests: summaryRequestsReducer.initial(),
|
|
@@ -234,6 +251,10 @@ export const buildReadFactsReducer = defineReducer({
|
|
|
234
251
|
reconcileBases: {},
|
|
235
252
|
reconcileHistory: [],
|
|
236
253
|
restackHistory: [],
|
|
254
|
+
candidateRecoveries: {},
|
|
255
|
+
candidateRecoverySeqs: {},
|
|
256
|
+
sessionStarts: [],
|
|
257
|
+
tipSources: {},
|
|
237
258
|
gitTips: [],
|
|
238
259
|
maxPlanRevision: -1,
|
|
239
260
|
seenTypes: [],
|
|
@@ -308,7 +329,28 @@ export const buildReadFactsReducer = defineReducer({
|
|
|
308
329
|
acc.summaryEligibleAfter = event.payload.eligibleAfter
|
|
309
330
|
if (event.type === 'publication.requested' && event.payload.operation === 'finalize')
|
|
310
331
|
acc.finalizePublicationRequested = true
|
|
311
|
-
|
|
332
|
+
// Keep checkpoints through repeated replacements, but never restore an old
|
|
333
|
+
// branch over a durably acknowledged rewrite of the public branch.
|
|
334
|
+
if (event.type === 'reconcile.rewritten' || event.type === 'restack.rewritten')
|
|
335
|
+
delete acc.workspacePreservation
|
|
336
|
+
if (event.type === 'session.started') {
|
|
337
|
+
const last = acc.sessionStarts.at(-1)
|
|
338
|
+
if (event.payload.continuation && last?.session === event.payload.continuation.predecessor)
|
|
339
|
+
acc.sessionStarts[acc.sessionStarts.length - 1] = {
|
|
340
|
+
...last,
|
|
341
|
+
session: event.payload.session,
|
|
342
|
+
}
|
|
343
|
+
else
|
|
344
|
+
acc.sessionStarts = [
|
|
345
|
+
...acc.sessionStarts.slice(-1),
|
|
346
|
+
{ session: event.payload.session, seq: event.seq },
|
|
347
|
+
]
|
|
348
|
+
}
|
|
349
|
+
if (event.type === 'workspace.fenced') acc.workspaceFence = event
|
|
350
|
+
if (event.type === 'workspace.commits-preserved') acc.workspacePreservation = event
|
|
351
|
+
if (event.type === 'workspace.commits-lost') acc.workspaceLoss = event
|
|
352
|
+
if (event.type === 'workspace.provisioned' || event.type === 'workspace.cleanup-required')
|
|
353
|
+
acc.latestWorkspace = event
|
|
312
354
|
if (event.type === 'plan-review.verdict')
|
|
313
355
|
acc.planFeedback[String(event.payload.round + 1)] =
|
|
314
356
|
event.payload.verdict === 'revise'
|
|
@@ -329,8 +371,41 @@ export const buildReadFactsReducer = defineReducer({
|
|
|
329
371
|
event.payload.feedback ?? null
|
|
330
372
|
if (event.type.startsWith('restack.'))
|
|
331
373
|
acc.restackHistory.push(event as Extract<AbEvent, { type: `restack.${string}` }>)
|
|
332
|
-
|
|
333
|
-
|
|
374
|
+
if (event.type === 'publication.candidate-retired') {
|
|
375
|
+
acc.candidateRecoveries[event.payload.operation] = event.payload
|
|
376
|
+
acc.candidateRecoverySeqs[event.payload.operation] = event.seq
|
|
377
|
+
if (
|
|
378
|
+
event.payload.operation === 'reconcile' &&
|
|
379
|
+
acc.reconcileTransaction?.id === event.payload.id
|
|
380
|
+
)
|
|
381
|
+
delete acc.reconcileReplay
|
|
382
|
+
const sources = acc.tipSources[event.payload.sha]
|
|
383
|
+
if (sources) {
|
|
384
|
+
acc.tipSources[event.payload.sha] = sources.filter(
|
|
385
|
+
(source) => source !== `${event.payload.operation}:${event.payload.id}`,
|
|
386
|
+
)
|
|
387
|
+
if (!acc.tipSources[event.payload.sha]!.length) {
|
|
388
|
+
delete acc.tipSources[event.payload.sha]
|
|
389
|
+
acc.gitTips = acc.gitTips.filter((tip) => tip !== event.payload.sha)
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
// Most events carry no Git history. Skip the allocating history selector
|
|
394
|
+
// entirely on that hot path; retirement is handled independently above.
|
|
395
|
+
if (referencesGitHistory(event.type))
|
|
396
|
+
for (const tip of referencedGitTips([event])) {
|
|
397
|
+
const ephemeral =
|
|
398
|
+
(event.type === 'reconcile.publish-intended' ||
|
|
399
|
+
event.type === 'restack.publish-intended') &&
|
|
400
|
+
event.payload.headSha === tip
|
|
401
|
+
const source = ephemeral ? `${event.type.split('.')[0]}:${event.payload.id}` : 'proven'
|
|
402
|
+
if (!acc.tipSources[tip]) {
|
|
403
|
+
acc.tipSources[tip] = []
|
|
404
|
+
acc.gitTips.push(tip)
|
|
405
|
+
}
|
|
406
|
+
if (!acc.tipSources[tip]!.includes(source)) acc.tipSources[tip]!.push(source)
|
|
407
|
+
}
|
|
408
|
+
|
|
334
409
|
if (
|
|
335
410
|
event.type === 'reconcile.started' ||
|
|
336
411
|
event.type === 'reconcile.completed' ||
|
|
@@ -382,7 +457,8 @@ export const buildReadFactsReducer = defineReducer({
|
|
|
382
457
|
acc.created ??= event
|
|
383
458
|
acc.lastCreated = event
|
|
384
459
|
}
|
|
385
|
-
if (event.type === 'workspace.provisioned'
|
|
460
|
+
if (event.type === 'workspace.provisioned' || event.type === 'workspace.cleanup-required')
|
|
461
|
+
acc.workspaceGenerations++
|
|
386
462
|
if (event.type === 'workspace.released') acc.latestRelease = event
|
|
387
463
|
if (event.type === 'dispatch.failed') {
|
|
388
464
|
acc.dispatchFailureCount++
|
|
@@ -432,6 +508,9 @@ export const buildReadFactsReducer = defineReducer({
|
|
|
432
508
|
summaryEligibleAfter: acc.summaryEligibleAfter,
|
|
433
509
|
finalizePublicationRequested: acc.finalizePublicationRequested,
|
|
434
510
|
latestWorkspace: acc.latestWorkspace,
|
|
511
|
+
workspaceFence: acc.workspaceFence,
|
|
512
|
+
workspacePreservation: acc.workspacePreservation,
|
|
513
|
+
workspaceLoss: acc.workspaceLoss,
|
|
435
514
|
planFeedback: structuredClone(acc.planFeedback),
|
|
436
515
|
findings: structuredClone(acc.findings),
|
|
437
516
|
feedback: structuredClone(acc.feedback),
|
|
@@ -439,6 +518,10 @@ export const buildReadFactsReducer = defineReducer({
|
|
|
439
518
|
reconcileHistory: structuredClone(acc.reconcileHistory),
|
|
440
519
|
restackHistory: structuredClone(acc.restackHistory),
|
|
441
520
|
gitTips: [...acc.gitTips],
|
|
521
|
+
candidateRecoveries: structuredClone(acc.candidateRecoveries),
|
|
522
|
+
candidateRecoverySeqs: { ...acc.candidateRecoverySeqs },
|
|
523
|
+
sessionStarts: acc.sessionStarts.map((start) => ({ ...start })),
|
|
524
|
+
tipSources: structuredClone(acc.tipSources),
|
|
442
525
|
reconcileTransaction: acc.reconcileTransaction,
|
|
443
526
|
reconcileReplay: acc.reconcileReplay,
|
|
444
527
|
firstWorkspace: acc.firstWorkspace,
|
|
@@ -481,6 +564,8 @@ import { dispatchStatusReducer } from './dispatch-status'
|
|
|
481
564
|
* correlations outside it use the explicitly parameterized cache. */
|
|
482
565
|
export const RECENT_DISPATCH_RUN_LIMIT = 16
|
|
483
566
|
export interface RepositoryReadAcc {
|
|
567
|
+
missingAccounts: Record<string, import('../accounts/availability').MissingAccountCredential>
|
|
568
|
+
preparation: ReturnType<typeof ticketPreparationReducer.initial>
|
|
484
569
|
compatibility: CompatibilityState
|
|
485
570
|
presence: Record<
|
|
486
571
|
string,
|
|
@@ -494,6 +579,10 @@ export interface RepositoryReadAcc {
|
|
|
494
579
|
string,
|
|
495
580
|
{ count: number; latest: Extract<RepositoryEvent, { type: 'harvest.failed' }> }
|
|
496
581
|
>
|
|
582
|
+
harvestTerminals: Record<
|
|
583
|
+
string,
|
|
584
|
+
Extract<RepositoryEvent, { type: 'harvest.proposals.submitted' | 'harvest.review.verdict' }>
|
|
585
|
+
>
|
|
497
586
|
harvestVerdicts: Record<
|
|
498
587
|
string,
|
|
499
588
|
{
|
|
@@ -522,6 +611,7 @@ export interface RepositoryReadAcc {
|
|
|
522
611
|
sandboxes: ReturnType<typeof sandboxStatesReducer.initial>
|
|
523
612
|
status: ReturnType<ReturnType<typeof dispatchStatusReducer>['initial']>
|
|
524
613
|
run?: string
|
|
614
|
+
scanSeq?: number
|
|
525
615
|
scan?: Extract<RepositoryEvent, { type: 'dispatcher.ticket-scan-completed' }>['payload']
|
|
526
616
|
recentRuns: [string, DispatcherRunFacts][]
|
|
527
617
|
latestRun?: string
|
|
@@ -531,9 +621,10 @@ export interface RepositoryReadAcc {
|
|
|
531
621
|
export const repositoryReadFactsReducer = defineReducer({
|
|
532
622
|
rawEvents: true,
|
|
533
623
|
version:
|
|
534
|
-
|
|
624
|
+
6 +
|
|
535
625
|
ticketMigrationsReducer.version +
|
|
536
626
|
dispatchUpgradeReducer.version +
|
|
627
|
+
ticketPreparationReducer.version +
|
|
537
628
|
dispatcherRunFactsReducer('version').version +
|
|
538
629
|
openHarvestExecutionsReducer.version +
|
|
539
630
|
forgeHealthReducer.version +
|
|
@@ -546,8 +637,10 @@ export const repositoryReadFactsReducer = defineReducer({
|
|
|
546
637
|
sandboxStatesReducer.version +
|
|
547
638
|
dispatchStatusReducer('version').version,
|
|
548
639
|
initial: (): RepositoryReadAcc => ({
|
|
640
|
+
missingAccounts: {},
|
|
549
641
|
compatibility: initialCompatibility(),
|
|
550
642
|
presence: {},
|
|
643
|
+
preparation: ticketPreparationReducer.initial(),
|
|
551
644
|
upgrades: dispatchUpgradeReducer.initial(),
|
|
552
645
|
recentRuns: [],
|
|
553
646
|
openHarvest: openHarvestExecutionsReducer.initial(),
|
|
@@ -557,6 +650,7 @@ export const repositoryReadFactsReducer = defineReducer({
|
|
|
557
650
|
harvestSessions: [],
|
|
558
651
|
harvestSessionEndings: {},
|
|
559
652
|
harvestFailures: {},
|
|
653
|
+
harvestTerminals: {},
|
|
560
654
|
harvestVerdicts: {},
|
|
561
655
|
harvestAuthorizations: {},
|
|
562
656
|
latestHarvestResumedSeq: 0,
|
|
@@ -573,6 +667,7 @@ export const repositoryReadFactsReducer = defineReducer({
|
|
|
573
667
|
publications: [],
|
|
574
668
|
}),
|
|
575
669
|
fold(acc: RepositoryReadAcc, events: readonly RepositoryEvent[]) {
|
|
670
|
+
acc.preparation = ticketPreparationReducer.advance(acc.preparation, events)
|
|
576
671
|
advanceCompatibility(acc.compatibility, events)
|
|
577
672
|
acc.upgrades = dispatchUpgradeReducer.advance(acc.upgrades, events)
|
|
578
673
|
acc.attention = repositoryAttentionReducer.advance(acc.attention, events)
|
|
@@ -586,6 +681,10 @@ export const repositoryReadFactsReducer = defineReducer({
|
|
|
586
681
|
acc.config = effectiveConfigReducer.advance(acc.config, events)
|
|
587
682
|
acc.sandboxes = sandboxStatesReducer.advance(acc.sandboxes, events)
|
|
588
683
|
for (const event of projectEvents(events)) {
|
|
684
|
+
if (event.type === 'account.credentials-unavailable')
|
|
685
|
+
acc.missingAccounts[event.payload.name] = event.payload
|
|
686
|
+
if (event.type === 'account.credentials-recovered')
|
|
687
|
+
delete acc.missingAccounts[event.payload.name]
|
|
589
688
|
if (event.type === 'change-presence.observed')
|
|
590
689
|
acc.presence[event.payload.destination] = event.payload
|
|
591
690
|
if (event.type === 'harvest.failed') {
|
|
@@ -595,6 +694,11 @@ export const repositoryReadFactsReducer = defineReducer({
|
|
|
595
694
|
latest: event,
|
|
596
695
|
}
|
|
597
696
|
}
|
|
697
|
+
if (
|
|
698
|
+
(event.type === 'harvest.proposals.submitted' || event.type === 'harvest.review.verdict') &&
|
|
699
|
+
event.actor.kind === 'agent'
|
|
700
|
+
)
|
|
701
|
+
acc.harvestTerminals[event.actor.session] = event
|
|
598
702
|
if (event.type === 'harvest.review.verdict') {
|
|
599
703
|
const key = JSON.stringify([event.payload.run, event.payload.round])
|
|
600
704
|
acc.harvestVerdicts[key] = {
|
|
@@ -648,7 +752,10 @@ export const repositoryReadFactsReducer = defineReducer({
|
|
|
648
752
|
acc.status = dispatchStatusReducer(acc.run).initial()
|
|
649
753
|
}
|
|
650
754
|
if (acc.run) acc.status = dispatchStatusReducer(acc.run).advance(acc.status, [event])
|
|
651
|
-
if (event.type === 'dispatcher.ticket-scan-completed')
|
|
755
|
+
if (event.type === 'dispatcher.ticket-scan-completed') {
|
|
756
|
+
acc.scan = event.payload
|
|
757
|
+
acc.scanSeq = event.seq
|
|
758
|
+
}
|
|
652
759
|
if (event.type === 'dispatcher.run-started') acc.latestRun = event.payload.run
|
|
653
760
|
if (event.type === 'dispatcher.run-stopped') acc.latestStoppedRun = event.payload.run
|
|
654
761
|
if (
|
|
@@ -681,10 +788,13 @@ export const repositoryReadFactsReducer = defineReducer({
|
|
|
681
788
|
}
|
|
682
789
|
},
|
|
683
790
|
finish: (acc: RepositoryReadAcc) => ({
|
|
791
|
+
missingAccounts: structuredClone(acc.missingAccounts),
|
|
684
792
|
compatibility: structuredClone(acc.compatibility),
|
|
685
793
|
presence: structuredClone(acc.presence),
|
|
794
|
+
preparation: ticketPreparationReducer.finish(acc.preparation),
|
|
686
795
|
upgrades: dispatchUpgradeReducer.finish(acc.upgrades),
|
|
687
796
|
harvestFailures: structuredClone(acc.harvestFailures),
|
|
797
|
+
harvestTerminals: structuredClone(acc.harvestTerminals),
|
|
688
798
|
harvestVerdicts: structuredClone(acc.harvestVerdicts),
|
|
689
799
|
harvestAuthorizations: structuredClone(acc.harvestAuthorizations),
|
|
690
800
|
harvestExecutionStarts: { ...acc.harvestExecutionStarts },
|
|
@@ -705,6 +815,7 @@ export const repositoryReadFactsReducer = defineReducer({
|
|
|
705
815
|
sandboxes: sandboxStatesReducer.finish(acc.sandboxes),
|
|
706
816
|
status: acc.run ? dispatchStatusReducer(acc.run).finish(acc.status) : undefined,
|
|
707
817
|
scan: acc.scan,
|
|
818
|
+
scanSeq: acc.scanSeq,
|
|
708
819
|
recentRuns: structuredClone(acc.recentRuns),
|
|
709
820
|
latestRun: acc.latestRun,
|
|
710
821
|
latestStoppedRun: acc.latestStoppedRun,
|
|
@@ -11,13 +11,21 @@ export function reconcileRewriteHead(payload: EventPayload<'reconcile.rewritten'
|
|
|
11
11
|
return payload.observedHead ?? payload.headSha
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
const gitHistoryEvent =
|
|
15
|
+
/^(workspace\.provisioned|implement\.completed|code-review\.|restack\.|reconcile\.|finalize\.|pr\.)/
|
|
16
|
+
|
|
17
|
+
/** Shared allocation-free gate for the history selector and its incremental fold. */
|
|
18
|
+
export function referencesGitHistory(type: AbEvent['type']): boolean {
|
|
19
|
+
return gitHistoryEvent.test(type)
|
|
20
|
+
}
|
|
21
|
+
|
|
14
22
|
const oid = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/
|
|
15
23
|
/** Only Git-related event fields are object tips. Content digests and attachment
|
|
16
24
|
* hashes are not Git objects. Publication requests/losses describe attempts,
|
|
17
25
|
* not retained Git history: their objects can die with a released workspace.
|
|
18
26
|
* Successful phase facts and rewrite intents independently retain their tips. */
|
|
19
27
|
export function referencedGitTips(events: readonly AbEvent[]): string[] {
|
|
20
|
-
const
|
|
28
|
+
const sources = new Map<string, Set<string>>()
|
|
21
29
|
const keys = new Set([
|
|
22
30
|
'sha',
|
|
23
31
|
'base',
|
|
@@ -33,19 +41,34 @@ export function referencedGitTips(events: readonly AbEvent[]): string[] {
|
|
|
33
41
|
'localBranchHead',
|
|
34
42
|
'observedHead',
|
|
35
43
|
])
|
|
36
|
-
function visit(value: unknown, key = ''): void {
|
|
44
|
+
function visit(value: unknown, result: Set<string>, key = ''): void {
|
|
37
45
|
if (typeof value === 'string' && keys.has(key) && oid.test(value)) result.add(value)
|
|
38
|
-
else if (Array.isArray(value)) for (const item of value) visit(item)
|
|
46
|
+
else if (Array.isArray(value)) for (const item of value) visit(item, result)
|
|
39
47
|
else if (value !== null && typeof value === 'object')
|
|
40
|
-
for (const [name, item] of Object.entries(value)) visit(item, name)
|
|
48
|
+
for (const [name, item] of Object.entries(value)) visit(item, result, name)
|
|
41
49
|
}
|
|
42
50
|
for (const event of events) {
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
)
|
|
48
|
-
|
|
51
|
+
if (event.type === 'publication.candidate-retired')
|
|
52
|
+
sources.get(event.payload.sha)?.delete(`${event.payload.operation}:${event.payload.id}`)
|
|
53
|
+
if (!referencesGitHistory(event.type)) continue
|
|
54
|
+
const tips = new Set<string>()
|
|
55
|
+
visit(event.payload, tips)
|
|
56
|
+
for (const tip of tips) {
|
|
57
|
+
const ephemeral =
|
|
58
|
+
(event.type === 'reconcile.publish-intended' ||
|
|
59
|
+
event.type === 'restack.publish-intended') &&
|
|
60
|
+
event.payload.headSha === tip
|
|
61
|
+
const source = ephemeral ? `${event.type.split('.')[0]}:${event.payload.id}` : 'proven'
|
|
62
|
+
let refs = sources.get(tip)
|
|
63
|
+
if (!refs) {
|
|
64
|
+
refs = new Set()
|
|
65
|
+
sources.set(tip, refs)
|
|
66
|
+
}
|
|
67
|
+
refs.add(source)
|
|
68
|
+
}
|
|
49
69
|
}
|
|
50
|
-
return [...
|
|
70
|
+
return [...sources]
|
|
71
|
+
.filter(([, refs]) => refs.size > 0)
|
|
72
|
+
.map(([tip]) => tip)
|
|
73
|
+
.sort()
|
|
51
74
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { inspectGitCandidate } from '../ports/workspace/commit-preservation'
|
|
1
2
|
import { createHash } from 'node:crypto'
|
|
2
3
|
import { deferMixedVersion, MixedVersionDeferral } from './mixed-version'
|
|
3
4
|
import { suspendNativeLanding } from './landing-publication'
|
|
@@ -19,7 +20,16 @@ export interface RestackDeps {
|
|
|
19
20
|
workspacePath: string
|
|
20
21
|
forge: Forge
|
|
21
22
|
exec: Exec
|
|
23
|
+
instance?: string
|
|
24
|
+
clock?: import('../store/types').Clock
|
|
22
25
|
beforeRewrite?: () => Promise<void>
|
|
26
|
+
probeCandidate?: (input: {
|
|
27
|
+
ref: string
|
|
28
|
+
slug: string
|
|
29
|
+
branch: string
|
|
30
|
+
sha: string
|
|
31
|
+
replayPack?: string
|
|
32
|
+
}) => Promise<boolean>
|
|
23
33
|
automatic?: Pick<
|
|
24
34
|
EventPayload<'restack.prepared'>,
|
|
25
35
|
'trigger' | 'cycle' | 'observation' | 'message'
|
|
@@ -29,11 +39,16 @@ export interface RestackDeps {
|
|
|
29
39
|
* transactions have their own durable vocabulary and never fabricate a phase. */
|
|
30
40
|
async function replayHistory(deps: RestackDeps): Promise<readonly AbEvent[]> {
|
|
31
41
|
const facts = (await readBuildFacts(deps.store, deps.slug)).value
|
|
32
|
-
|
|
42
|
+
const recovery = facts.candidateRecoveries[deps.automatic ? 'restack' : 'reconcile']
|
|
43
|
+
if (deps.automatic === undefined)
|
|
44
|
+
return facts.reconcileHistory.filter(
|
|
45
|
+
(event) => !('id' in event.payload && event.payload.id === recovery?.id),
|
|
46
|
+
)
|
|
33
47
|
const mapped: AbEvent[] = [
|
|
34
48
|
...facts.reconcileHistory.filter((e) => e.type === 'workspace.provisioned'),
|
|
35
49
|
]
|
|
36
50
|
for (const event of facts.restackHistory) {
|
|
51
|
+
if ('id' in event.payload && event.payload.id === recovery?.id) continue
|
|
37
52
|
const type = event.type.replace('restack.', 'reconcile.')
|
|
38
53
|
const payload = { ...event.payload, attempt: 1 }
|
|
39
54
|
// Only replay mechanics consume these records; external writes below are
|
|
@@ -96,75 +111,8 @@ export function requireRewrite(forge: Forge) {
|
|
|
96
111
|
return forge.rewrite
|
|
97
112
|
}
|
|
98
113
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
* disposable guest disappears. Base history remains in the authoritative Git
|
|
102
|
-
* repository; this pack retains only objects introduced above that base. */
|
|
103
|
-
export async function retainReplay(deps: RestackDeps, head: string, base: string) {
|
|
104
|
-
const result = await deps.exec(
|
|
105
|
-
[
|
|
106
|
-
'bash',
|
|
107
|
-
'-o',
|
|
108
|
-
'pipefail',
|
|
109
|
-
'-c',
|
|
110
|
-
'printf "%s\\n" "$1" "^$2" | git pack-objects --stdout --revs | base64 -w0',
|
|
111
|
-
'retain-replay',
|
|
112
|
-
head,
|
|
113
|
-
base,
|
|
114
|
-
],
|
|
115
|
-
{ cwd: deps.workspacePath },
|
|
116
|
-
)
|
|
117
|
-
if (result.exitCode !== 0 || result.stdout.trim() === '')
|
|
118
|
-
throw new Error(`cannot retain replay objects: ${result.stderr}`)
|
|
119
|
-
await deps.store.putArtifact(deps.slug, {
|
|
120
|
-
kind: `replay-objects-${head}`,
|
|
121
|
-
content: result.stdout.trim(),
|
|
122
|
-
})
|
|
123
|
-
}
|
|
124
|
-
export async function restoreReplay(deps: RestackDeps, sha: string): Promise<boolean> {
|
|
125
|
-
const artifact = await deps.store.getArtifact(deps.slug, `replay-objects-${sha}`)
|
|
126
|
-
if (artifact === null) return false
|
|
127
|
-
const content = new TextDecoder().decode(artifact.content)
|
|
128
|
-
if (!/^[A-Za-z0-9+/=]+$/.test(content)) throw new Error('invalid retained replay pack')
|
|
129
|
-
const temporary = (await deps.exec(['mktemp'], { cwd: deps.workspacePath })).stdout.trim()
|
|
130
|
-
if (temporary === '') throw new Error('cannot create retained replay input')
|
|
131
|
-
try {
|
|
132
|
-
for (let offset = 0; offset < content.length; offset += 16_384) {
|
|
133
|
-
const written = await deps.exec(
|
|
134
|
-
[
|
|
135
|
-
'sh',
|
|
136
|
-
'-c',
|
|
137
|
-
'printf %s "$1" >> "$2"',
|
|
138
|
-
'replay-chunk',
|
|
139
|
-
content.slice(offset, offset + 16_384),
|
|
140
|
-
temporary,
|
|
141
|
-
],
|
|
142
|
-
{ cwd: deps.workspacePath },
|
|
143
|
-
)
|
|
144
|
-
if (written.exitCode !== 0) throw new Error('cannot stage retained replay input')
|
|
145
|
-
}
|
|
146
|
-
const result = await deps.exec(
|
|
147
|
-
[
|
|
148
|
-
'bash',
|
|
149
|
-
'-o',
|
|
150
|
-
'pipefail',
|
|
151
|
-
'-c',
|
|
152
|
-
'base64 -d "$1" | git unpack-objects -q',
|
|
153
|
-
'restore-replay',
|
|
154
|
-
temporary,
|
|
155
|
-
],
|
|
156
|
-
{ cwd: deps.workspacePath },
|
|
157
|
-
)
|
|
158
|
-
if (
|
|
159
|
-
result.exitCode !== 0 ||
|
|
160
|
-
(await git(deps, ['cat-file', '-e', `${sha}^{commit}`], true)).exitCode !== 0
|
|
161
|
-
)
|
|
162
|
-
throw new Error(`cannot restore replay objects ${sha}`)
|
|
163
|
-
} finally {
|
|
164
|
-
await deps.exec(['rm', '-f', temporary], { cwd: deps.workspacePath })
|
|
165
|
-
}
|
|
166
|
-
return true
|
|
167
|
-
}
|
|
114
|
+
export { retainReplay, restoreReplay } from './replay-retention'
|
|
115
|
+
import { restoreReplay } from './replay-retention'
|
|
168
116
|
|
|
169
117
|
/** Restore a sandbox-only change from durable bytes without remote write access. */
|
|
170
118
|
async function restoreChange(deps: RestackDeps, sha: string): Promise<boolean> {
|
|
@@ -181,6 +129,81 @@ async function restoreChange(deps: RestackDeps, sha: string): Promise<boolean> {
|
|
|
181
129
|
return true
|
|
182
130
|
}
|
|
183
131
|
|
|
132
|
+
/** Exact availability probes only. Transport/auth errors defer recovery;
|
|
133
|
+
* successful empty ref reads plus absent replay bytes prove candidate loss. */
|
|
134
|
+
export async function recoverLostCandidate(
|
|
135
|
+
deps: RestackDeps,
|
|
136
|
+
): Promise<'none' | 'available' | 'retired'> {
|
|
137
|
+
const current = await readBuildFacts(deps.store, deps.slug)
|
|
138
|
+
const request = current.value.publication.latestUncompletedRequest()
|
|
139
|
+
if (!request || !current.value.publication.lostRecorded(request)) return 'none'
|
|
140
|
+
const payload = request.payload
|
|
141
|
+
if ((payload.operation !== 'reconcile' && payload.operation !== 'restack') || !payload.rewrite)
|
|
142
|
+
return 'none'
|
|
143
|
+
if (
|
|
144
|
+
current.value.state.sessions.open.length ||
|
|
145
|
+
current.value.state.status === 'paused' ||
|
|
146
|
+
current.value.state.status === 'blocked' ||
|
|
147
|
+
current.value.state.pendingCommands.length
|
|
148
|
+
)
|
|
149
|
+
return 'none'
|
|
150
|
+
const record = await deps.store.getBuild(deps.slug)
|
|
151
|
+
if (
|
|
152
|
+
current.value.open &&
|
|
153
|
+
record?.lease &&
|
|
154
|
+
new Date(record.lease.expiresAt).getTime() > (deps.clock?.() ?? new Date()).getTime() &&
|
|
155
|
+
(deps.instance === undefined ||
|
|
156
|
+
current.value.open.instance !== deps.instance ||
|
|
157
|
+
record.lease.holder !== deps.instance)
|
|
158
|
+
)
|
|
159
|
+
return 'none'
|
|
160
|
+
const sha = payload.sha
|
|
161
|
+
const artifact = await deps.store.getArtifact(deps.slug, `replay-objects-${sha}`)
|
|
162
|
+
const replayPack = artifact ? new TextDecoder().decode(artifact.content) : undefined
|
|
163
|
+
const available = deps.probeCandidate
|
|
164
|
+
? await deps.probeCandidate({
|
|
165
|
+
ref: current.value.workspace?.ref ?? '',
|
|
166
|
+
slug: deps.slug,
|
|
167
|
+
branch: payload.branch,
|
|
168
|
+
sha,
|
|
169
|
+
replayPack,
|
|
170
|
+
})
|
|
171
|
+
: await inspectGitCandidate({
|
|
172
|
+
exec: deps.forge.kernelExec ?? deps.exec,
|
|
173
|
+
workspacePath: deps.workspacePath,
|
|
174
|
+
branch: payload.branch,
|
|
175
|
+
sha,
|
|
176
|
+
archiveRef: `refs/autobuild/archive/${deps.slug}/${sha}`,
|
|
177
|
+
local: deps.forge.name === 'local-git',
|
|
178
|
+
replayPack,
|
|
179
|
+
})
|
|
180
|
+
if (available) {
|
|
181
|
+
if (!current.value.workspace || !isRemoteWorkspace(current.value.workspace))
|
|
182
|
+
await (deps.forge.kernelRewrite ?? requireRewrite(deps.forge)).archive({
|
|
183
|
+
workspacePath: deps.workspacePath,
|
|
184
|
+
ref: `refs/autobuild/archive/${deps.slug}/${sha}`,
|
|
185
|
+
sha,
|
|
186
|
+
})
|
|
187
|
+
return 'available'
|
|
188
|
+
}
|
|
189
|
+
if (await deferMixedVersion(deps.store, deps.slug, KERNEL)) throw new MixedVersionDeferral()
|
|
190
|
+
if (
|
|
191
|
+
!(await deps.store.appendIfCurrent(deps.slug, current.cursor, {
|
|
192
|
+
actor: KERNEL,
|
|
193
|
+
type: 'publication.candidate-retired',
|
|
194
|
+
payload: {
|
|
195
|
+
request: request.seq,
|
|
196
|
+
operation: payload.operation,
|
|
197
|
+
id: payload.rewrite.id,
|
|
198
|
+
sha,
|
|
199
|
+
replacementId: `${payload.rewrite.id}-recovery-${request.seq}`,
|
|
200
|
+
},
|
|
201
|
+
}))
|
|
202
|
+
)
|
|
203
|
+
throw new Error('publication changed during candidate recovery; retry')
|
|
204
|
+
return 'retired'
|
|
205
|
+
}
|
|
206
|
+
|
|
184
207
|
export async function archiveTips(deps: RestackDeps, extra: string[] = []) {
|
|
185
208
|
const capability = requireRewrite(deps.forge)
|
|
186
209
|
const facts = (await readBuildFacts(deps.store, deps.slug)).value
|
|
@@ -188,14 +211,13 @@ export async function archiveTips(deps: RestackDeps, extra: string[] = []) {
|
|
|
188
211
|
const archives: { ref: string; sha: string }[] = []
|
|
189
212
|
for (const sha of tips) {
|
|
190
213
|
const ref = `refs/autobuild/archive/${deps.slug}/${sha}`
|
|
191
|
-
//
|
|
214
|
+
// Restore durable local changes first; the remote capability recovers other objects.
|
|
192
215
|
if (
|
|
193
216
|
(await git(deps, ['cat-file', '-e', `${sha}^{commit}`], true)).exitCode !== 0 &&
|
|
194
217
|
!(await restoreChange(deps, sha))
|
|
195
218
|
) {
|
|
196
219
|
if (deps.forge.name === 'local-git')
|
|
197
220
|
throw new Error(`missing recorded Git object ${sha}; restore it before reconcile`)
|
|
198
|
-
await git(deps, ['fetch', '--no-tags', '--no-write-fetch-head', 'origin', ref])
|
|
199
221
|
}
|
|
200
222
|
await capability.archive({ workspacePath: deps.workspacePath, ref, sha })
|
|
201
223
|
archives.push({ ref, sha })
|
|
@@ -219,6 +241,18 @@ export async function prepareRestack(
|
|
|
219
241
|
): Promise<ReconcileTransaction> {
|
|
220
242
|
if (await deferMixedVersion(deps.store, deps.slug, KERNEL)) throw new MixedVersionDeferral()
|
|
221
243
|
const capability = requireRewrite(deps.forge)
|
|
244
|
+
await recoverLostCandidate(deps)
|
|
245
|
+
const recovery = (await readBuildFacts(deps.store, deps.slug)).value.candidateRecoveries[
|
|
246
|
+
deps.automatic ? 'restack' : 'reconcile'
|
|
247
|
+
]
|
|
248
|
+
if (
|
|
249
|
+
recovery &&
|
|
250
|
+
(input.id === recovery.id ||
|
|
251
|
+
(deps.automatic === undefined &&
|
|
252
|
+
(await readBuildFacts(deps.store, deps.slug)).value.reconcileTransaction?.id ===
|
|
253
|
+
recovery.id))
|
|
254
|
+
)
|
|
255
|
+
input = { ...input, id: recovery.replacementId }
|
|
222
256
|
const events = await replayHistory(deps)
|
|
223
257
|
const prior = events.findLast(
|
|
224
258
|
(e) =>
|