@defrex/autobuild 1.12.0 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/SPEC.md +465 -163
- package/bin/ab-build-runner.ts +8 -0
- package/docs/answering-blocked-builds.md +28 -4
- package/docs/architecture.md +136 -53
- package/docs/cli.md +1 -1
- package/docs/configuration.md +120 -17
- package/docs/dispatcher.md +19 -8
- package/docs/integration-overview.md +1 -1
- package/docs/integration-tree.md +12 -9
- package/docs/merge-policy.md +7 -2
- package/docs/operating.md +13 -3
- package/docs/operator-api.md +46 -23
- package/docs/operator-surfaces.md +7 -6
- package/docs/optimization-nodes.md +7 -6
- package/docs/plugin-authoring.md +46 -18
- package/docs/remote-store-protocol.md +52 -13
- package/docs/remote-ticket-protocol.md +85 -38
- package/docs/restacking.md +48 -3
- package/docs/setup.md +2 -1
- package/docs/ticket-migration.md +2 -2
- package/docs/ticket-sources.md +23 -8
- package/docs/tickets.md +4 -4
- package/docs/troubleshooting.md +32 -2
- package/docs/verification.md +3 -1
- package/package.json +3 -3
- package/packages/core/src/cli/build-control.ts +72 -6
- package/packages/core/src/cli/dashboard/actions.ts +4 -0
- package/packages/core/src/cli/dashboard/integration-row.ts +43 -19
- package/packages/core/src/cli/dashboard/model.ts +14 -8
- package/packages/core/src/cli/dashboard/poll.ts +218 -10
- package/packages/core/src/cli/dashboard/queue.ts +21 -10
- package/packages/core/src/cli/dashboard/row-text.ts +2 -1
- package/packages/core/src/cli/dashboard/vocabulary.ts +5 -1
- package/packages/core/src/cli/dispatch-frontend.ts +2 -1
- package/packages/core/src/cli/dispatch-tickets.ts +33 -12
- package/packages/core/src/cli/dispatch.ts +547 -145
- package/packages/core/src/cli/help.ts +38 -24
- package/packages/core/src/cli/main.ts +7 -5
- package/packages/core/src/cli/publication-settlement.ts +4 -0
- package/packages/core/src/cli/remote-poll.ts +22 -5
- package/packages/core/src/cli/repository-status.ts +19 -9
- package/packages/core/src/cli/status.ts +23 -11
- package/packages/core/src/cli/store-opening.ts +12 -0
- package/packages/core/src/cli/ticket-start.ts +3 -3
- package/packages/core/src/cli/ticket.ts +12 -11
- package/packages/core/src/cli/wait.ts +8 -28
- package/packages/core/src/cli/watch.ts +113 -50
- package/packages/core/src/config/reference-metadata.ts +7 -1
- package/packages/core/src/config/reference.ts +5 -2
- package/packages/core/src/config/schema.ts +51 -16
- package/packages/core/src/events/payloads.ts +74 -14
- package/packages/core/src/events/policy.ts +1 -0
- package/packages/core/src/events/repository.ts +33 -3
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +31 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/be211f0e31a65006.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/0a10010ee5cf2e47.json +577 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/227701361be6d1e0.json +490 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/312cc4090820a612.json +1078 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/76e5043bae7a80ab.json +86 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/87a917802870bbed.json +87 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/9d85616e5b9e24c1.json +500 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a2780567b4989fb6.json +105 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/c7c94fbe7f63cf07.json +84 -0
- package/packages/core/src/kernel/clean-restack-policy.ts +40 -0
- package/packages/core/src/kernel/dispatch-capacity.ts +243 -107
- package/packages/core/src/kernel/done-escalations.ts +273 -0
- package/packages/core/src/kernel/engine.ts +28 -9
- package/packages/core/src/kernel/integration-landing.ts +24 -4
- package/packages/core/src/kernel/integration-stack.ts +39 -0
- package/packages/core/src/kernel/janitor-failure.ts +20 -1
- package/packages/core/src/kernel/log-index-value.ts +3 -0
- package/packages/core/src/kernel/log-index.ts +41 -2
- package/packages/core/src/kernel/open-pr-backpressure.ts +3 -3
- package/packages/core/src/kernel/reducer-registry.ts +3 -0
- package/packages/core/src/kernel/reducer-revisions.ts +19 -0
- package/packages/core/src/kernel/reducer.ts +42 -8
- package/packages/core/src/kernel/repository-attention.ts +14 -5
- package/packages/core/src/kernel/repository-read-facts.ts +9 -0
- package/packages/core/src/kernel/ticket-starts.ts +15 -4
- package/packages/core/src/kernel/verify-stages.ts +46 -7
- package/packages/core/src/operator/attention.ts +28 -3
- package/packages/core/src/operator/done-escalations.ts +38 -0
- package/packages/core/src/operator/presentation.ts +1 -1
- package/packages/core/src/operator/protocol.ts +8 -5
- package/packages/core/src/operator/query.ts +33 -19
- package/packages/core/src/operator/registry.ts +17 -13
- package/packages/core/src/operator/ticket-start.ts +8 -7
- package/packages/core/src/operator/tickets.ts +28 -9
- package/packages/core/src/plugin-sdk/index.ts +10 -0
- package/packages/core/src/plugins/manifest.ts +14 -1
- package/packages/core/src/ports/forge/create.ts +8 -0
- package/packages/core/src/ports/forge/github-transport.ts +5 -1
- package/packages/core/src/ports/forge/github.ts +3 -0
- package/packages/core/src/ports/tickets/contract.ts +147 -76
- package/packages/core/src/ports/tickets/create.ts +47 -7
- package/packages/core/src/ports/tickets/fake.ts +8 -4
- package/packages/core/src/ports/tickets/file-codec.ts +4 -3
- package/packages/core/src/ports/tickets/file.ts +7 -3
- package/packages/core/src/ports/tickets/github.ts +1 -0
- package/packages/core/src/ports/tickets/grants.ts +11 -3
- package/packages/core/src/ports/tickets/hosted-index.ts +5 -0
- package/packages/core/src/ports/tickets/linear.ts +28 -9
- package/packages/core/src/ports/tickets/migration.ts +4 -4
- package/packages/core/src/ports/tickets/operations.ts +4 -2
- package/packages/core/src/ports/tickets/priority-labels.ts +213 -0
- package/packages/core/src/ports/tickets/priority.ts +127 -21
- package/packages/core/src/ports/tickets/remote-protocol.ts +10 -0
- package/packages/core/src/ports/tickets/remote.ts +104 -11
- package/packages/core/src/ports/tickets/revision.ts +5 -3
- package/packages/core/src/ports/tickets/search.ts +9 -0
- package/packages/core/src/ports/tickets/tree.ts +8 -6
- package/packages/core/src/ports/types.ts +30 -15
- package/packages/core/src/ports/workspace/build-execution.ts +13 -1
- package/packages/core/src/ports/workspace/builtin-capabilities.ts +4 -0
- package/packages/core/src/ports/workspace/create.ts +16 -3
- package/packages/core/src/ports/workspace/execution-exit-marker.ts +41 -0
- package/packages/core/src/ports/workspace/recovery-step.ts +101 -0
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +596 -144
- package/packages/core/src/processes/build-execution-state.ts +4 -0
- package/packages/core/src/processes/build-runner.ts +14 -1
- package/packages/core/src/processes/dispatcher.ts +841 -230
- package/packages/core/src/processes/execution-settlement.ts +25 -3
- package/packages/core/src/processes/harvest-runner.ts +12 -7
- package/packages/core/src/processes/infrastructure-failure-budget.ts +7 -2
- package/packages/core/src/processes/invocation-budget.ts +176 -0
- package/packages/core/src/processes/publication-loss.ts +38 -3
- package/packages/core/src/processes/tick-publication.ts +1 -0
- package/packages/core/src/processes/workspace-preservation.ts +86 -15
- package/packages/core/src/store/contract.ts +88 -3
- package/packages/core/src/store/event-reads.ts +30 -1
- package/packages/core/src/store/reduced-reads.ts +23 -0
- package/packages/core/src/store/reducer-value-shapes.json +6759 -6490
- package/packages/core/src/store/reducer-value-validation.ts +188 -33
- package/packages/core/src/store/remote/client.ts +169 -29
- package/packages/core/src/store/remote/compatibility.ts +113 -56
- package/packages/core/src/store/remote/credentials.ts +4 -1
- package/packages/core/src/store/remote/protocol.ts +3 -0
- package/packages/core/src/store/remote/released-clients.json +22 -0
- package/packages/core/src/store/remote/released-reducer-values/1.13.0.json +35966 -0
- package/packages/core/src/store/remote/released-reducer-values/1.14.0.json +36076 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +20 -16
- package/packages/core/src/store/remote/released-value-policy.ts +144 -0
- package/packages/core/src/store/remote/retry.ts +406 -0
- package/packages/core/src/store/repo-state-events.ts +1 -0
- package/packages/core/src/testing/dispatch-read-budget.ts +155 -11
- package/packages/core/src/testing/index.ts +2 -0
- package/packages/core/src/testing/invocation-budget.ts +42 -0
- package/packages/core/src/testing/reduced-read-budget.ts +589 -19
- package/packages/core/src/testing/released-value-coverage.ts +423 -0
- package/packages/core/src/web/overview-source.ts +19 -6
- package/skills/guide/SKILL.md +147 -67
- package/skills/guide/references/integration-tree.md +12 -9
- package/skills/guide/references/merge-policy.md +7 -2
- package/skills/guide/references/operator-api.md +46 -23
- package/skills/guide/references/optimization-nodes.md +7 -6
- package/skills/guide/references/plugin-authoring.md +46 -18
- package/skills/guide/references/remote-store-protocol.md +52 -13
- package/skills/guide/references/remote-ticket-protocol.md +85 -38
- package/skills/guide/references/restacking.md +48 -3
- package/skills/guide/references/setup.md +2 -1
- package/skills/guide/references/ticket-migration.md +2 -2
- package/skills/operate/SKILL.md +136 -55
- package/skills/plan/SKILL.md +4 -3
- package/skills/spec/SKILL.md +9 -5
- package/skills/tickets/SKILL.md +25 -17
- package/templates/hosted-service/package.json +2 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { TicketPriority } from '../ports/types'
|
|
1
2
|
import { upgradeGenerationWrites } from './upgrade-generations'
|
|
2
3
|
import { restoreReplay } from '../kernel/replay-retention'
|
|
3
4
|
import { reducerValueForClient } from '../store/remote/compatibility'
|
|
@@ -16,6 +17,7 @@ import { tmpdir } from 'node:os'
|
|
|
16
17
|
import { join } from 'node:path'
|
|
17
18
|
import { DashboardBuildPollCache } from '../cli/dashboard/poll'
|
|
18
19
|
import { abDispatch } from '../cli/dispatch'
|
|
20
|
+
import { createInvocationBudget } from '../processes/invocation-budget'
|
|
19
21
|
import { createTerminalModeController } from '../cli/terminal-restore'
|
|
20
22
|
import { randomUuids } from '../ids'
|
|
21
23
|
import { ScriptedAgentRunner, defaultTurnResult } from '../ports/runner/fake'
|
|
@@ -43,6 +45,7 @@ import {
|
|
|
43
45
|
readDispatchBudget,
|
|
44
46
|
readRepositoryFacts,
|
|
45
47
|
readForgeHealth,
|
|
48
|
+
readDoneEscalations,
|
|
46
49
|
readRepositoryAttention,
|
|
47
50
|
readBuildDigests,
|
|
48
51
|
readDispatcherRunFacts,
|
|
@@ -414,7 +417,9 @@ export async function reducedReadBudget(opts: {
|
|
|
414
417
|
expect(costs.events).toBe(0)
|
|
415
418
|
// A new dashboard on every invocation must use canonical persisted facts,
|
|
416
419
|
// even after the build exceeds the hosted page cap. Warm and cold polls
|
|
417
|
-
// select zero event rows at either history length
|
|
420
|
+
// select zero event rows at either history length once the
|
|
421
|
+
// `doneEscalations` rollup has its one saved reduction.
|
|
422
|
+
await readDoneEscalations(store, repo)
|
|
418
423
|
reset()
|
|
419
424
|
for (let invocation = 0; invocation < 3; invocation++) {
|
|
420
425
|
const dashboard = new DashboardBuildPollCache(cold, repo, config)
|
|
@@ -426,6 +431,7 @@ export async function reducedReadBudget(opts: {
|
|
|
426
431
|
await coldDispatchOnceBudget(store, cold, length, costs)
|
|
427
432
|
await coldDispatchOnceBudget(store, cold, length, costs, true)
|
|
428
433
|
await coldDispatchOnceBudget(store, cold, length, costs, true, true)
|
|
434
|
+
await coldDispatchOnceBudget(store, cold, length, costs, false, false, true)
|
|
429
435
|
reset()
|
|
430
436
|
const view = new RepoViewStore(cold, { repo })
|
|
431
437
|
await view.refresh()
|
|
@@ -1087,12 +1093,17 @@ async function coldDispatchOnceBudget(
|
|
|
1087
1093
|
costs: ReducedReadCosts,
|
|
1088
1094
|
interactive = false,
|
|
1089
1095
|
outage = false,
|
|
1096
|
+
/** A bounded invocation whose work deadline passes during the tick's
|
|
1097
|
+
* first digest read: the stop adds no reads and still records the stop. */
|
|
1098
|
+
budgetStop = false,
|
|
1090
1099
|
) {
|
|
1091
1100
|
const onceRepo = outage
|
|
1092
1101
|
? 'https://github.com/budget/outage-ticks'
|
|
1093
1102
|
: interactive
|
|
1094
1103
|
? 'https://github.com/budget/interactive-ticks'
|
|
1095
|
-
:
|
|
1104
|
+
: budgetStop
|
|
1105
|
+
? 'https://github.com/budget/budget-stopped-once'
|
|
1106
|
+
: 'https://github.com/budget/cold-once'
|
|
1096
1107
|
await store.ensureRepo(onceRepo)
|
|
1097
1108
|
for (let i = 0; i < length; i++)
|
|
1098
1109
|
await store.appendRepo(onceRepo, {
|
|
@@ -1118,6 +1129,18 @@ steps = []
|
|
|
1118
1129
|
`,
|
|
1119
1130
|
)
|
|
1120
1131
|
const acquisitions = { facts: 0, digests: 0 }
|
|
1132
|
+
const deadlines: (() => void)[] = []
|
|
1133
|
+
const budget = budgetStop
|
|
1134
|
+
? createInvocationBudget({
|
|
1135
|
+
workDeadlineAt: 1000 + 210_000,
|
|
1136
|
+
hardDeadlineAt: 1000 + 240_000,
|
|
1137
|
+
now: () => 1000,
|
|
1138
|
+
timers: {
|
|
1139
|
+
setTimeout: (handler) => deadlines.push(handler),
|
|
1140
|
+
clearTimeout: () => {},
|
|
1141
|
+
},
|
|
1142
|
+
})
|
|
1143
|
+
: undefined
|
|
1121
1144
|
const stop = new AbortController()
|
|
1122
1145
|
let ticks = 0
|
|
1123
1146
|
let ticketScanWrites = 0
|
|
@@ -1179,6 +1202,12 @@ steps = []
|
|
|
1179
1202
|
if (key === 'getRepoBuildDigests')
|
|
1180
1203
|
return (...args: Parameters<BuildStore['getRepoBuildDigests']>) => {
|
|
1181
1204
|
acquisitions.digests++
|
|
1205
|
+
if (budget !== undefined && acquisitions.digests === 1) {
|
|
1206
|
+
// The work deadline passes while this read is on the wire; the
|
|
1207
|
+
// budgeted fetch would reject it with the deadline.
|
|
1208
|
+
deadlines[0]!()
|
|
1209
|
+
return Promise.reject(budget.work.reason)
|
|
1210
|
+
}
|
|
1182
1211
|
return target.getRepoBuildDigests(...args)
|
|
1183
1212
|
}
|
|
1184
1213
|
if (key === 'getReducerValue')
|
|
@@ -1250,6 +1279,7 @@ steps = []
|
|
|
1250
1279
|
},
|
|
1251
1280
|
kernelRunId: run,
|
|
1252
1281
|
...(interactive ? { frontendStatus: true } : {}),
|
|
1282
|
+
...(budget !== undefined ? { invocationBudget: budget } : {}),
|
|
1253
1283
|
storeRef: '/budget',
|
|
1254
1284
|
wire: () => ({
|
|
1255
1285
|
store: checked,
|
|
@@ -1278,9 +1308,12 @@ steps = []
|
|
|
1278
1308
|
const finished = (await readRepositoryFacts(checked, onceRepo)).value.recentRuns.find(
|
|
1279
1309
|
([id]) => id === run,
|
|
1280
1310
|
)?.[1]
|
|
1281
|
-
|
|
1311
|
+
if (budget !== undefined) {
|
|
1312
|
+
expect(budget.work.aborted).toBe(true)
|
|
1313
|
+
expect(finished?.stop?.payload).toMatchObject({ outcome: 'normal', exitCode: 0 })
|
|
1314
|
+
} else expect(finished?.completed?.type).toBe('dispatcher.tick-completed')
|
|
1282
1315
|
if (interactive) expect(finished?.completed?.payload).toMatchObject({ triage: 2 })
|
|
1283
|
-
else expect(finished?.completed?.payload).not.toHaveProperty('triage')
|
|
1316
|
+
else if (budget === undefined) expect(finished?.completed?.payload).not.toHaveProperty('triage')
|
|
1284
1317
|
expect(finished?.stop?.type).toBe('dispatcher.run-stopped')
|
|
1285
1318
|
// The same fresh invocation may fail before writing its start fact.
|
|
1286
1319
|
expect(
|
|
@@ -2484,6 +2517,191 @@ export async function flaggedWorkspaceSweepReadBudget(opts: {
|
|
|
2484
2517
|
})
|
|
2485
2518
|
}
|
|
2486
2519
|
|
|
2520
|
+
/** #1406: the early stage that serves `dispatcher.work-deferred` first. It
|
|
2521
|
+
* runs on every tick, so with no carried entry it makes no store request at
|
|
2522
|
+
* all, and with one it reads only the carried builds: the same reads at 100
|
|
2523
|
+
* and 100,000 events, whatever number of unrelated builds (here ones a newer
|
|
2524
|
+
* writer's decisive fact defers) the repository holds. Each carried build is
|
|
2525
|
+
* swept once per tick, so carrying it adds no reads to the tick. A carried
|
|
2526
|
+
* build its own mixed-version check defers stays carried. Fresh dispatchers
|
|
2527
|
+
* per tick: no per-process cache. */
|
|
2528
|
+
export async function deferredWorkReadBudget(): Promise<void> {
|
|
2529
|
+
const { newerFact, seedNewerMemoryFact } = await import('./newer-writer')
|
|
2530
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
2531
|
+
const repo = '/repos/deferred-work'
|
|
2532
|
+
const sha = 'a'.repeat(40)
|
|
2533
|
+
const config = parseConfig('[tickets]\nsource = "file"\nreadyState = "Ready"\n')
|
|
2534
|
+
async function world(length: number, unrelated: number) {
|
|
2535
|
+
let now = Date.parse('2026-12-01T00:00:00.000Z')
|
|
2536
|
+
const clock = () => new Date(now)
|
|
2537
|
+
const store = new MemoryBuildStore({ clock })
|
|
2538
|
+
await store.ensureRepo(repo)
|
|
2539
|
+
const created = (slug: string) => ({
|
|
2540
|
+
slug,
|
|
2541
|
+
repo,
|
|
2542
|
+
ticket: { source: 'fake', id: `T-${slug}` },
|
|
2543
|
+
branch: slug,
|
|
2544
|
+
created: {
|
|
2545
|
+
actor: DISPATCHER,
|
|
2546
|
+
type: 'build.created' as const,
|
|
2547
|
+
payload: { ticket: { source: 'fake', id: `T-${slug}` }, repo, baseBranch: 'main' },
|
|
2548
|
+
},
|
|
2549
|
+
})
|
|
2550
|
+
for (let i = 1; i <= unrelated; i++) {
|
|
2551
|
+
await store.createBuild(created(`deferred-${i}`))
|
|
2552
|
+
seedNewerMemoryFact(store, newerFact(2, 'decisive', `deferred-${i}`))
|
|
2553
|
+
}
|
|
2554
|
+
// The carried leaf: its execution ended on a sandbox that has since
|
|
2555
|
+
// stopped, and it holds its slot.
|
|
2556
|
+
const slug = 'carried'
|
|
2557
|
+
await store.createBuild(created(slug))
|
|
2558
|
+
await seedBuildFiller(store, slug, length, INERT_BUILD_FILLER)
|
|
2559
|
+
const ticket = { source: 'fake', id: `T-${slug}`, title: slug }
|
|
2560
|
+
for (const event of [
|
|
2561
|
+
{
|
|
2562
|
+
type: 'workspace.provisioned',
|
|
2563
|
+
payload: {
|
|
2564
|
+
provider: 'remote-test',
|
|
2565
|
+
ref: 'carried-g0',
|
|
2566
|
+
path: '/remote/workspace',
|
|
2567
|
+
branch: slug,
|
|
2568
|
+
base: { source: 'existing', sha },
|
|
2569
|
+
},
|
|
2570
|
+
},
|
|
2571
|
+
{ type: 'spec.imported', payload: { artifact: { kind: 'spec', rev: 0 }, ticket } },
|
|
2572
|
+
{ type: 'target.moved', payload: { branch: 'main', sha } },
|
|
2573
|
+
{ type: 'slot.admitted', payload: {} },
|
|
2574
|
+
{
|
|
2575
|
+
type: 'execution.started',
|
|
2576
|
+
payload: { provider: 'remote-test', workspaceRef: 'carried-g0', instance: 'i-1' },
|
|
2577
|
+
},
|
|
2578
|
+
{
|
|
2579
|
+
type: 'execution.ended',
|
|
2580
|
+
payload: { instance: 'i-1', workspaceRef: 'carried-g0', outcome: 'completed', exitCode: 0 },
|
|
2581
|
+
},
|
|
2582
|
+
])
|
|
2583
|
+
await store.append(slug, { actor: DISPATCHER, ...event } as never)
|
|
2584
|
+
await store.append(slug, { actor: KERNEL, type: 'plan.started', payload: { round: 1 } })
|
|
2585
|
+
now += 3_600_000
|
|
2586
|
+
const launches: string[] = []
|
|
2587
|
+
const dispatcher = () =>
|
|
2588
|
+
new Dispatcher({
|
|
2589
|
+
store,
|
|
2590
|
+
tickets: new FakeTicketSource([]),
|
|
2591
|
+
workspaces: {
|
|
2592
|
+
name: 'remote-test',
|
|
2593
|
+
preservation: async () => ({ outcome: 'preserved', heads: [] }),
|
|
2594
|
+
recovery: {
|
|
2595
|
+
fence: async () => ({ outcome: 'confirmed' }),
|
|
2596
|
+
reap: async () => ({
|
|
2597
|
+
outcome: 'confirmed',
|
|
2598
|
+
snapshots: { outcome: 'confirmed', deleted: 0 },
|
|
2599
|
+
}),
|
|
2600
|
+
},
|
|
2601
|
+
provision: async () => {
|
|
2602
|
+
throw new Error('not used')
|
|
2603
|
+
},
|
|
2604
|
+
release: async () => {},
|
|
2605
|
+
},
|
|
2606
|
+
forge: (() => {
|
|
2607
|
+
const forge = new FakeForge()
|
|
2608
|
+
forge.seedBranch('main', sha)
|
|
2609
|
+
return forge
|
|
2610
|
+
})(),
|
|
2611
|
+
config,
|
|
2612
|
+
repo,
|
|
2613
|
+
exec: async () => ({ stdout: `${sha}\trefs/heads/main\n`, stderr: '', exitCode: 0 }),
|
|
2614
|
+
launchRunner: async (launched: string) => {
|
|
2615
|
+
launches.push(launched)
|
|
2616
|
+
return 'scheduled' as const
|
|
2617
|
+
},
|
|
2618
|
+
ids: sequentialIds(),
|
|
2619
|
+
clock,
|
|
2620
|
+
})
|
|
2621
|
+
// One canonical reduction per key happens before anything is measured.
|
|
2622
|
+
await readRepositoryFacts(store, repo)
|
|
2623
|
+
await readBuildDigests(store, repo)
|
|
2624
|
+
await readBuildFacts(store, slug)
|
|
2625
|
+
for (let i = 1; i <= unrelated; i++) await readBuildFacts(store, `deferred-${i}`)
|
|
2626
|
+
const carry = (builds: { slug: string; step: 'resume' }[]) =>
|
|
2627
|
+
store.appendRepo(repo, {
|
|
2628
|
+
actor: DISPATCHER,
|
|
2629
|
+
type: 'dispatcher.work-deferred',
|
|
2630
|
+
payload: { builds },
|
|
2631
|
+
})
|
|
2632
|
+
/** One tick on a fresh dispatcher: the early stage's own store traffic
|
|
2633
|
+
* and the whole tick's requests naming the carried build. */
|
|
2634
|
+
const tick = async () => {
|
|
2635
|
+
const ticking = dispatcher()
|
|
2636
|
+
const stage = Reflect.get(ticking, 'serviceDeferredWork') as (
|
|
2637
|
+
...args: unknown[]
|
|
2638
|
+
) => Promise<void>
|
|
2639
|
+
let early: StoreReadMetrics | undefined
|
|
2640
|
+
Reflect.set(ticking, 'serviceDeferredWork', async (...args: unknown[]) => {
|
|
2641
|
+
early = await measureStoreReads(store, () => stage.apply(ticking, args))
|
|
2642
|
+
})
|
|
2643
|
+
const whole = await measureStoreReads(store, async () => {
|
|
2644
|
+
await ticking.tick({ acceptNewWork: false })
|
|
2645
|
+
})
|
|
2646
|
+
return { early: early!, carriedCalls: whole.slugs[slug] ?? 0 }
|
|
2647
|
+
}
|
|
2648
|
+
return { store, slug, launches, carry, tick }
|
|
2649
|
+
}
|
|
2650
|
+
|
|
2651
|
+
const stages: Record<
|
|
2652
|
+
string,
|
|
2653
|
+
{ calls: Record<string, number>; slugs: Record<string, number>; rows: number }
|
|
2654
|
+
> = {}
|
|
2655
|
+
for (const length of [100, 100_000]) {
|
|
2656
|
+
for (const unrelated of [20, 200]) {
|
|
2657
|
+
const w = await world(length, unrelated)
|
|
2658
|
+
// No carried entry: the stage makes no store request at all.
|
|
2659
|
+
await w.carry([])
|
|
2660
|
+
const idle = await w.tick()
|
|
2661
|
+
expect(idle.early.calls).toEqual({})
|
|
2662
|
+
expect(w.launches).toEqual([w.slug]) // the lease sweep launched it
|
|
2663
|
+
// Carried, with one carried build its mixed-version check defers.
|
|
2664
|
+
w.launches.length = 0
|
|
2665
|
+
await w.carry([
|
|
2666
|
+
{ slug: w.slug, step: 'resume' },
|
|
2667
|
+
{ slug: 'deferred-1', step: 'resume' },
|
|
2668
|
+
])
|
|
2669
|
+
const { early } = await w.tick()
|
|
2670
|
+
expect(w.launches).toEqual([w.slug])
|
|
2671
|
+
expect(Object.keys(early.slugs).sort()).toEqual([w.slug, 'deferred-1'].sort())
|
|
2672
|
+
// Only the tail the previous tick appended, never the seeded history.
|
|
2673
|
+
expect(early.read.every((row) => row.slug !== w.slug || row.seq > length)).toBe(true)
|
|
2674
|
+
const latest = (await w.store.getRepoEvents(repo)).findLast(
|
|
2675
|
+
(event) => event.type === 'dispatcher.work-deferred',
|
|
2676
|
+
)
|
|
2677
|
+
expect(latest?.payload).toEqual({ builds: [{ slug: 'deferred-1', step: 'resume' }] })
|
|
2678
|
+
stages[`${length}:${unrelated}`] = {
|
|
2679
|
+
calls: early.calls,
|
|
2680
|
+
slugs: early.slugs,
|
|
2681
|
+
rows: early.rows,
|
|
2682
|
+
}
|
|
2683
|
+
}
|
|
2684
|
+
}
|
|
2685
|
+
const [first, ...rest] = Object.values(stages)
|
|
2686
|
+
for (const other of rest) expect(other).toEqual(first!)
|
|
2687
|
+
|
|
2688
|
+
// Carrying a build adds no reads of it to the tick: the early stage's
|
|
2689
|
+
// sweep replaces the lease sweep's (and the settlement stage skips it).
|
|
2690
|
+
const carried = await world(100, 0)
|
|
2691
|
+
await carried.carry([{ slug: carried.slug, step: 'resume' }])
|
|
2692
|
+
const swept = await world(100, 0)
|
|
2693
|
+
const withHint = (await carried.tick()).carriedCalls
|
|
2694
|
+
const withoutHint = (await swept.tick()).carriedCalls
|
|
2695
|
+
expect(carried.launches).toEqual(swept.launches)
|
|
2696
|
+
expect(withHint).toBeLessThanOrEqual(withoutHint)
|
|
2697
|
+
console.log('deferred work read budget', {
|
|
2698
|
+
histories: [100, 100_000],
|
|
2699
|
+
unrelated: [20, 200],
|
|
2700
|
+
earlyStageCalls: first!.calls,
|
|
2701
|
+
carriedCallsPerTick: { withHint, withoutHint },
|
|
2702
|
+
})
|
|
2703
|
+
}
|
|
2704
|
+
|
|
2487
2705
|
/** A provision continuation that reaches its launch for a build at the
|
|
2488
2706
|
* no-progress limit applies the guard instead of starting a runner. Each
|
|
2489
2707
|
* continuation is a recurring invocation (every re-provision, every remote
|
|
@@ -2841,12 +3059,40 @@ export function memoryRepositoryReadCounter(
|
|
|
2841
3059
|
},
|
|
2842
3060
|
})
|
|
2843
3061
|
}
|
|
3062
|
+
let seedCalls = 0
|
|
3063
|
+
const reducedCallsBySlug = new Map<string, number>()
|
|
3064
|
+
const pageCallsBySlug = new Map<string, number>()
|
|
3065
|
+
const bump = (map: Map<string, number>, key: string) => map.set(key, (map.get(key) ?? 0) + 1)
|
|
3066
|
+
// Per-build digests served inside the repository's batch digest read are
|
|
3067
|
+
// the listing's cost, not a point read of that build.
|
|
3068
|
+
let inDigestBatch = 0
|
|
3069
|
+
const getRepoBuildDigests = store.getRepoBuildDigests.bind(store)
|
|
3070
|
+
store.getRepoBuildDigests = async (r) => {
|
|
3071
|
+
inDigestBatch++
|
|
3072
|
+
try {
|
|
3073
|
+
return await getRepoBuildDigests(r)
|
|
3074
|
+
} finally {
|
|
3075
|
+
inDigestBatch--
|
|
3076
|
+
}
|
|
3077
|
+
}
|
|
2844
3078
|
const getReducerValue = store.getReducerValue.bind(store)
|
|
2845
3079
|
store.getReducerValue = async (scope, request) => {
|
|
2846
3080
|
reducedCalls++
|
|
2847
3081
|
if (scope.kind === 'build' && request.reducer === 'buildReadFacts') buildFactsCalls++
|
|
3082
|
+
if (scope.kind === 'build' && request.reducer === 'buildStreamSeed') seedCalls++
|
|
3083
|
+
if (scope.kind === 'build' && inDigestBatch === 0) bump(reducedCallsBySlug, scope.slug)
|
|
2848
3084
|
return getReducerValue(scope, request)
|
|
2849
3085
|
}
|
|
3086
|
+
const getBuildEventPage = store.getBuildEventPage.bind(store)
|
|
3087
|
+
store.getBuildEventPage = async (build, since, opts) => {
|
|
3088
|
+
bump(pageCallsBySlug, build)
|
|
3089
|
+
return getBuildEventPage(build, since, opts)
|
|
3090
|
+
}
|
|
3091
|
+
const getEvents = store.getEvents.bind(store)
|
|
3092
|
+
store.getEvents = async (build, since, opts) => {
|
|
3093
|
+
bump(pageCallsBySlug, build)
|
|
3094
|
+
return getEvents(build, since, opts)
|
|
3095
|
+
}
|
|
2850
3096
|
return {
|
|
2851
3097
|
get rows() {
|
|
2852
3098
|
return rows
|
|
@@ -2863,12 +3109,27 @@ export function memoryRepositoryReadCounter(
|
|
|
2863
3109
|
get buildFactsCalls() {
|
|
2864
3110
|
return buildFactsCalls
|
|
2865
3111
|
},
|
|
3112
|
+
/** Build-scope `buildStreamSeed` reduced reads. */
|
|
3113
|
+
get seedCalls() {
|
|
3114
|
+
return seedCalls
|
|
3115
|
+
},
|
|
3116
|
+
/** Build-scope reduced reads per slug, outside the repository digest batch. */
|
|
3117
|
+
get reducedCallsBySlug() {
|
|
3118
|
+
return new Map(reducedCallsBySlug)
|
|
3119
|
+
},
|
|
3120
|
+
/** Event reads (`getBuildEventPage`, `getEvents`) per slug. */
|
|
3121
|
+
get pageCallsBySlug() {
|
|
3122
|
+
return new Map(pageCallsBySlug)
|
|
3123
|
+
},
|
|
2866
3124
|
reset() {
|
|
2867
3125
|
rows = 0
|
|
2868
3126
|
buildRows = 0
|
|
2869
3127
|
buildRowsBySlug.clear()
|
|
2870
3128
|
reducedCalls = 0
|
|
2871
3129
|
buildFactsCalls = 0
|
|
3130
|
+
seedCalls = 0
|
|
3131
|
+
reducedCallsBySlug.clear()
|
|
3132
|
+
pageCallsBySlug.clear()
|
|
2872
3133
|
},
|
|
2873
3134
|
}
|
|
2874
3135
|
}
|
|
@@ -3567,6 +3828,201 @@ export async function cliWatchDiscoveryReadBudget() {
|
|
|
3567
3828
|
expect(costs[1]).toEqual(costs[0]!)
|
|
3568
3829
|
}
|
|
3569
3830
|
|
|
3831
|
+
/**
|
|
3832
|
+
* A re-armed `ab watch --since` over many settled builds (#1288). At 100 and
|
|
3833
|
+
* 100,000 journal and build events, 40 builds are tracked, then 38 finish
|
|
3834
|
+
* while no watch runs. Re-arming delivers each finished build's completion
|
|
3835
|
+
* exactly once and drops it from the cursor; afterwards a retired build costs
|
|
3836
|
+
* no read of any kind, and an idle active build costs one event read per
|
|
3837
|
+
* pass with no `buildStreamSeed` read — locally per tick, and remotely per
|
|
3838
|
+
* wait window, where a retired build never opens a held read and the seed
|
|
3839
|
+
* count does not grow with the number of windows.
|
|
3840
|
+
*/
|
|
3841
|
+
export async function cliWatchSettledRetirementReadBudget() {
|
|
3842
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
3843
|
+
const { manualClock } = await import('./fixed')
|
|
3844
|
+
const builds = Array.from({ length: 40 }, (_, i) => `b${String(i).padStart(2, '0')}`)
|
|
3845
|
+
const settled = builds.slice(0, 38)
|
|
3846
|
+
const [active, finishing] = builds.slice(38) as [string, string]
|
|
3847
|
+
const complete = (store: InstanceType<typeof MemoryBuildStore>, build: string) =>
|
|
3848
|
+
store.append(build, {
|
|
3849
|
+
actor: DISPATCHER,
|
|
3850
|
+
type: 'build.completed',
|
|
3851
|
+
payload: { outcome: 'merged' },
|
|
3852
|
+
})
|
|
3853
|
+
type Cost = { rows: number; buildRows: number; seedCalls: number; reducedCalls: number }
|
|
3854
|
+
const costs: Record<string, Cost>[] = []
|
|
3855
|
+
for (const length of [100, 100_000]) {
|
|
3856
|
+
const clock = manualClock()
|
|
3857
|
+
const store = new MemoryBuildStore({ clock })
|
|
3858
|
+
await store.ensureRepo(repo)
|
|
3859
|
+
await seedRepoFiller(store, repo, length)
|
|
3860
|
+
for (const build of builds) {
|
|
3861
|
+
await store.createBuild({ slug: build, repo })
|
|
3862
|
+
await store.append(build, {
|
|
3863
|
+
actor: KERNEL,
|
|
3864
|
+
type: 'runner.attached',
|
|
3865
|
+
payload: { instance: 'i1', host: 'h1', resumedFromSeq: 0 },
|
|
3866
|
+
})
|
|
3867
|
+
}
|
|
3868
|
+
await seedBuildFiller(store, settled[0]!, length)
|
|
3869
|
+
// Served values exist before the watch, as on any running repository.
|
|
3870
|
+
await readRepositoryFacts(store, repo)
|
|
3871
|
+
await readRepositoryAttention(store, repo)
|
|
3872
|
+
await readBuildDigests(store, repo)
|
|
3873
|
+
for (const build of builds) await readBuildStreamSeed(store, build)
|
|
3874
|
+
const output: string[] = []
|
|
3875
|
+
const watch = (opts: {
|
|
3876
|
+
store?: BuildStore
|
|
3877
|
+
storeRef?: string
|
|
3878
|
+
since?: string
|
|
3879
|
+
timeout?: string
|
|
3880
|
+
signal?: AbortSignal
|
|
3881
|
+
delay?: () => Promise<void>
|
|
3882
|
+
}) =>
|
|
3883
|
+
abWatch({
|
|
3884
|
+
targetRepo: repo,
|
|
3885
|
+
env: {},
|
|
3886
|
+
exec,
|
|
3887
|
+
storeRef: opts.storeRef ?? '/budget',
|
|
3888
|
+
openStore: () => opts.store ?? store,
|
|
3889
|
+
json: true,
|
|
3890
|
+
events: ['build.completed'],
|
|
3891
|
+
now: clock,
|
|
3892
|
+
stdout: (line) => output.push(line),
|
|
3893
|
+
stderr: (line) => {
|
|
3894
|
+
throw new Error(line)
|
|
3895
|
+
},
|
|
3896
|
+
delay: opts.delay ?? (async () => clock.advance(1000)),
|
|
3897
|
+
...(opts.since !== undefined ? { since: opts.since } : {}),
|
|
3898
|
+
...(opts.timeout !== undefined ? { timeout: opts.timeout } : {}),
|
|
3899
|
+
...(opts.signal !== undefined ? { signal: opts.signal } : {}),
|
|
3900
|
+
})
|
|
3901
|
+
const lastCursor = () => (JSON.parse(output.at(-1)!) as { cursor: string }).cursor
|
|
3902
|
+
const delivered = () =>
|
|
3903
|
+
output
|
|
3904
|
+
.map((line) => JSON.parse(line) as { id?: string })
|
|
3905
|
+
.flatMap((record) => (record.id === undefined ? [] : [record.id]))
|
|
3906
|
+
const tracked = (cursor: string, storeRef = '/budget') =>
|
|
3907
|
+
Object.keys(decodeCursor(cursor, { store: storeRef, repo }).streams).toSorted()
|
|
3908
|
+
|
|
3909
|
+
await watch({ signal: AbortSignal.abort() })
|
|
3910
|
+
const armed = lastCursor()
|
|
3911
|
+
expect(tracked(armed)).toEqual(['#repo', ...builds].toSorted())
|
|
3912
|
+
for (const build of settled) await complete(store, build)
|
|
3913
|
+
|
|
3914
|
+
// ── Local re-arm: one sequential pass per tick ──
|
|
3915
|
+
const counter = memoryRepositoryReadCounter(store, repo)
|
|
3916
|
+
const sample: Record<string, Cost> = {}
|
|
3917
|
+
const retiredCosts: { pages: number; reduced: number }[] = []
|
|
3918
|
+
const cost = (): Cost => ({
|
|
3919
|
+
rows: counter.rows,
|
|
3920
|
+
buildRows: counter.buildRows,
|
|
3921
|
+
seedCalls: counter.seedCalls,
|
|
3922
|
+
reducedCalls: counter.reducedCalls,
|
|
3923
|
+
})
|
|
3924
|
+
const retiredReads = (retired: readonly string[]) => ({
|
|
3925
|
+
pages: retired.reduce((n, b) => n + (counter.pageCallsBySlug.get(b) ?? 0), 0),
|
|
3926
|
+
reduced: retired.reduce((n, b) => n + (counter.reducedCallsBySlug.get(b) ?? 0), 0),
|
|
3927
|
+
})
|
|
3928
|
+
let tick = 0
|
|
3929
|
+
output.length = 0
|
|
3930
|
+
await watch({
|
|
3931
|
+
since: armed,
|
|
3932
|
+
timeout: '6',
|
|
3933
|
+
delay: async () => {
|
|
3934
|
+
clock.advance(1000)
|
|
3935
|
+
tick++
|
|
3936
|
+
if (tick === 1) sample.attach = cost()
|
|
3937
|
+
if (tick >= 2)
|
|
3938
|
+
retiredCosts.push(retiredReads(tick >= 5 ? [...settled, finishing] : settled))
|
|
3939
|
+
if (tick === 2) sample.quiet = cost()
|
|
3940
|
+
if (tick === 3) {
|
|
3941
|
+
sample.quiet2 = cost()
|
|
3942
|
+
await complete(store, finishing)
|
|
3943
|
+
}
|
|
3944
|
+
if (tick === 4) sample.finishing = cost()
|
|
3945
|
+
if (tick === 5) sample.settled = cost()
|
|
3946
|
+
counter.reset()
|
|
3947
|
+
},
|
|
3948
|
+
})
|
|
3949
|
+
const ids = delivered()
|
|
3950
|
+
expect(ids.toSorted()).toEqual(
|
|
3951
|
+
[...settled, finishing].map((b) => `build:${b}:${b === settled[0] ? length + 1 : 2}`).sort(),
|
|
3952
|
+
)
|
|
3953
|
+
expect(new Set(ids).size).toBe(ids.length)
|
|
3954
|
+
const localFinal = lastCursor()
|
|
3955
|
+
expect(tracked(localFinal)).toEqual(['#repo', active])
|
|
3956
|
+
for (const key of ['quiet', 'quiet2', 'settled']) {
|
|
3957
|
+
expect(sample[key]!.rows).toBe(0)
|
|
3958
|
+
expect(sample[key]!.buildRows).toBe(0)
|
|
3959
|
+
expect(sample[key]!.seedCalls).toBe(0)
|
|
3960
|
+
}
|
|
3961
|
+
// The finishing build costs its one new row: read by its poll, and
|
|
3962
|
+
// folded once by the digest its retirement check advances.
|
|
3963
|
+
expect(sample.finishing!.buildRows).toBe(2)
|
|
3964
|
+
expect(sample.finishing!.seedCalls).toBe(0)
|
|
3965
|
+
for (const retired of retiredCosts) expect(retired).toEqual({ pages: 0, reduced: 0 })
|
|
3966
|
+
|
|
3967
|
+
// ── Remote re-arm: concurrent held reads per stream ──
|
|
3968
|
+
// The memory adapter holds on wall time; drop the hold so the injected
|
|
3969
|
+
// delay drives every window on the manual clock, recording held reads.
|
|
3970
|
+
const remoteRef = 'https://budget.example.test'
|
|
3971
|
+
const remote = async (timeout: string) => {
|
|
3972
|
+
const held = new Map<string, number>()
|
|
3973
|
+
const holding = new Proxy(store, {
|
|
3974
|
+
get(target, key) {
|
|
3975
|
+
const value = Reflect.get(target, key, target)
|
|
3976
|
+
if (typeof value !== 'function') return value
|
|
3977
|
+
if (!['getBuildEventPage', 'getEvents', 'getRepoEvents'].includes(key as string))
|
|
3978
|
+
return value.bind(target)
|
|
3979
|
+
return (build: string, since?: number, opts?: { waitSeconds?: number }) => {
|
|
3980
|
+
if ((opts?.waitSeconds ?? 0) > 0) held.set(build, (held.get(build) ?? 0) + 1)
|
|
3981
|
+
return value.call(target, build, since, { ...opts, waitSeconds: 0 })
|
|
3982
|
+
}
|
|
3983
|
+
},
|
|
3984
|
+
})
|
|
3985
|
+
counter.reset()
|
|
3986
|
+
output.length = 0
|
|
3987
|
+
await watch({
|
|
3988
|
+
store: holding,
|
|
3989
|
+
storeRef: remoteRef,
|
|
3990
|
+
since: encodeCursorFor(armed, remoteRef),
|
|
3991
|
+
timeout,
|
|
3992
|
+
})
|
|
3993
|
+
expect(tracked(lastCursor(), remoteRef)).toEqual(['#repo', active])
|
|
3994
|
+
return {
|
|
3995
|
+
held,
|
|
3996
|
+
seedCalls: counter.seedCalls,
|
|
3997
|
+
pages: counter.pageCallsBySlug,
|
|
3998
|
+
delivered: delivered().length,
|
|
3999
|
+
}
|
|
4000
|
+
}
|
|
4001
|
+
const short = await remote('8')
|
|
4002
|
+
const long = await remote('40')
|
|
4003
|
+
// The local run finished the last build too: 39 settled builds re-arm.
|
|
4004
|
+
for (const run of [short, long]) {
|
|
4005
|
+
expect(run.delivered).toBe(settled.length + 1)
|
|
4006
|
+
for (const build of [...settled, finishing]) {
|
|
4007
|
+
expect(run.pages.get(build)).toBe(1)
|
|
4008
|
+
expect(run.held.get(build)).toBeUndefined()
|
|
4009
|
+
}
|
|
4010
|
+
}
|
|
4011
|
+
expect(long.held.get(active)!).toBeGreaterThan(short.held.get(active)!)
|
|
4012
|
+
// Attach-time seed reads only: more windows add none.
|
|
4013
|
+
expect(long.seedCalls).toBe(short.seedCalls)
|
|
4014
|
+
costs.push(sample)
|
|
4015
|
+
}
|
|
4016
|
+
// History-independent: every pass costs the same at both lengths.
|
|
4017
|
+
expect(costs[1]).toEqual(costs[0]!)
|
|
4018
|
+
}
|
|
4019
|
+
|
|
4020
|
+
/** Re-issue a cursor's positions for another store reference. */
|
|
4021
|
+
function encodeCursorFor(cursor: string, storeRef: string): string {
|
|
4022
|
+
const payload = JSON.parse(Buffer.from(cursor.slice(3), 'base64url').toString('utf8'))
|
|
4023
|
+
return `v1.${Buffer.from(JSON.stringify({ ...payload, store: storeRef }), 'utf8').toString('base64url')}`
|
|
4024
|
+
}
|
|
4025
|
+
|
|
3570
4026
|
/** Fresh operator backends must not turn canonical build history into ticket requests. */
|
|
3571
4027
|
export async function operatorTicketAssociationBudget() {
|
|
3572
4028
|
const { MemoryBuildStore } = await import('../store/memory')
|
|
@@ -4136,8 +4592,9 @@ export async function ticketRoleTickBudget(
|
|
|
4136
4592
|
return baseline!
|
|
4137
4593
|
}
|
|
4138
4594
|
|
|
4139
|
-
/**
|
|
4140
|
-
* listing a due scan already reads:
|
|
4595
|
+
/** Intake order by level (AUT-1027, #1354) is an in-memory sort of the one
|
|
4596
|
+
* ready listing a due scan already reads: whatever the levels of the ready
|
|
4597
|
+
* tickets (all normal, one urgent, high or low, or all four levels at once),
|
|
4141
4598
|
* a quiet intake tick makes the same source calls and the same store reads, at
|
|
4142
4599
|
* 100 and 100,000 repository events, and an unchanged follow-up read costs zero
|
|
4143
4600
|
* rows. Returns the per-method source calls of one tick. */
|
|
@@ -4153,12 +4610,19 @@ export async function urgentIntakeReadBudget() {
|
|
|
4153
4610
|
const methods = ['listReady', 'get', 'dependencyStates', 'listAll'] as const
|
|
4154
4611
|
const results = new Map<string, { calls: Record<string, number>[]; rows: number[] }>()
|
|
4155
4612
|
const profileResults = new Map<string, { calls: Record<string, number>[]; rows: number[] }>()
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
[
|
|
4161
|
-
|
|
4613
|
+
// The levels of N1, N2 and U1 in each variant.
|
|
4614
|
+
type Levels = readonly [TicketPriority, TicketPriority, TicketPriority]
|
|
4615
|
+
const normal: Levels = ['normal', 'normal', 'normal']
|
|
4616
|
+
const variants: (readonly [string, Levels, boolean])[] = [
|
|
4617
|
+
['normal', normal, false],
|
|
4618
|
+
['urgent', ['normal', 'normal', 'urgent'], false],
|
|
4619
|
+
['high', ['normal', 'normal', 'high'], false],
|
|
4620
|
+
['low', ['normal', 'normal', 'low'], false],
|
|
4621
|
+
['mixed', ['high', 'low', 'urgent'], false],
|
|
4622
|
+
['normal', normal, true],
|
|
4623
|
+
['urgent', ['normal', 'normal', 'urgent'], true],
|
|
4624
|
+
]
|
|
4625
|
+
for (const [urgent, levels, profiles] of variants) {
|
|
4162
4626
|
const config = parseConfig(profiles ? profiled : plain)
|
|
4163
4627
|
for (const length of [100, 100_000]) {
|
|
4164
4628
|
const source = new FakeTicketSource([], { createState: 'triage', doneState: 'done' })
|
|
@@ -4179,7 +4643,7 @@ export async function urgentIntakeReadBudget() {
|
|
|
4179
4643
|
const ticket = await source.create({
|
|
4180
4644
|
title,
|
|
4181
4645
|
body: 'Budget',
|
|
4182
|
-
...(
|
|
4646
|
+
...(levels[index] !== 'normal' ? { priority: levels[index] } : {}),
|
|
4183
4647
|
...(profiles
|
|
4184
4648
|
? { labels: index === 0 ? ['deep'] : index === 1 ? ['deep', 'cheap'] : [] }
|
|
4185
4649
|
: {}),
|
|
@@ -5540,9 +6004,10 @@ export async function hookReadBudget(): Promise<void> {
|
|
|
5540
6004
|
requests: requests.vector(),
|
|
5541
6005
|
}
|
|
5542
6006
|
expect(delivered.slice(deliveredBefore)).toHaveLength(2)
|
|
5543
|
-
// Each new row is read once per hook
|
|
5544
|
-
//
|
|
5545
|
-
|
|
6007
|
+
// Each new row on a followed build is read once per hook: following a
|
|
6008
|
+
// tail reads no per-poll stream seed. An announced build also replays
|
|
6009
|
+
// from its seed.
|
|
6010
|
+
expect(changed.bySlug).toEqual({ 'active-a': 2, 'new-c': 9 })
|
|
5546
6011
|
expect(listing(changed.requests)).toEqual([0, 0, 0])
|
|
5547
6012
|
requests.restore()
|
|
5548
6013
|
|
|
@@ -7479,6 +7944,8 @@ export async function ticketStartReadBudget(): Promise<{
|
|
|
7479
7944
|
label: string,
|
|
7480
7945
|
/** AB-0 waits on a blocker whose dependency read fails. */
|
|
7481
7946
|
blocked = false,
|
|
7947
|
+
/** Further ready tickets, as `[id, level]`. */
|
|
7948
|
+
extra: readonly (readonly [string, import('../ports/types').TicketPriority])[] = [],
|
|
7482
7949
|
) => {
|
|
7483
7950
|
let now = 1_800_000_000_000
|
|
7484
7951
|
const clock = () => new Date(now)
|
|
@@ -7506,6 +7973,10 @@ export async function ticketStartReadBudget(): Promise<{
|
|
|
7506
7973
|
{ ...ticket('AB-W'), state: 'doing' },
|
|
7507
7974
|
ticket('AB-S'),
|
|
7508
7975
|
...Array.from({ length: builds }, (_, i) => ticket(`AB-${i + 1}`)),
|
|
7976
|
+
...extra.map(([id, level]) => ({
|
|
7977
|
+
...ticket(id),
|
|
7978
|
+
...(level === 'normal' ? {} : { priority: level }),
|
|
7979
|
+
})),
|
|
7509
7980
|
],
|
|
7510
7981
|
{ doneState: 'done' },
|
|
7511
7982
|
)
|
|
@@ -7942,6 +8413,52 @@ export async function ticketStartReadBudget(): Promise<{
|
|
|
7942
8413
|
}
|
|
7943
8414
|
expect(tiers.get(5_000)).toEqual(tiers.get(100))
|
|
7944
8415
|
for (const calls of tiers.get(100)!) expect(calls).toEqual({})
|
|
8416
|
+
|
|
8417
|
+
// More start requests than one tick evaluates, beside ready tickets at
|
|
8418
|
+
// every level, with free slots for all of them. Intake runs a late pass
|
|
8419
|
+
// before each level's first ready ticket, yet a tick evaluates at most eight
|
|
8420
|
+
// early-tier and eight late-tier requests; a request left unevaluated stays
|
|
8421
|
+
// ahead of ready tickets at its level and below until a later scan.
|
|
8422
|
+
const ids = (tier: string, from: number, to: number) =>
|
|
8423
|
+
Array.from({ length: to - from + 1 }, (_, i) => `R-${tier}-${from + i}`)
|
|
8424
|
+
const requested = [
|
|
8425
|
+
...ids('urgent', 1, 8).map((id) => [id, 'urgent'] as const),
|
|
8426
|
+
...(['high', 'normal', 'low'] as const).flatMap((tier) =>
|
|
8427
|
+
ids(tier, 1, 9).map((id) => [id, tier] as const),
|
|
8428
|
+
),
|
|
8429
|
+
]
|
|
8430
|
+
for (const history of [100, 5_000]) {
|
|
8431
|
+
const world = await open(0, history, 64, 'levels', false, [
|
|
8432
|
+
...requested.map(([id]) => [id, 'normal'] as const),
|
|
8433
|
+
['RU', 'urgent'],
|
|
8434
|
+
['RH', 'high'],
|
|
8435
|
+
['RL', 'low'],
|
|
8436
|
+
])
|
|
8437
|
+
for (const [id, tier] of requested)
|
|
8438
|
+
await requestTicketStart({
|
|
8439
|
+
store: world.store,
|
|
8440
|
+
repo: world.repo,
|
|
8441
|
+
source: world.tickets,
|
|
8442
|
+
id,
|
|
8443
|
+
user: 'budget',
|
|
8444
|
+
priority: tier,
|
|
8445
|
+
})
|
|
8446
|
+
// The first tick, before any build exists whose identity a later tick
|
|
8447
|
+
// projects: a started request's claim reads its ticket again, so count
|
|
8448
|
+
// each evaluated request once.
|
|
8449
|
+
const measured = await world.tick(true)
|
|
8450
|
+
expect([...new Set(measured.gets.filter((id) => id.startsWith('R-')))]).toEqual([
|
|
8451
|
+
...ids('urgent', 1, 8),
|
|
8452
|
+
...ids('high', 1, 8),
|
|
8453
|
+
])
|
|
8454
|
+
// R-high-9 was not evaluated: RH and every lower ready ticket wait.
|
|
8455
|
+
expect(world.claims).toEqual([...ids('urgent', 1, 8), 'RU', ...ids('high', 1, 8)])
|
|
8456
|
+
world.claims.length = 0
|
|
8457
|
+
await world.tick(true)
|
|
8458
|
+
// R-normal-8 and R-normal-9 were not evaluated: normal and low wait.
|
|
8459
|
+
expect(world.claims).toEqual(['R-high-9', 'RH', ...ids('normal', 1, 7)])
|
|
8460
|
+
await world.store.close()
|
|
8461
|
+
}
|
|
7945
8462
|
return baseline
|
|
7946
8463
|
}
|
|
7947
8464
|
|
|
@@ -8360,6 +8877,53 @@ export async function openBuildListingReadBudget(opts: { commands?: boolean } =
|
|
|
8360
8877
|
})
|
|
8361
8878
|
await store.createBuild({ slug: 'open-aborted', repo, created: created('open-aborted') })
|
|
8362
8879
|
await store.append('open-aborted', { actor: KERNEL, type: 'build.aborted', payload: {} })
|
|
8880
|
+
// Done builds with a post-completion escalation: one still open, one
|
|
8881
|
+
// acknowledged. Only the open one is listed, through `doneEscalations`.
|
|
8882
|
+
for (const slug of ['done-escalated', 'done-acknowledged']) {
|
|
8883
|
+
await store.createBuild({ slug, repo, created: created(slug) })
|
|
8884
|
+
await store.append(slug, {
|
|
8885
|
+
actor: DISPATCHER,
|
|
8886
|
+
type: 'build.completed',
|
|
8887
|
+
payload: { outcome: 'merged' },
|
|
8888
|
+
})
|
|
8889
|
+
await store.append(slug, {
|
|
8890
|
+
actor: KERNEL,
|
|
8891
|
+
type: 'escalation.raised',
|
|
8892
|
+
payload: {
|
|
8893
|
+
id: 'integration-audit-op',
|
|
8894
|
+
phase: 'verify:integration',
|
|
8895
|
+
source: 'agent',
|
|
8896
|
+
question: 'Integration result requires attention',
|
|
8897
|
+
},
|
|
8898
|
+
})
|
|
8899
|
+
}
|
|
8900
|
+
await store.append('done-acknowledged', {
|
|
8901
|
+
actor: humanActor('op'),
|
|
8902
|
+
type: 'escalation.answered',
|
|
8903
|
+
payload: { id: 'integration-audit-op', answer: 'ack', resolution: 'retry' },
|
|
8904
|
+
})
|
|
8905
|
+
// Aborted while blocked: the abort closed its escalation (#1387), so it
|
|
8906
|
+
// is listed nowhere and adds no read.
|
|
8907
|
+
await store.createBuild({
|
|
8908
|
+
slug: 'done-abort-closed',
|
|
8909
|
+
repo,
|
|
8910
|
+
created: created('done-abort-closed'),
|
|
8911
|
+
})
|
|
8912
|
+
await store.append('done-abort-closed', {
|
|
8913
|
+
actor: KERNEL,
|
|
8914
|
+
type: 'escalation.raised',
|
|
8915
|
+
payload: { id: 'abort-closed', phase: 'implement', source: 'agent', question: 'q' },
|
|
8916
|
+
})
|
|
8917
|
+
await store.append('done-abort-closed', {
|
|
8918
|
+
actor: DISPATCHER,
|
|
8919
|
+
type: 'build.aborted',
|
|
8920
|
+
payload: {},
|
|
8921
|
+
})
|
|
8922
|
+
await store.append('done-abort-closed', {
|
|
8923
|
+
actor: DISPATCHER,
|
|
8924
|
+
type: 'build.completed',
|
|
8925
|
+
payload: { outcome: 'abandoned' },
|
|
8926
|
+
})
|
|
8363
8927
|
for (let i = 0; i < settled; i++) {
|
|
8364
8928
|
const slug = `settled-${i}`
|
|
8365
8929
|
await store.createBuild({ slug, repo, created: created(slug) })
|
|
@@ -8469,12 +9033,18 @@ export async function openBuildListingReadBudget(opts: { commands?: boolean } =
|
|
|
8469
9033
|
expect([got.detail.slot, got.dashboardRow?.slot]).toEqual([held, held])
|
|
8470
9034
|
expect(
|
|
8471
9035
|
(await surfaces.dashboard(store)).model.builds.map((build) => build.slug).sort(),
|
|
8472
|
-
).toEqual(['open-aborted', 'open-consent', 'open-queued'])
|
|
9036
|
+
).toEqual(['done-escalated', 'open-aborted', 'open-consent', 'open-queued'])
|
|
9037
|
+
// The escalated done build is a blocked row that holds no slot.
|
|
9038
|
+
const escalatedRow = dashboardRows.find((row) => row.slug === 'done-escalated')
|
|
9039
|
+
expect(escalatedRow).toMatchObject({ status: 'blocked', statusBasis: { done: true } })
|
|
9040
|
+
expect(escalatedRow).not.toHaveProperty('slot')
|
|
8473
9041
|
expect((await surfaces.status(store)).capacity).toBeDefined()
|
|
8474
9042
|
const digest = await surfaces.attention(store)
|
|
8475
9043
|
expect(digest.merges.map((merge) => merge.slug)).toEqual(['open-consent'])
|
|
8476
|
-
expect(digest.escalations).toEqual([
|
|
8477
|
-
|
|
9044
|
+
expect(digest.escalations.map(({ slug, status }) => ({ slug, status }))).toEqual([
|
|
9045
|
+
{ slug: 'done-escalated', status: 'done' },
|
|
9046
|
+
])
|
|
9047
|
+
expect(JSON.stringify(digest)).not.toMatch(/open-aborted|done-abort-closed|settled-/)
|
|
8478
9048
|
const rows = memoryRepositoryReadCounter(store, repo)
|
|
8479
9049
|
const entries = memoryListingEntryCounter(store)
|
|
8480
9050
|
const calls = memoryStoreRequestCounter(store)
|