@defrex/autobuild 1.0.0-beta.0 → 1.0.0-beta.2
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 +9 -4
- package/SPEC.md +295 -62
- package/bin/ab-build-runner.ts +10 -8
- package/docs/architecture.md +179 -25
- package/docs/configuration.md +41 -6
- package/docs/hosted-service.md +35 -0
- package/docs/integration-tree.md +81 -4
- package/docs/landing-policy.md +11 -0
- package/docs/migration-1.0.md +9 -0
- package/docs/operator-api.md +18 -0
- package/docs/remote-store-protocol.md +11 -0
- package/docs/restacking.md +42 -7
- package/docs/setup.md +25 -0
- package/docs/ticket-dependencies.md +6 -45
- package/package.json +3 -3
- package/packages/core/src/cli/attention.ts +4 -1
- package/packages/core/src/cli/binary.ts +17 -1
- package/packages/core/src/cli/context.ts +53 -1
- package/packages/core/src/cli/dashboard/actions.ts +4 -0
- package/packages/core/src/cli/dashboard/detail.ts +45 -1
- package/packages/core/src/cli/dashboard/facts.ts +7 -2
- package/packages/core/src/cli/dashboard/integration-detail.ts +142 -0
- package/packages/core/src/cli/dashboard/integration-row.ts +248 -0
- package/packages/core/src/cli/dashboard/landing-display.ts +64 -0
- package/packages/core/src/cli/dashboard/model.ts +140 -16
- package/packages/core/src/cli/dashboard/poll.ts +40 -4
- package/packages/core/src/cli/dashboard/refresh.ts +20 -13
- package/packages/core/src/cli/dashboard/render.ts +106 -5
- package/packages/core/src/cli/dashboard/transcript.ts +2 -1
- package/packages/core/src/cli/dispatch-frontend.ts +22 -12
- package/packages/core/src/cli/dispatch.ts +59 -25
- package/packages/core/src/cli/help.ts +19 -2
- package/packages/core/src/cli/main.ts +37 -0
- package/packages/core/src/cli/publication-settlement.ts +49 -5
- package/packages/core/src/cli/repository-status.ts +97 -2
- package/packages/core/src/cli/status.ts +24 -1
- package/packages/core/src/cli/terminals.ts +94 -93
- package/packages/core/src/cli/wait.ts +11 -2
- package/packages/core/src/cli/watch.ts +12 -0
- package/packages/core/src/config/schema.ts +3 -0
- package/packages/core/src/events/catalog.ts +38 -0
- package/packages/core/src/events/compatibility.ts +183 -0
- package/packages/core/src/events/native-session.ts +13 -0
- package/packages/core/src/events/payloads.ts +148 -2
- package/packages/core/src/events/policy.ts +209 -0
- package/packages/core/src/events/repository.ts +48 -0
- package/packages/core/src/integration/harness.ts +4 -4
- package/packages/core/src/kernel/__snapshots__/{reducer-registry.test.ts.snap → reducer-accumulator-shapes.json} +771 -538
- package/packages/core/src/kernel/change-presence.ts +4 -2
- package/packages/core/src/kernel/dispatch-capacity.ts +119 -0
- package/packages/core/src/kernel/dispatcher-liveness.ts +5 -1
- package/packages/core/src/kernel/engine.ts +25 -5
- package/packages/core/src/kernel/forge-health.ts +19 -0
- package/packages/core/src/kernel/generators/build-log.ts +18 -0
- package/packages/core/src/kernel/generators/node-restack-log.ts +1 -1
- package/packages/core/src/kernel/generators/repository-journals.ts +10 -0
- package/packages/core/src/kernel/guarded-forge.ts +159 -0
- package/packages/core/src/kernel/incremental.ts +4 -2
- package/packages/core/src/kernel/integration-completeness.ts +61 -0
- package/packages/core/src/kernel/integration-landing.ts +5 -4
- package/packages/core/src/kernel/janitor-failure.ts +36 -0
- package/packages/core/src/kernel/landing-publication.ts +35 -15
- package/packages/core/src/kernel/landing-state.ts +7 -0
- package/packages/core/src/kernel/leaf-restack-state.ts +1 -1
- package/packages/core/src/kernel/log-index.ts +12 -1
- package/packages/core/src/kernel/mixed-version.ts +52 -0
- package/packages/core/src/kernel/node-landing.ts +14 -11
- package/packages/core/src/kernel/node-restack-demand.ts +29 -0
- package/packages/core/src/kernel/node-restack-state.ts +46 -16
- package/packages/core/src/kernel/node-restack-transaction.ts +151 -8
- package/packages/core/src/kernel/node-restack.ts +34 -10
- package/packages/core/src/kernel/publication.ts +22 -0
- package/packages/core/src/kernel/read-deferrals.ts +111 -0
- package/packages/core/src/kernel/read-facts.ts +27 -6
- package/packages/core/src/kernel/reconcile-restack.ts +23 -2
- package/packages/core/src/kernel/reducer-registry.ts +15 -2
- package/packages/core/src/kernel/reducer.ts +196 -10
- package/packages/core/src/kernel/repository-attention.ts +38 -1
- package/packages/core/src/kernel/terminal-guard.ts +11 -4
- package/packages/core/src/operator/annotations.ts +6 -0
- package/packages/core/src/operator/index.ts +2 -0
- package/packages/core/src/operator/presentation.ts +5 -0
- package/packages/core/src/operator/query.ts +45 -11
- package/packages/core/src/operator/registry.ts +17 -1
- package/packages/core/src/operator/restack.ts +51 -0
- package/packages/core/src/plugin-sdk/index.ts +10 -0
- package/packages/core/src/plugins/load.ts +3 -4
- package/packages/core/src/plugins/manifest.ts +1 -1
- package/packages/core/src/ports/forge/contract.ts +23 -0
- package/packages/core/src/ports/forge/fake.ts +6 -2
- package/packages/core/src/ports/forge/git-rewrite.ts +92 -64
- package/packages/core/src/ports/forge/github-transport.ts +45 -2
- package/packages/core/src/ports/forge/github.ts +56 -17
- package/packages/core/src/ports/forge/local-git.ts +7 -2
- package/packages/core/src/ports/forge-failure.ts +40 -0
- package/packages/core/src/ports/forge-request-context.ts +35 -0
- package/packages/core/src/ports/forge-telemetry.ts +16 -0
- package/packages/core/src/ports/runner/claude.ts +136 -9
- package/packages/core/src/ports/runner/codex.ts +112 -7
- package/packages/core/src/ports/runner/contract.ts +78 -0
- package/packages/core/src/ports/runner/fake.ts +59 -1
- package/packages/core/src/ports/runner/native-cli-fixture.ts +86 -0
- package/packages/core/src/ports/runner/native-process-fixture.ts +38 -0
- package/packages/core/src/ports/runner/native-session.ts +110 -0
- package/packages/core/src/ports/runner/pi-rpc.ts +7 -1
- package/packages/core/src/ports/runner/pi.ts +162 -2
- package/packages/core/src/ports/types.ts +53 -5
- package/packages/core/src/ports/workspace/git-worktree.ts +45 -51
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +28 -12
- package/packages/core/src/processes/build-child-exit.ts +50 -2
- package/packages/core/src/processes/build-child.ts +15 -7
- package/packages/core/src/processes/build-runner.ts +909 -213
- package/packages/core/src/processes/dispatcher.ts +652 -334
- package/packages/core/src/processes/execution-no-progress.ts +15 -0
- package/packages/core/src/processes/pause-execution-fixture.ts +37 -0
- package/packages/core/src/processes/phase-failure-budget.ts +2 -1
- package/packages/core/src/processes/publication-loss.ts +7 -3
- package/packages/core/src/processes/repo-view.ts +53 -6
- package/packages/core/src/processes/tick-publication.ts +6 -2
- package/packages/core/src/runtime-identity.ts +37 -0
- package/packages/core/src/store/adapter.ts +4 -2
- package/packages/core/src/store/build-scope.ts +9 -0
- package/packages/core/src/store/contract.ts +203 -16
- package/packages/core/src/store/digest.ts +20 -2
- package/packages/core/src/store/local/schema.ts +6 -0
- package/packages/core/src/store/local/store.ts +57 -4
- package/packages/core/src/store/memory.ts +83 -2
- package/packages/core/src/store/new-build.ts +2 -2
- package/packages/core/src/store/phase-session.ts +13 -0
- package/packages/core/src/store/reduced-reads.ts +43 -4
- package/packages/core/src/store/reducer-value-shapes.json +8238 -5764
- package/packages/core/src/store/reducer-value-validation.ts +103 -3
- package/packages/core/src/store/reducer-values.ts +21 -6
- package/packages/core/src/store/remote/client.ts +146 -20
- package/packages/core/src/store/remote/compatibility.ts +6 -0
- package/packages/core/src/store/remote/index.ts +2 -0
- package/packages/core/src/store/remote/protocol.ts +19 -0
- package/packages/core/src/store/remote/version.ts +2 -0
- package/packages/core/src/store/repo-state-events.ts +3 -1
- package/packages/core/src/store/repo-tick.ts +6 -1
- package/packages/core/src/store/session-handle.ts +8 -0
- package/packages/core/src/store/snapshots.ts +21 -5
- package/packages/core/src/store/types.ts +19 -1
- package/packages/core/src/testing/dispatch-read-budget.ts +17 -2
- package/packages/core/src/testing/index.ts +7 -0
- package/packages/core/src/testing/newer-writer.ts +37 -0
- package/packages/core/src/testing/reduced-read-budget.ts +3 -0
- package/skills/guide/SKILL.md +144 -27
- package/skills/guide/references/integration-tree.md +81 -4
- package/skills/guide/references/landing-policy.md +11 -0
- package/skills/guide/references/migration-1.0.md +9 -0
- package/skills/guide/references/operator-api.md +18 -0
- package/skills/guide/references/plugin-authoring.md +55 -7
- package/skills/guide/references/remote-store-protocol.md +11 -0
- package/skills/guide/references/restacking.md +42 -7
- package/skills/guide/references/setup.md +25 -0
- package/skills/guide/references/ticket-dependencies.md +6 -45
- package/skills/implement/SKILL.md +4 -2
- package/skills/operate/SKILL.md +63 -6
- package/skills/reconcile/SKILL.md +3 -1
- package/skills/spec/SKILL.md +49 -39
- package/skills/tickets/SKILL.md +15 -43
|
@@ -37,7 +37,7 @@ export function missingChanges(
|
|
|
37
37
|
return required.filter((id) => !available.has(id))
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
function originalForeign(sha: string, aliases: Map<string, string>): string {
|
|
40
|
+
export function originalForeign(sha: string, aliases: Map<string, string>): string {
|
|
41
41
|
const seen = new Set<string>()
|
|
42
42
|
while (aliases.has(sha) && aliases.get(sha) !== sha) {
|
|
43
43
|
if (seen.has(sha)) throw new Error('cyclic foreign identity evidence')
|
|
@@ -94,6 +94,7 @@ export async function observePresence(
|
|
|
94
94
|
head: string,
|
|
95
95
|
landings: LandingEvidence[],
|
|
96
96
|
aliases = new Map<string, string>(),
|
|
97
|
+
includeForeign = false,
|
|
97
98
|
): Promise<ChangeIdentity[]> {
|
|
98
99
|
const commits = await history(git, [head])
|
|
99
100
|
const proofs: ChangeIdentity[] = []
|
|
@@ -107,7 +108,8 @@ export async function observePresence(
|
|
|
107
108
|
for (const build of buildTrailers(commit.message)) result.push(`build:${build}`)
|
|
108
109
|
const foreign: ChangeIdentity = `foreign:${originalForeign(commit.sha, aliases)}`
|
|
109
110
|
proofs.push(foreign, `foreign:${commit.sha}`)
|
|
110
|
-
if (aliases.has(commit.sha) || relevantForeign.has(foreign))
|
|
111
|
+
if (includeForeign || aliases.has(commit.sha) || relevantForeign.has(foreign))
|
|
112
|
+
result.push(foreign)
|
|
111
113
|
}
|
|
112
114
|
return expandLandings(result, proofs, landings)
|
|
113
115
|
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { BuildRecord } from '../store/types'
|
|
2
|
+
import type { BuildState } from './reducer'
|
|
3
|
+
import { integrationNeedsRunner } from './integration-state'
|
|
4
|
+
|
|
5
|
+
/** Repository-scoped, reduced facts. Provisioning reserves a slot before a workspace exists. */
|
|
6
|
+
export interface CapacityBuild {
|
|
7
|
+
record: BuildRecord
|
|
8
|
+
state: BuildState
|
|
9
|
+
workspace: boolean
|
|
10
|
+
provisioning?: boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface DispatchCapacity {
|
|
14
|
+
configured: number
|
|
15
|
+
occupied: number
|
|
16
|
+
effective: number
|
|
17
|
+
borrowingNodes: string[]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function occupiesCapacity(build: CapacityBuild, now: Date): boolean {
|
|
21
|
+
const { state, record } = build
|
|
22
|
+
if (state.status === 'done' || state.status === 'aborted') return false
|
|
23
|
+
return (
|
|
24
|
+
state.kind !== 'node' ||
|
|
25
|
+
!!state.nodeRestack?.conflict ||
|
|
26
|
+
(integrationNeedsRunner(state) &&
|
|
27
|
+
(build.workspace ||
|
|
28
|
+
!!build.provisioning ||
|
|
29
|
+
(record.lease !== undefined && Date.parse(record.lease.expiresAt) > now.getTime())))
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Follow accepted build identities, validating the source-qualified ticket at every edge. */
|
|
34
|
+
function descendsFrom(
|
|
35
|
+
build: CapacityBuild,
|
|
36
|
+
node: string,
|
|
37
|
+
builds: Map<string, CapacityBuild>,
|
|
38
|
+
): boolean {
|
|
39
|
+
const seen = new Set<string>([build.record.slug])
|
|
40
|
+
let target = build.state.target
|
|
41
|
+
while (target) {
|
|
42
|
+
if (seen.has(target.build)) return false
|
|
43
|
+
seen.add(target.build)
|
|
44
|
+
const parent = builds.get(target.build)
|
|
45
|
+
if (
|
|
46
|
+
parent?.state.kind !== 'node' ||
|
|
47
|
+
parent.record.repo !== build.record.repo ||
|
|
48
|
+
parent.record.ticket?.source !== target.ticket.source ||
|
|
49
|
+
parent.record.ticket.id !== target.ticket.id
|
|
50
|
+
)
|
|
51
|
+
return false
|
|
52
|
+
if (parent.record.slug === node) return true
|
|
53
|
+
target = parent.state.target
|
|
54
|
+
}
|
|
55
|
+
return false
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function nodeCapacity(
|
|
59
|
+
builds: readonly CapacityBuild[],
|
|
60
|
+
node: string,
|
|
61
|
+
now: Date,
|
|
62
|
+
): {
|
|
63
|
+
occupied: number
|
|
64
|
+
excludedDescendants: string[]
|
|
65
|
+
} {
|
|
66
|
+
const identities = new Map(builds.map((build) => [build.record.slug, build]))
|
|
67
|
+
const excludedDescendants: string[] = []
|
|
68
|
+
let occupied = 0
|
|
69
|
+
for (const build of identities.values()) {
|
|
70
|
+
if (build.record.slug === node || !occupiesCapacity(build, now)) continue
|
|
71
|
+
if (
|
|
72
|
+
(build.state.status === 'blocked' || build.state.status === 'paused') &&
|
|
73
|
+
descendsFrom(build, node, identities)
|
|
74
|
+
)
|
|
75
|
+
excludedDescendants.push(build.record.slug)
|
|
76
|
+
else occupied++
|
|
77
|
+
}
|
|
78
|
+
return { occupied, excludedDescendants: excludedDescendants.sort() }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function dispatchCapacity(
|
|
82
|
+
builds: readonly CapacityBuild[],
|
|
83
|
+
configured: number,
|
|
84
|
+
now: Date,
|
|
85
|
+
): DispatchCapacity {
|
|
86
|
+
const unique = [...new Map(builds.map((build) => [build.record.slug, build])).values()]
|
|
87
|
+
const occupied = unique.filter((build) => occupiesCapacity(build, now)).length
|
|
88
|
+
const borrowingNodes = unique
|
|
89
|
+
.filter((build) => {
|
|
90
|
+
if (build.state.kind !== 'node' || !occupiesCapacity(build, now)) return false
|
|
91
|
+
// A waiting conflict owns capacity too, but only allocated runner work borrows.
|
|
92
|
+
if (
|
|
93
|
+
!build.workspace &&
|
|
94
|
+
!build.provisioning &&
|
|
95
|
+
!(build.record.lease && Date.parse(build.record.lease.expiresAt) > now.getTime())
|
|
96
|
+
)
|
|
97
|
+
return false
|
|
98
|
+
const admission = nodeCapacity(unique, build.record.slug, now)
|
|
99
|
+
return (
|
|
100
|
+
occupied > configured &&
|
|
101
|
+
admission.excludedDescendants.length > 0 &&
|
|
102
|
+
admission.occupied < configured
|
|
103
|
+
)
|
|
104
|
+
})
|
|
105
|
+
.map((build) => build.record.slug)
|
|
106
|
+
.sort()
|
|
107
|
+
return {
|
|
108
|
+
configured,
|
|
109
|
+
occupied,
|
|
110
|
+
effective: borrowingNodes.length ? Math.max(configured, occupied) : configured,
|
|
111
|
+
borrowingNodes,
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Shared wording for the terminal and browser control lines. */
|
|
116
|
+
export function capacityExplanation(capacity?: DispatchCapacity): string {
|
|
117
|
+
if (!capacity?.borrowingNodes.length) return ''
|
|
118
|
+
return ` (${capacity.configured} configured; ${capacity.borrowingNodes.length} node${capacity.borrowingNodes.length === 1 ? '' : 's'} using descendant-held slots: ${capacity.borrowingNodes.join(', ')})`
|
|
119
|
+
}
|
|
@@ -38,7 +38,11 @@ export function projectDispatcherLiveness(
|
|
|
38
38
|
lastTick: useSample
|
|
39
39
|
? finished.outcome === 'completed'
|
|
40
40
|
? { outcome: 'completed' as const, counters: finished.counters }
|
|
41
|
-
: {
|
|
41
|
+
: {
|
|
42
|
+
outcome: 'failed' as const,
|
|
43
|
+
error: finished.error,
|
|
44
|
+
forgeRequests: finished.forgeRequests,
|
|
45
|
+
}
|
|
42
46
|
: tick?.type === 'dispatcher.tick-completed'
|
|
43
47
|
? { outcome: 'completed' as const, counters: tick.payload.counters }
|
|
44
48
|
: tick?.type === 'dispatcher.tick-failed'
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { mixedVersionDeferred } from './mixed-version'
|
|
1
2
|
import { integrationCurrent, integrationConfig, integrationFailed } from './integration-state'
|
|
2
3
|
/**
|
|
3
4
|
* The kernel pipeline engine (SPEC §8): "read the event log, decide the next
|
|
@@ -41,7 +42,14 @@ import { stalledChains, type FindingChain } from './stall'
|
|
|
41
42
|
|
|
42
43
|
// ── The decision contract ────────────────────────────────────────────────────
|
|
43
44
|
|
|
44
|
-
export type WaitReason =
|
|
45
|
+
export type WaitReason =
|
|
46
|
+
| 'mixed-version'
|
|
47
|
+
| 'blocked'
|
|
48
|
+
| 'paused'
|
|
49
|
+
| 'awaiting-spec'
|
|
50
|
+
| 'awaiting-pr'
|
|
51
|
+
| 'done'
|
|
52
|
+
| 'aborted'
|
|
45
53
|
|
|
46
54
|
export type VerifyAction =
|
|
47
55
|
| { kind: 'run-check'; step: string; command: string; attempt: number }
|
|
@@ -56,6 +64,7 @@ export type VerifyAction =
|
|
|
56
64
|
export type FinalizeAction = { kind: 'check'; command: string } | { kind: 'agent'; skill: string }
|
|
57
65
|
|
|
58
66
|
export type Decision =
|
|
67
|
+
| ({ kind: 'raise-read-deferral' } & import('./read-deferrals').ReadDeferral)
|
|
59
68
|
| { kind: 'restack'; trigger: 'verify-entry' | 'awaiting-landing'; cycle: number }
|
|
60
69
|
| { kind: 'capture-reconcile-policy'; reconcileSeq: number }
|
|
61
70
|
| { kind: 'wait'; reason: WaitReason }
|
|
@@ -120,6 +129,7 @@ export function decideNext(events: AbEvent[], config: Config): Decision {
|
|
|
120
129
|
* the event array. `decideNext(events, config)` is exactly this over
|
|
121
130
|
* `reduceBuild(events)` and `indexLog(events)`. */
|
|
122
131
|
export function decideNextFromFacts(state: BuildState, log: LogIndex, config: Config): Decision {
|
|
132
|
+
if (mixedVersionDeferred(state)) return { kind: 'wait', reason: 'mixed-version' }
|
|
123
133
|
// ── 1. Terminal (§15.5: terminal wins, latest wins) ────────────────────────
|
|
124
134
|
if (state.status === 'aborted') return { kind: 'wait', reason: 'aborted' }
|
|
125
135
|
if (state.status === 'done') return { kind: 'wait', reason: 'done' }
|
|
@@ -145,6 +155,8 @@ export function decideNextFromFacts(state: BuildState, log: LogIndex, config: Co
|
|
|
145
155
|
// ── 3. Escalations (§11, §15.6-B) ──────────────────────────────────────────
|
|
146
156
|
// blocked ≡ any open (unanswered) escalation (§15.5).
|
|
147
157
|
if (state.openEscalations.length > 0) return { kind: 'wait', reason: 'blocked' }
|
|
158
|
+
const deferred = log.readDeferrals.find((item) => item.ended)
|
|
159
|
+
if (deferred) return { kind: 'raise-read-deferral', ...deferred }
|
|
148
160
|
if (state.kind === 'node') {
|
|
149
161
|
if (state.nodeRestack?.conflict) {
|
|
150
162
|
const attempt =
|
|
@@ -232,7 +244,9 @@ export function decideNextFromFacts(state: BuildState, log: LogIndex, config: Co
|
|
|
232
244
|
// condition's crash gap or acknowledge its exhausted budget.
|
|
233
245
|
const allRaised = [...state.openEscalations, ...state.answeredEscalations]
|
|
234
246
|
const raisedAfter = (seq: number, source: EscalationSource, phase: EscalationTarget): boolean =>
|
|
235
|
-
allRaised.some(
|
|
247
|
+
allRaised.some(
|
|
248
|
+
(e) => e.seq > seq && e.source === source && e.phase === phase && e.deferral === undefined,
|
|
249
|
+
)
|
|
236
250
|
const reconcileNoProgressRaisedAfter = (seq: number): boolean =>
|
|
237
251
|
allRaised.some(
|
|
238
252
|
(e) =>
|
|
@@ -337,7 +351,7 @@ export function decideNextFromFacts(state: BuildState, log: LogIndex, config: Co
|
|
|
337
351
|
const lastFail = fails.at(-1)
|
|
338
352
|
if (
|
|
339
353
|
lastFail !== undefined &&
|
|
340
|
-
fails.
|
|
354
|
+
new Set(fails.map((failure) => failure.attempt)).size >= config.policy.maxVerifyAttempts &&
|
|
341
355
|
!raisedAfter(lastFail.seq, 'policy', verifyPhase(lastFail.step))
|
|
342
356
|
) {
|
|
343
357
|
// Exhaustion escalates once per failure: an exact policy raise for this
|
|
@@ -719,11 +733,17 @@ type GuidanceDestination = 'plan' | 'code' | `verify:${string}` | 'other'
|
|
|
719
733
|
* feeds implement. Finalize/reconcile guidance travels through `ab context`.
|
|
720
734
|
*/
|
|
721
735
|
function guidanceDestination(
|
|
722
|
-
escalation: Pick<AnsweredEscalation, 'phase' | 'source'>,
|
|
736
|
+
escalation: Pick<AnsweredEscalation, 'phase' | 'source' | 'deferral'>,
|
|
723
737
|
): GuidanceDestination {
|
|
724
738
|
const { phase, source } = escalation
|
|
739
|
+
if (
|
|
740
|
+
escalation.deferral === 'own-build-read' &&
|
|
741
|
+
(phase === 'plan-review' || phase === 'code-review')
|
|
742
|
+
)
|
|
743
|
+
return 'other'
|
|
725
744
|
if (phase === 'plan' || phase === 'plan-review') return 'plan'
|
|
726
745
|
if (phase === 'implement' || phase === 'code-review') return 'code'
|
|
727
|
-
if (isVerifyPhase(phase))
|
|
746
|
+
if (isVerifyPhase(phase))
|
|
747
|
+
return source === 'agent' || escalation.deferral === 'own-build-read' ? phase : 'code'
|
|
728
748
|
return 'other'
|
|
729
749
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RepositoryEvent, RepositoryEventPayload } from '../events/repository'
|
|
2
|
+
import { defineReducer } from './incremental'
|
|
3
|
+
export type ForgeDegradation = RepositoryEventPayload<'dispatcher.forge-degraded'>
|
|
4
|
+
export const forgeHealthReducer = defineReducer<
|
|
5
|
+
{ active?: ForgeDegradation },
|
|
6
|
+
RepositoryEvent,
|
|
7
|
+
ForgeDegradation | undefined
|
|
8
|
+
>({
|
|
9
|
+
version: 1,
|
|
10
|
+
initial: () => ({}),
|
|
11
|
+
fold(acc, events) {
|
|
12
|
+
for (const event of events) {
|
|
13
|
+
if (event.type === 'dispatcher.forge-degraded') acc.active = event.payload
|
|
14
|
+
if (event.type === 'dispatcher.forge-recovered' && acc.active?.forge === event.payload.forge)
|
|
15
|
+
delete acc.active
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
finish: (acc) => acc.active,
|
|
19
|
+
})
|
|
@@ -40,6 +40,23 @@ function randomWrite(rand: () => number): EventWrite {
|
|
|
40
40
|
const session = pick(rand, ['s_a', 's_b'])
|
|
41
41
|
const step = pick(rand, ['types', 'unit'])
|
|
42
42
|
const templates: Array<() => EventWrite> = [
|
|
43
|
+
() =>
|
|
44
|
+
w('build.janitor-attempt-failed', {
|
|
45
|
+
firstFailureAt: '2026-01-01T00:00:00.000Z',
|
|
46
|
+
attempt,
|
|
47
|
+
message: 'forge unavailable',
|
|
48
|
+
nextAttemptAt: '2026-01-01T00:01:00.000Z',
|
|
49
|
+
}),
|
|
50
|
+
() => w('build.janitor-failing', { message: 'forge unavailable' }),
|
|
51
|
+
() => w('build.janitor-recovered', {}),
|
|
52
|
+
() =>
|
|
53
|
+
w('landing.application-failed', {
|
|
54
|
+
candidate: { head: SHA, parent: 'b'.repeat(40), cycle: 'cycle' },
|
|
55
|
+
decisionSeq: 1,
|
|
56
|
+
attempt,
|
|
57
|
+
message: 'rate limited',
|
|
58
|
+
after: '2026-01-01T00:01:00.000Z',
|
|
59
|
+
}),
|
|
43
60
|
() =>
|
|
44
61
|
w('landing.decided', {
|
|
45
62
|
candidate: { head: SHA, parent: 'b'.repeat(40), cycle: 'cycle' },
|
|
@@ -62,6 +79,7 @@ function randomWrite(rand: () => number): EventWrite {
|
|
|
62
79
|
decisionSeq: 1,
|
|
63
80
|
commandSeq: 2,
|
|
64
81
|
operation: 'rewrite-1',
|
|
82
|
+
publicationHead: SHA,
|
|
65
83
|
}),
|
|
66
84
|
() => w('runner.attached', { instance: 'runner-1', host: 'local' }),
|
|
67
85
|
() => w('spec.imported', { artifact: ART('spec', 0), ticket: { source: 'linear', id: 'E-1' } }),
|
|
@@ -148,6 +148,16 @@ export function randomStatusJournal(seed: number, length: number): RepositoryEve
|
|
|
148
148
|
for (let i = 0; i < length; i++) {
|
|
149
149
|
const run = pick(rand, ['run-a', 'run-b'])
|
|
150
150
|
const templates: Array<() => Spec> = [
|
|
151
|
+
() => ({
|
|
152
|
+
type: 'dispatcher.forge-degraded',
|
|
153
|
+
payload: {
|
|
154
|
+
forge: 'github',
|
|
155
|
+
message: 'rate limited',
|
|
156
|
+
firstFailureAt: '2026-01-01T00:00:00.000Z',
|
|
157
|
+
resetAt: '2026-01-01T00:01:00.000Z',
|
|
158
|
+
},
|
|
159
|
+
}),
|
|
160
|
+
() => ({ type: 'dispatcher.forge-recovered', payload: { forge: 'github' } }),
|
|
151
161
|
() => ({
|
|
152
162
|
type: 'dispatcher.run-started',
|
|
153
163
|
payload: {
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import type { Forge } from '../ports/types'
|
|
2
|
+
import { isForgeFailure } from '../ports/forge-failure'
|
|
3
|
+
import {
|
|
4
|
+
withForgeRequestGate,
|
|
5
|
+
forgeRequestGateActive,
|
|
6
|
+
ForgeRequestDeferred,
|
|
7
|
+
} from '../ports/forge-request-context'
|
|
8
|
+
import type { BuildStore } from '../store/types'
|
|
9
|
+
import { readForgeHealth } from '../store/reduced-reads'
|
|
10
|
+
import { KERNEL } from '../events/envelope'
|
|
11
|
+
|
|
12
|
+
/** Scheduling signal, never a failed attempt. */
|
|
13
|
+
export class ForgeCooldown extends ForgeRequestDeferred {}
|
|
14
|
+
|
|
15
|
+
/** Receiver bindings and optional plugin capabilities survive the wrapper.
|
|
16
|
+
* Only trusted kernel composition receives the repository Store authority. */
|
|
17
|
+
type GuardDeps = { store: BuildStore; repo: string; name: string; now?: () => Date; wait?: boolean }
|
|
18
|
+
const guarded = new WeakMap<Forge, { raw: Forge; deps: GuardDeps }>()
|
|
19
|
+
|
|
20
|
+
export function guardForge(
|
|
21
|
+
forge: Forge,
|
|
22
|
+
deps: {
|
|
23
|
+
store: BuildStore
|
|
24
|
+
repo: string
|
|
25
|
+
name: string
|
|
26
|
+
now?: () => Date
|
|
27
|
+
wait?: boolean
|
|
28
|
+
},
|
|
29
|
+
): Forge {
|
|
30
|
+
const previous = guarded.get(forge)
|
|
31
|
+
if (previous) {
|
|
32
|
+
if (
|
|
33
|
+
previous.deps.store === deps.store &&
|
|
34
|
+
previous.deps.repo === deps.repo &&
|
|
35
|
+
previous.deps.name === deps.name &&
|
|
36
|
+
previous.deps.wait === deps.wait &&
|
|
37
|
+
previous.deps.now === deps.now
|
|
38
|
+
)
|
|
39
|
+
return forge
|
|
40
|
+
return guardForge(previous.raw, deps)
|
|
41
|
+
}
|
|
42
|
+
if (deps.name === 'local-git') return forge
|
|
43
|
+
const now = deps.now ?? (() => new Date())
|
|
44
|
+
const health = () => readForgeHealth(deps.store, deps.repo)
|
|
45
|
+
const before = async () => {
|
|
46
|
+
let active = await health()
|
|
47
|
+
while (active && (deps.wait || Date.parse(active.resetAt) > now().getTime())) {
|
|
48
|
+
if (!deps.wait) throw new ForgeCooldown(`Forge cooldown until ${active.resetAt}`)
|
|
49
|
+
await new Promise((resolve) =>
|
|
50
|
+
setTimeout(
|
|
51
|
+
resolve,
|
|
52
|
+
Math.max(1000, Math.min(30_000, Date.parse(active!.resetAt) - now().getTime())),
|
|
53
|
+
),
|
|
54
|
+
)
|
|
55
|
+
active = await health()
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const failed = async (error: unknown) => {
|
|
59
|
+
if (!isForgeFailure(error) || error.details.kind !== 'rate-limited') return
|
|
60
|
+
const active = await health()
|
|
61
|
+
if (active?.resetAt === error.details.resetAt && active.message === error.message) return
|
|
62
|
+
// Runner/phase credentials cannot administer repositories; their repo
|
|
63
|
+
// already exists. Only the dispatcher may create it.
|
|
64
|
+
if (!deps.wait) await deps.store.ensureRepo(deps.repo)
|
|
65
|
+
await deps.store.appendRepo(deps.repo, {
|
|
66
|
+
actor: KERNEL,
|
|
67
|
+
type: 'dispatcher.forge-degraded',
|
|
68
|
+
payload: {
|
|
69
|
+
forge: deps.name,
|
|
70
|
+
message: error.message,
|
|
71
|
+
resetAt:
|
|
72
|
+
active && Date.parse(active.resetAt) > Date.parse(error.details.resetAt)
|
|
73
|
+
? active.resetAt
|
|
74
|
+
: error.details.resetAt,
|
|
75
|
+
firstFailureAt: active?.firstFailureAt ?? now().toISOString(),
|
|
76
|
+
},
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
function wrap(target: object): object {
|
|
80
|
+
return new Proxy(
|
|
81
|
+
{},
|
|
82
|
+
{
|
|
83
|
+
has: (_facade, key) => key in target,
|
|
84
|
+
ownKeys: () => Reflect.ownKeys(target),
|
|
85
|
+
getOwnPropertyDescriptor: (_facade, key) => {
|
|
86
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, key)
|
|
87
|
+
return descriptor ? { ...descriptor, configurable: true } : undefined
|
|
88
|
+
},
|
|
89
|
+
get(_facade, key) {
|
|
90
|
+
const value = Reflect.get(target, key, target)
|
|
91
|
+
if (
|
|
92
|
+
value &&
|
|
93
|
+
typeof value === 'object' &&
|
|
94
|
+
['rewrite', 'kernelRewrite', 'prAttachments'].includes(String(key))
|
|
95
|
+
)
|
|
96
|
+
return wrap(value)
|
|
97
|
+
if (typeof value !== 'function') return value
|
|
98
|
+
if (key === 'observeRequests') return value.bind(target)
|
|
99
|
+
return async function invoke(...args: unknown[]): Promise<unknown> {
|
|
100
|
+
await before()
|
|
101
|
+
let requested = false
|
|
102
|
+
let requestFailed = false
|
|
103
|
+
const gate = {
|
|
104
|
+
before: async () => {
|
|
105
|
+
await before()
|
|
106
|
+
requested = true
|
|
107
|
+
},
|
|
108
|
+
failed: async (error: unknown) => {
|
|
109
|
+
requestFailed ||= isForgeFailure(error)
|
|
110
|
+
await failed(error)
|
|
111
|
+
},
|
|
112
|
+
}
|
|
113
|
+
const stop = forge.observeRequests?.(() => {
|
|
114
|
+
if (forgeRequestGateActive(gate)) requested = true
|
|
115
|
+
})
|
|
116
|
+
try {
|
|
117
|
+
const result = await withForgeRequestGate(gate, () => value.apply(target, args))
|
|
118
|
+
// Git-only plumbing cannot prove API recovery. Legacy plugins have
|
|
119
|
+
// no wire observer: their successful provider operation is the probe.
|
|
120
|
+
if (
|
|
121
|
+
!requestFailed &&
|
|
122
|
+
(requested || !forge.observeRequests) &&
|
|
123
|
+
![
|
|
124
|
+
'pushBranch',
|
|
125
|
+
'kernelExec',
|
|
126
|
+
'snapshotBase',
|
|
127
|
+
'compareLocalBranches',
|
|
128
|
+
'fastForward',
|
|
129
|
+
'publish',
|
|
130
|
+
'snapshot',
|
|
131
|
+
'archive',
|
|
132
|
+
].includes(String(key))
|
|
133
|
+
) {
|
|
134
|
+
const active = await health()
|
|
135
|
+
if (active && !deps.wait && Date.parse(active.resetAt) <= now().getTime())
|
|
136
|
+
await deps.store.appendRepo(deps.repo, {
|
|
137
|
+
actor: KERNEL,
|
|
138
|
+
type: 'dispatcher.forge-recovered',
|
|
139
|
+
payload: { forge: deps.name },
|
|
140
|
+
})
|
|
141
|
+
}
|
|
142
|
+
return result
|
|
143
|
+
} catch (error) {
|
|
144
|
+
await failed(error)
|
|
145
|
+
if (deps.wait && isForgeFailure(error) && error.details.kind === 'rate-limited')
|
|
146
|
+
return invoke(...args)
|
|
147
|
+
throw error
|
|
148
|
+
} finally {
|
|
149
|
+
stop?.()
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
const result = wrap(forge) as Forge
|
|
157
|
+
guarded.set(result, { raw: forge, deps })
|
|
158
|
+
return result
|
|
159
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { filterKnownEvents } from '../events/compatibility'
|
|
1
2
|
/**
|
|
2
3
|
* The incremental reducer contract: every projection of an event array is a
|
|
3
4
|
* fold plus a final derivation, so its state can be advanced from a previously
|
|
@@ -31,6 +32,7 @@ export function cloneAcc<T>(acc: T): T {
|
|
|
31
32
|
* `fold`. */
|
|
32
33
|
export function defineReducer<Acc, Event, State>(def: {
|
|
33
34
|
version: number
|
|
35
|
+
rawEvents?: boolean
|
|
34
36
|
initial: () => Acc
|
|
35
37
|
fold: (acc: Acc, events: readonly Event[]) => void
|
|
36
38
|
finish: (acc: Acc) => State
|
|
@@ -40,13 +42,13 @@ export function defineReducer<Acc, Event, State>(def: {
|
|
|
40
42
|
initial: def.initial,
|
|
41
43
|
advance(acc, events) {
|
|
42
44
|
const next = cloneAcc(acc)
|
|
43
|
-
def.fold(next, events)
|
|
45
|
+
def.fold(next, def.rawEvents ? events : filterKnownEvents(events))
|
|
44
46
|
return next
|
|
45
47
|
},
|
|
46
48
|
finish: def.finish,
|
|
47
49
|
reduce(events) {
|
|
48
50
|
const acc = def.initial()
|
|
49
|
-
def.fold(acc, events)
|
|
51
|
+
def.fold(acc, def.rawEvents ? events : filterKnownEvents(events))
|
|
50
52
|
return def.finish(acc)
|
|
51
53
|
},
|
|
52
54
|
}
|
|
@@ -40,6 +40,8 @@ export async function observeIntegration(
|
|
|
40
40
|
contributions: [...(state.integration?.observation?.contributions ?? [])],
|
|
41
41
|
}
|
|
42
42
|
const children = new Set<string>()
|
|
43
|
+
observation.children = state.integration?.observation?.children
|
|
44
|
+
|
|
43
45
|
try {
|
|
44
46
|
if (!record?.ticket || !tickets.integrationTree || !tickets.listAll)
|
|
45
47
|
throw new Error('ticket source cannot establish exhaustive integration completeness')
|
|
@@ -65,6 +67,65 @@ export async function observeIntegration(
|
|
|
65
67
|
observation.contributions.push(build.slug)
|
|
66
68
|
}
|
|
67
69
|
observation.contributions.push(...(state.nodeRestack?.inventory?.contributions ?? []))
|
|
70
|
+
// Membership stays in the existing lifecycle arrays. This is display-only.
|
|
71
|
+
const display = new Map<string, NonNullable<typeof observation.children>[number]>()
|
|
72
|
+
const put = (
|
|
73
|
+
source: string,
|
|
74
|
+
id: string,
|
|
75
|
+
title?: string,
|
|
76
|
+
contribution?: string,
|
|
77
|
+
fresh = false,
|
|
78
|
+
) => {
|
|
79
|
+
const key = JSON.stringify([source, id])
|
|
80
|
+
const previous =
|
|
81
|
+
display.get(key) ??
|
|
82
|
+
state.integration?.observation?.children?.find((c) => c.source === source && c.id === id)
|
|
83
|
+
display.set(key, {
|
|
84
|
+
source,
|
|
85
|
+
id,
|
|
86
|
+
...(previous ?? {}),
|
|
87
|
+
...((fresh ? title : (previous?.title ?? title))
|
|
88
|
+
? { title: fresh ? title : (previous?.title ?? title) }
|
|
89
|
+
: {}),
|
|
90
|
+
...(contribution
|
|
91
|
+
? {
|
|
92
|
+
builds: [...new Set([...(previous?.builds ?? []), contribution])]
|
|
93
|
+
.filter((b) => observation.contributions.includes(b))
|
|
94
|
+
.sort(),
|
|
95
|
+
}
|
|
96
|
+
: {}),
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
for (const contribution of [...new Set(observation.contributions)].sort()) {
|
|
100
|
+
const build = builds.find((b) => b.record.slug === contribution)?.record
|
|
101
|
+
put(
|
|
102
|
+
build?.ticket?.source ?? record.ticket.source,
|
|
103
|
+
build?.ticket?.id ?? contribution,
|
|
104
|
+
build?.ticket?.title,
|
|
105
|
+
contribution,
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
for (const { record: build } of builds)
|
|
109
|
+
if (children.has(build.ticket?.id ?? build.slug))
|
|
110
|
+
put(
|
|
111
|
+
build.ticket?.source ?? record.ticket.source,
|
|
112
|
+
build.ticket?.id ?? build.slug,
|
|
113
|
+
build.ticket?.title,
|
|
114
|
+
)
|
|
115
|
+
for (const ticket of listing.tickets)
|
|
116
|
+
if (
|
|
117
|
+
(ticket.ref.source === record.ticket.source && children.has(ticket.ref.id)) ||
|
|
118
|
+
display.has(JSON.stringify([ticket.ref.source, ticket.ref.id]))
|
|
119
|
+
)
|
|
120
|
+
put(ticket.ref.source, ticket.ref.id, ticket.title, undefined, true)
|
|
121
|
+
for (const id of children) put(record.ticket.source, id)
|
|
122
|
+
if (observation.diagnostics.length)
|
|
123
|
+
for (const previous of state.integration?.observation?.children ?? [])
|
|
124
|
+
if (!display.has(JSON.stringify([previous.source, previous.id])))
|
|
125
|
+
display.set(JSON.stringify([previous.source, previous.id]), previous)
|
|
126
|
+
observation.children = [...display.values()].sort(
|
|
127
|
+
(a, b) => a.source.localeCompare(b.source) || a.id.localeCompare(b.id),
|
|
128
|
+
)
|
|
68
129
|
} catch (error) {
|
|
69
130
|
observation.diagnostics.push(error instanceof Error ? error.message : String(error))
|
|
70
131
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { deferMixedVersion, MixedVersionDeferral } from './mixed-version'
|
|
1
2
|
import { snapshotParent } from './snapshot-parent'
|
|
2
3
|
import { buildTrailers } from './build-identity'
|
|
3
4
|
import { KERNEL, DISPATCHER } from '../events/envelope'
|
|
@@ -29,9 +30,11 @@ export interface IntegrationLandingDeps {
|
|
|
29
30
|
/** The source-owned reservation protects root publication across lease loss. */
|
|
30
31
|
export async function landIntegrationRoot(deps: IntegrationLandingDeps): Promise<void> {
|
|
31
32
|
const { store, forge, slug, workspacePath, exec } = deps
|
|
33
|
+
if (await deferMixedVersion(store, slug, KERNEL)) return
|
|
32
34
|
if (!forge.rewrite || !forge.inspectLandingPr) return
|
|
33
35
|
if (!(await store.claimNodeWriter(slug, deps.holder, 60_000))) return
|
|
34
36
|
const authority = async () => {
|
|
37
|
+
if (await deferMixedVersion(store, slug, KERNEL)) throw new MixedVersionDeferral()
|
|
35
38
|
if (!(await store.renewNodeWriter(slug, deps.holder)))
|
|
36
39
|
throw new Error('integration writer lease lost')
|
|
37
40
|
}
|
|
@@ -55,10 +58,7 @@ export async function landIntegrationRoot(deps: IntegrationLandingDeps): Promise
|
|
|
55
58
|
deps.destination,
|
|
56
59
|
`refs/autobuild/reconcile/${slug}/readback`,
|
|
57
60
|
)
|
|
58
|
-
|
|
59
|
-
cwd: workspacePath,
|
|
60
|
-
})
|
|
61
|
-
if (contains.exitCode === 0) landed = existing.head
|
|
61
|
+
if (actual === existing.head) landed = existing.head
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
const abandon = async (reason: string) => {
|
|
@@ -201,6 +201,7 @@ export async function landIntegrationRoot(deps: IntegrationLandingDeps): Promise
|
|
|
201
201
|
export async function auditIntegrationLanding(
|
|
202
202
|
deps: Pick<IntegrationLandingDeps, 'store' | 'forge' | 'exec' | 'workspacePath' | 'slug' | 'id'>,
|
|
203
203
|
): Promise<void> {
|
|
204
|
+
if (await deferMixedVersion(deps.store, deps.slug, KERNEL)) return
|
|
204
205
|
const state = (await readBuildFacts(deps.store, deps.slug)).value.state
|
|
205
206
|
const landing = state.integration?.landing
|
|
206
207
|
if (!landing?.operation || state.integration?.audit || !deps.forge.rewrite) return
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { BuildState } from './reducer'
|
|
2
|
+
import type { BuildStore } from '../store/types'
|
|
3
|
+
import { DISPATCHER } from '../events/envelope'
|
|
4
|
+
export async function recordJanitorFailure(
|
|
5
|
+
store: BuildStore,
|
|
6
|
+
slug: string,
|
|
7
|
+
previous: BuildState['janitor'],
|
|
8
|
+
message: string,
|
|
9
|
+
now: Date,
|
|
10
|
+
policy: { janitorBackoffMaxSeconds: number; janitorFailureAttentionSeconds: number },
|
|
11
|
+
): Promise<void> {
|
|
12
|
+
const attempt = (previous?.attempt ?? 0) + 1
|
|
13
|
+
const firstFailureAt = previous?.firstFailureAt ?? now.toISOString()
|
|
14
|
+
await store.append(slug, {
|
|
15
|
+
actor: DISPATCHER,
|
|
16
|
+
type: 'build.janitor-attempt-failed',
|
|
17
|
+
payload: {
|
|
18
|
+
firstFailureAt,
|
|
19
|
+
attempt,
|
|
20
|
+
message,
|
|
21
|
+
nextAttemptAt: new Date(
|
|
22
|
+
now.getTime() +
|
|
23
|
+
Math.min(policy.janitorBackoffMaxSeconds, 30 * 2 ** Math.min(attempt - 1, 30)) * 1000,
|
|
24
|
+
).toISOString(),
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
if (
|
|
28
|
+
!previous?.attention &&
|
|
29
|
+
now.getTime() - Date.parse(firstFailureAt) >= policy.janitorFailureAttentionSeconds * 1000
|
|
30
|
+
)
|
|
31
|
+
await store.append(slug, {
|
|
32
|
+
actor: DISPATCHER,
|
|
33
|
+
type: 'build.janitor-failing',
|
|
34
|
+
payload: { message },
|
|
35
|
+
})
|
|
36
|
+
}
|