@defrex/autobuild 1.10.0 → 1.11.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 +738 -68
- 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 +155 -25
- 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 +63 -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 +101 -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 +178 -76
- package/packages/core/src/cli/dashboard/render.ts +129 -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 +29 -38
- 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 +200 -34
- 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 +97 -43
- 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 +316 -0
- 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/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/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/reducer-registry.ts +27 -8
- package/packages/core/src/kernel/reducer-revisions.ts +25 -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 +122 -72
- 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 +6987 -5749
- 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 +11 -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/index.ts +18 -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-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 +35 -0
- package/packages/core/src/web/server.ts +97 -0
- package/skills/code-review/SKILL.md +10 -2
- package/skills/guide/SKILL.md +366 -52
- 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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { upgradeGenerationWrites } from './upgrade-generations'
|
|
1
2
|
import { restoreReplay } from '../kernel/replay-retention'
|
|
2
3
|
import { reducerValueForClient } from '../store/remote/compatibility'
|
|
3
4
|
import { RELEASED_CLIENTS } from '../store/remote/released-clients'
|
|
@@ -721,6 +722,30 @@ export async function reducedReadBudget(opts: {
|
|
|
721
722
|
expect(costs.events).toBeLessThanOrEqual(2)
|
|
722
723
|
expect(costs.metadata).toBeLessThan(50)
|
|
723
724
|
}
|
|
725
|
+
// Fresh status readers reuse saved values even after long unrelated history.
|
|
726
|
+
// Check both absence and a no-holder, empty-drain unfinished handoff.
|
|
727
|
+
for (const handoff of [false, true]) {
|
|
728
|
+
if (handoff) {
|
|
729
|
+
for (const write of upgradeGenerationWrites(1000).slice(0, -1))
|
|
730
|
+
await store.appendRepo(repo, write)
|
|
731
|
+
}
|
|
732
|
+
await getRepositoryStatus(store, repo, new Date(1000))
|
|
733
|
+
for (let request = 0; request < 3; request++) {
|
|
734
|
+
const fresh = await opts.fresh()
|
|
735
|
+
reset()
|
|
736
|
+
const status = await getRepositoryStatus(fresh, repo, new Date(1000))
|
|
737
|
+
expect(status.dispatcherRunning).toBe(
|
|
738
|
+
Boolean(
|
|
739
|
+
status.dispatcher.holder ||
|
|
740
|
+
status.dispatcher.expiredHolder ||
|
|
741
|
+
status.upgradeStatus.handoff,
|
|
742
|
+
),
|
|
743
|
+
)
|
|
744
|
+
if (handoff) expect(status.dispatcherRunning).toBe(true)
|
|
745
|
+
expect(costs.events).toBe(0)
|
|
746
|
+
expect(costs.metadata).toBeLessThan(40)
|
|
747
|
+
}
|
|
748
|
+
}
|
|
724
749
|
}
|
|
725
750
|
|
|
726
751
|
/** Same SQL-instrumented harness, with indexed receipt reads rather than a
|
|
@@ -1459,21 +1484,15 @@ export async function parkedSweepReadBudget(opts: {
|
|
|
1459
1484
|
let seeded = 0
|
|
1460
1485
|
const idleRequests: Record<string, number>[] = []
|
|
1461
1486
|
for (const length of [100, 100_000]) {
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
}
|
|
1487
|
+
await seedBuildFiller(
|
|
1488
|
+
store,
|
|
1489
|
+
slugs[0]!,
|
|
1490
|
+
buildEventRows(store, slugs[0]!).length + length - seeded,
|
|
1491
|
+
)
|
|
1492
|
+
seeded = length
|
|
1469
1493
|
const recoveryEvents = Reflect.get(store, 'builds').get(recoverySlug)
|
|
1470
1494
|
.events as import('../events/catalog').AbEvent[]
|
|
1471
|
-
|
|
1472
|
-
await store.append(recoverySlug, {
|
|
1473
|
-
actor: humanActor('budget'),
|
|
1474
|
-
type: 'build.auto-merge-cancelled',
|
|
1475
|
-
payload: {},
|
|
1476
|
-
})
|
|
1495
|
+
await seedBuildFiller(store, recoverySlug, length)
|
|
1477
1496
|
await readBuildFacts(store, recoverySlug)
|
|
1478
1497
|
const recoverySlice = Array.prototype.slice
|
|
1479
1498
|
const recoveryBoundary = recoveryEvents.at(-1)!.seq
|
|
@@ -1679,12 +1698,7 @@ export async function parkedSweepReadBudget(opts: {
|
|
|
1679
1698
|
}
|
|
1680
1699
|
const refusedEvents = Reflect.get(store, 'builds').get(refusedSlug)
|
|
1681
1700
|
.events as import('../events/catalog').AbEvent[]
|
|
1682
|
-
|
|
1683
|
-
await store.append(refusedSlug, {
|
|
1684
|
-
actor: humanActor('budget'),
|
|
1685
|
-
type: 'build.auto-merge-cancelled',
|
|
1686
|
-
payload: {},
|
|
1687
|
-
})
|
|
1701
|
+
await seedBuildFiller(store, refusedSlug, length)
|
|
1688
1702
|
await readBuildFacts(store, refusedSlug)
|
|
1689
1703
|
const refusedBoundary = refusedEvents.at(-1)!.seq
|
|
1690
1704
|
let refusedRows = 0
|
|
@@ -2308,14 +2322,14 @@ async function seedRepoFiller(
|
|
|
2308
2322
|
store: import('../store/memory').MemoryBuildStore,
|
|
2309
2323
|
repo: string,
|
|
2310
2324
|
length: number,
|
|
2325
|
+
filler: Parameters<import('../store/memory').MemoryBuildStore['appendRepo']>[1] = {
|
|
2326
|
+
actor: humanActor('budget'),
|
|
2327
|
+
type: 'dispatcher.intake-set',
|
|
2328
|
+
payload: { enabled: true },
|
|
2329
|
+
},
|
|
2311
2330
|
): Promise<void> {
|
|
2312
2331
|
const events: { seq: number }[] = Reflect.get(store, 'repos').get(repo).events
|
|
2313
2332
|
if (events.length >= length) return
|
|
2314
|
-
const filler = {
|
|
2315
|
-
actor: humanActor('budget'),
|
|
2316
|
-
type: 'dispatcher.intake-set' as const,
|
|
2317
|
-
payload: { enabled: true },
|
|
2318
|
-
}
|
|
2319
2333
|
const template = await store.appendRepo(repo, filler)
|
|
2320
2334
|
while (events.length < length - 1) events.push({ ...template, seq: events.length + 1 })
|
|
2321
2335
|
if (events.length < length) await store.appendRepo(repo, filler)
|
|
@@ -2326,22 +2340,52 @@ async function seedBuildFiller(
|
|
|
2326
2340
|
store: import('../store/memory').MemoryBuildStore,
|
|
2327
2341
|
slug: string,
|
|
2328
2342
|
length: number,
|
|
2343
|
+
filler: Parameters<import('../store/memory').MemoryBuildStore['append']>[1] = {
|
|
2344
|
+
actor: humanActor('budget'),
|
|
2345
|
+
type: 'build.auto-merge-cancelled',
|
|
2346
|
+
payload: {},
|
|
2347
|
+
},
|
|
2329
2348
|
): Promise<void> {
|
|
2330
2349
|
const events = buildEventRows(store, slug)
|
|
2331
2350
|
if (events.length >= length) return
|
|
2332
2351
|
// One validated append, copied in bulk; the last append is real again so
|
|
2333
2352
|
// the build's and repository's change positions advance as usual.
|
|
2334
|
-
const filler = {
|
|
2335
|
-
actor: humanActor('budget'),
|
|
2336
|
-
type: 'build.auto-merge-cancelled' as const,
|
|
2337
|
-
payload: {},
|
|
2338
|
-
}
|
|
2339
2353
|
const template = await store.append(slug, filler)
|
|
2340
2354
|
while (events.length < length - 1)
|
|
2341
2355
|
events.push({ ...template, seq: events.length + 1 } as (typeof events)[number])
|
|
2342
2356
|
if (events.length < length) await store.append(slug, filler)
|
|
2343
2357
|
}
|
|
2344
2358
|
|
|
2359
|
+
/** Build padding that no reducer folds into state: the build reducer ignores
|
|
2360
|
+
* it and build facts keep one boolean, so a warm read costs the same at any
|
|
2361
|
+
* padding length. Distinct `observation.recorded` padding would instead grow
|
|
2362
|
+
* every saved build value by one entry per event. Not for builds whose
|
|
2363
|
+
* dispatch would post a ticket comment: the fact records that it was posted. */
|
|
2364
|
+
const INERT_BUILD_FILLER = {
|
|
2365
|
+
actor: DISPATCHER,
|
|
2366
|
+
type: 'dispatch.comment-posted',
|
|
2367
|
+
payload: {},
|
|
2368
|
+
} as const
|
|
2369
|
+
|
|
2370
|
+
/** Pad in bulk what the per-event loop `for (seeded < length)` appended: one
|
|
2371
|
+
* repository filler per step and one inert build fact on every tenth. */
|
|
2372
|
+
async function padRepoAndBuild(
|
|
2373
|
+
store: import('../store/memory').MemoryBuildStore,
|
|
2374
|
+
repo: string,
|
|
2375
|
+
slug: string,
|
|
2376
|
+
seeded: number,
|
|
2377
|
+
length: number,
|
|
2378
|
+
): Promise<void> {
|
|
2379
|
+
const repoRows: unknown[] = Reflect.get(store, 'repos').get(repo).events
|
|
2380
|
+
await seedRepoFiller(store, repo, repoRows.length + length - seeded)
|
|
2381
|
+
await seedBuildFiller(
|
|
2382
|
+
store,
|
|
2383
|
+
slug,
|
|
2384
|
+
buildEventRows(store, slug).length + Math.ceil(length / 10) - Math.ceil(seeded / 10),
|
|
2385
|
+
INERT_BUILD_FILLER,
|
|
2386
|
+
)
|
|
2387
|
+
}
|
|
2388
|
+
|
|
2345
2389
|
function buildEventRows(
|
|
2346
2390
|
store: import('../store/memory').MemoryBuildStore,
|
|
2347
2391
|
slug: string,
|
|
@@ -2719,6 +2763,48 @@ export async function seedPreparationHistory(
|
|
|
2719
2763
|
})
|
|
2720
2764
|
}
|
|
2721
2765
|
|
|
2766
|
+
/** Meter the memory adapter's private ticket-asset storage: `outerScans`
|
|
2767
|
+
* counts iterations of the all-tickets map (any listing that walks other
|
|
2768
|
+
* tickets or repositories), and `revisionRowsVisited` counts revision rows
|
|
2769
|
+
* read from per-name history arrays (a head read is one; a history walk is
|
|
2770
|
+
* every row). Install after seeding: arrays created later are not metered. */
|
|
2771
|
+
export function memoryTicketAssetReadCounter(store: import('../store/memory').MemoryBuildStore) {
|
|
2772
|
+
const tickets = Reflect.get(store, 'ticketAssets') as Map<string, Map<string, unknown[]>>
|
|
2773
|
+
let outerScans = 0
|
|
2774
|
+
let revisionRowsVisited = 0
|
|
2775
|
+
for (const key of ['values', 'entries', 'keys', 'forEach', Symbol.iterator] as const) {
|
|
2776
|
+
const original = (tickets[key] as (...args: unknown[]) => unknown).bind(tickets)
|
|
2777
|
+
Object.defineProperty(tickets, key, {
|
|
2778
|
+
configurable: true,
|
|
2779
|
+
value: (...args: unknown[]) => {
|
|
2780
|
+
outerScans++
|
|
2781
|
+
return original(...args)
|
|
2782
|
+
},
|
|
2783
|
+
})
|
|
2784
|
+
}
|
|
2785
|
+
for (const names of Map.prototype.values.call(tickets) as IterableIterator<
|
|
2786
|
+
Map<string, unknown[]>
|
|
2787
|
+
>)
|
|
2788
|
+
for (const [name, rows] of [...names])
|
|
2789
|
+
names.set(
|
|
2790
|
+
name,
|
|
2791
|
+
new Proxy(rows, {
|
|
2792
|
+
get(target, key, receiver) {
|
|
2793
|
+
if (typeof key === 'string' && /^\d+$/.test(key)) revisionRowsVisited++
|
|
2794
|
+
return Reflect.get(target, key, receiver)
|
|
2795
|
+
},
|
|
2796
|
+
}),
|
|
2797
|
+
)
|
|
2798
|
+
return {
|
|
2799
|
+
get outerScans() {
|
|
2800
|
+
return outerScans
|
|
2801
|
+
},
|
|
2802
|
+
get revisionRowsVisited() {
|
|
2803
|
+
return revisionRowsVisited
|
|
2804
|
+
},
|
|
2805
|
+
}
|
|
2806
|
+
}
|
|
2807
|
+
|
|
2722
2808
|
/** Count the memory adapter's private reducer-storage event slices, in addition
|
|
2723
2809
|
* to public history reads. This deliberately observes storage, not a selector. */
|
|
2724
2810
|
export function memoryRepositoryReadCounter(
|
|
@@ -2801,6 +2887,17 @@ export async function nodePollingReadBudget(opts: {
|
|
|
2801
2887
|
* so the every-tick admission stage is measured on its waiting path. Its
|
|
2802
2888
|
* own reads are excluded from the measurement. */
|
|
2803
2889
|
slotWaiting?: () => Promise<boolean>
|
|
2890
|
+
/** An optimization node with one in-flight attempt build (#1069): proves
|
|
2891
|
+
* its active-hours activity pass. Each change is appended on the attempt
|
|
2892
|
+
* build; `pad` appends unrelated events there. */
|
|
2893
|
+
activity?: {
|
|
2894
|
+
build: string
|
|
2895
|
+
start(): Promise<void>
|
|
2896
|
+
end(): Promise<void>
|
|
2897
|
+
/** A whole start and end pair. */
|
|
2898
|
+
between(): Promise<void>
|
|
2899
|
+
pad(count: number): Promise<void>
|
|
2900
|
+
}
|
|
2804
2901
|
}) {
|
|
2805
2902
|
const { store, slug } = opts
|
|
2806
2903
|
const checkpoint = (await readBuildFacts(store, slug)).value.state.nodePolling!
|
|
@@ -2890,11 +2987,132 @@ export async function nodePollingReadBudget(opts: {
|
|
|
2890
2987
|
} finally {
|
|
2891
2988
|
Reflect.deleteProperty(events, 'slice')
|
|
2892
2989
|
}
|
|
2990
|
+
if (opts.activity) costs.push(...(await activityBudget(store, slug, opts, opts.activity)))
|
|
2893
2991
|
if (baseline) expect(costs).toEqual(baseline)
|
|
2894
2992
|
baseline = costs
|
|
2895
2993
|
}
|
|
2896
2994
|
}
|
|
2897
2995
|
|
|
2996
|
+
/** The active-hours activity pass on an optimization node (#1069): an idle
|
|
2997
|
+
* tick writes nothing and reads nothing extra; a tick after new attempt
|
|
2998
|
+
* execution facts writes one batch and one acknowledgment and reads the
|
|
2999
|
+
* attempt's `executionIntervals` value once, with zero history rows on
|
|
3000
|
+
* either log, also after a long unrelated gap and with more unacknowledged
|
|
3001
|
+
* facts than any window would hold. Every tick is a fresh dispatcher. */
|
|
3002
|
+
async function activityBudget(
|
|
3003
|
+
store: import('../store/memory').MemoryBuildStore,
|
|
3004
|
+
slug: string,
|
|
3005
|
+
opts: { tick: () => Promise<unknown>; advance: (ms: number) => void },
|
|
3006
|
+
activity: NonNullable<Parameters<typeof nodePollingReadBudget>[0]['activity']>,
|
|
3007
|
+
): Promise<number[]> {
|
|
3008
|
+
const { readExecutionIntervals } = await import('./../store/reduced-reads')
|
|
3009
|
+
type Logged = import('../events/catalog').AbEvent
|
|
3010
|
+
const builds = Reflect.get(store, 'builds') as Map<string, { events: Logged[] }>
|
|
3011
|
+
const nodeEvents = builds.get(slug)!.events
|
|
3012
|
+
const attemptEvents = builds.get(activity.build)!.events
|
|
3013
|
+
const count = (events: Logged[], type: string) =>
|
|
3014
|
+
events.filter((event) => event.type === type).length
|
|
3015
|
+
// The value is computed once per key; every later read advances it. One
|
|
3016
|
+
// warm tick brings the attempt's own values to its log's end.
|
|
3017
|
+
await readExecutionIntervals(store, activity.build)
|
|
3018
|
+
opts.advance(10_000)
|
|
3019
|
+
await opts.tick()
|
|
3020
|
+
// Each reduced value of the attempt reads each row at most once over the
|
|
3021
|
+
// whole proof; raw event reads of the attempt are never made.
|
|
3022
|
+
const readBy = new Map<string, Set<number>>()
|
|
3023
|
+
const measure = async (change: () => Promise<void>) => {
|
|
3024
|
+
const nodeBoundary = nodeEvents.at(-1)!.seq
|
|
3025
|
+
await change()
|
|
3026
|
+
const batches = count(nodeEvents, 'optimization.activity-recorded')
|
|
3027
|
+
const acks = count(attemptEvents, 'execution.accounted')
|
|
3028
|
+
let history = 0
|
|
3029
|
+
let reader: string | undefined
|
|
3030
|
+
const nodeSlice = nodeEvents.slice.bind(nodeEvents)
|
|
3031
|
+
nodeEvents.slice = (start, end) => {
|
|
3032
|
+
const selected = nodeSlice(start, end)
|
|
3033
|
+
history += selected.filter((event) => event.seq <= nodeBoundary).length
|
|
3034
|
+
return selected
|
|
3035
|
+
}
|
|
3036
|
+
const attemptSlice = attemptEvents.slice.bind(attemptEvents)
|
|
3037
|
+
attemptEvents.slice = (start, end) => {
|
|
3038
|
+
const selected = attemptSlice(start, end)
|
|
3039
|
+
if (reader === undefined) history += selected.length
|
|
3040
|
+
else {
|
|
3041
|
+
const seen = readBy.get(reader) ?? new Set<number>()
|
|
3042
|
+
readBy.set(reader, seen)
|
|
3043
|
+
for (const event of selected) {
|
|
3044
|
+
if (seen.has(event.seq)) history++
|
|
3045
|
+
seen.add(event.seq)
|
|
3046
|
+
}
|
|
3047
|
+
}
|
|
3048
|
+
return selected
|
|
3049
|
+
}
|
|
3050
|
+
let intervalReads = 0
|
|
3051
|
+
const getReduced = store.getReducerValue.bind(store)
|
|
3052
|
+
// Serialized while measured, so each slice is attributed to its value.
|
|
3053
|
+
let chain: Promise<unknown> = Promise.resolve()
|
|
3054
|
+
store.getReducerValue = (scope, request) => {
|
|
3055
|
+
if (request.reducer === 'executionIntervals') intervalReads++
|
|
3056
|
+
const read = chain.then(async () => {
|
|
3057
|
+
reader =
|
|
3058
|
+
scope.kind === 'build' && scope.slug === activity.build
|
|
3059
|
+
? `${request.reducer}:${JSON.stringify(request.args ?? {})}`
|
|
3060
|
+
: undefined
|
|
3061
|
+
try {
|
|
3062
|
+
return await getReduced(scope, request)
|
|
3063
|
+
} finally {
|
|
3064
|
+
reader = undefined
|
|
3065
|
+
}
|
|
3066
|
+
})
|
|
3067
|
+
chain = read.catch(() => {})
|
|
3068
|
+
return read
|
|
3069
|
+
}
|
|
3070
|
+
try {
|
|
3071
|
+
opts.advance(10_000)
|
|
3072
|
+
await opts.tick()
|
|
3073
|
+
} finally {
|
|
3074
|
+
Reflect.deleteProperty(nodeEvents, 'slice')
|
|
3075
|
+
Reflect.deleteProperty(attemptEvents, 'slice')
|
|
3076
|
+
store.getReducerValue = getReduced
|
|
3077
|
+
}
|
|
3078
|
+
expect(history).toBe(0)
|
|
3079
|
+
return {
|
|
3080
|
+
batches: count(nodeEvents, 'optimization.activity-recorded') - batches,
|
|
3081
|
+
acks: count(attemptEvents, 'execution.accounted') - acks,
|
|
3082
|
+
intervalReads,
|
|
3083
|
+
}
|
|
3084
|
+
}
|
|
3085
|
+
const idle = { batches: 0, acks: 0, intervalReads: 0 }
|
|
3086
|
+
const recorded = { batches: 1, acks: 1, intervalReads: 1 }
|
|
3087
|
+
const vector: number[] = []
|
|
3088
|
+
const expectCost = async (change: () => Promise<void>, cost: typeof idle) => {
|
|
3089
|
+
const measured = await measure(change)
|
|
3090
|
+
expect(measured).toEqual(cost)
|
|
3091
|
+
vector.push(measured.batches, measured.acks, measured.intervalReads)
|
|
3092
|
+
}
|
|
3093
|
+
const nothing = async () => {}
|
|
3094
|
+
await expectCost(nothing, idle)
|
|
3095
|
+
await expectCost(activity.start, recorded)
|
|
3096
|
+
await expectCost(nothing, idle)
|
|
3097
|
+
await expectCost(activity.end, recorded)
|
|
3098
|
+
await expectCost(activity.between, recorded)
|
|
3099
|
+
await expectCost(nothing, idle)
|
|
3100
|
+
// A long unrelated gap between execution facts: still one value read.
|
|
3101
|
+
await expectCost(async () => {
|
|
3102
|
+
await activity.pad(100_000)
|
|
3103
|
+
await activity.between()
|
|
3104
|
+
}, recorded)
|
|
3105
|
+
await expectCost(nothing, idle)
|
|
3106
|
+
// More unacknowledged facts than any window would hold: one read, one
|
|
3107
|
+
// node event, and the value then holds no facts.
|
|
3108
|
+
await expectCost(async () => {
|
|
3109
|
+
for (let pair = 0; pair < 75; pair++) await activity.between()
|
|
3110
|
+
}, recorded)
|
|
3111
|
+
expect((await readExecutionIntervals(store, activity.build)).value.facts).toEqual([])
|
|
3112
|
+
await expectCost(nothing, idle)
|
|
3113
|
+
return vector
|
|
3114
|
+
}
|
|
3115
|
+
|
|
2898
3116
|
/** Node child discovery (AUT-1129) reads only the digest batch plus facts for
|
|
2899
3117
|
* builds whose digest names the node. Fresh dispatchers (one per hosted
|
|
2900
3118
|
* invocation) observing an open node spend the same store reads at 10 and at
|
|
@@ -3041,19 +3259,8 @@ export async function kernelGitOutageReadBudget(opts: {
|
|
|
3041
3259
|
let seeded = 0
|
|
3042
3260
|
let baseline: number[] | undefined
|
|
3043
3261
|
for (const length of [100, 100_000]) {
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
actor: humanActor('budget'),
|
|
3047
|
-
type: 'dispatcher.intake-set',
|
|
3048
|
-
payload: { enabled: true },
|
|
3049
|
-
})
|
|
3050
|
-
if (seeded % 10 === 0)
|
|
3051
|
-
await store.append(slug, {
|
|
3052
|
-
actor: KERNEL,
|
|
3053
|
-
type: 'observation.recorded',
|
|
3054
|
-
payload: { id: `obs-${seeded}`, kind: 'followup', summary: `budget padding ${seeded}` },
|
|
3055
|
-
})
|
|
3056
|
-
}
|
|
3262
|
+
await padRepoAndBuild(store, repo, slug, seeded, length)
|
|
3263
|
+
seeded = length
|
|
3057
3264
|
// Warm up: the outage tick, then one fresh read that catches up its own
|
|
3058
3265
|
// append. Nothing changes after that.
|
|
3059
3266
|
for (let n = 0; n < 2; n++) {
|
|
@@ -3218,20 +3425,22 @@ export async function cliWatchDiscoveryReadBudget() {
|
|
|
3218
3425
|
const clock = manualClock()
|
|
3219
3426
|
const store = new MemoryBuildStore({ clock })
|
|
3220
3427
|
await store.ensureRepo(repo)
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
})
|
|
3428
|
+
await seedRepoFiller(store, repo, length, {
|
|
3429
|
+
actor: humanActor('human'),
|
|
3430
|
+
type: 'dispatcher.intake-set',
|
|
3431
|
+
payload: { enabled: true },
|
|
3432
|
+
})
|
|
3227
3433
|
await store.createBuild({ slug: 'old', repo })
|
|
3228
3434
|
await store.append('old', {
|
|
3229
3435
|
actor: KERNEL,
|
|
3230
3436
|
type: 'runner.attached',
|
|
3231
3437
|
payload: { instance: 'i1', host: 'h1', resumedFromSeq: 0 },
|
|
3232
3438
|
})
|
|
3233
|
-
|
|
3234
|
-
|
|
3439
|
+
await seedBuildFiller(store, 'old', length, {
|
|
3440
|
+
actor: KERNEL,
|
|
3441
|
+
type: 'build.paused',
|
|
3442
|
+
payload: {},
|
|
3443
|
+
})
|
|
3235
3444
|
let attempts = 0
|
|
3236
3445
|
const announce = async (build: string) => {
|
|
3237
3446
|
const attempt = `attempt-${++attempts}`
|
|
@@ -3357,11 +3566,43 @@ export async function operatorTicketAssociationBudget() {
|
|
|
3357
3566
|
const legacy = 'ticket-12345678-1234-1234-1234-123456789abc'
|
|
3358
3567
|
const missing = 'ticket-87654321-4321-4321-4321-cba987654321'
|
|
3359
3568
|
const config = parseConfig('[tickets]\nsource="hosted"\nteamKey="AUT"\nreadyState="Todo"')
|
|
3360
|
-
|
|
3361
|
-
|
|
3569
|
+
const putFile = (
|
|
3570
|
+
store: InstanceType<typeof MemoryBuildStore>,
|
|
3571
|
+
r: string,
|
|
3572
|
+
id: string,
|
|
3573
|
+
name: string,
|
|
3574
|
+
) =>
|
|
3575
|
+
store.putTicketAsset(r, id, {
|
|
3576
|
+
kind: 'design',
|
|
3577
|
+
name,
|
|
3578
|
+
layout: 'file',
|
|
3579
|
+
entries: [{ type: 'file', path: name, content: new TextEncoder().encode(name) }],
|
|
3580
|
+
})
|
|
3581
|
+
for (const [size, withLegacy, history, unrelated] of [1, 200].flatMap((size) =>
|
|
3582
|
+
[false, true].flatMap((withLegacy) =>
|
|
3583
|
+
[1, 100].flatMap((history) =>
|
|
3584
|
+
[0, 100].map((unrelated) => [size, withLegacy, history, unrelated] as const),
|
|
3585
|
+
),
|
|
3586
|
+
),
|
|
3587
|
+
)) {
|
|
3588
|
+
{
|
|
3362
3589
|
let tick = 0
|
|
3363
3590
|
const store = new MemoryBuildStore({ clock: () => new Date(++tick * 1000) })
|
|
3364
3591
|
await store.ensureRepo(repo)
|
|
3592
|
+
// The ticket's own asset history: a live name and a tombstoned one.
|
|
3593
|
+
let live: import('../store/ticket-assets').TicketAssetMeta | undefined
|
|
3594
|
+
for (let i = 0; i < history; i++) {
|
|
3595
|
+
live = await putFile(store, repo, 'AUT-1', 'live')
|
|
3596
|
+
await putFile(store, repo, 'AUT-1', 'gone')
|
|
3597
|
+
}
|
|
3598
|
+
await store.removeTicketAsset(repo, 'AUT-1', 'design', 'gone')
|
|
3599
|
+
// Unrelated assets: other tickets here, and other repositories.
|
|
3600
|
+
for (let i = 0; i < unrelated; i++)
|
|
3601
|
+
for (const [r, id] of [
|
|
3602
|
+
[repo, `AUT-${i + 2}`],
|
|
3603
|
+
[`${repo}-other-${i}`, 'AUT-1'],
|
|
3604
|
+
] as const)
|
|
3605
|
+
for (let revision = 0; revision < 3; revision++) await putFile(store, r, id, 'other')
|
|
3365
3606
|
for (let i = 0; i < size; i++)
|
|
3366
3607
|
await store.createBuild({
|
|
3367
3608
|
slug: `canonical-${i}`,
|
|
@@ -3430,6 +3671,7 @@ export async function operatorTicketAssociationBudget() {
|
|
|
3430
3671
|
sourceFor: () => source,
|
|
3431
3672
|
statesFor: () => ['Triage', 'Todo'],
|
|
3432
3673
|
}
|
|
3674
|
+
const assetReads = memoryTicketAssetReadCounter(store)
|
|
3433
3675
|
const detail =
|
|
3434
3676
|
operation === 'get'
|
|
3435
3677
|
? await getOperatorTicket({
|
|
@@ -3459,6 +3701,22 @@ export async function operatorTicketAssociationBudget() {
|
|
|
3459
3701
|
operation === 'get' ? 1 : operation === 'update' ? 3 : 2,
|
|
3460
3702
|
)
|
|
3461
3703
|
expect(eventReads).toBe(0)
|
|
3704
|
+
// The current-asset listing reads one head per name of this ticket,
|
|
3705
|
+
// whatever its history or the other tickets and repositories hold.
|
|
3706
|
+
expect(assetReads.outerScans).toBe(0)
|
|
3707
|
+
if (operation === 'get') {
|
|
3708
|
+
expect((detail as import('../operator/tickets').OperatorTicketView).assets).toEqual([
|
|
3709
|
+
{
|
|
3710
|
+
kind: 'design',
|
|
3711
|
+
name: 'live',
|
|
3712
|
+
revision: live!.revision,
|
|
3713
|
+
size: 4,
|
|
3714
|
+
layout: 'file',
|
|
3715
|
+
fileCount: 1,
|
|
3716
|
+
},
|
|
3717
|
+
])
|
|
3718
|
+
expect(assetReads.revisionRowsVisited).toBe(2)
|
|
3719
|
+
} else expect(assetReads.revisionRowsVisited).toBe(0)
|
|
3462
3720
|
}
|
|
3463
3721
|
}
|
|
3464
3722
|
}
|
|
@@ -4232,13 +4490,7 @@ export async function nativeMaintenanceReadBudget(opts: {
|
|
|
4232
4490
|
const events = buildEventRows(store, slug)
|
|
4233
4491
|
let baseline: number[] | undefined
|
|
4234
4492
|
for (const length of [100, 10_000]) {
|
|
4235
|
-
|
|
4236
|
-
while (events.length < length)
|
|
4237
|
-
await store.append(slug, {
|
|
4238
|
-
actor: KERNEL,
|
|
4239
|
-
type: 'observation.recorded',
|
|
4240
|
-
payload: { id: `obs_budget_${length}_${filler++}`, kind: 'followup', summary: 'filler' },
|
|
4241
|
-
})
|
|
4493
|
+
await seedBuildFiller(store, slug, length, INERT_BUILD_FILLER)
|
|
4242
4494
|
// Warm the saved reduced values past the filler before measuring.
|
|
4243
4495
|
await opts.tick()
|
|
4244
4496
|
const boundary = events.at(-1)!.seq
|
|
@@ -4300,15 +4552,7 @@ export async function gatedPollingReadBudget(opts: {
|
|
|
4300
4552
|
}) {
|
|
4301
4553
|
const { store, slug, forge } = opts
|
|
4302
4554
|
const events = buildEventRows(store, slug)
|
|
4303
|
-
const fill =
|
|
4304
|
-
let filler = 0
|
|
4305
|
-
while (events.length < length)
|
|
4306
|
-
await store.append(slug, {
|
|
4307
|
-
actor: KERNEL,
|
|
4308
|
-
type: 'observation.recorded',
|
|
4309
|
-
payload: { id: `obs_polling_${length}_${filler++}`, kind: 'followup', summary: 'filler' },
|
|
4310
|
-
})
|
|
4311
|
-
}
|
|
4555
|
+
const fill = (length: number) => seedBuildFiller(store, slug, length, INERT_BUILD_FILLER)
|
|
4312
4556
|
const measure = async () => {
|
|
4313
4557
|
// Warm the saved reduced values past any new rows before measuring.
|
|
4314
4558
|
await opts.tick()
|
|
@@ -4522,19 +4766,8 @@ export async function janitorEscalationRequestBudget(opts: {
|
|
|
4522
4766
|
await store.ensureRepo(repo)
|
|
4523
4767
|
let seeded = 0
|
|
4524
4768
|
for (const length of [100, 100_000]) {
|
|
4525
|
-
|
|
4526
|
-
|
|
4527
|
-
actor: humanActor('budget'),
|
|
4528
|
-
type: 'dispatcher.intake-set',
|
|
4529
|
-
payload: { enabled: true },
|
|
4530
|
-
})
|
|
4531
|
-
if (seeded % 10 === 0)
|
|
4532
|
-
await store.append(slug, {
|
|
4533
|
-
actor: KERNEL,
|
|
4534
|
-
type: 'observation.recorded',
|
|
4535
|
-
payload: { id: `obs-${seeded}`, kind: 'followup', summary: `budget padding ${seeded}` },
|
|
4536
|
-
})
|
|
4537
|
-
}
|
|
4769
|
+
await padRepoAndBuild(store, repo, slug, seeded, length)
|
|
4770
|
+
seeded = length
|
|
4538
4771
|
// Warm up: a fresh dispatcher folds the padding once while nothing fails.
|
|
4539
4772
|
opts.failing(false)
|
|
4540
4773
|
await opts.tick()
|
|
@@ -4752,19 +4985,8 @@ export async function headPathsLandingReadBudget(opts: {
|
|
|
4752
4985
|
const vectors: Record<string, number>[] = []
|
|
4753
4986
|
try {
|
|
4754
4987
|
for (const length of [100, 100_000]) {
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
actor: humanActor('budget'),
|
|
4758
|
-
type: 'dispatcher.intake-set',
|
|
4759
|
-
payload: { enabled: true },
|
|
4760
|
-
})
|
|
4761
|
-
if (seeded % 10 === 0)
|
|
4762
|
-
await store.append(slug, {
|
|
4763
|
-
actor: KERNEL,
|
|
4764
|
-
type: 'observation.recorded',
|
|
4765
|
-
payload: { id: `obs-${seeded}`, kind: 'followup', summary: `budget padding ${seeded}` },
|
|
4766
|
-
})
|
|
4767
|
-
}
|
|
4988
|
+
await padRepoAndBuild(store, repo, slug, seeded, length)
|
|
4989
|
+
seeded = length
|
|
4768
4990
|
for (let n = 0; n < 2; n++) {
|
|
4769
4991
|
opts.advance(120_000)
|
|
4770
4992
|
await opts.tick()
|
|
@@ -5004,6 +5226,40 @@ export async function repositoryEventsReadBudget() {
|
|
|
5004
5226
|
hasMore: false,
|
|
5005
5227
|
})
|
|
5006
5228
|
expect(counter.rows).toBe(0)
|
|
5229
|
+
// The attention digest pages the same backlog through the same bounded,
|
|
5230
|
+
// disjoint reads and never touches the unbounded journal either.
|
|
5231
|
+
ranges.length = 0
|
|
5232
|
+
const digested: unknown[] = []
|
|
5233
|
+
let digestPages = 0
|
|
5234
|
+
cursor = 0
|
|
5235
|
+
for (;;) {
|
|
5236
|
+
const page = (await registry.call('repository.attention', { repo, cursor })) as {
|
|
5237
|
+
events: {
|
|
5238
|
+
items: { event: { type: string }; resolve: { tool: string }[] }[]
|
|
5239
|
+
cursor: number
|
|
5240
|
+
hasMore: boolean
|
|
5241
|
+
}
|
|
5242
|
+
}
|
|
5243
|
+
digestPages++
|
|
5244
|
+
for (const item of page.events.items) {
|
|
5245
|
+
digested.push(item.event)
|
|
5246
|
+
if (item.event.type === 'ticket.handed-back')
|
|
5247
|
+
expect(item.resolve[0]!.tool).toBe('tickets.move')
|
|
5248
|
+
}
|
|
5249
|
+
cursor = page.events.cursor
|
|
5250
|
+
if (!page.events.hasMore) break
|
|
5251
|
+
}
|
|
5252
|
+
expect(digested).toEqual(delivered)
|
|
5253
|
+
expect(digestPages).toBe(pages)
|
|
5254
|
+
expect(ranges).toHaveLength(pages)
|
|
5255
|
+
expect(ranges.every((range) => range.rows <= REPOSITORY_EVENTS_PAGE)).toBe(true)
|
|
5256
|
+
ranges.forEach((range, index) => {
|
|
5257
|
+
if (index > 0) expect(range.since).toBe(ranges[index - 1]!.since + ranges[index - 1]!.rows)
|
|
5258
|
+
})
|
|
5259
|
+
counter.reset()
|
|
5260
|
+
await registry.call('repository.attention', { repo, cursor })
|
|
5261
|
+
await registry.call('repository.attention', { repo })
|
|
5262
|
+
expect(counter.rows).toBe(0)
|
|
5007
5263
|
return pages
|
|
5008
5264
|
}
|
|
5009
5265
|
|
|
@@ -7322,7 +7578,7 @@ export async function ticketStartReadBudget(): Promise<{
|
|
|
7322
7578
|
for (const [builds, history] of [
|
|
7323
7579
|
[5, 100],
|
|
7324
7580
|
[5, 5_000],
|
|
7325
|
-
[
|
|
7581
|
+
[20, 100],
|
|
7326
7582
|
] as const) {
|
|
7327
7583
|
// Full capacity: the request waits for a slot.
|
|
7328
7584
|
const control = await open(builds, history, builds, 'control')
|
|
@@ -7445,7 +7701,7 @@ export async function ticketStartReadBudget(): Promise<{
|
|
|
7445
7701
|
// repeated on a warm and on a fresh process, then an admission. Each costs
|
|
7446
7702
|
// the same beyond the lockstep control at every fleet size.
|
|
7447
7703
|
const admissions = new Map<number, Record<string, number>[]>()
|
|
7448
|
-
for (const builds of [5,
|
|
7704
|
+
for (const builds of [5, 20]) {
|
|
7449
7705
|
const control = await open(builds, 100, builds + 1, 'admission-control')
|
|
7450
7706
|
const world = await open(builds, 100, builds + 1, 'admission', true)
|
|
7451
7707
|
const start = (id: string) =>
|
|
@@ -7527,8 +7783,8 @@ export async function ticketStartReadBudget(): Promise<{
|
|
|
7527
7783
|
await control.store.close()
|
|
7528
7784
|
await world.store.close()
|
|
7529
7785
|
}
|
|
7530
|
-
// No per-build read: identical store requests at 5 and at
|
|
7531
|
-
expect(admissions.get(
|
|
7786
|
+
// No per-build read: identical store requests at 5 and at 20 builds.
|
|
7787
|
+
expect(admissions.get(20)).toEqual(admissions.get(5))
|
|
7532
7788
|
|
|
7533
7789
|
// Priority tiers at full capacity: a normal request is read only by the
|
|
7534
7790
|
// post-dispatch pass, once per tick; re-requesting another priority is one
|
|
@@ -7590,3 +7846,1522 @@ export async function ticketStartReadBudget(): Promise<{
|
|
|
7590
7846
|
for (const calls of tiers.get(100)!) expect(calls).toEqual({})
|
|
7591
7847
|
return baseline
|
|
7592
7848
|
}
|
|
7849
|
+
|
|
7850
|
+
/** `sandbox.status` is a recurring poll (#1223): pad the repository journal
|
|
7851
|
+
* with `history` unrelated facts, open a ready memory sandbox, warm one status
|
|
7852
|
+
* call, then measure a second. The call vector and rows must not depend on
|
|
7853
|
+
* `history`, the repeat over an unchanged journal reads zero event rows, and
|
|
7854
|
+
* status writes nothing. */
|
|
7855
|
+
/** `sandbox.status`'s store cost over `history` unrelated repository facts.
|
|
7856
|
+
* The default measures a steady poll after the outcome was journaled. With
|
|
7857
|
+
* `settle: 'lost'` the attempt's own settle handler never fires (its
|
|
7858
|
+
* `settled` promise never resolves, as when the serving process froze), so
|
|
7859
|
+
* the first measured status is the one that records the outcome through the
|
|
7860
|
+
* compare-and-append, `next` the poll after it (which folds that one fact
|
|
7861
|
+
* into the saved value) and `steady` the poll after that. */
|
|
7862
|
+
export async function operatorSandboxStatusReadBudget(opts: { history: number; settle?: 'lost' }) {
|
|
7863
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
7864
|
+
const { createOperatorSandboxService } = await import('../operator/sandbox')
|
|
7865
|
+
const { memoryOperatorSandbox } = await import('./memory-operator-sandbox')
|
|
7866
|
+
const repo = 'https://github.com/example/sandbox-status-budget'
|
|
7867
|
+
const store = new MemoryBuildStore()
|
|
7868
|
+
await store.ensureRepo(repo)
|
|
7869
|
+
for (let i = 0; i < opts.history; i++) {
|
|
7870
|
+
await store.appendRepo(repo, {
|
|
7871
|
+
actor: humanActor('human'),
|
|
7872
|
+
type: 'dispatcher.intake-set',
|
|
7873
|
+
payload: { enabled: i % 2 === 0 },
|
|
7874
|
+
})
|
|
7875
|
+
}
|
|
7876
|
+
const lost = opts.settle === 'lost'
|
|
7877
|
+
const sandbox = memoryOperatorSandbox('memory-sandbox', lost ? { provisioning: 'deferred' } : {})
|
|
7878
|
+
const base = sandbox.provider.orchestratorSandbox!
|
|
7879
|
+
const service = await createOperatorSandboxService({
|
|
7880
|
+
store,
|
|
7881
|
+
repo,
|
|
7882
|
+
provider: sandbox.provider,
|
|
7883
|
+
sandbox: { idleMinutes: 30, environmentVariables: [] },
|
|
7884
|
+
baseBranch: 'main',
|
|
7885
|
+
...(lost
|
|
7886
|
+
? {
|
|
7887
|
+
capability: {
|
|
7888
|
+
...base,
|
|
7889
|
+
open: async (input: Parameters<typeof base.open>[0]) => {
|
|
7890
|
+
const opened = await base.open(input)
|
|
7891
|
+
return opened.settled === undefined
|
|
7892
|
+
? opened
|
|
7893
|
+
: { status: opened.status, settled: new Promise<never>(() => {}) }
|
|
7894
|
+
},
|
|
7895
|
+
},
|
|
7896
|
+
}
|
|
7897
|
+
: {}),
|
|
7898
|
+
})
|
|
7899
|
+
const registry = buildRegistry({ store, sandbox: service })
|
|
7900
|
+
const ctx = { identity: 'ada@example.com' }
|
|
7901
|
+
await registry.call('sandbox.open', { repo }, ctx)
|
|
7902
|
+
if (lost) sandbox.complete('ready')
|
|
7903
|
+
else await registry.call('sandbox.status', { repo }, ctx)
|
|
7904
|
+
const measure = async () => {
|
|
7905
|
+
const before = (await store.getRepoEvents(repo)).length
|
|
7906
|
+
const counter = memoryStoreRequestCounter(store)
|
|
7907
|
+
let metrics: StoreReadMetrics
|
|
7908
|
+
try {
|
|
7909
|
+
metrics = await measureStoreReads(store, async () => {
|
|
7910
|
+
await registry.call('sandbox.status', { repo }, ctx)
|
|
7911
|
+
})
|
|
7912
|
+
} finally {
|
|
7913
|
+
counter.restore()
|
|
7914
|
+
}
|
|
7915
|
+
const appended = (await store.getRepoEvents(repo)).length - before
|
|
7916
|
+
return {
|
|
7917
|
+
callVector: counter.vector(),
|
|
7918
|
+
rows: metrics.rows,
|
|
7919
|
+
repoRows: metrics.repoRows,
|
|
7920
|
+
appended,
|
|
7921
|
+
}
|
|
7922
|
+
}
|
|
7923
|
+
const first = await measure()
|
|
7924
|
+
const next = await measure()
|
|
7925
|
+
return { ...first, next, steady: await measure() }
|
|
7926
|
+
}
|
|
7927
|
+
|
|
7928
|
+
/** One hosted sandbox tool call's store cost (#1219): the resolver's gate
|
|
7929
|
+
* plus the sandbox service's own reads, measured on the second of two
|
|
7930
|
+
* consecutive `sandbox.exec` calls over `revisions` deposited effective
|
|
7931
|
+
* configs (the last enables `[orchestrator]`). The vector and row counts
|
|
7932
|
+
* must not depend on `revisions`, and two calls must issue at most one store
|
|
7933
|
+
* credential and compose once. */
|
|
7934
|
+
export async function operatorSandboxCallReadBudget(opts: { revisions: number }) {
|
|
7935
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
7936
|
+
const { historicalEffectiveConfig } = await import('../config/effective-artifact.fixture')
|
|
7937
|
+
const { createOperatorSandboxResolver } = await import('../operator/sandbox-resolver')
|
|
7938
|
+
const { createOperatorSandboxService } = await import('../operator/sandbox')
|
|
7939
|
+
const { memoryOperatorSandbox } = await import('./memory-operator-sandbox')
|
|
7940
|
+
const { DISPATCHER_EFFECTIVE_CONFIG_ARTIFACT } = await import('../store/retention')
|
|
7941
|
+
const sandboxRepo = 'https://github.com/example/sandbox-budget'
|
|
7942
|
+
const store = new MemoryBuildStore({ retention: { maxRevisions: opts.revisions + 1 } })
|
|
7943
|
+
await store.ensureRepo(sandboxRepo)
|
|
7944
|
+
for (let revision = 1; revision <= opts.revisions; revision++) {
|
|
7945
|
+
await store.putRepoArtifact(sandboxRepo, {
|
|
7946
|
+
kind: DISPATCHER_EFFECTIVE_CONFIG_ARTIFACT,
|
|
7947
|
+
content: JSON.stringify(historicalEffectiveConfig(revision === opts.revisions)),
|
|
7948
|
+
})
|
|
7949
|
+
}
|
|
7950
|
+
const deposited = await store.listRepoArtifacts(sandboxRepo, DISPATCHER_EFFECTIVE_CONFIG_ARTIFACT)
|
|
7951
|
+
expect(deposited).toHaveLength(opts.revisions)
|
|
7952
|
+
const sandbox = memoryOperatorSandbox()
|
|
7953
|
+
let issued = 0
|
|
7954
|
+
let composed = 0
|
|
7955
|
+
const resolver = createOperatorSandboxResolver({
|
|
7956
|
+
store,
|
|
7957
|
+
canPublish: true,
|
|
7958
|
+
issueStoreToken: async () => `token-${++issued}`,
|
|
7959
|
+
compose: async ({ repo, config }) => {
|
|
7960
|
+
composed++
|
|
7961
|
+
return createOperatorSandboxService({
|
|
7962
|
+
store,
|
|
7963
|
+
repo,
|
|
7964
|
+
provider: sandbox.provider,
|
|
7965
|
+
sandbox: config.orchestrator.sandbox,
|
|
7966
|
+
baseBranch: config.baseBranch,
|
|
7967
|
+
forge: new FakeForge(),
|
|
7968
|
+
})
|
|
7969
|
+
},
|
|
7970
|
+
})
|
|
7971
|
+
const registry = buildRegistry({ store, sandboxResolution: { canPublish: true } })
|
|
7972
|
+
const call = () =>
|
|
7973
|
+
registry.call(
|
|
7974
|
+
'sandbox.exec',
|
|
7975
|
+
{ repo: sandboxRepo, command: 'echo hi' },
|
|
7976
|
+
{ identity: 'ada@example.com', sandboxFor: () => resolver.resolve(sandboxRepo) },
|
|
7977
|
+
)
|
|
7978
|
+
await registry.call(
|
|
7979
|
+
'sandbox.open',
|
|
7980
|
+
{ repo: sandboxRepo },
|
|
7981
|
+
{ identity: 'ada@example.com', sandboxFor: () => resolver.resolve(sandboxRepo) },
|
|
7982
|
+
)
|
|
7983
|
+
await call()
|
|
7984
|
+
const counter = memoryStoreRequestCounter(store)
|
|
7985
|
+
let rows = 0
|
|
7986
|
+
try {
|
|
7987
|
+
const metrics = await measureStoreReads(store, async () => {
|
|
7988
|
+
await call()
|
|
7989
|
+
})
|
|
7990
|
+
rows = metrics.rows + metrics.repoRows
|
|
7991
|
+
} finally {
|
|
7992
|
+
counter.restore()
|
|
7993
|
+
}
|
|
7994
|
+
return { callVector: counter.vector(), rows, issued, composed }
|
|
7995
|
+
}
|
|
7996
|
+
|
|
7997
|
+
/** Agent-context stage (`processes/agent-context.ts`) read budget. At an
|
|
7998
|
+
* unchanged base head a warm stage makes no store call, and a fresh process
|
|
7999
|
+
* makes exactly one pointer read; neither reads an event row, a tree or a
|
|
8000
|
+
* blob, at 100 or at 10,000 repository journal events. Reading the latest
|
|
8001
|
+
* record costs one latest-revision artifact read at 1 and at 1,000 stored
|
|
8002
|
+
* revisions. */
|
|
8003
|
+
export async function agentContextReadBudget(): Promise<void> {
|
|
8004
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
8005
|
+
const { AgentContextCapture } = await import('../processes/agent-context')
|
|
8006
|
+
const { encodeAgentContext, readAgentContext, AGENT_CONTEXT_ARTIFACT } = await import(
|
|
8007
|
+
'../store/agent-context'
|
|
8008
|
+
)
|
|
8009
|
+
const { buildRegistry } = await import('../operator/registry')
|
|
8010
|
+
const canonical = async () => ({
|
|
8011
|
+
version: '0.0.0-budget',
|
|
8012
|
+
skills: [{ installName: 'ab-x', files: [{ path: 'SKILL.md', content: '# x' }] }],
|
|
8013
|
+
})
|
|
8014
|
+
const head = 'a'.repeat(40)
|
|
8015
|
+
const unchangedHeadCost = async (events: number) => {
|
|
8016
|
+
const store = new MemoryBuildStore()
|
|
8017
|
+
const repo = `agent-context-budget-${events}`
|
|
8018
|
+
await store.ensureRepo(repo)
|
|
8019
|
+
for (let i = 0; i < events; i++)
|
|
8020
|
+
await store.appendRepo(repo, {
|
|
8021
|
+
actor: humanActor('budget'),
|
|
8022
|
+
type: 'dispatcher.intake-set',
|
|
8023
|
+
payload: { enabled: true },
|
|
8024
|
+
})
|
|
8025
|
+
const forge = new FakeForge()
|
|
8026
|
+
forge.seedTree(head, {
|
|
8027
|
+
'.agents/skills/x/SKILL.md': '# x',
|
|
8028
|
+
'AGENTS.md': 'agents',
|
|
8029
|
+
})
|
|
8030
|
+
forge.remoteBranches.set('main', head)
|
|
8031
|
+
// Every run is past the head-poll interval: the head is really read.
|
|
8032
|
+
let elapsed = 0
|
|
8033
|
+
const paced = () => (elapsed += 60_000)
|
|
8034
|
+
const warm = new AgentContextCapture({ store, repo, forge, elapsed: paced })
|
|
8035
|
+
expect(await warm.run({ baseBranch: 'main' })).toEqual([])
|
|
8036
|
+
const forgeReads = () => [forge.treeReads.length, forge.blobReads.length]
|
|
8037
|
+
const before = forgeReads()
|
|
8038
|
+
const warmTick = await measureStoreReads(store, async () => {
|
|
8039
|
+
expect(await warm.run({ baseBranch: 'main' })).toEqual([])
|
|
8040
|
+
})
|
|
8041
|
+
const freshTick = await measureStoreReads(store, async () => {
|
|
8042
|
+
expect(
|
|
8043
|
+
await new AgentContextCapture({ store, repo, forge, elapsed: paced }).run({
|
|
8044
|
+
baseBranch: 'main',
|
|
8045
|
+
}),
|
|
8046
|
+
).toEqual([])
|
|
8047
|
+
})
|
|
8048
|
+
expect(forgeReads()).toEqual(before)
|
|
8049
|
+
// `repoState` is the memory store's own private lookup, not a store call.
|
|
8050
|
+
const publicCalls = (calls: Record<string, number>) =>
|
|
8051
|
+
Object.fromEntries(Object.entries(calls).filter(([name]) => name !== 'repoState'))
|
|
8052
|
+
return {
|
|
8053
|
+
warm: publicCalls(warmTick.calls),
|
|
8054
|
+
fresh: publicCalls(freshTick.calls),
|
|
8055
|
+
rows: warmTick.rows + warmTick.repoRows + freshTick.rows + freshTick.repoRows,
|
|
8056
|
+
}
|
|
8057
|
+
}
|
|
8058
|
+
const small = await unchangedHeadCost(100)
|
|
8059
|
+
expect(small).toEqual({ warm: {}, fresh: { getRepoArtifact: 1 }, rows: 0 })
|
|
8060
|
+
expect(await unchangedHeadCost(10_000)).toEqual(small)
|
|
8061
|
+
|
|
8062
|
+
const latestCost = async (revisions: number) => {
|
|
8063
|
+
const store = new MemoryBuildStore({ retention: { maxRevisions: 5_000 } })
|
|
8064
|
+
const repo = `agent-context-revisions-${revisions}`
|
|
8065
|
+
await store.ensureRepo(repo)
|
|
8066
|
+
for (let i = 0; i < revisions; i++) {
|
|
8067
|
+
const encoded = encodeAgentContext({
|
|
8068
|
+
version: 1,
|
|
8069
|
+
commit: i.toString(16).padStart(40, '0'),
|
|
8070
|
+
baseBranch: 'main',
|
|
8071
|
+
skills: [],
|
|
8072
|
+
instructions: [
|
|
8073
|
+
{
|
|
8074
|
+
paths: ['AGENTS.md'],
|
|
8075
|
+
directory: '',
|
|
8076
|
+
oid: `o${i}`,
|
|
8077
|
+
bytes: 1,
|
|
8078
|
+
text: `${i % 10}`,
|
|
8079
|
+
imports: [],
|
|
8080
|
+
},
|
|
8081
|
+
],
|
|
8082
|
+
imports: [],
|
|
8083
|
+
links: [],
|
|
8084
|
+
omitted: [],
|
|
8085
|
+
})
|
|
8086
|
+
await store.putRepoArtifact(repo, {
|
|
8087
|
+
kind: AGENT_CONTEXT_ARTIFACT,
|
|
8088
|
+
content: encoded.content,
|
|
8089
|
+
metadata: { digest: encoded.digest },
|
|
8090
|
+
})
|
|
8091
|
+
}
|
|
8092
|
+
const measure = async (read: () => Promise<unknown>) => {
|
|
8093
|
+
const metrics = await measureStoreReads(store, async () => {
|
|
8094
|
+
await read()
|
|
8095
|
+
})
|
|
8096
|
+
const calls = Object.fromEntries(
|
|
8097
|
+
Object.entries(metrics.calls).filter(([name]) => name !== 'repoState'),
|
|
8098
|
+
)
|
|
8099
|
+
return { calls, rows: metrics.rows + metrics.repoRows }
|
|
8100
|
+
}
|
|
8101
|
+
const record = await measure(async () => {
|
|
8102
|
+
expect((await readAgentContext(store, repo))?.meta.revision).toBe(revisions - 1)
|
|
8103
|
+
})
|
|
8104
|
+
// The context tools serve the same record: one latest-revision read each.
|
|
8105
|
+
const registry = buildRegistry({ store, canonicalSkills: canonical })
|
|
8106
|
+
const list = await measure(() => registry.call('context.list', { repo }))
|
|
8107
|
+
const read = await measure(() => registry.call('context.read', { repo, path: 'AGENTS.md' }))
|
|
8108
|
+
return { record, list, read }
|
|
8109
|
+
}
|
|
8110
|
+
const one = { calls: { getRepoArtifact: 1 }, rows: 0 }
|
|
8111
|
+
expect(await latestCost(1)).toEqual({ record: one, list: one, read: one })
|
|
8112
|
+
expect(await latestCost(1_000)).toEqual({ record: one, list: one, read: one })
|
|
8113
|
+
|
|
8114
|
+
// With no record: the same one (null) read, then the injected bundle.
|
|
8115
|
+
const empty = new MemoryBuildStore()
|
|
8116
|
+
await empty.ensureRepo('agent-context-none')
|
|
8117
|
+
const registry = buildRegistry({ store: empty, canonicalSkills: canonical })
|
|
8118
|
+
for (const [name, input] of [
|
|
8119
|
+
['context.list', { repo: 'agent-context-none' }],
|
|
8120
|
+
['context.read', { repo: 'agent-context-none', path: '.agents/skills/ab-x/SKILL.md' }],
|
|
8121
|
+
] as const) {
|
|
8122
|
+
const metrics = await measureStoreReads(empty, async () => {
|
|
8123
|
+
await registry.call(name, input)
|
|
8124
|
+
})
|
|
8125
|
+
const calls = Object.fromEntries(
|
|
8126
|
+
Object.entries(metrics.calls).filter(([call]) => call !== 'repoState'),
|
|
8127
|
+
)
|
|
8128
|
+
expect({ calls, rows: metrics.rows + metrics.repoRows }).toEqual(one)
|
|
8129
|
+
}
|
|
8130
|
+
}
|
|
8131
|
+
|
|
8132
|
+
/** Count the build records and digest entries callers receive from a memory
|
|
8133
|
+
* store: record entries from `listBuilds`, `listBuildsForRepo`, a found
|
|
8134
|
+
* `getBuild` and `listOpenBuilds`; digest entries from `getRepoBuildDigests`,
|
|
8135
|
+
* `listOpenBuilds` and outer `buildDigest` reductions. Calls the adapter
|
|
8136
|
+
* makes to itself are not counted. */
|
|
8137
|
+
function memoryListingEntryCounter(store: import('../store/memory').MemoryBuildStore) {
|
|
8138
|
+
const inside = new AsyncLocalStorage<true>()
|
|
8139
|
+
let records = 0
|
|
8140
|
+
let digests = 0
|
|
8141
|
+
const restore: (() => void)[] = []
|
|
8142
|
+
const wrap = (name: string, count: (result: unknown, args: unknown[]) => void) => {
|
|
8143
|
+
const original = Reflect.get(store, name) as (...args: unknown[]) => Promise<unknown>
|
|
8144
|
+
Reflect.set(store, name, async (...args: unknown[]) => {
|
|
8145
|
+
if (inside.getStore()) return original.apply(store, args)
|
|
8146
|
+
const result = await inside.run(true, () => original.apply(store, args))
|
|
8147
|
+
count(result, args)
|
|
8148
|
+
return result
|
|
8149
|
+
})
|
|
8150
|
+
restore.push(() => Reflect.deleteProperty(store, name))
|
|
8151
|
+
}
|
|
8152
|
+
wrap('listBuilds', (result) => (records += (result as unknown[]).length))
|
|
8153
|
+
wrap('listBuildsForRepo', (result) => (records += (result as unknown[]).length))
|
|
8154
|
+
wrap('getBuild', (result) => (records += result === null ? 0 : 1))
|
|
8155
|
+
wrap('listOpenBuilds', (result) => {
|
|
8156
|
+
records += (result as unknown[]).length
|
|
8157
|
+
digests += (result as unknown[]).length
|
|
8158
|
+
})
|
|
8159
|
+
wrap('getRepoBuildDigests', (result) => (digests += (result as Map<string, unknown>).size))
|
|
8160
|
+
wrap('getReducerValue', (_result, args) => {
|
|
8161
|
+
if ((args[1] as { reducer: string }).reducer === 'buildDigest') digests++
|
|
8162
|
+
})
|
|
8163
|
+
return {
|
|
8164
|
+
get vector() {
|
|
8165
|
+
return { records, digests }
|
|
8166
|
+
},
|
|
8167
|
+
reset() {
|
|
8168
|
+
records = 0
|
|
8169
|
+
digests = 0
|
|
8170
|
+
},
|
|
8171
|
+
restore() {
|
|
8172
|
+
for (const undo of restore) undo()
|
|
8173
|
+
},
|
|
8174
|
+
}
|
|
8175
|
+
}
|
|
8176
|
+
|
|
8177
|
+
/** Operator reads that list active work — `builds.list` active and queued,
|
|
8178
|
+
* `merges.list`, the dashboard snapshot and `repository.status` with its
|
|
8179
|
+
* held-config capacity — receive the same record and digest entries at 1 and
|
|
8180
|
+
* 30 settled builds and at 100 and 100,000 events, each through a fresh
|
|
8181
|
+
* store handle (the stand-in for a fresh process), and read zero event rows
|
|
8182
|
+
* while nothing changes (#1230). Returns the per-surface entry vectors. */
|
|
8183
|
+
export async function openBuildListingReadBudget() {
|
|
8184
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
8185
|
+
const { listOperatorLandings } = await import('../operator/landings')
|
|
8186
|
+
const { getOperatorAttention } = await import('../operator/attention')
|
|
8187
|
+
const { readRepositoryCapacity } = await import('../cli/repository-status')
|
|
8188
|
+
const repo = 'open-listing-budget'
|
|
8189
|
+
const now = new Date(1000)
|
|
8190
|
+
const created = (slug: string) => ({
|
|
8191
|
+
actor: DISPATCHER,
|
|
8192
|
+
type: 'build.created' as const,
|
|
8193
|
+
payload: { ticket: { source: 'file', id: slug }, repo, baseBranch: 'main' },
|
|
8194
|
+
})
|
|
8195
|
+
const seed = async (settled: number, padding: number) => {
|
|
8196
|
+
const store = new MemoryBuildStore({ clock: () => now })
|
|
8197
|
+
await store.ensureRepo(repo)
|
|
8198
|
+
const config = parseConfig(
|
|
8199
|
+
'[tickets]\nsource="file"\nreadyState="ready"\n[verify]\nsteps=[]\n[finalize]\nsteps=[]',
|
|
8200
|
+
)
|
|
8201
|
+
const { verify: _verify, finalize: _finalize, ...root } = config
|
|
8202
|
+
const artifact = await store.putRepoArtifact(repo, {
|
|
8203
|
+
kind: 'dispatcher-effective-config',
|
|
8204
|
+
content: JSON.stringify({ ...root, verify: { steps: [] }, finalize: { steps: [] } }),
|
|
8205
|
+
})
|
|
8206
|
+
await store.appendRepo(repo, {
|
|
8207
|
+
actor: DISPATCHER,
|
|
8208
|
+
type: 'dispatcher.run-started',
|
|
8209
|
+
payload: {
|
|
8210
|
+
run: 'budget-run',
|
|
8211
|
+
pid: 1,
|
|
8212
|
+
roleWarnings: [],
|
|
8213
|
+
effectiveConfig: { kind: artifact.kind, rev: artifact.revision },
|
|
8214
|
+
},
|
|
8215
|
+
})
|
|
8216
|
+
await store.claimRepoLease(repo, 'budget-run', 3_600_000)
|
|
8217
|
+
await seedRepoFiller(store, repo, padding)
|
|
8218
|
+
// Open builds: queued, settled awaiting consent, aborted in cleanup.
|
|
8219
|
+
await store.createBuild({ slug: 'open-queued', repo, created: created('open-queued') })
|
|
8220
|
+
await store.createBuild({
|
|
8221
|
+
slug: 'open-consent',
|
|
8222
|
+
repo,
|
|
8223
|
+
branch: 'branch/open-consent',
|
|
8224
|
+
created: created('open-consent'),
|
|
8225
|
+
})
|
|
8226
|
+
await store.append('open-consent', {
|
|
8227
|
+
actor: KERNEL,
|
|
8228
|
+
type: 'runner.attached',
|
|
8229
|
+
payload: { instance: 'runner', host: 'host' },
|
|
8230
|
+
})
|
|
8231
|
+
await store.append('open-consent', {
|
|
8232
|
+
actor: KERNEL,
|
|
8233
|
+
type: 'workspace.provisioned',
|
|
8234
|
+
payload: {
|
|
8235
|
+
provider: 'local',
|
|
8236
|
+
ref: 'local',
|
|
8237
|
+
path: '/workspace',
|
|
8238
|
+
branch: 'branch/open-consent',
|
|
8239
|
+
base: { source: 'local', remoteError: 'offline', sha: 'base' },
|
|
8240
|
+
},
|
|
8241
|
+
})
|
|
8242
|
+
const finalized = await store.append('open-consent', {
|
|
8243
|
+
actor: KERNEL,
|
|
8244
|
+
type: 'finalize.completed',
|
|
8245
|
+
payload: { pr: { number: 1, url: 'https://forge/1', headSha: 'head' } },
|
|
8246
|
+
})
|
|
8247
|
+
await store.append('open-consent', {
|
|
8248
|
+
actor: DISPATCHER,
|
|
8249
|
+
type: 'landing.decided',
|
|
8250
|
+
payload: {
|
|
8251
|
+
candidate: { head: 'head', parent: 'base', cycle: String(finalized.seq) },
|
|
8252
|
+
from: 'leaf',
|
|
8253
|
+
into: { kind: 'root' },
|
|
8254
|
+
labels: [],
|
|
8255
|
+
mode: 'consent',
|
|
8256
|
+
rule: { default: true },
|
|
8257
|
+
},
|
|
8258
|
+
})
|
|
8259
|
+
await store.createBuild({ slug: 'open-aborted', repo, created: created('open-aborted') })
|
|
8260
|
+
await store.append('open-aborted', { actor: KERNEL, type: 'build.aborted', payload: {} })
|
|
8261
|
+
for (let i = 0; i < settled; i++) {
|
|
8262
|
+
const slug = `settled-${i}`
|
|
8263
|
+
await store.createBuild({ slug, repo, created: created(slug) })
|
|
8264
|
+
if (i === 0) await seedBuildFiller(store, slug, padding, INERT_BUILD_FILLER)
|
|
8265
|
+
await store.append(slug, {
|
|
8266
|
+
actor: DISPATCHER,
|
|
8267
|
+
type: 'build.completed',
|
|
8268
|
+
payload: { outcome: 'merged' },
|
|
8269
|
+
})
|
|
8270
|
+
}
|
|
8271
|
+
return { store, artifact: (await store.getRepoArtifact(repo, artifact.kind))! }
|
|
8272
|
+
}
|
|
8273
|
+
const surfaces = {
|
|
8274
|
+
active: (store: BuildStore) => listOperatorBuilds({ store, repo, scope: 'active', now }),
|
|
8275
|
+
queued: (store: BuildStore) => listOperatorBuilds({ store, repo, scope: 'queued', now }),
|
|
8276
|
+
landings: (store: BuildStore) => listOperatorLandings({ store, repo }),
|
|
8277
|
+
dashboard: (store: BuildStore) => getOperatorDashboard({ store, repo, clock: () => now }),
|
|
8278
|
+
status: (store: BuildStore) => getRepositoryStatus(store, repo, now),
|
|
8279
|
+
attention: (store: BuildStore) => getOperatorAttention({ store, repo, now }),
|
|
8280
|
+
history: (store: BuildStore) => listOperatorBuilds({ store, repo, scope: 'all', now }),
|
|
8281
|
+
}
|
|
8282
|
+
let baseline: Record<string, { records: number; digests: number }> | undefined
|
|
8283
|
+
const history = new Map<number, number>()
|
|
8284
|
+
for (const settled of [1, 30])
|
|
8285
|
+
for (const padding of [100, 100_000]) {
|
|
8286
|
+
const { store, artifact } = await seed(settled, padding)
|
|
8287
|
+
const facts = (await readRepositoryFacts(store, repo)).value
|
|
8288
|
+
const capacity = (target: BuildStore) =>
|
|
8289
|
+
readRepositoryCapacity(target, repo, facts, artifact, now)
|
|
8290
|
+
const head = await store.getRepoHighWater(repo)
|
|
8291
|
+
const attentionAtHead = (target: BuildStore) =>
|
|
8292
|
+
getOperatorAttention({ store: target, repo, cursor: head, now })
|
|
8293
|
+
const all = { ...surfaces, capacity, attentionAtHead }
|
|
8294
|
+
// Warm-up: every once-per-key reduction happens here. The seeded
|
|
8295
|
+
// surfaces answer real work, so the counted reads are meaningful.
|
|
8296
|
+
for (const run of Object.values(all)) await run(store)
|
|
8297
|
+
expect((await surfaces.landings(store)).map((entry) => entry.slug)).toEqual(['open-consent'])
|
|
8298
|
+
expect(
|
|
8299
|
+
(await surfaces.dashboard(store)).model.builds.map((build) => build.slug).sort(),
|
|
8300
|
+
).toEqual(['open-aborted', 'open-consent', 'open-queued'])
|
|
8301
|
+
expect((await surfaces.status(store)).capacity).toBeDefined()
|
|
8302
|
+
const digest = await surfaces.attention(store)
|
|
8303
|
+
expect(digest.merges.map((merge) => merge.slug)).toEqual(['open-consent'])
|
|
8304
|
+
expect(digest.escalations).toEqual([])
|
|
8305
|
+
expect(JSON.stringify(digest)).not.toMatch(/open-aborted|settled-/)
|
|
8306
|
+
const rows = memoryRepositoryReadCounter(store, repo)
|
|
8307
|
+
const entries = memoryListingEntryCounter(store)
|
|
8308
|
+
const vectors: Record<string, { records: number; digests: number }> = {}
|
|
8309
|
+
try {
|
|
8310
|
+
for (const [name, run] of Object.entries(all)) {
|
|
8311
|
+
// A fresh handle shares no store-identity-keyed cache.
|
|
8312
|
+
const fresh = new Proxy(store, {
|
|
8313
|
+
get(target, property) {
|
|
8314
|
+
const value = Reflect.get(target, property)
|
|
8315
|
+
return typeof value === 'function' ? value.bind(target) : value
|
|
8316
|
+
},
|
|
8317
|
+
})
|
|
8318
|
+
rows.reset()
|
|
8319
|
+
entries.reset()
|
|
8320
|
+
await run(fresh)
|
|
8321
|
+
expect({ name, rows: rows.rows, buildRows: rows.buildRows }).toEqual({
|
|
8322
|
+
name,
|
|
8323
|
+
rows: 0,
|
|
8324
|
+
buildRows: 0,
|
|
8325
|
+
})
|
|
8326
|
+
if (name === 'history') history.set(settled, entries.vector.records)
|
|
8327
|
+
else vectors[name] = entries.vector
|
|
8328
|
+
}
|
|
8329
|
+
} finally {
|
|
8330
|
+
entries.restore()
|
|
8331
|
+
}
|
|
8332
|
+
if (baseline) expect(vectors).toEqual(baseline)
|
|
8333
|
+
baseline = vectors
|
|
8334
|
+
}
|
|
8335
|
+
// The counter bites: the explicit history listing grows with settled builds.
|
|
8336
|
+
expect(history.get(30)).toBeGreaterThan(history.get(1)!)
|
|
8337
|
+
return baseline!
|
|
8338
|
+
}
|
|
8339
|
+
|
|
8340
|
+
/** The repository-scoped MCP listing gate (`sandboxToolsListed`) over a
|
|
8341
|
+
* repository holding `revisions` deposited effective configs, the latest
|
|
8342
|
+
* enabling `[orchestrator]`. Proves the listing cost is one repository read
|
|
8343
|
+
* plus the latest artifact, independent of revision count, with no events. */
|
|
8344
|
+
export async function operatorSandboxListingReadBudget(opts: { revisions: number }) {
|
|
8345
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
8346
|
+
const { historicalEffectiveConfig } = await import('../config/effective-artifact.fixture')
|
|
8347
|
+
const { sandboxToolsListed } = await import('../operator/query')
|
|
8348
|
+
const { DISPATCHER_EFFECTIVE_CONFIG_ARTIFACT } = await import('../store/retention')
|
|
8349
|
+
const repo = 'https://github.com/example/sandbox-listing-budget'
|
|
8350
|
+
const store = new MemoryBuildStore({ retention: { maxRevisions: opts.revisions + 1 } })
|
|
8351
|
+
await store.ensureRepo(repo)
|
|
8352
|
+
for (let revision = 1; revision <= opts.revisions; revision++) {
|
|
8353
|
+
await store.putRepoArtifact(repo, {
|
|
8354
|
+
kind: DISPATCHER_EFFECTIVE_CONFIG_ARTIFACT,
|
|
8355
|
+
content: JSON.stringify(historicalEffectiveConfig(revision === opts.revisions)),
|
|
8356
|
+
})
|
|
8357
|
+
}
|
|
8358
|
+
const counter = memoryStoreRequestCounter(store)
|
|
8359
|
+
let listed = false
|
|
8360
|
+
let rows = 0
|
|
8361
|
+
try {
|
|
8362
|
+
const metrics = await measureStoreReads(store, async () => {
|
|
8363
|
+
listed = await sandboxToolsListed(store, repo)
|
|
8364
|
+
})
|
|
8365
|
+
rows = metrics.rows + metrics.repoRows
|
|
8366
|
+
} finally {
|
|
8367
|
+
counter.restore()
|
|
8368
|
+
}
|
|
8369
|
+
return { callVector: counter.vector(), rows, listed }
|
|
8370
|
+
}
|
|
8371
|
+
|
|
8372
|
+
/** What one measured feed or page read cost: the store calls, log rows and
|
|
8373
|
+
* returned bytes `measureStoreReads` saw, plus the feed-index or creation-order
|
|
8374
|
+
* entries the memory store visited to answer. */
|
|
8375
|
+
export interface BuildFeedReadCost {
|
|
8376
|
+
calls: Record<string, number>
|
|
8377
|
+
rows: number
|
|
8378
|
+
repoRows: number
|
|
8379
|
+
bytes: number
|
|
8380
|
+
examined: number
|
|
8381
|
+
}
|
|
8382
|
+
|
|
8383
|
+
/**
|
|
8384
|
+
* The changed-builds feed and the paged build listing cost what their answer
|
|
8385
|
+
* costs (RFC 0007 §8.4): the same at 100 and 10,000 builds, the same whether a
|
|
8386
|
+
* changed build saw 100 writes or 10,000, and never an event row. The memory
|
|
8387
|
+
* store's visited-entry counter stands in for the SQL adapters' index range
|
|
8388
|
+
* scans. Returns each axis's measured costs by size.
|
|
8389
|
+
*/
|
|
8390
|
+
export async function buildFeedReadBudget(): Promise<{
|
|
8391
|
+
builds: Record<number, { idle: BuildFeedReadCost; oneChange: BuildFeedReadCost }>
|
|
8392
|
+
repeated: Record<number, BuildFeedReadCost>
|
|
8393
|
+
paging: Record<number, { first: BuildFeedReadCost; second: BuildFeedReadCost }>
|
|
8394
|
+
}> {
|
|
8395
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
8396
|
+
type Store = import('../store/memory').MemoryBuildStore
|
|
8397
|
+
const repo = 'feed-budget/repo'
|
|
8398
|
+
const slug = (i: number) => `feed-${String(i).padStart(5, '0')}`
|
|
8399
|
+
const event = { actor: KERNEL, type: 'build.aborted' as const, payload: {} }
|
|
8400
|
+
const fresh = async (count: number) => {
|
|
8401
|
+
const store = new MemoryBuildStore({ clock: () => new Date('2026-11-23T00:00:00.000Z') })
|
|
8402
|
+
for (let i = 0; i < count; i++) await store.createBuild({ slug: slug(i), repo })
|
|
8403
|
+
return store
|
|
8404
|
+
}
|
|
8405
|
+
const measure = async <T>(
|
|
8406
|
+
store: Store,
|
|
8407
|
+
read: () => Promise<T>,
|
|
8408
|
+
): Promise<{ result: T; cost: BuildFeedReadCost }> => {
|
|
8409
|
+
const feedReads = Reflect.get(store, 'feedReads') as { examined: number }
|
|
8410
|
+
feedReads.examined = 0
|
|
8411
|
+
let result: T | undefined
|
|
8412
|
+
const metrics = await measureStoreReads(store, async () => {
|
|
8413
|
+
result = await read()
|
|
8414
|
+
})
|
|
8415
|
+
return {
|
|
8416
|
+
result: result as T,
|
|
8417
|
+
cost: {
|
|
8418
|
+
calls: metrics.calls,
|
|
8419
|
+
rows: metrics.rows,
|
|
8420
|
+
repoRows: metrics.repoRows,
|
|
8421
|
+
bytes: metrics.bytes,
|
|
8422
|
+
examined: feedReads.examined,
|
|
8423
|
+
},
|
|
8424
|
+
}
|
|
8425
|
+
}
|
|
8426
|
+
const sizes = [100, 10_000] as const
|
|
8427
|
+
const builds: Record<number, { idle: BuildFeedReadCost; oneChange: BuildFeedReadCost }> = {}
|
|
8428
|
+
const repeated: Record<number, BuildFeedReadCost> = {}
|
|
8429
|
+
const paging: Record<number, { first: BuildFeedReadCost; second: BuildFeedReadCost }> = {}
|
|
8430
|
+
|
|
8431
|
+
for (const n of sizes) {
|
|
8432
|
+
const store = await fresh(n)
|
|
8433
|
+
const head = await store.getRepoChangePosition(repo)
|
|
8434
|
+
// Idle: nothing after the head reads no rows and visits at most one entry.
|
|
8435
|
+
const idle = await measure(store, () => store.listBuildsChangedSince(repo, head))
|
|
8436
|
+
expect(idle.result).toEqual({ position: head, builds: [] })
|
|
8437
|
+
// One change: exactly that build, visiting it and the entry that stops the walk.
|
|
8438
|
+
const changed = slug(n / 2)
|
|
8439
|
+
await store.append(changed, event)
|
|
8440
|
+
const oneChange = await measure(store, () => store.listBuildsChangedSince(repo, head))
|
|
8441
|
+
expect(oneChange.result.builds).toEqual([
|
|
8442
|
+
{ slug: changed, position: oneChange.result.position },
|
|
8443
|
+
])
|
|
8444
|
+
builds[n] = { idle: idle.cost, oneChange: oneChange.cost }
|
|
8445
|
+
|
|
8446
|
+
// Paging: two newest-first pages through `next`.
|
|
8447
|
+
const first = await measure(store, () => store.listBuildsPage(repo))
|
|
8448
|
+
expect(first.result.builds.map((build) => build.slug)).toEqual(
|
|
8449
|
+
Array.from({ length: 25 }, (_, i) => slug(n - 1 - i)),
|
|
8450
|
+
)
|
|
8451
|
+
const second = await measure(store, () =>
|
|
8452
|
+
store.listBuildsPage(repo, { cursor: first.result.next! }),
|
|
8453
|
+
)
|
|
8454
|
+
expect(second.result.builds.map((build) => build.slug)).toEqual(
|
|
8455
|
+
Array.from({ length: 25 }, (_, i) => slug(n - 26 - i)),
|
|
8456
|
+
)
|
|
8457
|
+
paging[n] = { first: first.cost, second: second.cost }
|
|
8458
|
+
}
|
|
8459
|
+
|
|
8460
|
+
for (const m of sizes) {
|
|
8461
|
+
// Repeated changes to one build: one entry per build, never a growing log.
|
|
8462
|
+
const store = await fresh(10)
|
|
8463
|
+
const since = await store.getRepoChangePosition(repo)
|
|
8464
|
+
for (let i = 0; i < m; i++) await store.append(slug(3), event)
|
|
8465
|
+
const feed = await measure(store, () => store.listBuildsChangedSince(repo, since))
|
|
8466
|
+
expect(feed.result).toEqual({
|
|
8467
|
+
position: await store.getRepoChangePosition(repo),
|
|
8468
|
+
builds: [{ slug: slug(3), position: await store.getRepoChangePosition(repo) }],
|
|
8469
|
+
})
|
|
8470
|
+
repeated[m] = feed.cost
|
|
8471
|
+
}
|
|
8472
|
+
|
|
8473
|
+
const [small, large] = sizes
|
|
8474
|
+
for (const n of sizes) {
|
|
8475
|
+
const { idle, oneChange } = builds[n]!
|
|
8476
|
+
for (const cost of [idle, oneChange]) {
|
|
8477
|
+
expect(cost.calls).toEqual({ listBuildsChangedSince: 1 })
|
|
8478
|
+
expect(cost.rows).toBe(0)
|
|
8479
|
+
expect(cost.repoRows).toBe(0)
|
|
8480
|
+
expect(cost.bytes).toBeLessThanOrEqual(256)
|
|
8481
|
+
}
|
|
8482
|
+
expect(idle.examined).toBeLessThanOrEqual(1)
|
|
8483
|
+
expect(oneChange.examined).toBe(2)
|
|
8484
|
+
for (const cost of [paging[n]!.first, paging[n]!.second]) {
|
|
8485
|
+
expect(cost.rows).toBe(0)
|
|
8486
|
+
expect(cost.repoRows).toBe(0)
|
|
8487
|
+
expect(cost.examined).toBeLessThanOrEqual(26)
|
|
8488
|
+
}
|
|
8489
|
+
expect(repeated[n]!.rows).toBe(0)
|
|
8490
|
+
expect(repeated[n]!.examined).toBe(2)
|
|
8491
|
+
expect(repeated[n]!.calls).toEqual({ listBuildsChangedSince: 1 })
|
|
8492
|
+
}
|
|
8493
|
+
const shape = ({ calls, rows, repoRows, examined }: BuildFeedReadCost) => ({
|
|
8494
|
+
calls,
|
|
8495
|
+
rows,
|
|
8496
|
+
repoRows,
|
|
8497
|
+
examined,
|
|
8498
|
+
})
|
|
8499
|
+
expect(shape(builds[large]!.idle)).toEqual(shape(builds[small]!.idle))
|
|
8500
|
+
expect(shape(builds[large]!.oneChange)).toEqual(shape(builds[small]!.oneChange))
|
|
8501
|
+
expect(shape(repeated[large]!)).toEqual(shape(repeated[small]!))
|
|
8502
|
+
expect(paging[large]).toEqual(paging[small]!)
|
|
8503
|
+
return { builds, repeated, paging }
|
|
8504
|
+
}
|
|
8505
|
+
|
|
8506
|
+
/**
|
|
8507
|
+
* A filtered build page costs what its page costs: at most `limit + 1` listing
|
|
8508
|
+
* entries and no event row, the same at 100 and 100,000 builds, however many
|
|
8509
|
+
* builds match. Covers a rare filter matching only the oldest builds, a rare
|
|
8510
|
+
* activity window, a large active set, a rare kind inside it, an empty
|
|
8511
|
+
* intersection and later pages. Returns each request's page costs by size.
|
|
8512
|
+
*/
|
|
8513
|
+
export async function filteredBuildPageReadBudget(): Promise<
|
|
8514
|
+
Record<number, Record<string, BuildFeedReadCost[]>>
|
|
8515
|
+
> {
|
|
8516
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
8517
|
+
type Store = import('../store/memory').MemoryBuildStore
|
|
8518
|
+
type Options = import('../store/build-feed').BuildPageOptions
|
|
8519
|
+
const repo = 'filtered-budget/repo'
|
|
8520
|
+
const slug = (i: number) => `lf-${String(i).padStart(6, '0')}`
|
|
8521
|
+
const t0 = '2026-11-24T00:00:00.000Z'
|
|
8522
|
+
const t1 = '2026-11-24T01:00:00.000Z'
|
|
8523
|
+
const nodes = 30
|
|
8524
|
+
const range = (from: number, to: number) =>
|
|
8525
|
+
Array.from({ length: from - to + 1 }, (_, i) => slug(from - i))
|
|
8526
|
+
const measure = async (store: Store, opts: Options) => {
|
|
8527
|
+
const feedReads = Reflect.get(store, 'feedReads') as { examined: number }
|
|
8528
|
+
feedReads.examined = 0
|
|
8529
|
+
let page: import('../store/build-feed').BuildPage | undefined
|
|
8530
|
+
const metrics = await measureStoreReads(store, async () => {
|
|
8531
|
+
page = await store.listBuildsPage(repo, opts)
|
|
8532
|
+
})
|
|
8533
|
+
const cost: BuildFeedReadCost = {
|
|
8534
|
+
calls: metrics.calls,
|
|
8535
|
+
rows: metrics.rows,
|
|
8536
|
+
repoRows: metrics.repoRows,
|
|
8537
|
+
bytes: metrics.bytes,
|
|
8538
|
+
examined: feedReads.examined,
|
|
8539
|
+
}
|
|
8540
|
+
return { page: page!, cost }
|
|
8541
|
+
}
|
|
8542
|
+
/** Pages of one request, checked against their expected slugs; the last
|
|
8543
|
+
* expected page is the final one unless `more` says the walk stops early. */
|
|
8544
|
+
const walk = async (store: Store, opts: Options, expected: string[][], more = false) => {
|
|
8545
|
+
const costs: BuildFeedReadCost[] = []
|
|
8546
|
+
let cursor: string | undefined
|
|
8547
|
+
for (const [index, slugs] of expected.entries()) {
|
|
8548
|
+
const { page, cost } = await measure(store, {
|
|
8549
|
+
...opts,
|
|
8550
|
+
...(cursor === undefined ? {} : { cursor }),
|
|
8551
|
+
})
|
|
8552
|
+
expect(page.builds.map((build) => build.slug)).toEqual(slugs)
|
|
8553
|
+
expect(page.next === null).toBe(!more && index === expected.length - 1)
|
|
8554
|
+
cursor = page.next ?? undefined
|
|
8555
|
+
costs.push(cost)
|
|
8556
|
+
}
|
|
8557
|
+
return costs
|
|
8558
|
+
}
|
|
8559
|
+
|
|
8560
|
+
const sizes = [100, 100_000] as const
|
|
8561
|
+
const costs: Record<number, Record<string, BuildFeedReadCost[]>> = {}
|
|
8562
|
+
for (const n of sizes) {
|
|
8563
|
+
let now = t0
|
|
8564
|
+
const store = new MemoryBuildStore({ clock: () => new Date(now) })
|
|
8565
|
+
// The oldest builds are merged nodes; every later build is a plain leaf.
|
|
8566
|
+
for (let i = 0; i < n; i++)
|
|
8567
|
+
await store.createBuild({
|
|
8568
|
+
slug: slug(i),
|
|
8569
|
+
repo,
|
|
8570
|
+
...(i < nodes
|
|
8571
|
+
? {
|
|
8572
|
+
created: {
|
|
8573
|
+
actor: DISPATCHER,
|
|
8574
|
+
type: 'build.created' as const,
|
|
8575
|
+
payload: {
|
|
8576
|
+
ticket: { source: 'file' as const, id: slug(i) },
|
|
8577
|
+
repo,
|
|
8578
|
+
baseBranch: 'main',
|
|
8579
|
+
kind: 'node' as const,
|
|
8580
|
+
},
|
|
8581
|
+
},
|
|
8582
|
+
}
|
|
8583
|
+
: {}),
|
|
8584
|
+
})
|
|
8585
|
+
for (let i = 0; i < nodes; i++)
|
|
8586
|
+
await store.append(slug(i), {
|
|
8587
|
+
actor: DISPATCHER,
|
|
8588
|
+
type: 'build.completed',
|
|
8589
|
+
payload: { outcome: 'merged' },
|
|
8590
|
+
})
|
|
8591
|
+
// Three old builds are active again at t1.
|
|
8592
|
+
now = t1
|
|
8593
|
+
for (const i of [1, 2, 3])
|
|
8594
|
+
await store.append(slug(i), { actor: KERNEL, type: 'build.aborted', payload: {} })
|
|
8595
|
+
const recent = [slug(3), slug(2), slug(1)]
|
|
8596
|
+
const oldNodes = [range(29, 5), range(4, 0)]
|
|
8597
|
+
costs[n] = {
|
|
8598
|
+
node: await walk(store, { kind: 'node' }, oldNodes),
|
|
8599
|
+
merged: await walk(store, { outcome: 'merged' }, oldNodes),
|
|
8600
|
+
mergedNode: await walk(store, { kind: 'node', outcome: 'merged' }, oldNodes),
|
|
8601
|
+
mergedLeaf: await walk(store, { kind: 'leaf', outcome: 'merged' }, [[]]),
|
|
8602
|
+
recent: await walk(store, { activeSince: t1 }, [recent]),
|
|
8603
|
+
active: await walk(
|
|
8604
|
+
store,
|
|
8605
|
+
{ activeSince: t0 },
|
|
8606
|
+
[[...recent, ...range(n - 1, n - 22)], range(n - 23, n - 47)],
|
|
8607
|
+
true,
|
|
8608
|
+
),
|
|
8609
|
+
activeNode: await walk(store, { activeSince: t0, kind: 'node' }, [
|
|
8610
|
+
[...recent, ...range(29, 8)],
|
|
8611
|
+
[...range(7, 4), slug(0)],
|
|
8612
|
+
]),
|
|
8613
|
+
recentLeaf: await walk(store, { activeSince: t1, kind: 'leaf' }, [[]]),
|
|
8614
|
+
}
|
|
8615
|
+
}
|
|
8616
|
+
for (const n of sizes)
|
|
8617
|
+
for (const [name, pages] of Object.entries(costs[n]!))
|
|
8618
|
+
for (const cost of pages) {
|
|
8619
|
+
// `snapshot` is the memory store copying each returned record.
|
|
8620
|
+
const { snapshot: copies = 0, ...reads } = cost.calls
|
|
8621
|
+
expect(reads).toEqual({ listBuildsPage: 1 })
|
|
8622
|
+
expect(copies).toBeLessThanOrEqual(25)
|
|
8623
|
+
expect(cost.rows).toBe(0)
|
|
8624
|
+
expect(cost.repoRows).toBe(0)
|
|
8625
|
+
expect(cost.examined).toBeLessThanOrEqual(
|
|
8626
|
+
name === 'recent' ? 4 : name === 'mergedLeaf' || name === 'recentLeaf' ? 1 : 26,
|
|
8627
|
+
)
|
|
8628
|
+
}
|
|
8629
|
+
const shape = (pages: BuildFeedReadCost[]) =>
|
|
8630
|
+
pages.map(({ calls, rows, repoRows, examined }) => ({ calls, rows, repoRows, examined }))
|
|
8631
|
+
for (const name of Object.keys(costs[sizes[0]]!))
|
|
8632
|
+
expect(shape(costs[sizes[1]]![name]!)).toEqual(shape(costs[sizes[0]]![name]!))
|
|
8633
|
+
return costs
|
|
8634
|
+
}
|
|
8635
|
+
|
|
8636
|
+
/** What one measured rollup read cost (SPEC §7.7). */
|
|
8637
|
+
export interface RollupReadCost {
|
|
8638
|
+
calls: Record<string, number>
|
|
8639
|
+
rows: number
|
|
8640
|
+
repoRows: number
|
|
8641
|
+
/** Feed entries the memory store visited to answer `listBuildsChangedSince`. */
|
|
8642
|
+
examined: number
|
|
8643
|
+
/** `listBuildsChangedSince` positions the read asked from. */
|
|
8644
|
+
feedFrom: string[]
|
|
8645
|
+
}
|
|
8646
|
+
|
|
8647
|
+
/** One measured rollup read on a memory store: its answer and cost. Every
|
|
8648
|
+
* event read it makes is appended to `reads`. */
|
|
8649
|
+
async function measureRollupRead(
|
|
8650
|
+
store: import('../store/memory').MemoryBuildStore,
|
|
8651
|
+
scope: { kind: 'rollup'; repo: string },
|
|
8652
|
+
request: ReducerValueRequestLike,
|
|
8653
|
+
reads: { slug: string; seq: number }[],
|
|
8654
|
+
): Promise<{ value: unknown; cost: RollupReadCost }> {
|
|
8655
|
+
const feedReads = Reflect.get(store, 'feedReads') as { examined: number }
|
|
8656
|
+
feedReads.examined = 0
|
|
8657
|
+
const feedFrom: string[] = []
|
|
8658
|
+
const feed = store.listBuildsChangedSince.bind(store)
|
|
8659
|
+
Reflect.set(store, 'listBuildsChangedSince', (target: string, since: string) => {
|
|
8660
|
+
feedFrom.push(since)
|
|
8661
|
+
return feed(target, since)
|
|
8662
|
+
})
|
|
8663
|
+
let value: unknown
|
|
8664
|
+
try {
|
|
8665
|
+
const metrics = await measureStoreReads(store, async () => {
|
|
8666
|
+
value = (await store.getReducerValue(scope, request)).value
|
|
8667
|
+
})
|
|
8668
|
+
reads.push(...metrics.read)
|
|
8669
|
+
return {
|
|
8670
|
+
value,
|
|
8671
|
+
cost: {
|
|
8672
|
+
calls: metrics.calls,
|
|
8673
|
+
rows: metrics.rows,
|
|
8674
|
+
repoRows: metrics.repoRows,
|
|
8675
|
+
examined: feedReads.examined,
|
|
8676
|
+
feedFrom,
|
|
8677
|
+
},
|
|
8678
|
+
}
|
|
8679
|
+
} finally {
|
|
8680
|
+
Reflect.deleteProperty(store, 'listBuildsChangedSince')
|
|
8681
|
+
}
|
|
8682
|
+
}
|
|
8683
|
+
|
|
8684
|
+
/**
|
|
8685
|
+
* The `stepDurations` rollup costs what changed (RFC 0007 §9, SPEC §7.7): at
|
|
8686
|
+
* 100 and at 10,000 builds, an idle read reads zero event rows and makes no
|
|
8687
|
+
* feed query, including across a retention boundary; a read after changes
|
|
8688
|
+
* reads exactly the changed builds' new events through one feed query, the
|
|
8689
|
+
* same at both sizes; and each build's log is reduced once per rollup key,
|
|
8690
|
+
* ever: a second key and a fresh process's serialization reuse the saved
|
|
8691
|
+
* build values. Returns each size's measured costs.
|
|
8692
|
+
*/
|
|
8693
|
+
export async function rollupReadBudget(): Promise<
|
|
8694
|
+
Record<
|
|
8695
|
+
number,
|
|
8696
|
+
{
|
|
8697
|
+
first: RollupReadCost
|
|
8698
|
+
idle: RollupReadCost
|
|
8699
|
+
oneChange: RollupReadCost
|
|
8700
|
+
fiveChanges: RollupReadCost
|
|
8701
|
+
secondKey: RollupReadCost
|
|
8702
|
+
fresh: RollupReadCost
|
|
8703
|
+
retention: RollupReadCost
|
|
8704
|
+
}
|
|
8705
|
+
>
|
|
8706
|
+
> {
|
|
8707
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
8708
|
+
const { KeyedMutex } = await import('../store/rollups')
|
|
8709
|
+
const { agentActor } = await import('../events/envelope')
|
|
8710
|
+
const { manualClock } = await import('./fixed')
|
|
8711
|
+
type Store = import('../store/memory').MemoryBuildStore
|
|
8712
|
+
const repo = 'rollup-budget/repo'
|
|
8713
|
+
const scope = { kind: 'rollup', repo } as const
|
|
8714
|
+
const slug = (i: number) => `rollup-${String(i).padStart(5, '0')}`
|
|
8715
|
+
const planPair = async (store: Store, target: string, round: number, advance: () => void) => {
|
|
8716
|
+
await store.append(target, { actor: KERNEL, type: 'plan.started', payload: { round } })
|
|
8717
|
+
advance()
|
|
8718
|
+
await store.append(target, {
|
|
8719
|
+
actor: agentActor('plan', 'session'),
|
|
8720
|
+
type: 'plan.completed',
|
|
8721
|
+
payload: { round, artifact: { kind: 'plan', rev: 0 } },
|
|
8722
|
+
})
|
|
8723
|
+
}
|
|
8724
|
+
const results: Awaited<ReturnType<typeof rollupReadBudget>> = {}
|
|
8725
|
+
for (const n of [100, 10_000]) {
|
|
8726
|
+
const clock = manualClock('2026-11-23T00:00:00.000Z')
|
|
8727
|
+
const store = new MemoryBuildStore({ clock })
|
|
8728
|
+
const tick = () => clock.advance(60_000)
|
|
8729
|
+
for (let i = 0; i < n; i++) {
|
|
8730
|
+
await store.createBuild({ slug: slug(i), repo })
|
|
8731
|
+
await planPair(store, slug(i), 1, () => {})
|
|
8732
|
+
await store.append(slug(i), {
|
|
8733
|
+
actor: DISPATCHER,
|
|
8734
|
+
type: 'build.completed',
|
|
8735
|
+
payload: { outcome: 'merged' },
|
|
8736
|
+
})
|
|
8737
|
+
}
|
|
8738
|
+
const reads: { slug: string; seq: number }[] = []
|
|
8739
|
+
const measure = (request: ReducerValueRequestLike) =>
|
|
8740
|
+
measureRollupRead(store, scope, request, reads)
|
|
8741
|
+
const request = { reducer: 'stepDurations', read: { window: 'all' } }
|
|
8742
|
+
const first = await measure(request)
|
|
8743
|
+
const count = (value: unknown) =>
|
|
8744
|
+
(value as { steps: { step: string; count: number }[] }).steps.find(
|
|
8745
|
+
(step) => step.step === 'plan',
|
|
8746
|
+
)?.count ?? 0
|
|
8747
|
+
expect(count(first.value)).toBe(n)
|
|
8748
|
+
const idle = await measure(request)
|
|
8749
|
+
expect(idle.value).toEqual(first.value)
|
|
8750
|
+
|
|
8751
|
+
tick()
|
|
8752
|
+
await planPair(store, slug(n / 2), 2, tick)
|
|
8753
|
+
const oneChange = await measure(request)
|
|
8754
|
+
expect(count(oneChange.value)).toBe(n + 1)
|
|
8755
|
+
|
|
8756
|
+
for (let i = 0; i < 5; i++) await planPair(store, slug(i * 7), 2, tick)
|
|
8757
|
+
const fiveChanges = await measure(request)
|
|
8758
|
+
expect(count(fiveChanges.value)).toBe(n + 6)
|
|
8759
|
+
|
|
8760
|
+
const secondKey = await measure({ ...request, args: { outcome: 'all' } })
|
|
8761
|
+
expect(count(secondKey.value)).toBe(n + 6)
|
|
8762
|
+
|
|
8763
|
+
// A fresh process carries no in-memory state: only the saved rows.
|
|
8764
|
+
Reflect.set(store, 'rollupLocks', new KeyedMutex())
|
|
8765
|
+
const fresh = await measure(request)
|
|
8766
|
+
expect(fresh.value).toEqual(fiveChanges.value)
|
|
8767
|
+
|
|
8768
|
+
// Idle across the retention boundary of the oldest day.
|
|
8769
|
+
clock.advance(402 * 86_400_000)
|
|
8770
|
+
const retention = await measure(request)
|
|
8771
|
+
expect(count(retention.value)).toBe(0)
|
|
8772
|
+
|
|
8773
|
+
// Each build's log is reduced once, ever, across every read above.
|
|
8774
|
+
const firstRows = new Map<string, number>()
|
|
8775
|
+
for (const read of reads)
|
|
8776
|
+
if (read.seq === 1) firstRows.set(read.slug, (firstRows.get(read.slug) ?? 0) + 1)
|
|
8777
|
+
expect(firstRows.size).toBe(n)
|
|
8778
|
+
expect([...firstRows.values()].every((times) => times === 1)).toBe(true)
|
|
8779
|
+
|
|
8780
|
+
for (const cost of [idle.cost, fresh.cost, retention.cost]) {
|
|
8781
|
+
expect(cost.rows).toBe(0)
|
|
8782
|
+
expect(cost.repoRows).toBe(0)
|
|
8783
|
+
expect(cost.feedFrom).toEqual([])
|
|
8784
|
+
expect(cost.calls.listBuildsChangedSince ?? 0).toBe(0)
|
|
8785
|
+
}
|
|
8786
|
+
expect(first.cost.feedFrom).toEqual(['0'])
|
|
8787
|
+
expect(oneChange.cost.rows).toBe(2)
|
|
8788
|
+
expect(oneChange.cost.feedFrom).toHaveLength(1)
|
|
8789
|
+
expect(fiveChanges.cost.rows).toBe(5 * oneChange.cost.rows)
|
|
8790
|
+
expect(fiveChanges.cost.feedFrom).toHaveLength(1)
|
|
8791
|
+
// The second key's first computation reuses every saved build value.
|
|
8792
|
+
expect(secondKey.cost.rows).toBe(0)
|
|
8793
|
+
expect(secondKey.cost.feedFrom).toEqual(['0'])
|
|
8794
|
+
results[n] = {
|
|
8795
|
+
first: first.cost,
|
|
8796
|
+
idle: idle.cost,
|
|
8797
|
+
oneChange: oneChange.cost,
|
|
8798
|
+
fiveChanges: fiveChanges.cost,
|
|
8799
|
+
secondKey: secondKey.cost,
|
|
8800
|
+
fresh: fresh.cost,
|
|
8801
|
+
retention: retention.cost,
|
|
8802
|
+
}
|
|
8803
|
+
}
|
|
8804
|
+
const flat = ({ calls, rows, repoRows, examined }: RollupReadCost) => ({
|
|
8805
|
+
calls,
|
|
8806
|
+
rows,
|
|
8807
|
+
repoRows,
|
|
8808
|
+
examined,
|
|
8809
|
+
})
|
|
8810
|
+
for (const axis of ['idle', 'oneChange', 'fiveChanges', 'fresh', 'retention'] as const)
|
|
8811
|
+
expect(flat(results[10_000]![axis])).toEqual(flat(results[100]![axis]))
|
|
8812
|
+
return results
|
|
8813
|
+
}
|
|
8814
|
+
|
|
8815
|
+
type ReducerValueRequestLike = import('../store/reducer-values').ReducerValueRequest
|
|
8816
|
+
|
|
8817
|
+
/**
|
|
8818
|
+
* The `buildRoster` rollup (SPEC §7.7) costs O(live builds + 50) from a fresh
|
|
8819
|
+
* process, not O(all builds): at 100 and at 100,000 builds (5 live, the rest
|
|
8820
|
+
* finished, the newest 50 completions identical at both sizes), an idle read
|
|
8821
|
+
* and a fresh process's read make no feed query and read zero event rows; one
|
|
8822
|
+
* completion and one new build read only their new rows through one feed
|
|
8823
|
+
* query; each build's log is reduced once, ever; and the saved accumulator
|
|
8824
|
+
* holds exactly 50 finished and 5 live entries, byte for byte the same size at
|
|
8825
|
+
* both sizes. Returns each size's measured costs.
|
|
8826
|
+
*/
|
|
8827
|
+
export async function buildRosterReadBudget(): Promise<
|
|
8828
|
+
Record<
|
|
8829
|
+
number,
|
|
8830
|
+
{
|
|
8831
|
+
first: RollupReadCost
|
|
8832
|
+
idle: RollupReadCost
|
|
8833
|
+
fresh: RollupReadCost
|
|
8834
|
+
oneCompletion: RollupReadCost
|
|
8835
|
+
newBuild: RollupReadCost
|
|
8836
|
+
accBytes: number
|
|
8837
|
+
}
|
|
8838
|
+
>
|
|
8839
|
+
> {
|
|
8840
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
8841
|
+
const { KeyedMutex, resolveRollupValue } = await import('../store/rollups')
|
|
8842
|
+
const { manualClock } = await import('./fixed')
|
|
8843
|
+
type Roster = import('../kernel/build-roster').BuildRosterValue
|
|
8844
|
+
type RosterAcc = import('../kernel/build-roster').BuildRosterAcc
|
|
8845
|
+
type Store = import('../store/memory').MemoryBuildStore
|
|
8846
|
+
const repo = 'roster-budget/repo'
|
|
8847
|
+
const scope = { kind: 'rollup', repo } as const
|
|
8848
|
+
const request = { reducer: 'buildRoster' }
|
|
8849
|
+
const end = Date.parse('2026-11-24T00:00:00.000Z')
|
|
8850
|
+
const minute = 60_000
|
|
8851
|
+
// Finished rank 0 is the newest completion, at `end`.
|
|
8852
|
+
const done = (rank: number) => `done-${String(rank).padStart(6, '0')}`
|
|
8853
|
+
const live = (i: number) => `live-${i}`
|
|
8854
|
+
// Seq 1 of every build, as `createBuild` writes it in production.
|
|
8855
|
+
const create = (store: Store, slug: string) =>
|
|
8856
|
+
store.createBuild({
|
|
8857
|
+
slug,
|
|
8858
|
+
repo,
|
|
8859
|
+
created: {
|
|
8860
|
+
actor: DISPATCHER,
|
|
8861
|
+
type: 'build.created',
|
|
8862
|
+
payload: { ticket: { source: 'file', id: slug, title: slug }, repo, baseBranch: 'main' },
|
|
8863
|
+
},
|
|
8864
|
+
})
|
|
8865
|
+
const results: Awaited<ReturnType<typeof buildRosterReadBudget>> = {}
|
|
8866
|
+
for (const n of [100, 100_000]) {
|
|
8867
|
+
const clock = manualClock(new Date(end).toISOString())
|
|
8868
|
+
const store = new MemoryBuildStore({ clock })
|
|
8869
|
+
const finished = n - 5
|
|
8870
|
+
for (let rank = finished - 1; rank >= 0; rank--) {
|
|
8871
|
+
clock.set(new Date(end - rank * minute).toISOString())
|
|
8872
|
+
await create(store, done(rank))
|
|
8873
|
+
// Every fourth build aborts; the rest merge.
|
|
8874
|
+
await (rank % 4 === 3
|
|
8875
|
+
? store.append(done(rank), { actor: KERNEL, type: 'build.aborted', payload: {} })
|
|
8876
|
+
: store.append(done(rank), {
|
|
8877
|
+
actor: DISPATCHER,
|
|
8878
|
+
type: 'build.completed',
|
|
8879
|
+
payload: { outcome: 'merged' },
|
|
8880
|
+
}))
|
|
8881
|
+
}
|
|
8882
|
+
for (let i = 0; i < 5; i++) {
|
|
8883
|
+
clock.advance(minute)
|
|
8884
|
+
await create(store, live(i))
|
|
8885
|
+
}
|
|
8886
|
+
const reads: { slug: string; seq: number }[] = []
|
|
8887
|
+
const measure = async () => {
|
|
8888
|
+
const { value, cost } = await measureRollupRead(store, scope, request, reads)
|
|
8889
|
+
return { value: value as Roster, cost }
|
|
8890
|
+
}
|
|
8891
|
+
const first = await measure()
|
|
8892
|
+
expect(first.value.live.map((entry) => entry.slug)).toEqual([0, 1, 2, 3, 4].map(live))
|
|
8893
|
+
expect(first.value.finished.map((entry) => entry.slug)).toEqual(
|
|
8894
|
+
Array.from({ length: 10 }, (_, rank) => done(rank)),
|
|
8895
|
+
)
|
|
8896
|
+
const idle = await measure()
|
|
8897
|
+
expect(idle.value).toEqual(first.value)
|
|
8898
|
+
|
|
8899
|
+
// A fresh process carries no in-memory state: only the saved rows.
|
|
8900
|
+
Reflect.set(store, 'rollupLocks', new KeyedMutex())
|
|
8901
|
+
const fresh = await measure()
|
|
8902
|
+
expect(fresh.value).toEqual(first.value)
|
|
8903
|
+
|
|
8904
|
+
clock.advance(minute)
|
|
8905
|
+
await store.append(live(2), {
|
|
8906
|
+
actor: DISPATCHER,
|
|
8907
|
+
type: 'build.completed',
|
|
8908
|
+
payload: { outcome: 'merged' },
|
|
8909
|
+
})
|
|
8910
|
+
const oneCompletion = await measure()
|
|
8911
|
+
expect(oneCompletion.value.finished[0]).toEqual({
|
|
8912
|
+
slug: live(2),
|
|
8913
|
+
kind: 'work',
|
|
8914
|
+
outcome: 'merged',
|
|
8915
|
+
completedAt: clock().toISOString(),
|
|
8916
|
+
})
|
|
8917
|
+
expect(oneCompletion.value.live).toHaveLength(4)
|
|
8918
|
+
|
|
8919
|
+
clock.advance(minute)
|
|
8920
|
+
await create(store, live(5))
|
|
8921
|
+
const newBuild = await measure()
|
|
8922
|
+
expect(newBuild.value.live.map((entry) => entry.slug)).toEqual([0, 1, 3, 4, 5].map(live))
|
|
8923
|
+
expect(newBuild.value.finished).toHaveLength(10)
|
|
8924
|
+
|
|
8925
|
+
// Each build's log is reduced once, ever, across every read above.
|
|
8926
|
+
const firstRows = new Map<string, number>()
|
|
8927
|
+
for (const read of reads)
|
|
8928
|
+
if (read.seq === 1) firstRows.set(read.slug, (firstRows.get(read.slug) ?? 0) + 1)
|
|
8929
|
+
expect(firstRows.size).toBe(n + 1)
|
|
8930
|
+
expect([...firstRows.values()].every((times) => times === 1)).toBe(true)
|
|
8931
|
+
|
|
8932
|
+
expect(first.cost.feedFrom).toEqual(['0'])
|
|
8933
|
+
for (const cost of [idle.cost, fresh.cost]) {
|
|
8934
|
+
expect(cost.rows).toBe(0)
|
|
8935
|
+
expect(cost.repoRows).toBe(0)
|
|
8936
|
+
expect(cost.feedFrom).toEqual([])
|
|
8937
|
+
expect(cost.calls.listBuildsChangedSince ?? 0).toBe(0)
|
|
8938
|
+
}
|
|
8939
|
+
expect(oneCompletion.cost.rows).toBe(1)
|
|
8940
|
+
expect(oneCompletion.cost.feedFrom).toHaveLength(1)
|
|
8941
|
+
expect(newBuild.cost.rows).toBe(1)
|
|
8942
|
+
expect(newBuild.cost.feedFrom).toHaveLength(1)
|
|
8943
|
+
|
|
8944
|
+
// The saved value is bounded by the live builds and the history cap.
|
|
8945
|
+
const { key } = resolveRollupValue(repo, request)
|
|
8946
|
+
const snapshots: Map<string, { state: { acc: RosterAcc } }> = Reflect.get(store, 'snapshots')
|
|
8947
|
+
const row = snapshots.get(`rollup:${repo}\u0000${key}`)!
|
|
8948
|
+
expect(row.state.acc.finished).toHaveLength(50)
|
|
8949
|
+
expect(Object.keys(row.state.acc.live)).toHaveLength(5)
|
|
8950
|
+
results[n] = {
|
|
8951
|
+
first: first.cost,
|
|
8952
|
+
idle: idle.cost,
|
|
8953
|
+
fresh: fresh.cost,
|
|
8954
|
+
oneCompletion: oneCompletion.cost,
|
|
8955
|
+
newBuild: newBuild.cost,
|
|
8956
|
+
accBytes: JSON.stringify(row.state.acc).length,
|
|
8957
|
+
}
|
|
8958
|
+
}
|
|
8959
|
+
const flat = ({ calls, rows, repoRows, examined }: RollupReadCost) => ({
|
|
8960
|
+
calls,
|
|
8961
|
+
rows,
|
|
8962
|
+
repoRows,
|
|
8963
|
+
examined,
|
|
8964
|
+
})
|
|
8965
|
+
const [small, large] = [results[100]!, results[100_000]!]
|
|
8966
|
+
for (const axis of ['idle', 'fresh', 'oneCompletion', 'newBuild'] as const)
|
|
8967
|
+
expect(flat(large[axis])).toEqual(flat(small[axis]))
|
|
8968
|
+
expect(large.accBytes).toBe(small.accBytes)
|
|
8969
|
+
return results
|
|
8970
|
+
}
|
|
8971
|
+
|
|
8972
|
+
/** Fresh remote clients get the server's canonical rollup in one request each
|
|
8973
|
+
* and never make the backing store read event rows after its first
|
|
8974
|
+
* computation. Callers instrument the backing store's event rows and count
|
|
8975
|
+
* the client's requests by path. */
|
|
8976
|
+
export async function rollupRemoteReadBudget(opts: {
|
|
8977
|
+
backing: BuildStore
|
|
8978
|
+
fresh: () => BuildStore
|
|
8979
|
+
repo: string
|
|
8980
|
+
reset: () => void
|
|
8981
|
+
eventRows: () => number
|
|
8982
|
+
requests: () => string[]
|
|
8983
|
+
/** The rollup read; defaults to every build's step durations. */
|
|
8984
|
+
request?: ReducerValueRequestLike
|
|
8985
|
+
}): Promise<void> {
|
|
8986
|
+
const scope = { kind: 'rollup', repo: opts.repo } as const
|
|
8987
|
+
const request = opts.request ?? {
|
|
8988
|
+
reducer: 'stepDurations',
|
|
8989
|
+
args: { outcome: 'all' },
|
|
8990
|
+
read: { window: 'all' },
|
|
8991
|
+
}
|
|
8992
|
+
const { catalogIdentity: _, ...expected } = await opts.backing.getReducerValue(scope, request)
|
|
8993
|
+
opts.reset()
|
|
8994
|
+
const before = opts.requests().length
|
|
8995
|
+
for (let i = 0; i < 3; i++) {
|
|
8996
|
+
const client = opts.fresh()
|
|
8997
|
+
const { catalogIdentity: __, ...answer } = await client.getReducerValue(scope, request)
|
|
8998
|
+
expect(answer).toEqual(expected)
|
|
8999
|
+
await client.close()
|
|
9000
|
+
}
|
|
9001
|
+
const made = opts.requests().slice(before)
|
|
9002
|
+
expect(made).toEqual(Array(3).fill(`/repos/${encodeURIComponent(opts.repo)}/rollup-values`))
|
|
9003
|
+
expect(opts.eventRows()).toBe(0)
|
|
9004
|
+
}
|
|
9005
|
+
|
|
9006
|
+
/** One measured analytics request: the store calls the source made, by
|
|
9007
|
+
* method, its build-scope reads by slug, its listing options, and the event
|
|
9008
|
+
* rows the store read to answer. */
|
|
9009
|
+
export interface WebAnalyticsReadCost {
|
|
9010
|
+
calls: Record<string, number>
|
|
9011
|
+
timelines: string[]
|
|
9012
|
+
listings: import('../store/build-feed').BuildPageOptions[]
|
|
9013
|
+
rows: number
|
|
9014
|
+
repoRows: number
|
|
9015
|
+
read: { slug: string; seq: number }[]
|
|
9016
|
+
}
|
|
9017
|
+
|
|
9018
|
+
/**
|
|
9019
|
+
* The web analytics source costs what changed (SPEC §14, RFC 0007 §9.3): at
|
|
9020
|
+
* 100 and at 10,000 builds, with the rollup and timelines already saved, a
|
|
9021
|
+
* request reads one rollup value, one filtered listing page and at most 25
|
|
9022
|
+
* saved timelines; a repeat reads only the change position; settled
|
|
9023
|
+
* timelines are served from memory; a UTC day rolling over re-reads the
|
|
9024
|
+
* rollup and the listing but no timeline; a live change re-reads exactly the
|
|
9025
|
+
* changed build; a repository-only change reads one feed query; and no
|
|
9026
|
+
* request reads an event row it did not need or any history. Returns each
|
|
9027
|
+
* size's measured costs.
|
|
9028
|
+
*/
|
|
9029
|
+
export async function webAnalyticsReadBudget(): Promise<
|
|
9030
|
+
Record<number, Record<string, WebAnalyticsReadCost>>
|
|
9031
|
+
> {
|
|
9032
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
9033
|
+
const { WebAnalyticsSource, GANTT_PAGE_SIZE } = await import('../web/analytics-source')
|
|
9034
|
+
const { agentActor } = await import('../events/envelope')
|
|
9035
|
+
const { manualClock } = await import('./fixed')
|
|
9036
|
+
type Store = import('../store/memory').MemoryBuildStore
|
|
9037
|
+
type Query = import('../web/protocol').WebAnalyticsQuery
|
|
9038
|
+
const repo = 'web-analytics-budget/repo'
|
|
9039
|
+
const defaults: Query = { window: '7d', outcome: 'merged', kind: 'leaf' }
|
|
9040
|
+
const everything: Query = { window: '7d', outcome: 'all', kind: 'all' }
|
|
9041
|
+
const MIN = 60_000
|
|
9042
|
+
|
|
9043
|
+
const seedBuild = async (
|
|
9044
|
+
store: Store,
|
|
9045
|
+
clock: ReturnType<typeof manualClock>,
|
|
9046
|
+
slug: string,
|
|
9047
|
+
opts: { kind?: 'node'; outcome?: 'merged' | 'closed-unmerged' },
|
|
9048
|
+
) => {
|
|
9049
|
+
await store.createBuild({
|
|
9050
|
+
slug,
|
|
9051
|
+
repo,
|
|
9052
|
+
ticket: { source: 'file', id: slug, title: `Build ${slug}` },
|
|
9053
|
+
created: {
|
|
9054
|
+
actor: DISPATCHER,
|
|
9055
|
+
type: 'build.created',
|
|
9056
|
+
payload: {
|
|
9057
|
+
ticket: { source: 'file', id: slug },
|
|
9058
|
+
repo,
|
|
9059
|
+
baseBranch: 'main',
|
|
9060
|
+
...(opts.kind !== undefined ? { kind: opts.kind } : {}),
|
|
9061
|
+
},
|
|
9062
|
+
},
|
|
9063
|
+
})
|
|
9064
|
+
await store.append(slug, { actor: KERNEL, type: 'plan.started', payload: { round: 1 } })
|
|
9065
|
+
clock.advance(MIN)
|
|
9066
|
+
if (opts.outcome === undefined) return
|
|
9067
|
+
await store.append(slug, {
|
|
9068
|
+
actor: agentActor('plan', 'session'),
|
|
9069
|
+
type: 'plan.completed',
|
|
9070
|
+
payload: { round: 1, artifact: { kind: 'plan', rev: 0 } },
|
|
9071
|
+
})
|
|
9072
|
+
await store.append(slug, {
|
|
9073
|
+
actor: DISPATCHER,
|
|
9074
|
+
type: 'build.completed',
|
|
9075
|
+
payload: { outcome: opts.outcome },
|
|
9076
|
+
})
|
|
9077
|
+
clock.advance(MIN)
|
|
9078
|
+
}
|
|
9079
|
+
|
|
9080
|
+
const results: Record<number, Record<string, WebAnalyticsReadCost>> = {}
|
|
9081
|
+
for (const n of [100, 10_000]) {
|
|
9082
|
+
const clock = manualClock('2026-10-01T00:00:00.000Z')
|
|
9083
|
+
const store = new MemoryBuildStore({ clock })
|
|
9084
|
+
await store.ensureRepo(repo)
|
|
9085
|
+
// Most builds are old, half of them unmerged: the default filters are rare.
|
|
9086
|
+
const old = n - 47
|
|
9087
|
+
for (let i = 0; i < old; i++)
|
|
9088
|
+
await seedBuild(store, clock, `old-${String(i).padStart(5, '0')}`, {
|
|
9089
|
+
outcome: i % 2 === 0 ? 'merged' : 'closed-unmerged',
|
|
9090
|
+
})
|
|
9091
|
+
// Four merged leaves whose plan closed on the window's first day.
|
|
9092
|
+
clock.set('2026-11-13T12:00:00.000Z')
|
|
9093
|
+
const edge = Array.from({ length: 4 }, (_, i) => `edge-${i}`)
|
|
9094
|
+
for (const slug of edge) await seedBuild(store, clock, slug, { outcome: 'merged' })
|
|
9095
|
+
// Thirty recent merged leaves, interleaved with merged nodes and closed leaves.
|
|
9096
|
+
clock.set('2026-11-20T10:00:00.000Z')
|
|
9097
|
+
const recent: string[] = []
|
|
9098
|
+
for (let i = 0; i < 30; i++) {
|
|
9099
|
+
const slug = `recent-${String(i).padStart(2, '0')}`
|
|
9100
|
+
recent.push(slug)
|
|
9101
|
+
await seedBuild(store, clock, slug, { outcome: 'merged' })
|
|
9102
|
+
if (i % 6 === 0) {
|
|
9103
|
+
await seedBuild(store, clock, `node-${i}`, { kind: 'node', outcome: 'merged' })
|
|
9104
|
+
await seedBuild(store, clock, `closed-${i}`, { outcome: 'closed-unmerged' })
|
|
9105
|
+
}
|
|
9106
|
+
}
|
|
9107
|
+
// Three live builds, created last.
|
|
9108
|
+
const live = ['live-0', 'live-1', 'live-2']
|
|
9109
|
+
for (const slug of live) await seedBuild(store, clock, slug, {})
|
|
9110
|
+
clock.set('2026-11-20T23:30:00.000Z')
|
|
9111
|
+
// The canonical values exist before any request: every key the budget
|
|
9112
|
+
// asks for, and through them every build's saved timeline.
|
|
9113
|
+
for (const args of [
|
|
9114
|
+
{ outcome: 'merged', kind: 'leaf' },
|
|
9115
|
+
{ outcome: 'merged', kind: 'node' },
|
|
9116
|
+
{ outcome: 'all', kind: 'all' },
|
|
9117
|
+
])
|
|
9118
|
+
await store.getReducerValue({ kind: 'rollup', repo }, { reducer: 'stepDurations', args })
|
|
9119
|
+
|
|
9120
|
+
const calls: { name: string; args: unknown[] }[] = []
|
|
9121
|
+
const reader = new Proxy(store, {
|
|
9122
|
+
get(target, key, receiver) {
|
|
9123
|
+
const value = Reflect.get(target, key, receiver)
|
|
9124
|
+
if (typeof value !== 'function') return value
|
|
9125
|
+
return (...args: unknown[]) => {
|
|
9126
|
+
calls.push({ name: String(key), args })
|
|
9127
|
+
return Reflect.apply(value, target, args)
|
|
9128
|
+
}
|
|
9129
|
+
},
|
|
9130
|
+
})
|
|
9131
|
+
const source = new WebAnalyticsSource(reader, repo, { clock: () => clock().getTime() })
|
|
9132
|
+
const measure = async <T>(run: () => Promise<T>): Promise<[T, WebAnalyticsReadCost]> => {
|
|
9133
|
+
calls.length = 0
|
|
9134
|
+
let answer!: T
|
|
9135
|
+
const metrics = await measureStoreReads(store, async () => {
|
|
9136
|
+
answer = await run()
|
|
9137
|
+
})
|
|
9138
|
+
const cost: WebAnalyticsReadCost = {
|
|
9139
|
+
calls: {},
|
|
9140
|
+
timelines: [],
|
|
9141
|
+
listings: [],
|
|
9142
|
+
rows: metrics.rows,
|
|
9143
|
+
repoRows: metrics.repoRows,
|
|
9144
|
+
read: metrics.read,
|
|
9145
|
+
}
|
|
9146
|
+
for (const call of calls) {
|
|
9147
|
+
cost.calls[call.name] = (cost.calls[call.name] ?? 0) + 1
|
|
9148
|
+
const scope = call.args[0] as { kind?: string; slug?: string }
|
|
9149
|
+
if (call.name === 'getReducerValue' && scope.kind === 'build')
|
|
9150
|
+
cost.timelines.push(scope.slug!)
|
|
9151
|
+
if (call.name === 'listBuildsPage')
|
|
9152
|
+
cost.listings.push(call.args[1] as import('../store/build-feed').BuildPageOptions)
|
|
9153
|
+
}
|
|
9154
|
+
return [answer, cost]
|
|
9155
|
+
}
|
|
9156
|
+
const slugs = (answer: import('../web/protocol').WebAnalytics) =>
|
|
9157
|
+
answer.gantt.rows.map((row) => row.slug)
|
|
9158
|
+
const count = (answer: import('../web/protocol').WebAnalytics) =>
|
|
9159
|
+
answer.durations.find((step) => step.step === 'plan')?.count ?? 0
|
|
9160
|
+
const costs: Record<string, WebAnalyticsReadCost> = {}
|
|
9161
|
+
|
|
9162
|
+
// (a) A fresh source's first request.
|
|
9163
|
+
const [first, firstCost] = await measure(() => source.analytics(defaults))
|
|
9164
|
+
expect(firstCost.calls).toEqual({
|
|
9165
|
+
getRepoChangePosition: 1,
|
|
9166
|
+
getReducerValue: 1 + GANTT_PAGE_SIZE,
|
|
9167
|
+
listBuildsPage: 1,
|
|
9168
|
+
})
|
|
9169
|
+
expect(firstCost.listings).toEqual([
|
|
9170
|
+
{
|
|
9171
|
+
limit: 25,
|
|
9172
|
+
activeSince: '2026-11-13T00:00:00.000Z',
|
|
9173
|
+
outcome: 'merged',
|
|
9174
|
+
kind: 'leaf',
|
|
9175
|
+
},
|
|
9176
|
+
])
|
|
9177
|
+
expect(slugs(first)).toEqual([...recent].reverse().slice(0, 25))
|
|
9178
|
+
expect(first.windowStart).toBe('2026-11-13T00:00:00.000Z')
|
|
9179
|
+
expect(count(first)).toBe(recent.length + edge.length)
|
|
9180
|
+
costs.first = firstCost
|
|
9181
|
+
|
|
9182
|
+
// (a′) Other filters: one listing each, a full page when 25 match.
|
|
9183
|
+
const [nodes, nodeCost] = await measure(() => source.analytics({ ...defaults, kind: 'node' }))
|
|
9184
|
+
expect(nodeCost.calls.listBuildsPage).toBe(1)
|
|
9185
|
+
expect(nodes.gantt.rows.every((row) => row.kind === 'node')).toBe(true)
|
|
9186
|
+
expect(nodes.gantt.rows).toHaveLength(5)
|
|
9187
|
+
expect(nodeCost.listings[0]).toEqual({
|
|
9188
|
+
limit: 25,
|
|
9189
|
+
activeSince: '2026-11-13T00:00:00.000Z',
|
|
9190
|
+
outcome: 'merged',
|
|
9191
|
+
kind: 'node',
|
|
9192
|
+
})
|
|
9193
|
+
const [all, allCost] = await measure(() => source.analytics(everything))
|
|
9194
|
+
expect(allCost.calls.listBuildsPage).toBe(1)
|
|
9195
|
+
expect(allCost.timelines.length).toBeLessThanOrEqual(GANTT_PAGE_SIZE)
|
|
9196
|
+
expect(all.gantt.rows).toHaveLength(GANTT_PAGE_SIZE)
|
|
9197
|
+
expect(slugs(all).slice(0, 3)).toEqual([...live].reverse())
|
|
9198
|
+
expect(allCost.listings[0]).toEqual({ limit: 25, activeSince: '2026-11-13T00:00:00.000Z' })
|
|
9199
|
+
costs.node = nodeCost
|
|
9200
|
+
costs.all = allCost
|
|
9201
|
+
|
|
9202
|
+
// (b) The same request again: only the change position.
|
|
9203
|
+
const [, repeat] = await measure(() => source.analytics(defaults))
|
|
9204
|
+
expect(repeat.calls).toEqual({ getRepoChangePosition: 1 })
|
|
9205
|
+
costs.repeat = repeat
|
|
9206
|
+
|
|
9207
|
+
// (c) Page 2 reads its own timelines once; a repeat reads none.
|
|
9208
|
+
const [page2, page2Cost] = await measure(() =>
|
|
9209
|
+
source.analytics({ ...defaults, page: first.gantt.next! }),
|
|
9210
|
+
)
|
|
9211
|
+
expect(slugs(page2)).toEqual([...[...recent].reverse().slice(25), ...[...edge].reverse()])
|
|
9212
|
+
expect(page2Cost.timelines.sort()).toEqual(slugs(page2).sort())
|
|
9213
|
+
const [, page2Again] = await measure(() =>
|
|
9214
|
+
source.analytics({ ...defaults, page: first.gantt.next! }),
|
|
9215
|
+
)
|
|
9216
|
+
expect(page2Again.timelines).toEqual([])
|
|
9217
|
+
costs.page2 = page2Cost
|
|
9218
|
+
costs.page2Again = page2Again
|
|
9219
|
+
|
|
9220
|
+
// (d) Another window: one rollup and one listing, no timeline read.
|
|
9221
|
+
const [, wider] = await measure(() => source.analytics({ ...defaults, window: '30d' }))
|
|
9222
|
+
expect(wider.calls).toEqual({
|
|
9223
|
+
getRepoChangePosition: 1,
|
|
9224
|
+
getReducerValue: 1,
|
|
9225
|
+
listBuildsPage: 1,
|
|
9226
|
+
})
|
|
9227
|
+
costs.wider = wider
|
|
9228
|
+
|
|
9229
|
+
// (d′) A UTC midnight with no write moves the window.
|
|
9230
|
+
clock.set('2026-11-21T00:30:00.000Z')
|
|
9231
|
+
const [nextDay, nextDayCost] = await measure(() => source.analytics(defaults))
|
|
9232
|
+
expect(nextDayCost.calls).toEqual({
|
|
9233
|
+
getRepoChangePosition: 1,
|
|
9234
|
+
getReducerValue: 1,
|
|
9235
|
+
listBuildsPage: 1,
|
|
9236
|
+
})
|
|
9237
|
+
expect(nextDay.windowStart).toBe('2026-11-14T00:00:00.000Z')
|
|
9238
|
+
expect(count(nextDay)).toBe(recent.length)
|
|
9239
|
+
const [, sameDay] = await measure(() => source.analytics(defaults))
|
|
9240
|
+
expect(sameDay.calls).toEqual({ getRepoChangePosition: 1 })
|
|
9241
|
+
costs.nextDay = nextDayCost
|
|
9242
|
+
costs.sameDay = sameDay
|
|
9243
|
+
|
|
9244
|
+
// (e) A live build gains an event: one feed query, that build re-read.
|
|
9245
|
+
await source.analytics(everything)
|
|
9246
|
+
clock.advance(MIN)
|
|
9247
|
+
await store.append(live[2]!, {
|
|
9248
|
+
actor: agentActor('plan', 'session'),
|
|
9249
|
+
type: 'plan.completed',
|
|
9250
|
+
payload: { round: 1, artifact: { kind: 'plan', rev: 0 } },
|
|
9251
|
+
})
|
|
9252
|
+
const [changed, changedCost] = await measure(() => source.analytics(everything))
|
|
9253
|
+
expect(changedCost.calls.listBuildsChangedSince).toBe(1)
|
|
9254
|
+
expect(changedCost.timelines).toEqual([live[2]!])
|
|
9255
|
+
expect(changedCost.read.every((row) => row.slug === live[2])).toBe(true)
|
|
9256
|
+
expect(changed.gantt.rows[0]!.segments.find((s) => s.category === 'plan')?.state).toBe('closed')
|
|
9257
|
+
costs.changed = changedCost
|
|
9258
|
+
|
|
9259
|
+
// (f) A repository event alone: one feed query, nothing re-read.
|
|
9260
|
+
await store.appendRepo(repo, {
|
|
9261
|
+
actor: humanActor('budget'),
|
|
9262
|
+
type: 'dispatcher.pause-set',
|
|
9263
|
+
payload: { enabled: false },
|
|
9264
|
+
})
|
|
9265
|
+
const [, repository] = await measure(() => source.analytics(everything))
|
|
9266
|
+
expect(repository.calls).toEqual({ getRepoChangePosition: 1, listBuildsChangedSince: 1 })
|
|
9267
|
+
costs.repository = repository
|
|
9268
|
+
|
|
9269
|
+
// (g) A cached build's timeline: only the change position.
|
|
9270
|
+
const [row, cached] = await measure(() => source.timeline(recent[0]!))
|
|
9271
|
+
expect(row?.slug).toBe(recent[0])
|
|
9272
|
+
expect(cached.calls).toEqual({ getRepoChangePosition: 1 })
|
|
9273
|
+
costs.timeline = cached
|
|
9274
|
+
|
|
9275
|
+
for (const [name, cost] of Object.entries(costs)) {
|
|
9276
|
+
if (name !== 'changed') expect(cost.rows).toBe(0)
|
|
9277
|
+
expect(cost.repoRows).toBe(0)
|
|
9278
|
+
for (const call of Object.keys(cost.calls))
|
|
9279
|
+
expect([
|
|
9280
|
+
'getRepoChangePosition',
|
|
9281
|
+
'listBuildsChangedSince',
|
|
9282
|
+
'listBuildsPage',
|
|
9283
|
+
'getReducerValue',
|
|
9284
|
+
'getBuild',
|
|
9285
|
+
]).toContain(call)
|
|
9286
|
+
}
|
|
9287
|
+
results[n] = costs
|
|
9288
|
+
}
|
|
9289
|
+
const flat = ({ calls, timelines, rows, repoRows }: WebAnalyticsReadCost) => ({
|
|
9290
|
+
calls,
|
|
9291
|
+
timelines,
|
|
9292
|
+
rows,
|
|
9293
|
+
repoRows,
|
|
9294
|
+
})
|
|
9295
|
+
for (const name of Object.keys(results[100]!))
|
|
9296
|
+
expect(flat(results[10_000]![name]!)).toEqual(flat(results[100]![name]!))
|
|
9297
|
+
return results
|
|
9298
|
+
}
|
|
9299
|
+
|
|
9300
|
+
/** A leaf whose rejected base an operator's accept-target waived
|
|
9301
|
+
* (`target.rewrite-recovered` with `accepted`): repeated idle observations of
|
|
9302
|
+
* the unchanged accepted target, by the dispatcher and by a runner enforcing
|
|
9303
|
+
* its used baseline, append nothing and read zero event rows at 100 and
|
|
9304
|
+
* 100,000 events. The waiver comes from the reduced value already read. */
|
|
9305
|
+
export async function waivedTargetObservationReadBudget(): Promise<void> {
|
|
9306
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
9307
|
+
const { steppingClock } = await import('./fixed')
|
|
9308
|
+
const store = new MemoryBuildStore({ clock: steppingClock() })
|
|
9309
|
+
const waivedSlug = 'waived-target'
|
|
9310
|
+
const old = 'a'.repeat(40)
|
|
9311
|
+
const rewritten = 'b'.repeat(40)
|
|
9312
|
+
const forge = new FakeForge()
|
|
9313
|
+
forge.seedCommit(old)
|
|
9314
|
+
forge.seedCommit(rewritten)
|
|
9315
|
+
await store.createBuild({ slug: waivedSlug, repo })
|
|
9316
|
+
await store.append(waivedSlug, {
|
|
9317
|
+
actor: KERNEL,
|
|
9318
|
+
type: 'workspace.provisioned',
|
|
9319
|
+
payload: { provider: 'fake', ref: '/ws', branch: 'ab/w', base: { source: 'remote', sha: old } },
|
|
9320
|
+
})
|
|
9321
|
+
await store.append(waivedSlug, {
|
|
9322
|
+
actor: KERNEL,
|
|
9323
|
+
type: 'target.rewritten',
|
|
9324
|
+
payload: { branch: 'main', previousSha: old, sha: rewritten },
|
|
9325
|
+
})
|
|
9326
|
+
await store.append(waivedSlug, {
|
|
9327
|
+
actor: KERNEL,
|
|
9328
|
+
type: 'target.rewrite-recovered',
|
|
9329
|
+
payload: {
|
|
9330
|
+
branch: 'main',
|
|
9331
|
+
previousSha: old,
|
|
9332
|
+
sha: rewritten,
|
|
9333
|
+
base: old,
|
|
9334
|
+
recovery: 'accepted',
|
|
9335
|
+
escalation: 'esc-1',
|
|
9336
|
+
},
|
|
9337
|
+
})
|
|
9338
|
+
for (const length of [100, 100_000]) {
|
|
9339
|
+
await seedBuildFiller(store, waivedSlug, length)
|
|
9340
|
+
const metrics = { historicalRows: 0, tailRows: 0 }
|
|
9341
|
+
const boundary = buildEventRows(store, waivedSlug).at(-1)!.seq
|
|
9342
|
+
// Warm the reduced value over the new tail once.
|
|
9343
|
+
await readBuildFacts(store, waivedSlug)
|
|
9344
|
+
const undo = instrumentBuildRows(store, waivedSlug, () => boundary, metrics)
|
|
9345
|
+
try {
|
|
9346
|
+
for (const enforceUsedBaseline of [false, true, false, true]) {
|
|
9347
|
+
const requests = await countStoreRequests(store, async () => {
|
|
9348
|
+
expect(
|
|
9349
|
+
await observeTarget({
|
|
9350
|
+
store,
|
|
9351
|
+
forge,
|
|
9352
|
+
slug: waivedSlug,
|
|
9353
|
+
branch: 'main',
|
|
9354
|
+
sha: rewritten,
|
|
9355
|
+
enforceUsedBaseline,
|
|
9356
|
+
actor: KERNEL,
|
|
9357
|
+
}),
|
|
9358
|
+
).toBe('unchanged')
|
|
9359
|
+
})
|
|
9360
|
+
expect(requests.appendIfCurrent ?? 0).toBe(0)
|
|
9361
|
+
}
|
|
9362
|
+
} finally {
|
|
9363
|
+
undo()
|
|
9364
|
+
}
|
|
9365
|
+
expect(metrics).toEqual({ historicalRows: 0, tailRows: 0 })
|
|
9366
|
+
}
|
|
9367
|
+
}
|