@defrex/autobuild 1.0.0-beta.3 → 1.0.0-beta.4
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 +317 -20
- package/bin/ab-dispatch-generation.ts +93 -0
- package/docs/answering-blocked-builds.md +21 -3
- package/docs/architecture.md +166 -7
- package/docs/configuration.md +173 -5
- package/docs/integration-tree.md +87 -2
- package/docs/integration.md +54 -0
- package/docs/operator-api.md +58 -5
- package/docs/remote-store-protocol.md +4 -1
- package/docs/restacking.md +4 -1
- package/docs/setup.md +20 -0
- package/docs/spec-standard.md +23 -5
- package/package.json +3 -3
- package/packages/core/src/cli/artifact.ts +5 -4
- package/packages/core/src/cli/attention.ts +2 -0
- package/packages/core/src/cli/binary-direct.ts +190 -0
- package/packages/core/src/cli/binary-lifecycle.ts +46 -0
- package/packages/core/src/cli/binary.ts +24 -210
- package/packages/core/src/cli/build-control.ts +105 -2
- package/packages/core/src/cli/context.ts +41 -1
- package/packages/core/src/cli/dashboard/hand-pushed.ts +24 -0
- package/packages/core/src/cli/dashboard/handoff.ts +64 -0
- package/packages/core/src/cli/dashboard/integration-detail.ts +3 -0
- package/packages/core/src/cli/dashboard/model.ts +34 -10
- package/packages/core/src/cli/dashboard/render.ts +24 -2
- package/packages/core/src/cli/dashboard/rollback.ts +30 -0
- package/packages/core/src/cli/dispatch-args.ts +53 -0
- package/packages/core/src/cli/dispatch-crash-budget.ts +15 -0
- package/packages/core/src/cli/dispatch-frontend.ts +52 -5
- package/packages/core/src/cli/dispatch-handoff.ts +276 -0
- package/packages/core/src/cli/dispatch-launch-contract.ts +170 -0
- package/packages/core/src/cli/dispatch-launcher.ts +580 -0
- package/packages/core/src/cli/dispatch-parent-watch.ts +44 -0
- package/packages/core/src/cli/dispatch-preflight.ts +272 -0
- package/packages/core/src/cli/dispatch-presentation-job.ts +46 -0
- package/packages/core/src/cli/dispatch-presentation-ownership.ts +9 -0
- package/packages/core/src/cli/dispatch-process.ts +22 -90
- package/packages/core/src/cli/dispatch-readiness.ts +47 -0
- package/packages/core/src/cli/dispatch-repository-feed.ts +5 -1
- package/packages/core/src/cli/dispatch-runtime-cache.ts +522 -0
- package/packages/core/src/cli/dispatch-runtime-dependencies.ts +291 -0
- package/packages/core/src/cli/dispatch-runtime-use.ts +336 -0
- package/packages/core/src/cli/dispatch-upgrade-controller.ts +221 -0
- package/packages/core/src/cli/dispatch-upgrade-install.ts +258 -0
- package/packages/core/src/cli/dispatch-upgrade-source.ts +309 -0
- package/packages/core/src/cli/dispatch-upgrade-target.ts +190 -0
- package/packages/core/src/cli/dispatch.ts +604 -60
- package/packages/core/src/cli/dispatcher-liveness.ts +1 -1
- package/packages/core/src/cli/harvest.ts +28 -11
- package/packages/core/src/cli/help.ts +6 -3
- package/packages/core/src/cli/installation.ts +5 -3
- package/packages/core/src/cli/main-checkout.ts +59 -0
- package/packages/core/src/cli/main.ts +15 -45
- package/packages/core/src/cli/node-verification-provenance.ts +97 -0
- package/packages/core/src/cli/repo-state.ts +3 -58
- package/packages/core/src/cli/repository-status.ts +67 -3
- package/packages/core/src/cli/runtime-spawn.ts +16 -0
- package/packages/core/src/cli/status.ts +57 -3
- package/packages/core/src/cli/upgrade-followup.ts +25 -0
- package/packages/core/src/cli/wait.ts +3 -0
- package/packages/core/src/cli/watch.ts +7 -0
- package/packages/core/src/config/live.ts +1 -0
- package/packages/core/src/config/schema.ts +8 -4
- package/packages/core/src/distribution-packaging.ts +116 -0
- package/packages/core/src/events/catalog.ts +6 -0
- package/packages/core/src/events/payloads.ts +53 -9
- package/packages/core/src/events/policy.ts +25 -0
- package/packages/core/src/events/repository.ts +184 -4
- package/packages/core/src/events/runtime.ts +16 -0
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +2515 -78
- package/packages/core/src/kernel/dispatch-drain-recovery.ts +121 -0
- package/packages/core/src/kernel/dispatch-status.ts +4 -2
- package/packages/core/src/kernel/dispatch-upgrade.ts +171 -0
- package/packages/core/src/kernel/dispatcher-liveness.ts +7 -0
- package/packages/core/src/kernel/generators/repository-journals.ts +82 -0
- package/packages/core/src/kernel/guarded-forge.ts +1 -1
- package/packages/core/src/kernel/harvest.ts +98 -4
- package/packages/core/src/kernel/integration-attention.ts +20 -0
- package/packages/core/src/kernel/integration-state.ts +80 -11
- package/packages/core/src/kernel/landing-readiness.ts +6 -1
- package/packages/core/src/kernel/mixed-version.ts +34 -0
- package/packages/core/src/kernel/node-polling.ts +160 -0
- package/packages/core/src/kernel/read-facts.ts +40 -5
- package/packages/core/src/kernel/reducer-registry.ts +3 -0
- package/packages/core/src/kernel/reducer.ts +75 -14
- package/packages/core/src/kernel/service-facts.ts +11 -4
- package/packages/core/src/operator/presentation.ts +7 -0
- package/packages/core/src/operator/query.ts +6 -2
- package/packages/core/src/operator/registry.ts +1 -1
- package/packages/core/src/plugins/load.ts +4 -1
- package/packages/core/src/plugins/runtime-snapshot.ts +128 -0
- package/packages/core/src/ports/forge/contract.ts +29 -0
- package/packages/core/src/ports/forge/github.ts +189 -61
- package/packages/core/src/ports/forge-failure.ts +1 -0
- package/packages/core/src/ports/forge-telemetry.ts +3 -0
- package/packages/core/src/ports/runner/session-env.ts +1 -0
- package/packages/core/src/ports/types.ts +10 -0
- package/packages/core/src/ports/workspace/distribution-archive.ts +22 -149
- package/packages/core/src/ports/workspace/distribution-release.ts +56 -0
- package/packages/core/src/ports/workspace/git-worktree.ts +2 -1
- package/packages/core/src/ports/workspace/local-build-execution.ts +37 -17
- package/packages/core/src/processes/build-child-exit.ts +5 -26
- package/packages/core/src/processes/build-runner.ts +81 -11
- package/packages/core/src/processes/dispatcher.ts +254 -23
- package/packages/core/src/processes/execution-no-progress.ts +6 -0
- package/packages/core/src/processes/execution-relaunch.ts +30 -0
- package/packages/core/src/processes/execution-settlement.ts +16 -7
- package/packages/core/src/processes/harvest-runner.ts +328 -292
- package/packages/core/src/processes/process-group-reaper.ts +17 -10
- package/packages/core/src/runtime-identity.ts +22 -3
- package/packages/core/src/store/contract.ts +153 -0
- package/packages/core/src/store/local/store.ts +197 -72
- package/packages/core/src/store/reduced-reads.ts +8 -0
- package/packages/core/src/store/reducer-value-shapes.json +5783 -3305
- package/packages/core/src/store/remote/client.ts +43 -0
- package/packages/core/src/store/repo-state-events.ts +20 -3
- package/packages/core/src/store/types.ts +7 -0
- package/skills/guide/SKILL.md +231 -23
- package/skills/guide/references/integration-tree.md +87 -2
- package/skills/guide/references/operator-api.md +53 -4
- package/skills/guide/references/plugin-authoring.md +45 -4
- package/skills/guide/references/remote-store-protocol.md +4 -1
- package/skills/guide/references/restacking.md +4 -1
- package/skills/guide/references/setup.md +20 -0
- package/skills/guide/references/spec-standard.md +23 -5
- package/skills/harvest/SKILL.md +4 -0
- package/skills/harvest-review/SKILL.md +4 -0
- package/skills/operate/SKILL.md +78 -8
- package/skills/spec/SKILL.md +19 -1
- package/skills/tickets/SKILL.md +19 -0
|
@@ -5,6 +5,7 @@ import type { BuildState } from './reducer'
|
|
|
5
5
|
/** Exact immutable inputs, retained independently of disposable execution. */
|
|
6
6
|
export interface IntegrationState {
|
|
7
7
|
cycles?: (EventPayload<'integration.prepared'> & { seq: number })[]
|
|
8
|
+
failures?: (EventPayload<'integration.verification-failed'> & { seq: number })[]
|
|
8
9
|
observation?: EventPayload<'integration.observed'>
|
|
9
10
|
cycle?: EventPayload<'integration.prepared'> & { seq: number }
|
|
10
11
|
intent?: EventPayload<'integration.landing-intended'>
|
|
@@ -13,6 +14,10 @@ export interface IntegrationState {
|
|
|
13
14
|
}
|
|
14
15
|
export function advanceIntegration(state: IntegrationState, event: AbEvent): void {
|
|
15
16
|
switch (event.type) {
|
|
17
|
+
case 'integration.verification-failed':
|
|
18
|
+
state.failures ??= []
|
|
19
|
+
state.failures.push({ ...event.payload, seq: event.seq })
|
|
20
|
+
break
|
|
16
21
|
case 'integration.observed':
|
|
17
22
|
state.observation = event.payload
|
|
18
23
|
break
|
|
@@ -44,30 +49,40 @@ export function integrationComplete(state: Pick<BuildState, 'integration'>): boo
|
|
|
44
49
|
observation.contributions.length > 0
|
|
45
50
|
)
|
|
46
51
|
}
|
|
52
|
+
type CycleState = Pick<BuildState, 'integration' | 'restartSince' | 'nodeComparison' | 'verify'>
|
|
53
|
+
|
|
54
|
+
/** A spec revision invalidates execution eligibility, never historical receipts. */
|
|
55
|
+
export function integrationCycleCurrent(
|
|
56
|
+
state: Pick<CycleState, 'integration' | 'restartSince'>,
|
|
57
|
+
): boolean {
|
|
58
|
+
return !!state.integration?.cycle && state.integration.cycle.seq > state.restartSince
|
|
59
|
+
}
|
|
60
|
+
|
|
47
61
|
export function integrationCurrent(state: BuildState): boolean {
|
|
48
62
|
const cycle = state.integration?.cycle
|
|
49
63
|
return (
|
|
50
|
-
|
|
64
|
+
integrationCycleCurrent(state) &&
|
|
51
65
|
integrationComplete(state) &&
|
|
52
66
|
!state.nodeRestack?.parentRequest &&
|
|
53
67
|
!state.nodeRestack?.parentChange &&
|
|
54
68
|
!state.nodeRestack?.active &&
|
|
55
|
-
state.nodeComparison?.headSha === cycle
|
|
56
|
-
state.nodeComparison?.parentSha === cycle
|
|
57
|
-
(!state.nodeRestack?.observedParent ||
|
|
58
|
-
|
|
69
|
+
state.nodeComparison?.headSha === cycle!.head &&
|
|
70
|
+
state.nodeComparison?.parentSha === cycle!.parent &&
|
|
71
|
+
(!state.nodeRestack?.observedParent ||
|
|
72
|
+
state.nodeRestack.observedParent.sha === cycle!.parent) &&
|
|
73
|
+
state.nodeRestack?.contributionBase === cycle!.parent
|
|
59
74
|
)
|
|
60
75
|
}
|
|
61
76
|
|
|
62
77
|
export function integrationConfig(config: import('../config/schema').Config): string {
|
|
63
78
|
return JSON.stringify({ verify: config.verify, commands: config.commands })
|
|
64
79
|
}
|
|
65
|
-
export function integrationFailed(state:
|
|
80
|
+
export function integrationFailed(state: CycleState): boolean {
|
|
66
81
|
const cycle = state.integration?.cycle
|
|
67
82
|
return (
|
|
68
|
-
|
|
69
|
-
state.nodeComparison?.headSha === cycle
|
|
70
|
-
state.nodeComparison?.parentSha === cycle
|
|
83
|
+
integrationCycleCurrent(state) &&
|
|
84
|
+
state.nodeComparison?.headSha === cycle!.head &&
|
|
85
|
+
state.nodeComparison?.parentSha === cycle!.parent &&
|
|
71
86
|
state.verify.results.some(
|
|
72
87
|
(result) =>
|
|
73
88
|
result.seq > cycle!.seq && result.restackId === cycle!.id && result.outcome === 'fail',
|
|
@@ -123,9 +138,16 @@ export function integrationHeadVerified(state: BuildState, head: string): boolea
|
|
|
123
138
|
* remains available to landing audits, but cannot authorize a new parent. */
|
|
124
139
|
export function integrationCycleVerified(state: BuildState): boolean {
|
|
125
140
|
const cycle = state.integration?.cycle
|
|
126
|
-
if (!cycle) return false
|
|
141
|
+
if (!cycle || !integrationCycleCurrent(state)) return false
|
|
127
142
|
return integrationHeadVerified(
|
|
128
|
-
{
|
|
143
|
+
{
|
|
144
|
+
...state,
|
|
145
|
+
verify: {
|
|
146
|
+
...state.verify,
|
|
147
|
+
results: state.verify.results.filter((result) => result.seq > cycle.seq),
|
|
148
|
+
},
|
|
149
|
+
integration: { ...state.integration, cycles: [cycle] },
|
|
150
|
+
},
|
|
129
151
|
cycle.head,
|
|
130
152
|
)
|
|
131
153
|
}
|
|
@@ -133,3 +155,50 @@ export function integrationCycleVerified(state: BuildState): boolean {
|
|
|
133
155
|
export function integrationNeedsRunner(state: BuildState): boolean {
|
|
134
156
|
return integrationCurrent(state) && !integrationFailed(state) && !integrationCycleVerified(state)
|
|
135
157
|
}
|
|
158
|
+
|
|
159
|
+
/** Only the current failed cycle can still require a repair child. */
|
|
160
|
+
export function missingIntegrationFailures(
|
|
161
|
+
state: BuildState,
|
|
162
|
+
slug: string,
|
|
163
|
+
): EventPayload<'integration.verification-failed'>[] {
|
|
164
|
+
if (
|
|
165
|
+
state.kind !== 'node' ||
|
|
166
|
+
state.status === 'done' ||
|
|
167
|
+
state.status === 'aborted' ||
|
|
168
|
+
!integrationCycleCurrent(state)
|
|
169
|
+
)
|
|
170
|
+
return []
|
|
171
|
+
const cycle = state.integration?.cycle
|
|
172
|
+
if (
|
|
173
|
+
!cycle ||
|
|
174
|
+
state.nodeComparison?.headSha !== cycle.head ||
|
|
175
|
+
state.nodeComparison?.parentSha !== cycle.parent
|
|
176
|
+
)
|
|
177
|
+
return []
|
|
178
|
+
if (state.integration?.failures?.some((failure) => failure.id === cycle.id)) return []
|
|
179
|
+
const steps = [
|
|
180
|
+
...new Set(
|
|
181
|
+
state.verify.results
|
|
182
|
+
.filter(
|
|
183
|
+
(result) =>
|
|
184
|
+
result.seq > cycle.seq &&
|
|
185
|
+
result.restackId === cycle.id &&
|
|
186
|
+
result.headSha === cycle.head &&
|
|
187
|
+
result.baseSha === cycle.parent &&
|
|
188
|
+
result.outcome === 'fail',
|
|
189
|
+
)
|
|
190
|
+
.map((result) => result.step),
|
|
191
|
+
),
|
|
192
|
+
]
|
|
193
|
+
return steps.length
|
|
194
|
+
? [
|
|
195
|
+
{
|
|
196
|
+
id: cycle.id,
|
|
197
|
+
head: cycle.head,
|
|
198
|
+
parent: cycle.parent,
|
|
199
|
+
steps,
|
|
200
|
+
guidance: `file a repair child targeting this node: ${slug}`,
|
|
201
|
+
},
|
|
202
|
+
]
|
|
203
|
+
: []
|
|
204
|
+
}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import type { BuildState } from './reducer'
|
|
2
2
|
import { discardInFlight } from './reducer'
|
|
3
3
|
import type { LeafRestackState } from './leaf-restack-state'
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
integrationCurrent,
|
|
6
|
+
integrationCycleVerified,
|
|
7
|
+
integrationCycleCurrent,
|
|
8
|
+
} from './integration-state'
|
|
5
9
|
|
|
6
10
|
/** The deterministic part of land's guard. Live completeness and CAS remain at the write boundary. */
|
|
7
11
|
export function landPreconditions(state: BuildState, restack: LeafRestackState): boolean {
|
|
8
12
|
const decision = state.landing?.decision
|
|
9
13
|
return (
|
|
10
14
|
!!decision &&
|
|
15
|
+
(state.kind !== 'node' || integrationCycleCurrent(state)) &&
|
|
11
16
|
state.status !== 'paused' &&
|
|
12
17
|
!state.currentPhase &&
|
|
13
18
|
!state.openEscalations.length &&
|
|
@@ -1,9 +1,42 @@
|
|
|
1
|
+
import type { RuntimeIdentity } from '../events/runtime'
|
|
1
2
|
import type { CompatibilityState } from '../events/compatibility'
|
|
2
3
|
import type { BuildState } from './reducer'
|
|
3
4
|
import type { BuildStore } from '../store/types'
|
|
4
5
|
import type { Actor } from '../events/envelope'
|
|
5
6
|
import { readBuildFacts } from '../store/reduced-reads'
|
|
6
7
|
|
|
8
|
+
const drainingExecutions = new WeakMap<BuildStore, { instance: string; runtime: RuntimeIdentity }>()
|
|
9
|
+
/** Carry the caller's own immutable execution identity through nested kernel
|
|
10
|
+
* helpers without adding repository authority to a build-scoped store. */
|
|
11
|
+
export function withDrainingExecution<T extends BuildStore>(
|
|
12
|
+
store: T,
|
|
13
|
+
instance: string,
|
|
14
|
+
runtime: RuntimeIdentity,
|
|
15
|
+
): T {
|
|
16
|
+
const scoped = new Proxy(store, {
|
|
17
|
+
get(target, key) {
|
|
18
|
+
const value = Reflect.get(target, key, target)
|
|
19
|
+
return typeof value === 'function' ? value.bind(target) : value
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
drainingExecutions.set(scoped, { instance, runtime })
|
|
23
|
+
return scoped
|
|
24
|
+
}
|
|
25
|
+
async function authorizedDrainingExecution(store: BuildStore, slug: string): Promise<boolean> {
|
|
26
|
+
const execution = drainingExecutions.get(store)
|
|
27
|
+
if (!execution) return false
|
|
28
|
+
const authorization = (await readBuildFacts(store, slug)).value.state.drainingExecutions?.[
|
|
29
|
+
execution.instance
|
|
30
|
+
]?.authorization
|
|
31
|
+
return (
|
|
32
|
+
!!authorization &&
|
|
33
|
+
authorization.runtime.version === execution.runtime.version &&
|
|
34
|
+
authorization.runtime.commit === execution.runtime.commit &&
|
|
35
|
+
authorization.runtime.source.kind === execution.runtime.source.kind &&
|
|
36
|
+
authorization.runtime.source.location === execution.runtime.source.location
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
7
40
|
export function compatibilityDiagnostic(facts: CompatibilityState): string | undefined {
|
|
8
41
|
if (facts.decisiveFacts === 0) return undefined
|
|
9
42
|
const versions = facts.decisiveWriterVersions.length
|
|
@@ -28,6 +61,7 @@ export async function deferMixedVersion(
|
|
|
28
61
|
const { state } = (await readBuildFacts(store, slug)).value
|
|
29
62
|
const diagnostic = compatibilityDiagnostic(state.compatibility)
|
|
30
63
|
if (!diagnostic) return false
|
|
64
|
+
if (await authorizedDrainingExecution(store, slug)) return true
|
|
31
65
|
const facts = state.compatibility
|
|
32
66
|
if (state.compatibilityDeferredBoundary === facts.decisiveBoundary) return true
|
|
33
67
|
const written = await store.appendIfCurrent(slug, state.lastSeq, {
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import type { AbEvent } from '../events/catalog'
|
|
3
|
+
import type { BuildState } from './reducer'
|
|
4
|
+
|
|
5
|
+
export interface NodePollingPolicy {
|
|
6
|
+
nodeIdleAfterSeconds: number
|
|
7
|
+
nodeIdlePollSeconds: number
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Canonical serialization also survives JSONB key reordering. */
|
|
11
|
+
function canonical(value: unknown): string {
|
|
12
|
+
if (Array.isArray(value)) return `[${value.map(canonical).join(',')}]`
|
|
13
|
+
if (value !== null && typeof value === 'object')
|
|
14
|
+
return `{${Object.entries(value)
|
|
15
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
16
|
+
.map(([k, v]) => `${JSON.stringify(k)}:${canonical(v)}`)
|
|
17
|
+
.join(',')}}`
|
|
18
|
+
return JSON.stringify(value) ?? 'null'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const observations = new Set([
|
|
22
|
+
'node.compared',
|
|
23
|
+
'node.parent-distance',
|
|
24
|
+
'integration.observed',
|
|
25
|
+
'target.moved',
|
|
26
|
+
'node.inventory',
|
|
27
|
+
'landing.decided',
|
|
28
|
+
'node.parent-rejected',
|
|
29
|
+
])
|
|
30
|
+
|
|
31
|
+
/** Commands retain identity, even repeated holds. Observations retain meaning.
|
|
32
|
+
* The bounded map has at most one entry per event type, never per log entry. */
|
|
33
|
+
export function advancePollingActivity(activity: Record<string, string>, event: AbEvent): void {
|
|
34
|
+
if (
|
|
35
|
+
event.type === 'node.poll-checked' ||
|
|
36
|
+
event.type === 'observation.recorded' ||
|
|
37
|
+
event.type.startsWith('session.') ||
|
|
38
|
+
event.type.startsWith('runner.') ||
|
|
39
|
+
event.type.startsWith('workspace.') ||
|
|
40
|
+
event.type.startsWith('build.janitor-')
|
|
41
|
+
)
|
|
42
|
+
return
|
|
43
|
+
activity[event.type] = observations.has(event.type) ? canonical(event.payload) : String(event.seq)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function nodeActivityKey(
|
|
47
|
+
state: Pick<BuildState, 'pollingActivity'>,
|
|
48
|
+
children: readonly { slug: string; state: Pick<BuildState, 'pollingActivity'> }[],
|
|
49
|
+
): string {
|
|
50
|
+
return createHash('sha256')
|
|
51
|
+
.update(
|
|
52
|
+
canonical({
|
|
53
|
+
own: state.pollingActivity,
|
|
54
|
+
children: children
|
|
55
|
+
.map(({ slug, state: child }) => ({ slug, activity: child.pollingActivity }))
|
|
56
|
+
.sort((a, b) => a.slug.localeCompare(b.slug)),
|
|
57
|
+
}),
|
|
58
|
+
)
|
|
59
|
+
.digest('hex')
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Ticket membership needs claims, PR lifecycle and operator demand, not each
|
|
63
|
+
* plan/review/verification event that keeps GitHub observation active. */
|
|
64
|
+
export function nodeTicketObservationKey(
|
|
65
|
+
state: Pick<BuildState, 'pollingActivity'>,
|
|
66
|
+
children: readonly { slug: string; state: Pick<BuildState, 'pollingActivity'> }[],
|
|
67
|
+
): string {
|
|
68
|
+
const select = (activity: BuildState['pollingActivity'], types: readonly string[]) =>
|
|
69
|
+
Object.fromEntries(
|
|
70
|
+
types.flatMap((type) => (activity?.[type] === undefined ? [] : [[type, activity[type]]])),
|
|
71
|
+
)
|
|
72
|
+
return nodeActivityKey(
|
|
73
|
+
{
|
|
74
|
+
pollingActivity: select(state.pollingActivity, [
|
|
75
|
+
'build.land-requested',
|
|
76
|
+
'build.hold-requested',
|
|
77
|
+
'node.restack-requested',
|
|
78
|
+
'escalation.answered',
|
|
79
|
+
'node.parent-requested',
|
|
80
|
+
'node.parent-accepted',
|
|
81
|
+
]),
|
|
82
|
+
},
|
|
83
|
+
children.map((child) => ({
|
|
84
|
+
slug: child.slug,
|
|
85
|
+
state: {
|
|
86
|
+
pollingActivity: select(child.state.pollingActivity, [
|
|
87
|
+
'build.created',
|
|
88
|
+
'pr.opened',
|
|
89
|
+
'finalize.completed',
|
|
90
|
+
'pr.merged',
|
|
91
|
+
'pr.closed',
|
|
92
|
+
'build.completed',
|
|
93
|
+
'build.aborted',
|
|
94
|
+
'node.contribution-recorded',
|
|
95
|
+
'integration.landed',
|
|
96
|
+
]),
|
|
97
|
+
},
|
|
98
|
+
})),
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Pending operations always bypass cadence; hold and absent consent do not. */
|
|
103
|
+
export function nodePollingUnsettled(state: BuildState): boolean {
|
|
104
|
+
return (
|
|
105
|
+
!state.nodeOpened ||
|
|
106
|
+
!state.nodeComparison ||
|
|
107
|
+
state.nodeRestack?.distance?.count === null ||
|
|
108
|
+
!!state.currentPhase ||
|
|
109
|
+
state.status === 'done' ||
|
|
110
|
+
state.status === 'aborted' ||
|
|
111
|
+
state.prState === 'closed' ||
|
|
112
|
+
state.prState === 'merged' ||
|
|
113
|
+
state.pendingCommands.length > 0 ||
|
|
114
|
+
state.sessions.open.length > 0 ||
|
|
115
|
+
!!state.landing?.native?.operation ||
|
|
116
|
+
!!state.landing?.native?.enabled ||
|
|
117
|
+
!!state.landing?.nativeEnablePending ||
|
|
118
|
+
!!state.landing?.applicationFailure ||
|
|
119
|
+
!!(
|
|
120
|
+
state.pr &&
|
|
121
|
+
state.landing?.command &&
|
|
122
|
+
state.landing.command.seq !== state.landing.acknowledgedSeq
|
|
123
|
+
) ||
|
|
124
|
+
!!state.nodeRestack?.active ||
|
|
125
|
+
!!state.nodeRestack?.parentRequest ||
|
|
126
|
+
!!state.nodeRestack?.parentChange ||
|
|
127
|
+
Object.keys(state.nodeRestack?.requests ?? {}).length > 0 ||
|
|
128
|
+
!!state.integration?.intent
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function nodePollingSchedule(
|
|
133
|
+
state: BuildState,
|
|
134
|
+
activityKey: string,
|
|
135
|
+
policy: NodePollingPolicy,
|
|
136
|
+
now: Date,
|
|
137
|
+
unsettled = nodePollingUnsettled(state),
|
|
138
|
+
) {
|
|
139
|
+
const check = state.nodePolling
|
|
140
|
+
const time = now.getTime()
|
|
141
|
+
const checked = Date.parse(check?.checkedAt ?? '')
|
|
142
|
+
const unchanged = Date.parse(check?.unchangedSince ?? '')
|
|
143
|
+
const idle =
|
|
144
|
+
!unsettled &&
|
|
145
|
+
check?.activityKey === activityKey &&
|
|
146
|
+
check.nodeIdleAfterSeconds === policy.nodeIdleAfterSeconds &&
|
|
147
|
+
check.nodeIdlePollSeconds === policy.nodeIdlePollSeconds &&
|
|
148
|
+
Number.isFinite(time) &&
|
|
149
|
+
Number.isFinite(checked) &&
|
|
150
|
+
Number.isFinite(unchanged) &&
|
|
151
|
+
unchanged <= checked &&
|
|
152
|
+
checked <= time &&
|
|
153
|
+
time - unchanged >= policy.nodeIdleAfterSeconds * 1000
|
|
154
|
+
return {
|
|
155
|
+
mode: idle ? ('idle' as const) : ('active' as const),
|
|
156
|
+
due: !idle || time - checked >= policy.nodeIdlePollSeconds * 1000,
|
|
157
|
+
intervalSeconds: policy.nodeIdlePollSeconds,
|
|
158
|
+
lastChecked: check?.checkedAt,
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ticketMigrationsReducer } from './ticket-migrations'
|
|
2
|
+
import { dispatchUpgradeReducer } from './dispatch-upgrade'
|
|
2
3
|
import {
|
|
3
4
|
advanceCompatibility,
|
|
4
5
|
initialCompatibility,
|
|
@@ -114,7 +115,16 @@ const parts = {
|
|
|
114
115
|
dashboard: dashboardFactsReducer,
|
|
115
116
|
deferral: currentDeferralObservationReducer,
|
|
116
117
|
}
|
|
118
|
+
export interface RunnerAttach {
|
|
119
|
+
seq: number
|
|
120
|
+
ts: string
|
|
121
|
+
instance: string
|
|
122
|
+
host: string
|
|
123
|
+
resumedFromSeq?: number
|
|
124
|
+
runtime: import('../events/runtime').RuntimeIdentity | null
|
|
125
|
+
}
|
|
117
126
|
export interface BuildReadAcc {
|
|
127
|
+
runnerAttaches: RunnerAttach[]
|
|
118
128
|
summaryRequests: ReturnType<typeof summaryRequestsReducer.initial>
|
|
119
129
|
summaryBoundary: ReturnType<typeof summaryBoundaryReducer.initial>
|
|
120
130
|
hostedImages: ReturnType<typeof hostedPrAttachmentsReducer.initial>
|
|
@@ -190,8 +200,9 @@ export interface BuildReadAcc {
|
|
|
190
200
|
}
|
|
191
201
|
export const buildReadFactsReducer = defineReducer({
|
|
192
202
|
rawEvents: true,
|
|
193
|
-
version:
|
|
203
|
+
version: 4 + Object.values(parts).reduce((sum, reducer) => sum + reducer.version, 0),
|
|
194
204
|
initial: (): BuildReadAcc => ({
|
|
205
|
+
runnerAttaches: [],
|
|
195
206
|
summaryRequests: summaryRequestsReducer.initial(),
|
|
196
207
|
summaryBoundary: summaryBoundaryReducer.initial(),
|
|
197
208
|
hostedImages: hostedPrAttachmentsReducer.initial(),
|
|
@@ -263,6 +274,14 @@ export const buildReadFactsReducer = defineReducer({
|
|
|
263
274
|
acc.dashboard = dashboardFactsReducer.advance(acc.dashboard, events)
|
|
264
275
|
acc.deferral = currentDeferralObservationReducer.advance(acc.deferral, events)
|
|
265
276
|
for (const event of projectEvents(events)) {
|
|
277
|
+
if (event.type === 'runner.attached')
|
|
278
|
+
acc.runnerAttaches.push({ seq: event.seq, ts: event.ts, ...event.payload, runtime: null })
|
|
279
|
+
if (event.type === 'runner.runtime-recorded') {
|
|
280
|
+
const attach = acc.runnerAttaches.find(
|
|
281
|
+
(a) => a.seq === event.payload.attachedSeq && a.instance === event.payload.instance,
|
|
282
|
+
)
|
|
283
|
+
if (attach) attach.runtime = event.payload.runtime
|
|
284
|
+
}
|
|
266
285
|
if (event.type === 'plan-review.verdict' || event.type === 'code-review.verdict')
|
|
267
286
|
acc.summaryHistory.push({
|
|
268
287
|
kind: 'review',
|
|
@@ -384,6 +403,7 @@ export const buildReadFactsReducer = defineReducer({
|
|
|
384
403
|
}
|
|
385
404
|
},
|
|
386
405
|
finish: (acc: BuildReadAcc) => ({
|
|
406
|
+
runnerAttaches: structuredClone(acc.runnerAttaches),
|
|
387
407
|
summaryRequests: summaryRequestsReducer.finish(acc.summaryRequests),
|
|
388
408
|
summaryBoundary: summaryBoundaryReducer.finish(acc.summaryBoundary),
|
|
389
409
|
hostedImages: [...hostedPrAttachmentsReducer.finish(acc.hostedImages)],
|
|
@@ -467,6 +487,7 @@ export interface RepositoryReadAcc {
|
|
|
467
487
|
Extract<RepositoryEvent, { type: 'change-presence.observed' }>['payload']
|
|
468
488
|
>
|
|
469
489
|
|
|
490
|
+
upgrades: ReturnType<typeof dispatchUpgradeReducer.initial>
|
|
470
491
|
openHarvest: ReturnType<typeof openHarvestExecutionsReducer.initial>
|
|
471
492
|
attention: ReturnType<typeof repositoryAttentionReducer.initial>
|
|
472
493
|
harvestFailures: Record<
|
|
@@ -512,6 +533,7 @@ export const repositoryReadFactsReducer = defineReducer({
|
|
|
512
533
|
version:
|
|
513
534
|
4 +
|
|
514
535
|
ticketMigrationsReducer.version +
|
|
536
|
+
dispatchUpgradeReducer.version +
|
|
515
537
|
dispatcherRunFactsReducer('version').version +
|
|
516
538
|
openHarvestExecutionsReducer.version +
|
|
517
539
|
forgeHealthReducer.version +
|
|
@@ -526,6 +548,7 @@ export const repositoryReadFactsReducer = defineReducer({
|
|
|
526
548
|
initial: (): RepositoryReadAcc => ({
|
|
527
549
|
compatibility: initialCompatibility(),
|
|
528
550
|
presence: {},
|
|
551
|
+
upgrades: dispatchUpgradeReducer.initial(),
|
|
529
552
|
recentRuns: [],
|
|
530
553
|
openHarvest: openHarvestExecutionsReducer.initial(),
|
|
531
554
|
attention: repositoryAttentionReducer.initial(),
|
|
@@ -551,6 +574,7 @@ export const repositoryReadFactsReducer = defineReducer({
|
|
|
551
574
|
}),
|
|
552
575
|
fold(acc: RepositoryReadAcc, events: readonly RepositoryEvent[]) {
|
|
553
576
|
advanceCompatibility(acc.compatibility, events)
|
|
577
|
+
acc.upgrades = dispatchUpgradeReducer.advance(acc.upgrades, events)
|
|
554
578
|
acc.attention = repositoryAttentionReducer.advance(acc.attention, events)
|
|
555
579
|
acc.openHarvest = openHarvestExecutionsReducer.advance(acc.openHarvest, events)
|
|
556
580
|
acc.settings = dispatchSettingsReducer.advance(acc.settings, events)
|
|
@@ -583,6 +607,12 @@ export const repositoryReadFactsReducer = defineReducer({
|
|
|
583
607
|
if (event.type === 'harvest.execution.authorized')
|
|
584
608
|
acc.harvestAuthorizations[JSON.stringify(event.payload.execution)] ??= event
|
|
585
609
|
if (event.type === 'harvest.resumed') acc.latestHarvestResumedSeq = event.seq
|
|
610
|
+
if (event.type === 'harvest.session.started' && event.payload.continuation) {
|
|
611
|
+
const prior = acc.harvestSessions.find(
|
|
612
|
+
(s) => s.session === event.payload.continuation!.predecessor,
|
|
613
|
+
)
|
|
614
|
+
if (prior) prior.status = 'ended'
|
|
615
|
+
}
|
|
586
616
|
if (event.type === 'harvest.session.started')
|
|
587
617
|
acc.harvestSessions.push({
|
|
588
618
|
run: event.payload.run,
|
|
@@ -591,16 +621,18 @@ export const repositoryReadFactsReducer = defineReducer({
|
|
|
591
621
|
step: event.payload.step,
|
|
592
622
|
round: event.payload.round,
|
|
593
623
|
status: 'open',
|
|
624
|
+
...(event.payload.continuation ? { continuation: event.payload.continuation } : {}),
|
|
594
625
|
...(event.payload.stream === undefined ? {} : { stream: event.payload.stream }),
|
|
595
626
|
streamStatus: event.payload.stream === undefined ? 'closed' : 'open',
|
|
596
627
|
})
|
|
597
|
-
if (event.type === 'harvest.session.ended') {
|
|
628
|
+
if (event.type === 'harvest.session.ended' || event.type === 'harvest.session.suspended') {
|
|
598
629
|
acc.harvestSessionEndings[JSON.stringify(event.payload.session)] ??= event.seq
|
|
599
630
|
const session = acc.harvestSessions.findLast(
|
|
600
631
|
(session) => session.session === event.payload.session && session.status === 'open',
|
|
601
632
|
)
|
|
602
633
|
if (session) {
|
|
603
|
-
session.status = 'ended'
|
|
634
|
+
session.status = event.type === 'harvest.session.suspended' ? 'suspended' : 'ended'
|
|
635
|
+
session.transcript = event.payload.transcript
|
|
604
636
|
session.streamStatus = 'closed'
|
|
605
637
|
}
|
|
606
638
|
}
|
|
@@ -651,6 +683,7 @@ export const repositoryReadFactsReducer = defineReducer({
|
|
|
651
683
|
finish: (acc: RepositoryReadAcc) => ({
|
|
652
684
|
compatibility: structuredClone(acc.compatibility),
|
|
653
685
|
presence: structuredClone(acc.presence),
|
|
686
|
+
upgrades: dispatchUpgradeReducer.finish(acc.upgrades),
|
|
654
687
|
harvestFailures: structuredClone(acc.harvestFailures),
|
|
655
688
|
harvestVerdicts: structuredClone(acc.harvestVerdicts),
|
|
656
689
|
harvestAuthorizations: structuredClone(acc.harvestAuthorizations),
|
|
@@ -692,6 +725,7 @@ export function optionalValue<A, E, V>(reducer: IncrementalReducer<A, E, V>) {
|
|
|
692
725
|
|
|
693
726
|
/** One run's correlation facts. History for unrelated runs never enters this value. */
|
|
694
727
|
export interface DispatcherRunFacts {
|
|
728
|
+
runtime?: RepositoryEvent
|
|
695
729
|
start?: RepositoryEvent
|
|
696
730
|
latestStart?: RepositoryEvent
|
|
697
731
|
stop?: RepositoryEvent
|
|
@@ -702,7 +736,7 @@ export interface DispatcherRunFacts {
|
|
|
702
736
|
}
|
|
703
737
|
export function dispatcherRunFactsReducer(run: string) {
|
|
704
738
|
return defineReducer<DispatcherRunFacts, RepositoryEvent, DispatcherRunFacts>({
|
|
705
|
-
version:
|
|
739
|
+
version: 3,
|
|
706
740
|
initial: () => ({}),
|
|
707
741
|
fold(acc, events) {
|
|
708
742
|
for (const event of projectEvents(events)) {
|
|
@@ -718,7 +752,8 @@ function foldDispatcherRunFact(acc: DispatcherRunFacts, event: RepositoryEvent):
|
|
|
718
752
|
if (event.type === 'dispatcher.run-started') {
|
|
719
753
|
acc.start ??= event
|
|
720
754
|
acc.latestStart = event
|
|
721
|
-
} else if (event.type === 'dispatcher.
|
|
755
|
+
} else if (event.type === 'dispatcher.runtime-recorded') acc.runtime = event
|
|
756
|
+
else if (event.type === 'dispatcher.run-stopped') acc.stop = event
|
|
722
757
|
else if (event.type === 'dispatcher.stop-requested') acc.stopRequest ??= event
|
|
723
758
|
else if (
|
|
724
759
|
event.type === 'dispatcher.tick-started' ||
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ticketMigrationsReducer } from './ticket-migrations'
|
|
2
|
+
import { dispatchUpgradeReducer } from './dispatch-upgrade'
|
|
2
3
|
import { forgeHealthReducer } from './forge-health'
|
|
3
4
|
import { decodeStoredEvent } from '../events/compatibility'
|
|
4
5
|
import { nodeRestackReducer } from './node-restack-state'
|
|
@@ -98,6 +99,7 @@ const REGISTERED: Record<string, Omit<RegisteredReducer, 'valueRead'>> = {
|
|
|
98
99
|
covers: [],
|
|
99
100
|
},
|
|
100
101
|
dispatcherRunFacts: { reducer: dispatcherRunFactsReducer('run-a'), covers: [] },
|
|
102
|
+
dispatchUpgrade: { reducer: dispatchUpgradeReducer, covers: [] },
|
|
101
103
|
repositoryAttention: { reducer: repositoryAttentionReducer, covers: [] },
|
|
102
104
|
repositoryReadFacts: { reducer: repositoryReadFactsReducer, covers: [] },
|
|
103
105
|
buildStreamSeed: { reducer: buildStreamSeedReducer, covers: [] },
|
|
@@ -216,6 +218,7 @@ const repositoryValues = new Set([
|
|
|
216
218
|
'ticketMigrations',
|
|
217
219
|
'forgeHealthValue',
|
|
218
220
|
'repositoryReadFacts',
|
|
221
|
+
'dispatchUpgrade',
|
|
219
222
|
'dispatcherRunFacts',
|
|
220
223
|
'repositoryAttention',
|
|
221
224
|
'effectiveConfig',
|