@defrex/autobuild 1.10.0 → 1.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/SPEC.md +745 -69
- package/bin/ab-dispatch-generation.ts +3 -1
- package/docs/accounts.md +2 -1
- package/docs/answering-blocked-builds.md +20 -0
- package/docs/architecture.md +165 -29
- package/docs/build-store.md +10 -7
- package/docs/cli.md +33 -1
- package/docs/configuration-overview.md +4 -1
- package/docs/configuration.md +381 -29
- package/docs/dispatcher.md +64 -4
- package/docs/forges.md +7 -0
- package/docs/integration-tree.md +2 -2
- package/docs/operating.md +4 -2
- package/docs/operator-api.md +134 -6
- package/docs/operator-surfaces.md +85 -0
- package/docs/optimization-nodes.md +69 -11
- package/docs/plugin-authoring.md +37 -1
- package/docs/remote-store-protocol.md +94 -13
- package/docs/remote-ticket-protocol.md +40 -0
- package/docs/restacking.md +20 -4
- package/docs/setup.md +14 -2
- package/docs/ticket-dependencies.md +10 -3
- package/docs/ticket-sources.md +24 -2
- package/docs/tickets.md +7 -1
- package/docs/troubleshooting.md +8 -0
- package/docs/verification.md +4 -3
- package/docs/workspaces.md +3 -0
- package/package.json +9 -5
- package/packages/core/src/cli/accounts.ts +7 -2
- package/packages/core/src/cli/attention.ts +3 -1
- package/packages/core/src/cli/binary-direct.ts +2 -0
- package/packages/core/src/cli/binary-lifecycle.ts +2 -1
- package/packages/core/src/cli/build-control.ts +79 -1
- package/packages/core/src/cli/context.ts +4 -0
- package/packages/core/src/cli/dashboard/facts.ts +49 -53
- package/packages/core/src/cli/dashboard/header.ts +111 -0
- package/packages/core/src/cli/dashboard/model.ts +31 -39
- package/packages/core/src/cli/dashboard/objective-row.ts +46 -14
- package/packages/core/src/cli/dashboard/poll.ts +179 -76
- package/packages/core/src/cli/dashboard/render.ts +159 -230
- package/packages/core/src/cli/dashboard/row-text.ts +538 -0
- package/packages/core/src/cli/dashboard/timeline.ts +288 -0
- package/packages/core/src/cli/dashboard/vocabulary.ts +188 -0
- package/packages/core/src/cli/dispatch-args.ts +44 -1
- package/packages/core/src/cli/dispatch-frontend.ts +40 -40
- package/packages/core/src/cli/dispatch-launch-stop.ts +18 -0
- package/packages/core/src/cli/dispatch-launcher.ts +20 -7
- package/packages/core/src/cli/dispatch-web.ts +155 -0
- package/packages/core/src/cli/dispatch.ts +202 -38
- package/packages/core/src/cli/help.ts +87 -3
- package/packages/core/src/cli/init-validation.ts +3 -3
- package/packages/core/src/cli/main.ts +70 -6
- package/packages/core/src/cli/mcp.ts +35 -3
- package/packages/core/src/cli/objective.ts +1 -1
- package/packages/core/src/cli/operator-preference.ts +57 -0
- package/packages/core/src/cli/repo-lease.ts +2 -0
- package/packages/core/src/cli/repo-state.ts +56 -6
- package/packages/core/src/cli/repository-status.ts +105 -49
- package/packages/core/src/cli/status.ts +82 -1
- package/packages/core/src/cli/terminal-restore.ts +32 -7
- package/packages/core/src/cli/ticket.ts +98 -36
- package/packages/core/src/cli/wait.ts +14 -6
- package/packages/core/src/cli/watch.ts +20 -4
- package/packages/core/src/cli/web.ts +139 -0
- package/packages/core/src/config/live.ts +99 -14
- package/packages/core/src/config/load.ts +61 -20
- package/packages/core/src/config/local.ts +212 -0
- package/packages/core/src/config/pipeline-source.ts +2 -0
- package/packages/core/src/config/reference.ts +18 -0
- package/packages/core/src/config/schema.ts +45 -10
- package/packages/core/src/events/catalog.ts +4 -0
- package/packages/core/src/events/payloads.ts +97 -0
- package/packages/core/src/events/policy.ts +10 -0
- package/packages/core/src/events/repository.ts +46 -3
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +381 -30
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/017d8dd5bb6dd80b.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/178e12f1759b7552.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/4932c70a2af97faf.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/536085773daf6b58.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/6bd6275061aaffa5.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/89625654b02e9ac1.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/a98af134be2da8a9.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/d5d5ccca80a893d8.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/f8155387eb5f375c.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/3c27f918b194e3b3.json +465 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/46196d8f0076496a.json +97 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/79f0e0f4ccd43ba2.json +455 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/859c09edac738823.json +1086 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a283c1f3462b1cc1.json +81 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a6e570fb126991ff.json +36 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a8acf22c968b6e3d.json +81 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/ba7b85895bf6698e.json +1153 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/fc66408cde0b6b04.json +637 -0
- package/packages/core/src/kernel/build-roster.ts +230 -0
- package/packages/core/src/kernel/dispatch-capacity.ts +4 -2
- package/packages/core/src/kernel/dispatch-status.ts +139 -0
- package/packages/core/src/kernel/engine.ts +43 -5
- package/packages/core/src/kernel/execution-intervals.ts +61 -0
- package/packages/core/src/kernel/generators/optimization-log.ts +101 -0
- package/packages/core/src/kernel/generators/repository-journals.ts +13 -0
- package/packages/core/src/kernel/leaf-restack-base.ts +33 -7
- package/packages/core/src/kernel/leaf-restack-state.ts +82 -3
- package/packages/core/src/kernel/log-index.ts +19 -0
- package/packages/core/src/kernel/optimization-admission.ts +244 -3
- package/packages/core/src/kernel/optimization.ts +183 -4
- package/packages/core/src/kernel/phase-failures.ts +121 -0
- package/packages/core/src/kernel/published-branch-head.ts +60 -0
- package/packages/core/src/kernel/read-facts.ts +15 -13
- package/packages/core/src/kernel/reducer-registry.ts +27 -8
- package/packages/core/src/kernel/reducer-revisions.ts +27 -0
- package/packages/core/src/kernel/reducer.ts +63 -4
- package/packages/core/src/kernel/rollup.ts +61 -0
- package/packages/core/src/kernel/setup-streak.ts +38 -0
- package/packages/core/src/kernel/step-durations.ts +257 -0
- package/packages/core/src/kernel/target-observation.ts +6 -1
- package/packages/core/src/kernel/target-rewrite-recovery.ts +116 -0
- package/packages/core/src/kernel/verify-diff-base.ts +5 -0
- package/packages/core/src/kernel/verify-stages.ts +13 -3
- package/packages/core/src/ontology.ts +5 -0
- package/packages/core/src/operator/agent-context-serve.ts +631 -0
- package/packages/core/src/operator/annotations.ts +75 -5
- package/packages/core/src/operator/attention.ts +470 -0
- package/packages/core/src/operator/canonical-skills.ts +35 -0
- package/packages/core/src/operator/cli-equivalents.ts +270 -0
- package/packages/core/src/operator/context-prompts.ts +61 -0
- package/packages/core/src/operator/index.ts +49 -1
- package/packages/core/src/operator/landings.ts +28 -19
- package/packages/core/src/operator/optimization.ts +7 -0
- package/packages/core/src/operator/protocol.ts +3 -0
- package/packages/core/src/operator/query.ts +129 -74
- package/packages/core/src/operator/read-view.ts +5 -2
- package/packages/core/src/operator/registry.ts +406 -46
- package/packages/core/src/operator/requests.ts +20 -18
- package/packages/core/src/operator/sandbox-host.ts +107 -11
- package/packages/core/src/operator/sandbox-resolver.ts +253 -0
- package/packages/core/src/operator/sandbox.ts +778 -82
- package/packages/core/src/operator/ticket-asset-list.ts +77 -0
- package/packages/core/src/operator/ticket-assets.ts +167 -0
- package/packages/core/src/operator/tickets.ts +33 -2
- package/packages/core/src/plugin-sdk/index.ts +22 -0
- package/packages/core/src/plugins/manifest.ts +1 -1
- package/packages/core/src/ports/forge/fake.ts +92 -1
- package/packages/core/src/ports/forge/git-blob.ts +15 -0
- package/packages/core/src/ports/forge/github.ts +82 -0
- package/packages/core/src/ports/forge/local-git.ts +61 -1
- package/packages/core/src/ports/forge-failure.ts +24 -0
- package/packages/core/src/ports/runner/antigravity-test.fixture.ts +149 -0
- package/packages/core/src/ports/runner/claude-test.fixture.ts +71 -0
- package/packages/core/src/ports/runner/codex-test.fixture.ts +63 -0
- package/packages/core/src/ports/tickets/contract.ts +71 -0
- package/packages/core/src/ports/tickets/fake.ts +11 -0
- package/packages/core/src/ports/tickets/file.ts +18 -0
- package/packages/core/src/ports/tickets/github-fake.ts +136 -4
- package/packages/core/src/ports/tickets/github.ts +387 -30
- package/packages/core/src/ports/tickets/hosted-index.ts +10 -0
- package/packages/core/src/ports/tickets/linear.ts +130 -0
- package/packages/core/src/ports/tickets/priority.ts +9 -0
- package/packages/core/src/ports/tickets/remote-protocol.ts +34 -0
- package/packages/core/src/ports/tickets/remote.ts +70 -6
- package/packages/core/src/ports/tickets/search.ts +139 -0
- package/packages/core/src/ports/types.ts +104 -2
- package/packages/core/src/ports/workspace/builtin-capabilities.ts +9 -0
- package/packages/core/src/ports/workspace/create.ts +15 -1
- package/packages/core/src/ports/workspace/fake.ts +340 -12
- package/packages/core/src/ports/workspace/git-worktree.ts +833 -42
- package/packages/core/src/ports/workspace/operator-sandbox.ts +129 -12
- package/packages/core/src/ports/workspace/process-group.ts +48 -0
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +1260 -123
- package/packages/core/src/processes/agent-context-assemble.ts +576 -0
- package/packages/core/src/processes/agent-context.ts +469 -0
- package/packages/core/src/processes/build-runner.ts +387 -236
- package/packages/core/src/processes/dispatcher.ts +211 -55
- package/packages/core/src/processes/execution-no-progress.ts +4 -0
- package/packages/core/src/processes/optimization-activity.ts +120 -0
- package/packages/core/src/processes/phase-failure-budget.ts +1 -0
- package/packages/core/src/processes/repo-view.ts +78 -2
- package/packages/core/src/processes/sandbox-state.ts +53 -6
- package/packages/core/src/processes/tick-publication.ts +2 -0
- package/packages/core/src/processes/workspace-preparation.ts +76 -0
- package/packages/core/src/scenarios/harness.ts +0 -5
- package/packages/core/src/store/account-redaction.ts +1 -0
- package/packages/core/src/store/adapter.ts +52 -1
- package/packages/core/src/store/agent-context.ts +432 -0
- package/packages/core/src/store/build-feed.ts +291 -0
- package/packages/core/src/store/build-scope.ts +19 -1
- package/packages/core/src/store/contract.ts +911 -14
- package/packages/core/src/store/digest.ts +19 -6
- package/packages/core/src/store/histogram.ts +113 -0
- package/packages/core/src/store/local/schema.ts +62 -0
- package/packages/core/src/store/local/store.ts +628 -22
- package/packages/core/src/store/local/ticket-asset-heads.ts +23 -0
- package/packages/core/src/store/memory.ts +461 -69
- package/packages/core/src/store/open-builds.ts +19 -0
- package/packages/core/src/store/phase-session.ts +32 -4
- package/packages/core/src/store/reduced-reads.ts +14 -4
- package/packages/core/src/store/reducer-value-shapes.json +7027 -5751
- package/packages/core/src/store/reducer-values.ts +6 -1
- package/packages/core/src/store/remote/client.ts +208 -2
- package/packages/core/src/store/remote/compatibility.ts +1 -1
- package/packages/core/src/store/remote/index.ts +33 -0
- package/packages/core/src/store/remote/protocol.ts +69 -0
- package/packages/core/src/store/remote/released-clients.json +22 -0
- package/packages/core/src/store/remote/released-reducer-values/1.11.0.json +35680 -0
- package/packages/core/src/store/remote/released-reducer-values/1.11.1.json +35718 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +20 -16
- package/packages/core/src/store/retention.ts +23 -1
- package/packages/core/src/store/rollups.ts +337 -0
- package/packages/core/src/store/session-handle.ts +20 -2
- package/packages/core/src/store/snapshots.ts +10 -0
- package/packages/core/src/store/types.ts +108 -9
- package/packages/core/src/testing/dispatch-journals.ts +117 -0
- package/packages/core/src/testing/dispatch-read-budget.ts +1092 -2
- package/packages/core/src/testing/git-config-isolation.ts +7 -5
- package/packages/core/src/testing/index.ts +27 -0
- package/packages/core/src/testing/memory-operator-sandbox.ts +346 -0
- package/packages/core/src/testing/reduced-read-budget.ts +1873 -98
- package/packages/core/src/web/analytics-source.ts +303 -0
- package/packages/core/src/web/assets/Atkinson-OFL.txt +93 -0
- package/packages/core/src/web/assets/AtkinsonHyperlegibleNext.latin.woff2 +0 -0
- package/packages/core/src/web/assets/JetBrains-OFL.txt +93 -0
- package/packages/core/src/web/assets/JetBrainsMono.latin.woff2 +0 -0
- package/packages/core/src/web/assets/app.css +1 -0
- package/packages/core/src/web/assets/app.js +9 -0
- package/packages/core/src/web/assets/manifest.json +31 -0
- package/packages/core/src/web/assets/theme.js +1 -0
- package/packages/core/src/web/bounded.ts +31 -0
- package/packages/core/src/web/http.ts +315 -0
- package/packages/core/src/web/hub.ts +160 -0
- package/packages/core/src/web/options.ts +38 -0
- package/packages/core/src/web/overview-source.ts +322 -0
- package/packages/core/src/web/page.ts +56 -0
- package/packages/core/src/web/protocol.ts +151 -0
- package/packages/core/src/web/read-only.ts +23 -0
- package/packages/core/src/web/repository-source.ts +39 -0
- package/packages/core/src/web/server.ts +97 -0
- package/skills/code-review/SKILL.md +10 -2
- package/skills/guide/SKILL.md +376 -54
- package/skills/guide/references/accounts.md +2 -1
- package/skills/guide/references/integration-tree.md +2 -2
- package/skills/guide/references/operator-api.md +134 -6
- package/skills/guide/references/optimization-nodes.md +69 -11
- package/skills/guide/references/plugin-authoring.md +37 -1
- package/skills/guide/references/remote-store-protocol.md +94 -13
- package/skills/guide/references/remote-ticket-protocol.md +40 -0
- package/skills/guide/references/restacking.md +20 -4
- package/skills/guide/references/setup.md +14 -2
- package/skills/guide/references/ticket-dependencies.md +10 -3
- package/skills/implement/SKILL.md +23 -4
- package/skills/operate/SKILL.md +134 -32
- package/skills/plan/SKILL.md +10 -4
- package/skills/plan-review/SKILL.md +9 -2
- package/skills/spec/SKILL.md +34 -8
- package/skills/tickets/SKILL.md +51 -5
- package/templates/hosted-service/package.json +2 -2
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `buildRoster`, a rollup (SPEC §7.7): every live build plus the newest
|
|
3
|
+
* finished builds, with their outcome and completion time.
|
|
4
|
+
*
|
|
5
|
+
* - `buildRosterEntry` is the build-scope reducer it reads: the build's kind,
|
|
6
|
+
* its creation time and its latest terminal fact. `build.completed` and
|
|
7
|
+
* `build.aborted` overwrite one terminal field in log order, the build
|
|
8
|
+
* reducer's "terminal, latest wins" rule (SPEC §15.5).
|
|
9
|
+
* - The accumulator keeps every live entry and the newest
|
|
10
|
+
* `BUILD_ROSTER_HISTORY` finished entries. A completion beyond the cap
|
|
11
|
+
* prunes the oldest; a build that leaves the history is not replaced by an
|
|
12
|
+
* older completion, so the answer may show fewer finished builds than
|
|
13
|
+
* `BUILD_ROSTER_FINISHED` after many reopens.
|
|
14
|
+
* - No key or read-time arguments: one key per repository.
|
|
15
|
+
*
|
|
16
|
+
* Pure and browser-safe.
|
|
17
|
+
*/
|
|
18
|
+
import { z } from 'zod'
|
|
19
|
+
import type { AbEvent } from '../events/catalog'
|
|
20
|
+
import type { BuildOutcome } from '../ontology'
|
|
21
|
+
import { defineReducer } from './incremental'
|
|
22
|
+
import { reducerVersion } from './reducer-identity'
|
|
23
|
+
import type { RollupDefinition } from './rollup'
|
|
24
|
+
|
|
25
|
+
/** Finished entries the accumulator retains. */
|
|
26
|
+
export const BUILD_ROSTER_HISTORY = 50
|
|
27
|
+
/** Finished entries the answer reports. */
|
|
28
|
+
export const BUILD_ROSTER_FINISHED = 10
|
|
29
|
+
|
|
30
|
+
export type RosterOutcome = 'merged' | 'closed' | 'aborted'
|
|
31
|
+
export type RosterKind = 'work' | 'node'
|
|
32
|
+
|
|
33
|
+
/** A terminal fact's roster outcome: `merged` stays, every other completion
|
|
34
|
+
* outcome is `closed`, an abort is `aborted`. */
|
|
35
|
+
export function rosterOutcome(terminal: BuildOutcome | 'aborted'): RosterOutcome {
|
|
36
|
+
return terminal === 'merged' || terminal === 'aborted' ? terminal : 'closed'
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** One build's roster entry: `finished` is present exactly when the build
|
|
40
|
+
* reducer's status is `done` or `aborted`. */
|
|
41
|
+
export interface BuildRosterEntry {
|
|
42
|
+
kind: RosterKind
|
|
43
|
+
/** Timestamp of the build's first event. */
|
|
44
|
+
createdAt?: string
|
|
45
|
+
finished?: { outcome: RosterOutcome; completedAt: string }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface RosterEntryAcc {
|
|
49
|
+
kind: RosterKind
|
|
50
|
+
createdAt?: string
|
|
51
|
+
terminal?: { outcome: RosterOutcome; at: string }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const buildRosterEntryReducer = defineReducer<RosterEntryAcc, AbEvent, BuildRosterEntry>({
|
|
55
|
+
identity: 'buildRosterEntry',
|
|
56
|
+
initial: () => ({ kind: 'work' }),
|
|
57
|
+
fold(acc, events) {
|
|
58
|
+
for (const event of events) {
|
|
59
|
+
acc.createdAt ??= event.ts
|
|
60
|
+
switch (event.type) {
|
|
61
|
+
case 'build.created':
|
|
62
|
+
acc.kind = event.payload.kind ?? 'work'
|
|
63
|
+
break
|
|
64
|
+
// Terminal, latest wins: an in-order overwrite, cleared by nothing.
|
|
65
|
+
case 'build.completed':
|
|
66
|
+
acc.terminal = { outcome: rosterOutcome(event.payload.outcome), at: event.ts }
|
|
67
|
+
break
|
|
68
|
+
case 'build.aborted':
|
|
69
|
+
acc.terminal = { outcome: 'aborted', at: event.ts }
|
|
70
|
+
break
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
finish: (acc) => ({
|
|
75
|
+
kind: acc.kind,
|
|
76
|
+
...(acc.createdAt !== undefined ? { createdAt: acc.createdAt } : {}),
|
|
77
|
+
...(acc.terminal !== undefined
|
|
78
|
+
? { finished: { outcome: acc.terminal.outcome, completedAt: acc.terminal.at } }
|
|
79
|
+
: {}),
|
|
80
|
+
}),
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
const position = z.string().regex(/^(0|[1-9][0-9]*)$/)
|
|
84
|
+
const kindSchema = z.enum(['work', 'node'])
|
|
85
|
+
const liveEntrySchema = z
|
|
86
|
+
.object({ slug: z.string().min(1), kind: kindSchema, createdAt: z.string().optional() })
|
|
87
|
+
.strict()
|
|
88
|
+
const finishedEntrySchema = z
|
|
89
|
+
.object({
|
|
90
|
+
slug: z.string().min(1),
|
|
91
|
+
kind: kindSchema,
|
|
92
|
+
outcome: z.enum(['merged', 'closed', 'aborted']),
|
|
93
|
+
completedAt: z.string(),
|
|
94
|
+
})
|
|
95
|
+
.strict()
|
|
96
|
+
export type BuildRosterLive = z.infer<typeof liveEntrySchema>
|
|
97
|
+
export type BuildRosterFinished = z.infer<typeof finishedEntrySchema>
|
|
98
|
+
|
|
99
|
+
const contributionSchema = z.discriminatedUnion('state', [
|
|
100
|
+
liveEntrySchema.extend({ state: z.literal('live') }),
|
|
101
|
+
finishedEntrySchema.extend({ state: z.literal('finished') }),
|
|
102
|
+
])
|
|
103
|
+
export type BuildRosterContribution = z.infer<typeof contributionSchema>
|
|
104
|
+
|
|
105
|
+
const accSchema = z
|
|
106
|
+
.object({
|
|
107
|
+
live: z.record(z.string().min(1), liveEntrySchema),
|
|
108
|
+
/** Newest first; `expired` and `prune` enforce the cap. */
|
|
109
|
+
finished: z.array(finishedEntrySchema),
|
|
110
|
+
})
|
|
111
|
+
.strict()
|
|
112
|
+
export type BuildRosterAcc = z.infer<typeof accSchema>
|
|
113
|
+
|
|
114
|
+
const valueSchema = z
|
|
115
|
+
.object({
|
|
116
|
+
position,
|
|
117
|
+
live: z.array(liveEntrySchema),
|
|
118
|
+
finished: z.array(finishedEntrySchema).max(BUILD_ROSTER_FINISHED),
|
|
119
|
+
})
|
|
120
|
+
.strict()
|
|
121
|
+
export interface BuildRosterValue {
|
|
122
|
+
/** The repository change position the answer reflects. */
|
|
123
|
+
position: string
|
|
124
|
+
/** Every live build, oldest first (no creation time first), then by slug. */
|
|
125
|
+
live: BuildRosterLive[]
|
|
126
|
+
/** Up to `BUILD_ROSTER_FINISHED` retained finished builds, newest first. */
|
|
127
|
+
finished: BuildRosterFinished[]
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const noArgs = z.object({}).strict()
|
|
131
|
+
type NoArgs = z.infer<typeof noArgs>
|
|
132
|
+
|
|
133
|
+
const order = (a: string, b: string) => (a < b ? -1 : a > b ? 1 : 0)
|
|
134
|
+
/** Newest completion first, then slug. */
|
|
135
|
+
const newestFirst = (a: BuildRosterFinished, b: BuildRosterFinished) =>
|
|
136
|
+
order(b.completedAt, a.completedAt) || order(a.slug, b.slug)
|
|
137
|
+
|
|
138
|
+
function contribute(
|
|
139
|
+
value: unknown,
|
|
140
|
+
_args: NoArgs,
|
|
141
|
+
_now: Date,
|
|
142
|
+
slug: string,
|
|
143
|
+
): BuildRosterContribution {
|
|
144
|
+
const entry = value as BuildRosterEntry
|
|
145
|
+
if (entry.finished !== undefined)
|
|
146
|
+
return {
|
|
147
|
+
state: 'finished',
|
|
148
|
+
slug,
|
|
149
|
+
kind: entry.kind,
|
|
150
|
+
outcome: entry.finished.outcome,
|
|
151
|
+
completedAt: entry.finished.completedAt,
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
state: 'live',
|
|
155
|
+
slug,
|
|
156
|
+
kind: entry.kind,
|
|
157
|
+
...(entry.createdAt !== undefined ? { createdAt: entry.createdAt } : {}),
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function remove(acc: BuildRosterAcc, slug: string): void {
|
|
162
|
+
const at = acc.finished.findIndex((entry) => entry.slug === slug)
|
|
163
|
+
if (at >= 0) acc.finished.splice(at, 1)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function add(acc: BuildRosterAcc, contribution: BuildRosterContribution): void {
|
|
167
|
+
const { state, ...entry } = contribution
|
|
168
|
+
if (state === 'live') {
|
|
169
|
+
acc.live[entry.slug] = entry as BuildRosterLive
|
|
170
|
+
return
|
|
171
|
+
}
|
|
172
|
+
const finished = entry as BuildRosterFinished
|
|
173
|
+
remove(acc, finished.slug)
|
|
174
|
+
let at = acc.finished.findIndex((other) => newestFirst(finished, other) < 0)
|
|
175
|
+
if (at < 0) at = acc.finished.length
|
|
176
|
+
acc.finished.splice(at, 0, finished)
|
|
177
|
+
acc.finished.length = Math.min(acc.finished.length, BUILD_ROSTER_HISTORY)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Remove a build's entry. A finished entry already pruned is a no-op, and
|
|
181
|
+
* nothing older takes its place. */
|
|
182
|
+
function subtract(acc: BuildRosterAcc, contribution: BuildRosterContribution): void {
|
|
183
|
+
if (contribution.state === 'live') delete acc.live[contribution.slug]
|
|
184
|
+
else remove(acc, contribution.slug)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const expired = (acc: BuildRosterAcc) => acc.finished.length > BUILD_ROSTER_HISTORY
|
|
188
|
+
|
|
189
|
+
function prune(acc: BuildRosterAcc): boolean {
|
|
190
|
+
if (!expired(acc)) return false
|
|
191
|
+
acc.finished.length = BUILD_ROSTER_HISTORY
|
|
192
|
+
return true
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function finish(acc: BuildRosterAcc, _read: NoArgs, _now: Date, at: string): BuildRosterValue {
|
|
196
|
+
const live = Object.values(acc.live)
|
|
197
|
+
.map((entry) => ({ ...entry }))
|
|
198
|
+
.sort(
|
|
199
|
+
(a, b) =>
|
|
200
|
+
(a.createdAt === undefined ? 0 : 1) - (b.createdAt === undefined ? 0 : 1) ||
|
|
201
|
+
order(a.createdAt ?? '', b.createdAt ?? '') ||
|
|
202
|
+
order(a.slug, b.slug),
|
|
203
|
+
)
|
|
204
|
+
const finished = acc.finished.slice(0, BUILD_ROSTER_FINISHED).map((entry) => ({ ...entry }))
|
|
205
|
+
return { position: at, live, finished }
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export const buildRosterRollup: RollupDefinition<
|
|
209
|
+
NoArgs,
|
|
210
|
+
NoArgs,
|
|
211
|
+
BuildRosterAcc,
|
|
212
|
+
BuildRosterContribution,
|
|
213
|
+
BuildRosterValue
|
|
214
|
+
> = {
|
|
215
|
+
identity: 'buildRoster',
|
|
216
|
+
version: reducerVersion('buildRoster', [buildRosterEntryReducer]),
|
|
217
|
+
buildReducer: 'buildRosterEntry',
|
|
218
|
+
args: noArgs,
|
|
219
|
+
read: noArgs,
|
|
220
|
+
accSchema,
|
|
221
|
+
contributionSchema,
|
|
222
|
+
valueSchema,
|
|
223
|
+
initial: () => ({ live: {}, finished: [] }),
|
|
224
|
+
contribute,
|
|
225
|
+
add,
|
|
226
|
+
subtract,
|
|
227
|
+
expired,
|
|
228
|
+
prune,
|
|
229
|
+
finish,
|
|
230
|
+
}
|
|
@@ -239,10 +239,12 @@ function leafSlotRequest(build: CapacityBuild, now: Date): SlotRequest | undefin
|
|
|
239
239
|
!parkedLeaf(build, now) ||
|
|
240
240
|
state.status === 'paused' ||
|
|
241
241
|
state.status === 'blocked' ||
|
|
242
|
-
(state.compatibility?.decisiveFacts ?? 0) > 0
|
|
243
|
-
state.targetRewrite !== undefined
|
|
242
|
+
(state.compatibility?.decisiveFacts ?? 0) > 0
|
|
244
243
|
)
|
|
245
244
|
return undefined
|
|
245
|
+
// A parked leaf on a rewritten target needs a runner to leave the wait: it
|
|
246
|
+
// reprovisions itself or raises its one escalation (SPEC §7.4).
|
|
247
|
+
if (state.targetRewrite !== undefined) return 'resume'
|
|
246
248
|
// A ticket wait parks a leaf mid-pipeline: it asks for a slot only once the
|
|
247
249
|
// wait has ended, to resume the phase that declared it.
|
|
248
250
|
if (waitParked(state)) return waitResumeDue(state) ? 'resume' : undefined
|
|
@@ -192,6 +192,145 @@ export function dispatchStatusReducer(
|
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
+
/** Shared current reads retain a fixed recent window of dispatcher runs. It
|
|
196
|
+
* bounds `recentRuns` in repository read facts and the pending runs the
|
|
197
|
+
* reported dispatch status tracks. Historical holder correlations outside it
|
|
198
|
+
* use the explicitly parameterized cache. */
|
|
199
|
+
export const RECENT_DISPATCH_RUN_LIMIT = 16
|
|
200
|
+
|
|
201
|
+
/** A started, unstopped run other than the reported one, folded from its own
|
|
202
|
+
* `dispatcher.run-started` onward. `started` is that start's seq. */
|
|
203
|
+
export interface PendingDispatchRun {
|
|
204
|
+
started: number
|
|
205
|
+
status: DispatchStatus
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Which dispatcher run the repository's reduced status describes. */
|
|
209
|
+
export interface ReportedDispatch {
|
|
210
|
+
run?: string
|
|
211
|
+
status: DispatchStatus
|
|
212
|
+
/** Whether the reported run has recorded a tick boundary. */
|
|
213
|
+
ticked: boolean
|
|
214
|
+
/** Seq of the reported run's latest retained start; 0 when never seen. */
|
|
215
|
+
started: number
|
|
216
|
+
/** Sorted ascending by `started`, at most `RECENT_DISPATCH_RUN_LIMIT`. */
|
|
217
|
+
pending: PendingDispatchRun[]
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export function initialReportedDispatch(): ReportedDispatch {
|
|
221
|
+
return {
|
|
222
|
+
status: dispatchStatusReducer('initial').initial(),
|
|
223
|
+
ticked: false,
|
|
224
|
+
started: 0,
|
|
225
|
+
pending: [],
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function stopped(status: Readonly<DispatchStatus>): boolean {
|
|
230
|
+
return status.health === 'stopped' || status.health === 'failed'
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function tickBoundary(event: RepositoryEvent): boolean {
|
|
234
|
+
return (
|
|
235
|
+
event.type === 'dispatcher.tick-started' ||
|
|
236
|
+
event.type === 'dispatcher.tick-completed' ||
|
|
237
|
+
event.type === 'dispatcher.tick-failed'
|
|
238
|
+
)
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** Insert in start order, then evict the oldest starts beyond the bound. */
|
|
242
|
+
function retain(state: ReportedDispatch, entry: PendingDispatchRun): void {
|
|
243
|
+
let index = state.pending.length
|
|
244
|
+
while (index > 0 && state.pending[index - 1]!.started > entry.started) index--
|
|
245
|
+
state.pending.splice(index, 0, entry)
|
|
246
|
+
while (state.pending.length > RECENT_DISPATCH_RUN_LIMIT) state.pending.shift()
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** Move the reported run aside (while it is live) and report `status`. */
|
|
250
|
+
function report(
|
|
251
|
+
state: ReportedDispatch,
|
|
252
|
+
status: DispatchStatus,
|
|
253
|
+
started: number,
|
|
254
|
+
ticked: boolean,
|
|
255
|
+
): void {
|
|
256
|
+
if (state.run !== undefined && !stopped(state.status))
|
|
257
|
+
retain(state, { started: state.started, status: state.status })
|
|
258
|
+
state.run = status.run
|
|
259
|
+
state.status = status
|
|
260
|
+
state.started = started
|
|
261
|
+
state.ticked = ticked
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** Fold one repository event into the reported dispatcher run, in place.
|
|
265
|
+
*
|
|
266
|
+
* The reported run is the one that holds repository authority, or held it
|
|
267
|
+
* most recently, as far as the journal shows: a run that has recorded a tick
|
|
268
|
+
* boundary (`tick-started`, `tick-completed`, `tick-failed`). A run that
|
|
269
|
+
* starts while a ticked, live run is reported waits in `pending` and only
|
|
270
|
+
* displaces it by recording its own tick boundary, so a newcomer that yields
|
|
271
|
+
* and stops never touches the holder's status. When the reported run has
|
|
272
|
+
* stopped or has not ticked yet, a new start is reported at once, as is any
|
|
273
|
+
* start when no run is reported. A tick boundary from a run whose start is
|
|
274
|
+
* no longer retained promotes it too, carrying the last known effective
|
|
275
|
+
* config until the run records its own. Other events from unknown runs are
|
|
276
|
+
* ignored; a run's stop is its last event, so a stopped pending run is
|
|
277
|
+
* dropped rather than remembered.
|
|
278
|
+
*
|
|
279
|
+
* Pending holds at most `RECENT_DISPATCH_RUN_LIMIT` runs, the most recently
|
|
280
|
+
* started, so the state is bounded independent of journal length.
|
|
281
|
+
*
|
|
282
|
+
* `repositoryReadFacts` persists this state: changing this fold or its shape
|
|
283
|
+
* requires a `repositoryReadFacts` reducer revision. */
|
|
284
|
+
export function foldReportedDispatch(state: ReportedDispatch, event: RepositoryEvent): void {
|
|
285
|
+
const run = (event.payload as { run?: unknown }).run
|
|
286
|
+
if (typeof run !== 'string') return
|
|
287
|
+
if (event.type === 'dispatcher.run-started') {
|
|
288
|
+
const fresh = reduceDispatchStatus([event], run)
|
|
289
|
+
if (state.run === run) {
|
|
290
|
+
state.status = fresh
|
|
291
|
+
state.started = event.seq
|
|
292
|
+
state.ticked = false
|
|
293
|
+
return
|
|
294
|
+
}
|
|
295
|
+
const index = state.pending.findIndex((entry) => entry.status.run === run)
|
|
296
|
+
if (index !== -1) state.pending.splice(index, 1)
|
|
297
|
+
if (state.run === undefined || stopped(state.status) || !state.ticked)
|
|
298
|
+
report(state, fresh, event.seq, false)
|
|
299
|
+
else retain(state, { started: event.seq, status: fresh })
|
|
300
|
+
return
|
|
301
|
+
}
|
|
302
|
+
if (state.run === run) {
|
|
303
|
+
state.status = reduceDispatchStatus([event], run, state.status)
|
|
304
|
+
if (tickBoundary(event)) state.ticked = true
|
|
305
|
+
return
|
|
306
|
+
}
|
|
307
|
+
const index = state.pending.findIndex((entry) => entry.status.run === run)
|
|
308
|
+
if (index !== -1) {
|
|
309
|
+
const entry = state.pending[index]!
|
|
310
|
+
if (tickBoundary(event)) {
|
|
311
|
+
state.pending.splice(index, 1)
|
|
312
|
+
report(state, reduceDispatchStatus([event], run, entry.status), entry.started, true)
|
|
313
|
+
} else if (event.type === 'dispatcher.run-stopped') {
|
|
314
|
+
state.pending.splice(index, 1)
|
|
315
|
+
} else {
|
|
316
|
+
entry.status = reduceDispatchStatus([event], run, entry.status)
|
|
317
|
+
}
|
|
318
|
+
return
|
|
319
|
+
}
|
|
320
|
+
if (!tickBoundary(event)) return
|
|
321
|
+
const seed: DispatchStatus = {
|
|
322
|
+
run,
|
|
323
|
+
health: 'running',
|
|
324
|
+
...(state.status.effectiveConfig !== undefined
|
|
325
|
+
? { effectiveConfig: state.status.effectiveConfig }
|
|
326
|
+
: {}),
|
|
327
|
+
roleWarnings: [],
|
|
328
|
+
diagnostics: [],
|
|
329
|
+
lastSeq: 0,
|
|
330
|
+
}
|
|
331
|
+
report(state, reduceDispatchStatus([event], run, seed), 0, true)
|
|
332
|
+
}
|
|
333
|
+
|
|
195
334
|
export function forgeReadinessWarnings(status: Readonly<DispatchStatus>): string[] {
|
|
196
335
|
return (status.forgeReadinessFailures ?? []).map(formatReadinessFailure)
|
|
197
336
|
}
|
|
@@ -47,6 +47,7 @@ import { reduceBuild, type AnsweredEscalation, type BuildState } from './reducer
|
|
|
47
47
|
import { stalledChains, type FindingChain } from './stall'
|
|
48
48
|
import { pendingWaitRequest, waitGuidance, waitResumeRestackCycle } from './ticket-wait'
|
|
49
49
|
import { leafRestackedBase } from './leaf-restack-state'
|
|
50
|
+
import { acceptedRewriteBoundary } from './leaf-restack-base'
|
|
50
51
|
import {
|
|
51
52
|
baselineMeasurementDue,
|
|
52
53
|
pendingMeasurementRequest,
|
|
@@ -113,6 +114,12 @@ export type Decision =
|
|
|
113
114
|
cycle: number
|
|
114
115
|
}
|
|
115
116
|
| { kind: 'capture-reconcile-policy'; reconcileSeq: number }
|
|
117
|
+
/** A leaf parked on a rewritten target (or holding an open no-work reset)
|
|
118
|
+
* with no target-rewrite escalation in this episode: the runner proves
|
|
119
|
+
* whether it has work, then reprovisions it or escalates. */
|
|
120
|
+
| { kind: 'recover-target-rewrite' }
|
|
121
|
+
/** The episode's target-rewrite escalation was answered `accept-target`. */
|
|
122
|
+
| { kind: 'accept-target-rewrite'; escalation: string }
|
|
116
123
|
| { kind: 'wait'; reason: WaitReason }
|
|
117
124
|
| { kind: 'acknowledge'; command: 'pause' | 'resume' | 'abort' }
|
|
118
125
|
| {
|
|
@@ -291,8 +298,25 @@ function decideNextInternal(state: BuildState, log: LogIndex, config: Config): D
|
|
|
291
298
|
return { kind: 'wait', reason: 'awaiting-spec' }
|
|
292
299
|
|
|
293
300
|
// Frozen transactions retain their original destination and may recover.
|
|
294
|
-
|
|
295
|
-
|
|
301
|
+
// A leaf leaves the wait by itself (SPEC §7.4): with no work it is
|
|
302
|
+
// reprovisioned from the current target; with work it raises one escalation
|
|
303
|
+
// per episode, which an operator answers with accept-target or abort. An
|
|
304
|
+
// open no-work reset is completed before any phase work even after the
|
|
305
|
+
// rewrite cleared, because its workspace mutation may already have run.
|
|
306
|
+
const reprovision = state.kind === 'node' ? undefined : log.restack.reprovision
|
|
307
|
+
if ((state.targetRewrite || reprovision) && !log.restack.active && !state.nodeRestack?.active) {
|
|
308
|
+
if (state.kind === 'node' || state.openEscalations.length > 0)
|
|
309
|
+
return { kind: 'wait', reason: 'target-rewritten' }
|
|
310
|
+
const since = state.targetRewrite
|
|
311
|
+
? (state.targetRewriteSince ?? state.targetRewrite.seq)
|
|
312
|
+
: reprovision!.seq
|
|
313
|
+
const latest = state.answeredEscalations.findLast(
|
|
314
|
+
(e) => e.source === 'policy' && e.policyCause === 'target-rewritten' && e.seq > since,
|
|
315
|
+
)
|
|
316
|
+
if (latest?.resolution === 'accept-target')
|
|
317
|
+
return { kind: 'accept-target-rewrite', escalation: latest.id }
|
|
318
|
+
return { kind: 'recover-target-rewrite' }
|
|
319
|
+
}
|
|
296
320
|
|
|
297
321
|
// ── 3. Escalations (§11, §15.6-B) ──────────────────────────────────────────
|
|
298
322
|
// blocked ≡ any open (unanswered) escalation (§15.5).
|
|
@@ -512,7 +536,11 @@ function decideNextInternal(state: BuildState, log: LogIndex, config: Config): D
|
|
|
512
536
|
// the union is the complete durable deduplication history. Both dimensions
|
|
513
537
|
// must match: a later raise for another source or target cannot repair this
|
|
514
538
|
// condition's crash gap or acknowledge its exhausted budget.
|
|
515
|
-
|
|
539
|
+
// A target-rewrite raise belongs to its own episode, never to another
|
|
540
|
+
// condition's dedup history for the same phase, and the reverse.
|
|
541
|
+
const allRaised = [...state.openEscalations, ...state.answeredEscalations].filter(
|
|
542
|
+
(e) => e.policyCause !== 'target-rewritten',
|
|
543
|
+
)
|
|
516
544
|
const raisedAfter = (seq: number, source: EscalationSource, phase: EscalationTarget): boolean =>
|
|
517
545
|
allRaised.some(
|
|
518
546
|
(e) => e.seq > seq && e.source === source && e.phase === phase && e.deferral === undefined,
|
|
@@ -564,7 +592,15 @@ function decideNextInternal(state: BuildState, log: LogIndex, config: Config): D
|
|
|
564
592
|
// selection's `stageCycle` above shares these inputs. Replay identity
|
|
565
593
|
// remains separate: refreshing config or resuming a wait neither restacks
|
|
566
594
|
// the workspace again nor discards its post-reconcile policy.
|
|
567
|
-
|
|
595
|
+
// An accepted rewritten target opens a replay boundary like a completed
|
|
596
|
+
// reconcile: the build's own commits restack onto the current target before
|
|
597
|
+
// any further verification.
|
|
598
|
+
const acceptedBoundary = acceptedRewriteBoundary(log) ?? 0
|
|
599
|
+
const replayBoundary = Math.max(
|
|
600
|
+
log.code.latestApproveSeq,
|
|
601
|
+
log.lastReconcileCompletedSeq,
|
|
602
|
+
acceptedBoundary,
|
|
603
|
+
)
|
|
568
604
|
const cycleBoundary = leafVerifyCycleInputs(log)
|
|
569
605
|
const cycleResults = log.verifyCompleted.filter((v) => v.seq > cycleBoundary)
|
|
570
606
|
const cycleFails = cycleResults.filter((v) => v.outcome === 'fail')
|
|
@@ -718,7 +754,9 @@ function decideNextInternal(state: BuildState, log: LogIndex, config: Config): D
|
|
|
718
754
|
}
|
|
719
755
|
if (
|
|
720
756
|
log.restack.gates[String(replayBoundary)] === undefined &&
|
|
721
|
-
|
|
757
|
+
// A pending finalize owner that publishes and then finishes finalize
|
|
758
|
+
// still restacks onto the accepted target before landing.
|
|
759
|
+
((log.restack.finalizedAt ?? 0) < replayBoundary || replayBoundary === acceptedBoundary) &&
|
|
722
760
|
!log.verifyStarted.some((v) => v.seq > replayBoundary) &&
|
|
723
761
|
!log.verifyCompleted.some((v) => v.seq > replayBoundary)
|
|
724
762
|
) {
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One build's execution facts that an optimization node has not yet
|
|
3
|
+
* acknowledged (SPEC §13.1.1): the input the dispatcher copies into a node's
|
|
4
|
+
* active-hours clock. A served reduced value, advanced incrementally and
|
|
5
|
+
* holding only execution facts, so reading it never costs a read of the
|
|
6
|
+
* build's log, however long it grows.
|
|
7
|
+
*
|
|
8
|
+
* Complete by construction: every fact numbered above `acknowledged` is in
|
|
9
|
+
* `facts`, and the dispatcher acknowledges a count only after the node has
|
|
10
|
+
* recorded it. There is no window and no truncation.
|
|
11
|
+
*/
|
|
12
|
+
import type { AbEvent } from '../events/catalog'
|
|
13
|
+
import { defineReducer } from './incremental'
|
|
14
|
+
|
|
15
|
+
/** One `execution.started` or `execution.ended`, numbered from 1 in log order. */
|
|
16
|
+
export interface ExecutionFact {
|
|
17
|
+
n: number
|
|
18
|
+
kind: 'started' | 'ended'
|
|
19
|
+
instance: string
|
|
20
|
+
/** The fact's envelope timestamp. */
|
|
21
|
+
at: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ExecutionIntervalsValue {
|
|
25
|
+
/** Every execution fact on the build. */
|
|
26
|
+
count: number
|
|
27
|
+
/** The highest count a node has acknowledged with `execution.accounted`. */
|
|
28
|
+
acknowledged: number
|
|
29
|
+
/** The facts numbered above `acknowledged`, in log order. */
|
|
30
|
+
facts: ExecutionFact[]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const executionIntervalsReducer = defineReducer<
|
|
34
|
+
ExecutionIntervalsValue,
|
|
35
|
+
AbEvent,
|
|
36
|
+
ExecutionIntervalsValue
|
|
37
|
+
>({
|
|
38
|
+
identity: 'executionIntervals',
|
|
39
|
+
initial: () => ({ count: 0, acknowledged: 0, facts: [] }),
|
|
40
|
+
fold(acc, events) {
|
|
41
|
+
for (const event of events) {
|
|
42
|
+
if (event.type === 'execution.started' || event.type === 'execution.ended') {
|
|
43
|
+
acc.count += 1
|
|
44
|
+
acc.facts.push({
|
|
45
|
+
n: acc.count,
|
|
46
|
+
kind: event.type === 'execution.started' ? 'started' : 'ended',
|
|
47
|
+
instance: event.payload.instance,
|
|
48
|
+
at: event.ts,
|
|
49
|
+
})
|
|
50
|
+
} else if (event.type === 'execution.accounted') {
|
|
51
|
+
// Folded as a maximum, so a repeated acknowledgment is a no-op; never
|
|
52
|
+
// above the facts this build has, so a later fact is always kept.
|
|
53
|
+
const acknowledged = Math.min(acc.count, Math.max(acc.acknowledged, event.payload.count))
|
|
54
|
+
if (acknowledged === acc.acknowledged) continue
|
|
55
|
+
acc.acknowledged = acknowledged
|
|
56
|
+
acc.facts = acc.facts.filter((fact) => fact.n > acknowledged)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
finish: (acc) => structuredClone(acc),
|
|
61
|
+
})
|
|
@@ -399,6 +399,107 @@ export class OptimizationLogBuilder {
|
|
|
399
399
|
stop(cause: EventWrite<'optimization.stopped'>['payload']['cause'], mode: 'abort' | 'drain') {
|
|
400
400
|
return this.push({ actor: KERNEL, type: 'optimization.stopped', payload: { cause, mode } })
|
|
401
401
|
}
|
|
402
|
+
|
|
403
|
+
/** One of this log's own execution facts. */
|
|
404
|
+
execution(kind: 'started' | 'ended', instance: string) {
|
|
405
|
+
return kind === 'started'
|
|
406
|
+
? this.push({
|
|
407
|
+
actor: DISPATCHER,
|
|
408
|
+
type: 'execution.started',
|
|
409
|
+
payload: { provider: 'local', workspaceRef: '/ws', instance },
|
|
410
|
+
})
|
|
411
|
+
: this.push({
|
|
412
|
+
actor: DISPATCHER,
|
|
413
|
+
type: 'execution.ended',
|
|
414
|
+
payload: { instance, workspaceRef: '/ws', outcome: 'completed' },
|
|
415
|
+
})
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/** A dispatcher batch of attempt execution facts, each `[build, n, kind,
|
|
419
|
+
* instance, minutes before now]`. The watermark is the latest fact. */
|
|
420
|
+
activity(
|
|
421
|
+
facts: [string, number, 'started' | 'ended', string, number][],
|
|
422
|
+
extra: Pick<EventWrite<'optimization.activity-recorded'>['payload'], 'released' | 'settles'> & {
|
|
423
|
+
watermark?: string
|
|
424
|
+
} = {},
|
|
425
|
+
) {
|
|
426
|
+
const now = this.clock
|
|
427
|
+
const written = facts
|
|
428
|
+
.map(([build, n, kind, instance, ago]) => ({
|
|
429
|
+
build,
|
|
430
|
+
n,
|
|
431
|
+
kind,
|
|
432
|
+
instance,
|
|
433
|
+
at: new Date(now - ago * 60_000).toISOString(),
|
|
434
|
+
}))
|
|
435
|
+
.sort((a, b) => (a.at < b.at ? -1 : a.at > b.at ? 1 : a.n - b.n))
|
|
436
|
+
const accounted: Record<string, number> = {}
|
|
437
|
+
for (const fact of written) accounted[fact.build] = Math.max(accounted[fact.build] ?? 0, fact.n)
|
|
438
|
+
const { watermark, ...rest } = extra
|
|
439
|
+
return this.push({
|
|
440
|
+
actor: DISPATCHER,
|
|
441
|
+
type: 'optimization.activity-recorded',
|
|
442
|
+
payload: {
|
|
443
|
+
facts: written,
|
|
444
|
+
accounted,
|
|
445
|
+
watermark: watermark ?? written.at(-1)?.at ?? new Date(now).toISOString(),
|
|
446
|
+
...rest,
|
|
447
|
+
},
|
|
448
|
+
})
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/** A running node's active-hours clock: its own measurement run, attempt
|
|
453
|
+
* runs batched with one still open, a tracked and a released build, and an
|
|
454
|
+
* acknowledged attempt log's execution facts. */
|
|
455
|
+
export function optimizationClockLog(): AbEvent[] {
|
|
456
|
+
return new OptimizationLogBuilder('clock-node')
|
|
457
|
+
.accept(commandObjective(), 1)
|
|
458
|
+
.execution('started', 'node-1')
|
|
459
|
+
.wait(20)
|
|
460
|
+
.baseline(1, 50, 1.6)
|
|
461
|
+
.execution('ended', 'node-1')
|
|
462
|
+
.propose('r1', ['c1', 'c2'])
|
|
463
|
+
.wait(30)
|
|
464
|
+
.activity([
|
|
465
|
+
['attempt-c1', 1, 'started', 'i1', 25],
|
|
466
|
+
['attempt-c1', 2, 'ended', 'i1', 10],
|
|
467
|
+
['attempt-c2', 1, 'started', 'i2', 5],
|
|
468
|
+
])
|
|
469
|
+
.wait(10)
|
|
470
|
+
.activity([['attempt-c1', 3, 'started', 'i3', 8]])
|
|
471
|
+
.wait(10)
|
|
472
|
+
.activity([['attempt-c1', 4, 'ended', 'i3', 2]], { released: ['attempt-c1'] })
|
|
473
|
+
.push({ actor: DISPATCHER, type: 'execution.accounted', payload: { count: 1 } }).events
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/** A stopped node whose settlement closed its clock for good. */
|
|
477
|
+
export function optimizationSettledClockLog(): AbEvent[] {
|
|
478
|
+
return new OptimizationLogBuilder('settled-node')
|
|
479
|
+
.accept(commandObjective(), 1)
|
|
480
|
+
.baseline(1, 50, 1.6)
|
|
481
|
+
.propose('r1', ['s1'])
|
|
482
|
+
.wait(30)
|
|
483
|
+
.activity([['attempt-s1', 1, 'started', 'i1', 20]])
|
|
484
|
+
.wait(30)
|
|
485
|
+
.stop('operator', 'abort')
|
|
486
|
+
.settle('s1', 'stopped')
|
|
487
|
+
.wait(5)
|
|
488
|
+
.activity([['attempt-s1', 2, 'ended', 'i1', 10]], { settles: true }).events
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/** An attempt log's execution facts with an acknowledgment, for the
|
|
492
|
+
* `executionIntervals` value: facts above the acknowledged count remain. */
|
|
493
|
+
export function executionIntervalsLog(): AbEvent[] {
|
|
494
|
+
return new OptimizationLogBuilder('attempt-x1')
|
|
495
|
+
.execution('started', 'x1')
|
|
496
|
+
.wait(10)
|
|
497
|
+
.execution('ended', 'x1')
|
|
498
|
+
.wait(5)
|
|
499
|
+
.execution('started', 'x2')
|
|
500
|
+
.push({ actor: DISPATCHER, type: 'execution.accounted', payload: { count: 1 } })
|
|
501
|
+
.wait(5)
|
|
502
|
+
.execution('ended', 'x2').events
|
|
402
503
|
}
|
|
403
504
|
|
|
404
505
|
/** A node log that reaches every digest and ledger field, for shape coverage. */
|
|
@@ -344,6 +344,19 @@ export function randomSandboxJournal(seed: number, length: number): RepositoryEv
|
|
|
344
344
|
type: 'orchestrator.sandbox.released',
|
|
345
345
|
payload: { ...base, snapshots: { outcome: 'confirmed' } },
|
|
346
346
|
}),
|
|
347
|
+
() => ({
|
|
348
|
+
type: 'orchestrator.sandbox.provisioning',
|
|
349
|
+
payload: { ...base, provider: 'vercel', kind: rand() < 0.5 ? 'provision' : 'resume' },
|
|
350
|
+
}),
|
|
351
|
+
() => ({
|
|
352
|
+
type: 'orchestrator.sandbox.provision-failed',
|
|
353
|
+
payload: { ...base, stage: 'setup', message: 'boom' },
|
|
354
|
+
}),
|
|
355
|
+
() => ({ type: 'orchestrator.sandbox.closed', payload: base }),
|
|
356
|
+
() => ({
|
|
357
|
+
type: 'orchestrator.sandbox.refreshed',
|
|
358
|
+
payload: { ...base, baseSha: 'a'.repeat(40), headSha: 'a'.repeat(40) },
|
|
359
|
+
}),
|
|
347
360
|
]
|
|
348
361
|
specs.push({ ...pick(rand, templates)(), actor: DISPATCHER })
|
|
349
362
|
}
|