@defrex/autobuild 1.9.0 → 1.10.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 +3 -3
- package/SPEC.md +1512 -125
- package/bin/ab-dispatch-generation.ts +2 -0
- package/docs/agent-runtimes.md +30 -3
- package/docs/answering-blocked-builds.md +15 -7
- package/docs/architecture.md +282 -39
- package/docs/builds.md +5 -0
- package/docs/cli.md +7 -1
- package/docs/configuration-overview.md +1 -0
- package/docs/configuration.md +268 -45
- package/docs/dispatcher.md +17 -3
- package/docs/forges.md +1 -1
- package/docs/getting-started.md +1 -1
- package/docs/integration-overview.md +4 -2
- package/docs/integration-tree.md +102 -11
- package/docs/merge-policy.md +30 -14
- package/docs/migration-1.0.md +2 -1
- package/docs/operating.md +32 -4
- package/docs/operator-api.md +117 -14
- package/docs/optimization-nodes.md +1042 -0
- package/docs/overview.md +1 -1
- package/docs/plugin-authoring.md +46 -12
- package/docs/remote-store-protocol.md +46 -7
- package/docs/remote-ticket-protocol.md +50 -2
- package/docs/restacking.md +99 -11
- package/docs/seams.md +2 -2
- package/docs/setup.md +13 -2
- package/docs/skills.md +4 -2
- package/docs/spec-standard.md +2 -1
- package/docs/ticket-dependencies.md +5 -0
- package/docs/ticket-migration.md +4 -2
- package/docs/ticket-sources.md +30 -12
- package/docs/tickets.md +15 -6
- package/docs/troubleshooting.md +3 -2
- package/docs/verification.md +11 -0
- package/docs/workspaces.md +3 -1
- package/package.json +3 -3
- package/packages/core/src/accounts/chatgpt-oauth.ts +7 -5
- package/packages/core/src/cli/attempt.ts +103 -0
- package/packages/core/src/cli/attention.ts +8 -1
- package/packages/core/src/cli/binary-direct.ts +52 -1
- package/packages/core/src/cli/binary.ts +5 -3
- package/packages/core/src/cli/build-control.ts +328 -66
- package/packages/core/src/cli/context.ts +268 -15
- package/packages/core/src/cli/dashboard/detail.ts +26 -2
- package/packages/core/src/cli/dashboard/facts.ts +40 -3
- package/packages/core/src/cli/dashboard/integration-detail.ts +7 -2
- package/packages/core/src/cli/dashboard/landing-display.ts +15 -2
- package/packages/core/src/cli/dashboard/model.ts +102 -27
- package/packages/core/src/cli/dashboard/objective-row.ts +189 -0
- package/packages/core/src/cli/dashboard/render.ts +47 -1
- package/packages/core/src/cli/dashboard/reopen-display.ts +39 -0
- package/packages/core/src/cli/dashboard/tree.ts +12 -1
- package/packages/core/src/cli/dispatch-frontend.ts +9 -1
- package/packages/core/src/cli/dispatch-launch-stop.ts +55 -0
- package/packages/core/src/cli/dispatch-launcher.ts +26 -44
- package/packages/core/src/cli/dispatch-repository-feed.ts +1 -1
- package/packages/core/src/cli/dispatch.ts +16 -4
- package/packages/core/src/cli/env.ts +42 -0
- package/packages/core/src/cli/help.ts +208 -11
- package/packages/core/src/cli/init-agent.ts +4 -1
- package/packages/core/src/cli/init-readiness-remote.ts +3 -2
- package/packages/core/src/cli/init-validation.ts +2 -2
- package/packages/core/src/cli/init.ts +3 -2
- package/packages/core/src/cli/judge-entry.ts +82 -0
- package/packages/core/src/cli/judge.ts +233 -0
- package/packages/core/src/cli/landings.ts +3 -2
- package/packages/core/src/cli/main.ts +412 -143
- package/packages/core/src/cli/measurement-text.ts +19 -0
- package/packages/core/src/cli/objective.ts +154 -0
- package/packages/core/src/cli/publication-settlement.ts +106 -22
- package/packages/core/src/cli/repo-lease.ts +1 -0
- package/packages/core/src/cli/repository-status.ts +113 -18
- package/packages/core/src/cli/status.ts +193 -15
- package/packages/core/src/cli/store-opening.ts +4 -0
- package/packages/core/src/cli/terminals.ts +205 -8
- package/packages/core/src/cli/ticket-start.ts +53 -0
- package/packages/core/src/cli/ticket.ts +68 -2
- package/packages/core/src/cli/upgrade-agent.ts +12 -8
- package/packages/core/src/cli/wait.ts +8 -2
- package/packages/core/src/cli/watch.ts +341 -91
- package/packages/core/src/config/create-labels.ts +23 -0
- package/packages/core/src/config/live.ts +2 -0
- package/packages/core/src/config/pipeline-source.ts +1 -3
- package/packages/core/src/config/roles.ts +182 -73
- package/packages/core/src/config/schema.ts +112 -9
- package/packages/core/src/events/catalog.ts +39 -3
- package/packages/core/src/events/compatibility.ts +7 -1
- package/packages/core/src/events/payloads.ts +588 -1
- package/packages/core/src/events/policy.ts +53 -0
- package/packages/core/src/events/repository.ts +107 -24
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +1481 -199
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/0ab2a90d0305dc9d.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/10a4657408d4e121.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/1152a2e97ee81728.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/13ca84752c5f8b54.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/1411d1cdbdd9911e.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/1444fe1fa7fc802c.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/1491ac0600349391.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/1921f86f752428c9.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/1972c1d66008ef6b.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/19e8e43e7f3f1a06.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/20a85c143c3e8164.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/21ce2c0bf58318e1.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/293dcb3a94fb3470.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/2ab7436356267118.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/2d084641735caaff.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/3237bcecf68e5db9.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/33d0cc593610e56f.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/3451ed2136dcc356.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/358ec8693f2237e6.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/35cf9ccc4478b2d2.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/3649e7bd1203f154.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/378da6dece82202a.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/38c75099d9191471.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/398952f1f01db1a3.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/3b64d352d56c9121.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/3dc486226c05372d.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/431c9bb2ee8838e0.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/4400dffca929e2f0.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/49064fc079964a5c.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/4edded75f17742f4.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/4f00c0f2c8afd159.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/516a5a7aadf97587.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/516dc6ea85d67cd7.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/584e2ba74608e051.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/59ffaa6974094c72.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/5bb43afb121674c6.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/5f0ca42af862c4ee.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/6118031132db9bfc.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/63107a8d58776b63.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/63546b08d4d6fa11.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/643d70429ce03dad.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/677ea92572c29082.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/6ae5bf60504d6467.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/6efdc8defc75fccb.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/71c53d33f09d8204.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/7267ca2757cffba7.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/76b7d4244082b3f9.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/7749f918c6f10968.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/7833e42d16301424.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/7d4edad0614adaf1.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/837365898d04f45a.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/85f9f0c921b8b5bb.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/8879f57a24733897.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/88cb9e71bdec972d.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/8a0cd6dd06cc155e.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/8aa9ca8609dc051d.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/8c8640255bd61658.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/8cc15eb1807c0157.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/8ced97c44bc0af3a.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/8d4144004720b9f8.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/8db633ead1807f8b.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/8e42cdbd0994ab0c.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/9011d0f6ff955ef9.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/916ebc5433801c41.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/9539b995af5c54a9.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/95f391bfd7b7dbd7.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/9613e8fa568a9281.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/9a68f8753bd9038d.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/9b25e58227080094.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/9ee3919fbd4f9458.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/a04a34cc2717147b.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/a0b32c12e4e6edb6.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/a55218252707bdd3.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/a732fd08b31522a6.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/a9d206a01f9039e5.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/abf7fe3c92c82f2d.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/ac928b04842c00db.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/af953392d81911da.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/b0d877c44810ecb0.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/b0f7c6ebb2db57fc.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/b905c22ec17eed31.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/bce0c54e865f4b79.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/c68b7ee2e2610f30.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/c7f7e0378aeea237.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/c98cb1659eb142b6.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/ca830adf06ed55a1.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/cb3a219f33e437ca.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/cf1e0c0d82567e0c.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/d008d86d9ff77b30.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/d1432a819d8e48c5.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/d185ed6aa9192aff.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/d873fad29d6c7e55.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/db84b12316e2da4a.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/ddf6dc967d898767.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/dfc64de6e7bfc0a0.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/e2f18fa32fe1f6d0.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/e37393fed29e84c5.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/e6a8585e2a054ff6.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/e7e9e327baca6903.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/e86447af0571672c.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/ea819202d22122e5.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/eb4535585f2e84f6.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/eb7ddd5319d09e27.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/eca4959b2b87ae15.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/ee10d7959ec4843c.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/ef1b68347966ab26.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/f3e55425cc41f230.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/f40042c1cdb9fd43.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/f48466215c790a3f.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/f5b9ace9b59351e7.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/fa8f1475a55be935.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/fb21116a15d0b1f1.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/fe95444fbeabe592.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/09bf0a1611d07363.json +984 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/10eac4988d66e161.json +1067 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/1a436b5fb45aee3e.json +1116 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/249db6f7a41f90e2.json +161 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/25dcb2fb6eaa83f4.json +858 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/2e1bdc763924616f.json +4932 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/30e9dabce3c4263d.json +399 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/4898ef339c68fa36.json +83 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/51816c0ffa62af6e.json +417 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/561bf45320062a44.json +83 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/5672d0233085d050.json +84 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/5e39f42cbdbf35ef.json +163 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/7771a7a2250f9964.json +868 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/881c491321bec99a.json +1074 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/965f25c3af1d2cdc.json +160 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/9b76d89da575ca90.json +20 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/9eb485320a72a9ff.json +233 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a60448c01016135e.json +18 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a6584fb61b6679bd.json +97 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/c88365c25b3186d3.json +543 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/e8f0481b23f90056.json +711 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/ee55782ed40ebbac.json +110 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/fc5082fac8167f3d.json +98 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/fd55c329cfe921cc.json +1069 -0
- package/packages/core/src/kernel/attempt-creation-key.ts +20 -0
- package/packages/core/src/kernel/attempt-settlement.ts +125 -0
- package/packages/core/src/kernel/auto-merge-default.ts +1 -3
- package/packages/core/src/kernel/auto-merge.ts +1 -3
- package/packages/core/src/kernel/dispatch-capacity.ts +312 -38
- package/packages/core/src/kernel/dispatch-placement.ts +1 -1
- package/packages/core/src/kernel/dispatch-settings.ts +1 -4
- package/packages/core/src/kernel/dispatch-status.ts +3 -5
- package/packages/core/src/kernel/dispatch-upgrade.ts +1 -1
- package/packages/core/src/kernel/engine.ts +109 -13
- package/packages/core/src/kernel/forge-checks.ts +140 -0
- package/packages/core/src/kernel/forge-health.ts +2 -2
- package/packages/core/src/kernel/generated-files.ts +43 -0
- package/packages/core/src/kernel/generated-regeneration.ts +254 -0
- package/packages/core/src/kernel/generators/build-log.ts +30 -2
- package/packages/core/src/kernel/generators/optimization-log.ts +578 -0
- package/packages/core/src/kernel/generators/panel-log.ts +133 -0
- package/packages/core/src/kernel/guarded-forge.ts +76 -11
- package/packages/core/src/kernel/harvest.ts +1 -4
- package/packages/core/src/kernel/head-paths.ts +4 -1
- package/packages/core/src/kernel/history-retention.ts +337 -0
- package/packages/core/src/kernel/incremental-fixtures.ts +6 -0
- package/packages/core/src/kernel/incremental.ts +14 -4
- package/packages/core/src/kernel/integration-landing.ts +64 -13
- package/packages/core/src/kernel/integration-stack.ts +123 -20
- package/packages/core/src/kernel/integration-state.ts +39 -2
- package/packages/core/src/kernel/janitor-failure.ts +2 -0
- package/packages/core/src/kernel/kernel-git.ts +1 -1
- package/packages/core/src/kernel/landing-measurement.ts +275 -0
- package/packages/core/src/kernel/landing-readiness.ts +2 -0
- package/packages/core/src/kernel/landing-state.ts +20 -1
- package/packages/core/src/kernel/leaf-restack-state.ts +17 -1
- package/packages/core/src/kernel/log-index-value.ts +2 -0
- package/packages/core/src/kernel/log-index.ts +81 -3
- package/packages/core/src/kernel/measurement.ts +406 -0
- package/packages/core/src/kernel/mixed-version.ts +6 -3
- package/packages/core/src/kernel/node-landing.ts +92 -18
- package/packages/core/src/kernel/node-restack-state.ts +27 -1
- package/packages/core/src/kernel/node-restack-transaction.ts +80 -23
- package/packages/core/src/kernel/node-verification-context.ts +14 -4
- package/packages/core/src/kernel/open-pr-backpressure-state.ts +24 -0
- package/packages/core/src/kernel/open-pr-backpressure.ts +133 -0
- package/packages/core/src/kernel/optimization-admission.ts +249 -0
- package/packages/core/src/kernel/optimization.ts +774 -0
- package/packages/core/src/kernel/panel.ts +225 -0
- package/packages/core/src/kernel/phases.ts +42 -6
- package/packages/core/src/kernel/pr-attachments.ts +4 -16
- package/packages/core/src/kernel/pr-summary.ts +2 -2
- package/packages/core/src/kernel/read-deferrals.ts +2 -2
- package/packages/core/src/kernel/read-facts.ts +69 -31
- package/packages/core/src/kernel/reconcile-restack.ts +352 -103
- package/packages/core/src/kernel/reducer-identity.ts +659 -0
- package/packages/core/src/kernel/reducer-registry.ts +37 -3
- package/packages/core/src/kernel/reducer-revisions.ts +50 -0
- package/packages/core/src/kernel/reducer.ts +208 -9
- package/packages/core/src/kernel/reopen-state.ts +48 -0
- package/packages/core/src/kernel/reopen.ts +143 -0
- package/packages/core/src/kernel/replay-retention.ts +208 -39
- package/packages/core/src/kernel/repository-attention.ts +1 -1
- package/packages/core/src/kernel/service-facts.ts +19 -7
- package/packages/core/src/kernel/terminal-guard.ts +13 -5
- package/packages/core/src/kernel/ticket-handbacks.ts +1 -1
- package/packages/core/src/kernel/ticket-migrations.ts +1 -1
- package/packages/core/src/kernel/ticket-preparation.ts +1 -1
- package/packages/core/src/kernel/ticket-source-health.ts +1 -1
- package/packages/core/src/kernel/ticket-starts.ts +118 -0
- package/packages/core/src/kernel/ticket-wait.ts +37 -2
- package/packages/core/src/kernel/verify-diff-base.ts +62 -0
- package/packages/core/src/kernel/verify-stage-state.ts +1 -0
- package/packages/core/src/kernel/verify-stages.ts +41 -1
- package/packages/core/src/objective.ts +532 -0
- package/packages/core/src/ontology.ts +49 -6
- package/packages/core/src/operator/annotations.ts +35 -4
- package/packages/core/src/operator/control.ts +2 -1
- package/packages/core/src/operator/index.ts +12 -0
- package/packages/core/src/operator/optimization.ts +307 -0
- package/packages/core/src/operator/protocol.ts +30 -1
- package/packages/core/src/operator/query.ts +15 -1
- package/packages/core/src/operator/registry.ts +219 -13
- package/packages/core/src/operator/requests.ts +25 -2
- package/packages/core/src/operator/ticket-start.ts +152 -0
- package/packages/core/src/operator/tickets.ts +3 -2
- package/packages/core/src/plugin-sdk/index.ts +2 -0
- package/packages/core/src/plugins/registry.ts +1 -0
- package/packages/core/src/ports/forge/contract.ts +9 -0
- package/packages/core/src/ports/forge/fake.ts +23 -2
- package/packages/core/src/ports/forge/git-rewrite.ts +6 -4
- package/packages/core/src/ports/forge/github-readiness.ts +1 -1
- package/packages/core/src/ports/forge/github-transport.ts +156 -1
- package/packages/core/src/ports/forge/github.ts +306 -100
- package/packages/core/src/ports/forge/readiness.ts +15 -3
- package/packages/core/src/ports/forge-failure.ts +22 -0
- package/packages/core/src/ports/forge-request-context.ts +23 -1
- package/packages/core/src/ports/forge-telemetry.ts +16 -0
- package/packages/core/src/ports/runner/antigravity.ts +1071 -0
- package/packages/core/src/ports/runner/claude.ts +6 -1
- package/packages/core/src/ports/runner/codex.ts +11 -2
- package/packages/core/src/ports/runner/contract.ts +25 -1
- package/packages/core/src/ports/runner/fake.ts +2 -2
- package/packages/core/src/ports/runner/native-cli-fixture.ts +40 -5
- package/packages/core/src/ports/runner/native-process-fixture.ts +4 -1
- package/packages/core/src/ports/runner/pi.ts +23 -7
- package/packages/core/src/ports/runner/production.ts +19 -2
- package/packages/core/src/ports/runner/session-env.ts +65 -5
- package/packages/core/src/ports/runner/start-prompt.ts +6 -4
- package/packages/core/src/ports/tickets/contract.ts +4 -2
- package/packages/core/src/ports/tickets/github.ts +20 -5
- package/packages/core/src/ports/tickets/hosted-index.ts +6 -1
- package/packages/core/src/ports/tickets/labels.ts +21 -0
- package/packages/core/src/ports/tickets/linear.ts +33 -0
- package/packages/core/src/ports/tickets/migration.ts +2 -0
- package/packages/core/src/ports/tickets/priority.ts +11 -0
- package/packages/core/src/ports/tickets/remote-protocol.ts +71 -6
- package/packages/core/src/ports/tickets/remote.ts +138 -16
- package/packages/core/src/ports/tickets/tree.ts +17 -4
- package/packages/core/src/ports/types.ts +98 -4
- package/packages/core/src/ports/workspace/builtin-capabilities.ts +7 -4
- package/packages/core/src/ports/workspace/commit-preservation.ts +182 -64
- package/packages/core/src/ports/workspace/create.ts +3 -0
- package/packages/core/src/ports/workspace/git-worktree.ts +13 -1
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +242 -61
- package/packages/core/src/processes/build-execution-state.ts +1 -3
- package/packages/core/src/processes/build-runner.ts +1435 -132
- package/packages/core/src/processes/dispatch-failure-budget.ts +1 -1
- package/packages/core/src/processes/dispatcher-selectors.ts +15 -13
- package/packages/core/src/processes/dispatcher.ts +2781 -242
- package/packages/core/src/processes/execution-no-progress.ts +36 -1
- package/packages/core/src/processes/execution-settlement.ts +2 -6
- package/packages/core/src/processes/harvest-execution-state.ts +2 -6
- package/packages/core/src/processes/harvest-runner.ts +7 -2
- package/packages/core/src/processes/infrastructure-failure-budget.ts +1 -3
- package/packages/core/src/processes/judge-launcher.ts +38 -0
- package/packages/core/src/processes/measurement-runner.ts +235 -0
- package/packages/core/src/processes/optimization-merges.ts +101 -0
- package/packages/core/src/processes/optimization-stop.ts +179 -0
- package/packages/core/src/processes/panel-runner.ts +756 -0
- package/packages/core/src/processes/phase-failure-budget.ts +1 -0
- package/packages/core/src/processes/publication-state.ts +1 -4
- package/packages/core/src/processes/repo-view.ts +77 -5
- package/packages/core/src/processes/sandbox-state.ts +1 -4
- package/packages/core/src/processes/tick-state.ts +1 -3
- package/packages/core/src/processes/workspace-preservation.ts +67 -9
- package/packages/core/src/scenarios/harness.ts +19 -8
- package/packages/core/src/store/contract.ts +44 -0
- package/packages/core/src/store/digest.ts +89 -7
- package/packages/core/src/store/judge-authority.ts +161 -0
- package/packages/core/src/store/phase-session.ts +226 -4
- package/packages/core/src/store/reduced-reads.ts +10 -0
- package/packages/core/src/store/reducer-value-shapes.json +17060 -12099
- package/packages/core/src/store/remote/client.ts +12 -2
- package/packages/core/src/store/remote/credentials.ts +31 -1
- package/packages/core/src/store/remote/index.ts +8 -0
- package/packages/core/src/store/remote/protocol.ts +38 -0
- package/packages/core/src/store/remote/released-clients.json +11 -0
- package/packages/core/src/store/remote/released-reducer-values/1.10.0.json +34439 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +18 -16
- package/packages/core/src/store/remote/token.ts +13 -4
- package/packages/core/src/store/repo-state-events.ts +6 -8
- package/packages/core/src/store/session-reducer.ts +1 -4
- package/packages/core/src/store/ticket-assets.ts +1 -3
- package/packages/core/src/store/types.ts +9 -0
- package/packages/core/src/testing/dispatch-read-budget.ts +70 -0
- package/packages/core/src/testing/git-config-isolation.ts +25 -0
- package/packages/core/src/testing/index.ts +13 -0
- package/packages/core/src/testing/reduced-read-budget.ts +3455 -34
- package/skills/code-review/SKILL.md +16 -0
- package/skills/finalize/SKILL.md +10 -4
- package/skills/guide/SKILL.md +383 -77
- package/skills/guide/references/integration-tree.md +102 -11
- package/skills/guide/references/merge-policy.md +30 -14
- package/skills/guide/references/migration-1.0.md +2 -1
- package/skills/guide/references/operator-api.md +117 -14
- package/skills/guide/references/optimization-nodes.md +1042 -0
- package/skills/guide/references/plugin-authoring.md +46 -12
- package/skills/guide/references/remote-store-protocol.md +46 -7
- package/skills/guide/references/remote-ticket-protocol.md +50 -2
- package/skills/guide/references/restacking.md +99 -11
- package/skills/guide/references/setup.md +13 -2
- package/skills/guide/references/spec-standard.md +2 -1
- package/skills/guide/references/ticket-dependencies.md +5 -0
- package/skills/guide/references/ticket-migration.md +4 -2
- package/skills/implement/SKILL.md +51 -1
- package/skills/judge/SKILL.md +43 -0
- package/skills/operate/SKILL.md +243 -28
- package/skills/plan/SKILL.md +18 -0
- package/skills/plan-review/SKILL.md +15 -1
- package/skills/propose/SKILL.md +121 -0
- package/skills/reconcile/SKILL.md +21 -2
- package/skills/spec/SKILL.md +30 -4
- package/skills/tickets/SKILL.md +44 -5
- package/templates/hosted-service/package.json +2 -2
|
@@ -3,6 +3,7 @@ import { reducerValueForClient } from '../store/remote/compatibility'
|
|
|
3
3
|
import { RELEASED_CLIENTS } from '../store/remote/released-clients'
|
|
4
4
|
import { missingAccountCredentials, reconcileMissingAccounts } from '../accounts/availability'
|
|
5
5
|
import { decideNextFromFacts } from '../kernel/engine'
|
|
6
|
+
import { slotRequest, type CapacityBuild } from '../kernel/dispatch-capacity'
|
|
6
7
|
import { proveTargetLineage } from '../kernel/target-lineage'
|
|
7
8
|
import { nodeRestackLog } from '../kernel/generators/node-restack-log'
|
|
8
9
|
import { REPLACED_HEADS_CAP } from '../kernel/read-facts'
|
|
@@ -17,7 +18,7 @@ import { abDispatch } from '../cli/dispatch'
|
|
|
17
18
|
import { createTerminalModeController } from '../cli/terminal-restore'
|
|
18
19
|
import { randomUuids } from '../ids'
|
|
19
20
|
import { ScriptedAgentRunner, defaultTurnResult } from '../ports/runner/fake'
|
|
20
|
-
import { Dispatcher, defaultTriageState } from '../processes/dispatcher'
|
|
21
|
+
import { Dispatcher, defaultTriageState, emptyTickReport } from '../processes/dispatcher'
|
|
21
22
|
import { boundedStateCount } from '../ports/tickets/states'
|
|
22
23
|
import { FakeTicketSource } from '../ports/tickets/fake'
|
|
23
24
|
import { FakeWorkspaceProvider } from '../ports/workspace/fake'
|
|
@@ -33,6 +34,7 @@ import {
|
|
|
33
34
|
import { buildRegistry } from '../operator/registry'
|
|
34
35
|
import { expect } from 'bun:test'
|
|
35
36
|
import type { BuildStore } from '../store/types'
|
|
37
|
+
import type { TicketRef } from '../ontology'
|
|
36
38
|
import { KERNEL, DISPATCHER, humanActor } from '../events/envelope'
|
|
37
39
|
import {
|
|
38
40
|
readBuildFacts,
|
|
@@ -1350,12 +1352,15 @@ export async function parkedSweepReadBudget(opts: {
|
|
|
1350
1352
|
if (args[1] === kind) metrics.meta++
|
|
1351
1353
|
return meta(...args)
|
|
1352
1354
|
}
|
|
1355
|
+
// Store-retained history is read only by recovery, never by idle work.
|
|
1356
|
+
let retainedHistoryReads = 0
|
|
1353
1357
|
store.getArtifact = async (...args) => {
|
|
1354
1358
|
const result = await get(...args)
|
|
1355
1359
|
if (args[1] === kind) {
|
|
1356
1360
|
metrics.bodies++
|
|
1357
1361
|
metrics.bytes += result?.content.byteLength ?? 0
|
|
1358
1362
|
}
|
|
1363
|
+
if (/^(?:history-objects-|replay-v1-)/.test(args[1])) retainedHistoryReads++
|
|
1359
1364
|
return result
|
|
1360
1365
|
}
|
|
1361
1366
|
const reset = () => {
|
|
@@ -1410,6 +1415,47 @@ export async function parkedSweepReadBudget(opts: {
|
|
|
1410
1415
|
replacementId: 'replacement',
|
|
1411
1416
|
},
|
|
1412
1417
|
})
|
|
1418
|
+
// A remote-workspace candidate whose guest archive push and REST fallback are
|
|
1419
|
+
// refused: each retry reads the same bounded facts and appends nothing.
|
|
1420
|
+
const refusedSlug = 'refused-archive-read-budget'
|
|
1421
|
+
await store.ensureRepo('/refused-archive-read-budget')
|
|
1422
|
+
await store.createBuild({ slug: refusedSlug, repo: '/refused-archive-read-budget' })
|
|
1423
|
+
const candidate = '8'.repeat(40)
|
|
1424
|
+
await store.append(refusedSlug, {
|
|
1425
|
+
actor: DISPATCHER,
|
|
1426
|
+
type: 'workspace.provisioned',
|
|
1427
|
+
payload: {
|
|
1428
|
+
provider: 'vercel-sandbox',
|
|
1429
|
+
ref: 'refused-sandbox',
|
|
1430
|
+
path: '/vercel/sandbox/workspace',
|
|
1431
|
+
branch: `ab/${refusedSlug}`,
|
|
1432
|
+
base: { source: 'remote', sha: transaction.oldBase },
|
|
1433
|
+
remote: true,
|
|
1434
|
+
},
|
|
1435
|
+
})
|
|
1436
|
+
const refusedRequest = await store.append(refusedSlug, {
|
|
1437
|
+
actor: KERNEL,
|
|
1438
|
+
type: 'publication.requested',
|
|
1439
|
+
payload: {
|
|
1440
|
+
operation: 'reconcile',
|
|
1441
|
+
branch: `ab/${refusedSlug}`,
|
|
1442
|
+
sha: candidate,
|
|
1443
|
+
rewrite: { ...transaction, branch: `ab/${refusedSlug}` },
|
|
1444
|
+
artifact: { kind: 'reconcile-notes', rev: 0 },
|
|
1445
|
+
},
|
|
1446
|
+
})
|
|
1447
|
+
await store.append(refusedSlug, {
|
|
1448
|
+
actor: DISPATCHER,
|
|
1449
|
+
type: 'publication.lost',
|
|
1450
|
+
payload: {
|
|
1451
|
+
request: refusedRequest.seq,
|
|
1452
|
+
operation: 'reconcile',
|
|
1453
|
+
branch: `ab/${refusedSlug}`,
|
|
1454
|
+
sha: candidate,
|
|
1455
|
+
reason: 'replacement',
|
|
1456
|
+
},
|
|
1457
|
+
})
|
|
1458
|
+
const refusedAttempts: Record<string, number>[] = []
|
|
1413
1459
|
let seeded = 0
|
|
1414
1460
|
const idleRequests: Record<string, number>[] = []
|
|
1415
1461
|
for (const length of [100, 100_000]) {
|
|
@@ -1523,6 +1569,160 @@ export async function parkedSweepReadBudget(opts: {
|
|
|
1523
1569
|
if (idleRequests.length) expect(requests).toEqual(idleRequests[0]!)
|
|
1524
1570
|
idleRequests.push(requests)
|
|
1525
1571
|
}
|
|
1572
|
+
// A parked build that holds store-retained history costs the same: its
|
|
1573
|
+
// `history.retained` fact folds into the saved value once, and idle
|
|
1574
|
+
// ticks never read the retained copies.
|
|
1575
|
+
const retainedSha = (length === 100 ? 'e' : 'f').repeat(40)
|
|
1576
|
+
const digest = '0'.repeat(64)
|
|
1577
|
+
await store.putArtifact(slugs[0]!, {
|
|
1578
|
+
kind: `replay-v1-${digest}-0`,
|
|
1579
|
+
content: new Uint8Array([1, 2, 3]),
|
|
1580
|
+
})
|
|
1581
|
+
await store.putArtifact(slugs[0]!, {
|
|
1582
|
+
kind: `history-objects-${retainedSha}`,
|
|
1583
|
+
content: JSON.stringify({
|
|
1584
|
+
version: 1,
|
|
1585
|
+
head: retainedSha,
|
|
1586
|
+
base: transaction.targetBase,
|
|
1587
|
+
digest,
|
|
1588
|
+
bytes: 3,
|
|
1589
|
+
chunkBytes: 1024 * 1024,
|
|
1590
|
+
chunks: 1,
|
|
1591
|
+
}),
|
|
1592
|
+
})
|
|
1593
|
+
await store.append(slugs[0]!, {
|
|
1594
|
+
actor: KERNEL,
|
|
1595
|
+
type: 'history.retained',
|
|
1596
|
+
payload: {
|
|
1597
|
+
operation: 'restack',
|
|
1598
|
+
id: `retained-${length}`,
|
|
1599
|
+
base: transaction.targetBase,
|
|
1600
|
+
store: [retainedSha],
|
|
1601
|
+
target: [transaction.oldBase],
|
|
1602
|
+
unretained: [],
|
|
1603
|
+
},
|
|
1604
|
+
})
|
|
1605
|
+
opts.advance()
|
|
1606
|
+
await idle.tick({ acceptNewWork: true })
|
|
1607
|
+
for (const _ of [0, 1]) {
|
|
1608
|
+
opts.advance()
|
|
1609
|
+
reset()
|
|
1610
|
+
retainedHistoryReads = 0
|
|
1611
|
+
const requests = await countStoreRequests(store, () =>
|
|
1612
|
+
idle.tick({ acceptNewWork: true }).then(() => undefined),
|
|
1613
|
+
)
|
|
1614
|
+
expect(requests).toEqual(idleRequests[0]!)
|
|
1615
|
+
expect(metrics.historicalRows).toBe(0)
|
|
1616
|
+
expect({ meta: metrics.meta, bodies: metrics.bodies }).toEqual(baseline)
|
|
1617
|
+
expect(retainedHistoryReads).toBe(0)
|
|
1618
|
+
}
|
|
1619
|
+
// So does one whose unpublished workspace commits and node write history
|
|
1620
|
+
// are held in the store: provisioning and recovery read them, idle ticks never.
|
|
1621
|
+
const nodeSha = (length === 100 ? 'c' : 'd').repeat(40)
|
|
1622
|
+
await store.putArtifact(slugs[0]!, {
|
|
1623
|
+
kind: `history-objects-${nodeSha}`,
|
|
1624
|
+
content: JSON.stringify({
|
|
1625
|
+
version: 1,
|
|
1626
|
+
head: nodeSha,
|
|
1627
|
+
base: transaction.targetBase,
|
|
1628
|
+
digest,
|
|
1629
|
+
bytes: 3,
|
|
1630
|
+
chunkBytes: 1024 * 1024,
|
|
1631
|
+
chunks: 1,
|
|
1632
|
+
}),
|
|
1633
|
+
})
|
|
1634
|
+
await store.append(slugs[0]!, {
|
|
1635
|
+
actor: KERNEL,
|
|
1636
|
+
type: 'node.history-retained',
|
|
1637
|
+
payload: {
|
|
1638
|
+
operation: 'restack',
|
|
1639
|
+
id: `node-retained-${length}`,
|
|
1640
|
+
base: transaction.targetBase,
|
|
1641
|
+
store: [nodeSha],
|
|
1642
|
+
target: [],
|
|
1643
|
+
unretained: [],
|
|
1644
|
+
},
|
|
1645
|
+
})
|
|
1646
|
+
await store.append(slugs[0]!, {
|
|
1647
|
+
actor: DISPATCHER,
|
|
1648
|
+
type: 'workspace.commits-retained',
|
|
1649
|
+
payload: {
|
|
1650
|
+
workspace: 1,
|
|
1651
|
+
execution: 0,
|
|
1652
|
+
ref: 'retained-workspace',
|
|
1653
|
+
branch: `ab/${slugs[0]!}`,
|
|
1654
|
+
phase: 'implement',
|
|
1655
|
+
round: 1,
|
|
1656
|
+
heads: [
|
|
1657
|
+
{
|
|
1658
|
+
sha: retainedSha,
|
|
1659
|
+
role: 'producer',
|
|
1660
|
+
commits: [retainedSha],
|
|
1661
|
+
storeBase: transaction.targetBase,
|
|
1662
|
+
},
|
|
1663
|
+
],
|
|
1664
|
+
},
|
|
1665
|
+
})
|
|
1666
|
+
opts.advance()
|
|
1667
|
+
await idle.tick({ acceptNewWork: true })
|
|
1668
|
+
for (const _ of [0, 1]) {
|
|
1669
|
+
opts.advance()
|
|
1670
|
+
reset()
|
|
1671
|
+
retainedHistoryReads = 0
|
|
1672
|
+
const requests = await countStoreRequests(store, () =>
|
|
1673
|
+
idle.tick({ acceptNewWork: true }).then(() => undefined),
|
|
1674
|
+
)
|
|
1675
|
+
expect(requests).toEqual(idleRequests[0]!)
|
|
1676
|
+
expect(metrics.historicalRows).toBe(0)
|
|
1677
|
+
expect({ meta: metrics.meta, bodies: metrics.bodies }).toEqual(baseline)
|
|
1678
|
+
expect(retainedHistoryReads).toBe(0)
|
|
1679
|
+
}
|
|
1680
|
+
const refusedEvents = Reflect.get(store, 'builds').get(refusedSlug)
|
|
1681
|
+
.events as import('../events/catalog').AbEvent[]
|
|
1682
|
+
while (refusedEvents.length < length)
|
|
1683
|
+
await store.append(refusedSlug, {
|
|
1684
|
+
actor: humanActor('budget'),
|
|
1685
|
+
type: 'build.auto-merge-cancelled',
|
|
1686
|
+
payload: {},
|
|
1687
|
+
})
|
|
1688
|
+
await readBuildFacts(store, refusedSlug)
|
|
1689
|
+
const refusedBoundary = refusedEvents.at(-1)!.seq
|
|
1690
|
+
let refusedRows = 0
|
|
1691
|
+
refusedEvents.slice = function (start?: number, end?: number) {
|
|
1692
|
+
const result = Array.prototype.slice.call(this, start, end) as typeof refusedEvents
|
|
1693
|
+
refusedRows += result.filter((event) => event.seq <= refusedBoundary).length
|
|
1694
|
+
return result
|
|
1695
|
+
}
|
|
1696
|
+
const { recoverLostCandidate } = await import('../kernel/reconcile-restack')
|
|
1697
|
+
let probes = 0
|
|
1698
|
+
for (const attempt of [0, 1, 2]) {
|
|
1699
|
+
let outcome: string | undefined
|
|
1700
|
+
const requests = await countStoreRequests(store, async () => {
|
|
1701
|
+
outcome = await recoverLostCandidate({
|
|
1702
|
+
store,
|
|
1703
|
+
slug: refusedSlug,
|
|
1704
|
+
workspacePath: '/unused',
|
|
1705
|
+
forge: new FakeForge(),
|
|
1706
|
+
exec: async () => {
|
|
1707
|
+
throw new Error('a remote workspace candidate is never archived from the host')
|
|
1708
|
+
},
|
|
1709
|
+
// A provider absorbs the refused archive push and REST fallback and
|
|
1710
|
+
// reports the candidate available; settlement retains it later.
|
|
1711
|
+
probeCandidate: async () => {
|
|
1712
|
+
probes++
|
|
1713
|
+
return true
|
|
1714
|
+
},
|
|
1715
|
+
}).catch(() => 'deferred')
|
|
1716
|
+
})
|
|
1717
|
+
expect(outcome).toBe('available')
|
|
1718
|
+
expect(probes).toBe(attempt + 1)
|
|
1719
|
+
expect(requests.append ?? 0).toBe(0)
|
|
1720
|
+
expect(requests.appendIfCurrent ?? 0).toBe(0)
|
|
1721
|
+
if (refusedAttempts.length) expect(requests).toEqual(refusedAttempts[0]!)
|
|
1722
|
+
refusedAttempts.push(requests)
|
|
1723
|
+
}
|
|
1724
|
+
expect(refusedRows).toBe(0)
|
|
1725
|
+
Reflect.deleteProperty(refusedEvents, 'slice')
|
|
1526
1726
|
console.log('parked sweep read budget', {
|
|
1527
1727
|
history: length,
|
|
1528
1728
|
builds: slugs.length,
|
|
@@ -1599,6 +1799,433 @@ export async function ticketWaitIdleReadBudget(opts: {
|
|
|
1599
1799
|
}
|
|
1600
1800
|
}
|
|
1601
1801
|
|
|
1802
|
+
/** Sampled attempt measurements (SPEC §13.1.1): the dispatcher decides each
|
|
1803
|
+
* parked attempt's sampled request with one reduced read of its node, once,
|
|
1804
|
+
* and idle ticks afterwards read the node no more often than before any
|
|
1805
|
+
* sample, append nothing and read zero historical event rows, at 100 and
|
|
1806
|
+
* 100,000 events on every attempt and on the node. The idle tick before any
|
|
1807
|
+
* sample, which also runs proposer admission for the node, reads no history
|
|
1808
|
+
* and the same number of node values at both lengths. `sample` appends a fresh
|
|
1809
|
+
* request and its samples to one attempt; `decided` names the fact the
|
|
1810
|
+
* dispatcher must have written for it. With `progress`, which appends the
|
|
1811
|
+
* request and partial sampling work (a judge panel's facts) first, ticks
|
|
1812
|
+
* while the samples are pending append nothing, read zero historical rows
|
|
1813
|
+
* and read the node equally often at every history length, and `sample`
|
|
1814
|
+
* then appends only the samples. */
|
|
1815
|
+
export async function sampledMeasurementReadBudget(opts: {
|
|
1816
|
+
store: import('../store/memory').MemoryBuildStore
|
|
1817
|
+
node: string
|
|
1818
|
+
attempts: string[]
|
|
1819
|
+
dispatcher: () => Dispatcher
|
|
1820
|
+
progress?: (slug: string, request: string) => Promise<void>
|
|
1821
|
+
sample: (slug: string, request: string) => Promise<void>
|
|
1822
|
+
decided: (slug: string, request: string) => Promise<boolean>
|
|
1823
|
+
advance: () => void
|
|
1824
|
+
}): Promise<void> {
|
|
1825
|
+
const { store, node, attempts } = opts
|
|
1826
|
+
let nodeReads = 0
|
|
1827
|
+
const getReducerValue = store.getReducerValue.bind(store)
|
|
1828
|
+
store.getReducerValue = (async (...args: Parameters<typeof store.getReducerValue>) => {
|
|
1829
|
+
const [scope] = args
|
|
1830
|
+
if (scope.kind === 'build' && scope.slug === node) nodeReads++
|
|
1831
|
+
return getReducerValue(...args)
|
|
1832
|
+
}) as typeof store.getReducerValue
|
|
1833
|
+
const metrics = { historicalRows: 0, tailRows: 0 }
|
|
1834
|
+
// Writes to the attempts only: the node's own polling facts are not this
|
|
1835
|
+
// stage's.
|
|
1836
|
+
let attemptWrites = 0
|
|
1837
|
+
const append = store.append.bind(store)
|
|
1838
|
+
const appendIfCurrent = store.appendIfCurrent.bind(store)
|
|
1839
|
+
store.append = ((slug: string, event: never) => {
|
|
1840
|
+
if (attempts.includes(slug)) attemptWrites++
|
|
1841
|
+
return append(slug, event)
|
|
1842
|
+
}) as typeof store.append
|
|
1843
|
+
store.appendIfCurrent = ((slug: string, expected: number, event: never) => {
|
|
1844
|
+
if (attempts.includes(slug)) attemptWrites++
|
|
1845
|
+
return appendIfCurrent(slug, expected, event)
|
|
1846
|
+
}) as typeof store.appendIfCurrent
|
|
1847
|
+
let pendingNodeReads: number | undefined
|
|
1848
|
+
const idleReads: number[] = []
|
|
1849
|
+
try {
|
|
1850
|
+
for (const length of [100, 100_000]) {
|
|
1851
|
+
for (const slug of [node, ...attempts]) await seedBuildFiller(store, slug, length)
|
|
1852
|
+
const dispatcher = opts.dispatcher()
|
|
1853
|
+
// Warm durable projections over the new filler once.
|
|
1854
|
+
opts.advance()
|
|
1855
|
+
await dispatcher.tick({ acceptNewWork: false })
|
|
1856
|
+
opts.advance()
|
|
1857
|
+
await dispatcher.tick({ acceptNewWork: false })
|
|
1858
|
+
// Rows up to here are history; the idle tick's polling facts, the
|
|
1859
|
+
// samples and the decisions are the tail.
|
|
1860
|
+
const restore = [node, ...attempts].map((slug) => {
|
|
1861
|
+
const boundary = buildEventRows(store, slug).at(-1)!.seq
|
|
1862
|
+
return instrumentBuildRows(store, slug, () => boundary, metrics)
|
|
1863
|
+
})
|
|
1864
|
+
const request = `m-${length}`
|
|
1865
|
+
try {
|
|
1866
|
+
// An idle tick before any sample, which runs the node's proposer
|
|
1867
|
+
// admission too, costs the same node reads at every history length
|
|
1868
|
+
// and reads no history.
|
|
1869
|
+
opts.advance()
|
|
1870
|
+
nodeReads = 0
|
|
1871
|
+
metrics.historicalRows = 0
|
|
1872
|
+
await dispatcher.tick({ acceptNewWork: false })
|
|
1873
|
+
const idleNodeReads = nodeReads
|
|
1874
|
+
expect(metrics.historicalRows).toBe(0)
|
|
1875
|
+
idleReads.push(idleNodeReads)
|
|
1876
|
+
if (opts.progress !== undefined) {
|
|
1877
|
+
for (const slug of attempts) await opts.progress(slug, request)
|
|
1878
|
+
// Waiting for the samples: no decision, no write, no history.
|
|
1879
|
+
for (const make of [() => dispatcher, opts.dispatcher]) {
|
|
1880
|
+
const ticking = make()
|
|
1881
|
+
opts.advance()
|
|
1882
|
+
nodeReads = 0
|
|
1883
|
+
metrics.historicalRows = 0
|
|
1884
|
+
attemptWrites = 0
|
|
1885
|
+
await ticking.tick({ acceptNewWork: false })
|
|
1886
|
+
for (const slug of attempts) expect(await opts.decided(slug, request)).toBe(false)
|
|
1887
|
+
expect(attemptWrites).toBe(0)
|
|
1888
|
+
// The landing gate's per-child reads of a pending request: the
|
|
1889
|
+
// same on every tick, dispatcher and history length.
|
|
1890
|
+
pendingNodeReads ??= nodeReads
|
|
1891
|
+
expect(nodeReads).toBe(pendingNodeReads)
|
|
1892
|
+
expect(metrics.historicalRows).toBe(0)
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
for (const slug of attempts) await opts.sample(slug, request)
|
|
1896
|
+
// The deciding tick: one node read per sampled request, once.
|
|
1897
|
+
opts.advance()
|
|
1898
|
+
nodeReads = 0
|
|
1899
|
+
metrics.historicalRows = 0
|
|
1900
|
+
attemptWrites = 0
|
|
1901
|
+
await dispatcher.tick({ acceptNewWork: false })
|
|
1902
|
+
expect(attemptWrites).toBe(attempts.length)
|
|
1903
|
+
expect(nodeReads - idleNodeReads).toBe(attempts.length)
|
|
1904
|
+
expect(metrics.historicalRows).toBe(0)
|
|
1905
|
+
for (const slug of attempts) expect(await opts.decided(slug, request)).toBe(true)
|
|
1906
|
+
// Idle ticks after the decisions, on this and on a fresh dispatcher.
|
|
1907
|
+
for (const make of [() => dispatcher, opts.dispatcher, () => dispatcher]) {
|
|
1908
|
+
const ticking = make()
|
|
1909
|
+
opts.advance()
|
|
1910
|
+
nodeReads = 0
|
|
1911
|
+
metrics.historicalRows = 0
|
|
1912
|
+
attemptWrites = 0
|
|
1913
|
+
await ticking.tick({ acceptNewWork: false })
|
|
1914
|
+
expect(attemptWrites).toBe(0)
|
|
1915
|
+
expect(nodeReads).toBeLessThanOrEqual(idleNodeReads)
|
|
1916
|
+
expect(metrics.historicalRows).toBe(0)
|
|
1917
|
+
}
|
|
1918
|
+
console.log('sampled measurement read budget', {
|
|
1919
|
+
history: length,
|
|
1920
|
+
attempts: attempts.length,
|
|
1921
|
+
idleNodeReads,
|
|
1922
|
+
})
|
|
1923
|
+
} finally {
|
|
1924
|
+
for (const undo of restore) undo()
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
expect(idleReads[1]).toBe(idleReads[0])
|
|
1928
|
+
} finally {
|
|
1929
|
+
store.getReducerValue = getReducerValue
|
|
1930
|
+
store.append = append
|
|
1931
|
+
store.appendIfCurrent = appendIfCurrent
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1935
|
+
/** Backing store traffic during one measured window: calls by method and by
|
|
1936
|
+
* build slug, returned bytes, event rows read from any build log, each named
|
|
1937
|
+
* by its build and sequence, and rows read from any repository journal. */
|
|
1938
|
+
export interface StoreReadMetrics {
|
|
1939
|
+
calls: Record<string, number>
|
|
1940
|
+
slugs: Record<string, number>
|
|
1941
|
+
bytes: number
|
|
1942
|
+
rows: number
|
|
1943
|
+
read: { slug: string; seq: number }[]
|
|
1944
|
+
repoRows: number
|
|
1945
|
+
}
|
|
1946
|
+
|
|
1947
|
+
const STORE_WRITES = new Set([
|
|
1948
|
+
'append',
|
|
1949
|
+
'appendIfCurrent',
|
|
1950
|
+
'appendWithArtifacts',
|
|
1951
|
+
'appendWithArtifactsIfCurrent',
|
|
1952
|
+
'appendRepo',
|
|
1953
|
+
'putArtifact',
|
|
1954
|
+
])
|
|
1955
|
+
|
|
1956
|
+
/** Like `countStoreRequests`, attributing each call to the build slug it
|
|
1957
|
+
* names and measuring what it returned. */
|
|
1958
|
+
export async function measureStoreReads(
|
|
1959
|
+
store: import('../store/memory').MemoryBuildStore,
|
|
1960
|
+
run: () => Promise<void>,
|
|
1961
|
+
): Promise<StoreReadMetrics> {
|
|
1962
|
+
const metrics: StoreReadMetrics = {
|
|
1963
|
+
calls: {},
|
|
1964
|
+
slugs: {},
|
|
1965
|
+
bytes: 0,
|
|
1966
|
+
rows: 0,
|
|
1967
|
+
read: [],
|
|
1968
|
+
repoRows: 0,
|
|
1969
|
+
}
|
|
1970
|
+
const builds: Map<string, { events: import('../events/catalog').AbEvent[] }> = Reflect.get(
|
|
1971
|
+
store,
|
|
1972
|
+
'builds',
|
|
1973
|
+
)
|
|
1974
|
+
const restore: (() => void)[] = []
|
|
1975
|
+
// The memory store hands out log rows through `slice` (reducer advances,
|
|
1976
|
+
// pages) and `filter` (`getEvents`, `getRepoEvents`). Both return a fresh
|
|
1977
|
+
// array, so a row is counted once however the caller narrows it further.
|
|
1978
|
+
const count = <E extends { seq: number }>(events: E[], read: (rows: E[]) => void) => {
|
|
1979
|
+
for (const method of ['slice', 'filter'] as const) {
|
|
1980
|
+
const original = Array.prototype[method] as (...args: unknown[]) => E[]
|
|
1981
|
+
Object.defineProperty(events, method, {
|
|
1982
|
+
configurable: true,
|
|
1983
|
+
writable: true,
|
|
1984
|
+
value(this: E[], ...args: unknown[]) {
|
|
1985
|
+
const result = original.apply(this, args)
|
|
1986
|
+
read(result)
|
|
1987
|
+
return result
|
|
1988
|
+
},
|
|
1989
|
+
})
|
|
1990
|
+
restore.push(() => Reflect.deleteProperty(events, method))
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
const repositories: Map<string, { events: { seq: number }[] }> = Reflect.get(store, 'repos')
|
|
1994
|
+
for (const repository of repositories.values())
|
|
1995
|
+
count(repository.events, (rows) => {
|
|
1996
|
+
metrics.repoRows += rows.length
|
|
1997
|
+
})
|
|
1998
|
+
for (const [slug, build] of builds)
|
|
1999
|
+
count(build.events, (rows) => {
|
|
2000
|
+
metrics.rows += rows.length
|
|
2001
|
+
for (const event of rows) metrics.read.push({ slug, seq: event.seq })
|
|
2002
|
+
})
|
|
2003
|
+
const names = Object.getOwnPropertyNames(Object.getPrototypeOf(store)).filter(
|
|
2004
|
+
(name) => name !== 'constructor' && typeof Reflect.get(store, name) === 'function',
|
|
2005
|
+
)
|
|
2006
|
+
// Bytes are what the store returns to its caller; a call the store makes
|
|
2007
|
+
// to itself returns its own internal state, which is not traffic.
|
|
2008
|
+
const inside = new AsyncLocalStorage<true>()
|
|
2009
|
+
for (const name of names) {
|
|
2010
|
+
const own = Object.getOwnPropertyDescriptor(store, name)
|
|
2011
|
+
const original = Reflect.get(store, name) as (...args: unknown[]) => unknown
|
|
2012
|
+
const measure = (internal: boolean) => (result: unknown) => {
|
|
2013
|
+
if (!internal && !STORE_WRITES.has(name))
|
|
2014
|
+
metrics.bytes += Buffer.byteLength(
|
|
2015
|
+
JSON.stringify(result, (_key, value) =>
|
|
2016
|
+
value instanceof Uint8Array ? value.byteLength : value,
|
|
2017
|
+
) ?? '',
|
|
2018
|
+
)
|
|
2019
|
+
return result
|
|
2020
|
+
}
|
|
2021
|
+
Reflect.set(store, name, (...args: unknown[]) => {
|
|
2022
|
+
metrics.calls[name] = (metrics.calls[name] ?? 0) + 1
|
|
2023
|
+
const scope = args[0]
|
|
2024
|
+
const slug =
|
|
2025
|
+
typeof scope === 'string'
|
|
2026
|
+
? scope
|
|
2027
|
+
: scope !== null && typeof scope === 'object' && 'slug' in scope
|
|
2028
|
+
? String(scope.slug)
|
|
2029
|
+
: undefined
|
|
2030
|
+
if (slug !== undefined && builds.has(slug))
|
|
2031
|
+
metrics.slugs[slug] = (metrics.slugs[slug] ?? 0) + 1
|
|
2032
|
+
const internal = inside.getStore() === true
|
|
2033
|
+
const result = inside.run(true, () => original.apply(store, args))
|
|
2034
|
+
return result instanceof Promise ? result.then(measure(internal)) : measure(internal)(result)
|
|
2035
|
+
})
|
|
2036
|
+
restore.push(() =>
|
|
2037
|
+
own ? Object.defineProperty(store, name, own) : Reflect.deleteProperty(store, name),
|
|
2038
|
+
)
|
|
2039
|
+
}
|
|
2040
|
+
try {
|
|
2041
|
+
await run()
|
|
2042
|
+
} finally {
|
|
2043
|
+
for (const undo of restore) undo()
|
|
2044
|
+
}
|
|
2045
|
+
return metrics
|
|
2046
|
+
}
|
|
2047
|
+
|
|
2048
|
+
/** The tripwire `measureStoreReads` gives budget proofs: every public path
|
|
2049
|
+
* that returns build or repository log rows is counted, each row once. A
|
|
2050
|
+
* reducer advance reads only its new rows; a full `getEvents` or
|
|
2051
|
+
* `getRepoEvents` reads the history and is seen doing so. */
|
|
2052
|
+
export async function storeReadMetricsTripwire(): Promise<void> {
|
|
2053
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
2054
|
+
const store = new MemoryBuildStore()
|
|
2055
|
+
const repo = 'tripwire/repo'
|
|
2056
|
+
const slug = 'tripwire-build'
|
|
2057
|
+
await store.ensureRepo(repo)
|
|
2058
|
+
await store.appendRepo(repo, {
|
|
2059
|
+
actor: DISPATCHER,
|
|
2060
|
+
type: 'dispatcher.run-started',
|
|
2061
|
+
payload: {
|
|
2062
|
+
run: 'tripwire-run',
|
|
2063
|
+
pid: 1,
|
|
2064
|
+
roleWarnings: [],
|
|
2065
|
+
effectiveConfig: { kind: 'dispatcher-effective-config', rev: 1 },
|
|
2066
|
+
},
|
|
2067
|
+
})
|
|
2068
|
+
await store.createBuild({ slug, repo })
|
|
2069
|
+
const scope = { kind: 'build', slug } as const
|
|
2070
|
+
const request = { reducer: 'buildReadFacts' } as const
|
|
2071
|
+
await store.getReducerValue(scope, request)
|
|
2072
|
+
const historical = (await store.getEvents(slug)).map((event) => event.seq)
|
|
2073
|
+
const repoHistory = (await store.getRepoEvents(repo)).length
|
|
2074
|
+
expect(repoHistory).toBeGreaterThan(0)
|
|
2075
|
+
|
|
2076
|
+
const builds = await measureStoreReads(store, async () => {
|
|
2077
|
+
await store.getEvents(slug)
|
|
2078
|
+
})
|
|
2079
|
+
expect(builds.read).toEqual(historical.map((seq) => ({ slug, seq })))
|
|
2080
|
+
expect(builds.rows).toBe(historical.length)
|
|
2081
|
+
const since = await measureStoreReads(store, async () => {
|
|
2082
|
+
await store.getEvents(slug, historical.at(-1))
|
|
2083
|
+
})
|
|
2084
|
+
expect(since.rows).toBe(0)
|
|
2085
|
+
const repository = await measureStoreReads(store, async () => {
|
|
2086
|
+
await store.getRepoEvents(repo)
|
|
2087
|
+
})
|
|
2088
|
+
expect(repository.repoRows).toBe(repoHistory)
|
|
2089
|
+
expect(repository.rows).toBe(0)
|
|
2090
|
+
|
|
2091
|
+
// A reducer advancing over one new row reads that row, once.
|
|
2092
|
+
const appended = await store.append(slug, {
|
|
2093
|
+
actor: KERNEL,
|
|
2094
|
+
type: 'runner.attached',
|
|
2095
|
+
payload: { instance: 'tripwire', host: 'host' },
|
|
2096
|
+
})
|
|
2097
|
+
const advance = await measureStoreReads(store, async () => {
|
|
2098
|
+
await store.getReducerValue(scope, request)
|
|
2099
|
+
})
|
|
2100
|
+
expect(advance.read).toEqual([{ slug, seq: appended.seq }])
|
|
2101
|
+
expect(advance.repoRows).toBe(0)
|
|
2102
|
+
}
|
|
2103
|
+
|
|
2104
|
+
function writes(metrics: StoreReadMetrics): number {
|
|
2105
|
+
return Object.entries(metrics.calls)
|
|
2106
|
+
.filter(([name]) => STORE_WRITES.has(name))
|
|
2107
|
+
.reduce((sum, [, count]) => sum + count, 0)
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2110
|
+
/** The dispatcher stages this proposer adds, run over the dispatcher's own
|
|
2111
|
+
* view: the proposer stage over the digest batch `admitWaitingNodes`
|
|
2112
|
+
* already reads, the attempt creation hold, and proposer admission over the
|
|
2113
|
+
* capacity states that pass already loads. The tick's shared refresh,
|
|
2114
|
+
* digest batch and capacity reads happen outside the window. */
|
|
2115
|
+
async function measureProposerStages(
|
|
2116
|
+
store: import('../store/memory').MemoryBuildStore,
|
|
2117
|
+
dispatcher: Dispatcher,
|
|
2118
|
+
): Promise<StoreReadMetrics> {
|
|
2119
|
+
type Stages = {
|
|
2120
|
+
store: { refresh(): Promise<void> }
|
|
2121
|
+
deps: { clock(): Date }
|
|
2122
|
+
capacityBuilds(): Promise<unknown[]>
|
|
2123
|
+
repoBuildDigests(): Promise<unknown[]>
|
|
2124
|
+
advanceOptimizationNodes(
|
|
2125
|
+
report: unknown,
|
|
2126
|
+
opts: object,
|
|
2127
|
+
entries: unknown[],
|
|
2128
|
+
now: Date,
|
|
2129
|
+
): Promise<void>
|
|
2130
|
+
optimizationCreationHolds(): Promise<unknown>
|
|
2131
|
+
releaseStrandedNodeWorkspaces(
|
|
2132
|
+
builds: unknown[],
|
|
2133
|
+
now: Date,
|
|
2134
|
+
launched: Set<string>,
|
|
2135
|
+
report: unknown,
|
|
2136
|
+
opts: object,
|
|
2137
|
+
): Promise<void>
|
|
2138
|
+
admitProposers(
|
|
2139
|
+
builds: unknown[],
|
|
2140
|
+
now: Date,
|
|
2141
|
+
admitted: number,
|
|
2142
|
+
report: unknown,
|
|
2143
|
+
launched: Set<string>,
|
|
2144
|
+
opts: object,
|
|
2145
|
+
): Promise<void>
|
|
2146
|
+
}
|
|
2147
|
+
const stages = dispatcher as unknown as Stages
|
|
2148
|
+
await stages.store.refresh()
|
|
2149
|
+
const entries = await stages.repoBuildDigests()
|
|
2150
|
+
const builds = await stages.capacityBuilds()
|
|
2151
|
+
const report = emptyTickReport()
|
|
2152
|
+
return measureStoreReads(store, async () => {
|
|
2153
|
+
const now = stages.deps.clock()
|
|
2154
|
+
await stages.advanceOptimizationNodes(report, {}, entries, now)
|
|
2155
|
+
await stages.optimizationCreationHolds()
|
|
2156
|
+
await stages.releaseStrandedNodeWorkspaces(builds, now, new Set(), report, {})
|
|
2157
|
+
await stages.admitProposers(builds, now, 0, report, new Set(), {})
|
|
2158
|
+
})
|
|
2159
|
+
}
|
|
2160
|
+
|
|
2161
|
+
/**
|
|
2162
|
+
* The optimization proposer's recurring cost (SPEC §13.1.1). At every size,
|
|
2163
|
+
* after one warm-up pass that records the refused nodes' deferrals:
|
|
2164
|
+
*
|
|
2165
|
+
* - unchanged passes in a warm dispatcher, at a clock moving past backoffs
|
|
2166
|
+
* and hours budgets, make zero backing calls, return zero bytes and read
|
|
2167
|
+
* zero event rows, and write nothing;
|
|
2168
|
+
* - so do passes in fresh dispatchers over the same store;
|
|
2169
|
+
* - a wake fact on one deferred node costs reads of that node alone, then
|
|
2170
|
+
* one write, and the pass after it costs nothing again;
|
|
2171
|
+
* - freeing one slot admits exactly one waiting proposer and reads no
|
|
2172
|
+
* other waiting node.
|
|
2173
|
+
*/
|
|
2174
|
+
export async function optimizationProposerReadBudget(opts: {
|
|
2175
|
+
sizes: readonly number[]
|
|
2176
|
+
setup: (size: number) => Promise<{
|
|
2177
|
+
store: import('../store/memory').MemoryBuildStore
|
|
2178
|
+
dispatcher: () => Dispatcher
|
|
2179
|
+
advance: (ms: number) => void
|
|
2180
|
+
/** Append one fact that clears a deferral; returns the woken slug. */
|
|
2181
|
+
wake: () => Promise<string>
|
|
2182
|
+
/** Free one slot; returns the capacity-waiting node slugs. */
|
|
2183
|
+
release: () => Promise<string[]>
|
|
2184
|
+
launches: () => string[]
|
|
2185
|
+
}>
|
|
2186
|
+
}): Promise<void> {
|
|
2187
|
+
const totals: Record<number, StoreReadMetrics[]> = {}
|
|
2188
|
+
for (const size of opts.sizes) {
|
|
2189
|
+
const fixture = await opts.setup(size)
|
|
2190
|
+
const { store } = fixture
|
|
2191
|
+
const warm = fixture.dispatcher()
|
|
2192
|
+
const first = await measureProposerStages(store, warm)
|
|
2193
|
+
expect(writes(first)).toBeGreaterThan(0)
|
|
2194
|
+
const unchanged: StoreReadMetrics[] = []
|
|
2195
|
+
for (const hours of [1, 6, 30, 72]) {
|
|
2196
|
+
fixture.advance(hours * 3_600_000)
|
|
2197
|
+
unchanged.push(await measureProposerStages(store, warm))
|
|
2198
|
+
}
|
|
2199
|
+
for (const _ of [0, 1]) unchanged.push(await measureProposerStages(store, fixture.dispatcher()))
|
|
2200
|
+
for (const metrics of unchanged) {
|
|
2201
|
+
expect(metrics.calls).toEqual({})
|
|
2202
|
+
expect(metrics.bytes).toBe(0)
|
|
2203
|
+
expect(metrics.rows).toBe(0)
|
|
2204
|
+
}
|
|
2205
|
+
totals[size] = unchanged
|
|
2206
|
+
|
|
2207
|
+
const woken = await fixture.wake()
|
|
2208
|
+
const wake = await measureProposerStages(store, warm)
|
|
2209
|
+
expect(Object.keys(wake.slugs)).toEqual([woken])
|
|
2210
|
+
expect(writes(wake)).toBe(1)
|
|
2211
|
+
const after = await measureProposerStages(store, warm)
|
|
2212
|
+
expect(after.calls).toEqual({})
|
|
2213
|
+
|
|
2214
|
+
const waiting = await fixture.release()
|
|
2215
|
+
const launched = fixture.launches().length
|
|
2216
|
+
const admission = await measureProposerStages(store, warm)
|
|
2217
|
+
expect(fixture.launches().length - launched).toBe(1)
|
|
2218
|
+
const admitted = fixture.launches().at(-1)!
|
|
2219
|
+
expect(waiting).toContain(admitted)
|
|
2220
|
+
for (const slug of waiting) if (slug !== admitted) expect(admission.slugs[slug] ?? 0).toBe(0)
|
|
2221
|
+
console.log('optimization proposer read budget', {
|
|
2222
|
+
size,
|
|
2223
|
+
first: { calls: first.calls, rows: first.rows },
|
|
2224
|
+
admission: { calls: admission.calls, rows: admission.rows },
|
|
2225
|
+
})
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
|
|
1602
2229
|
/** Count every MemoryBuildStore method call made while `run` executes. */
|
|
1603
2230
|
export async function countStoreRequests(
|
|
1604
2231
|
store: import('../store/memory').MemoryBuildStore,
|
|
@@ -1628,6 +2255,72 @@ export async function countStoreRequests(
|
|
|
1628
2255
|
return counts
|
|
1629
2256
|
}
|
|
1630
2257
|
|
|
2258
|
+
/** Resolving an attempt's context (`ab context` and `ab done`, AUT-1279)
|
|
2259
|
+
* through a session-scoped store reads a fixed vector of served values at
|
|
2260
|
+
* every node and repository log length: once warm, an unchanged invocation
|
|
2261
|
+
* reads no build or repository row and downloads no events, and one new node
|
|
2262
|
+
* fact costs exactly that row. Returns the per-invocation call vector. */
|
|
2263
|
+
export async function attemptContextReadBudget(opts: {
|
|
2264
|
+
store: import('../store/memory').MemoryBuildStore
|
|
2265
|
+
node: string
|
|
2266
|
+
repo: string
|
|
2267
|
+
sizes: readonly number[]
|
|
2268
|
+
/** One invocation's attempt read, through the scoped store. */
|
|
2269
|
+
run: () => Promise<void>
|
|
2270
|
+
}): Promise<Record<string, number>> {
|
|
2271
|
+
const { store, node, repo } = opts
|
|
2272
|
+
const replays = ['getEvents', 'getRepoEvents', 'getBuildEventPage', 'getRepositoryTail']
|
|
2273
|
+
let baseline: Record<string, number> | undefined
|
|
2274
|
+
for (const size of opts.sizes) {
|
|
2275
|
+
await seedBuildFiller(store, node, size)
|
|
2276
|
+
await seedRepoFiller(store, repo, size)
|
|
2277
|
+
// The served values are reduced once per key; later invocations advance.
|
|
2278
|
+
await opts.run()
|
|
2279
|
+
const idle = await measureStoreReads(store, opts.run)
|
|
2280
|
+
expect(idle.rows).toBe(0)
|
|
2281
|
+
expect(idle.repoRows).toBe(0)
|
|
2282
|
+
for (const name of replays) expect(idle.calls[name]).toBeUndefined()
|
|
2283
|
+
await store.append(node, {
|
|
2284
|
+
actor: humanActor('budget'),
|
|
2285
|
+
type: 'build.auto-merge-cancelled',
|
|
2286
|
+
payload: {},
|
|
2287
|
+
})
|
|
2288
|
+
const advanced = await measureStoreReads(store, opts.run)
|
|
2289
|
+
expect(advanced.rows).toBe(1)
|
|
2290
|
+
expect(advanced.repoRows).toBe(0)
|
|
2291
|
+
for (const name of replays) expect(advanced.calls[name]).toBeUndefined()
|
|
2292
|
+
// The caller-facing requests, without the store's own internal calls.
|
|
2293
|
+
const requests = memoryStoreRequestCounter(store)
|
|
2294
|
+
try {
|
|
2295
|
+
await opts.run()
|
|
2296
|
+
} finally {
|
|
2297
|
+
requests.restore()
|
|
2298
|
+
}
|
|
2299
|
+
if (baseline) expect(requests.vector()).toEqual(baseline)
|
|
2300
|
+
baseline = requests.vector()
|
|
2301
|
+
}
|
|
2302
|
+
return baseline!
|
|
2303
|
+
}
|
|
2304
|
+
|
|
2305
|
+
/** Append filler facts to one repository until its journal holds `length`
|
|
2306
|
+
* events. */
|
|
2307
|
+
async function seedRepoFiller(
|
|
2308
|
+
store: import('../store/memory').MemoryBuildStore,
|
|
2309
|
+
repo: string,
|
|
2310
|
+
length: number,
|
|
2311
|
+
): Promise<void> {
|
|
2312
|
+
const events: { seq: number }[] = Reflect.get(store, 'repos').get(repo).events
|
|
2313
|
+
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
|
+
const template = await store.appendRepo(repo, filler)
|
|
2320
|
+
while (events.length < length - 1) events.push({ ...template, seq: events.length + 1 })
|
|
2321
|
+
if (events.length < length) await store.appendRepo(repo, filler)
|
|
2322
|
+
}
|
|
2323
|
+
|
|
1631
2324
|
/** Append filler facts to one build until its log holds `length` events. */
|
|
1632
2325
|
async function seedBuildFiller(
|
|
1633
2326
|
store: import('../store/memory').MemoryBuildStore,
|
|
@@ -1635,12 +2328,18 @@ async function seedBuildFiller(
|
|
|
1635
2328
|
length: number,
|
|
1636
2329
|
): Promise<void> {
|
|
1637
2330
|
const events = buildEventRows(store, slug)
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
2331
|
+
if (events.length >= length) return
|
|
2332
|
+
// One validated append, copied in bulk; the last append is real again so
|
|
2333
|
+
// 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
|
+
const template = await store.append(slug, filler)
|
|
2340
|
+
while (events.length < length - 1)
|
|
2341
|
+
events.push({ ...template, seq: events.length + 1 } as (typeof events)[number])
|
|
2342
|
+
if (events.length < length) await store.append(slug, filler)
|
|
1644
2343
|
}
|
|
1645
2344
|
|
|
1646
2345
|
function buildEventRows(
|
|
@@ -1673,10 +2372,12 @@ function instrumentBuildRows(
|
|
|
1673
2372
|
}
|
|
1674
2373
|
|
|
1675
2374
|
/** A stale build whose open workspace is flagged `cleanup-required` and whose
|
|
1676
|
-
* preservation keeps failing re-enters
|
|
1677
|
-
*
|
|
1678
|
-
*
|
|
1679
|
-
*
|
|
2375
|
+
* preservation keeps failing re-enters a reap on every pass: the sweep's reap
|
|
2376
|
+
* branch for a leaf, the verification tail's replacement for a node. Each pass
|
|
2377
|
+
* records exactly one failure (the paths never both reap in one tick), must
|
|
2378
|
+
* read only the tail it appended itself, the same number of reduced reads at
|
|
2379
|
+
* 100 and 100,000 events, and nothing at all once the build is healthy again.
|
|
2380
|
+
* Fresh dispatchers retain no per-process cache. */
|
|
1680
2381
|
export async function flaggedWorkspaceSweepReadBudget(opts: {
|
|
1681
2382
|
store: import('../store/memory').MemoryBuildStore
|
|
1682
2383
|
slug: string
|
|
@@ -1868,31 +2569,130 @@ export async function provisionContinuationGuardReadBudget(opts: {
|
|
|
1868
2569
|
})
|
|
1869
2570
|
}
|
|
1870
2571
|
|
|
1871
|
-
/**
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
)
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
2572
|
+
/** A teardown-abandoned provisioning marker is adopted by the next
|
|
2573
|
+
* invocation, and a bounded invocation without budget for the provision
|
|
2574
|
+
* defers it. Both recur (every invocation), so each must read no seeded
|
|
2575
|
+
* history and the same reduced values at 100 and 100,000 events. The budget
|
|
2576
|
+
* gate is clock arithmetic: a deferring tick writes nothing for the build, and
|
|
2577
|
+
* repeated deferrals cost the same each time. */
|
|
2578
|
+
export async function teardownAdoptionReadBudget(opts: {
|
|
2579
|
+
store: import('../store/memory').MemoryBuildStore
|
|
2580
|
+
/** Seeds a fresh build whose next tick kicks a remote provision
|
|
2581
|
+
* continuation, and returns its slug. Called before filler. */
|
|
2582
|
+
seed: (length: number) => Promise<string>
|
|
2583
|
+
/** A fresh dispatcher per measured invocation: no per-process cache. */
|
|
2584
|
+
dispatcher: () => Dispatcher
|
|
2585
|
+
advance: () => void
|
|
2586
|
+
now: () => number
|
|
2587
|
+
/** The provider's provisioning estimate. */
|
|
2588
|
+
estimateMs: number
|
|
2589
|
+
/** The latest provision request the provider received. */
|
|
2590
|
+
lastProvision: () => { adoptAbandoned?: boolean; generation?: number } | undefined
|
|
2591
|
+
}) {
|
|
2592
|
+
const { store } = opts
|
|
2593
|
+
type Measured = { reduced: Record<string, number>; appended: number }
|
|
2594
|
+
const results: Record<number, { deferred: Measured[]; adopted: Measured }> = {}
|
|
2595
|
+
for (const length of [100, 100_000]) {
|
|
2596
|
+
const slug = await opts.seed(length)
|
|
2597
|
+
await seedBuildFiller(store, slug, length)
|
|
2598
|
+
const generation = (await readBuildFacts(store, slug)).value.workspaceGenerations
|
|
2599
|
+
await store.append(slug, {
|
|
1884
2600
|
actor: DISPATCHER,
|
|
1885
|
-
type: '
|
|
1886
|
-
payload: {
|
|
2601
|
+
type: 'workspace.provision-started',
|
|
2602
|
+
payload: { provider: 'remote-test', branch: `ab/${slug}`, generation },
|
|
1887
2603
|
})
|
|
1888
|
-
await store.
|
|
2604
|
+
await store.append(slug, {
|
|
1889
2605
|
actor: DISPATCHER,
|
|
1890
|
-
type: '
|
|
1891
|
-
payload: {
|
|
2606
|
+
type: 'dispatch.failed',
|
|
2607
|
+
payload: {
|
|
2608
|
+
stage: 'workspace',
|
|
2609
|
+
attempt: 1,
|
|
2610
|
+
error: 'provisioning abandoned at dispatcher teardown',
|
|
2611
|
+
abandoned: 'teardown',
|
|
2612
|
+
},
|
|
1892
2613
|
})
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
2614
|
+
const short = () => opts.now() + opts.estimateMs - 1
|
|
2615
|
+
// An unmeasured deferring tick writes no provisioning fact, only its own
|
|
2616
|
+
// observations; then materialize every build-scoped value once, without a
|
|
2617
|
+
// kicking tick, which would itself start the continuation being measured.
|
|
2618
|
+
await opts.dispatcher().tick({ acceptNewWork: false, deadlineAt: short() })
|
|
2619
|
+
expect((await readBuildFacts(store, slug)).value.provisionMarker).toMatchObject({
|
|
2620
|
+
abandoned: 'teardown',
|
|
2621
|
+
generation,
|
|
2622
|
+
})
|
|
2623
|
+
for (const reducer of ['buildDigest', 'baseBranchValue', 'publishedBranchHeadValue'])
|
|
2624
|
+
await store.getReducerValue({ kind: 'build', slug }, { reducer })
|
|
2625
|
+
await readDispatchBudget(store, slug, true)
|
|
2626
|
+
const measure = async (deadlineAt?: () => number): Promise<Measured> => {
|
|
2627
|
+
const boundary = buildEventRows(store, slug).at(-1)!.seq
|
|
2628
|
+
const rows = { historicalRows: 0, tailRows: 0 }
|
|
2629
|
+
const reduced: Record<string, number> = {}
|
|
2630
|
+
const getReducerValue = store.getReducerValue.bind(store)
|
|
2631
|
+
store.getReducerValue = async (scope, request) => {
|
|
2632
|
+
if (scope.kind === 'build' && scope.slug === slug)
|
|
2633
|
+
reduced[request.reducer] = (reduced[request.reducer] ?? 0) + 1
|
|
2634
|
+
return getReducerValue(scope, request)
|
|
2635
|
+
}
|
|
2636
|
+
const restoreRows = instrumentBuildRows(store, slug, () => boundary, rows)
|
|
2637
|
+
try {
|
|
2638
|
+
opts.advance()
|
|
2639
|
+
const dispatcher = opts.dispatcher()
|
|
2640
|
+
await dispatcher.tick({
|
|
2641
|
+
acceptNewWork: false,
|
|
2642
|
+
...(deadlineAt === undefined ? {} : { deadlineAt: deadlineAt() }),
|
|
2643
|
+
})
|
|
2644
|
+
await dispatcher.drainProvisioning()
|
|
2645
|
+
} finally {
|
|
2646
|
+
restoreRows()
|
|
2647
|
+
Reflect.deleteProperty(store, 'getReducerValue')
|
|
2648
|
+
}
|
|
2649
|
+
expect(rows.historicalRows).toBe(0)
|
|
2650
|
+
return { reduced, appended: buildEventRows(store, slug).at(-1)!.seq - boundary }
|
|
2651
|
+
}
|
|
2652
|
+
const deferred = [await measure(short), await measure(short)]
|
|
2653
|
+
expect(deferred.map((tick) => tick.appended)).toEqual([0, 0])
|
|
2654
|
+
expect(deferred[1]).toEqual(deferred[0]!)
|
|
2655
|
+
const adopted = await measure()
|
|
2656
|
+
expect(opts.lastProvision()).toMatchObject({ adoptAbandoned: true })
|
|
2657
|
+
const types = buildEventRows(store, slug).map((event) => event.type)
|
|
2658
|
+
expect(types).not.toContain('infrastructure.failed')
|
|
2659
|
+
expect(types.at(-1)).toBe('workspace.provisioned')
|
|
2660
|
+
results[length] = { deferred, adopted }
|
|
2661
|
+
}
|
|
2662
|
+
expect(results[100]).toEqual(results[100_000]!)
|
|
2663
|
+
console.log('teardown adoption read budget', {
|
|
2664
|
+
histories: [100, 100_000],
|
|
2665
|
+
deferred: results[100_000]!.deferred[0],
|
|
2666
|
+
adopted: results[100_000]!.adopted,
|
|
2667
|
+
historicalRows: 0,
|
|
2668
|
+
})
|
|
2669
|
+
}
|
|
2670
|
+
|
|
2671
|
+
/** In-memory history seeding for preparation budgets; never used as a recurring read. */
|
|
2672
|
+
export async function seedPreparationHistory(
|
|
2673
|
+
store: BuildStore,
|
|
2674
|
+
repo: string,
|
|
2675
|
+
facts: number,
|
|
2676
|
+
/** Record the pending attempt's creation identity, keyed when `creationKey` is set. */
|
|
2677
|
+
creation?: { slug: string; creationKey?: string },
|
|
2678
|
+
) {
|
|
2679
|
+
await store.ensureRepo(repo)
|
|
2680
|
+
for (let i = 0; i < facts / 2; i++) {
|
|
2681
|
+
const ticket = { source: 'fake', id: `old-${i}` }
|
|
2682
|
+
const attempt = `historical-${i}`
|
|
2683
|
+
await store.appendRepo(repo, {
|
|
2684
|
+
actor: DISPATCHER,
|
|
2685
|
+
type: 'ticket-preparation.intended',
|
|
2686
|
+
payload: { attempt, ticket, readyState: 'Ready', claimedState: 'Doing' },
|
|
2687
|
+
})
|
|
2688
|
+
await store.appendRepo(repo, {
|
|
2689
|
+
actor: DISPATCHER,
|
|
2690
|
+
type: 'ticket-preparation.resolved',
|
|
2691
|
+
payload: { attempt, ticket, outcome: 'handed-back' },
|
|
2692
|
+
})
|
|
2693
|
+
}
|
|
2694
|
+
await store.appendRepo(repo, {
|
|
2695
|
+
actor: DISPATCHER,
|
|
1896
2696
|
type: 'ticket-preparation.intended',
|
|
1897
2697
|
payload: {
|
|
1898
2698
|
attempt: 'pending',
|
|
@@ -2037,7 +2837,7 @@ export async function nodePollingReadBudget(opts: {
|
|
|
2037
2837
|
await store.append(slug, {
|
|
2038
2838
|
actor: humanActor('budget'),
|
|
2039
2839
|
type: 'build.hold-requested',
|
|
2040
|
-
payload: {},
|
|
2840
|
+
payload: { reason: 'budget' },
|
|
2041
2841
|
})
|
|
2042
2842
|
await opts.tick()
|
|
2043
2843
|
const events = Reflect.get(store, 'builds').get(slug)
|
|
@@ -2401,6 +3201,155 @@ export async function stoppedOwnerWatchReadBudget() {
|
|
|
2401
3201
|
}
|
|
2402
3202
|
}
|
|
2403
3203
|
|
|
3204
|
+
/**
|
|
3205
|
+
* A no-slug CLI watch follows build announcements (AUT-1221). At 100 and
|
|
3206
|
+
* 100,000 journal events and pre-existing build events: attachment and quiet
|
|
3207
|
+
* passes read no event rows, a build announced mid-watch costs its own rows
|
|
3208
|
+
* and the appended journal rows, and resuming a cursor taken before an
|
|
3209
|
+
* announced build costs that gap — never the pre-existing build's log, which
|
|
3210
|
+
* is neither replayed nor reconstructed client-side.
|
|
3211
|
+
*/
|
|
3212
|
+
export async function cliWatchDiscoveryReadBudget() {
|
|
3213
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
3214
|
+
const { manualClock } = await import('./fixed')
|
|
3215
|
+
type Cost = { rows: number; buildRows: number; reducedCalls: number; own?: number }
|
|
3216
|
+
const costs: Record<string, Cost>[] = []
|
|
3217
|
+
for (const length of [100, 100_000]) {
|
|
3218
|
+
const clock = manualClock()
|
|
3219
|
+
const store = new MemoryBuildStore({ clock })
|
|
3220
|
+
await store.ensureRepo(repo)
|
|
3221
|
+
for (let i = 0; i < length; i++)
|
|
3222
|
+
await store.appendRepo(repo, {
|
|
3223
|
+
actor: humanActor('human'),
|
|
3224
|
+
type: 'dispatcher.intake-set',
|
|
3225
|
+
payload: { enabled: true },
|
|
3226
|
+
})
|
|
3227
|
+
await store.createBuild({ slug: 'old', repo })
|
|
3228
|
+
await store.append('old', {
|
|
3229
|
+
actor: KERNEL,
|
|
3230
|
+
type: 'runner.attached',
|
|
3231
|
+
payload: { instance: 'i1', host: 'h1', resumedFromSeq: 0 },
|
|
3232
|
+
})
|
|
3233
|
+
for (let i = 1; i < length; i++)
|
|
3234
|
+
await store.append('old', { actor: KERNEL, type: 'build.paused', payload: {} })
|
|
3235
|
+
let attempts = 0
|
|
3236
|
+
const announce = async (build: string) => {
|
|
3237
|
+
const attempt = `attempt-${++attempts}`
|
|
3238
|
+
const ticket = { source: 'fake', id: attempt }
|
|
3239
|
+
await store.appendRepo(repo, {
|
|
3240
|
+
actor: DISPATCHER,
|
|
3241
|
+
type: 'ticket-preparation.creation-selected',
|
|
3242
|
+
payload: { attempt, ticket, slug: build },
|
|
3243
|
+
})
|
|
3244
|
+
await store.createBuild({ slug: build, repo })
|
|
3245
|
+
await store.append(build, {
|
|
3246
|
+
actor: KERNEL,
|
|
3247
|
+
type: 'runner.attached',
|
|
3248
|
+
payload: { instance: 'i1', host: 'h1', resumedFromSeq: 0 },
|
|
3249
|
+
})
|
|
3250
|
+
for (const id of ['esc_1', 'esc_2'])
|
|
3251
|
+
await store.append(build, {
|
|
3252
|
+
actor: KERNEL,
|
|
3253
|
+
type: 'escalation.raised',
|
|
3254
|
+
payload: { id, phase: 'implement', round: 1, source: 'agent', question: id },
|
|
3255
|
+
})
|
|
3256
|
+
await store.appendRepo(repo, {
|
|
3257
|
+
actor: DISPATCHER,
|
|
3258
|
+
type: 'ticket-preparation.resolved',
|
|
3259
|
+
payload: { attempt, ticket, outcome: 'owned' },
|
|
3260
|
+
})
|
|
3261
|
+
}
|
|
3262
|
+
// Served values exist before the watch, as on any running repository.
|
|
3263
|
+
await readRepositoryFacts(store, repo)
|
|
3264
|
+
await readRepositoryAttention(store, repo)
|
|
3265
|
+
await readBuildDigests(store, repo)
|
|
3266
|
+
await readBuildStreamSeed(store, 'old')
|
|
3267
|
+
const fromStart: string[] = []
|
|
3268
|
+
const getEvents = store.getEvents.bind(store)
|
|
3269
|
+
store.getEvents = async (build, sinceSeq, opts) => {
|
|
3270
|
+
if (build === 'old' && (sinceSeq ?? 0) === 0) fromStart.push(build)
|
|
3271
|
+
return getEvents(build, sinceSeq, opts)
|
|
3272
|
+
}
|
|
3273
|
+
let counter = memoryRepositoryReadCounter(store, repo)
|
|
3274
|
+
const cost = (announced?: string): Cost => ({
|
|
3275
|
+
rows: counter.rows,
|
|
3276
|
+
buildRows: counter.buildRows,
|
|
3277
|
+
reducedCalls: counter.reducedCalls,
|
|
3278
|
+
...(announced !== undefined ? { own: counter.buildRowsBySlug.get(announced) ?? 0 } : {}),
|
|
3279
|
+
})
|
|
3280
|
+
const sample: Record<string, Cost> = {}
|
|
3281
|
+
const output: string[] = []
|
|
3282
|
+
let tick = 0
|
|
3283
|
+
const watch = (opts: { since?: string; timeout: string; signal?: AbortSignal }) =>
|
|
3284
|
+
abWatch({
|
|
3285
|
+
targetRepo: repo,
|
|
3286
|
+
env: {},
|
|
3287
|
+
exec,
|
|
3288
|
+
storeRef: '/budget',
|
|
3289
|
+
openStore: () => store,
|
|
3290
|
+
json: true,
|
|
3291
|
+
now: clock,
|
|
3292
|
+
stdout: (line) => output.push(line),
|
|
3293
|
+
stderr: (line) => {
|
|
3294
|
+
throw new Error(line)
|
|
3295
|
+
},
|
|
3296
|
+
delay: async () => {
|
|
3297
|
+
clock.advance(1000)
|
|
3298
|
+
tick++
|
|
3299
|
+
if (tick === 1) sample.attach = cost()
|
|
3300
|
+
if (tick === 2) sample.quiet = cost()
|
|
3301
|
+
if (tick === 3) {
|
|
3302
|
+
await announce('late')
|
|
3303
|
+
// The adapter counter wraps only builds that exist when it is made.
|
|
3304
|
+
counter = memoryRepositoryReadCounter(store, repo)
|
|
3305
|
+
}
|
|
3306
|
+
if (tick === 4) sample.announced = cost('late')
|
|
3307
|
+
if (tick === 5) sample.settled = cost()
|
|
3308
|
+
counter.reset()
|
|
3309
|
+
},
|
|
3310
|
+
...opts,
|
|
3311
|
+
})
|
|
3312
|
+
await watch({ timeout: '6' })
|
|
3313
|
+
const records = output.map((line) => JSON.parse(line) as { id?: string; cursor: string })
|
|
3314
|
+
expect(records.filter((r) => r.id !== undefined).map((r) => r.id)).toEqual([
|
|
3315
|
+
'build:late:2',
|
|
3316
|
+
'build:late:3',
|
|
3317
|
+
])
|
|
3318
|
+
const cursor = records.at(-1)!.cursor
|
|
3319
|
+
|
|
3320
|
+
// While no watch runs, another build is announced after the cursor.
|
|
3321
|
+
await announce('gap')
|
|
3322
|
+
counter = memoryRepositoryReadCounter(store, repo)
|
|
3323
|
+
output.length = 0
|
|
3324
|
+
await watch({ since: cursor, timeout: '1', signal: AbortSignal.abort() })
|
|
3325
|
+
sample.resume = cost('gap')
|
|
3326
|
+
expect(
|
|
3327
|
+
output
|
|
3328
|
+
.map((line) => JSON.parse(line) as { id?: string })
|
|
3329
|
+
.filter((r) => r.id !== undefined)
|
|
3330
|
+
.map((r) => r.id),
|
|
3331
|
+
).toEqual(['build:gap:2', 'build:gap:3'])
|
|
3332
|
+
|
|
3333
|
+
// Attachment and quiet passes read no event rows at all.
|
|
3334
|
+
for (const key of ['attach', 'quiet', 'settled']) {
|
|
3335
|
+
expect(sample[key]!.rows).toBe(0)
|
|
3336
|
+
expect(sample[key]!.buildRows).toBe(0)
|
|
3337
|
+
}
|
|
3338
|
+
// The new builds' rows are their own few events; journal rows the gap.
|
|
3339
|
+
expect(sample.announced!.own).toBeGreaterThan(0)
|
|
3340
|
+
expect(sample.announced!.own).toBeLessThanOrEqual(3 * 3)
|
|
3341
|
+
expect(sample.announced!.rows).toBeLessThanOrEqual(2 * 4)
|
|
3342
|
+
expect(sample.resume!.own).toBeGreaterThan(0)
|
|
3343
|
+
expect(sample.resume!.own).toBeLessThanOrEqual(3 * 3)
|
|
3344
|
+
expect(sample.resume!.rows).toBeLessThanOrEqual(2 * 4)
|
|
3345
|
+
// The pre-existing build's log is never read from the start.
|
|
3346
|
+
expect(fromStart).toEqual([])
|
|
3347
|
+
costs.push(sample)
|
|
3348
|
+
}
|
|
3349
|
+
// History-independent: every pass costs the same at both lengths.
|
|
3350
|
+
expect(costs[1]).toEqual(costs[0]!)
|
|
3351
|
+
}
|
|
3352
|
+
|
|
2404
3353
|
/** Fresh operator backends must not turn canonical build history into ticket requests. */
|
|
2405
3354
|
export async function operatorTicketAssociationBudget() {
|
|
2406
3355
|
const { MemoryBuildStore } = await import('../store/memory')
|
|
@@ -2596,6 +3545,8 @@ export async function hostedSeedReadBudget() {
|
|
|
2596
3545
|
const { REDUCERS } = await import('../kernel/reducer-registry')
|
|
2597
3546
|
const { repositoryAttentionReducer } = await import('../kernel/repository-attention')
|
|
2598
3547
|
const { buildStreamSeedReducer } = await import('../kernel/read-facts')
|
|
3548
|
+
const { deriveReducerVersion } = await import('../kernel/reducer-identity')
|
|
3549
|
+
const { REDUCER_REVISIONS } = await import('../kernel/reducer-revisions')
|
|
2599
3550
|
const gapCosts: number[] = []
|
|
2600
3551
|
for (const length of [100, 10_000]) {
|
|
2601
3552
|
const store = new MemoryBuildStore()
|
|
@@ -2688,6 +3639,33 @@ export async function hostedSeedReadBudget() {
|
|
|
2688
3639
|
if ('excluded' in entry) throw new Error('missing seed entry')
|
|
2689
3640
|
const create = entry.create
|
|
2690
3641
|
const validate = entry.validate
|
|
3642
|
+
const identity = create({}).identity!
|
|
3643
|
+
/** The ledger with `generation` synthetic revisions of this identity. */
|
|
3644
|
+
const ledger = (generation: number) => ({
|
|
3645
|
+
...REDUCER_REVISIONS,
|
|
3646
|
+
...Object.fromEntries(
|
|
3647
|
+
Array.from({ length: generation }, (_, index) => [
|
|
3648
|
+
`${identity}/shape/seedgen${String(index + 1).padStart(3, '0')}`,
|
|
3649
|
+
'read budget',
|
|
3650
|
+
]),
|
|
3651
|
+
),
|
|
3652
|
+
})
|
|
3653
|
+
// Generation 0: the ledger-derived identity the migration leaves in
|
|
3654
|
+
// place reuses every saved value and reads zero event rows.
|
|
3655
|
+
try {
|
|
3656
|
+
const reducer = create({})
|
|
3657
|
+
entry.create = () => ({
|
|
3658
|
+
...reducer,
|
|
3659
|
+
version: deriveReducerVersion({ identity, ledger: ledger(0) }),
|
|
3660
|
+
})
|
|
3661
|
+
expect(entry.create({}).version).toBe(reducer.version)
|
|
3662
|
+
counter.reset()
|
|
3663
|
+
await store.getStreamSeed(scope, requested)
|
|
3664
|
+
await new RepoViewStore(store, { repo }).getStreamSeed!(scope, requested)
|
|
3665
|
+
expect(counter.rows + counter.buildRows).toBe(0)
|
|
3666
|
+
} finally {
|
|
3667
|
+
entry.create = create
|
|
3668
|
+
}
|
|
2691
3669
|
entry.validate = (state) => {
|
|
2692
3670
|
if (!state || typeof state !== 'object') return false
|
|
2693
3671
|
const { addedByNewVersion, ...prior } = state as Record<string, unknown>
|
|
@@ -2700,7 +3678,7 @@ export async function hostedSeedReadBudget() {
|
|
|
2700
3678
|
const reducer = create({})
|
|
2701
3679
|
entry.create = () => ({
|
|
2702
3680
|
...reducer,
|
|
2703
|
-
version:
|
|
3681
|
+
version: deriveReducerVersion({ identity, ledger: ledger(generation) }),
|
|
2704
3682
|
initial: () => ({ ...reducer.initial(), addedByNewVersion: 0 }),
|
|
2705
3683
|
finish: (acc) => ({ ...reducer.finish(acc), addedByNewVersion: acc.addedByNewVersion }),
|
|
2706
3684
|
advance: (acc, events) => ({
|
|
@@ -2809,6 +3787,22 @@ export async function ticketRoleTickBudget(
|
|
|
2809
3787
|
now += 60_000
|
|
2810
3788
|
const forge = new FakeForge()
|
|
2811
3789
|
forge.seedBranch('main', sha)
|
|
3790
|
+
// Every tick observes a forge rate-limit reading: carrying it in tick
|
|
3791
|
+
// telemetry is in-memory and must not move the row bound below.
|
|
3792
|
+
Object.assign(forge, {
|
|
3793
|
+
observeRequests: (observer: import('../ports/forge-failure').ForgeRequestObserver) => {
|
|
3794
|
+
observer({
|
|
3795
|
+
outcome: 'restPrimary',
|
|
3796
|
+
rateLimit: {
|
|
3797
|
+
resource: 'core',
|
|
3798
|
+
limit: 5000,
|
|
3799
|
+
remaining: 4000,
|
|
3800
|
+
resetAt: new Date(now + 3_600_000).toISOString(),
|
|
3801
|
+
},
|
|
3802
|
+
})
|
|
3803
|
+
return () => {}
|
|
3804
|
+
},
|
|
3805
|
+
})
|
|
2812
3806
|
const dispatcher = new Dispatcher({
|
|
2813
3807
|
store,
|
|
2814
3808
|
tickets,
|
|
@@ -2831,6 +3825,7 @@ export async function ticketRoleTickBudget(
|
|
|
2831
3825
|
counter.reset()
|
|
2832
3826
|
const report = await dispatcher.tick()
|
|
2833
3827
|
costs.push(requests() - before)
|
|
3828
|
+
expect(report.forgeRequests?.rateLimits?.map((limit) => limit.remaining)).toEqual([4000])
|
|
2834
3829
|
expect(report.dispatched).toBe(0)
|
|
2835
3830
|
expect(report.dependencyBlocked).toBe(2)
|
|
2836
3831
|
expect(
|
|
@@ -3006,6 +4001,222 @@ export async function urgentIntakeReadBudget() {
|
|
|
3006
4001
|
return baseline!.calls[0]!
|
|
3007
4002
|
}
|
|
3008
4003
|
|
|
4004
|
+
/** Slot admission order (SPEC §12): urgent and normal parked builds waiting
|
|
4005
|
+
* on a full repository cost each idle tick zero historical rows, no append and
|
|
4006
|
+
* no ready listing inside the scan interval, at 100 and 100,000 events. Once
|
|
4007
|
+
* `free` opens one slot for the normal build, its first deferral forces one
|
|
4008
|
+
* listing; while its launch keeps being refused under the same deferral key,
|
|
4009
|
+
* idle ticks force no further listing and still read no history. */
|
|
4010
|
+
export async function slotAdmissionReadBudget(opts: {
|
|
4011
|
+
store: import('../store/memory').MemoryBuildStore
|
|
4012
|
+
/** The normal parked build; filler events extend its log. */
|
|
4013
|
+
slug: string
|
|
4014
|
+
tick: () => Promise<unknown>
|
|
4015
|
+
listed: () => number
|
|
4016
|
+
launched: () => number
|
|
4017
|
+
/** Advance the clock by a small fraction of the scan interval. */
|
|
4018
|
+
advance: () => void
|
|
4019
|
+
/** Advance the clock past the scan interval, so the next scan is due. */
|
|
4020
|
+
advanceDue: () => void
|
|
4021
|
+
free: () => Promise<void>
|
|
4022
|
+
}): Promise<void> {
|
|
4023
|
+
const { store, slug } = opts
|
|
4024
|
+
const events = buildEventRows(store, slug)
|
|
4025
|
+
const appended = () => {
|
|
4026
|
+
let total = 0
|
|
4027
|
+
for (const build of (
|
|
4028
|
+
Reflect.get(store, 'builds') as Map<string, { events: unknown[] }>
|
|
4029
|
+
).values())
|
|
4030
|
+
total += build.events.length
|
|
4031
|
+
for (const repo of (Reflect.get(store, 'repos') as Map<string, { events: unknown[] }>).values())
|
|
4032
|
+
total += repo.events.length
|
|
4033
|
+
return total
|
|
4034
|
+
}
|
|
4035
|
+
const idle = async (ticks: number) => {
|
|
4036
|
+
const boundary = events.at(-1)!.seq
|
|
4037
|
+
const metrics = { historicalRows: 0, tailRows: 0 }
|
|
4038
|
+
const restore = instrumentBuildRows(store, slug, () => boundary, metrics)
|
|
4039
|
+
const before = { listed: opts.listed(), launched: opts.launched(), appended: appended() }
|
|
4040
|
+
try {
|
|
4041
|
+
for (let tick = 0; tick < ticks; tick++) {
|
|
4042
|
+
opts.advance()
|
|
4043
|
+
await opts.tick()
|
|
4044
|
+
}
|
|
4045
|
+
} finally {
|
|
4046
|
+
restore()
|
|
4047
|
+
}
|
|
4048
|
+
expect(metrics.historicalRows).toBe(0)
|
|
4049
|
+
expect(opts.listed() - before.listed).toBe(0)
|
|
4050
|
+
expect(opts.launched() - before.launched).toBe(0)
|
|
4051
|
+
expect(appended() - before.appended).toBe(0)
|
|
4052
|
+
}
|
|
4053
|
+
let filler = 0
|
|
4054
|
+
for (const length of [100, 100_000]) {
|
|
4055
|
+
while (events.length < length)
|
|
4056
|
+
await store.append(slug, {
|
|
4057
|
+
actor: humanActor('budget'),
|
|
4058
|
+
type: 'build.auto-merge-cancelled',
|
|
4059
|
+
payload: {},
|
|
4060
|
+
})
|
|
4061
|
+
filler++
|
|
4062
|
+
// Warm the saved reduced values past the filler, and past the warm
|
|
4063
|
+
// tick's own acknowledgement, before measuring; the idle window that
|
|
4064
|
+
// follows sits inside one scan interval.
|
|
4065
|
+
opts.advanceDue()
|
|
4066
|
+
await opts.tick()
|
|
4067
|
+
opts.advance()
|
|
4068
|
+
await opts.tick()
|
|
4069
|
+
await idle(3)
|
|
4070
|
+
}
|
|
4071
|
+
expect(filler).toBe(2)
|
|
4072
|
+
await opts.free()
|
|
4073
|
+
opts.advance()
|
|
4074
|
+
const listed = opts.listed()
|
|
4075
|
+
await opts.tick()
|
|
4076
|
+
// The first deferral forces one listing and admits the build after it.
|
|
4077
|
+
expect(opts.listed() - listed).toBe(1)
|
|
4078
|
+
await idle(3)
|
|
4079
|
+
}
|
|
4080
|
+
|
|
4081
|
+
/** Open-PR backpressure (SPEC §12 Intake order) counts open root PRs over the
|
|
4082
|
+
* capacity builds the tick already loaded and reads its engagement from the
|
|
4083
|
+
* advanced repository view: a quiet intake tick with backpressure engaged
|
|
4084
|
+
* costs no more store rows or ticket-source requests than the same tick with
|
|
4085
|
+
* it disabled, at 100 and 100,000 repository events, and a steady engaged
|
|
4086
|
+
* state appends nothing. */
|
|
4087
|
+
export async function openPrBackpressureReadBudget() {
|
|
4088
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
4089
|
+
const sha = 'a'.repeat(40)
|
|
4090
|
+
const plain =
|
|
4091
|
+
'[tickets]\nsource = "hosted"\nteamKey = "ENG"\n[verify]\nsteps = []\n[finalize]\nsteps = []\n'
|
|
4092
|
+
const methods = ['listReady', 'get', 'dependencyStates', 'listAll'] as const
|
|
4093
|
+
const results = new Map<string, { calls: Record<string, number>[]; rows: number[] }>()
|
|
4094
|
+
for (const engaged of [false, true]) {
|
|
4095
|
+
const config = parseConfig(engaged ? `${plain}[policy]\nmaxOpenPrs = 1\n` : plain)
|
|
4096
|
+
for (const length of [100, 100_000]) {
|
|
4097
|
+
const source = new FakeTicketSource([], { createState: 'triage', doneState: 'done' })
|
|
4098
|
+
const calls: Record<string, number> = Object.fromEntries(methods.map((name) => [name, 0]))
|
|
4099
|
+
const tickets = new Proxy(source, {
|
|
4100
|
+
get(target, key) {
|
|
4101
|
+
const value = Reflect.get(target, key, target)
|
|
4102
|
+
if (typeof value !== 'function') return value
|
|
4103
|
+
return (...args: unknown[]) => {
|
|
4104
|
+
if (typeof key === 'string' && key in calls) calls[key]! += 1
|
|
4105
|
+
return value.apply(target, args)
|
|
4106
|
+
}
|
|
4107
|
+
},
|
|
4108
|
+
})
|
|
4109
|
+
// Every ready ticket is blocked, so the disabled baseline claims nothing either.
|
|
4110
|
+
const blocker = await source.create({ title: 'Unresolved blocker', body: 'Budget' })
|
|
4111
|
+
for (const title of ['N1', 'N2']) {
|
|
4112
|
+
const ticket = await source.create({ title, body: 'Budget' })
|
|
4113
|
+
await source.addBlocker(ticket.ref.id, blocker.ref.id)
|
|
4114
|
+
await source.transition(ticket.ref.id, 'ready')
|
|
4115
|
+
}
|
|
4116
|
+
|
|
4117
|
+
let now = 1_800_000_000_000
|
|
4118
|
+
const clock = () => new Date(now)
|
|
4119
|
+
const store = new MemoryBuildStore({ clock })
|
|
4120
|
+
const repo = `https://github.com/budget/open-pr-backpressure-${engaged}-${length}`
|
|
4121
|
+
await store.ensureRepo(repo)
|
|
4122
|
+
// One open root PR, in both variants.
|
|
4123
|
+
const slug = 'open-pr'
|
|
4124
|
+
await store.createBuild({ slug, repo, branch: `ab/${slug}` })
|
|
4125
|
+
await store.append(slug, {
|
|
4126
|
+
actor: DISPATCHER,
|
|
4127
|
+
type: 'build.created',
|
|
4128
|
+
payload: { ticket: { source: 'hosted', id: 'OPEN' }, repo, baseBranch: 'main' },
|
|
4129
|
+
})
|
|
4130
|
+
await store.append(slug, { actor: DISPATCHER, type: 'build.paused', payload: {} })
|
|
4131
|
+
await store.append(slug, {
|
|
4132
|
+
actor: KERNEL,
|
|
4133
|
+
type: 'finalize.completed',
|
|
4134
|
+
payload: { pr: { number: 1, url: 'https://github.com/budget/pr/1', headSha: sha } },
|
|
4135
|
+
})
|
|
4136
|
+
for (let i = 0; i < length - (engaged ? 1 : 0); i++)
|
|
4137
|
+
await store.appendRepo(repo, {
|
|
4138
|
+
actor: humanActor('budget'),
|
|
4139
|
+
type: 'dispatcher.intake-set',
|
|
4140
|
+
payload: { enabled: true },
|
|
4141
|
+
})
|
|
4142
|
+
if (engaged)
|
|
4143
|
+
await store.appendRepo(repo, {
|
|
4144
|
+
actor: DISPATCHER,
|
|
4145
|
+
type: 'dispatcher.open-pr-backpressure-engaged',
|
|
4146
|
+
payload: { openPrs: 1, maxOpenPrs: 1, resumeOpenPrs: 0, excludeHeld: false },
|
|
4147
|
+
})
|
|
4148
|
+
// The one serialized reduction per key happens before the measured ticks.
|
|
4149
|
+
await readRepositoryFacts(store, repo)
|
|
4150
|
+
await readBuildDigests(store, repo)
|
|
4151
|
+
const counter = memoryRepositoryReadCounter(store, repo)
|
|
4152
|
+
const perTick: Record<string, number>[] = []
|
|
4153
|
+
const rows: number[] = []
|
|
4154
|
+
for (let tick = 0; tick < 3; tick++) {
|
|
4155
|
+
now += 60_000
|
|
4156
|
+
const forge = new FakeForge()
|
|
4157
|
+
forge.seedBranch('main', sha)
|
|
4158
|
+
const dispatcher = new Dispatcher({
|
|
4159
|
+
store,
|
|
4160
|
+
tickets,
|
|
4161
|
+
workspaces: new FakeWorkspaceProvider({
|
|
4162
|
+
root: '/open-pr-backpressure-budget',
|
|
4163
|
+
mode: 'logical',
|
|
4164
|
+
base: { source: 'remote', sha },
|
|
4165
|
+
}),
|
|
4166
|
+
forge,
|
|
4167
|
+
config,
|
|
4168
|
+
repo,
|
|
4169
|
+
exec: async () => ({ stdout: `${sha}\trefs/heads/main\n`, stderr: '', exitCode: 0 }),
|
|
4170
|
+
launchRunner: async () => {
|
|
4171
|
+
throw new Error('no launches in the open-PR backpressure budget')
|
|
4172
|
+
},
|
|
4173
|
+
ids: sequentialIds(),
|
|
4174
|
+
clock,
|
|
4175
|
+
})
|
|
4176
|
+
const before = { ...calls }
|
|
4177
|
+
const appended = (await store.getRepoEvents(repo)).length
|
|
4178
|
+
counter.reset()
|
|
4179
|
+
const report = await dispatcher.tick()
|
|
4180
|
+
expect(report.dispatched).toBe(0)
|
|
4181
|
+
// The warm-up tick makes the once-per-key reductions the open PR's
|
|
4182
|
+
// forge work needs (forge health); later ticks are measured.
|
|
4183
|
+
if (tick > 0) {
|
|
4184
|
+
perTick.push(
|
|
4185
|
+
Object.fromEntries(methods.map((name) => [name, calls[name]! - before[name]!])),
|
|
4186
|
+
)
|
|
4187
|
+
rows.push(counter.rows)
|
|
4188
|
+
expect(counter.rows).toBeLessThanOrEqual(32)
|
|
4189
|
+
}
|
|
4190
|
+
// A steady state records no backpressure transition.
|
|
4191
|
+
expect(
|
|
4192
|
+
(await store.getRepoEvents(repo, appended)).filter((event) =>
|
|
4193
|
+
event.type.startsWith('dispatcher.open-pr-backpressure-'),
|
|
4194
|
+
),
|
|
4195
|
+
).toEqual([])
|
|
4196
|
+
await readRepositoryFacts(store, repo)
|
|
4197
|
+
await readBuildDigests(store, repo)
|
|
4198
|
+
counter.reset()
|
|
4199
|
+
await readRepositoryFacts(store, repo)
|
|
4200
|
+
await readBuildDigests(store, repo)
|
|
4201
|
+
expect(counter.rows).toBe(0)
|
|
4202
|
+
}
|
|
4203
|
+
results.set(`${engaged}:${length}`, { calls: perTick, rows })
|
|
4204
|
+
await store.close()
|
|
4205
|
+
}
|
|
4206
|
+
}
|
|
4207
|
+
const disabled = results.get('false:100')!
|
|
4208
|
+
expect(results.get('false:100000')).toEqual(disabled)
|
|
4209
|
+
const engaged = results.get('true:100')!
|
|
4210
|
+
expect(results.get('true:100000')).toEqual(engaged)
|
|
4211
|
+
// Paused intake skips the dependency preflight, so it can only save.
|
|
4212
|
+
engaged.calls.forEach((tick, index) => {
|
|
4213
|
+
for (const name of methods)
|
|
4214
|
+
expect(tick[name]).toBeLessThanOrEqual(disabled.calls[index]![name]!)
|
|
4215
|
+
expect(engaged.rows[index]).toBeLessThanOrEqual(disabled.rows[index]!)
|
|
4216
|
+
})
|
|
4217
|
+
return { disabled, engaged }
|
|
4218
|
+
}
|
|
4219
|
+
|
|
3009
4220
|
/** Native identity maintenance (SPEC §15.7) adds one forge identity read per
|
|
3010
4221
|
* armed, eligible poll and nothing else: a fresh dispatcher's quiet
|
|
3011
4222
|
* maintenance tick reads no history, spends exactly the store reads of the same
|
|
@@ -3513,8 +4724,14 @@ export async function headPathsLandingReadBudget(opts: {
|
|
|
3513
4724
|
advance: (ms: number) => void
|
|
3514
4725
|
/** Git commands attempted so far. */
|
|
3515
4726
|
git: () => readonly string[][]
|
|
4727
|
+
/** Seeds the forge's checks at the PR head. With it, the head turns red
|
|
4728
|
+
* after the first warm-up: exactly one `pr.checks-failed` is recorded and
|
|
4729
|
+
* an unchanged red head then costs the poll no extra store request. */
|
|
4730
|
+
failingChecks?: { set: (checks: import('../ports/types').HeadChecks) => void }
|
|
3516
4731
|
}) {
|
|
3517
4732
|
const { store, repo, slug } = opts
|
|
4733
|
+
const ciFailures = async () =>
|
|
4734
|
+
(await store.getEvents(slug)).filter((event) => event.type === 'pr.checks-failed').length
|
|
3518
4735
|
/** The commands that derive a head's path facts. */
|
|
3519
4736
|
const pathFact = /^(merge-base|diff|merge-tree|worktree|cherry-pick|write-tree)$/
|
|
3520
4737
|
const { candidateHeadPaths, HEAD_PATHS_ARTIFACT, HEAD_PATHS_PREVIEW } = await import(
|
|
@@ -3552,6 +4769,18 @@ export async function headPathsLandingReadBudget(opts: {
|
|
|
3552
4769
|
opts.advance(120_000)
|
|
3553
4770
|
await opts.tick()
|
|
3554
4771
|
}
|
|
4772
|
+
if (opts.failingChecks && length === 100) {
|
|
4773
|
+
opts.failingChecks.set({
|
|
4774
|
+
kind: 'known',
|
|
4775
|
+
pending: false,
|
|
4776
|
+
failing: [{ name: 'unit', source: 'check-run', conclusion: 'failure' }],
|
|
4777
|
+
})
|
|
4778
|
+
for (let n = 0; n < 2; n++) {
|
|
4779
|
+
opts.advance(120_000)
|
|
4780
|
+
await opts.tick()
|
|
4781
|
+
}
|
|
4782
|
+
expect(await ciFailures()).toBe(1)
|
|
4783
|
+
}
|
|
3555
4784
|
if (opts.warm) {
|
|
3556
4785
|
const landing = (await store.getEvents(slug)).filter(
|
|
3557
4786
|
(event) => event.type === 'landing.decided' || event.type === 'landing.deferred',
|
|
@@ -3623,6 +4852,8 @@ export async function headPathsLandingReadBudget(opts: {
|
|
|
3623
4852
|
store.getArtifact = getArtifact
|
|
3624
4853
|
}
|
|
3625
4854
|
expect(vectors[1]).toEqual(vectors[0])
|
|
4855
|
+
// A red head is recorded once and never re-emitted while it stays red.
|
|
4856
|
+
if (opts.failingChecks) expect(await ciFailures()).toBe(1)
|
|
3626
4857
|
const answer = candidateHeadPaths((await readBuildFacts(store, slug)).value.state)
|
|
3627
4858
|
expect(answer.recorded).toBe(opts.recorded)
|
|
3628
4859
|
if (answer.recorded) {
|
|
@@ -4169,3 +5400,2193 @@ export async function hookReadBudget(): Promise<void> {
|
|
|
4169
5400
|
}
|
|
4170
5401
|
expect(measured[1]).toEqual(measured[0])
|
|
4171
5402
|
}
|
|
5403
|
+
|
|
5404
|
+
/**
|
|
5405
|
+
* Optimization node reads (SPEC §15.5, RFC 0005 §11.2). For a node with 10
|
|
5406
|
+
* and with 10,000 settled attempts, each attempt a build with its own log:
|
|
5407
|
+
*
|
|
5408
|
+
* 1. the stop and admission inputs come from the node's reduced digest in
|
|
5409
|
+
* BuildState: an identical request vector and a digest of the same size at
|
|
5410
|
+
* both histories;
|
|
5411
|
+
* 2. idle reads read zero event rows;
|
|
5412
|
+
* 3. one new `attempt.settled` costs exactly its own node row;
|
|
5413
|
+
* 4. the ledger advances with only the new node rows, through the store and
|
|
5414
|
+
* through a fresh repository view over it;
|
|
5415
|
+
* 5. the objective row (RFC 0005 §12) on the terminal dashboard poll, in the
|
|
5416
|
+
* status summary and from `builds.get` comes from that same digest: an
|
|
5417
|
+
* idle poll reads zero event rows with an identical request vector, and a
|
|
5418
|
+
* row of the same size, at both histories; and
|
|
5419
|
+
* 6. no measured read ever touches an attempt build's log; and
|
|
5420
|
+
* 7. once the node stops, the dispatcher's stop duty reads at most one
|
|
5421
|
+
* reduced `buildFacts` per unmerged in-flight attempt build not mid-abort, zero
|
|
5422
|
+
* event rows while idle, and never a settled or aborted attempt's build.
|
|
5423
|
+
*/
|
|
5424
|
+
export async function optimizationReadBudget(): Promise<void> {
|
|
5425
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
5426
|
+
const { commandObjective } = await import('../kernel/generators/optimization-log')
|
|
5427
|
+
const {
|
|
5428
|
+
optimizationAdmission,
|
|
5429
|
+
optimizationProposerAdmissible,
|
|
5430
|
+
optimizationStopCause,
|
|
5431
|
+
optimizationStopEligibility,
|
|
5432
|
+
} = await import('../kernel/optimization')
|
|
5433
|
+
const { enforceOptimizationStop } = await import('../processes/optimization-stop')
|
|
5434
|
+
const { reconcileMergedAttempts } = await import('../processes/optimization-merges')
|
|
5435
|
+
const { readBuildDigests, readOptimizationLedger } = await import('../store/reduced-reads')
|
|
5436
|
+
const { readAttemptContext } = await import('../cli/attempt')
|
|
5437
|
+
const { objectiveSummary } = await import('../cli/dashboard/objective-row')
|
|
5438
|
+
const { summarizeFrom } = await import('../cli/status')
|
|
5439
|
+
const { getOperatorBuild } = await import('../operator/query')
|
|
5440
|
+
const repo = '/budget/optimization'
|
|
5441
|
+
const node = 'opt-node'
|
|
5442
|
+
const sha = (n: number) => n.toString(16).padStart(40, '0')
|
|
5443
|
+
const now = new Date('2026-11-18T00:00:00Z')
|
|
5444
|
+
const config = parseConfig(
|
|
5445
|
+
'[tickets]\nsource="fake"\nreadyState="ready"\n[verify]\nsteps=[]\n[finalize]\nsteps=[]',
|
|
5446
|
+
)
|
|
5447
|
+
const { verify: _verify, finalize: _finalize, ...root } = config
|
|
5448
|
+
const measured: {
|
|
5449
|
+
vector: Record<string, number>
|
|
5450
|
+
digest: number
|
|
5451
|
+
attempt: Record<string, number>
|
|
5452
|
+
migrated: Record<string, number>
|
|
5453
|
+
poll: Record<string, number>
|
|
5454
|
+
objectiveRow: number
|
|
5455
|
+
stopVector: Record<string, number>
|
|
5456
|
+
slotPoll: Record<string, number>
|
|
5457
|
+
slotDigest: number
|
|
5458
|
+
reconcileFirst: Record<string, number>
|
|
5459
|
+
reconcileIdle: Record<string, number>
|
|
5460
|
+
}[] = []
|
|
5461
|
+
for (const attempts of [10, 10_000]) {
|
|
5462
|
+
const store = new MemoryBuildStore()
|
|
5463
|
+
await store.ensureRepo(repo)
|
|
5464
|
+
const configArtifact = await store.putRepoArtifact(repo, {
|
|
5465
|
+
kind: 'dispatcher-effective-config',
|
|
5466
|
+
content: JSON.stringify({ ...root, verify: { steps: [] }, finalize: { steps: [] } }),
|
|
5467
|
+
})
|
|
5468
|
+
await store.appendRepo(repo, {
|
|
5469
|
+
actor: DISPATCHER,
|
|
5470
|
+
type: 'dispatcher.run-started',
|
|
5471
|
+
payload: {
|
|
5472
|
+
run: 'budget-run',
|
|
5473
|
+
pid: 1,
|
|
5474
|
+
roleWarnings: [],
|
|
5475
|
+
effectiveConfig: { kind: configArtifact.kind, rev: configArtifact.revision },
|
|
5476
|
+
},
|
|
5477
|
+
})
|
|
5478
|
+
await store.createBuild({ slug: node, repo, branch: 'ab-node/opt-node' })
|
|
5479
|
+
await store.append(node, {
|
|
5480
|
+
actor: DISPATCHER,
|
|
5481
|
+
type: 'build.created',
|
|
5482
|
+
payload: { repo, ticket: { source: 'fake', id: 'NODE' }, baseBranch: 'main', kind: 'node' },
|
|
5483
|
+
})
|
|
5484
|
+
await store.append(node, {
|
|
5485
|
+
actor: DISPATCHER,
|
|
5486
|
+
type: 'optimization.objective-accepted',
|
|
5487
|
+
payload: {
|
|
5488
|
+
objective: commandObjective({ budget: { maxAttempts: 20_000 } }),
|
|
5489
|
+
revision: 1,
|
|
5490
|
+
harnessPin: sha(1),
|
|
5491
|
+
specRev: 0,
|
|
5492
|
+
},
|
|
5493
|
+
})
|
|
5494
|
+
await store.append(node, { actor: DISPATCHER, type: 'node.opened', payload: { sha: sha(1) } })
|
|
5495
|
+
await store.append(node, {
|
|
5496
|
+
actor: KERNEL,
|
|
5497
|
+
type: 'optimization.baseline-measured',
|
|
5498
|
+
payload: { revision: 1, head: sha(1), harnessPin: sha(1), samples: 7, median: 50, spread: 1 },
|
|
5499
|
+
})
|
|
5500
|
+
const proposal = (i: number) => ({
|
|
5501
|
+
id: `p${i}`,
|
|
5502
|
+
ticket: { source: 'fake', id: `A-${i}` },
|
|
5503
|
+
title: `Attempt ${i}`,
|
|
5504
|
+
strategy: `strategy ${i}`,
|
|
5505
|
+
})
|
|
5506
|
+
for (let batch = 0; batch < attempts; batch += 4) {
|
|
5507
|
+
const ids = Array.from({ length: Math.min(4, attempts - batch) }, (_, k) => batch + k)
|
|
5508
|
+
await store.append(node, {
|
|
5509
|
+
actor: DISPATCHER,
|
|
5510
|
+
type: 'optimization.attempts-proposed',
|
|
5511
|
+
payload: { request: `r${batch}`, proposals: ids.map(proposal) },
|
|
5512
|
+
})
|
|
5513
|
+
for (const i of ids) {
|
|
5514
|
+
const slug = `attempt-${i}`
|
|
5515
|
+
await store.createBuild({ slug, repo, branch: `ab/${slug}` })
|
|
5516
|
+
await store.append(slug, {
|
|
5517
|
+
actor: DISPATCHER,
|
|
5518
|
+
type: 'build.created',
|
|
5519
|
+
payload: { repo, ticket: proposal(i).ticket, baseBranch: 'ab-node/opt-node' },
|
|
5520
|
+
})
|
|
5521
|
+
const accepted = i % 50 === 0
|
|
5522
|
+
const delta = accepted ? 1 : (i % 3) * 0.1
|
|
5523
|
+
await store.append(slug, {
|
|
5524
|
+
actor: KERNEL,
|
|
5525
|
+
type: 'attempt.measured',
|
|
5526
|
+
payload: {
|
|
5527
|
+
request: `m${i}`,
|
|
5528
|
+
candidate: sha(i + 2),
|
|
5529
|
+
baseline: sha(1),
|
|
5530
|
+
harnessPin: sha(1),
|
|
5531
|
+
revision: 1,
|
|
5532
|
+
samples: 7,
|
|
5533
|
+
medians: { candidate: 50 - delta, baseline: 50 },
|
|
5534
|
+
delta,
|
|
5535
|
+
decision: accepted ? 'improved' : 'no-improvement',
|
|
5536
|
+
},
|
|
5537
|
+
})
|
|
5538
|
+
await store.append(node, {
|
|
5539
|
+
actor: DISPATCHER,
|
|
5540
|
+
type: 'attempt.settled',
|
|
5541
|
+
payload: {
|
|
5542
|
+
attempt: { proposal: `p${i}`, ticket: proposal(i).ticket, build: slug },
|
|
5543
|
+
outcome: accepted ? 'accepted' : i % 2 ? 'declined' : 'no-improvement',
|
|
5544
|
+
...(accepted || i % 2 === 0
|
|
5545
|
+
? { measurement: { revision: 1, baseline: 50, candidate: 50 - delta, delta } }
|
|
5546
|
+
: {}),
|
|
5547
|
+
},
|
|
5548
|
+
})
|
|
5549
|
+
// The node sweep's committed rejected-role move.
|
|
5550
|
+
if (!accepted)
|
|
5551
|
+
await store.append(node, {
|
|
5552
|
+
actor: DISPATCHER,
|
|
5553
|
+
type: 'attempt.ticket-rejected',
|
|
5554
|
+
payload: { proposal: `p${i}`, ticket: proposal(i).ticket, state: 'Rejected' },
|
|
5555
|
+
})
|
|
5556
|
+
}
|
|
5557
|
+
}
|
|
5558
|
+
// Two in-flight attempts: one under the configured source, and one whose
|
|
5559
|
+
// proposal predates a recorded migration to the `hosted` source.
|
|
5560
|
+
const live = { source: 'fake', id: 'LIVE' }
|
|
5561
|
+
const moved = { source: 'old', id: 'OLD-1' }
|
|
5562
|
+
await store.append(node, {
|
|
5563
|
+
actor: DISPATCHER,
|
|
5564
|
+
type: 'optimization.attempts-proposed',
|
|
5565
|
+
payload: {
|
|
5566
|
+
request: 'live',
|
|
5567
|
+
proposals: [
|
|
5568
|
+
{ id: 'p-live', ticket: live, title: 'Live', strategy: 'live' },
|
|
5569
|
+
{ id: 'p-moved', ticket: moved, title: 'Moved', strategy: 'moved' },
|
|
5570
|
+
],
|
|
5571
|
+
},
|
|
5572
|
+
})
|
|
5573
|
+
await store.appendRepo(repo, {
|
|
5574
|
+
actor: { kind: 'human', user: 'operator' },
|
|
5575
|
+
type: 'tickets.migration-recorded',
|
|
5576
|
+
payload: {
|
|
5577
|
+
identity: 'old-to-hosted',
|
|
5578
|
+
from: 'old',
|
|
5579
|
+
to: 'hosted',
|
|
5580
|
+
mapping: { 'OLD-1': 'H-1' },
|
|
5581
|
+
},
|
|
5582
|
+
})
|
|
5583
|
+
const child = async (slug: string, ticket: { source: string; id: string }, target = true) => {
|
|
5584
|
+
await store.createBuild({ slug, repo, branch: `ab/${slug}` })
|
|
5585
|
+
await store.append(slug, {
|
|
5586
|
+
actor: DISPATCHER,
|
|
5587
|
+
type: 'build.created',
|
|
5588
|
+
payload: {
|
|
5589
|
+
repo,
|
|
5590
|
+
ticket,
|
|
5591
|
+
baseBranch: 'ab-node/opt-node',
|
|
5592
|
+
...(target ? { target: { ticket: { source: 'fake', id: 'NODE' }, build: node } } : {}),
|
|
5593
|
+
},
|
|
5594
|
+
})
|
|
5595
|
+
const state = (await readBuildFacts(store, slug)).value.state
|
|
5596
|
+
return { slug, state, repo, ticket }
|
|
5597
|
+
}
|
|
5598
|
+
const liveChild = await child('live-child', live)
|
|
5599
|
+
const movedChild = await child('moved-child', { source: 'hosted', id: 'H-1' })
|
|
5600
|
+
const plainChild = await child('plain-child', { source: 'fake', id: 'PLAIN' }, false)
|
|
5601
|
+
// Warm-up: each reduced key is computed once and saved.
|
|
5602
|
+
await readBuildFacts(store, node)
|
|
5603
|
+
await readOptimizationLedger(store, node)
|
|
5604
|
+
await readRepositoryFacts(store, repo)
|
|
5605
|
+
const rows = memoryRepositoryReadCounter(store, repo)
|
|
5606
|
+
const requests = memoryStoreRequestCounter(store)
|
|
5607
|
+
const attemptRows = () => [...rows.buildRowsBySlug].filter(([slug]) => slug !== node)
|
|
5608
|
+
try {
|
|
5609
|
+
// 1. The stop and admission inputs: one reduced read, from the digest.
|
|
5610
|
+
const state = (await readBuildFacts(store, node)).value.state
|
|
5611
|
+
const digest = state.optimization!
|
|
5612
|
+
expect(digest.attempts.filed).toBe(attempts + 2)
|
|
5613
|
+
expect(digest.inFlight.map((attempt) => attempt.proposal)).toEqual(['p-live', 'p-moved'])
|
|
5614
|
+
optimizationStopEligibility(digest, now)
|
|
5615
|
+
optimizationStopCause(digest, now)
|
|
5616
|
+
optimizationProposerAdmissible(digest, now)
|
|
5617
|
+
optimizationAdmission(digest, now)
|
|
5618
|
+
const vector = requests.vector()
|
|
5619
|
+
const digestSize = JSON.stringify(digest).length
|
|
5620
|
+
expect(rows.buildRows).toBe(0)
|
|
5621
|
+
|
|
5622
|
+
// 1b. Attempt resolution (`ab context`, `ab done`) reads the node's
|
|
5623
|
+
// served value once, plus the repository's only for an optimization
|
|
5624
|
+
// node; a build without a target reads nothing. No event rows, and no
|
|
5625
|
+
// attempt log.
|
|
5626
|
+
requests.reset()
|
|
5627
|
+
const resolved = await readAttemptContext(store, {
|
|
5628
|
+
...liveChild,
|
|
5629
|
+
ticketSource: async () => 'fake',
|
|
5630
|
+
})
|
|
5631
|
+
expect(resolved?.attempt.proposal).toBe('p-live')
|
|
5632
|
+
const attemptVector = requests.vector()
|
|
5633
|
+
expect(attemptVector).toEqual({ getRepo: 1, getReducerValue: 2 })
|
|
5634
|
+
requests.reset()
|
|
5635
|
+
const migrated = await readAttemptContext(store, {
|
|
5636
|
+
...movedChild,
|
|
5637
|
+
ticketSource: async () => 'hosted',
|
|
5638
|
+
})
|
|
5639
|
+
expect(migrated?.attempt.proposal).toBe('p-moved')
|
|
5640
|
+
const migratedVector = requests.vector()
|
|
5641
|
+
requests.reset()
|
|
5642
|
+
expect(
|
|
5643
|
+
await readAttemptContext(store, { ...plainChild, ticketSource: async () => 'fake' }),
|
|
5644
|
+
).toBeUndefined()
|
|
5645
|
+
expect(requests.vector()).toEqual({})
|
|
5646
|
+
expect(rows.buildRows).toBe(0)
|
|
5647
|
+
|
|
5648
|
+
// 1c. The objective row. The dashboard reader lists only the node: the
|
|
5649
|
+
// live attempt builds are other rows, outside this surface's cost.
|
|
5650
|
+
const record = (await store.getBuild(node))!
|
|
5651
|
+
const nodeOnly = new Proxy(store, {
|
|
5652
|
+
get(target, property) {
|
|
5653
|
+
if (property === 'listBuildsForRepo') return async () => [record]
|
|
5654
|
+
const value = Reflect.get(target, property)
|
|
5655
|
+
return typeof value === 'function' ? value.bind(target) : value
|
|
5656
|
+
},
|
|
5657
|
+
}) as BuildStore
|
|
5658
|
+
const dashboard = new DashboardBuildPollCache(
|
|
5659
|
+
{
|
|
5660
|
+
listBuildsForRepo: async () => [record],
|
|
5661
|
+
getEvents: store.getEvents.bind(store),
|
|
5662
|
+
getReducerValue: store.getReducerValue.bind(store),
|
|
5663
|
+
},
|
|
5664
|
+
repo,
|
|
5665
|
+
config,
|
|
5666
|
+
)
|
|
5667
|
+
await dashboard.refresh()
|
|
5668
|
+
rows.reset()
|
|
5669
|
+
requests.reset()
|
|
5670
|
+
const polled = (await dashboard.refresh()).builds.find((build) => build.slug === node)
|
|
5671
|
+
const pollVector = requests.vector()
|
|
5672
|
+
expect(polled?.objectiveRow?.attempts.filed).toBe(attempts + 2)
|
|
5673
|
+
expect(polled?.objectiveRow?.attempts.running).toBe(2)
|
|
5674
|
+
expect(rows.buildRows).toBe(0)
|
|
5675
|
+
expect(summarizeFrom(record, state, now).objective).toEqual(objectiveSummary(state, now))
|
|
5676
|
+
await getOperatorBuild({ store: nodeOnly, repo, slug: node, now })
|
|
5677
|
+
rows.reset()
|
|
5678
|
+
const operator = await getOperatorBuild({ store: nodeOnly, repo, slug: node, now })
|
|
5679
|
+
expect(rows.buildRows).toBe(0)
|
|
5680
|
+
expect(operator.detail.objective).toEqual(objectiveSummary(state, now))
|
|
5681
|
+
expect(operator.dashboardRow?.objectiveRow).toEqual(polled!.objectiveRow!)
|
|
5682
|
+
|
|
5683
|
+
// 1d. Slot-holding conditions ride on the same digest: an unmeasured
|
|
5684
|
+
// merge marked on an in-flight attempt, and a settled attempt's branch
|
|
5685
|
+
// obligation. The marker costs exactly its own node row; the poll and
|
|
5686
|
+
// the operator detail then read zero event rows and no attempt log.
|
|
5687
|
+
await store.append(node, {
|
|
5688
|
+
actor: DISPATCHER,
|
|
5689
|
+
type: 'optimization.attempts-proposed',
|
|
5690
|
+
payload: {
|
|
5691
|
+
request: 'cleanup',
|
|
5692
|
+
proposals: [
|
|
5693
|
+
{
|
|
5694
|
+
id: 'p-clean',
|
|
5695
|
+
ticket: { source: 'fake', id: 'CLEAN' },
|
|
5696
|
+
title: 'Clean',
|
|
5697
|
+
strategy: 'clean',
|
|
5698
|
+
},
|
|
5699
|
+
],
|
|
5700
|
+
},
|
|
5701
|
+
})
|
|
5702
|
+
await store.append(node, {
|
|
5703
|
+
actor: DISPATCHER,
|
|
5704
|
+
type: 'attempt.settled',
|
|
5705
|
+
payload: {
|
|
5706
|
+
attempt: {
|
|
5707
|
+
proposal: 'p-clean',
|
|
5708
|
+
ticket: { source: 'fake', id: 'CLEAN' },
|
|
5709
|
+
build: 'clean-child',
|
|
5710
|
+
branch: 'ab/clean-child',
|
|
5711
|
+
},
|
|
5712
|
+
outcome: 'declined',
|
|
5713
|
+
},
|
|
5714
|
+
})
|
|
5715
|
+
await readBuildFacts(store, node)
|
|
5716
|
+
await store.append(node, {
|
|
5717
|
+
actor: DISPATCHER,
|
|
5718
|
+
type: 'attempt.merged-unmeasured',
|
|
5719
|
+
payload: {
|
|
5720
|
+
proposal: 'p-live',
|
|
5721
|
+
ticket: live,
|
|
5722
|
+
build: 'live-child',
|
|
5723
|
+
sha: sha(9),
|
|
5724
|
+
reason: 'absent',
|
|
5725
|
+
},
|
|
5726
|
+
})
|
|
5727
|
+
rows.reset()
|
|
5728
|
+
const slotState = (await readBuildFacts(store, node)).value.state
|
|
5729
|
+
expect(rows.buildRowsBySlug.get(node)).toBe(1)
|
|
5730
|
+
expect(rows.buildRows).toBe(1)
|
|
5731
|
+
await dashboard.refresh()
|
|
5732
|
+
rows.reset()
|
|
5733
|
+
requests.reset()
|
|
5734
|
+
const slotRow = (await dashboard.refresh()).builds.find((build) => build.slug === node)
|
|
5735
|
+
const slotPoll = requests.vector()
|
|
5736
|
+
expect(rows.buildRows).toBe(0)
|
|
5737
|
+
expect(slotRow?.objectiveRow?.unmeasuredMerges).toBe(1)
|
|
5738
|
+
await getOperatorBuild({ store: nodeOnly, repo, slug: node, now })
|
|
5739
|
+
rows.reset()
|
|
5740
|
+
const slotDetail = (await getOperatorBuild({ store: nodeOnly, repo, slug: node, now })).detail
|
|
5741
|
+
expect(rows.buildRows).toBe(0)
|
|
5742
|
+
expect(slotDetail.unmeasuredMerges?.map((merge) => merge.proposal)).toEqual(['p-live'])
|
|
5743
|
+
expect(slotDetail.pendingCleanups).toEqual([
|
|
5744
|
+
{ proposal: 'p-clean', build: 'clean-child', branch: 'ab/clean-child' },
|
|
5745
|
+
])
|
|
5746
|
+
const slotDigest = JSON.stringify(slotState.optimization).length
|
|
5747
|
+
expect(attemptRows()).toEqual([])
|
|
5748
|
+
await store.append(node, {
|
|
5749
|
+
actor: DISPATCHER,
|
|
5750
|
+
type: 'attempt.ticket-rejected',
|
|
5751
|
+
payload: {
|
|
5752
|
+
proposal: 'p-clean',
|
|
5753
|
+
ticket: { source: 'fake', id: 'CLEAN' },
|
|
5754
|
+
state: 'Rejected',
|
|
5755
|
+
},
|
|
5756
|
+
})
|
|
5757
|
+
await readBuildFacts(store, node)
|
|
5758
|
+
await readOptimizationLedger(store, node)
|
|
5759
|
+
|
|
5760
|
+
// 2. Idle reads read zero event rows.
|
|
5761
|
+
rows.reset()
|
|
5762
|
+
for (let i = 0; i < 5; i++) {
|
|
5763
|
+
const idle = (await readBuildFacts(store, node)).value.state.optimization!
|
|
5764
|
+
optimizationAdmission(idle, now)
|
|
5765
|
+
await readOptimizationLedger(store, node)
|
|
5766
|
+
}
|
|
5767
|
+
expect(rows.buildRows).toBe(0)
|
|
5768
|
+
|
|
5769
|
+
// 3. One new settlement costs exactly its own node row.
|
|
5770
|
+
await store.append(node, {
|
|
5771
|
+
actor: DISPATCHER,
|
|
5772
|
+
type: 'optimization.attempts-proposed',
|
|
5773
|
+
payload: { request: 'last', proposals: [proposal(attempts)] },
|
|
5774
|
+
})
|
|
5775
|
+
await readBuildFacts(store, node)
|
|
5776
|
+
await readOptimizationLedger(store, node)
|
|
5777
|
+
await store.append(node, {
|
|
5778
|
+
actor: DISPATCHER,
|
|
5779
|
+
type: 'attempt.settled',
|
|
5780
|
+
payload: {
|
|
5781
|
+
attempt: { proposal: `p${attempts}`, ticket: proposal(attempts).ticket },
|
|
5782
|
+
outcome: 'declined',
|
|
5783
|
+
},
|
|
5784
|
+
})
|
|
5785
|
+
rows.reset()
|
|
5786
|
+
const advanced = (await readBuildFacts(store, node)).value.state.optimization!
|
|
5787
|
+
expect(advanced.attempts.filed).toBe(attempts + 4)
|
|
5788
|
+
expect(rows.buildRowsBySlug.get(node)).toBe(1)
|
|
5789
|
+
|
|
5790
|
+
// 4. The ledger advances with only the new node row, also through a
|
|
5791
|
+
// fresh repository view over the same store.
|
|
5792
|
+
rows.reset()
|
|
5793
|
+
const ledger = (await readOptimizationLedger(store, node)).value
|
|
5794
|
+
expect(ledger.entries).toHaveLength(attempts + 2)
|
|
5795
|
+
expect(rows.buildRowsBySlug.get(node)).toBe(1)
|
|
5796
|
+
rows.reset()
|
|
5797
|
+
const view = new RepoViewStore(store, { repo })
|
|
5798
|
+
expect((await readOptimizationLedger(view, node)).value.entries).toHaveLength(attempts + 2)
|
|
5799
|
+
expect(rows.buildRows).toBe(0)
|
|
5800
|
+
|
|
5801
|
+
// 6. No attempt log was read at any point.
|
|
5802
|
+
expect(attemptRows()).toEqual([])
|
|
5803
|
+
|
|
5804
|
+
// Settle the attempts used by the upstream context-read checks before
|
|
5805
|
+
// exercising the stop duty at its four-attempt concurrency bound.
|
|
5806
|
+
for (const attempt of [
|
|
5807
|
+
{ proposal: 'p-live', ticket: live },
|
|
5808
|
+
{ proposal: 'p-moved', ticket: moved },
|
|
5809
|
+
]) {
|
|
5810
|
+
await store.append(node, {
|
|
5811
|
+
actor: DISPATCHER,
|
|
5812
|
+
type: 'attempt.settled',
|
|
5813
|
+
payload: { attempt, outcome: 'declined' },
|
|
5814
|
+
})
|
|
5815
|
+
}
|
|
5816
|
+
|
|
5817
|
+
// 7. A stopped node with concurrency attempts in flight: one never
|
|
5818
|
+
// built, one aborted, two holding a pending abort. The stop duty reads
|
|
5819
|
+
// only the two non-terminal attempt builds.
|
|
5820
|
+
const inFlight = [1, 2, 3, 4].map((k) => attempts + k)
|
|
5821
|
+
await store.append(node, {
|
|
5822
|
+
actor: DISPATCHER,
|
|
5823
|
+
type: 'optimization.attempts-proposed',
|
|
5824
|
+
payload: { request: 'stopping', proposals: inFlight.map(proposal) },
|
|
5825
|
+
})
|
|
5826
|
+
for (const i of inFlight.slice(1)) {
|
|
5827
|
+
const slug = `attempt-${i}`
|
|
5828
|
+
await store.createBuild({ slug, repo, branch: `ab/${slug}`, ticket: proposal(i).ticket })
|
|
5829
|
+
await store.append(slug, {
|
|
5830
|
+
actor: DISPATCHER,
|
|
5831
|
+
type: 'build.created',
|
|
5832
|
+
payload: {
|
|
5833
|
+
repo,
|
|
5834
|
+
ticket: proposal(i).ticket,
|
|
5835
|
+
baseBranch: 'ab-node/opt-node',
|
|
5836
|
+
target: { ticket: { source: 'fake', id: 'NODE' }, build: node },
|
|
5837
|
+
},
|
|
5838
|
+
})
|
|
5839
|
+
await store.append(slug, {
|
|
5840
|
+
actor: humanActor('op'),
|
|
5841
|
+
type: 'build.abort-requested',
|
|
5842
|
+
payload: {},
|
|
5843
|
+
})
|
|
5844
|
+
}
|
|
5845
|
+
await store.append(`attempt-${inFlight[1]}`, {
|
|
5846
|
+
actor: DISPATCHER,
|
|
5847
|
+
type: 'build.aborted',
|
|
5848
|
+
payload: {},
|
|
5849
|
+
})
|
|
5850
|
+
await store.append(node, {
|
|
5851
|
+
actor: DISPATCHER,
|
|
5852
|
+
type: 'optimization.stopped',
|
|
5853
|
+
payload: { cause: 'operator', mode: 'abort' },
|
|
5854
|
+
})
|
|
5855
|
+
const repoView = new RepoViewStore(store, { repo })
|
|
5856
|
+
const deps = {
|
|
5857
|
+
store: repoView,
|
|
5858
|
+
clock: () => now,
|
|
5859
|
+
migrations: { migrations: [] },
|
|
5860
|
+
ticketSource: 'fake',
|
|
5861
|
+
}
|
|
5862
|
+
const listing = async () => {
|
|
5863
|
+
const digests = await readBuildDigests(store, repo)
|
|
5864
|
+
return (await store.listBuilds())
|
|
5865
|
+
.filter((record) => record.repo === repo)
|
|
5866
|
+
.map((record) => ({ record, digest: digests.get(record.slug)! }))
|
|
5867
|
+
}
|
|
5868
|
+
const stopTick = async () => {
|
|
5869
|
+
const builds = await listing()
|
|
5870
|
+
const before = (await readBuildFacts(store, node)).value.state
|
|
5871
|
+
rows.reset()
|
|
5872
|
+
requests.restore()
|
|
5873
|
+
const counted = memoryStoreRequestCounter(store)
|
|
5874
|
+
const wrote = await enforceOptimizationStop(
|
|
5875
|
+
deps,
|
|
5876
|
+
builds.find((b) => b.record.slug === node)!.record,
|
|
5877
|
+
before,
|
|
5878
|
+
builds,
|
|
5879
|
+
)
|
|
5880
|
+
const cost = { wrote, vector: counted.vector() }
|
|
5881
|
+
counted.restore()
|
|
5882
|
+
return cost
|
|
5883
|
+
}
|
|
5884
|
+
// The enforcer settles only the unbuilt attempt; cleanup owns the aborted one.
|
|
5885
|
+
expect((await stopTick()).wrote).toBe(true)
|
|
5886
|
+
const touched = attemptRows().map(([slug]) => slug)
|
|
5887
|
+
expect(
|
|
5888
|
+
touched.every((slug) =>
|
|
5889
|
+
[inFlight[2], inFlight[3]].map((i) => `attempt-${i}`).includes(slug),
|
|
5890
|
+
),
|
|
5891
|
+
).toBe(true)
|
|
5892
|
+
const settled = (await readBuildFacts(store, node)).value.state.optimization!
|
|
5893
|
+
expect(settled.inFlight.map((a) => a.proposal)).toEqual([
|
|
5894
|
+
`p${inFlight[1]}`,
|
|
5895
|
+
`p${inFlight[2]}`,
|
|
5896
|
+
`p${inFlight[3]}`,
|
|
5897
|
+
])
|
|
5898
|
+
// Idle ticks: reduced reads of the two pending-abort attempts, no rows.
|
|
5899
|
+
await stopTick()
|
|
5900
|
+
const idle = await stopTick()
|
|
5901
|
+
expect(idle.wrote).toBe(false)
|
|
5902
|
+
expect(rows.buildRows).toBe(0)
|
|
5903
|
+
// One saved reduced value per non-terminal attempt build, nothing else.
|
|
5904
|
+
expect(idle.vector).toEqual({ getReducerValue: settled.inFlight.length - 1 })
|
|
5905
|
+
|
|
5906
|
+
// 8. Reconciliation of a merged attempt no settlement or marker
|
|
5907
|
+
// recorded (an upgrade from before the marker): the first tick reads
|
|
5908
|
+
// that one child's reduced value and writes the marker; every later
|
|
5909
|
+
// tick is a pure scan of the listing it already has, with zero store
|
|
5910
|
+
// requests. Unmerged and aborted attempts are never read.
|
|
5911
|
+
const mergedTicket = { source: 'fake', id: 'MERGED' }
|
|
5912
|
+
await store.append(node, {
|
|
5913
|
+
actor: DISPATCHER,
|
|
5914
|
+
type: 'optimization.attempts-proposed',
|
|
5915
|
+
payload: {
|
|
5916
|
+
request: 'merged',
|
|
5917
|
+
proposals: [{ id: 'p-merged', ticket: mergedTicket, title: 'M', strategy: 'm' }],
|
|
5918
|
+
},
|
|
5919
|
+
})
|
|
5920
|
+
await store.createBuild({
|
|
5921
|
+
slug: 'merged-child',
|
|
5922
|
+
repo,
|
|
5923
|
+
branch: 'ab/merged-child',
|
|
5924
|
+
ticket: mergedTicket,
|
|
5925
|
+
})
|
|
5926
|
+
await store.append('merged-child', {
|
|
5927
|
+
actor: DISPATCHER,
|
|
5928
|
+
type: 'build.created',
|
|
5929
|
+
payload: {
|
|
5930
|
+
repo,
|
|
5931
|
+
ticket: mergedTicket,
|
|
5932
|
+
baseBranch: 'ab-node/opt-node',
|
|
5933
|
+
target: { ticket: { source: 'fake', id: 'NODE' }, build: node },
|
|
5934
|
+
},
|
|
5935
|
+
})
|
|
5936
|
+
await store.append('merged-child', {
|
|
5937
|
+
actor: DISPATCHER,
|
|
5938
|
+
type: 'pr.opened',
|
|
5939
|
+
payload: { pr: { number: 9, url: 'https://forge/9', headSha: sha(9) } },
|
|
5940
|
+
})
|
|
5941
|
+
await store.append('merged-child', {
|
|
5942
|
+
actor: DISPATCHER,
|
|
5943
|
+
type: 'pr.merged',
|
|
5944
|
+
payload: { sha: sha(9) },
|
|
5945
|
+
})
|
|
5946
|
+
await store.append('merged-child', {
|
|
5947
|
+
actor: DISPATCHER,
|
|
5948
|
+
type: 'build.completed',
|
|
5949
|
+
payload: { outcome: 'merged' },
|
|
5950
|
+
})
|
|
5951
|
+
await readBuildFacts(store, 'merged-child')
|
|
5952
|
+
const reconcileTick = async () => {
|
|
5953
|
+
const builds = await listing()
|
|
5954
|
+
const before = (await readBuildFacts(store, node)).value.state
|
|
5955
|
+
rows.reset()
|
|
5956
|
+
requests.restore()
|
|
5957
|
+
const counted = memoryStoreRequestCounter(store)
|
|
5958
|
+
const wrote = await reconcileMergedAttempts(
|
|
5959
|
+
deps,
|
|
5960
|
+
builds.find((b) => b.record.slug === node)!.record,
|
|
5961
|
+
before,
|
|
5962
|
+
builds,
|
|
5963
|
+
)
|
|
5964
|
+
const cost = { wrote, vector: counted.vector(), rows: rows.buildRows }
|
|
5965
|
+
counted.restore()
|
|
5966
|
+
return cost
|
|
5967
|
+
}
|
|
5968
|
+
const first = await reconcileTick()
|
|
5969
|
+
expect(first.wrote).toBe(true)
|
|
5970
|
+
expect(first.rows).toBe(0)
|
|
5971
|
+
const reconciled = (await readBuildFacts(store, node)).value.state.optimization!
|
|
5972
|
+
expect(
|
|
5973
|
+
reconciled.inFlight.find((a) => a.proposal === 'p-merged')?.unmeasuredMerge,
|
|
5974
|
+
).toMatchObject({
|
|
5975
|
+
build: 'merged-child',
|
|
5976
|
+
sha: sha(9),
|
|
5977
|
+
reason: 'absent',
|
|
5978
|
+
})
|
|
5979
|
+
const reconcileIdle = await reconcileTick()
|
|
5980
|
+
expect(reconcileIdle).toEqual({ wrote: false, vector: {}, rows: 0 })
|
|
5981
|
+
expect((await reconcileTick()).vector).toEqual({})
|
|
5982
|
+
measured.push({
|
|
5983
|
+
vector,
|
|
5984
|
+
digest: digestSize,
|
|
5985
|
+
attempt: attemptVector,
|
|
5986
|
+
migrated: migratedVector,
|
|
5987
|
+
poll: pollVector,
|
|
5988
|
+
objectiveRow: JSON.stringify(polled!.objectiveRow).length,
|
|
5989
|
+
stopVector: idle.vector,
|
|
5990
|
+
slotPoll,
|
|
5991
|
+
slotDigest,
|
|
5992
|
+
reconcileFirst: first.vector,
|
|
5993
|
+
reconcileIdle: reconcileIdle.vector,
|
|
5994
|
+
})
|
|
5995
|
+
} finally {
|
|
5996
|
+
requests.restore()
|
|
5997
|
+
}
|
|
5998
|
+
}
|
|
5999
|
+
expect(measured[1]!.stopVector).toEqual(measured[0]!.stopVector)
|
|
6000
|
+
expect(measured[1]!.slotPoll).toEqual(measured[0]!.slotPoll)
|
|
6001
|
+
expect(Math.abs(measured[1]!.slotDigest - measured[0]!.slotDigest)).toBeLessThanOrEqual(16)
|
|
6002
|
+
expect(measured[1]!.reconcileFirst).toEqual(measured[0]!.reconcileFirst)
|
|
6003
|
+
expect(measured[1]!.reconcileIdle).toEqual(measured[0]!.reconcileIdle)
|
|
6004
|
+
expect(measured[1]!.vector).toEqual(measured[0]!.vector)
|
|
6005
|
+
expect(measured[1]!.attempt).toEqual(measured[0]!.attempt)
|
|
6006
|
+
expect(measured[1]!.migrated).toEqual(measured[0]!.migrated)
|
|
6007
|
+
expect(Math.abs(measured[1]!.digest - measured[0]!.digest)).toBeLessThanOrEqual(16)
|
|
6008
|
+
expect(measured[1]!.poll).toEqual(measured[0]!.poll)
|
|
6009
|
+
expect(Math.abs(measured[1]!.objectiveRow - measured[0]!.objectiveRow)).toBeLessThanOrEqual(16)
|
|
6010
|
+
}
|
|
6011
|
+
|
|
6012
|
+
/**
|
|
6013
|
+
* Judge panel sessions (SPEC §13.1.1) on the build's session rows. With a
|
|
6014
|
+
* short and a padded build log, each holding a panel whose judges fell back
|
|
6015
|
+
* from their primary to an alternate:
|
|
6016
|
+
*
|
|
6017
|
+
* 1. an idle terminal dashboard poll and an operator build-detail read read
|
|
6018
|
+
* zero event rows, with an identical request vector at both lengths;
|
|
6019
|
+
* 2. the reduced panel state counts a substituted failure as no failure; and
|
|
6020
|
+
* 3. the polled session rows carry each judge session with its phase and
|
|
6021
|
+
* stream, and nothing that names the order a judge was given.
|
|
6022
|
+
*/
|
|
6023
|
+
export async function judgePanelSessionReadBudget(): Promise<void> {
|
|
6024
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
6025
|
+
const { PanelLogBuilder, panelStarted } = await import('../kernel/generators/panel-log')
|
|
6026
|
+
const { countedFailures } = await import('../kernel/panel')
|
|
6027
|
+
const { getOperatorBuild } = await import('../operator/query')
|
|
6028
|
+
const repo = '/budget/judge-panel'
|
|
6029
|
+
const slug = 'attempt-panel'
|
|
6030
|
+
const now = new Date('2026-11-18T00:00:00Z')
|
|
6031
|
+
const config = parseConfig(
|
|
6032
|
+
'[tickets]\nsource="fake"\nreadyState="ready"\n[verify]\nsteps=[]\n[finalize]\nsteps=[]',
|
|
6033
|
+
)
|
|
6034
|
+
const { verify: _verify, finalize: _finalize, ...root } = config
|
|
6035
|
+
const measured: Array<{ poll: Record<string, number>; operator: Record<string, number> }> = []
|
|
6036
|
+
for (const padding of [10, 10_000]) {
|
|
6037
|
+
const store = new MemoryBuildStore()
|
|
6038
|
+
await store.ensureRepo(repo)
|
|
6039
|
+
const configArtifact = await store.putRepoArtifact(repo, {
|
|
6040
|
+
kind: 'dispatcher-effective-config',
|
|
6041
|
+
content: JSON.stringify({ ...root, verify: { steps: [] }, finalize: { steps: [] } }),
|
|
6042
|
+
})
|
|
6043
|
+
await store.appendRepo(repo, {
|
|
6044
|
+
actor: DISPATCHER,
|
|
6045
|
+
type: 'dispatcher.run-started',
|
|
6046
|
+
payload: {
|
|
6047
|
+
run: 'budget-run',
|
|
6048
|
+
pid: 1,
|
|
6049
|
+
roleWarnings: [],
|
|
6050
|
+
effectiveConfig: { kind: configArtifact.kind, rev: configArtifact.revision },
|
|
6051
|
+
},
|
|
6052
|
+
})
|
|
6053
|
+
await store.createBuild({ slug, repo, branch: `ab/${slug}` })
|
|
6054
|
+
await store.append(slug, {
|
|
6055
|
+
actor: DISPATCHER,
|
|
6056
|
+
type: 'build.created',
|
|
6057
|
+
payload: { repo, ticket: { source: 'fake', id: 'PANEL' }, baseBranch: 'main' },
|
|
6058
|
+
})
|
|
6059
|
+
for (let i = 0; i < padding; i++)
|
|
6060
|
+
await store.append(slug, {
|
|
6061
|
+
actor: KERNEL,
|
|
6062
|
+
type: 'observation.recorded',
|
|
6063
|
+
payload: { id: `obs-${i}`, kind: 'followup', summary: `budget padding ${i}` },
|
|
6064
|
+
})
|
|
6065
|
+
const log = new PanelLogBuilder(slug).started(panelStarted({ judges: 2 }))
|
|
6066
|
+
for (const judge of [1, 2]) {
|
|
6067
|
+
const primary = `s_${judge}a`
|
|
6068
|
+
const alternate = `s_${judge}b`
|
|
6069
|
+
log
|
|
6070
|
+
.judgeStarted(judge, primary, 'candidate-first', 'panel-1', {
|
|
6071
|
+
runner: 'codex',
|
|
6072
|
+
stream: `st_${primary}`,
|
|
6073
|
+
})
|
|
6074
|
+
.ended(judge, primary, 'failed')
|
|
6075
|
+
.substituted(
|
|
6076
|
+
judge,
|
|
6077
|
+
alternate,
|
|
6078
|
+
'candidate-first',
|
|
6079
|
+
{ session: primary, index: 0, runner: 'codex' },
|
|
6080
|
+
{ runner: 'claude', stream: `st_${alternate}` },
|
|
6081
|
+
)
|
|
6082
|
+
.ended(judge, alternate, 'failed')
|
|
6083
|
+
}
|
|
6084
|
+
for (const event of log.events) await store.append(slug, event)
|
|
6085
|
+
|
|
6086
|
+
const record = (await store.getBuild(slug))!
|
|
6087
|
+
const single = new Proxy(store, {
|
|
6088
|
+
get(target, property) {
|
|
6089
|
+
if (property === 'listBuildsForRepo') return async () => [record]
|
|
6090
|
+
const value = Reflect.get(target, property)
|
|
6091
|
+
return typeof value === 'function' ? value.bind(target) : value
|
|
6092
|
+
},
|
|
6093
|
+
}) as BuildStore
|
|
6094
|
+
const dashboard = new DashboardBuildPollCache(
|
|
6095
|
+
{
|
|
6096
|
+
listBuildsForRepo: async () => [record],
|
|
6097
|
+
getEvents: store.getEvents.bind(store),
|
|
6098
|
+
getReducerValue: store.getReducerValue.bind(store),
|
|
6099
|
+
},
|
|
6100
|
+
repo,
|
|
6101
|
+
config,
|
|
6102
|
+
)
|
|
6103
|
+
// Warm-up: each reduced key is computed once and saved.
|
|
6104
|
+
await dashboard.refresh()
|
|
6105
|
+
await getOperatorBuild({ store: single, repo, slug, now })
|
|
6106
|
+
const rows = memoryRepositoryReadCounter(store, repo)
|
|
6107
|
+
const requests = memoryStoreRequestCounter(store)
|
|
6108
|
+
try {
|
|
6109
|
+
// 1. Idle reads: zero event rows.
|
|
6110
|
+
rows.reset()
|
|
6111
|
+
requests.reset()
|
|
6112
|
+
const polled = (await dashboard.refresh()).builds.find((build) => build.slug === slug)
|
|
6113
|
+
const poll = requests.vector()
|
|
6114
|
+
expect(rows.buildRows).toBe(0)
|
|
6115
|
+
rows.reset()
|
|
6116
|
+
requests.reset()
|
|
6117
|
+
const operator = await getOperatorBuild({ store: single, repo, slug, now })
|
|
6118
|
+
const operatorVector = requests.vector()
|
|
6119
|
+
expect(rows.buildRows).toBe(0)
|
|
6120
|
+
expect(operator.detail.slug).toBe(slug)
|
|
6121
|
+
|
|
6122
|
+
// 2. Each launch fell back once and exhausted: one counted failure.
|
|
6123
|
+
rows.reset()
|
|
6124
|
+
const panel = (await readBuildFacts(store, slug)).value.state.panel!
|
|
6125
|
+
expect(rows.buildRows).toBe(0)
|
|
6126
|
+
expect(countedFailures(panel, 1)).toEqual(['failed'])
|
|
6127
|
+
expect(countedFailures(panel, 2)).toEqual(['failed'])
|
|
6128
|
+
|
|
6129
|
+
// 3. The session rows name each judge session's target and stream.
|
|
6130
|
+
const sessions = polled!.sessions ?? []
|
|
6131
|
+
expect(
|
|
6132
|
+
sessions.map((session) => [session.id, session.phase, session.runtime, session.stream]),
|
|
6133
|
+
).toEqual([
|
|
6134
|
+
['s_1a', 'judge:panel-1:1', 'codex', 'st_s_1a'],
|
|
6135
|
+
['s_1b', 'judge:panel-1:1', 'claude', 'st_s_1b'],
|
|
6136
|
+
['s_2a', 'judge:panel-1:2', 'codex', 'st_s_2a'],
|
|
6137
|
+
['s_2b', 'judge:panel-1:2', 'claude', 'st_s_2b'],
|
|
6138
|
+
])
|
|
6139
|
+
expect(JSON.stringify(sessions)).not.toContain('first')
|
|
6140
|
+
measured.push({ poll, operator: operatorVector })
|
|
6141
|
+
} finally {
|
|
6142
|
+
requests.restore()
|
|
6143
|
+
}
|
|
6144
|
+
}
|
|
6145
|
+
expect(measured[1]).toEqual(measured[0])
|
|
6146
|
+
}
|
|
6147
|
+
|
|
6148
|
+
/**
|
|
6149
|
+
* The measurement landing gate and the rejected-role sweep (AUT-1226) have
|
|
6150
|
+
* bounded read cost, at 10 and at 1,000 settled attempts plus 2,000 terminal
|
|
6151
|
+
* builds in the repository, each poll from a fresh dispatcher:
|
|
6152
|
+
*
|
|
6153
|
+
* 1. with no pending rejection, the sweep makes zero store requests;
|
|
6154
|
+
* 2. with pending rejections and a tracker that refuses the move, every poll
|
|
6155
|
+
* costs the same requests, never lists builds or reads repository digests,
|
|
6156
|
+
* reads at most `concurrency` build facts and zero event rows; the pending
|
|
6157
|
+
* entries stay within `concurrency` and admission reports no slot;
|
|
6158
|
+
* 3. once the move succeeds the entry clears and its slot returns;
|
|
6159
|
+
* 4. the gate, with a would-be request waiting behind another attempt's
|
|
6160
|
+
* landing turn, reads zero event rows while nothing changes, never lists
|
|
6161
|
+
* builds or reads repository digests (its turn candidates come from the
|
|
6162
|
+
* janitor's listing), and reads at most one reduced value per in-flight
|
|
6163
|
+
* attempt plus the node;
|
|
6164
|
+
* 5. a completed node without pending rejections leaves the janitor's work
|
|
6165
|
+
* set; a late settlement re-arms it through its incremental digest, which
|
|
6166
|
+
* reads only the new row, never the node's history.
|
|
6167
|
+
*/
|
|
6168
|
+
export async function optimizationLandingReadBudget(): Promise<void> {
|
|
6169
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
6170
|
+
const { commandObjective } = await import('../kernel/generators/optimization-log')
|
|
6171
|
+
const { optimizationAdmission } = await import('../kernel/optimization')
|
|
6172
|
+
const { isWorkDigest } = await import('../processes/repo-view')
|
|
6173
|
+
const repo = '/budget/optimization-landing'
|
|
6174
|
+
const node = 'opt-node'
|
|
6175
|
+
const concurrency = 3
|
|
6176
|
+
const sha = 'a'.repeat(40)
|
|
6177
|
+
const config = parseConfig(
|
|
6178
|
+
'[tickets]\nsource = "file"\nreadyState = "Ready"\nrejectedState = "Rejected"\n[verify]\nsteps = []\n[finalize]\nsteps = []\n',
|
|
6179
|
+
)
|
|
6180
|
+
const vectors: Record<string, Record<string, number>[]>[] = []
|
|
6181
|
+
for (const history of [10, 1_000]) {
|
|
6182
|
+
const store = new MemoryBuildStore()
|
|
6183
|
+
const tickets = new FakeTicketSource()
|
|
6184
|
+
await store.ensureRepo(repo)
|
|
6185
|
+
const created = async (slug: string, kind?: 'node', target?: string, ticket?: TicketRef) => {
|
|
6186
|
+
const ref = ticket ?? { source: 'fake', id: slug.toUpperCase() }
|
|
6187
|
+
await store.createBuild({ slug, repo, branch: `ab/${slug}`, ticket: ref })
|
|
6188
|
+
await store.append(slug, {
|
|
6189
|
+
actor: DISPATCHER,
|
|
6190
|
+
type: 'build.created',
|
|
6191
|
+
payload: {
|
|
6192
|
+
repo,
|
|
6193
|
+
ticket: ref,
|
|
6194
|
+
baseBranch: 'main',
|
|
6195
|
+
...(kind ? { kind } : {}),
|
|
6196
|
+
...(target ? { target: { build: target, ticket: { source: 'fake', id: 'NODE' } } } : {}),
|
|
6197
|
+
},
|
|
6198
|
+
})
|
|
6199
|
+
}
|
|
6200
|
+
const completed = (slug: string) =>
|
|
6201
|
+
store.append(slug, {
|
|
6202
|
+
actor: DISPATCHER,
|
|
6203
|
+
type: 'build.completed',
|
|
6204
|
+
payload: { outcome: 'abandoned' },
|
|
6205
|
+
})
|
|
6206
|
+
for (let i = 0; i < 2 * history; i++) {
|
|
6207
|
+
await created(`old-${i}`)
|
|
6208
|
+
await completed(`old-${i}`)
|
|
6209
|
+
}
|
|
6210
|
+
await created(node, 'node')
|
|
6211
|
+
await store.append(node, {
|
|
6212
|
+
actor: DISPATCHER,
|
|
6213
|
+
type: 'optimization.objective-accepted',
|
|
6214
|
+
payload: {
|
|
6215
|
+
objective: commandObjective({
|
|
6216
|
+
budget: { maxAttempts: 100_000 },
|
|
6217
|
+
proposer: { concurrency },
|
|
6218
|
+
}),
|
|
6219
|
+
revision: 1,
|
|
6220
|
+
harnessPin: sha,
|
|
6221
|
+
specRev: 0,
|
|
6222
|
+
},
|
|
6223
|
+
})
|
|
6224
|
+
const propose = async (id: string) => {
|
|
6225
|
+
const ticket = await tickets.create({ title: id, body: 'Attempt' })
|
|
6226
|
+
await store.append(node, {
|
|
6227
|
+
actor: DISPATCHER,
|
|
6228
|
+
type: 'optimization.attempts-proposed',
|
|
6229
|
+
payload: {
|
|
6230
|
+
request: `r-${id}`,
|
|
6231
|
+
proposals: [{ id, ticket: ticket.ref, title: id, strategy: id }],
|
|
6232
|
+
},
|
|
6233
|
+
})
|
|
6234
|
+
return ticket.ref
|
|
6235
|
+
}
|
|
6236
|
+
const settle = (
|
|
6237
|
+
id: string,
|
|
6238
|
+
ticket: TicketRef,
|
|
6239
|
+
build: string,
|
|
6240
|
+
outcome: 'declined' | 'aborted',
|
|
6241
|
+
) =>
|
|
6242
|
+
store.append(node, {
|
|
6243
|
+
actor: DISPATCHER,
|
|
6244
|
+
type: 'attempt.settled',
|
|
6245
|
+
payload: { attempt: { proposal: id, ticket, build }, outcome },
|
|
6246
|
+
})
|
|
6247
|
+
// Settled history, every ticket already moved.
|
|
6248
|
+
for (let i = 0; i < history; i++) {
|
|
6249
|
+
const ticket = await propose(`h${i}`)
|
|
6250
|
+
await settle(`h${i}`, ticket, `old-${i}`, 'declined')
|
|
6251
|
+
await store.append(node, {
|
|
6252
|
+
actor: DISPATCHER,
|
|
6253
|
+
type: 'attempt.ticket-rejected',
|
|
6254
|
+
payload: { proposal: `h${i}`, ticket, state: 'Rejected' },
|
|
6255
|
+
})
|
|
6256
|
+
}
|
|
6257
|
+
// Live: two settled attempts whose moves are pending (one build done, one
|
|
6258
|
+
// still cleaning up), and one in flight.
|
|
6259
|
+
const live: TicketRef[] = []
|
|
6260
|
+
for (let i = 0; i < concurrency; i++) {
|
|
6261
|
+
live.push(await propose(`p${i}`))
|
|
6262
|
+
await created(`attempt-${i}`, undefined, node, live[i])
|
|
6263
|
+
}
|
|
6264
|
+
await completed('attempt-0')
|
|
6265
|
+
await settle('p0', live[0]!, 'attempt-0', 'declined')
|
|
6266
|
+
await settle('p1', live[1]!, 'attempt-1', 'aborted')
|
|
6267
|
+
// A child holding an unsampled request whose baseline a later
|
|
6268
|
+
// `target.moved` superseded (stage 7).
|
|
6269
|
+
await created('stale-child', undefined, node)
|
|
6270
|
+
await store.append('stale-child', {
|
|
6271
|
+
actor: DISPATCHER,
|
|
6272
|
+
type: 'attempt.measurement-requested',
|
|
6273
|
+
payload: {
|
|
6274
|
+
id: 'stale',
|
|
6275
|
+
node,
|
|
6276
|
+
candidate: 'c'.repeat(40),
|
|
6277
|
+
baseline: sha,
|
|
6278
|
+
harnessPin: sha,
|
|
6279
|
+
revision: 1,
|
|
6280
|
+
},
|
|
6281
|
+
})
|
|
6282
|
+
await store.append('stale-child', {
|
|
6283
|
+
actor: DISPATCHER,
|
|
6284
|
+
type: 'target.moved',
|
|
6285
|
+
payload: { branch: `ab/${node}`, sha: 'd'.repeat(40) },
|
|
6286
|
+
})
|
|
6287
|
+
|
|
6288
|
+
const forge = new FakeForge()
|
|
6289
|
+
const dispatcher = () =>
|
|
6290
|
+
new Dispatcher({
|
|
6291
|
+
store,
|
|
6292
|
+
tickets,
|
|
6293
|
+
workspaces: new FakeWorkspaceProvider({
|
|
6294
|
+
root: '/optimization-landing-budget',
|
|
6295
|
+
mode: 'logical',
|
|
6296
|
+
base: { source: 'remote', sha },
|
|
6297
|
+
}),
|
|
6298
|
+
forge,
|
|
6299
|
+
config,
|
|
6300
|
+
repo,
|
|
6301
|
+
exec: async () => ({ stdout: '', stderr: '', exitCode: 0 }),
|
|
6302
|
+
launchRunner: async () => {
|
|
6303
|
+
throw new Error('no launches in the optimization landing budget')
|
|
6304
|
+
},
|
|
6305
|
+
ids: sequentialIds(),
|
|
6306
|
+
clock: () => new Date('2026-11-18T00:00:00Z'),
|
|
6307
|
+
})
|
|
6308
|
+
const call = <T>(d: Dispatcher, name: string, ...args: unknown[]): Promise<T> =>
|
|
6309
|
+
(Reflect.get(d, name) as (...a: unknown[]) => Promise<T>).apply(d, args)
|
|
6310
|
+
const nodeState = async () => (await readBuildFacts(store, node)).value.state
|
|
6311
|
+
// Warm-up: each reduced key is computed once and saved.
|
|
6312
|
+
await nodeState()
|
|
6313
|
+
for (let i = 0; i < concurrency; i++) await readBuildFacts(store, `attempt-${i}`)
|
|
6314
|
+
await readBuildFacts(store, 'stale-child')
|
|
6315
|
+
await readBuildDigests(store, repo)
|
|
6316
|
+
const nodeRecord = (await store.getBuild(node))!
|
|
6317
|
+
const rows = memoryRepositoryReadCounter(store, repo)
|
|
6318
|
+
const requests = memoryStoreRequestCounter(store)
|
|
6319
|
+
const measured: Record<string, Record<string, number>[]> = {
|
|
6320
|
+
refused: [],
|
|
6321
|
+
gate: [],
|
|
6322
|
+
cleanup: [],
|
|
6323
|
+
superseded: [],
|
|
6324
|
+
}
|
|
6325
|
+
try {
|
|
6326
|
+
// 1. Nothing pending: zero requests.
|
|
6327
|
+
const idle = { ...(await nodeState()) }
|
|
6328
|
+
idle.optimization = { ...idle.optimization!, rejections: [] }
|
|
6329
|
+
requests.reset()
|
|
6330
|
+
expect(await call<boolean>(dispatcher(), 'sweepAttemptRejections', nodeRecord, idle)).toBe(
|
|
6331
|
+
false,
|
|
6332
|
+
)
|
|
6333
|
+
expect(requests.vector()).toEqual({})
|
|
6334
|
+
|
|
6335
|
+
// 2. A refusing tracker: constant cost, bounded entries, no slot.
|
|
6336
|
+
const transition = tickets.transition.bind(tickets)
|
|
6337
|
+
tickets.transition = async () => {
|
|
6338
|
+
throw new Error('tracker refused the move')
|
|
6339
|
+
}
|
|
6340
|
+
for (let poll = 0; poll < 3; poll++) {
|
|
6341
|
+
const state = await nodeState()
|
|
6342
|
+
expect(state.optimization!.rejections.length).toBeLessThanOrEqual(concurrency)
|
|
6343
|
+
expect(optimizationAdmission(state.optimization!, new Date()).slots).toBe(0)
|
|
6344
|
+
rows.reset()
|
|
6345
|
+
requests.reset()
|
|
6346
|
+
await expect(
|
|
6347
|
+
call(dispatcher(), 'sweepAttemptRejections', nodeRecord, state),
|
|
6348
|
+
).rejects.toThrow('tracker refused the move')
|
|
6349
|
+
const vector = requests.vector()
|
|
6350
|
+
expect(vector.listBuilds).toBeUndefined()
|
|
6351
|
+
expect(vector.getRepoBuildDigests).toBeUndefined()
|
|
6352
|
+
expect(rows.buildFactsCalls).toBeLessThanOrEqual(concurrency)
|
|
6353
|
+
expect(rows.buildRows).toBe(0)
|
|
6354
|
+
measured.refused!.push(vector)
|
|
6355
|
+
}
|
|
6356
|
+
expect(new Set(measured.refused!.map((v) => JSON.stringify(v))).size).toBe(1)
|
|
6357
|
+
|
|
6358
|
+
// 3. The move succeeds: the done attempt's entry clears; the other waits
|
|
6359
|
+
// for its build to finish.
|
|
6360
|
+
tickets.transition = transition
|
|
6361
|
+
expect(
|
|
6362
|
+
await call<boolean>(dispatcher(), 'sweepAttemptRejections', nodeRecord, await nodeState()),
|
|
6363
|
+
).toBe(true)
|
|
6364
|
+
let state = await nodeState()
|
|
6365
|
+
expect(state.optimization!.rejections.map((entry) => entry.proposal)).toEqual(['p1'])
|
|
6366
|
+
expect(optimizationAdmission(state.optimization!, new Date()).slots).toBe(1)
|
|
6367
|
+
expect((await tickets.get(live[0]!.id))?.state).toBe('Rejected')
|
|
6368
|
+
expect((await tickets.get(live[1]!.id))?.state).not.toBe('Rejected')
|
|
6369
|
+
|
|
6370
|
+
// 4. The gate and its landing turn: attempt-2 has a known pair and
|
|
6371
|
+
// would request a measurement, but attempt-3, overtaken three times,
|
|
6372
|
+
// holds the turn. Zero event rows while unchanged, no listing or digest
|
|
6373
|
+
// read beyond the janitor's own, and one reduced read per in-flight
|
|
6374
|
+
// attempt plus the node.
|
|
6375
|
+
const turnTicket = await propose('p3')
|
|
6376
|
+
await created('attempt-3', undefined, node, turnTicket)
|
|
6377
|
+
for (let i = 0; i < 4; i++)
|
|
6378
|
+
await store.append('attempt-3', {
|
|
6379
|
+
actor: DISPATCHER,
|
|
6380
|
+
type: 'attempt.measurement-requested',
|
|
6381
|
+
payload: {
|
|
6382
|
+
id: `m${i}`,
|
|
6383
|
+
node,
|
|
6384
|
+
candidate: 'c'.repeat(40),
|
|
6385
|
+
baseline: String(i).repeat(40),
|
|
6386
|
+
harnessPin: sha,
|
|
6387
|
+
revision: 1,
|
|
6388
|
+
},
|
|
6389
|
+
})
|
|
6390
|
+
await store.append('attempt-2', {
|
|
6391
|
+
actor: KERNEL,
|
|
6392
|
+
type: 'workspace.provisioned',
|
|
6393
|
+
payload: {
|
|
6394
|
+
provider: 'fake',
|
|
6395
|
+
remote: false,
|
|
6396
|
+
ref: 'attempt-2',
|
|
6397
|
+
branch: 'ab/attempt-2',
|
|
6398
|
+
base: { source: 'remote', sha },
|
|
6399
|
+
},
|
|
6400
|
+
})
|
|
6401
|
+
await store.append('attempt-2', {
|
|
6402
|
+
actor: DISPATCHER,
|
|
6403
|
+
type: 'target.moved',
|
|
6404
|
+
payload: { branch: 'main', sha },
|
|
6405
|
+
})
|
|
6406
|
+
await store.append('attempt-2', {
|
|
6407
|
+
actor: DISPATCHER,
|
|
6408
|
+
type: 'pr.opened',
|
|
6409
|
+
payload: { pr: { number: 2, url: 'https://forge/2', headSha: 'b'.repeat(40) } },
|
|
6410
|
+
})
|
|
6411
|
+
await nodeState()
|
|
6412
|
+
for (const slug of ['attempt-2', 'attempt-3']) await readBuildFacts(store, slug)
|
|
6413
|
+
await readBuildDigests(store, repo)
|
|
6414
|
+
const record = (await store.getBuild('attempt-2'))!
|
|
6415
|
+
const tick = async () => {
|
|
6416
|
+
const d = dispatcher()
|
|
6417
|
+
// The janitor's one listing per tick, which the gate reuses.
|
|
6418
|
+
Reflect.set(d, 'janitorEntries', await call(d, 'repoBuildDigests'))
|
|
6419
|
+
// A cached view would hide a second listing from the store counters;
|
|
6420
|
+
// the gate must not scan the repository's builds even in memory.
|
|
6421
|
+
let listings = 0
|
|
6422
|
+
Reflect.set(d, 'repoBuildDigests', async () => {
|
|
6423
|
+
listings += 1
|
|
6424
|
+
return []
|
|
6425
|
+
})
|
|
6426
|
+
return { d, listings: () => listings }
|
|
6427
|
+
}
|
|
6428
|
+
await call((await tick()).d, 'landingVerdict', record, node)
|
|
6429
|
+
for (let poll = 0; poll < 3; poll++) {
|
|
6430
|
+
const { d, listings } = await tick()
|
|
6431
|
+
rows.reset()
|
|
6432
|
+
requests.reset()
|
|
6433
|
+
const verdict = await call<{ verdict: string }>(d, 'landingVerdict', record, node)
|
|
6434
|
+
expect(verdict.verdict).toBe('wait-turn')
|
|
6435
|
+
expect(listings()).toBe(0)
|
|
6436
|
+
expect(rows.buildRows).toBe(0)
|
|
6437
|
+
expect(rows.buildFactsCalls).toBeLessThanOrEqual(concurrency + 1)
|
|
6438
|
+
const vector = requests.vector()
|
|
6439
|
+
expect(vector.listBuilds).toBeUndefined()
|
|
6440
|
+
expect(vector.getRepoBuildDigests).toBeUndefined()
|
|
6441
|
+
measured.gate!.push(vector)
|
|
6442
|
+
}
|
|
6443
|
+
expect(new Set(measured.gate!.map((v) => JSON.stringify(v))).size).toBe(1)
|
|
6444
|
+
|
|
6445
|
+
// 5. The node completes; its last pending move then clears it from the
|
|
6446
|
+
// work set, and a late settlement re-arms it incrementally.
|
|
6447
|
+
await completed(node)
|
|
6448
|
+
await completed('attempt-1')
|
|
6449
|
+
await call(dispatcher(), 'sweepAttemptRejections', nodeRecord, await nodeState())
|
|
6450
|
+
state = await nodeState()
|
|
6451
|
+
expect(state.optimization!.rejections).toEqual([])
|
|
6452
|
+
rows.reset()
|
|
6453
|
+
let digest = (await readBuildDigests(store, repo)).get(node)!
|
|
6454
|
+
expect(digest.terminal).toBe('done')
|
|
6455
|
+
expect(digest.rejectionsPending).toBeUndefined()
|
|
6456
|
+
expect(isWorkDigest(digest)).toBe(false)
|
|
6457
|
+
await settle('p2', live[2]!, 'attempt-2', 'aborted')
|
|
6458
|
+
rows.reset()
|
|
6459
|
+
digest = (await readBuildDigests(store, repo)).get(node)!
|
|
6460
|
+
expect(digest.rejectionsPending).toBe(true)
|
|
6461
|
+
expect(isWorkDigest(digest)).toBe(true)
|
|
6462
|
+
expect(rows.buildRowsBySlug.get(node)).toBe(1)
|
|
6463
|
+
expect(rows.buildRows).toBe(1)
|
|
6464
|
+
|
|
6465
|
+
// 6. A declined attempt that published: its branch obligation is one
|
|
6466
|
+
// forge delete per poll while failing, with the same request vector
|
|
6467
|
+
// each poll and one failure fact per distinct error; then the delete
|
|
6468
|
+
// and the move clear it. No listing, digest or event-row read.
|
|
6469
|
+
const cleanupTicket = await propose('p4')
|
|
6470
|
+
await created('attempt-4', undefined, node, cleanupTicket)
|
|
6471
|
+
await completed('attempt-4')
|
|
6472
|
+
await store.append(node, {
|
|
6473
|
+
actor: DISPATCHER,
|
|
6474
|
+
type: 'attempt.settled',
|
|
6475
|
+
payload: {
|
|
6476
|
+
attempt: {
|
|
6477
|
+
proposal: 'p4',
|
|
6478
|
+
ticket: cleanupTicket,
|
|
6479
|
+
build: 'attempt-4',
|
|
6480
|
+
branch: 'ab/attempt-4',
|
|
6481
|
+
},
|
|
6482
|
+
outcome: 'declined',
|
|
6483
|
+
},
|
|
6484
|
+
})
|
|
6485
|
+
for (let poll = 0; poll < 3; poll++) forge.failNextDeleteBranch('forge refused the delete')
|
|
6486
|
+
const failures = async () =>
|
|
6487
|
+
(await store.getEvents(node)).filter((e) => e.type === 'attempt.branch-cleanup-failed')
|
|
6488
|
+
for (let poll = 0; poll < 3; poll++) {
|
|
6489
|
+
const current = await nodeState()
|
|
6490
|
+
rows.reset()
|
|
6491
|
+
requests.reset()
|
|
6492
|
+
await call(dispatcher(), 'sweepAttemptRejections', nodeRecord, current)
|
|
6493
|
+
const vector = requests.vector()
|
|
6494
|
+
expect(vector.listBuilds).toBeUndefined()
|
|
6495
|
+
expect(vector.getRepoBuildDigests).toBeUndefined()
|
|
6496
|
+
expect(rows.buildRows).toBe(0)
|
|
6497
|
+
expect(rows.buildFactsCalls).toBeLessThanOrEqual(concurrency)
|
|
6498
|
+
// The first poll records the failure; the next ones repeat only the delete.
|
|
6499
|
+
if (poll > 0) measured.cleanup!.push(vector)
|
|
6500
|
+
}
|
|
6501
|
+
expect(new Set(measured.cleanup!.map((v) => JSON.stringify(v))).size).toBe(1)
|
|
6502
|
+
expect(await failures()).toHaveLength(1)
|
|
6503
|
+
expect(forge.deleteBranchCalls.map((c) => c.branch)).toEqual(Array(3).fill('ab/attempt-4'))
|
|
6504
|
+
expect((await tickets.get(cleanupTicket.id))?.state).not.toBe('Rejected')
|
|
6505
|
+
await call(dispatcher(), 'sweepAttemptRejections', nodeRecord, await nodeState())
|
|
6506
|
+
state = await nodeState()
|
|
6507
|
+
expect(state.optimization!.rejections.map((entry) => entry.proposal)).toEqual(['p2'])
|
|
6508
|
+
expect((await tickets.get(cleanupTicket.id))?.state).toBe('Rejected')
|
|
6509
|
+
expect(forge.deleteBranchCalls.map((c) => c.branch)).toEqual(Array(4).fill('ab/attempt-4'))
|
|
6510
|
+
|
|
6511
|
+
// 7. A superseded measurement request: capacity assembly from a fresh
|
|
6512
|
+
// dispatcher asks no slot for it, reads zero event rows and appends
|
|
6513
|
+
// nothing, at the same cost every poll.
|
|
6514
|
+
const staleLog = (await store.getEvents('stale-child')).length
|
|
6515
|
+
// Earlier stages changed other builds; one assembly advances their
|
|
6516
|
+
// saved values before nothing changes.
|
|
6517
|
+
await call(dispatcher(), 'capacityBuilds')
|
|
6518
|
+
for (let poll = 0; poll < 3; poll++) {
|
|
6519
|
+
const d = dispatcher()
|
|
6520
|
+
rows.reset()
|
|
6521
|
+
requests.reset()
|
|
6522
|
+
const builds = await call<CapacityBuild[]>(d, 'capacityBuilds')
|
|
6523
|
+
const child = builds.find((build) => build.record.slug === 'stale-child')!
|
|
6524
|
+
expect(child.state.attemptMeasurement?.observedHead).toBe('d'.repeat(40))
|
|
6525
|
+
expect(slotRequest(child, new Date('2026-11-18T00:00:00Z'))).toBeUndefined()
|
|
6526
|
+
expect(rows.buildRows).toBe(0)
|
|
6527
|
+
measured.superseded!.push({ ...requests.vector(), buildFacts: rows.buildFactsCalls })
|
|
6528
|
+
}
|
|
6529
|
+
expect(new Set(measured.superseded!.map((v) => JSON.stringify(v))).size).toBe(1)
|
|
6530
|
+
expect((await store.getEvents('stale-child')).length).toBe(staleLog)
|
|
6531
|
+
} finally {
|
|
6532
|
+
requests.restore()
|
|
6533
|
+
}
|
|
6534
|
+
vectors.push(measured)
|
|
6535
|
+
await store.close()
|
|
6536
|
+
}
|
|
6537
|
+
expect(vectors[1]).toEqual(vectors[0]!)
|
|
6538
|
+
}
|
|
6539
|
+
|
|
6540
|
+
/** AUT-1245: a judge's atomic preference write is one served delegation read
|
|
6541
|
+
* and one conditional append per uncontended attempt, the same request vector
|
|
6542
|
+
* at 100 and 100,000 build events, and zero historical event rows once the
|
|
6543
|
+
* key's one-time reduction is saved. A refused retry costs one read and only
|
|
6544
|
+
* the new rows since the saved cursor. No path reads the log. */
|
|
6545
|
+
export async function judgePreferenceReadBudget() {
|
|
6546
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
6547
|
+
const { appendJudgePreference } = await import('../store/judge-authority')
|
|
6548
|
+
const { sampleBuildInput } = await import('../store/contract')
|
|
6549
|
+
const { agentActor } = await import('../events/envelope')
|
|
6550
|
+
const repo = 'acme/judge-budget'
|
|
6551
|
+
const build = 'judge-budget'
|
|
6552
|
+
const scope = { build, panel: 'panel-1', judge: 1, session: 's_judge' }
|
|
6553
|
+
const write = (preference: 'A' | 'B') => ({
|
|
6554
|
+
actor: agentActor('judge', scope.session),
|
|
6555
|
+
type: 'panel.preferred' as const,
|
|
6556
|
+
payload: {
|
|
6557
|
+
panel: scope.panel,
|
|
6558
|
+
judge: scope.judge,
|
|
6559
|
+
session: scope.session,
|
|
6560
|
+
preference,
|
|
6561
|
+
reason: 'A follows the rubric',
|
|
6562
|
+
},
|
|
6563
|
+
})
|
|
6564
|
+
const results: Array<{
|
|
6565
|
+
recorded: { vector: Record<string, number>; rows: number }
|
|
6566
|
+
refused: { vector: Record<string, number>; rows: number }
|
|
6567
|
+
}> = []
|
|
6568
|
+
for (const filler of [100, 100_000]) {
|
|
6569
|
+
const store = new MemoryBuildStore()
|
|
6570
|
+
await store.createBuild({ ...sampleBuildInput(build), repo })
|
|
6571
|
+
await store.ensureRepo(repo)
|
|
6572
|
+
await store.append(build, {
|
|
6573
|
+
actor: KERNEL,
|
|
6574
|
+
type: 'panel.started',
|
|
6575
|
+
payload: {
|
|
6576
|
+
panel: scope.panel,
|
|
6577
|
+
candidate: 'c'.repeat(40),
|
|
6578
|
+
baseline: 'b'.repeat(40),
|
|
6579
|
+
harnessPin: 'a'.repeat(40),
|
|
6580
|
+
purpose: 'clear prose',
|
|
6581
|
+
rubric: 'evals/rubric.md',
|
|
6582
|
+
harness: ['evals/**'],
|
|
6583
|
+
judges: 1,
|
|
6584
|
+
},
|
|
6585
|
+
})
|
|
6586
|
+
await store.append(build, {
|
|
6587
|
+
actor: KERNEL,
|
|
6588
|
+
type: 'panel.judge-started',
|
|
6589
|
+
payload: {
|
|
6590
|
+
panel: scope.panel,
|
|
6591
|
+
judge: scope.judge,
|
|
6592
|
+
session: scope.session,
|
|
6593
|
+
order: 'candidate-first',
|
|
6594
|
+
runner: 'scripted',
|
|
6595
|
+
},
|
|
6596
|
+
})
|
|
6597
|
+
for (let i = 0; i < filler; i++)
|
|
6598
|
+
await store.append(build, {
|
|
6599
|
+
actor: KERNEL,
|
|
6600
|
+
type: 'observation.recorded',
|
|
6601
|
+
payload: { id: `obs-${i}`, kind: 'followup', summary: `budget padding ${i}` },
|
|
6602
|
+
})
|
|
6603
|
+
// The one-time reduction of this (build, buildDelegation) key.
|
|
6604
|
+
await store.getReducerValue({ kind: 'build', slug: build }, { reducer: 'buildDelegation' })
|
|
6605
|
+
const rows = memoryRepositoryReadCounter(store, repo)
|
|
6606
|
+
const requests = memoryStoreRequestCounter(store)
|
|
6607
|
+
try {
|
|
6608
|
+
const measure = async (preference: 'A' | 'B') => {
|
|
6609
|
+
rows.reset()
|
|
6610
|
+
requests.reset()
|
|
6611
|
+
const result = await appendJudgePreference(store, scope, write(preference))
|
|
6612
|
+
return { result, vector: requests.vector(), rows: rows.buildRows }
|
|
6613
|
+
}
|
|
6614
|
+
const recorded = await measure('A')
|
|
6615
|
+
expect(recorded.result.kind).toBe('recorded')
|
|
6616
|
+
const refused = await measure('B')
|
|
6617
|
+
expect(refused.result).toEqual({
|
|
6618
|
+
kind: 'refused',
|
|
6619
|
+
reason: 'this judge already recorded its preference',
|
|
6620
|
+
})
|
|
6621
|
+
results.push({
|
|
6622
|
+
recorded: { vector: recorded.vector, rows: recorded.rows },
|
|
6623
|
+
refused: { vector: refused.vector, rows: refused.rows },
|
|
6624
|
+
})
|
|
6625
|
+
} finally {
|
|
6626
|
+
requests.restore()
|
|
6627
|
+
}
|
|
6628
|
+
}
|
|
6629
|
+
const [small, large] = results as [(typeof results)[0], (typeof results)[0]]
|
|
6630
|
+
expect(small.recorded.vector).toEqual({ appendIfCurrent: 1, getReducerValue: 1 })
|
|
6631
|
+
expect(small.refused.vector).toEqual({ getReducerValue: 1 })
|
|
6632
|
+
expect(small.recorded.rows).toBe(0)
|
|
6633
|
+
expect(small.refused.rows).toBeLessThanOrEqual(1)
|
|
6634
|
+
expect(large).toEqual(small)
|
|
6635
|
+
return { small, large }
|
|
6636
|
+
}
|
|
6637
|
+
|
|
6638
|
+
/**
|
|
6639
|
+
* Panel progress selection (SPEC §15.5). For a panel node whose history is
|
|
6640
|
+
* 100 and 100,000 events of accepted attempts each measured for progress:
|
|
6641
|
+
*
|
|
6642
|
+
* 1. idle selection (`progressMeasurementDue`, `nodeMeasurementDue`, slot
|
|
6643
|
+
* request, capacity and the engine decision) reads zero event rows with an
|
|
6644
|
+
* identical request vector at both sizes;
|
|
6645
|
+
* 2. a new accepted settlement costs exactly its own node row, after which
|
|
6646
|
+
* progress is due for its head, the node requests a runner and the engine
|
|
6647
|
+
* decides `measure-progress`;
|
|
6648
|
+
* 3. the recorded progress costs its own row and clears the selection, and
|
|
6649
|
+
* the landing gate holds (`wait-progress`) and then lands from the same
|
|
6650
|
+
* digest with no extra reads.
|
|
6651
|
+
*/
|
|
6652
|
+
export async function panelProgressReadBudget(): Promise<void> {
|
|
6653
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
6654
|
+
const { panelObjective } = await import('../kernel/generators/optimization-log')
|
|
6655
|
+
const { nodeMeasurementDue, progressMeasurementDue } = await import('../kernel/measurement')
|
|
6656
|
+
const { occupiesCapacity, slotRequest, strandedNodeWorkspace } = await import(
|
|
6657
|
+
'../kernel/dispatch-capacity'
|
|
6658
|
+
)
|
|
6659
|
+
const { landingMeasurementGate } = await import('../kernel/landing-measurement')
|
|
6660
|
+
const repo = '/budget/panel-progress'
|
|
6661
|
+
const node = 'panel-node'
|
|
6662
|
+
const sha = (n: number) => n.toString(16).padStart(40, '0')
|
|
6663
|
+
const now = new Date('2026-11-18T00:00:00Z')
|
|
6664
|
+
const config = parseConfig(
|
|
6665
|
+
'[tickets]\nsource="fake"\nreadyState="ready"\n[verify]\nsteps=[]\n[finalize]\nsteps=[]',
|
|
6666
|
+
)
|
|
6667
|
+
const ticket = (i: number) => ({ source: 'fake', id: `A-${i}` })
|
|
6668
|
+
const measured: {
|
|
6669
|
+
idle: Record<string, number>
|
|
6670
|
+
accepted: Record<string, number>
|
|
6671
|
+
rows: number[]
|
|
6672
|
+
}[] = []
|
|
6673
|
+
for (const events of [100, 100_000]) {
|
|
6674
|
+
const store = new MemoryBuildStore()
|
|
6675
|
+
await store.ensureRepo(repo)
|
|
6676
|
+
await store.createBuild({ slug: node, repo, branch: 'ab-node/panel-node' })
|
|
6677
|
+
await store.append(node, {
|
|
6678
|
+
actor: DISPATCHER,
|
|
6679
|
+
type: 'build.created',
|
|
6680
|
+
payload: { repo, ticket: { source: 'fake', id: 'NODE' }, baseBranch: 'main', kind: 'node' },
|
|
6681
|
+
})
|
|
6682
|
+
await store.append(node, {
|
|
6683
|
+
actor: DISPATCHER,
|
|
6684
|
+
type: 'optimization.objective-accepted',
|
|
6685
|
+
payload: {
|
|
6686
|
+
objective: { ...panelObjective(), budget: { maxAttempts: 1_000_000 } },
|
|
6687
|
+
revision: 1,
|
|
6688
|
+
harnessPin: sha(1),
|
|
6689
|
+
specRev: 0,
|
|
6690
|
+
},
|
|
6691
|
+
})
|
|
6692
|
+
await store.append(node, { actor: DISPATCHER, type: 'node.opened', payload: { sha: sha(1) } })
|
|
6693
|
+
await store.append(node, {
|
|
6694
|
+
actor: KERNEL,
|
|
6695
|
+
type: 'optimization.baseline-measured',
|
|
6696
|
+
payload: {
|
|
6697
|
+
revision: 1,
|
|
6698
|
+
head: sha(1),
|
|
6699
|
+
harnessPin: sha(1),
|
|
6700
|
+
samples: 5,
|
|
6701
|
+
median: 0.5,
|
|
6702
|
+
spread: 0,
|
|
6703
|
+
},
|
|
6704
|
+
})
|
|
6705
|
+
const accept = (i: number) =>
|
|
6706
|
+
store.append(node, {
|
|
6707
|
+
actor: DISPATCHER,
|
|
6708
|
+
type: 'attempt.settled',
|
|
6709
|
+
payload: {
|
|
6710
|
+
attempt: { proposal: `p${i}`, ticket: ticket(i) },
|
|
6711
|
+
outcome: 'accepted',
|
|
6712
|
+
measurement: { revision: 1, baseline: 0.5, candidate: 0.6, delta: 0.1 },
|
|
6713
|
+
head: sha(i + 2),
|
|
6714
|
+
},
|
|
6715
|
+
})
|
|
6716
|
+
const progress = (i: number) =>
|
|
6717
|
+
store.append(node, {
|
|
6718
|
+
actor: KERNEL,
|
|
6719
|
+
type: 'optimization.progress-measured',
|
|
6720
|
+
payload: { revision: 1, head: sha(i + 2), start: sha(1), winRate: 0.6, judges: 5 },
|
|
6721
|
+
})
|
|
6722
|
+
// Cycles of one proposal, its acceptance and its progress.
|
|
6723
|
+
const cycles = Math.floor((events - 4) / 3)
|
|
6724
|
+
for (let i = 0; i < cycles; i++) {
|
|
6725
|
+
await store.append(node, {
|
|
6726
|
+
actor: DISPATCHER,
|
|
6727
|
+
type: 'optimization.attempts-proposed',
|
|
6728
|
+
payload: {
|
|
6729
|
+
request: `r${i}`,
|
|
6730
|
+
proposals: [{ id: `p${i}`, ticket: ticket(i), title: `Attempt ${i}`, strategy: 's' }],
|
|
6731
|
+
},
|
|
6732
|
+
})
|
|
6733
|
+
await accept(i)
|
|
6734
|
+
await progress(i)
|
|
6735
|
+
}
|
|
6736
|
+
await store.append(node, {
|
|
6737
|
+
actor: DISPATCHER,
|
|
6738
|
+
type: 'optimization.attempts-proposed',
|
|
6739
|
+
payload: {
|
|
6740
|
+
request: 'r-next',
|
|
6741
|
+
proposals: [{ id: `p${cycles}`, ticket: ticket(cycles), title: 'Next', strategy: 's' }],
|
|
6742
|
+
},
|
|
6743
|
+
})
|
|
6744
|
+
const record = (await store.getBuild(node))!
|
|
6745
|
+
// Warm-up: the reduced key is computed once and saved.
|
|
6746
|
+
await readBuildFacts(store, node)
|
|
6747
|
+
const rows = memoryRepositoryReadCounter(store, repo)
|
|
6748
|
+
const requests = memoryStoreRequestCounter(store)
|
|
6749
|
+
const select = async () => {
|
|
6750
|
+
const facts = (await readBuildFacts(store, node)).value
|
|
6751
|
+
const build = { record, state: facts.state, workspace: false }
|
|
6752
|
+
return {
|
|
6753
|
+
due: progressMeasurementDue(facts.state),
|
|
6754
|
+
node: nodeMeasurementDue(facts.state),
|
|
6755
|
+
request: slotRequest(build, now),
|
|
6756
|
+
occupies: occupiesCapacity(build, now),
|
|
6757
|
+
decision: decideNextFromFacts(facts.state, facts.log, config),
|
|
6758
|
+
digest: facts.state.optimization!,
|
|
6759
|
+
}
|
|
6760
|
+
}
|
|
6761
|
+
const gate = (digest: Parameters<typeof landingMeasurementGate>[0]['digest']) =>
|
|
6762
|
+
landingMeasurementGate({
|
|
6763
|
+
digest,
|
|
6764
|
+
attempt: 'in-flight',
|
|
6765
|
+
lm: {
|
|
6766
|
+
request: {
|
|
6767
|
+
id: 'm',
|
|
6768
|
+
node,
|
|
6769
|
+
candidate: sha(0xfff),
|
|
6770
|
+
baseline: sha(0xffe),
|
|
6771
|
+
harnessPin: sha(1),
|
|
6772
|
+
revision: 1,
|
|
6773
|
+
seq: 1,
|
|
6774
|
+
},
|
|
6775
|
+
result: {
|
|
6776
|
+
request: 'm',
|
|
6777
|
+
candidate: sha(0xfff),
|
|
6778
|
+
baseline: sha(0xffe),
|
|
6779
|
+
harnessPin: sha(1),
|
|
6780
|
+
revision: 1,
|
|
6781
|
+
samples: 5,
|
|
6782
|
+
winRate: 0.9,
|
|
6783
|
+
delta: 0.4,
|
|
6784
|
+
decision: 'improved',
|
|
6785
|
+
seq: 2,
|
|
6786
|
+
},
|
|
6787
|
+
overtakes: 0,
|
|
6788
|
+
},
|
|
6789
|
+
candidate: sha(0xfff),
|
|
6790
|
+
nodeHead: sha(0xffe),
|
|
6791
|
+
self: 'attempt',
|
|
6792
|
+
})
|
|
6793
|
+
try {
|
|
6794
|
+
// 1. Idle selection: zero event rows, repeatedly.
|
|
6795
|
+
for (let repeat = 0; repeat < 5; repeat++) {
|
|
6796
|
+
const idle = await select()
|
|
6797
|
+
expect(idle.due).toBeUndefined()
|
|
6798
|
+
expect(idle.node).toBe(false)
|
|
6799
|
+
expect(idle.request).toBeUndefined()
|
|
6800
|
+
expect(idle.occupies).toBe(false)
|
|
6801
|
+
expect(idle.decision).toEqual({ kind: 'wait', reason: 'awaiting-pr' })
|
|
6802
|
+
expect(gate(idle.digest)).toBe('land')
|
|
6803
|
+
}
|
|
6804
|
+
expect(rows.buildRows).toBe(0)
|
|
6805
|
+
const idle = requests.vector()
|
|
6806
|
+
const rowCounts = [rows.buildRows]
|
|
6807
|
+
|
|
6808
|
+
// 2. A new acceptance costs its own row and makes progress due.
|
|
6809
|
+
await accept(cycles)
|
|
6810
|
+
rows.reset()
|
|
6811
|
+
requests.reset()
|
|
6812
|
+
const due = await select()
|
|
6813
|
+
expect(rows.buildRows).toBe(1)
|
|
6814
|
+
rowCounts.push(rows.buildRows)
|
|
6815
|
+
expect(due.due).toEqual({
|
|
6816
|
+
revision: 1,
|
|
6817
|
+
head: sha(cycles + 2),
|
|
6818
|
+
start: sha(1),
|
|
6819
|
+
harnessPin: sha(1),
|
|
6820
|
+
})
|
|
6821
|
+
expect(due.node).toBe(true)
|
|
6822
|
+
expect(due.request).toBe('verification')
|
|
6823
|
+
expect(due.decision).toMatchObject({ kind: 'measure-progress', head: sha(cycles + 2) })
|
|
6824
|
+
// Proposer arbitration uses these same reduced facts, with no reads:
|
|
6825
|
+
// an unstarted request waits, an admitted session finishes, and neither
|
|
6826
|
+
// cleanup path can release a workspace still owed a panel.
|
|
6827
|
+
const facts = (await readBuildFacts(store, node)).value
|
|
6828
|
+
const state = structuredClone(facts.state)
|
|
6829
|
+
state.optimization!.proposal = {
|
|
6830
|
+
id: 'waiting',
|
|
6831
|
+
head: sha(cycles + 2),
|
|
6832
|
+
room: 1,
|
|
6833
|
+
requestedAt: now.toISOString(),
|
|
6834
|
+
round: 100,
|
|
6835
|
+
}
|
|
6836
|
+
const shared = { record, state, workspace: true }
|
|
6837
|
+
const before = requests.vector()
|
|
6838
|
+
for (let repeat = 0; repeat < 5; repeat++) {
|
|
6839
|
+
expect(slotRequest({ ...shared, workspace: false }, now)).toBe('verification')
|
|
6840
|
+
expect(decideNextFromFacts(state, facts.log, config).kind).toBe('measure-progress')
|
|
6841
|
+
expect(strandedNodeWorkspace(shared, now)).toBe(false)
|
|
6842
|
+
state.currentPhase = { phase: 'propose', round: 100, seq: state.lastSeq }
|
|
6843
|
+
expect(slotRequest({ ...shared, workspace: false }, now)).toBe('propose')
|
|
6844
|
+
expect(decideNextFromFacts(state, facts.log, config)).toMatchObject({
|
|
6845
|
+
kind: 'run-phase',
|
|
6846
|
+
phase: 'propose',
|
|
6847
|
+
})
|
|
6848
|
+
expect(strandedNodeWorkspace(shared, now)).toBe(false)
|
|
6849
|
+
delete state.currentPhase
|
|
6850
|
+
}
|
|
6851
|
+
expect(rows.buildRows).toBe(1)
|
|
6852
|
+
expect(gate(due.digest)).toBe('wait-progress')
|
|
6853
|
+
expect(requests.vector()).toEqual(before)
|
|
6854
|
+
const accepted = requests.vector()
|
|
6855
|
+
|
|
6856
|
+
// 3. Recorded progress costs its own row and clears the selection.
|
|
6857
|
+
await progress(cycles)
|
|
6858
|
+
rows.reset()
|
|
6859
|
+
const cleared = await select()
|
|
6860
|
+
expect(rows.buildRows).toBe(1)
|
|
6861
|
+
expect(cleared.due).toBeUndefined()
|
|
6862
|
+
expect(cleared.node).toBe(false)
|
|
6863
|
+
expect(gate(cleared.digest)).toBe('land')
|
|
6864
|
+
rows.reset()
|
|
6865
|
+
await select()
|
|
6866
|
+
expect(rows.buildRows).toBe(0)
|
|
6867
|
+
rowCounts.push(rows.buildRows)
|
|
6868
|
+
measured.push({ idle, accepted, rows: rowCounts })
|
|
6869
|
+
} finally {
|
|
6870
|
+
requests.restore()
|
|
6871
|
+
}
|
|
6872
|
+
}
|
|
6873
|
+
expect(measured[1]).toEqual(measured[0])
|
|
6874
|
+
}
|
|
6875
|
+
|
|
6876
|
+
/** What one pass of check verification cost a leaf build. */
|
|
6877
|
+
export interface VerifyCheckBaseCosts {
|
|
6878
|
+
/** Store calls per method across the check runs. */
|
|
6879
|
+
calls: Record<string, number>
|
|
6880
|
+
/** Event rows the store returned, and how many of them predate the runs. */
|
|
6881
|
+
rows: number
|
|
6882
|
+
historicalRows: number
|
|
6883
|
+
/** Keyed reads of the standalone verify diff base selector. */
|
|
6884
|
+
verifyDiffBaseReads: number
|
|
6885
|
+
/** The `AB_VERIFY_BASE` each check command received, in launch order;
|
|
6886
|
+
* null when the runner did not pass the key, so an inherited value leaks. */
|
|
6887
|
+
bases: (string | undefined | null)[]
|
|
6888
|
+
/** Node mode: whether the running check's signal was aborted. */
|
|
6889
|
+
aborted?: boolean
|
|
6890
|
+
}
|
|
6891
|
+
|
|
6892
|
+
/**
|
|
6893
|
+
* Check verification hands every command the verify diff base from the build
|
|
6894
|
+
* facts the runner already reads. A leaf build carries `length` events of
|
|
6895
|
+
* history, rich in `restack.*` and `phase.failed` facts that move or neighbour
|
|
6896
|
+
* the base; its saved values are warmed once, then one unconditional check,
|
|
6897
|
+
* one conditional check and both members of a staged pair (the stage's
|
|
6898
|
+
* per-member resolve-then-run) execute against a scripted shell. The costs
|
|
6899
|
+
* must be identical at any history length. `provisioned: false` omits the
|
|
6900
|
+
* workspace fact, so the build has no base, and runs only the unconditional
|
|
6901
|
+
* check (a conditional one requires a base).
|
|
6902
|
+
*
|
|
6903
|
+
* `node` runs one check of a node's prepared verification cycle under an
|
|
6904
|
+
* attached runner, firing `beats` live heartbeats while the command runs, so
|
|
6905
|
+
* the landing interruption (a lapsed beat during a node check) is proved to
|
|
6906
|
+
* add no subscription and no reads while the lease stays live.
|
|
6907
|
+
*/
|
|
6908
|
+
export async function verifyCheckBaseReadBudget(opts: {
|
|
6909
|
+
length: number
|
|
6910
|
+
provisioned?: boolean
|
|
6911
|
+
node?: { beats: number }
|
|
6912
|
+
}): Promise<VerifyCheckBaseCosts> {
|
|
6913
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
6914
|
+
const { BuildRunner } = await import('../processes/build-runner')
|
|
6915
|
+
const { readBuildFacts, readPhaseFailures } = await import('../store/reduced-reads')
|
|
6916
|
+
const { steppingClock } = await import('./fixed')
|
|
6917
|
+
const slug = 'verify-base'
|
|
6918
|
+
const base = 'b'.repeat(40)
|
|
6919
|
+
const store = new MemoryBuildStore()
|
|
6920
|
+
await store.createBuild({ slug, repo: 'repo', branch: `ab/${slug}` })
|
|
6921
|
+
const config = parseConfig(
|
|
6922
|
+
'[tickets]\nsource = "file"\nreadyState = "ready"\n\n[roles.default]\nruntime = "scripted"\n',
|
|
6923
|
+
)
|
|
6924
|
+
const nodeHead = 'c'.repeat(40)
|
|
6925
|
+
await store.append(slug, {
|
|
6926
|
+
actor: DISPATCHER,
|
|
6927
|
+
type: 'build.created',
|
|
6928
|
+
payload: {
|
|
6929
|
+
ticket: { source: 'file', id: 'T-1' },
|
|
6930
|
+
repo: 'repo',
|
|
6931
|
+
baseBranch: 'main',
|
|
6932
|
+
...(opts.node ? { kind: 'node' as const } : {}),
|
|
6933
|
+
},
|
|
6934
|
+
})
|
|
6935
|
+
if (opts.node) {
|
|
6936
|
+
const { integrationConfig } = await import('../kernel/integration-state')
|
|
6937
|
+
await store.append(slug, { actor: DISPATCHER, type: 'node.opened', payload: { sha: base } })
|
|
6938
|
+
await store.append(slug, {
|
|
6939
|
+
actor: DISPATCHER,
|
|
6940
|
+
type: 'node.compared',
|
|
6941
|
+
payload: { parentSha: base, headSha: nodeHead, ahead: 1 },
|
|
6942
|
+
})
|
|
6943
|
+
await store.append(slug, {
|
|
6944
|
+
actor: DISPATCHER,
|
|
6945
|
+
type: 'integration.observed',
|
|
6946
|
+
payload: { openChildren: [], diagnostics: [], contributions: ['child'] },
|
|
6947
|
+
})
|
|
6948
|
+
await store.append(slug, {
|
|
6949
|
+
actor: DISPATCHER,
|
|
6950
|
+
type: 'integration.prepared',
|
|
6951
|
+
payload: { id: 'cycle', parent: base, head: nodeHead, config: integrationConfig(config) },
|
|
6952
|
+
})
|
|
6953
|
+
}
|
|
6954
|
+
if (opts.provisioned !== false)
|
|
6955
|
+
await store.append(slug, {
|
|
6956
|
+
actor: DISPATCHER,
|
|
6957
|
+
type: 'workspace.provisioned',
|
|
6958
|
+
payload: {
|
|
6959
|
+
provider: 'fake',
|
|
6960
|
+
ref: 'ws',
|
|
6961
|
+
branch: `ab/${slug}`,
|
|
6962
|
+
base: { source: 'remote', sha: 'a'.repeat(40) },
|
|
6963
|
+
},
|
|
6964
|
+
})
|
|
6965
|
+
// One validated append of each history fact, copied in rotation.
|
|
6966
|
+
const templates = [
|
|
6967
|
+
// A node's history has no leaf restack facts.
|
|
6968
|
+
...(opts.node
|
|
6969
|
+
? []
|
|
6970
|
+
: [
|
|
6971
|
+
await store.append(slug, {
|
|
6972
|
+
actor: KERNEL,
|
|
6973
|
+
type: 'restack.advanced',
|
|
6974
|
+
payload: {
|
|
6975
|
+
trigger: 'wait-resume',
|
|
6976
|
+
cycle: 1,
|
|
6977
|
+
observation: 1,
|
|
6978
|
+
branch: `ab/${slug}`,
|
|
6979
|
+
from: 'a'.repeat(40),
|
|
6980
|
+
to: base,
|
|
6981
|
+
},
|
|
6982
|
+
}),
|
|
6983
|
+
]),
|
|
6984
|
+
await store.append(slug, {
|
|
6985
|
+
actor: KERNEL,
|
|
6986
|
+
type: 'phase.failed',
|
|
6987
|
+
payload: { phase: 'implement', round: 1, attempt: 1, error: 'transient', willRetry: true },
|
|
6988
|
+
}),
|
|
6989
|
+
await store.append(slug, {
|
|
6990
|
+
actor: humanActor('budget'),
|
|
6991
|
+
type: 'build.auto-merge-cancelled',
|
|
6992
|
+
payload: {},
|
|
6993
|
+
}),
|
|
6994
|
+
]
|
|
6995
|
+
const events = buildEventRows(store, slug)
|
|
6996
|
+
while (events.length < opts.length)
|
|
6997
|
+
events.push({
|
|
6998
|
+
...templates[events.length % templates.length]!,
|
|
6999
|
+
seq: events.length + 1,
|
|
7000
|
+
} as (typeof events)[number])
|
|
7001
|
+
const bases: (string | undefined | null)[] = []
|
|
7002
|
+
let beat: (() => void) | undefined
|
|
7003
|
+
let aborted = false
|
|
7004
|
+
const exec: Exec = async (cmd, execOpts) => {
|
|
7005
|
+
if (cmd[0] === 'sh') {
|
|
7006
|
+
bases.push(
|
|
7007
|
+
execOpts.env && 'AB_VERIFY_BASE' in execOpts.env ? execOpts.env.AB_VERIFY_BASE : null,
|
|
7008
|
+
)
|
|
7009
|
+
// Live beats while the command runs; each settles before the next.
|
|
7010
|
+
for (let i = 0; i < (opts.node?.beats ?? 0); i++) {
|
|
7011
|
+
beat!()
|
|
7012
|
+
for (let turn = 0; turn < 10; turn++) await Promise.resolve()
|
|
7013
|
+
}
|
|
7014
|
+
aborted = execOpts.signal?.aborted ?? false
|
|
7015
|
+
return { stdout: '', stderr: '', exitCode: 0 }
|
|
7016
|
+
}
|
|
7017
|
+
if (opts.node && cmd[0] === 'git' && cmd[1] === 'rev-parse' && cmd.includes('HEAD'))
|
|
7018
|
+
return { stdout: `${nodeHead}\n`, stderr: '', exitCode: 0 }
|
|
7019
|
+
if (cmd[0] === 'git' && cmd[1] === 'diff')
|
|
7020
|
+
return { stdout: 'src/changed.ts\0', stderr: '', exitCode: 0 }
|
|
7021
|
+
return { stdout: '', stderr: '', exitCode: 0 }
|
|
7022
|
+
}
|
|
7023
|
+
const runner = new BuildRunner({
|
|
7024
|
+
store: store.scopeBuild(slug),
|
|
7025
|
+
config,
|
|
7026
|
+
runtimes: {
|
|
7027
|
+
scripted: {
|
|
7028
|
+
runner: new ScriptedAgentRunner({ script: () => defaultTurnResult() }),
|
|
7029
|
+
servesModels: [''],
|
|
7030
|
+
},
|
|
7031
|
+
},
|
|
7032
|
+
workspacePath: '/ws',
|
|
7033
|
+
branch: `ab/${slug}`,
|
|
7034
|
+
slug,
|
|
7035
|
+
exec,
|
|
7036
|
+
forge: new FakeForge(),
|
|
7037
|
+
ids: sequentialIds(),
|
|
7038
|
+
clock: steppingClock(),
|
|
7039
|
+
instance: 'runner-1',
|
|
7040
|
+
host: 'test',
|
|
7041
|
+
runtimeIdentity: {
|
|
7042
|
+
version: '0.0.0-test',
|
|
7043
|
+
commit: 'unknown',
|
|
7044
|
+
source: { kind: 'package', location: '/autobuild' },
|
|
7045
|
+
},
|
|
7046
|
+
opts: {
|
|
7047
|
+
scheduleHeartbeat: (fn) => {
|
|
7048
|
+
beat = fn
|
|
7049
|
+
return () => {
|
|
7050
|
+
beat = undefined
|
|
7051
|
+
}
|
|
7052
|
+
},
|
|
7053
|
+
},
|
|
7054
|
+
})
|
|
7055
|
+
type Check = { kind: 'run-check'; step: string; command: string; attempt: number }
|
|
7056
|
+
const internals = runner as unknown as {
|
|
7057
|
+
stopHeartbeat(): void
|
|
7058
|
+
runCheck(decision: Check): Promise<void>
|
|
7059
|
+
evaluateVerify(decision: unknown): Promise<void>
|
|
7060
|
+
resolveVerify(decision: unknown): Promise<Check>
|
|
7061
|
+
}
|
|
7062
|
+
const check = (step: string): Check => ({ kind: 'run-check', step, command: step, attempt: 1 })
|
|
7063
|
+
const conditional = (step: string) => ({
|
|
7064
|
+
kind: 'evaluate-verify',
|
|
7065
|
+
step,
|
|
7066
|
+
attempt: 1,
|
|
7067
|
+
paths: ['src/**'],
|
|
7068
|
+
action: check(step),
|
|
7069
|
+
})
|
|
7070
|
+
const steps = ['unit', 'dashboard', 'lint', 'docs']
|
|
7071
|
+
// A node check runs under an attached runner, whose heartbeat is armed.
|
|
7072
|
+
if (opts.node) await runner.attach()
|
|
7073
|
+
// Warm every saved value the runs read: computed once per key, then served.
|
|
7074
|
+
await readBuildFacts(store, slug)
|
|
7075
|
+
for (const step of steps) await readPhaseFailures(store, slug, `verify:${step}`, 1)
|
|
7076
|
+
const boundary = events.at(-1)!.seq
|
|
7077
|
+
let verifyDiffBaseReads = 0
|
|
7078
|
+
const getReducerValue = store.getReducerValue.bind(store)
|
|
7079
|
+
store.getReducerValue = (async (...args: Parameters<typeof getReducerValue>) => {
|
|
7080
|
+
if (args[1].reducer === 'verifyDiffBaseValue') verifyDiffBaseReads += 1
|
|
7081
|
+
return getReducerValue(...args)
|
|
7082
|
+
}) as typeof store.getReducerValue
|
|
7083
|
+
const metrics = await measureStoreReads(store, async () => {
|
|
7084
|
+
await internals.runCheck(check('unit'))
|
|
7085
|
+
if (opts.provisioned === false || opts.node) return
|
|
7086
|
+
await internals.evaluateVerify(conditional('dashboard'))
|
|
7087
|
+
// A stage resolves each member, then runs the resolved check.
|
|
7088
|
+
const members = await Promise.all([
|
|
7089
|
+
internals.resolveVerify(conditional('lint')),
|
|
7090
|
+
Promise.resolve(check('docs')),
|
|
7091
|
+
])
|
|
7092
|
+
await Promise.all(members.map((member) => internals.runCheck(member)))
|
|
7093
|
+
})
|
|
7094
|
+
Reflect.deleteProperty(store, 'getReducerValue')
|
|
7095
|
+
internals.stopHeartbeat()
|
|
7096
|
+
return {
|
|
7097
|
+
calls: metrics.calls,
|
|
7098
|
+
rows: metrics.rows,
|
|
7099
|
+
historicalRows: metrics.read.filter((row) => row.seq <= boundary).length,
|
|
7100
|
+
verifyDiffBaseReads,
|
|
7101
|
+
bases,
|
|
7102
|
+
...(opts.node ? { aborted } : {}),
|
|
7103
|
+
}
|
|
7104
|
+
}
|
|
7105
|
+
|
|
7106
|
+
/** Operator single-ticket start requests (AUT-1293) cost nothing while none
|
|
7107
|
+
* is pending and one targeted `get` per pending request per tick otherwise,
|
|
7108
|
+
* independent of journal length and of how many unrelated builds are active.
|
|
7109
|
+
* Two identical worlds tick in lockstep with intake off, one with a request,
|
|
7110
|
+
* so the difference is exactly the start stage's cost. Hosted builds' canonical
|
|
7111
|
+
* identities are projected once per build, durably: a fresh dispatcher and a
|
|
7112
|
+
* later request resolve none again. Returns the steady per-tick difference. */
|
|
7113
|
+
export async function ticketStartReadBudget(): Promise<{
|
|
7114
|
+
gets: number
|
|
7115
|
+
calls: Record<string, number>
|
|
7116
|
+
rows: number
|
|
7117
|
+
repoRows: number
|
|
7118
|
+
}> {
|
|
7119
|
+
// While a request waits at full capacity, or is admitted, capacity comes
|
|
7120
|
+
// from the build facts the tick's fleet-wide stages already read, so the
|
|
7121
|
+
// stage adds no per-build read on a fresh process or a warm one.
|
|
7122
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
7123
|
+
const { CONFORMING_BODY } = await import('../scenarios/harness')
|
|
7124
|
+
const { requestTicketStart } = await import('../operator/ticket-start')
|
|
7125
|
+
const sha = 'a'.repeat(40)
|
|
7126
|
+
type Source = import('../ports/types').TicketSource
|
|
7127
|
+
type Run = { gets: number; calls: Record<string, number>; rows: number; repoRows: number }
|
|
7128
|
+
const results = new Map<string, Run[]>()
|
|
7129
|
+
const open = async (
|
|
7130
|
+
builds: number,
|
|
7131
|
+
history: number,
|
|
7132
|
+
capacity: number,
|
|
7133
|
+
label: string,
|
|
7134
|
+
/** AB-0 waits on a blocker whose dependency read fails. */
|
|
7135
|
+
blocked = false,
|
|
7136
|
+
) => {
|
|
7137
|
+
let now = 1_800_000_000_000
|
|
7138
|
+
const clock = () => new Date(now)
|
|
7139
|
+
const store = new MemoryBuildStore({ clock })
|
|
7140
|
+
const repo = `https://github.com/budget/ticket-start-${label}-${builds}-${history}`
|
|
7141
|
+
await store.ensureRepo(repo)
|
|
7142
|
+
for (let i = 0; i < history; i++)
|
|
7143
|
+
await store.appendRepo(repo, {
|
|
7144
|
+
actor: humanActor('budget'),
|
|
7145
|
+
type: 'dispatcher.intake-set',
|
|
7146
|
+
payload: { enabled: false },
|
|
7147
|
+
})
|
|
7148
|
+
const ticket = (id: string): import('../ports/types').Ticket => ({
|
|
7149
|
+
revision: 'budget',
|
|
7150
|
+
ref: { source: 'hosted', id },
|
|
7151
|
+
title: id,
|
|
7152
|
+
body: CONFORMING_BODY,
|
|
7153
|
+
state: 'ready',
|
|
7154
|
+
resolved: false,
|
|
7155
|
+
labels: [],
|
|
7156
|
+
})
|
|
7157
|
+
const fake = new FakeTicketSource(
|
|
7158
|
+
[
|
|
7159
|
+
{ ...ticket('AB-0'), ...(blocked ? { blockedBy: ['AB-B'] } : {}) },
|
|
7160
|
+
{ ...ticket('AB-W'), state: 'doing' },
|
|
7161
|
+
ticket('AB-S'),
|
|
7162
|
+
...Array.from({ length: builds }, (_, i) => ticket(`AB-${i + 1}`)),
|
|
7163
|
+
],
|
|
7164
|
+
{ doneState: 'done' },
|
|
7165
|
+
)
|
|
7166
|
+
const gets: string[] = []
|
|
7167
|
+
const claims: string[] = []
|
|
7168
|
+
const launches: string[] = []
|
|
7169
|
+
const listings = { count: 0 }
|
|
7170
|
+
// A hosted-named source whose `get` also resolves legacy `ticket-<n>` aliases.
|
|
7171
|
+
const tickets = new Proxy(fake, {
|
|
7172
|
+
get(target, key) {
|
|
7173
|
+
if (key === 'name') return 'hosted'
|
|
7174
|
+
// Hosted sources own their assets; the memory store stands in.
|
|
7175
|
+
if (key === 'assets') return store
|
|
7176
|
+
if (key === 'get')
|
|
7177
|
+
return (id: string) => {
|
|
7178
|
+
gets.push(id)
|
|
7179
|
+
return target.get(id.replace(/^ticket-/, 'AB-'))
|
|
7180
|
+
}
|
|
7181
|
+
if (key === 'claim')
|
|
7182
|
+
return (id: string) => {
|
|
7183
|
+
claims.push(id)
|
|
7184
|
+
return target.claim(id)
|
|
7185
|
+
}
|
|
7186
|
+
if (key === 'listReady')
|
|
7187
|
+
return (...args: Parameters<typeof target.listReady>) => {
|
|
7188
|
+
listings.count += 1
|
|
7189
|
+
return target.listReady(...args)
|
|
7190
|
+
}
|
|
7191
|
+
if (key === 'dependencyStates' && blocked)
|
|
7192
|
+
return async () => {
|
|
7193
|
+
throw new Error('dependency read failed')
|
|
7194
|
+
}
|
|
7195
|
+
return Reflect.get(target, key, target)
|
|
7196
|
+
},
|
|
7197
|
+
}) as unknown as Source
|
|
7198
|
+
// Unrelated active builds: legacy aliases and readable ids in mixed case.
|
|
7199
|
+
for (let i = 1; i <= builds; i++) {
|
|
7200
|
+
const ref = { source: 'hosted', id: i % 2 ? `ticket-${i}` : `ab-${i}` }
|
|
7201
|
+
await store.createBuild({
|
|
7202
|
+
slug: `active-${i}`,
|
|
7203
|
+
repo,
|
|
7204
|
+
ticket: ref,
|
|
7205
|
+
branch: `ab/active-${i}`,
|
|
7206
|
+
created: {
|
|
7207
|
+
actor: DISPATCHER,
|
|
7208
|
+
type: 'build.created',
|
|
7209
|
+
payload: { ticket: ref, repo, baseBranch: 'main' },
|
|
7210
|
+
},
|
|
7211
|
+
})
|
|
7212
|
+
}
|
|
7213
|
+
// Unrelated builds this runtime defers for a newer writer's decisive
|
|
7214
|
+
// fact, one per five active builds: they hold slots and their deferral
|
|
7215
|
+
// check reads them on every tick, so capacity must serve that read.
|
|
7216
|
+
const { newerFact, seedNewerMemoryFact } = await import('./newer-writer')
|
|
7217
|
+
const deferred = Math.ceil(builds / 5)
|
|
7218
|
+
for (let i = 1; i <= deferred; i++) {
|
|
7219
|
+
const slug = `deferred-${i}`
|
|
7220
|
+
const ref = { source: 'fake', id: `DEFERRED-${i}` }
|
|
7221
|
+
await store.createBuild({
|
|
7222
|
+
slug,
|
|
7223
|
+
repo,
|
|
7224
|
+
ticket: ref,
|
|
7225
|
+
branch: `ab/${slug}`,
|
|
7226
|
+
created: {
|
|
7227
|
+
actor: DISPATCHER,
|
|
7228
|
+
type: 'build.created',
|
|
7229
|
+
payload: { ticket: ref, repo, baseBranch: 'main' },
|
|
7230
|
+
},
|
|
7231
|
+
})
|
|
7232
|
+
const seq = (await store.getEvents(slug)).length + 1
|
|
7233
|
+
seedNewerMemoryFact(store, newerFact(seq, 'decisive', slug))
|
|
7234
|
+
}
|
|
7235
|
+
// The default scan cadence: each tick advances the clock past it.
|
|
7236
|
+
const config = parseConfig(
|
|
7237
|
+
`capacity = ${capacity + deferred}\n[tickets]\nsource = "hosted"\nteamKey = "ENG"\n[verify]\nsteps = []\n[finalize]\nsteps = []\n`,
|
|
7238
|
+
)
|
|
7239
|
+
const dispatcher = () => {
|
|
7240
|
+
const forge = new FakeForge()
|
|
7241
|
+
forge.seedBranch('main', sha)
|
|
7242
|
+
return new Dispatcher({
|
|
7243
|
+
store,
|
|
7244
|
+
tickets,
|
|
7245
|
+
workspaces: new FakeWorkspaceProvider({
|
|
7246
|
+
root: '/ticket-start-budget',
|
|
7247
|
+
mode: 'logical',
|
|
7248
|
+
base: { source: 'remote', sha },
|
|
7249
|
+
}),
|
|
7250
|
+
forge,
|
|
7251
|
+
config,
|
|
7252
|
+
repo,
|
|
7253
|
+
exec: async () => ({ stdout: `${sha}\trefs/heads/main\n`, stderr: '', exitCode: 0 }),
|
|
7254
|
+
launchRunner: async (slug: string) => {
|
|
7255
|
+
launches.push(slug)
|
|
7256
|
+
return 'scheduled' as const
|
|
7257
|
+
},
|
|
7258
|
+
ids: sequentialIds(),
|
|
7259
|
+
clock,
|
|
7260
|
+
})
|
|
7261
|
+
}
|
|
7262
|
+
// The one serialized reduction per key happens before the measured ticks.
|
|
7263
|
+
await readRepositoryFacts(store, repo)
|
|
7264
|
+
await readBuildDigests(store, repo)
|
|
7265
|
+
let current = dispatcher()
|
|
7266
|
+
return {
|
|
7267
|
+
store,
|
|
7268
|
+
repo,
|
|
7269
|
+
/** Each deferred build recorded its deferral once and never ran. */
|
|
7270
|
+
deferredHeld: async () => {
|
|
7271
|
+
for (let i = 1; i <= deferred; i++) {
|
|
7272
|
+
const events = await store.getEvents(`deferred-${i}`)
|
|
7273
|
+
expect(events.filter((e) => e.type === 'build.compatibility-deferred')).toHaveLength(1)
|
|
7274
|
+
}
|
|
7275
|
+
expect(launches.filter((slug) => slug.startsWith('deferred-'))).toEqual([])
|
|
7276
|
+
},
|
|
7277
|
+
gets,
|
|
7278
|
+
claims,
|
|
7279
|
+
tickets,
|
|
7280
|
+
fresh: () => {
|
|
7281
|
+
current = dispatcher()
|
|
7282
|
+
},
|
|
7283
|
+
tick: async (acceptNewWork = false) => {
|
|
7284
|
+
now += 60_000
|
|
7285
|
+
gets.length = 0
|
|
7286
|
+
listings.count = 0
|
|
7287
|
+
const before = (await store.getRepoEvents(repo)).length
|
|
7288
|
+
const metrics = await measureStoreReads(store, async () => {
|
|
7289
|
+
await current.tick({ acceptNewWork })
|
|
7290
|
+
})
|
|
7291
|
+
const appended = (await store.getRepoEvents(repo)).slice(before)
|
|
7292
|
+
return {
|
|
7293
|
+
gets: [...gets],
|
|
7294
|
+
listReady: listings.count,
|
|
7295
|
+
calls: metrics.calls,
|
|
7296
|
+
rows: metrics.rows,
|
|
7297
|
+
repoRows: metrics.repoRows,
|
|
7298
|
+
appended,
|
|
7299
|
+
}
|
|
7300
|
+
},
|
|
7301
|
+
}
|
|
7302
|
+
}
|
|
7303
|
+
const difference = (a: Record<string, number>, b: Record<string, number>) => {
|
|
7304
|
+
const out: Record<string, number> = {}
|
|
7305
|
+
for (const key of new Set([...Object.keys(a), ...Object.keys(b)])) {
|
|
7306
|
+
const delta = (a[key] ?? 0) - (b[key] ?? 0)
|
|
7307
|
+
if (delta !== 0) out[key] = delta
|
|
7308
|
+
}
|
|
7309
|
+
return out
|
|
7310
|
+
}
|
|
7311
|
+
/** Source reads the pending world made beyond the lockstep control's. */
|
|
7312
|
+
const subtract = (measured: readonly string[], base: readonly string[]) => {
|
|
7313
|
+
const extra = [...measured]
|
|
7314
|
+
for (const id of base) {
|
|
7315
|
+
const index = extra.indexOf(id)
|
|
7316
|
+
expect(index).toBeGreaterThanOrEqual(0)
|
|
7317
|
+
extra.splice(index, 1)
|
|
7318
|
+
}
|
|
7319
|
+
return extra
|
|
7320
|
+
}
|
|
7321
|
+
// History length at a small fleet, fleet size at a short history.
|
|
7322
|
+
for (const [builds, history] of [
|
|
7323
|
+
[5, 100],
|
|
7324
|
+
[5, 5_000],
|
|
7325
|
+
[50, 100],
|
|
7326
|
+
] as const) {
|
|
7327
|
+
// Full capacity: the request waits for a slot.
|
|
7328
|
+
const control = await open(builds, history, builds, 'control')
|
|
7329
|
+
const pending = await open(builds, history, builds, 'pending')
|
|
7330
|
+
// The operator invocation: one get, one reduced value, at most one append.
|
|
7331
|
+
pending.gets.length = 0
|
|
7332
|
+
const invocation = await measureStoreReads(pending.store, async () => {
|
|
7333
|
+
await requestTicketStart({
|
|
7334
|
+
store: pending.store,
|
|
7335
|
+
repo: pending.repo,
|
|
7336
|
+
source: pending.tickets,
|
|
7337
|
+
id: 'AB-0',
|
|
7338
|
+
user: 'budget',
|
|
7339
|
+
})
|
|
7340
|
+
})
|
|
7341
|
+
expect(pending.gets).toEqual(['AB-0'])
|
|
7342
|
+
expect(invocation.calls.getReducerValue).toBe(1)
|
|
7343
|
+
expect(invocation.calls.appendRepo).toBe(1)
|
|
7344
|
+
expect(invocation.calls.getRepoEvents).toBeUndefined()
|
|
7345
|
+
expect(invocation.calls.listBuilds).toBeUndefined()
|
|
7346
|
+
// Projection: at most 16 identity reads per tick, each build once in total.
|
|
7347
|
+
const projectionTicks = Math.ceil(builds / 16)
|
|
7348
|
+
const resolved: string[] = []
|
|
7349
|
+
for (let tick = 0; tick < projectionTicks; tick++) {
|
|
7350
|
+
const base = await control.tick()
|
|
7351
|
+
const measured = await pending.tick()
|
|
7352
|
+
const extra = subtract(measured.gets, base.gets)
|
|
7353
|
+
expect(extra.filter((id) => id === 'AB-0')).toHaveLength(1)
|
|
7354
|
+
const identity = extra.filter((id) => id !== 'AB-0')
|
|
7355
|
+
expect(identity.length).toBeLessThanOrEqual(16)
|
|
7356
|
+
resolved.push(...identity)
|
|
7357
|
+
expect(measured.appended.map((event) => event.type)).toEqual(['ticket.identity-recorded'])
|
|
7358
|
+
}
|
|
7359
|
+
const recorded = Array.from({ length: builds }, (_, i) =>
|
|
7360
|
+
(i + 1) % 2 ? `ticket-${i + 1}` : `ab-${i + 1}`,
|
|
7361
|
+
)
|
|
7362
|
+
expect(resolved.sort()).toEqual(recorded.sort())
|
|
7363
|
+
// Steady state: one get per tick, no identity read, no write, no claim.
|
|
7364
|
+
for (const fresh of [false, true]) {
|
|
7365
|
+
if (fresh) {
|
|
7366
|
+
control.fresh()
|
|
7367
|
+
pending.fresh()
|
|
7368
|
+
}
|
|
7369
|
+
// The unleased builds are relaunched until their launch budget blocks
|
|
7370
|
+
// them. Capacity is measured from the facts the tick's own stages
|
|
7371
|
+
// read, so even a fresh process's first waiting tick reads no build
|
|
7372
|
+
// the control does not.
|
|
7373
|
+
for (let i = 0; i < (fresh ? 1 : 2); i++) {
|
|
7374
|
+
const base = await control.tick()
|
|
7375
|
+
const measured = await pending.tick()
|
|
7376
|
+
expect(measured.rows - base.rows).toBe(0)
|
|
7377
|
+
// Only journal snapshot maintenance may differ while the journals'
|
|
7378
|
+
// lengths differ; no served value or event read is extra.
|
|
7379
|
+
const {
|
|
7380
|
+
putSnapshot: _put,
|
|
7381
|
+
snapshotTail: _tail,
|
|
7382
|
+
...reads
|
|
7383
|
+
} = difference(measured.calls, base.calls)
|
|
7384
|
+
expect(reads).toEqual({})
|
|
7385
|
+
}
|
|
7386
|
+
// Each tick advances the clock past the default scan interval, so
|
|
7387
|
+
// nothing the stage serves expires with time.
|
|
7388
|
+
let calls: Record<string, number> = {}
|
|
7389
|
+
let rows = 0
|
|
7390
|
+
let repoRows = 0
|
|
7391
|
+
let extra: string[] = []
|
|
7392
|
+
for (let i = 0; i < 2; i++) {
|
|
7393
|
+
const base = await control.tick()
|
|
7394
|
+
const measured = await pending.tick()
|
|
7395
|
+
extra = subtract(measured.gets, base.gets)
|
|
7396
|
+
expect(extra).toEqual(['AB-0'])
|
|
7397
|
+
expect(measured.appended).toEqual([])
|
|
7398
|
+
expect(pending.claims).toEqual([])
|
|
7399
|
+
// The pending world reads no build facts the control does not.
|
|
7400
|
+
rows = measured.rows - base.rows
|
|
7401
|
+
repoRows = measured.repoRows - base.repoRows
|
|
7402
|
+
expect(rows).toBe(0)
|
|
7403
|
+
expect(repoRows).toBeLessThanOrEqual(projectionTicks + 1)
|
|
7404
|
+
calls = difference(measured.calls, base.calls)
|
|
7405
|
+
for (const replay of ['getEvents', 'getRepoEvents', 'getBuildEventPage'])
|
|
7406
|
+
expect(calls[replay]).toBeUndefined()
|
|
7407
|
+
expect(calls).toEqual({})
|
|
7408
|
+
}
|
|
7409
|
+
const key = `${builds}:${fresh}`
|
|
7410
|
+
const run = { gets: extra.length, calls, rows, repoRows }
|
|
7411
|
+
results.set(key, [...(results.get(key) ?? []), run])
|
|
7412
|
+
}
|
|
7413
|
+
await pending.deferredHeld()
|
|
7414
|
+
// Cancelling ends the request; the tick after it settles nothing.
|
|
7415
|
+
await pending.store.appendRepo(pending.repo, {
|
|
7416
|
+
actor: humanActor('budget'),
|
|
7417
|
+
type: 'ticket.start-cancelled',
|
|
7418
|
+
payload: {
|
|
7419
|
+
request: (await readRepositoryFacts(pending.store, pending.repo)).value.ticketStarts
|
|
7420
|
+
.pending['hosted:AB-0']!.seq,
|
|
7421
|
+
ticket: { source: 'hosted', id: 'AB-0' },
|
|
7422
|
+
},
|
|
7423
|
+
})
|
|
7424
|
+
await control.tick()
|
|
7425
|
+
await pending.tick()
|
|
7426
|
+
// No request pending: the stage reads nothing, not even identities.
|
|
7427
|
+
const base = await control.tick()
|
|
7428
|
+
const idle = await pending.tick()
|
|
7429
|
+
expect(idle.gets).toEqual(base.gets)
|
|
7430
|
+
expect(difference(idle.calls, base.calls)).toEqual({})
|
|
7431
|
+
expect(idle.appended).toEqual([])
|
|
7432
|
+
await control.store.close()
|
|
7433
|
+
await pending.store.close()
|
|
7434
|
+
}
|
|
7435
|
+
// Identical at every history length; source reads and store requests
|
|
7436
|
+
// identical at every build count.
|
|
7437
|
+
for (const runs of results.values()) for (const run of runs) expect(run).toEqual(runs[0]!)
|
|
7438
|
+
const baseline = results.get('5:false')![0]!
|
|
7439
|
+
for (const runs of results.values()) {
|
|
7440
|
+
expect(runs[0]!.gets).toBe(baseline.gets)
|
|
7441
|
+
expect(runs[0]!.calls).toEqual(baseline.calls)
|
|
7442
|
+
}
|
|
7443
|
+
|
|
7444
|
+
// A free slot: a wait the slot cannot end (a failed dependency read),
|
|
7445
|
+
// repeated on a warm and on a fresh process, then an admission. Each costs
|
|
7446
|
+
// the same beyond the lockstep control at every fleet size.
|
|
7447
|
+
const admissions = new Map<number, Record<string, number>[]>()
|
|
7448
|
+
for (const builds of [5, 50]) {
|
|
7449
|
+
const control = await open(builds, 100, builds + 1, 'admission-control')
|
|
7450
|
+
const world = await open(builds, 100, builds + 1, 'admission', true)
|
|
7451
|
+
const start = (id: string) =>
|
|
7452
|
+
requestTicketStart({
|
|
7453
|
+
store: world.store,
|
|
7454
|
+
repo: world.repo,
|
|
7455
|
+
source: world.tickets,
|
|
7456
|
+
id,
|
|
7457
|
+
user: 'budget',
|
|
7458
|
+
})
|
|
7459
|
+
// `active-1` records the legacy alias `ticket-1` of AB-1, which is
|
|
7460
|
+
// Ready: its request matches through the identity projection and is
|
|
7461
|
+
// never claimed. AB-W is not ready, so its request waits until the
|
|
7462
|
+
// projection is complete, then settles.
|
|
7463
|
+
await start('AB-1')
|
|
7464
|
+
await start('AB-W')
|
|
7465
|
+
const projection = Math.ceil(builds / 16)
|
|
7466
|
+
const settled: unknown[] = []
|
|
7467
|
+
for (let tick = 0; tick < projection; tick++) {
|
|
7468
|
+
await control.tick()
|
|
7469
|
+
const measured = await world.tick()
|
|
7470
|
+
expect(measured.appended[0]?.type).toBe('ticket.identity-recorded')
|
|
7471
|
+
settled.push(
|
|
7472
|
+
...measured.appended
|
|
7473
|
+
.filter((event) => event.type === 'ticket.start-settled')
|
|
7474
|
+
.map((event) => event.payload),
|
|
7475
|
+
)
|
|
7476
|
+
}
|
|
7477
|
+
expect(settled).toEqual([
|
|
7478
|
+
expect.objectContaining({ outcome: 'already-building', slug: 'active-1' }),
|
|
7479
|
+
expect.objectContaining({ outcome: 'not-ready' }),
|
|
7480
|
+
])
|
|
7481
|
+
// Settle both worlds' relaunches before measuring.
|
|
7482
|
+
for (let tick = 0; tick < 2; tick++) {
|
|
7483
|
+
await control.tick()
|
|
7484
|
+
await world.tick()
|
|
7485
|
+
}
|
|
7486
|
+
const measure = async (fresh: boolean) => {
|
|
7487
|
+
if (fresh) {
|
|
7488
|
+
control.fresh()
|
|
7489
|
+
world.fresh()
|
|
7490
|
+
}
|
|
7491
|
+
const base = await control.tick()
|
|
7492
|
+
const measured = await world.tick()
|
|
7493
|
+
expect(measured.rows - base.rows).toBe(0)
|
|
7494
|
+
const {
|
|
7495
|
+
putSnapshot: _put,
|
|
7496
|
+
snapshotTail: _tail,
|
|
7497
|
+
...calls
|
|
7498
|
+
} = difference(measured.calls, base.calls)
|
|
7499
|
+
for (const replay of ['getEvents', 'getRepoEvents', 'getBuildEventPage'])
|
|
7500
|
+
expect(calls[replay]).toBeUndefined()
|
|
7501
|
+
return {
|
|
7502
|
+
calls,
|
|
7503
|
+
settled: measured.appended
|
|
7504
|
+
.filter((event) => event.type === 'ticket.start-settled')
|
|
7505
|
+
.map((event) => event.payload as { outcome: string; ticket: { id: string } }),
|
|
7506
|
+
}
|
|
7507
|
+
}
|
|
7508
|
+
// AB-0's blocker read fails: the request stays pending, unclaimed.
|
|
7509
|
+
await start('AB-0')
|
|
7510
|
+
const waits = []
|
|
7511
|
+
for (const fresh of [false, false, true]) {
|
|
7512
|
+
const wait = await measure(fresh)
|
|
7513
|
+
expect(wait.settled).toEqual([])
|
|
7514
|
+
waits.push(wait.calls)
|
|
7515
|
+
}
|
|
7516
|
+
expect(world.claims).toEqual([])
|
|
7517
|
+
for (const wait of waits) expect(wait).toEqual(waits[0]!)
|
|
7518
|
+
// AB-S takes the free slot beside the still-waiting AB-0.
|
|
7519
|
+
await start('AB-S')
|
|
7520
|
+
const admitted = await measure(false)
|
|
7521
|
+
expect(admitted.settled).toEqual([
|
|
7522
|
+
expect.objectContaining({ outcome: 'started', ticket: { source: 'hosted', id: 'AB-S' } }),
|
|
7523
|
+
])
|
|
7524
|
+
expect(world.claims).toEqual(['AB-S'])
|
|
7525
|
+
await world.deferredHeld()
|
|
7526
|
+
admissions.set(builds, [waits[0]!, admitted.calls])
|
|
7527
|
+
await control.store.close()
|
|
7528
|
+
await world.store.close()
|
|
7529
|
+
}
|
|
7530
|
+
// No per-build read: identical store requests at 5 and at 50 builds.
|
|
7531
|
+
expect(admissions.get(50)).toEqual(admissions.get(5))
|
|
7532
|
+
|
|
7533
|
+
// Priority tiers at full capacity: a normal request is read only by the
|
|
7534
|
+
// post-dispatch pass, once per tick; re-requesting another priority is one
|
|
7535
|
+
// append; a manual request with intake on forces no ready listing. Each is
|
|
7536
|
+
// identical at a short and a long history.
|
|
7537
|
+
const tiers = new Map<number, Record<string, number>[]>()
|
|
7538
|
+
for (const history of [100, 5_000]) {
|
|
7539
|
+
const control = await open(5, history, 5, 'tiers-control')
|
|
7540
|
+
const world = await open(5, history, 5, 'tiers')
|
|
7541
|
+
const request = (priority: 'manual' | 'urgent' | 'normal') =>
|
|
7542
|
+
requestTicketStart({
|
|
7543
|
+
store: world.store,
|
|
7544
|
+
repo: world.repo,
|
|
7545
|
+
source: world.tickets,
|
|
7546
|
+
id: 'AB-0',
|
|
7547
|
+
user: 'budget',
|
|
7548
|
+
priority,
|
|
7549
|
+
})
|
|
7550
|
+
const steady = async (acceptNewWork = false) => {
|
|
7551
|
+
const base = await control.tick(acceptNewWork)
|
|
7552
|
+
const measured = await world.tick(acceptNewWork)
|
|
7553
|
+
expect(subtract(measured.gets, base.gets)).toEqual(['AB-0'])
|
|
7554
|
+
expect(measured.listReady).toBe(base.listReady)
|
|
7555
|
+
expect(measured.rows - base.rows).toBe(0)
|
|
7556
|
+
// With intake on, both worlds record the same ordinary scan.
|
|
7557
|
+
const types = (events: { type: string }[]) => events.map((event) => event.type)
|
|
7558
|
+
expect(types(measured.appended)).toEqual(types(base.appended))
|
|
7559
|
+
// Snapshot upkeep after the request's own append is not a read.
|
|
7560
|
+
const {
|
|
7561
|
+
putSnapshot: _put,
|
|
7562
|
+
snapshotTail: _tail,
|
|
7563
|
+
...calls
|
|
7564
|
+
} = difference(measured.calls, base.calls)
|
|
7565
|
+
for (const replay of ['getEvents', 'getRepoEvents', 'getBuildEventPage'])
|
|
7566
|
+
expect(calls[replay]).toBeUndefined()
|
|
7567
|
+
return calls
|
|
7568
|
+
}
|
|
7569
|
+
await request('normal')
|
|
7570
|
+
// The identity projection ticks first in both worlds.
|
|
7571
|
+
await control.tick()
|
|
7572
|
+
await world.tick()
|
|
7573
|
+
const normal = await steady()
|
|
7574
|
+
world.gets.length = 0
|
|
7575
|
+
const update = await measureStoreReads(world.store, async () => {
|
|
7576
|
+
expect(await request('urgent')).toMatchObject({ updated: true })
|
|
7577
|
+
})
|
|
7578
|
+
expect(world.gets).toEqual(['AB-0'])
|
|
7579
|
+
expect(update.calls.appendRepo).toBe(1)
|
|
7580
|
+
expect(update.calls.getReducerValue).toBe(1)
|
|
7581
|
+
const urgent = await steady()
|
|
7582
|
+
await request('manual')
|
|
7583
|
+
const manual = await steady(true)
|
|
7584
|
+
expect(world.claims).toEqual([])
|
|
7585
|
+
tiers.set(history, [normal, urgent, manual])
|
|
7586
|
+
await control.store.close()
|
|
7587
|
+
await world.store.close()
|
|
7588
|
+
}
|
|
7589
|
+
expect(tiers.get(5_000)).toEqual(tiers.get(100))
|
|
7590
|
+
for (const calls of tiers.get(100)!) expect(calls).toEqual({})
|
|
7591
|
+
return baseline
|
|
7592
|
+
}
|