@defrex/autobuild 1.0.0-beta.1 → 1.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SPEC.md +310 -56
- package/bin/ab-build-runner.ts +10 -8
- package/docs/architecture.md +177 -23
- package/docs/configuration.md +35 -4
- package/docs/hosted-service.md +35 -0
- package/docs/integration-tree.md +83 -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 +16 -0
- package/docs/remote-ticket-protocol.md +5 -0
- package/docs/restacking.md +42 -7
- package/docs/setup.md +25 -0
- package/docs/spec-standard.md +71 -0
- package/docs/ticket-dependencies.md +6 -45
- package/docs/ticket-migration.md +50 -4
- 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/build-control.ts +3 -3
- 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 +144 -0
- package/packages/core/src/cli/dashboard/integration-row.ts +255 -0
- package/packages/core/src/cli/dashboard/landing-display.ts +64 -0
- package/packages/core/src/cli/dashboard/model.ts +147 -16
- package/packages/core/src/cli/dashboard/poll.ts +40 -4
- 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 +11 -0
- package/packages/core/src/cli/dispatch-repository-feed.ts +2 -1
- package/packages/core/src/cli/dispatch.ts +49 -14
- package/packages/core/src/cli/help.ts +17 -1
- package/packages/core/src/cli/main.ts +48 -8
- package/packages/core/src/cli/publication-settlement.ts +49 -5
- package/packages/core/src/cli/repository-status.ts +103 -2
- package/packages/core/src/cli/status.ts +24 -1
- package/packages/core/src/cli/terminals.ts +94 -93
- package/packages/core/src/cli/ticket.ts +35 -11
- 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 +150 -2
- package/packages/core/src/events/policy.ts +210 -0
- package/packages/core/src/events/repository.ts +69 -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} +4286 -4006
- package/packages/core/src/kernel/change-presence.ts +11 -3
- package/packages/core/src/kernel/dispatch-capacity.ts +127 -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 +108 -9
- 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-parent.ts +35 -10
- 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 +34 -6
- package/packages/core/src/kernel/reconcile-restack.ts +23 -2
- package/packages/core/src/kernel/reducer-registry.ts +18 -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/kernel/ticket-migrations.ts +139 -0
- 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 +51 -11
- package/packages/core/src/operator/registry.ts +17 -1
- package/packages/core/src/operator/restack.ts +51 -0
- package/packages/core/src/operator/tickets.ts +30 -26
- package/packages/core/src/plugin-sdk/index.ts +10 -0
- 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/tickets/linear.ts +180 -12
- package/packages/core/src/ports/tickets/migration.ts +92 -9
- package/packages/core/src/ports/types.ts +60 -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 +815 -369
- 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 +233 -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 +8911 -6344
- 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 +145 -20
- 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 +5 -2
- 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 +17 -1
- package/packages/core/src/testing/dispatch-read-budget.ts +18 -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 +140 -25
- package/skills/guide/references/integration-tree.md +83 -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 +47 -4
- package/skills/guide/references/remote-store-protocol.md +16 -0
- package/skills/guide/references/remote-ticket-protocol.md +5 -0
- package/skills/guide/references/restacking.md +42 -7
- package/skills/guide/references/setup.md +25 -0
- package/skills/guide/references/spec-standard.md +71 -0
- package/skills/guide/references/ticket-dependencies.md +6 -45
- package/skills/guide/references/ticket-migration.md +50 -4
- 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 +62 -40
- package/skills/tickets/SKILL.md +15 -43
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { TicketRef } from '../ontology'
|
|
1
2
|
import type { BuildRecord, BuildDigest } from '../store/types'
|
|
2
3
|
import type { CurrentBuildFacts } from '../store/reduced-reads'
|
|
3
4
|
import type { BuildState } from './reducer'
|
|
@@ -17,9 +18,14 @@ export function blockerBuild(
|
|
|
17
18
|
entries: PresenceBuild[],
|
|
18
19
|
source: string,
|
|
19
20
|
id: string,
|
|
21
|
+
identity: (ref: TicketRef, build?: string) => string = (ref) =>
|
|
22
|
+
JSON.stringify([ref.source, ref.id]),
|
|
20
23
|
): PresenceBuild | string | undefined {
|
|
21
24
|
const generations = entries
|
|
22
|
-
.filter(
|
|
25
|
+
.filter(
|
|
26
|
+
({ record }) =>
|
|
27
|
+
record.ticket && identity(record.ticket, record.slug) === identity({ source, id }),
|
|
28
|
+
)
|
|
23
29
|
.sort(
|
|
24
30
|
(a, b) =>
|
|
25
31
|
b.record.createdAt.localeCompare(a.record.createdAt) ||
|
|
@@ -37,7 +43,7 @@ export function missingChanges(
|
|
|
37
43
|
return required.filter((id) => !available.has(id))
|
|
38
44
|
}
|
|
39
45
|
|
|
40
|
-
function originalForeign(sha: string, aliases: Map<string, string>): string {
|
|
46
|
+
export function originalForeign(sha: string, aliases: Map<string, string>): string {
|
|
41
47
|
const seen = new Set<string>()
|
|
42
48
|
while (aliases.has(sha) && aliases.get(sha) !== sha) {
|
|
43
49
|
if (seen.has(sha)) throw new Error('cyclic foreign identity evidence')
|
|
@@ -94,6 +100,7 @@ export async function observePresence(
|
|
|
94
100
|
head: string,
|
|
95
101
|
landings: LandingEvidence[],
|
|
96
102
|
aliases = new Map<string, string>(),
|
|
103
|
+
includeForeign = false,
|
|
97
104
|
): Promise<ChangeIdentity[]> {
|
|
98
105
|
const commits = await history(git, [head])
|
|
99
106
|
const proofs: ChangeIdentity[] = []
|
|
@@ -107,7 +114,8 @@ export async function observePresence(
|
|
|
107
114
|
for (const build of buildTrailers(commit.message)) result.push(`build:${build}`)
|
|
108
115
|
const foreign: ChangeIdentity = `foreign:${originalForeign(commit.sha, aliases)}`
|
|
109
116
|
proofs.push(foreign, `foreign:${commit.sha}`)
|
|
110
|
-
if (aliases.has(commit.sha) || relevantForeign.has(foreign))
|
|
117
|
+
if (includeForeign || aliases.has(commit.sha) || relevantForeign.has(foreign))
|
|
118
|
+
result.push(foreign)
|
|
111
119
|
}
|
|
112
120
|
return expandLandings(result, proofs, landings)
|
|
113
121
|
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { TicketRef } from '../ontology'
|
|
2
|
+
import type { BuildRecord } from '../store/types'
|
|
3
|
+
import type { BuildState } from './reducer'
|
|
4
|
+
import { integrationNeedsRunner } from './integration-state'
|
|
5
|
+
|
|
6
|
+
/** Repository-scoped, reduced facts. Provisioning reserves a slot before a workspace exists. */
|
|
7
|
+
export interface CapacityBuild {
|
|
8
|
+
record: BuildRecord
|
|
9
|
+
state: BuildState
|
|
10
|
+
workspace: boolean
|
|
11
|
+
provisioning?: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface DispatchCapacity {
|
|
15
|
+
configured: number
|
|
16
|
+
occupied: number
|
|
17
|
+
effective: number
|
|
18
|
+
borrowingNodes: string[]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function occupiesCapacity(build: CapacityBuild, now: Date): boolean {
|
|
22
|
+
const { state, record } = build
|
|
23
|
+
if (state.status === 'done' || state.status === 'aborted') return false
|
|
24
|
+
return (
|
|
25
|
+
state.kind !== 'node' ||
|
|
26
|
+
!!state.nodeRestack?.conflict ||
|
|
27
|
+
(integrationNeedsRunner(state) &&
|
|
28
|
+
(build.workspace ||
|
|
29
|
+
!!build.provisioning ||
|
|
30
|
+
(record.lease !== undefined && Date.parse(record.lease.expiresAt) > now.getTime())))
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type Identity = (ref: TicketRef, build?: string) => string
|
|
35
|
+
const exactIdentity: Identity = (ref) => JSON.stringify([ref.source, ref.id])
|
|
36
|
+
|
|
37
|
+
/** Follow accepted build identities, validating the source-qualified ticket at every edge. */
|
|
38
|
+
function descendsFrom(
|
|
39
|
+
build: CapacityBuild,
|
|
40
|
+
node: string,
|
|
41
|
+
builds: Map<string, CapacityBuild>,
|
|
42
|
+
identity: Identity,
|
|
43
|
+
): boolean {
|
|
44
|
+
const seen = new Set<string>([build.record.slug])
|
|
45
|
+
let target = build.state.target
|
|
46
|
+
while (target) {
|
|
47
|
+
if (seen.has(target.build)) return false
|
|
48
|
+
seen.add(target.build)
|
|
49
|
+
const parent = builds.get(target.build)
|
|
50
|
+
if (
|
|
51
|
+
parent?.state.kind !== 'node' ||
|
|
52
|
+
parent.record.repo !== build.record.repo ||
|
|
53
|
+
!parent.record.ticket ||
|
|
54
|
+
identity(parent.record.ticket, parent.record.slug) !==
|
|
55
|
+
identity(target.ticket, build.record.slug)
|
|
56
|
+
)
|
|
57
|
+
return false
|
|
58
|
+
if (parent.record.slug === node) return true
|
|
59
|
+
target = parent.state.target
|
|
60
|
+
}
|
|
61
|
+
return false
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function nodeCapacity(
|
|
65
|
+
builds: readonly CapacityBuild[],
|
|
66
|
+
node: string,
|
|
67
|
+
now: Date,
|
|
68
|
+
identity: Identity = exactIdentity,
|
|
69
|
+
): {
|
|
70
|
+
occupied: number
|
|
71
|
+
excludedDescendants: string[]
|
|
72
|
+
} {
|
|
73
|
+
const identities = new Map(builds.map((build) => [build.record.slug, build]))
|
|
74
|
+
const excludedDescendants: string[] = []
|
|
75
|
+
let occupied = 0
|
|
76
|
+
for (const build of identities.values()) {
|
|
77
|
+
if (build.record.slug === node || !occupiesCapacity(build, now)) continue
|
|
78
|
+
if (
|
|
79
|
+
(build.state.status === 'blocked' || build.state.status === 'paused') &&
|
|
80
|
+
descendsFrom(build, node, identities, identity)
|
|
81
|
+
)
|
|
82
|
+
excludedDescendants.push(build.record.slug)
|
|
83
|
+
else occupied++
|
|
84
|
+
}
|
|
85
|
+
return { occupied, excludedDescendants: excludedDescendants.sort() }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function dispatchCapacity(
|
|
89
|
+
builds: readonly CapacityBuild[],
|
|
90
|
+
configured: number,
|
|
91
|
+
now: Date,
|
|
92
|
+
identity: Identity = exactIdentity,
|
|
93
|
+
): DispatchCapacity {
|
|
94
|
+
const unique = [...new Map(builds.map((build) => [build.record.slug, build])).values()]
|
|
95
|
+
const occupied = unique.filter((build) => occupiesCapacity(build, now)).length
|
|
96
|
+
const borrowingNodes = unique
|
|
97
|
+
.filter((build) => {
|
|
98
|
+
if (build.state.kind !== 'node' || !occupiesCapacity(build, now)) return false
|
|
99
|
+
// A waiting conflict owns capacity too, but only allocated runner work borrows.
|
|
100
|
+
if (
|
|
101
|
+
!build.workspace &&
|
|
102
|
+
!build.provisioning &&
|
|
103
|
+
!(build.record.lease && Date.parse(build.record.lease.expiresAt) > now.getTime())
|
|
104
|
+
)
|
|
105
|
+
return false
|
|
106
|
+
const admission = nodeCapacity(unique, build.record.slug, now, identity)
|
|
107
|
+
return (
|
|
108
|
+
occupied > configured &&
|
|
109
|
+
admission.excludedDescendants.length > 0 &&
|
|
110
|
+
admission.occupied < configured
|
|
111
|
+
)
|
|
112
|
+
})
|
|
113
|
+
.map((build) => build.record.slug)
|
|
114
|
+
.sort()
|
|
115
|
+
return {
|
|
116
|
+
configured,
|
|
117
|
+
occupied,
|
|
118
|
+
effective: borrowingNodes.length ? Math.max(configured, occupied) : configured,
|
|
119
|
+
borrowingNodes,
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Shared wording for the terminal and browser control lines. */
|
|
124
|
+
export function capacityExplanation(capacity?: DispatchCapacity): string {
|
|
125
|
+
if (!capacity?.borrowingNodes.length) return ''
|
|
126
|
+
return ` (${capacity.configured} configured; ${capacity.borrowingNodes.length} node${capacity.borrowingNodes.length === 1 ? '' : 's'} using descendant-held slots: ${capacity.borrowingNodes.join(', ')})`
|
|
127
|
+
}
|
|
@@ -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
|
}
|