@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,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
1
2
|
import type { TicketRef } from '../ontology'
|
|
2
3
|
import type { BuildRecord, BuildDigest } from '../store/types'
|
|
3
4
|
import type { CurrentBuildFacts } from '../store/reduced-reads'
|
|
@@ -102,24 +103,83 @@ export async function observePresence(
|
|
|
102
103
|
aliases = new Map<string, string>(),
|
|
103
104
|
includeForeign = false,
|
|
104
105
|
): Promise<ChangeIdentity[]> {
|
|
106
|
+
return projectPresence(await presenceWitness(git, head), landings, aliases, includeForeign)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface PresenceWitness {
|
|
110
|
+
version: 1
|
|
111
|
+
commits: string[]
|
|
112
|
+
identities: `build:${string}`[]
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export async function presenceWitness(git: NodeGit, head: string): Promise<PresenceWitness> {
|
|
105
116
|
const commits = await history(git, [head])
|
|
117
|
+
return {
|
|
118
|
+
version: 1,
|
|
119
|
+
commits: [...new Set(commits.map((commit) => commit.sha))].sort(),
|
|
120
|
+
identities: [
|
|
121
|
+
...new Set(
|
|
122
|
+
commits.flatMap((commit) =>
|
|
123
|
+
buildTrailers(commit.message).map((slug) => `build:${slug}` as const),
|
|
124
|
+
),
|
|
125
|
+
),
|
|
126
|
+
].sort(),
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function presenceEvidence(witness: PresenceWitness, identities: ChangeIdentity[]): string {
|
|
131
|
+
return `presence-v3:${createHash('sha256')
|
|
132
|
+
.update(
|
|
133
|
+
JSON.stringify([
|
|
134
|
+
witness.version,
|
|
135
|
+
[...new Set(witness.commits)].sort(),
|
|
136
|
+
normalizeIdentities(witness.identities),
|
|
137
|
+
normalizeIdentities(identities),
|
|
138
|
+
]),
|
|
139
|
+
)
|
|
140
|
+
.digest('hex')}`
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function projectPresence(
|
|
144
|
+
witness: PresenceWitness,
|
|
145
|
+
landings: LandingEvidence[],
|
|
146
|
+
aliases = new Map<string, string>(),
|
|
147
|
+
includeForeign = false,
|
|
148
|
+
): ChangeIdentity[] {
|
|
106
149
|
const proofs: ChangeIdentity[] = []
|
|
107
|
-
const result: ChangeIdentity[] = []
|
|
150
|
+
const result: ChangeIdentity[] = [...witness.identities]
|
|
108
151
|
const relevantForeign = new Set(
|
|
109
152
|
landings
|
|
110
153
|
.flatMap((landing) => landing.contribution ?? [])
|
|
111
154
|
.filter((id) => id.startsWith('foreign:')),
|
|
112
155
|
)
|
|
113
|
-
for (const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (includeForeign || aliases.has(commit.sha) || relevantForeign.has(foreign))
|
|
118
|
-
result.push(foreign)
|
|
156
|
+
for (const sha of witness.commits) {
|
|
157
|
+
const foreign: ChangeIdentity = `foreign:${originalForeign(sha, aliases)}`
|
|
158
|
+
proofs.push(foreign, `foreign:${sha}`)
|
|
159
|
+
if (includeForeign || aliases.has(sha) || relevantForeign.has(foreign)) result.push(foreign)
|
|
119
160
|
}
|
|
120
161
|
return expandLandings(result, proofs, landings)
|
|
121
162
|
}
|
|
122
163
|
|
|
164
|
+
/** Only aliases belonging to this destination's accepted ancestry are relevant. */
|
|
165
|
+
export function destinationAliases(
|
|
166
|
+
inputs: PresenceInputs,
|
|
167
|
+
destination?: string,
|
|
168
|
+
): Map<string, string> {
|
|
169
|
+
const aliases = new Map<string, string>()
|
|
170
|
+
const seen = new Set<string>()
|
|
171
|
+
while (destination) {
|
|
172
|
+
if (seen.has(destination)) throw new Error('cyclic destination ancestry')
|
|
173
|
+
seen.add(destination)
|
|
174
|
+
const state = inputs.states.get(destination)
|
|
175
|
+
if (!state) throw new Error('missing destination ancestry')
|
|
176
|
+
for (const [sha, original] of Object.entries(state.nodeRestack?.foreignAliases ?? {}))
|
|
177
|
+
aliases.set(sha, original)
|
|
178
|
+
destination = state.target?.build
|
|
179
|
+
}
|
|
180
|
+
return aliases
|
|
181
|
+
}
|
|
182
|
+
|
|
123
183
|
/** Reconstruct a historical node contribution only from its retained source
|
|
124
184
|
* range. The caller must establish the source head and confirmed landing. */
|
|
125
185
|
export async function ownedContribution(
|
|
@@ -158,6 +218,7 @@ export async function presenceInputs(
|
|
|
158
218
|
store: { buildFacts(slug: string): Promise<CurrentBuildFacts> },
|
|
159
219
|
entries: PresenceBuild[],
|
|
160
220
|
destinations: Iterable<string> = [],
|
|
221
|
+
landings = confirmedLandings(entries),
|
|
161
222
|
): Promise<PresenceInputs> {
|
|
162
223
|
const states = new Map<string, BuildState>()
|
|
163
224
|
const aliases = new Map<string, string>()
|
|
@@ -171,6 +232,11 @@ export async function presenceInputs(
|
|
|
171
232
|
aliases.set(sha, original)
|
|
172
233
|
if (state.target) pending.push(state.target.build)
|
|
173
234
|
}
|
|
235
|
+
return { entries, states, aliases, landings }
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** Shared once per dispatcher tick from the existing batched digest read. */
|
|
239
|
+
export function confirmedLandings(entries: PresenceBuild[]): LandingEvidence[] {
|
|
174
240
|
const landings: LandingEvidence[] = []
|
|
175
241
|
for (const { record, digest } of entries) {
|
|
176
242
|
if (!digest.mergedSha || digest.terminal === 'aborted' || digest.prClosed) continue
|
|
@@ -183,5 +249,5 @@ export async function presenceInputs(
|
|
|
183
249
|
})
|
|
184
250
|
} else landings.push({ slug: record.slug, sha: digest.mergedSha })
|
|
185
251
|
}
|
|
186
|
-
return
|
|
252
|
+
return landings
|
|
187
253
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { RepositoryEvent, DispatchPlacementFact } from '../events/repository'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import { dispatchPlacementFactSchema } from '../events/repository'
|
|
4
|
+
import { defineReducer } from './incremental'
|
|
5
|
+
|
|
6
|
+
export const dispatchPlacementSchema = z.discriminatedUnion('status', [
|
|
7
|
+
z.strictObject({ status: z.literal('known'), placement: dispatchPlacementFactSchema }),
|
|
8
|
+
z.strictObject({
|
|
9
|
+
status: z.literal('unknown'),
|
|
10
|
+
reason: z.enum(['unrecorded', 'unsupported-capability']),
|
|
11
|
+
}),
|
|
12
|
+
])
|
|
13
|
+
export type DispatchPlacement = z.infer<typeof dispatchPlacementSchema>
|
|
14
|
+
export const dispatchPlacementReducer = defineReducer<
|
|
15
|
+
{ placement: DispatchPlacementFact | null },
|
|
16
|
+
RepositoryEvent,
|
|
17
|
+
DispatchPlacement
|
|
18
|
+
>({
|
|
19
|
+
version: 1,
|
|
20
|
+
initial: () => ({ placement: null }),
|
|
21
|
+
fold: (acc, events) => {
|
|
22
|
+
for (const event of events) {
|
|
23
|
+
if (event.type === 'dispatcher.placement-set') acc.placement = event.payload
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
finish: (acc) =>
|
|
27
|
+
acc.placement === null
|
|
28
|
+
? { status: 'unknown', reason: 'unrecorded' }
|
|
29
|
+
: { status: 'known', placement: structuredClone(acc.placement) },
|
|
30
|
+
})
|
|
@@ -46,6 +46,7 @@ import { stalledChains, type FindingChain } from './stall'
|
|
|
46
46
|
// ── The decision contract ────────────────────────────────────────────────────
|
|
47
47
|
|
|
48
48
|
export type WaitReason =
|
|
49
|
+
| 'target-rewritten'
|
|
49
50
|
| 'publication-retry'
|
|
50
51
|
| 'verify-stage'
|
|
51
52
|
| 'mixed-version'
|
|
@@ -228,6 +229,10 @@ function decideNextInternal(state: BuildState, log: LogIndex, config: Config): D
|
|
|
228
229
|
return { kind: 'acknowledge', command: 'pause' }
|
|
229
230
|
}
|
|
230
231
|
|
|
232
|
+
// Frozen transactions retain their original destination and may recover.
|
|
233
|
+
if (state.targetRewrite && !log.restack.active && !state.nodeRestack?.active)
|
|
234
|
+
return { kind: 'wait', reason: 'target-rewritten' }
|
|
235
|
+
|
|
231
236
|
// ── 3. Escalations (§11, §15.6-B) ──────────────────────────────────────────
|
|
232
237
|
// blocked ≡ any open (unanswered) escalation (§15.5).
|
|
233
238
|
const stageCycle =
|
|
@@ -394,6 +399,14 @@ function decideNextInternal(state: BuildState, log: LogIndex, config: Config): D
|
|
|
394
399
|
// ── 4. Spec (§6.3: dispatch owns the import; `spec` is not a phase §5) ─────
|
|
395
400
|
if (state.specRev === undefined) return { kind: 'wait', reason: 'awaiting-spec' }
|
|
396
401
|
|
|
402
|
+
// A revised contract invalidates approvals, but an unfinished replay still
|
|
403
|
+
// belongs to its reconcile occurrence. Publish it before opening the new
|
|
404
|
+
// plan loop so no other phase inherits its detached/conflicted workspace.
|
|
405
|
+
if (state.currentPhase?.phase === 'reconcile' && state.currentPhase.seq < log.restartSeq) {
|
|
406
|
+
const attempt = state.currentPhase.attempt ?? state.reconcileAttempts
|
|
407
|
+
return { kind: 'run-phase', phase: 'reconcile', round: attempt, reconcile: { attempt } }
|
|
408
|
+
}
|
|
409
|
+
|
|
397
410
|
// ── Shared routing inputs ──────────────────────────────────────────────────
|
|
398
411
|
|
|
399
412
|
// dismiss-finding contributes the raised escalation's refs to the dismissed
|
|
@@ -753,6 +766,20 @@ function decideNextInternal(state: BuildState, log: LogIndex, config: Config): D
|
|
|
753
766
|
// ── 9. Post-PR epilogue (§15.7): finalize → (conflicted → reconcile →
|
|
754
767
|
// verify:*)* → merged | closed. The dispatcher's janitor emits pr.* and
|
|
755
768
|
// completes the build; the engine only ever runs reconcile here.
|
|
769
|
+
// Resume a retained resolver occurrence before considering a newly observed
|
|
770
|
+
// target. Candidate retirement removes its result, not its frozen intent.
|
|
771
|
+
if (
|
|
772
|
+
state.prState === 'conflicted' &&
|
|
773
|
+
(log.conflictReconcileStarted !== undefined || state.currentPhase?.phase === 'reconcile')
|
|
774
|
+
) {
|
|
775
|
+
// A later conflict observation clears the log marker, but cannot retire
|
|
776
|
+
// an unfinished resolver or spend another occurrence during reconstruction.
|
|
777
|
+
const attempt =
|
|
778
|
+
log.conflictReconcileStarted?.attempt ??
|
|
779
|
+
state.currentPhase?.attempt ??
|
|
780
|
+
state.reconcileAttempts
|
|
781
|
+
return { kind: 'run-phase', phase: 'reconcile', round: attempt, reconcile: { attempt } }
|
|
782
|
+
}
|
|
756
783
|
if (
|
|
757
784
|
log.restack.target !== undefined &&
|
|
758
785
|
(log.restack.target.sha !== (log.restack.completed?.targetBase ?? log.restack.initialBase) ||
|
|
@@ -762,18 +789,6 @@ function decideNextInternal(state: BuildState, log: LogIndex, config: Config): D
|
|
|
762
789
|
return { kind: 'restack', trigger: 'awaiting-landing', cycle: cycleBoundary }
|
|
763
790
|
}
|
|
764
791
|
if (state.prState === 'conflicted' && log.lastConflict !== undefined) {
|
|
765
|
-
if (log.conflictReconcileStarted !== undefined) {
|
|
766
|
-
// Crashed reconcile: re-run the SAME attempt from its start (§15.6-C) —
|
|
767
|
-
// the reducer's reconcileAttempts is the kernel's own counter precisely
|
|
768
|
-
// so a re-run does not double-count.
|
|
769
|
-
const crashAttempt = log.conflictReconcileStarted.attempt
|
|
770
|
-
return {
|
|
771
|
-
kind: 'run-phase',
|
|
772
|
-
phase: 'reconcile',
|
|
773
|
-
round: crashAttempt,
|
|
774
|
-
reconcile: { attempt: crashAttempt },
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
792
|
const nextAttempt = state.reconcileAttempts + 1
|
|
778
793
|
const completed = log.lastReconcileCompleted
|
|
779
794
|
if (completed !== undefined && completed.completedSeq < log.lastConflict.seq) {
|
|
@@ -65,7 +65,23 @@ export function leafRestackLog(): AbEvent[] {
|
|
|
65
65
|
{
|
|
66
66
|
type: 'target.moved',
|
|
67
67
|
actor: KERNEL,
|
|
68
|
-
payload: {
|
|
68
|
+
payload: {
|
|
69
|
+
branch: 'main',
|
|
70
|
+
sha: leafTransaction.targetBase,
|
|
71
|
+
lineage: [
|
|
72
|
+
{
|
|
73
|
+
node: 'parent',
|
|
74
|
+
from: leafTransaction.oldBase,
|
|
75
|
+
receipts: [
|
|
76
|
+
{
|
|
77
|
+
id: 'parent-restack',
|
|
78
|
+
previous: leafTransaction.oldBase,
|
|
79
|
+
head: leafTransaction.targetBase,
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
},
|
|
69
85
|
},
|
|
70
86
|
{
|
|
71
87
|
type: 'target.distance',
|
|
@@ -19,6 +19,20 @@ export function nodeRestackLog(): AbEvent[] {
|
|
|
19
19
|
},
|
|
20
20
|
},
|
|
21
21
|
{ actor: DISPATCHER, type: 'node.opened', payload: { sha: 'd'.repeat(40) } },
|
|
22
|
+
{
|
|
23
|
+
actor: KERNEL,
|
|
24
|
+
type: 'node.restack-availability-observed',
|
|
25
|
+
payload: {
|
|
26
|
+
version: 1,
|
|
27
|
+
fingerprint: 'assessment',
|
|
28
|
+
branch: 'ab-node/node',
|
|
29
|
+
parentBranch: 'main',
|
|
30
|
+
head: expected,
|
|
31
|
+
parent,
|
|
32
|
+
base: 'd'.repeat(40),
|
|
33
|
+
available: [],
|
|
34
|
+
},
|
|
35
|
+
},
|
|
22
36
|
{
|
|
23
37
|
actor: KERNEL,
|
|
24
38
|
type: 'node.writer-reserved',
|
|
@@ -8,7 +8,8 @@ export interface LeafRestackState {
|
|
|
8
8
|
postStepAt?: number
|
|
9
9
|
completedAt?: number
|
|
10
10
|
finalizedAt?: number
|
|
11
|
-
target?: { seq: number
|
|
11
|
+
target?: EventPayload<'target.moved'> & { seq: number }
|
|
12
|
+
targetRewrite?: EventPayload<'target.rewritten'>
|
|
12
13
|
distance?: EventPayload<'target.distance'>
|
|
13
14
|
active?: EventPayload<'restack.prepared'>
|
|
14
15
|
replay?: EventPayload<'restack.replayed'>
|
|
@@ -29,6 +30,7 @@ export function advanceLeafRestack(state: LeafRestackState, events: readonly AbE
|
|
|
29
30
|
state.finalizedAt = event.seq
|
|
30
31
|
break
|
|
31
32
|
case 'node.parent-accepted':
|
|
33
|
+
delete state.targetRewrite
|
|
32
34
|
delete state.distance
|
|
33
35
|
delete state.target
|
|
34
36
|
break
|
|
@@ -54,10 +56,30 @@ export function advanceLeafRestack(state: LeafRestackState, events: readonly AbE
|
|
|
54
56
|
case 'target.distance':
|
|
55
57
|
state.distance = event.payload
|
|
56
58
|
break
|
|
59
|
+
case 'target.rewritten':
|
|
60
|
+
state.targetRewrite = event.payload
|
|
61
|
+
break
|
|
62
|
+
case 'target.rewrite-cleared':
|
|
63
|
+
if (
|
|
64
|
+
event.payload.lineage &&
|
|
65
|
+
state.target?.branch === event.payload.branch &&
|
|
66
|
+
state.target.sha === event.payload.sha
|
|
67
|
+
)
|
|
68
|
+
state.target.lineage = event.payload.lineage
|
|
69
|
+
delete state.targetRewrite
|
|
70
|
+
break
|
|
57
71
|
case 'target.moved':
|
|
72
|
+
delete state.targetRewrite
|
|
58
73
|
delete state.distance
|
|
59
74
|
state.target = { seq: event.seq, ...event.payload }
|
|
60
75
|
break
|
|
76
|
+
case 'publication.candidate-retired':
|
|
77
|
+
if (event.payload.operation === 'restack' && state.active?.id === event.payload.id) {
|
|
78
|
+
state.active = { ...state.active, id: event.payload.replacementId }
|
|
79
|
+
delete state.replay
|
|
80
|
+
delete state.intent
|
|
81
|
+
}
|
|
82
|
+
break
|
|
61
83
|
case 'restack.prepared':
|
|
62
84
|
state.active = event.payload
|
|
63
85
|
delete state.replay
|
|
@@ -91,7 +113,7 @@ export function advanceLeafRestack(state: LeafRestackState, events: readonly AbE
|
|
|
91
113
|
}
|
|
92
114
|
}
|
|
93
115
|
export const leafRestackReducer = defineReducer<LeafRestackState, AbEvent, LeafRestackState>({
|
|
94
|
-
version:
|
|
116
|
+
version: 8,
|
|
95
117
|
initial: () => ({ gates: {} }),
|
|
96
118
|
fold: advanceLeafRestack,
|
|
97
119
|
finish: (state) => structuredClone(state),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { observeTarget } from './target-observation'
|
|
1
2
|
import { deferMixedVersion, MixedVersionDeferral } from './mixed-version'
|
|
2
3
|
import { inspectIntegrationStack } from './integration-stack'
|
|
3
4
|
import { integrationFailed } from './integration-state'
|
|
@@ -128,6 +129,18 @@ export async function landIntoNode(
|
|
|
128
129
|
branch: deps.destination,
|
|
129
130
|
destinationRef: `refs/autobuild/reconcile/${deps.slug}/landing-destination`,
|
|
130
131
|
})
|
|
132
|
+
if (
|
|
133
|
+
(await observeTarget({
|
|
134
|
+
store,
|
|
135
|
+
forge,
|
|
136
|
+
slug: deps.slug,
|
|
137
|
+
branch: deps.destination,
|
|
138
|
+
sha: expected,
|
|
139
|
+
enforceUsedBaseline: true,
|
|
140
|
+
actor: KERNEL,
|
|
141
|
+
})) === 'rejected'
|
|
142
|
+
)
|
|
143
|
+
return defer('Upstream destination rewrite requires operator attention.')
|
|
131
144
|
const candidate = await forge.rewrite.snapshot({
|
|
132
145
|
workspacePath,
|
|
133
146
|
branch: deps.branch,
|
|
@@ -147,13 +160,14 @@ export async function landIntoNode(
|
|
|
147
160
|
? expected !== deps.stack.parent || candidate !== deps.stack.head
|
|
148
161
|
: parents.stdout.trim() !== expected
|
|
149
162
|
) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
163
|
+
await observeTarget({
|
|
164
|
+
store,
|
|
165
|
+
forge,
|
|
166
|
+
slug: deps.slug,
|
|
167
|
+
branch: deps.destination,
|
|
168
|
+
sha: expected,
|
|
169
|
+
actor: KERNEL,
|
|
170
|
+
})
|
|
157
171
|
return defer(
|
|
158
172
|
'Leaf head is not one canonical change on the current node head; awaiting restack or human provenance review.',
|
|
159
173
|
)
|
|
@@ -304,10 +318,13 @@ export async function landIntoNode(
|
|
|
304
318
|
})
|
|
305
319
|
}
|
|
306
320
|
if (result.actual)
|
|
307
|
-
await
|
|
321
|
+
await observeTarget({
|
|
322
|
+
store,
|
|
323
|
+
forge,
|
|
324
|
+
slug: deps.slug,
|
|
325
|
+
branch: deps.destination,
|
|
326
|
+
sha: result.actual,
|
|
308
327
|
actor: KERNEL,
|
|
309
|
-
type: 'target.moved',
|
|
310
|
-
payload: { branch: deps.destination, sha: result.actual },
|
|
311
328
|
})
|
|
312
329
|
return undefined
|
|
313
330
|
}
|
|
@@ -129,27 +129,60 @@ export function nodePollingUnsettled(state: BuildState): boolean {
|
|
|
129
129
|
)
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
|
|
132
|
+
/** Valid scheduling evidence may be reused across processes, never across activity epochs. */
|
|
133
|
+
export function nodePollingEvidenceValid(
|
|
133
134
|
state: BuildState,
|
|
134
135
|
activityKey: string,
|
|
135
136
|
policy: NodePollingPolicy,
|
|
136
137
|
now: Date,
|
|
137
|
-
|
|
138
|
-
) {
|
|
138
|
+
): boolean {
|
|
139
139
|
const check = state.nodePolling
|
|
140
140
|
const time = now.getTime()
|
|
141
141
|
const checked = Date.parse(check?.checkedAt ?? '')
|
|
142
142
|
const unchanged = Date.parse(check?.unchangedSince ?? '')
|
|
143
|
-
|
|
144
|
-
!unsettled &&
|
|
143
|
+
return (
|
|
145
144
|
check?.activityKey === activityKey &&
|
|
146
145
|
check.nodeIdleAfterSeconds === policy.nodeIdleAfterSeconds &&
|
|
147
146
|
check.nodeIdlePollSeconds === policy.nodeIdlePollSeconds &&
|
|
148
147
|
Number.isFinite(time) &&
|
|
149
148
|
Number.isFinite(checked) &&
|
|
150
149
|
Number.isFinite(unchanged) &&
|
|
151
|
-
|
|
152
|
-
|
|
150
|
+
// The anchor uses the dispatcher clock; checkedAt uses the store clock.
|
|
151
|
+
// Validate each against now without imposing an order across clocks.
|
|
152
|
+
unchanged <= time &&
|
|
153
|
+
checked <= time
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Successful unchanged active observations need no additional durable record. */
|
|
158
|
+
export function nodePollingCheckpointRequired(
|
|
159
|
+
state: BuildState,
|
|
160
|
+
activityKey: string,
|
|
161
|
+
policy: NodePollingPolicy,
|
|
162
|
+
now: Date,
|
|
163
|
+
): boolean {
|
|
164
|
+
if (!nodePollingEvidenceValid(state, activityKey, policy, now)) return true
|
|
165
|
+
const check = state.nodePolling!
|
|
166
|
+
return (
|
|
167
|
+
now.getTime() - Date.parse(check.unchangedSince) >= policy.nodeIdleAfterSeconds * 1000 &&
|
|
168
|
+
now.getTime() - Date.parse(check.checkedAt) >= policy.nodeIdlePollSeconds * 1000
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function nodePollingSchedule(
|
|
173
|
+
state: BuildState,
|
|
174
|
+
activityKey: string,
|
|
175
|
+
policy: NodePollingPolicy,
|
|
176
|
+
now: Date,
|
|
177
|
+
unsettled = nodePollingUnsettled(state),
|
|
178
|
+
) {
|
|
179
|
+
const check = state.nodePolling
|
|
180
|
+
const time = now.getTime()
|
|
181
|
+
const checked = Date.parse(check?.checkedAt ?? '')
|
|
182
|
+
const unchanged = Date.parse(check?.unchangedSince ?? '')
|
|
183
|
+
const idle =
|
|
184
|
+
!unsettled &&
|
|
185
|
+
nodePollingEvidenceValid(state, activityKey, policy, now) &&
|
|
153
186
|
time - unchanged >= policy.nodeIdleAfterSeconds * 1000
|
|
154
187
|
return {
|
|
155
188
|
mode: idle ? ('idle' as const) : ('active' as const),
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import type { PresenceInputs } from './change-presence'
|
|
1
3
|
import type { BuildState } from './reducer'
|
|
2
4
|
import { integrationComplete, integrationFailed } from './integration-state'
|
|
3
5
|
|
|
4
6
|
/** Existing reservations are recovery work, regardless of fresh demand. */
|
|
5
7
|
export function nodeRestackDemand(state: BuildState): boolean {
|
|
8
|
+
if (state.targetRewrite && !state.nodeRestack?.active) return false
|
|
6
9
|
return !!(
|
|
7
10
|
state.nodeRestack?.active ||
|
|
8
11
|
state.nodeRestack?.parentChange ||
|
|
@@ -27,3 +30,75 @@ export function presenceRestackPath(
|
|
|
27
30
|
.flatMap((entry) => (entry.slug && requested.has(entry.slug) ? [entry.slug] : []))
|
|
28
31
|
.reverse()
|
|
29
32
|
}
|
|
33
|
+
|
|
34
|
+
/** Canonical semantic evidence only: polling facts and journal positions do not
|
|
35
|
+
* invalidate an assessment, but unchanged-head landing proofs do. */
|
|
36
|
+
export function restackAvailabilityFingerprint(
|
|
37
|
+
state: BuildState,
|
|
38
|
+
branch: string,
|
|
39
|
+
parentBranch: string,
|
|
40
|
+
head: string,
|
|
41
|
+
parent: string,
|
|
42
|
+
evidence: PresenceInputs,
|
|
43
|
+
landingKey = restackLandingKey(evidence.landings),
|
|
44
|
+
): string {
|
|
45
|
+
const requests = Object.values(state.nodeRestack?.requests ?? {})
|
|
46
|
+
.map((r) => [
|
|
47
|
+
r.id,
|
|
48
|
+
r.reason,
|
|
49
|
+
r.branch,
|
|
50
|
+
r.parent,
|
|
51
|
+
r.dependent?.source,
|
|
52
|
+
r.dependent?.id,
|
|
53
|
+
[...new Set(r.identities ?? [])].sort(),
|
|
54
|
+
])
|
|
55
|
+
.sort((a, b) => String(a[0]).localeCompare(String(b[0])))
|
|
56
|
+
const ancestry = [...evidence.states]
|
|
57
|
+
.map(([slug, s]) => [
|
|
58
|
+
slug,
|
|
59
|
+
s.target?.build,
|
|
60
|
+
s.baseBranch,
|
|
61
|
+
Object.entries(s.nodeRestack?.foreignAliases ?? {}).sort(([a], [b]) => a.localeCompare(b)),
|
|
62
|
+
])
|
|
63
|
+
.sort((a, b) => String(a[0]).localeCompare(String(b[0])))
|
|
64
|
+
return createHash('sha256')
|
|
65
|
+
.update(
|
|
66
|
+
JSON.stringify([
|
|
67
|
+
1,
|
|
68
|
+
branch,
|
|
69
|
+
parentBranch,
|
|
70
|
+
head,
|
|
71
|
+
parent,
|
|
72
|
+
state.nodeRestack?.contributionBase,
|
|
73
|
+
requests,
|
|
74
|
+
ancestry,
|
|
75
|
+
landingKey,
|
|
76
|
+
]),
|
|
77
|
+
)
|
|
78
|
+
.digest('hex')
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function actionableRestackDemand(state: BuildState, fingerprint: string): boolean {
|
|
82
|
+
const observation = state.nodeRestack?.availability
|
|
83
|
+
if (observation?.version !== 1 || observation.fingerprint !== fingerprint)
|
|
84
|
+
return nodeRestackDemand(state)
|
|
85
|
+
return nodeRestackDemand({
|
|
86
|
+
...state,
|
|
87
|
+
nodeRestack: {
|
|
88
|
+
...state.nodeRestack!,
|
|
89
|
+
requests: Object.fromEntries(
|
|
90
|
+
Object.entries(state.nodeRestack?.requests ?? {}).filter(
|
|
91
|
+
([id, request]) => request.reason === 'operator' || observation.available.includes(id),
|
|
92
|
+
),
|
|
93
|
+
),
|
|
94
|
+
},
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Hash shared landing evidence once, not once per considered node. */
|
|
99
|
+
export function restackLandingKey(landings: PresenceInputs['landings']): string {
|
|
100
|
+
const canonical = landings
|
|
101
|
+
.map((l) => [l.slug, l.sha, [...new Set(l.contribution ?? [])].sort()])
|
|
102
|
+
.sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)))
|
|
103
|
+
return createHash('sha256').update(JSON.stringify(canonical)).digest('hex')
|
|
104
|
+
}
|
|
@@ -19,6 +19,8 @@ export function sameParentRejection(
|
|
|
19
19
|
* holder resumes these immutable inputs before admitting another operation. */
|
|
20
20
|
export interface NodeRestackState {
|
|
21
21
|
requests?: Record<string, EventPayload<'node.restack-requested'>>
|
|
22
|
+
availability?: EventPayload<'node.restack-availability-observed'>
|
|
23
|
+
targetRewrite?: EventPayload<'target.rewritten'>
|
|
22
24
|
distance?: EventPayload<'node.parent-distance'>
|
|
23
25
|
parentRequest?: EventPayload<'node.parent-requested'>
|
|
24
26
|
parentChange?: EventPayload<'node.parent-accepted'>
|
|
@@ -50,6 +52,9 @@ export function advanceNodeRestack(state: NodeRestackState, events: readonly AbE
|
|
|
50
52
|
case 'node.restack-satisfied':
|
|
51
53
|
if (state.requests) delete state.requests[event.payload.id]
|
|
52
54
|
break
|
|
55
|
+
case 'node.restack-availability-observed':
|
|
56
|
+
state.availability = event.payload
|
|
57
|
+
break
|
|
53
58
|
case 'node.parent-distance':
|
|
54
59
|
state.distance = event.payload
|
|
55
60
|
break
|
|
@@ -57,6 +62,7 @@ export function advanceNodeRestack(state: NodeRestackState, events: readonly AbE
|
|
|
57
62
|
state.parentRequest = event.payload
|
|
58
63
|
break
|
|
59
64
|
case 'node.parent-accepted':
|
|
65
|
+
delete state.targetRewrite
|
|
60
66
|
state.parentChange = event.payload
|
|
61
67
|
delete state.parentRequest
|
|
62
68
|
delete state.parentReplay
|
|
@@ -80,7 +86,20 @@ export function advanceNodeRestack(state: NodeRestackState, events: readonly AbE
|
|
|
80
86
|
case 'node.parent-completed':
|
|
81
87
|
if (state.parentChange?.id === event.payload.id) delete state.parentChange
|
|
82
88
|
break
|
|
89
|
+
case 'target.rewritten':
|
|
90
|
+
state.targetRewrite = event.payload
|
|
91
|
+
break
|
|
92
|
+
case 'target.rewrite-cleared':
|
|
93
|
+
if (
|
|
94
|
+
event.payload.lineage &&
|
|
95
|
+
state.observedParent?.branch === event.payload.branch &&
|
|
96
|
+
state.observedParent.sha === event.payload.sha
|
|
97
|
+
)
|
|
98
|
+
state.observedParent.lineage = event.payload.lineage
|
|
99
|
+
delete state.targetRewrite
|
|
100
|
+
break
|
|
83
101
|
case 'target.moved':
|
|
102
|
+
delete state.targetRewrite
|
|
84
103
|
if (state.contributionBase !== undefined) state.observedParent = event.payload
|
|
85
104
|
break
|
|
86
105
|
case 'node.opened':
|
|
@@ -214,7 +233,7 @@ export function advanceNodeRestack(state: NodeRestackState, events: readonly AbE
|
|
|
214
233
|
}
|
|
215
234
|
}
|
|
216
235
|
export const nodeRestackReducer = defineReducer<NodeRestackState, AbEvent, NodeRestackState>({
|
|
217
|
-
version:
|
|
236
|
+
version: 9,
|
|
218
237
|
initial: () => ({ items: [] }),
|
|
219
238
|
fold: advanceNodeRestack,
|
|
220
239
|
finish: (state) => structuredClone(state),
|