@defrex/autobuild 1.4.2 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/SPEC.md +512 -101
- package/bin/ab-dispatch-kernel.ts +1 -0
- package/docs/accounts.md +9 -0
- package/docs/agent-runtimes.md +1 -0
- package/docs/answering-blocked-builds.md +7 -3
- package/docs/architecture.md +313 -130
- package/docs/assets/headline-wide.png +0 -0
- package/docs/build-store.md +33 -3
- package/docs/cli.md +2 -1
- package/docs/configuration-overview.md +9 -0
- package/docs/configuration.md +217 -106
- package/docs/dispatcher-hosting.md +19 -3
- package/docs/dispatcher.md +11 -6
- package/docs/glossary.md +1 -1
- package/docs/integration-overview.md +2 -2
- package/docs/integration-tree.md +91 -28
- package/docs/merge-policy.md +28 -9
- package/docs/operating.md +1 -1
- package/docs/operator-api.md +57 -20
- package/docs/operator-surfaces.md +1 -1
- package/docs/plugin-authoring.md +89 -8
- package/docs/remote-store-protocol.md +39 -11
- package/docs/remote-ticket-protocol.md +126 -12
- package/docs/restacking.md +24 -6
- package/docs/seams.md +2 -2
- package/docs/setup.md +19 -13
- package/docs/spec-standard.md +2 -1
- package/docs/ticket-dependencies.md +26 -8
- package/docs/ticket-migration.md +70 -7
- package/docs/ticket-sources.md +82 -5
- package/docs/tickets.md +34 -2
- package/docs/troubleshooting.md +3 -3
- package/docs/verification.md +5 -5
- package/docs/website.md +8 -0
- package/docs/workspaces.md +1 -1
- package/package.json +4 -3
- package/packages/core/src/accounts/hosted-readiness.ts +21 -0
- package/packages/core/src/cli/attention.ts +3 -0
- package/packages/core/src/cli/build-control.ts +36 -12
- package/packages/core/src/cli/connect.ts +9 -18
- package/packages/core/src/cli/context.ts +44 -0
- package/packages/core/src/cli/dashboard/configuration.ts +11 -0
- package/packages/core/src/cli/dashboard/model.ts +51 -11
- package/packages/core/src/cli/dashboard/poll.ts +14 -0
- package/packages/core/src/cli/dashboard/queue.ts +21 -0
- package/packages/core/src/cli/dashboard/render.ts +43 -22
- package/packages/core/src/cli/dispatch-frontend.ts +63 -30
- package/packages/core/src/cli/dispatch-mode.ts +35 -16
- package/packages/core/src/cli/dispatch-preflight.ts +4 -1
- package/packages/core/src/cli/dispatch-repository-feed.ts +40 -11
- package/packages/core/src/cli/dispatch-tickets.ts +47 -0
- package/packages/core/src/cli/dispatch-upgrade-controller.ts +3 -0
- package/packages/core/src/cli/dispatch.ts +522 -145
- package/packages/core/src/cli/help.ts +63 -24
- package/packages/core/src/cli/init-hosted-accounts.ts +54 -0
- package/packages/core/src/cli/init-readiness-remote.ts +16 -3
- package/packages/core/src/cli/init-validation.ts +144 -42
- package/packages/core/src/cli/issue-links.ts +67 -0
- package/packages/core/src/cli/main.ts +32 -15
- package/packages/core/src/cli/pr-summary-publication.ts +38 -7
- package/packages/core/src/cli/publication-settlement.ts +36 -24
- package/packages/core/src/cli/repo-lease.ts +225 -0
- package/packages/core/src/cli/repository-status.ts +203 -49
- package/packages/core/src/cli/status.ts +42 -4
- package/packages/core/src/cli/terminals.ts +37 -2
- package/packages/core/src/cli/ticket-editor.ts +20 -6
- package/packages/core/src/cli/ticket.ts +264 -46
- package/packages/core/src/cli/triage-count-sampler.ts +59 -0
- package/packages/core/src/cli/wait.ts +4 -1
- package/packages/core/src/cli/watch.ts +19 -4
- package/packages/core/src/config/live.ts +45 -4
- package/packages/core/src/config/load.ts +9 -0
- package/packages/core/src/config/pipeline-source.ts +6 -2
- package/packages/core/src/config/ready-assignee.ts +86 -0
- package/packages/core/src/config/schema.ts +202 -38
- package/packages/core/src/distribution-packaging.ts +1 -1
- package/packages/core/src/events/catalog.ts +7 -0
- package/packages/core/src/events/compatibility.ts +2 -1
- package/packages/core/src/events/payloads.ts +85 -0
- package/packages/core/src/events/policy.ts +10 -0
- package/packages/core/src/events/repository.ts +93 -28
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +237 -230
- package/packages/core/src/kernel/build-identity.ts +12 -0
- package/packages/core/src/kernel/change-presence.ts +139 -6
- package/packages/core/src/kernel/dispatch-capacity.ts +189 -19
- package/packages/core/src/kernel/dispatch-status.ts +10 -1
- package/packages/core/src/kernel/dispatch-upgrade.ts +104 -5
- package/packages/core/src/kernel/engine.ts +17 -8
- package/packages/core/src/kernel/finalize-pr-rejection.ts +95 -0
- package/packages/core/src/kernel/generators/build-log.ts +9 -0
- package/packages/core/src/kernel/generators/repository-journals.ts +15 -1
- package/packages/core/src/kernel/harvest.ts +4 -1
- package/packages/core/src/kernel/incremental-fixtures.ts +1 -0
- package/packages/core/src/kernel/integration-completeness.ts +104 -17
- package/packages/core/src/kernel/integration-landing.ts +17 -0
- package/packages/core/src/kernel/integration-state.ts +17 -0
- package/packages/core/src/kernel/issue-keywords.ts +202 -0
- package/packages/core/src/kernel/janitor-failure.ts +96 -5
- package/packages/core/src/kernel/kernel-git.ts +87 -0
- package/packages/core/src/kernel/landing-readiness.ts +25 -17
- package/packages/core/src/kernel/leaf-restack-state.ts +4 -2
- package/packages/core/src/kernel/log-index.ts +1 -1
- package/packages/core/src/kernel/node-issue-links.ts +142 -0
- package/packages/core/src/kernel/node-landing.ts +2 -1
- package/packages/core/src/kernel/node-parent.ts +6 -0
- package/packages/core/src/kernel/node-restack-transaction.ts +2 -0
- package/packages/core/src/kernel/pr-summary.ts +24 -0
- package/packages/core/src/kernel/read-deferrals.ts +75 -12
- package/packages/core/src/kernel/read-facts.ts +32 -1
- package/packages/core/src/kernel/reconcile-restack.ts +1 -1
- package/packages/core/src/kernel/reducer-registry.ts +37 -2
- package/packages/core/src/kernel/reducer.ts +147 -5
- package/packages/core/src/kernel/ticket-preparation.ts +16 -0
- package/packages/core/src/kernel/verify-budget.ts +43 -0
- package/packages/core/src/operator/index.ts +3 -1
- package/packages/core/src/operator/presentation.ts +3 -0
- package/packages/core/src/operator/protocol.ts +38 -2
- package/packages/core/src/operator/query.ts +69 -29
- package/packages/core/src/operator/registry.ts +47 -26
- package/packages/core/src/operator/tickets.ts +77 -10
- package/packages/core/src/plugin-sdk/index.ts +13 -0
- package/packages/core/src/plugins/manifest.ts +1 -1
- package/packages/core/src/plugins/registry.ts +1 -0
- package/packages/core/src/ports/forge/contract.ts +69 -0
- package/packages/core/src/ports/forge/create.ts +5 -0
- package/packages/core/src/ports/forge/fake.ts +184 -3
- package/packages/core/src/ports/forge/git-rewrite.ts +4 -2
- package/packages/core/src/ports/forge/github.ts +175 -38
- package/packages/core/src/ports/forge/local-git.ts +14 -0
- package/packages/core/src/ports/forge/readiness.ts +10 -0
- package/packages/core/src/ports/forge-failure.ts +43 -0
- package/packages/core/src/ports/runner/claude.ts +7 -1
- package/packages/core/src/ports/runner/codex.ts +7 -2
- package/packages/core/src/ports/runner/native-cli-fixture.ts +2 -1
- package/packages/core/src/ports/runner/pi.ts +7 -1
- package/packages/core/src/ports/runner/runtime.ts +3 -0
- package/packages/core/src/ports/runner/start-prompt.ts +37 -0
- package/packages/core/src/ports/tickets/contract.ts +320 -7
- package/packages/core/src/ports/tickets/create.ts +89 -20
- package/packages/core/src/ports/tickets/fake.ts +18 -0
- package/packages/core/src/ports/tickets/file-codec.ts +20 -0
- package/packages/core/src/ports/tickets/file.ts +43 -1
- package/packages/core/src/ports/tickets/github-fake.ts +1123 -0
- package/packages/core/src/ports/tickets/github-issues.ts +431 -0
- package/packages/core/src/ports/tickets/github-validators.ts +194 -0
- package/packages/core/src/ports/tickets/github.ts +2029 -0
- package/packages/core/src/ports/tickets/hosted-index.ts +34 -3
- package/packages/core/src/ports/tickets/issue-links.ts +86 -0
- package/packages/core/src/ports/tickets/lifecycle.ts +60 -4
- package/packages/core/src/ports/tickets/linear.ts +66 -6
- package/packages/core/src/ports/tickets/migration.ts +290 -68
- package/packages/core/src/ports/tickets/operations.ts +98 -12
- package/packages/core/src/ports/tickets/priority.ts +55 -0
- package/packages/core/src/ports/tickets/remote-protocol.ts +195 -29
- package/packages/core/src/ports/tickets/remote.ts +188 -13
- package/packages/core/src/ports/tickets/revision.ts +22 -1
- package/packages/core/src/ports/tickets/states.ts +43 -0
- package/packages/core/src/ports/tickets/tree.ts +58 -12
- package/packages/core/src/ports/tickets/update.ts +12 -2
- package/packages/core/src/ports/types.ts +194 -9
- package/packages/core/src/ports/workspace/commit-preservation.ts +163 -25
- package/packages/core/src/ports/workspace/git-worktree.ts +6 -2
- package/packages/core/src/ports/workspace/harvest-execution.ts +4 -2
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +121 -27
- package/packages/core/src/processes/build-runner.ts +101 -22
- package/packages/core/src/processes/dispatcher.ts +1046 -372
- package/packages/core/src/processes/execution-no-progress.ts +7 -0
- package/packages/core/src/processes/harvest-child.ts +4 -2
- package/packages/core/src/processes/harvest-execution-state.ts +104 -0
- package/packages/core/src/processes/harvest-runner.ts +263 -25
- package/packages/core/src/processes/harvest.ts +5 -8
- package/packages/core/src/processes/tick-publication.ts +12 -2
- package/packages/core/src/processes/ticket-scan-schedule.ts +78 -0
- package/packages/core/src/processes/workspace-preservation.ts +36 -1
- package/packages/core/src/runtime-identity.ts +10 -2
- package/packages/core/src/scenarios/harness.ts +149 -35
- package/packages/core/src/store/adapter.ts +7 -1
- package/packages/core/src/store/contract.ts +83 -2
- package/packages/core/src/store/digest.ts +32 -1
- package/packages/core/src/store/reduced-reads.ts +10 -0
- package/packages/core/src/store/reducer-value-shapes.json +4471 -3427
- package/packages/core/src/store/remote/protocol.ts +2 -0
- package/packages/core/src/store/remote/released-clients.json +22 -0
- package/packages/core/src/store/remote/released-reducer-values/1.5.0.json +26924 -0
- package/packages/core/src/store/remote/released-reducer-values/1.6.0.json +27173 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +4 -0
- package/packages/core/src/store/repo-state-events.ts +2 -0
- package/packages/core/src/store/types.ts +5 -0
- package/packages/core/src/testing/dispatch-read-budget.ts +729 -123
- package/packages/core/src/testing/index.ts +18 -1
- package/packages/core/src/testing/presence-history.ts +79 -0
- package/packages/core/src/testing/reduced-read-budget.ts +1424 -33
- package/packages/core/src/testing/upgrade-generations.ts +77 -0
- package/skills/code-review/SKILL.md +4 -3
- package/skills/finalize/SKILL.md +18 -2
- package/skills/guide/SKILL.md +417 -143
- package/skills/guide/references/accounts.md +9 -0
- package/skills/guide/references/integration-tree.md +91 -28
- package/skills/guide/references/merge-policy.md +28 -9
- package/skills/guide/references/operator-api.md +57 -20
- package/skills/guide/references/plugin-authoring.md +89 -8
- package/skills/guide/references/remote-store-protocol.md +39 -11
- package/skills/guide/references/remote-ticket-protocol.md +126 -12
- package/skills/guide/references/restacking.md +24 -6
- package/skills/guide/references/setup.md +19 -13
- package/skills/guide/references/spec-standard.md +2 -1
- package/skills/guide/references/ticket-dependencies.md +26 -8
- package/skills/guide/references/ticket-migration.md +70 -7
- package/skills/harvest-review/SKILL.md +4 -3
- package/skills/implement/SKILL.md +20 -1
- package/skills/operate/SKILL.md +149 -35
- package/skills/plan/SKILL.md +1 -1
- package/skills/reconcile/SKILL.md +5 -4
- package/skills/spec/SKILL.md +15 -2
- package/skills/tickets/SKILL.md +116 -37
- package/templates/autobuild.toml +5 -0
- package/templates/hosted-service/package.json +2 -2
|
@@ -5,9 +5,11 @@ import { missingAccountCredentials, reconcileMissingAccounts } from '../accounts
|
|
|
5
5
|
import { decideNextFromFacts } from '../kernel/engine'
|
|
6
6
|
import { proveTargetLineage } from '../kernel/target-lineage'
|
|
7
7
|
import { nodeRestackLog } from '../kernel/generators/node-restack-log'
|
|
8
|
+
import { REPLACED_HEADS_CAP } from '../kernel/read-facts'
|
|
8
9
|
import { observeTarget } from '../kernel/target-observation'
|
|
9
10
|
import { autoMergeDeferralObservation } from '../kernel/auto-merge'
|
|
10
11
|
import { mkdtemp, writeFile, rm } from 'node:fs/promises'
|
|
12
|
+
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
11
13
|
import { tmpdir } from 'node:os'
|
|
12
14
|
import { join } from 'node:path'
|
|
13
15
|
import { DashboardBuildPollCache } from '../cli/dashboard/poll'
|
|
@@ -15,7 +17,8 @@ import { abDispatch } from '../cli/dispatch'
|
|
|
15
17
|
import { createTerminalModeController } from '../cli/terminal-restore'
|
|
16
18
|
import { randomUuids } from '../ids'
|
|
17
19
|
import { ScriptedAgentRunner, defaultTurnResult } from '../ports/runner/fake'
|
|
18
|
-
import { Dispatcher } from '../processes/dispatcher'
|
|
20
|
+
import { Dispatcher, defaultTriageState } from '../processes/dispatcher'
|
|
21
|
+
import { boundedStateCount } from '../ports/tickets/states'
|
|
19
22
|
import { FakeTicketSource } from '../ports/tickets/fake'
|
|
20
23
|
import { FakeWorkspaceProvider } from '../ports/workspace/fake'
|
|
21
24
|
import { FakeForge } from '../ports/forge/fake'
|
|
@@ -34,17 +37,30 @@ import { KERNEL, DISPATCHER, humanActor } from '../events/envelope'
|
|
|
34
37
|
import {
|
|
35
38
|
readBuildFacts,
|
|
36
39
|
readBuildStreamSeed,
|
|
40
|
+
readDispatchBudget,
|
|
37
41
|
readRepositoryFacts,
|
|
38
42
|
readForgeHealth,
|
|
39
43
|
readRepositoryAttention,
|
|
40
44
|
readBuildDigests,
|
|
41
45
|
readDispatcherRunFacts,
|
|
42
46
|
readOpenTick,
|
|
47
|
+
readHostedHarvestAuthority,
|
|
43
48
|
} from '../store/reduced-reads'
|
|
49
|
+
import { decideHostedHarvestAuthority } from '../processes/harvest-execution-state'
|
|
44
50
|
import { RepoViewStore } from '../processes/repo-view'
|
|
51
|
+
import { settlePendingPublication } from '../cli/publication-settlement'
|
|
52
|
+
import {
|
|
53
|
+
readLaunchFence,
|
|
54
|
+
refreshSummaryBoundary,
|
|
55
|
+
settleSummaryRequests,
|
|
56
|
+
summaryHandoffPending,
|
|
57
|
+
} from '../cli/pr-summary-publication'
|
|
58
|
+
import { ForgeRequestDeferred } from '../ports/forge-request-context'
|
|
45
59
|
import { abWatch, decodeCursor } from '../cli/watch'
|
|
46
60
|
import { abWait } from '../cli/wait'
|
|
61
|
+
import { TRIAGE_COUNT_REFRESH_MS } from '../cli/triage-count-sampler'
|
|
47
62
|
import type { Exec } from '../ports/workspace/git-worktree'
|
|
63
|
+
export { syntheticPresenceObservation } from './presence-history'
|
|
48
64
|
|
|
49
65
|
export interface ReducedReadCosts {
|
|
50
66
|
events: number
|
|
@@ -209,6 +225,7 @@ export async function reducedReadBudget(opts: {
|
|
|
209
225
|
costs.bytes = 0
|
|
210
226
|
}
|
|
211
227
|
let repositoryBytes: number | undefined
|
|
228
|
+
let deferredScanProbe: { metadata: number; bytes: number } | undefined
|
|
212
229
|
for (const length of [32, 256]) {
|
|
213
230
|
for (let i = 0; i < length; i++) {
|
|
214
231
|
await store.append(slug, {
|
|
@@ -404,10 +421,18 @@ export async function reducedReadBudget(opts: {
|
|
|
404
421
|
launchRunner: async () => 'scheduled',
|
|
405
422
|
})
|
|
406
423
|
await dispatcher().observeReady()
|
|
424
|
+
// A fresh journal anchor per length keeps the cadence counts identical.
|
|
425
|
+
const latest = (await readRepositoryFacts(cold, repo)).value.scan
|
|
426
|
+
if (latest === undefined) throw new Error('missing ticket scan fact')
|
|
427
|
+
await store.appendRepo(repo, {
|
|
428
|
+
actor: DISPATCHER,
|
|
429
|
+
type: 'dispatcher.ticket-scan-completed',
|
|
430
|
+
payload: { ...latest, startedAt: new Date(scanTime).toISOString() },
|
|
431
|
+
})
|
|
407
432
|
const scanSeq = (await readRepositoryFacts(cold, repo)).value.scanSeq
|
|
408
433
|
let cadenceReads = 0
|
|
409
434
|
let cadenceWrites = 0
|
|
410
|
-
|
|
435
|
+
const countedHandle = async () => {
|
|
411
436
|
const freshHandle = await opts.fresh()
|
|
412
437
|
const counted = new Proxy(freshHandle, {
|
|
413
438
|
get(target, key) {
|
|
@@ -425,19 +450,56 @@ export async function reducedReadBudget(opts: {
|
|
|
425
450
|
return typeof value === 'function' ? value.bind(target) : value
|
|
426
451
|
},
|
|
427
452
|
})
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
453
|
+
return { freshHandle, counted }
|
|
454
|
+
}
|
|
455
|
+
const scanDispatcher = (counted: BuildStore) =>
|
|
456
|
+
new Dispatcher({
|
|
457
|
+
store: counted,
|
|
458
|
+
repo,
|
|
459
|
+
config,
|
|
460
|
+
tickets: new FakeTicketSource([]),
|
|
461
|
+
workspaces: new FakeWorkspaceProvider({ root: '/budget-workspaces', mode: 'logical' }),
|
|
462
|
+
forge: new FakeForge(),
|
|
463
|
+
ids: sequentialIds(),
|
|
464
|
+
clock: () => new Date(scanTime),
|
|
465
|
+
exec,
|
|
466
|
+
launchRunner: async () => 'scheduled',
|
|
467
|
+
})
|
|
468
|
+
// While the journal measurement alone proves the scan is not due, fresh
|
|
469
|
+
// processes make no cadence request and read no event rows.
|
|
470
|
+
const anchorTime = scanTime
|
|
471
|
+
let deferred: { metadata: number; bytes: number } | undefined
|
|
472
|
+
for (let k = 1; k < 6; k++) {
|
|
473
|
+
scanTime = anchorTime + k * 10_000
|
|
474
|
+
const { freshHandle, counted } = await countedHandle()
|
|
475
|
+
reset()
|
|
476
|
+
await scanDispatcher(counted).observeReady()
|
|
477
|
+
deferred ??= { metadata: costs.metadata, bytes: costs.bytes }
|
|
478
|
+
expect(costs.events).toBe(0)
|
|
479
|
+
expect(cadenceReads).toBe(0)
|
|
480
|
+
expect((await readRepositoryFacts(freshHandle, repo)).value.scanSeq).toBe(scanSeq)
|
|
481
|
+
}
|
|
482
|
+
if (deferredScanProbe === undefined) deferredScanProbe = deferred
|
|
483
|
+
else {
|
|
484
|
+
// Flat with history: the repository facts value is bounded, as above.
|
|
485
|
+
expect(deferred!.metadata).toBe(deferredScanProbe!.metadata)
|
|
486
|
+
expect(deferred!.bytes).toBeLessThan(deferredScanProbe!.bytes + 512)
|
|
487
|
+
}
|
|
488
|
+
// At the interval the row is consulted; the unchanged scan advances only it.
|
|
489
|
+
scanTime = anchorTime + 60_000
|
|
490
|
+
{
|
|
491
|
+
const { freshHandle, counted } = await countedHandle()
|
|
492
|
+
reset()
|
|
493
|
+
await scanDispatcher(counted).observeReady()
|
|
494
|
+
expect(costs.events).toBe(0)
|
|
495
|
+
expect(cadenceReads).toBe(1)
|
|
496
|
+
expect(cadenceWrites).toBe(1)
|
|
497
|
+
expect(deferred!.metadata).toBeLessThan(costs.metadata)
|
|
498
|
+
expect((await readRepositoryFacts(freshHandle, repo)).value.scanSeq).toBe(scanSeq)
|
|
499
|
+
}
|
|
500
|
+
for (let interval = 0; interval < 3; interval++) {
|
|
501
|
+
const { freshHandle, counted } = await countedHandle()
|
|
502
|
+
const observe = () => scanDispatcher(counted).observeReady()
|
|
441
503
|
scanTime += 30_000
|
|
442
504
|
reset()
|
|
443
505
|
await observe()
|
|
@@ -450,8 +512,8 @@ export async function reducedReadBudget(opts: {
|
|
|
450
512
|
expect(costs.metadata).toBeLessThan(100)
|
|
451
513
|
expect((await readRepositoryFacts(freshHandle, repo)).value.scanSeq).toBe(scanSeq)
|
|
452
514
|
}
|
|
453
|
-
expect(cadenceReads).toBe(
|
|
454
|
-
expect(cadenceWrites).toBe(
|
|
515
|
+
expect(cadenceReads).toBe(7)
|
|
516
|
+
expect(cadenceWrites).toBe(4)
|
|
455
517
|
await dispatcher().tick({ acceptNewWork: false })
|
|
456
518
|
await getOperatorDashboard({ store: cold, repo, clock: () => new Date(1000) })
|
|
457
519
|
reset()
|
|
@@ -732,6 +794,240 @@ export async function targetLineageReadBudget(opts: {
|
|
|
732
794
|
/** Exercise the real outer DispatchLoop with a new invocation identity, either
|
|
733
795
|
* once or for cold and warmed interactive ticks. Only shared values are warmed:
|
|
734
796
|
* no parameterized run value may hide a cold replay. */
|
|
797
|
+
/** A finalize request parked behind its forge-rejection escalation costs the
|
|
798
|
+
* same at every journal length and reads no event rows while nothing changes:
|
|
799
|
+
* no provider probe, description read or forge request per tick. */
|
|
800
|
+
export async function finalizePrRejectionReadBudget(opts: {
|
|
801
|
+
store: BuildStore
|
|
802
|
+
costs: ReducedReadCosts
|
|
803
|
+
fresh: () => Promise<BuildStore>
|
|
804
|
+
}) {
|
|
805
|
+
const { store, costs } = opts
|
|
806
|
+
const build = 'finalize-rejection-budget'
|
|
807
|
+
const branch = `ab/${build}`
|
|
808
|
+
const sha = 'f'.repeat(40)
|
|
809
|
+
await store.createBuild({ slug: build, repo, branch })
|
|
810
|
+
await store.append(build, {
|
|
811
|
+
actor: DISPATCHER,
|
|
812
|
+
type: 'build.created',
|
|
813
|
+
payload: { ticket: { source: 'file', id: 'BUDGET-PR' }, repo, baseBranch: 'main' },
|
|
814
|
+
})
|
|
815
|
+
await store.append(build, {
|
|
816
|
+
actor: KERNEL,
|
|
817
|
+
type: 'workspace.provisioned',
|
|
818
|
+
payload: {
|
|
819
|
+
provider: 'vercel-sandbox',
|
|
820
|
+
remote: true,
|
|
821
|
+
ref: 'sandbox-budget',
|
|
822
|
+
branch,
|
|
823
|
+
base: { source: 'remote', sha: 'e'.repeat(40) },
|
|
824
|
+
},
|
|
825
|
+
})
|
|
826
|
+
const description = await store.putArtifact(build, {
|
|
827
|
+
kind: 'pr-description',
|
|
828
|
+
content: '# Budget\n\nBody.\n',
|
|
829
|
+
})
|
|
830
|
+
await store.append(build, {
|
|
831
|
+
actor: { kind: 'agent', role: 'finalize', session: 'budget-finalize' },
|
|
832
|
+
type: 'publication.requested',
|
|
833
|
+
payload: {
|
|
834
|
+
operation: 'finalize',
|
|
835
|
+
branch,
|
|
836
|
+
sha,
|
|
837
|
+
description: { kind: description.kind, rev: description.revision },
|
|
838
|
+
},
|
|
839
|
+
})
|
|
840
|
+
const forge = new FakeForge()
|
|
841
|
+
forge.setHeadSha(sha)
|
|
842
|
+
forge.rejectNextOpenPr(422, 'Validation Failed: No commits between main and ab/x', 'GitHub')
|
|
843
|
+
let probes = 0
|
|
844
|
+
const settle = (reader: BuildStore) =>
|
|
845
|
+
settlePendingPublication(
|
|
846
|
+
{
|
|
847
|
+
store: reader,
|
|
848
|
+
storeRef: 'budget',
|
|
849
|
+
publication: {
|
|
850
|
+
isPublished: async () => {
|
|
851
|
+
probes++
|
|
852
|
+
return true
|
|
853
|
+
},
|
|
854
|
+
publish: async () => {},
|
|
855
|
+
},
|
|
856
|
+
forge,
|
|
857
|
+
workspacePath: '/budget',
|
|
858
|
+
checkoutless: true,
|
|
859
|
+
exec: async () => ({ stdout: '', stderr: '', exitCode: 0 }),
|
|
860
|
+
ids: sequentialIds(),
|
|
861
|
+
runId: 'budget',
|
|
862
|
+
},
|
|
863
|
+
build,
|
|
864
|
+
)
|
|
865
|
+
await expect(settle(store)).rejects.toBeInstanceOf(ForgeRequestDeferred)
|
|
866
|
+
const raised = async () =>
|
|
867
|
+
(await store.getEvents(build)).filter((event) => event.type === 'escalation.raised').length
|
|
868
|
+
expect(await raised()).toBe(1)
|
|
869
|
+
const bytes = new Map<string, number>()
|
|
870
|
+
let metadata: number | undefined
|
|
871
|
+
let seeded = (await store.getEvents(build)).length
|
|
872
|
+
for (const length of [100, 10_000]) {
|
|
873
|
+
for (; seeded < length; seeded++)
|
|
874
|
+
await store.append(build, {
|
|
875
|
+
actor: humanActor('budget'),
|
|
876
|
+
type: 'build.auto-merge-cancelled',
|
|
877
|
+
payload: {},
|
|
878
|
+
})
|
|
879
|
+
for (const [name, reader] of [
|
|
880
|
+
['live', store],
|
|
881
|
+
['fresh', await opts.fresh()],
|
|
882
|
+
] as const) {
|
|
883
|
+
// Catching up to the padded tail is allowed once per reader.
|
|
884
|
+
await expect(settle(reader)).rejects.toBeInstanceOf(ForgeRequestDeferred)
|
|
885
|
+
costs.events = costs.metadata = costs.bytes = 0
|
|
886
|
+
probes = 0
|
|
887
|
+
const attempts = forge.openPrAttempts
|
|
888
|
+
for (let tick = 0; tick < 3; tick++)
|
|
889
|
+
await expect(settle(reader)).rejects.toBeInstanceOf(ForgeRequestDeferred)
|
|
890
|
+
expect(costs.events).toBe(0)
|
|
891
|
+
expect(probes).toBe(0)
|
|
892
|
+
expect(forge.openPrAttempts).toBe(attempts)
|
|
893
|
+
if (length === 100) {
|
|
894
|
+
metadata ??= costs.metadata
|
|
895
|
+
expect(costs.metadata).toBeLessThan(20)
|
|
896
|
+
bytes.set(name, costs.bytes)
|
|
897
|
+
} else {
|
|
898
|
+
// Seq digits grow in the saved value; allow 100 bytes per measured call.
|
|
899
|
+
expect(costs.bytes).toBeLessThanOrEqual(bytes.get(name)! + 300)
|
|
900
|
+
}
|
|
901
|
+
expect(costs.metadata).toBe(metadata!)
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
expect(forge.openPrAttempts).toBe(1)
|
|
905
|
+
expect(await raised()).toBe(1)
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
/** Remote summary handoff: the dispatcher's launch fence and exit
|
|
909
|
+
* classification plus the guest's coalescing boundary read reduced values
|
|
910
|
+
* only, at constant cost in build length. */
|
|
911
|
+
export async function summaryHandoffReadBudget(opts: {
|
|
912
|
+
store: BuildStore
|
|
913
|
+
costs: ReducedReadCosts
|
|
914
|
+
fresh: () => Promise<BuildStore>
|
|
915
|
+
}) {
|
|
916
|
+
const { store, costs } = opts
|
|
917
|
+
const build = 'summary-handoff-budget'
|
|
918
|
+
const branch = `ab/${build}`
|
|
919
|
+
await store.createBuild({ slug: build, repo, branch })
|
|
920
|
+
await store.append(build, {
|
|
921
|
+
actor: DISPATCHER,
|
|
922
|
+
type: 'build.created',
|
|
923
|
+
payload: { ticket: { source: 'file', id: 'BUDGET-SUMMARY' }, repo, baseBranch: 'main' },
|
|
924
|
+
})
|
|
925
|
+
await store.append(build, {
|
|
926
|
+
actor: KERNEL,
|
|
927
|
+
type: 'workspace.provisioned',
|
|
928
|
+
payload: {
|
|
929
|
+
provider: 'vercel-sandbox',
|
|
930
|
+
remote: true,
|
|
931
|
+
ref: 'sandbox-summary',
|
|
932
|
+
branch,
|
|
933
|
+
base: { source: 'remote', sha: 'e'.repeat(40) },
|
|
934
|
+
},
|
|
935
|
+
})
|
|
936
|
+
const forge = new FakeForge()
|
|
937
|
+
const pr = await forge.openPr({
|
|
938
|
+
workspacePath: '/budget',
|
|
939
|
+
head: branch,
|
|
940
|
+
base: 'main',
|
|
941
|
+
title: 'Budget',
|
|
942
|
+
body: '',
|
|
943
|
+
})
|
|
944
|
+
await store.append(build, { actor: KERNEL, type: 'finalize.completed', payload: { pr } })
|
|
945
|
+
await store.append(build, {
|
|
946
|
+
actor: KERNEL,
|
|
947
|
+
type: 'verify.started',
|
|
948
|
+
payload: { step: 'unit', attempt: 1 },
|
|
949
|
+
})
|
|
950
|
+
await store.append(build, {
|
|
951
|
+
actor: KERNEL,
|
|
952
|
+
type: 'verify.completed',
|
|
953
|
+
payload: { step: 'unit', attempt: 1, outcome: 'pass' },
|
|
954
|
+
})
|
|
955
|
+
const deps = (reader: BuildStore) => ({
|
|
956
|
+
store: reader,
|
|
957
|
+
forge,
|
|
958
|
+
slug: build,
|
|
959
|
+
workspacePath: '/budget',
|
|
960
|
+
storeRef: 'budget',
|
|
961
|
+
clock: () => new Date(),
|
|
962
|
+
})
|
|
963
|
+
// Launch fence, then the guest writes its request and exits.
|
|
964
|
+
const fence = await readLaunchFence(store, build)
|
|
965
|
+
expect(await refreshSummaryBoundary(deps(store))).toBe(true)
|
|
966
|
+
expect(summaryHandoffPending((await readBuildFacts(store, build)).value, fence)).toBe(true)
|
|
967
|
+
await settleSummaryRequests({ ...deps(store), holder: 'budget-host' })
|
|
968
|
+
expect(forge.comments).toHaveLength(1)
|
|
969
|
+
// One launch and exit: fence, completion classification, guest boundary.
|
|
970
|
+
const sequence = async (reader: BuildStore, launchFence: number) => {
|
|
971
|
+
const next = await readLaunchFence(reader, build)
|
|
972
|
+
const pending = summaryHandoffPending((await readBuildFacts(reader, build)).value, launchFence)
|
|
973
|
+
const yielded = await refreshSummaryBoundary(deps(reader), {
|
|
974
|
+
continuesVerifyCycle: true,
|
|
975
|
+
reassert: true,
|
|
976
|
+
})
|
|
977
|
+
return { next, pending, yielded }
|
|
978
|
+
}
|
|
979
|
+
const bytes = new Map<string, number>()
|
|
980
|
+
let metadata: number | undefined
|
|
981
|
+
let seeded = (await store.getEvents(build)).length
|
|
982
|
+
for (const length of [100, 10_000]) {
|
|
983
|
+
for (; seeded < length; seeded++)
|
|
984
|
+
await store.append(build, {
|
|
985
|
+
actor: humanActor('budget'),
|
|
986
|
+
type: 'build.auto-merge-cancelled',
|
|
987
|
+
payload: {},
|
|
988
|
+
})
|
|
989
|
+
for (const [name, reader] of [
|
|
990
|
+
['live', store],
|
|
991
|
+
['fresh', await opts.fresh()],
|
|
992
|
+
] as const) {
|
|
993
|
+
// Catching up to the padded tail is allowed once per reader.
|
|
994
|
+
const launchFence = (await sequence(reader, fence)).next
|
|
995
|
+
costs.events = costs.metadata = costs.bytes = 0
|
|
996
|
+
for (let exit = 0; exit < 3; exit++)
|
|
997
|
+
expect(await sequence(reader, launchFence)).toEqual({
|
|
998
|
+
next: launchFence,
|
|
999
|
+
pending: false,
|
|
1000
|
+
yielded: false,
|
|
1001
|
+
})
|
|
1002
|
+
expect(costs.events).toBe(0)
|
|
1003
|
+
if (length === 100) {
|
|
1004
|
+
metadata ??= costs.metadata
|
|
1005
|
+
expect(costs.metadata).toBeLessThan(20)
|
|
1006
|
+
bytes.set(name, costs.bytes)
|
|
1007
|
+
} else {
|
|
1008
|
+
// Seq digits grow in the saved value; allow 100 bytes per measured call.
|
|
1009
|
+
expect(costs.bytes).toBeLessThanOrEqual(bytes.get(name)! + 300)
|
|
1010
|
+
}
|
|
1011
|
+
expect(costs.metadata).toBe(metadata!)
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
// A guest-written request is the only new tail the next exit reads.
|
|
1015
|
+
const launchFence = await readLaunchFence(store, build)
|
|
1016
|
+
const fresh = await opts.fresh()
|
|
1017
|
+
await sequence(fresh, launchFence)
|
|
1018
|
+
await store.append(build, {
|
|
1019
|
+
actor: KERNEL,
|
|
1020
|
+
type: 'pr-summary.requested',
|
|
1021
|
+
payload: (await readBuildFacts(store, build)).value.summaryBoundary!,
|
|
1022
|
+
})
|
|
1023
|
+
for (const reader of [store, fresh]) {
|
|
1024
|
+
costs.events = 0
|
|
1025
|
+
expect((await sequence(reader, launchFence)).pending).toBe(true)
|
|
1026
|
+
expect(costs.events).toBeLessThanOrEqual(3)
|
|
1027
|
+
}
|
|
1028
|
+
expect(forge.comments).toHaveLength(1)
|
|
1029
|
+
}
|
|
1030
|
+
|
|
735
1031
|
async function coldDispatchOnceBudget(
|
|
736
1032
|
store: BuildStore,
|
|
737
1033
|
cold: BuildStore,
|
|
@@ -775,6 +1071,23 @@ steps = []
|
|
|
775
1071
|
let ticketScanWrites = 0
|
|
776
1072
|
let deferredAttempts = 0
|
|
777
1073
|
let tickAcquisitions = { facts: 0, digests: 0 }
|
|
1074
|
+
// The display-only triage sample is read only by a dispatcher that feeds
|
|
1075
|
+
// an interactive frontend, between ticks and at most once per
|
|
1076
|
+
// TRIAGE_COUNT_REFRESH_MS; no read ever lands inside a tick window.
|
|
1077
|
+
const startedAt = Date.now()
|
|
1078
|
+
let stateReads = 0
|
|
1079
|
+
let stateReadsInTick = 0
|
|
1080
|
+
let tickOpen = false
|
|
1081
|
+
const tickets = Object.assign(new FakeTicketSource([]), {
|
|
1082
|
+
countStates: async (names: readonly string[]) => {
|
|
1083
|
+
stateReads++
|
|
1084
|
+
if (tickOpen) stateReadsInTick++
|
|
1085
|
+
return names.map((name) => ({ name, tickets: 2 }))
|
|
1086
|
+
},
|
|
1087
|
+
listStates: async () => {
|
|
1088
|
+
throw new Error('the triage sample never lists ticket states')
|
|
1089
|
+
},
|
|
1090
|
+
})
|
|
778
1091
|
const checked = new Proxy(cold, {
|
|
779
1092
|
get(target, key) {
|
|
780
1093
|
if (interactive && key === 'beginRepoTick')
|
|
@@ -786,14 +1099,19 @@ steps = []
|
|
|
786
1099
|
expect(costs.historicalEvents).toBe(0)
|
|
787
1100
|
acquisitions.facts = acquisitions.digests = ticketScanWrites = 0
|
|
788
1101
|
costs.events = costs.historicalEvents = 0
|
|
1102
|
+
tickOpen = true
|
|
789
1103
|
return target.beginRepoTick(...args)
|
|
790
1104
|
}
|
|
791
1105
|
if (interactive && key === 'finishRepoTick')
|
|
792
|
-
return (...args: Parameters<BuildStore['finishRepoTick']>) => {
|
|
1106
|
+
return async (...args: Parameters<BuildStore['finishRepoTick']>) => {
|
|
793
1107
|
// Close the kernel window before the independent dashboard poll.
|
|
794
1108
|
tickAcquisitions = { ...acquisitions, facts: acquisitions.facts - ticketScanWrites }
|
|
795
|
-
|
|
796
|
-
|
|
1109
|
+
try {
|
|
1110
|
+
if (outage && ticks === 0) throw new Error('budget tick write refused')
|
|
1111
|
+
return await target.finishRepoTick(...args)
|
|
1112
|
+
} finally {
|
|
1113
|
+
tickOpen = false
|
|
1114
|
+
}
|
|
797
1115
|
}
|
|
798
1116
|
if (interactive && key === 'appendRepo')
|
|
799
1117
|
return (...args: Parameters<BuildStore['appendRepo']>) => {
|
|
@@ -861,6 +1179,11 @@ steps = []
|
|
|
861
1179
|
// Drain the asynchronous launch gate before closing each tick window.
|
|
862
1180
|
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
863
1181
|
expect(tickAcquisitions).toEqual({ facts: 1, digests: 1 })
|
|
1182
|
+
expect(stateReadsInTick).toBe(0)
|
|
1183
|
+
expect(stateReads).toBeLessThanOrEqual(
|
|
1184
|
+
interactive ? Math.ceil((Date.now() - startedAt) / TRIAGE_COUNT_REFRESH_MS) + 1 : 0,
|
|
1185
|
+
)
|
|
1186
|
+
if (interactive) expect(stateReads).toBeGreaterThan(0)
|
|
864
1187
|
expect(costs.historicalEvents).toBe(0)
|
|
865
1188
|
expect(costs.events).toBeLessThanOrEqual(32)
|
|
866
1189
|
// Prepare the newly written tick-completed tail, then prove an
|
|
@@ -874,11 +1197,12 @@ steps = []
|
|
|
874
1197
|
if (++ticks === (outage ? 3 : 2)) stop.abort()
|
|
875
1198
|
},
|
|
876
1199
|
kernelRunId: run,
|
|
1200
|
+
...(interactive ? { frontendStatus: true } : {}),
|
|
877
1201
|
storeRef: '/budget',
|
|
878
1202
|
wire: () => ({
|
|
879
1203
|
store: checked,
|
|
880
1204
|
storeRef: '/budget',
|
|
881
|
-
tickets
|
|
1205
|
+
tickets,
|
|
882
1206
|
forge: new FakeForge(),
|
|
883
1207
|
workspaces: new FakeWorkspaceProvider({ root: '/once-workspaces', mode: 'logical' }),
|
|
884
1208
|
buildExecution: {
|
|
@@ -903,6 +1227,8 @@ steps = []
|
|
|
903
1227
|
([id]) => id === run,
|
|
904
1228
|
)?.[1]
|
|
905
1229
|
expect(finished?.completed?.type).toBe('dispatcher.tick-completed')
|
|
1230
|
+
if (interactive) expect(finished?.completed?.payload).toMatchObject({ triage: 2 })
|
|
1231
|
+
else expect(finished?.completed?.payload).not.toHaveProperty('triage')
|
|
906
1232
|
expect(finished?.stop?.type).toBe('dispatcher.run-stopped')
|
|
907
1233
|
// The same fresh invocation may fail before writing its start fact.
|
|
908
1234
|
expect(
|
|
@@ -1060,6 +1386,7 @@ export async function parkedSweepReadBudget(opts: {
|
|
|
1060
1386
|
},
|
|
1061
1387
|
})
|
|
1062
1388
|
let seeded = 0
|
|
1389
|
+
const idleRequests: Record<string, number>[] = []
|
|
1063
1390
|
for (const length of [100, 100_000]) {
|
|
1064
1391
|
for (; seeded < length; seeded++) {
|
|
1065
1392
|
await store.append(slugs[0]!, {
|
|
@@ -1146,6 +1473,31 @@ export async function parkedSweepReadBudget(opts: {
|
|
|
1146
1473
|
expect(metrics.bodies).toBe(slugs.length)
|
|
1147
1474
|
expect(blobReads).toBe(slugs.length)
|
|
1148
1475
|
expect(metrics.historicalRows).toBe(0)
|
|
1476
|
+
// Idle admission ticks over settled parked builds: capacity adds no
|
|
1477
|
+
// recurring read and writes nothing, at either history length.
|
|
1478
|
+
reset()
|
|
1479
|
+
await dispatcher.tick({ acceptNewWork: false })
|
|
1480
|
+
const baseline = { meta: metrics.meta, bodies: metrics.bodies }
|
|
1481
|
+
const idle = opts.dispatcher()
|
|
1482
|
+
opts.advance()
|
|
1483
|
+
// Warm intake's own projections and persist their snapshots.
|
|
1484
|
+
for (const _ of [0, 1]) {
|
|
1485
|
+
await idle.tick({ acceptNewWork: true })
|
|
1486
|
+
opts.advance()
|
|
1487
|
+
}
|
|
1488
|
+
for (const _ of [0, 1]) {
|
|
1489
|
+
opts.advance()
|
|
1490
|
+
reset()
|
|
1491
|
+
const requests = await countStoreRequests(store, () =>
|
|
1492
|
+
idle.tick({ acceptNewWork: true }).then(() => undefined),
|
|
1493
|
+
)
|
|
1494
|
+
expect(requests.append ?? 0).toBe(0)
|
|
1495
|
+
expect(requests.appendIfCurrent ?? 0).toBe(0)
|
|
1496
|
+
expect(metrics.historicalRows).toBe(0)
|
|
1497
|
+
expect({ meta: metrics.meta, bodies: metrics.bodies }).toEqual(baseline)
|
|
1498
|
+
if (idleRequests.length) expect(requests).toEqual(idleRequests[0]!)
|
|
1499
|
+
idleRequests.push(requests)
|
|
1500
|
+
}
|
|
1149
1501
|
console.log('parked sweep read budget', {
|
|
1150
1502
|
history: length,
|
|
1151
1503
|
builds: slugs.length,
|
|
@@ -1160,6 +1512,35 @@ export async function parkedSweepReadBudget(opts: {
|
|
|
1160
1512
|
}
|
|
1161
1513
|
}
|
|
1162
1514
|
|
|
1515
|
+
/** Count every MemoryBuildStore method call made while `run` executes. */
|
|
1516
|
+
async function countStoreRequests(
|
|
1517
|
+
store: import('../store/memory').MemoryBuildStore,
|
|
1518
|
+
run: () => Promise<void>,
|
|
1519
|
+
): Promise<Record<string, number>> {
|
|
1520
|
+
const counts: Record<string, number> = {}
|
|
1521
|
+
const names = Object.getOwnPropertyNames(Object.getPrototypeOf(store)).filter(
|
|
1522
|
+
(name) => name !== 'constructor' && typeof Reflect.get(store, name) === 'function',
|
|
1523
|
+
)
|
|
1524
|
+
const restore: (() => void)[] = []
|
|
1525
|
+
for (const name of names) {
|
|
1526
|
+
const own = Object.getOwnPropertyDescriptor(store, name)
|
|
1527
|
+
const original = Reflect.get(store, name) as (...args: unknown[]) => unknown
|
|
1528
|
+
Reflect.set(store, name, (...args: unknown[]) => {
|
|
1529
|
+
counts[name] = (counts[name] ?? 0) + 1
|
|
1530
|
+
return original.apply(store, args)
|
|
1531
|
+
})
|
|
1532
|
+
restore.push(() =>
|
|
1533
|
+
own ? Object.defineProperty(store, name, own) : Reflect.deleteProperty(store, name),
|
|
1534
|
+
)
|
|
1535
|
+
}
|
|
1536
|
+
try {
|
|
1537
|
+
await run()
|
|
1538
|
+
} finally {
|
|
1539
|
+
for (const undo of restore) undo()
|
|
1540
|
+
}
|
|
1541
|
+
return counts
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1163
1544
|
/** Append filler facts to one build until its log holds `length` events. */
|
|
1164
1545
|
async function seedBuildFiller(
|
|
1165
1546
|
store: import('../store/memory').MemoryBuildStore,
|
|
@@ -1272,6 +1653,134 @@ export async function flaggedWorkspaceSweepReadBudget(opts: {
|
|
|
1272
1653
|
})
|
|
1273
1654
|
}
|
|
1274
1655
|
|
|
1656
|
+
/** A provision continuation that reaches its launch for a build at the
|
|
1657
|
+
* no-progress limit applies the guard instead of starting a runner. Each
|
|
1658
|
+
* continuation is a recurring invocation (every re-provision, every remote
|
|
1659
|
+
* dispatch), so it must read no seeded history and the same reduced values,
|
|
1660
|
+
* artifacts and tail rows at 100 and 100,000 events, both in the whole tick
|
|
1661
|
+
* and in the guarded launch window after `workspace.provisioned`. */
|
|
1662
|
+
export async function provisionContinuationGuardReadBudget(opts: {
|
|
1663
|
+
store: import('../store/memory').MemoryBuildStore
|
|
1664
|
+
/** Seeds a fresh build whose next tick kicks a remote provision
|
|
1665
|
+
* continuation with `tail`, and returns its slug. Called before filler. */
|
|
1666
|
+
seed: (tail: 'launch' | 'dispatch', length: number) => Promise<string>
|
|
1667
|
+
/** A fresh dispatcher per measured invocation: no per-process cache. */
|
|
1668
|
+
dispatcher: () => Dispatcher
|
|
1669
|
+
advance: () => void
|
|
1670
|
+
launches: () => number
|
|
1671
|
+
}) {
|
|
1672
|
+
const { store } = opts
|
|
1673
|
+
const configKind = 'build-runner-effective-config'
|
|
1674
|
+
type Counts = { reduced: Record<string, number>; configReads: number; tailRows: number }
|
|
1675
|
+
const results: Record<string, { tick: Counts; launchWindow: Counts }> = {}
|
|
1676
|
+
for (const tail of ['launch', 'dispatch'] as const) {
|
|
1677
|
+
for (const length of [100, 100_000]) {
|
|
1678
|
+
const slug = await opts.seed(tail, length)
|
|
1679
|
+
// Filler is a progress fact, so it precedes the no-progress streak.
|
|
1680
|
+
await seedBuildFiller(store, slug, length)
|
|
1681
|
+
for (const instance of ['empty-a', 'empty-b', 'empty-c']) {
|
|
1682
|
+
await store.append(slug, {
|
|
1683
|
+
actor: DISPATCHER,
|
|
1684
|
+
type: 'execution.started',
|
|
1685
|
+
payload: { instance, provider: 'remote-test', workspaceRef: 'sandbox-g0' },
|
|
1686
|
+
})
|
|
1687
|
+
await store.append(slug, {
|
|
1688
|
+
actor: DISPATCHER,
|
|
1689
|
+
type: 'execution.ended',
|
|
1690
|
+
payload: { instance, workspaceRef: 'sandbox-g0', outcome: 'completed', exitCode: 0 },
|
|
1691
|
+
})
|
|
1692
|
+
}
|
|
1693
|
+
// Materialize every build-scoped value the tick reads once, without a
|
|
1694
|
+
// tick, which would itself kick the continuation being measured. A
|
|
1695
|
+
// first reduction per key is canonical; the measured tick must only
|
|
1696
|
+
// advance saved values over its own tail.
|
|
1697
|
+
expect((await readBuildFacts(store, slug)).value.executionNoProgress.count).toBe(3)
|
|
1698
|
+
for (const reducer of ['buildDigest', 'baseBranchValue', 'publishedBranchHeadValue'])
|
|
1699
|
+
await store.getReducerValue({ kind: 'build', slug }, { reducer })
|
|
1700
|
+
// The remote provider is recovery-capable, so it owns the workspace.
|
|
1701
|
+
await readDispatchBudget(store, slug, true)
|
|
1702
|
+
const boundary = buildEventRows(store, slug).at(-1)!.seq
|
|
1703
|
+
const rows = { historicalRows: 0, tailRows: 0 }
|
|
1704
|
+
const counts = (): Counts => ({ reduced: {}, configReads: 0, tailRows: 0 })
|
|
1705
|
+
const tick = counts()
|
|
1706
|
+
let atProvision: Counts | undefined
|
|
1707
|
+
const getReducerValue = store.getReducerValue.bind(store)
|
|
1708
|
+
store.getReducerValue = async (scope, request) => {
|
|
1709
|
+
if (scope.kind === 'build' && scope.slug === slug)
|
|
1710
|
+
tick.reduced[request.reducer] = (tick.reduced[request.reducer] ?? 0) + 1
|
|
1711
|
+
return getReducerValue(scope, request)
|
|
1712
|
+
}
|
|
1713
|
+
const getArtifact = store.getArtifact.bind(store)
|
|
1714
|
+
store.getArtifact = async (...args) => {
|
|
1715
|
+
if (args[0] === slug && args[1] === configKind) tick.configReads++
|
|
1716
|
+
return getArtifact(...args)
|
|
1717
|
+
}
|
|
1718
|
+
const append = store.append.bind(store)
|
|
1719
|
+
store.append = (async (...args: Parameters<typeof append>) => {
|
|
1720
|
+
const result = await append(...args)
|
|
1721
|
+
if (args[0] === slug && args[1].type === 'workspace.provisioned')
|
|
1722
|
+
atProvision = { ...structuredClone(tick), tailRows: rows.tailRows }
|
|
1723
|
+
return result
|
|
1724
|
+
}) as typeof store.append
|
|
1725
|
+
const restoreRows = instrumentBuildRows(store, slug, () => boundary, rows)
|
|
1726
|
+
const launchesBefore = opts.launches()
|
|
1727
|
+
try {
|
|
1728
|
+
opts.advance()
|
|
1729
|
+
const dispatcher = opts.dispatcher()
|
|
1730
|
+
await dispatcher.tick({ acceptNewWork: false })
|
|
1731
|
+
await dispatcher.drainProvisioning()
|
|
1732
|
+
} finally {
|
|
1733
|
+
restoreRows()
|
|
1734
|
+
Reflect.deleteProperty(store, 'getReducerValue')
|
|
1735
|
+
Reflect.deleteProperty(store, 'getArtifact')
|
|
1736
|
+
Reflect.deleteProperty(store, 'append')
|
|
1737
|
+
}
|
|
1738
|
+
tick.tailRows = rows.tailRows
|
|
1739
|
+
const appended = buildEventRows(store, slug).at(-1)!.seq - boundary
|
|
1740
|
+
expect(rows.historicalRows).toBe(0)
|
|
1741
|
+
expect(atProvision).toBeDefined()
|
|
1742
|
+
const launchWindow: Counts = {
|
|
1743
|
+
reduced: Object.fromEntries(
|
|
1744
|
+
Object.entries(tick.reduced).map(([reducer, n]) => [
|
|
1745
|
+
reducer,
|
|
1746
|
+
n - (atProvision!.reduced[reducer] ?? 0),
|
|
1747
|
+
]),
|
|
1748
|
+
),
|
|
1749
|
+
configReads: tick.configReads - atProvision!.configReads,
|
|
1750
|
+
tailRows: tick.tailRows - atProvision!.tailRows,
|
|
1751
|
+
}
|
|
1752
|
+
const events = buildEventRows(store, slug).filter((event) => event.seq > boundary)
|
|
1753
|
+
expect(
|
|
1754
|
+
events.filter(
|
|
1755
|
+
(event) =>
|
|
1756
|
+
event.type === 'escalation.raised' &&
|
|
1757
|
+
event.payload.policyCause === 'execution-no-progress',
|
|
1758
|
+
),
|
|
1759
|
+
).toHaveLength(1)
|
|
1760
|
+
expect(opts.launches()).toBe(launchesBefore)
|
|
1761
|
+
// The guarded launch window reads the reduced build facts twice on
|
|
1762
|
+
// either tail: the continuation's own queued check, and the guard's
|
|
1763
|
+
// read after its refresh. The dispatch tail's completion boundaries
|
|
1764
|
+
// already add three on main: the mixed-version check, the discard
|
|
1765
|
+
// check, and the pre-launch re-read. The guard's decision reads the
|
|
1766
|
+
// pinned config once (the fixture carries no verify pin).
|
|
1767
|
+
expect(launchWindow.reduced.buildReadFacts).toBe(tail === 'launch' ? 2 : 5)
|
|
1768
|
+
expect(launchWindow.configReads).toBe(1)
|
|
1769
|
+
// Tail rows are only rows this invocation appended (each read at most
|
|
1770
|
+
// once per reduced read that advances over it).
|
|
1771
|
+
expect(launchWindow.tailRows).toBeLessThanOrEqual(appended * tick.reduced.buildReadFacts!)
|
|
1772
|
+
results[`${tail}:${length}`] = { tick, launchWindow }
|
|
1773
|
+
}
|
|
1774
|
+
expect(results[`${tail}:100`]).toEqual(results[`${tail}:100000`]!)
|
|
1775
|
+
}
|
|
1776
|
+
console.log('provision continuation guard read budget', {
|
|
1777
|
+
histories: [100, 100_000],
|
|
1778
|
+
launch: results['launch:100000'],
|
|
1779
|
+
dispatch: results['dispatch:100000'],
|
|
1780
|
+
historicalRows: 0,
|
|
1781
|
+
})
|
|
1782
|
+
}
|
|
1783
|
+
|
|
1275
1784
|
/** In-memory history seeding for preparation budgets; never used as a recurring read. */
|
|
1276
1785
|
export async function seedPreparationHistory(store: BuildStore, repo: string, facts: number) {
|
|
1277
1786
|
await store.ensureRepo(repo)
|
|
@@ -1386,6 +1895,13 @@ export async function nodePollingReadBudget(opts: {
|
|
|
1386
1895
|
slug: string
|
|
1387
1896
|
tick: () => Promise<unknown>
|
|
1388
1897
|
advance: (ms: number) => void
|
|
1898
|
+
/** Seed every 10th event as a recorded child's issue links: 10 children at
|
|
1899
|
+
* 100 events and 10,000 at 100,000, over a bounded issue set. */
|
|
1900
|
+
issueLinkChildren?: boolean
|
|
1901
|
+
/** Proves the node still waits for a runner slot after each measured tick,
|
|
1902
|
+
* so the every-tick admission stage is measured on its waiting path. Its
|
|
1903
|
+
* own reads are excluded from the measurement. */
|
|
1904
|
+
slotWaiting?: () => Promise<boolean>
|
|
1389
1905
|
}) {
|
|
1390
1906
|
const { store, slug } = opts
|
|
1391
1907
|
const checkpoint = (await readBuildFacts(store, slug)).value.state.nodePolling!
|
|
@@ -1393,16 +1909,32 @@ export async function nodePollingReadBudget(opts: {
|
|
|
1393
1909
|
let baseline: number[] | undefined
|
|
1394
1910
|
for (const length of [100, 100_000]) {
|
|
1395
1911
|
for (; seeded < length; seeded++)
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1912
|
+
if (opts.issueLinkChildren && seeded % 10 === 0)
|
|
1913
|
+
await store.append(slug, {
|
|
1914
|
+
actor: DISPATCHER,
|
|
1915
|
+
type: 'node.issue-links-recorded',
|
|
1916
|
+
payload: {
|
|
1917
|
+
build: `child-${seeded}`,
|
|
1918
|
+
issueLinks: [
|
|
1919
|
+
{
|
|
1920
|
+
issue: (seeded % 50) + 1,
|
|
1921
|
+
intent: seeded % 7 ? 'closes' : 'refs',
|
|
1922
|
+
...(seeded % 11 === 0 ? { downgraded: true as const } : {}),
|
|
1923
|
+
},
|
|
1924
|
+
],
|
|
1925
|
+
},
|
|
1926
|
+
})
|
|
1927
|
+
else
|
|
1928
|
+
await store.append(slug, {
|
|
1929
|
+
actor: DISPATCHER,
|
|
1930
|
+
type: 'node.poll-checked',
|
|
1931
|
+
payload: {
|
|
1932
|
+
activityKey: checkpoint.activityKey,
|
|
1933
|
+
unchangedSince: checkpoint.unchangedSince,
|
|
1934
|
+
nodeIdleAfterSeconds: checkpoint.nodeIdleAfterSeconds,
|
|
1935
|
+
nodeIdlePollSeconds: checkpoint.nodeIdlePollSeconds,
|
|
1936
|
+
},
|
|
1937
|
+
})
|
|
1406
1938
|
await store.append(slug, {
|
|
1407
1939
|
actor: humanActor('budget'),
|
|
1408
1940
|
type: 'build.hold-requested',
|
|
@@ -1438,31 +1970,248 @@ export async function nodePollingReadBudget(opts: {
|
|
|
1438
1970
|
expect(rows).toBeLessThanOrEqual(8)
|
|
1439
1971
|
if (elapsed === 10_000) expect(rows).toBe(0)
|
|
1440
1972
|
costs.push(rows, calls)
|
|
1973
|
+
if (opts.slotWaiting) expect(await opts.slotWaiting()).toBe(true)
|
|
1974
|
+
history = 0
|
|
1441
1975
|
}
|
|
1442
1976
|
} finally {
|
|
1443
1977
|
Reflect.deleteProperty(events, 'slice')
|
|
1444
1978
|
store.getReducerValue = getReduced
|
|
1445
1979
|
}
|
|
1980
|
+
// A status-style read serves the saved reduced value without history.
|
|
1981
|
+
history = 0
|
|
1982
|
+
events.slice = (start, end) => {
|
|
1983
|
+
const selected = slice(start, end)
|
|
1984
|
+
history += selected.filter((event) => event.seq <= boundary).length
|
|
1985
|
+
return selected
|
|
1986
|
+
}
|
|
1987
|
+
try {
|
|
1988
|
+
const status = (await readBuildFacts(store, slug)).value.state
|
|
1989
|
+
if (opts.issueLinkChildren) expect(status.nodeIssueLinks?.builds).toHaveLength(length / 10)
|
|
1990
|
+
expect(history).toBe(0)
|
|
1991
|
+
} finally {
|
|
1992
|
+
Reflect.deleteProperty(events, 'slice')
|
|
1993
|
+
}
|
|
1446
1994
|
if (baseline) expect(costs).toEqual(baseline)
|
|
1447
1995
|
baseline = costs
|
|
1448
1996
|
}
|
|
1449
1997
|
}
|
|
1450
1998
|
|
|
1451
|
-
/**
|
|
1999
|
+
/** Node child discovery (AUT-1129) reads only the digest batch plus facts for
|
|
2000
|
+
* builds whose digest names the node. Fresh dispatchers (one per hosted
|
|
2001
|
+
* invocation) observing an open node spend the same store reads at 10 and at
|
|
2002
|
+
* 1,000 unrelated builds, never read an unrelated build outside the digest
|
|
2003
|
+
* batch, and read zero event rows on an unchanged tick. */
|
|
2004
|
+
export async function nodeChildDiscoveryReadBudget(opts: {
|
|
2005
|
+
store: import('../store/memory').MemoryBuildStore
|
|
2006
|
+
repo: string
|
|
2007
|
+
/** One tick on a fresh dispatcher. */
|
|
2008
|
+
tick: () => Promise<unknown>
|
|
2009
|
+
advance: (ms: number) => void
|
|
2010
|
+
/** Exhaustive ticket listings so far: proves observation actually ran. */
|
|
2011
|
+
observed: () => number
|
|
2012
|
+
}) {
|
|
2013
|
+
const { store, repo } = opts
|
|
2014
|
+
const ticket = { source: 'fake', id: 'UNRELATED' }
|
|
2015
|
+
const created = (target?: string, kind?: 'node') => ({
|
|
2016
|
+
actor: DISPATCHER,
|
|
2017
|
+
type: 'build.created' as const,
|
|
2018
|
+
payload: {
|
|
2019
|
+
ticket,
|
|
2020
|
+
repo,
|
|
2021
|
+
baseBranch: 'main',
|
|
2022
|
+
...(kind ? { kind } : {}),
|
|
2023
|
+
...(target ? { target: { ticket, build: target } } : {}),
|
|
2024
|
+
},
|
|
2025
|
+
})
|
|
2026
|
+
const terminal = async (slug: string, target?: string, kind?: 'node') => {
|
|
2027
|
+
await store.createBuild({ slug, repo, ticket, created: created(target, kind) })
|
|
2028
|
+
await store.append(slug, {
|
|
2029
|
+
actor: DISPATCHER,
|
|
2030
|
+
type: 'build.completed',
|
|
2031
|
+
payload: { outcome: 'merged' },
|
|
2032
|
+
})
|
|
2033
|
+
}
|
|
2034
|
+
// Half the unrelated builds target a different, finished node: the filter
|
|
2035
|
+
// is per node, not "has any target".
|
|
2036
|
+
await terminal('unrelated-node', undefined, 'node')
|
|
2037
|
+
const unrelated = new Set(['unrelated-node'])
|
|
2038
|
+
const methods = [
|
|
2039
|
+
'getReducerValue',
|
|
2040
|
+
'getEvents',
|
|
2041
|
+
'getBuild',
|
|
2042
|
+
'getArtifact',
|
|
2043
|
+
'getLatestArtifactMeta',
|
|
2044
|
+
'listArtifacts',
|
|
2045
|
+
'getRepoBuildDigests',
|
|
2046
|
+
] as const
|
|
2047
|
+
let baseline: Record<string, number> | undefined
|
|
2048
|
+
for (const count of [10, 1000]) {
|
|
2049
|
+
while (unrelated.size <= count) {
|
|
2050
|
+
const slug = `unrelated-${unrelated.size}`
|
|
2051
|
+
await terminal(slug, unrelated.size % 2 ? 'unrelated-node' : undefined)
|
|
2052
|
+
unrelated.add(slug)
|
|
2053
|
+
}
|
|
2054
|
+
// Saved reduced values for the new builds settle once.
|
|
2055
|
+
await opts.tick()
|
|
2056
|
+
const calls: Record<string, number> = {}
|
|
2057
|
+
let strays = 0
|
|
2058
|
+
const originals = new Map<string, unknown>()
|
|
2059
|
+
for (const method of methods) {
|
|
2060
|
+
const original = Reflect.get(store, method) as (...args: unknown[]) => Promise<unknown>
|
|
2061
|
+
originals.set(method, original)
|
|
2062
|
+
Reflect.set(store, method, (...args: unknown[]) => {
|
|
2063
|
+
const [first, second] = args as [unknown, { reducer?: string } | undefined]
|
|
2064
|
+
// The per-key reads behind the digest batch are the listing every
|
|
2065
|
+
// tick already pays; they are not per-build discovery reads.
|
|
2066
|
+
if (method !== 'getReducerValue' || second?.reducer !== 'buildDigest') {
|
|
2067
|
+
calls[method] = (calls[method] ?? 0) + 1
|
|
2068
|
+
const slug =
|
|
2069
|
+
typeof first === 'string'
|
|
2070
|
+
? first
|
|
2071
|
+
: first && typeof first === 'object' && 'slug' in first
|
|
2072
|
+
? first.slug
|
|
2073
|
+
: undefined
|
|
2074
|
+
if (typeof slug === 'string' && unrelated.has(slug)) strays++
|
|
2075
|
+
}
|
|
2076
|
+
return original.apply(store, args)
|
|
2077
|
+
})
|
|
2078
|
+
}
|
|
2079
|
+
const logs = [
|
|
2080
|
+
...(
|
|
2081
|
+
Reflect.get(store, 'builds') as Map<
|
|
2082
|
+
string,
|
|
2083
|
+
{ events: import('../events/catalog').AbEvent[] }
|
|
2084
|
+
>
|
|
2085
|
+
).values(),
|
|
2086
|
+
]
|
|
2087
|
+
let rows = 0
|
|
2088
|
+
for (const { events } of logs) {
|
|
2089
|
+
const slice = events.slice.bind(events)
|
|
2090
|
+
events.slice = (start, end) => {
|
|
2091
|
+
const selected = slice(start, end)
|
|
2092
|
+
rows += selected.length
|
|
2093
|
+
return selected
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
try {
|
|
2097
|
+
const listings = opts.observed()
|
|
2098
|
+
// Past the integration poll window, so the node observes its children.
|
|
2099
|
+
opts.advance(301_000)
|
|
2100
|
+
await opts.tick()
|
|
2101
|
+
expect(opts.observed()).toBeGreaterThan(listings)
|
|
2102
|
+
expect(strays).toBe(0)
|
|
2103
|
+
const costs = { ...calls }
|
|
2104
|
+
// Nothing changes: a fresh process reads no event rows.
|
|
2105
|
+
opts.advance(10_000)
|
|
2106
|
+
await opts.tick()
|
|
2107
|
+
rows = 0
|
|
2108
|
+
opts.advance(10_000)
|
|
2109
|
+
await opts.tick()
|
|
2110
|
+
expect(rows).toBe(0)
|
|
2111
|
+
expect(strays).toBe(0)
|
|
2112
|
+
if (baseline) expect(costs).toEqual(baseline)
|
|
2113
|
+
baseline = costs
|
|
2114
|
+
} finally {
|
|
2115
|
+
for (const { events } of logs) Reflect.deleteProperty(events, 'slice')
|
|
2116
|
+
for (const method of methods) Reflect.deleteProperty(store, method)
|
|
2117
|
+
for (const [method, original] of originals)
|
|
2118
|
+
if (Reflect.get(store, method) !== original) Reflect.set(store, method, original)
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
|
|
2123
|
+
/** A kernel Git outage is one durable repository condition. Fresh
|
|
2124
|
+
* dispatchers (one per hosted invocation) read it from the saved repository
|
|
2125
|
+
* value: while nothing changes each tick spends at most one failed Git spawn
|
|
2126
|
+
* and reads zero event rows, at 100 and at 100,000 events. */
|
|
2127
|
+
export async function kernelGitOutageReadBudget(opts: {
|
|
2128
|
+
store: import('../store/memory').MemoryBuildStore
|
|
2129
|
+
repo: string
|
|
2130
|
+
slug: string
|
|
2131
|
+
/** One tick on a fresh dispatcher whose kernel Git cannot execute. */
|
|
2132
|
+
tick: () => Promise<unknown>
|
|
2133
|
+
advance: (ms: number) => void
|
|
2134
|
+
/** Kernel Git spawns attempted so far. */
|
|
2135
|
+
spawns: () => number
|
|
2136
|
+
}) {
|
|
2137
|
+
const { store, repo, slug } = opts
|
|
2138
|
+
const unavailable = async () =>
|
|
2139
|
+
(await store.getRepoEvents(repo)).filter(
|
|
2140
|
+
(event) => event.type === 'dispatcher.kernel-git-unavailable',
|
|
2141
|
+
).length
|
|
2142
|
+
let seeded = 0
|
|
2143
|
+
let baseline: number[] | undefined
|
|
2144
|
+
for (const length of [100, 100_000]) {
|
|
2145
|
+
for (; seeded < length; seeded++) {
|
|
2146
|
+
await store.appendRepo(repo, {
|
|
2147
|
+
actor: humanActor('budget'),
|
|
2148
|
+
type: 'dispatcher.intake-set',
|
|
2149
|
+
payload: { enabled: true },
|
|
2150
|
+
})
|
|
2151
|
+
if (seeded % 10 === 0)
|
|
2152
|
+
await store.append(slug, {
|
|
2153
|
+
actor: KERNEL,
|
|
2154
|
+
type: 'observation.recorded',
|
|
2155
|
+
payload: { id: `obs-${seeded}`, kind: 'followup', summary: `budget padding ${seeded}` },
|
|
2156
|
+
})
|
|
2157
|
+
}
|
|
2158
|
+
// Warm up: the outage tick, then one fresh read that catches up its own
|
|
2159
|
+
// append. Nothing changes after that.
|
|
2160
|
+
for (let n = 0; n < 2; n++) {
|
|
2161
|
+
opts.advance(120_000)
|
|
2162
|
+
await opts.tick()
|
|
2163
|
+
}
|
|
2164
|
+
const counter = memoryRepositoryReadCounter(store, repo)
|
|
2165
|
+
const costs: number[] = []
|
|
2166
|
+
for (let n = 0; n < 3; n++) {
|
|
2167
|
+
opts.advance(120_000)
|
|
2168
|
+
counter.reset()
|
|
2169
|
+
const before = opts.spawns()
|
|
2170
|
+
await opts.tick()
|
|
2171
|
+
expect(counter.rows).toBe(0)
|
|
2172
|
+
expect(counter.buildRows).toBe(0)
|
|
2173
|
+
expect(opts.spawns() - before).toBeLessThanOrEqual(1)
|
|
2174
|
+
costs.push(counter.rows, counter.buildRows, counter.reducedCalls, opts.spawns() - before)
|
|
2175
|
+
}
|
|
2176
|
+
expect(await unavailable()).toBe(1)
|
|
2177
|
+
if (baseline) expect(costs).toEqual(baseline)
|
|
2178
|
+
baseline = costs
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
|
|
2182
|
+
/** Expired sampled owners resolve once through exact persisted run values;
|
|
2183
|
+
* historical abandoned preparations never replay and a new one reports once. */
|
|
1452
2184
|
export async function stoppedOwnerWatchReadBudget() {
|
|
1453
2185
|
const { MemoryBuildStore } = await import('../store/memory')
|
|
1454
2186
|
const { manualClock } = await import('./fixed')
|
|
1455
2187
|
let previousBytes: number | undefined
|
|
2188
|
+
const abandon = (store: BuildStore, attempt: string) =>
|
|
2189
|
+
store.appendRepo(repo, {
|
|
2190
|
+
actor: DISPATCHER,
|
|
2191
|
+
type: 'ticket-preparation.resolved',
|
|
2192
|
+
payload: {
|
|
2193
|
+
attempt,
|
|
2194
|
+
ticket: { source: 'fake', id: attempt },
|
|
2195
|
+
outcome: 'abandoned',
|
|
2196
|
+
reason: 'Ticket no longer exists; ticket unchanged.',
|
|
2197
|
+
claimed: false,
|
|
2198
|
+
},
|
|
2199
|
+
})
|
|
1456
2200
|
for (const length of [100, 100_000]) {
|
|
1457
2201
|
const clock = manualClock()
|
|
1458
2202
|
const store = new MemoryBuildStore({ clock })
|
|
1459
2203
|
await store.ensureRepo(repo)
|
|
1460
|
-
for (let i = 0; i < length; i++)
|
|
2204
|
+
for (let i = 0; i < length; i++) {
|
|
2205
|
+
if (i % 1000 === 50) {
|
|
2206
|
+
await abandon(store, `historical-${i}`)
|
|
2207
|
+
continue
|
|
2208
|
+
}
|
|
1461
2209
|
await store.appendRepo(repo, {
|
|
1462
2210
|
actor: humanActor('human'),
|
|
1463
2211
|
type: 'dispatcher.intake-set',
|
|
1464
2212
|
payload: { enabled: true },
|
|
1465
2213
|
})
|
|
2214
|
+
}
|
|
1466
2215
|
const start = async (run: string) => {
|
|
1467
2216
|
await store.appendRepo(repo, {
|
|
1468
2217
|
actor: DISPATCHER,
|
|
@@ -1518,6 +2267,7 @@ export async function stoppedOwnerWatchReadBudget() {
|
|
|
1518
2267
|
await stop('B')
|
|
1519
2268
|
await start('C')
|
|
1520
2269
|
}
|
|
2270
|
+
if (tick === 3) await abandon(store, 'fresh')
|
|
1521
2271
|
if (tick === 6) {
|
|
1522
2272
|
counter.reset()
|
|
1523
2273
|
quietCalls = counter.reducedCalls
|
|
@@ -1530,6 +2280,12 @@ export async function stoppedOwnerWatchReadBudget() {
|
|
|
1530
2280
|
.filter((r) => r.observation)
|
|
1531
2281
|
.map((r) => r.observation.run),
|
|
1532
2282
|
).toEqual(['C'])
|
|
2283
|
+
expect(
|
|
2284
|
+
output
|
|
2285
|
+
.map((line) => JSON.parse(line))
|
|
2286
|
+
.filter((r) => r.event?.type === 'ticket-preparation.resolved')
|
|
2287
|
+
.map((r) => r.event.payload.attempt),
|
|
2288
|
+
).toEqual(['fresh'])
|
|
1533
2289
|
expect(counter.rows).toBe(0)
|
|
1534
2290
|
expect(counter.reducedCalls - quietCalls).toBeLessThan(20)
|
|
1535
2291
|
await readDispatcherRunFacts(store, repo, 'missing')
|
|
@@ -1893,3 +2649,638 @@ export async function hostedSeedReadBudget() {
|
|
|
1893
2649
|
}
|
|
1894
2650
|
expect(gapCosts).toEqual([14, 14])
|
|
1895
2651
|
}
|
|
2652
|
+
|
|
2653
|
+
/** The backlog and rejected roles ride the dispatcher's existing ticket reads:
|
|
2654
|
+
* a role-aware tick issues exactly as many ticket-source requests as a
|
|
2655
|
+
* role-free one, at 100 and at 100,000 repository events, and an unchanged
|
|
2656
|
+
* read after it costs zero event rows. `open` returns the source a project
|
|
2657
|
+
* with `config` dispatches over and a running count of its source requests.
|
|
2658
|
+
*
|
|
2659
|
+
* Each tick is followed by the interactive dispatcher's triage sample: exactly
|
|
2660
|
+
* `sampleRequests` source requests (one bounded count, or none for a source
|
|
2661
|
+
* without counts), never a listing, zero event rows, and the same cost at
|
|
2662
|
+
* every log length. */
|
|
2663
|
+
export async function ticketRoleTickBudget(
|
|
2664
|
+
open: (
|
|
2665
|
+
config: import('../config/schema').Config,
|
|
2666
|
+
) => Promise<{ tickets: import('../ports/types').TicketSource; requests: () => number }>,
|
|
2667
|
+
sampleRequests: 0 | 1,
|
|
2668
|
+
) {
|
|
2669
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
2670
|
+
const sha = 'a'.repeat(40)
|
|
2671
|
+
const perTick = new Map<string, number[]>()
|
|
2672
|
+
for (const roles of [false, true]) {
|
|
2673
|
+
for (const length of [100, 100_000]) {
|
|
2674
|
+
const config = parseConfig(
|
|
2675
|
+
`[tickets]\nsource = "hosted"\nteamKey = "ENG"\n${
|
|
2676
|
+
roles ? 'backlogState = "icebox"\nrejectedState = "rejected"\n' : ''
|
|
2677
|
+
}[verify]\nsteps = []\n[finalize]\nsteps = []\n`,
|
|
2678
|
+
)
|
|
2679
|
+
const { tickets, requests } = await open(config)
|
|
2680
|
+
// Every ready ticket is blocked, so ticks claim nothing and change nothing.
|
|
2681
|
+
const seed = async (title: string, state: string, blocker?: string) => {
|
|
2682
|
+
const ticket = await tickets.create({ title, body: 'Budget' })
|
|
2683
|
+
if (blocker !== undefined) await tickets.addBlocker(ticket.ref.id, blocker)
|
|
2684
|
+
await tickets.transition(ticket.ref.id, state)
|
|
2685
|
+
return ticket.ref.id
|
|
2686
|
+
}
|
|
2687
|
+
const rejected = await seed('Rejected blocker', 'rejected')
|
|
2688
|
+
const pending = await seed('Incomplete blocker', 'triage')
|
|
2689
|
+
await seed('Blocked by rejected', 'ready', rejected)
|
|
2690
|
+
await seed('Blocked by incomplete', 'ready', pending)
|
|
2691
|
+
await seed('Deferred', 'icebox')
|
|
2692
|
+
|
|
2693
|
+
let now = 1_800_000_000_000
|
|
2694
|
+
const clock = () => new Date(now)
|
|
2695
|
+
const store = new MemoryBuildStore({ clock })
|
|
2696
|
+
const repo = `https://github.com/budget/ticket-roles-${roles}-${length}`
|
|
2697
|
+
await store.ensureRepo(repo)
|
|
2698
|
+
for (let i = 0; i < length; i++)
|
|
2699
|
+
await store.appendRepo(repo, {
|
|
2700
|
+
actor: humanActor('budget'),
|
|
2701
|
+
type: 'dispatcher.intake-set',
|
|
2702
|
+
payload: { enabled: true },
|
|
2703
|
+
})
|
|
2704
|
+
// The one serialized reduction per key happens before the measured ticks.
|
|
2705
|
+
await readRepositoryFacts(store, repo)
|
|
2706
|
+
await readBuildDigests(store, repo)
|
|
2707
|
+
const counter = memoryRepositoryReadCounter(store, repo)
|
|
2708
|
+
const costs: number[] = []
|
|
2709
|
+
for (let tick = 0; tick < 2; tick++) {
|
|
2710
|
+
now += 60_000
|
|
2711
|
+
const forge = new FakeForge()
|
|
2712
|
+
forge.seedBranch('main', sha)
|
|
2713
|
+
const dispatcher = new Dispatcher({
|
|
2714
|
+
store,
|
|
2715
|
+
tickets,
|
|
2716
|
+
workspaces: new FakeWorkspaceProvider({
|
|
2717
|
+
root: '/ticket-role-budget',
|
|
2718
|
+
mode: 'logical',
|
|
2719
|
+
base: { source: 'remote', sha },
|
|
2720
|
+
}),
|
|
2721
|
+
forge,
|
|
2722
|
+
config,
|
|
2723
|
+
repo,
|
|
2724
|
+
exec: async () => ({ stdout: `${sha}\trefs/heads/main\n`, stderr: '', exitCode: 0 }),
|
|
2725
|
+
launchRunner: async () => {
|
|
2726
|
+
throw new Error('no launches in the ticket role budget')
|
|
2727
|
+
},
|
|
2728
|
+
ids: sequentialIds(),
|
|
2729
|
+
clock,
|
|
2730
|
+
})
|
|
2731
|
+
const before = requests()
|
|
2732
|
+
counter.reset()
|
|
2733
|
+
const report = await dispatcher.tick()
|
|
2734
|
+
costs.push(requests() - before)
|
|
2735
|
+
expect(report.dispatched).toBe(0)
|
|
2736
|
+
expect(report.dependencyBlocked).toBe(2)
|
|
2737
|
+
expect(
|
|
2738
|
+
report.dependencyDiagnostics.some((line) => line.endsWith('which was rejected')),
|
|
2739
|
+
).toBe(roles)
|
|
2740
|
+
expect(counter.rows).toBeLessThanOrEqual(32)
|
|
2741
|
+
// The interactive dispatcher's per-tick triage sample, exactly as it
|
|
2742
|
+
// calls it: one bounded count at most, never a listing or an event read.
|
|
2743
|
+
const listStates = Object.getOwnPropertyDescriptor(tickets, 'listStates')
|
|
2744
|
+
Object.defineProperty(tickets, 'listStates', {
|
|
2745
|
+
configurable: true,
|
|
2746
|
+
writable: true,
|
|
2747
|
+
value: async () => {
|
|
2748
|
+
throw new Error('the triage sample never lists ticket states')
|
|
2749
|
+
},
|
|
2750
|
+
})
|
|
2751
|
+
try {
|
|
2752
|
+
const sampleBefore = requests()
|
|
2753
|
+
counter.reset()
|
|
2754
|
+
const triage = await boundedStateCount(tickets, defaultTriageState(config))
|
|
2755
|
+
expect(requests() - sampleBefore).toBe(sampleRequests)
|
|
2756
|
+
expect(triage === undefined).toBe(sampleRequests === 0)
|
|
2757
|
+
expect(counter.rows).toBe(0)
|
|
2758
|
+
} finally {
|
|
2759
|
+
if (listStates === undefined) Reflect.deleteProperty(tickets, 'listStates')
|
|
2760
|
+
else Object.defineProperty(tickets, 'listStates', listStates)
|
|
2761
|
+
}
|
|
2762
|
+
// Prepare the tick's own tail, then prove an unchanged read costs zero rows.
|
|
2763
|
+
await readRepositoryFacts(store, repo)
|
|
2764
|
+
await readBuildDigests(store, repo)
|
|
2765
|
+
counter.reset()
|
|
2766
|
+
await readRepositoryFacts(store, repo)
|
|
2767
|
+
await readBuildDigests(store, repo)
|
|
2768
|
+
expect(counter.rows).toBe(0)
|
|
2769
|
+
}
|
|
2770
|
+
perTick.set(`${roles}:${length}`, costs)
|
|
2771
|
+
await store.close()
|
|
2772
|
+
}
|
|
2773
|
+
}
|
|
2774
|
+
const [baseline, ...rest] = [...perTick.values()]
|
|
2775
|
+
for (const costs of rest) expect(costs).toEqual(baseline!)
|
|
2776
|
+
return baseline!
|
|
2777
|
+
}
|
|
2778
|
+
|
|
2779
|
+
/** Urgent intake order (AUT-1027) is an in-memory partition of the one ready
|
|
2780
|
+
* listing a due scan already reads: with and without an urgent ticket present,
|
|
2781
|
+
* a quiet intake tick makes the same source calls and the same store reads, at
|
|
2782
|
+
* 100 and 100,000 repository events, and an unchanged follow-up read costs zero
|
|
2783
|
+
* rows. Returns the per-method source calls of one tick. */
|
|
2784
|
+
export async function urgentIntakeReadBudget() {
|
|
2785
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
2786
|
+
const sha = 'a'.repeat(40)
|
|
2787
|
+
const config = parseConfig(
|
|
2788
|
+
'[tickets]\nsource = "hosted"\nteamKey = "ENG"\n[verify]\nsteps = []\n[finalize]\nsteps = []\n',
|
|
2789
|
+
)
|
|
2790
|
+
const methods = ['listReady', 'get', 'dependencyStates', 'listAll'] as const
|
|
2791
|
+
const results = new Map<string, { calls: Record<string, number>[]; rows: number[] }>()
|
|
2792
|
+
for (const urgent of [false, true]) {
|
|
2793
|
+
for (const length of [100, 100_000]) {
|
|
2794
|
+
const source = new FakeTicketSource([], { createState: 'triage', doneState: 'done' })
|
|
2795
|
+
const calls: Record<string, number> = Object.fromEntries(methods.map((name) => [name, 0]))
|
|
2796
|
+
const tickets = new Proxy(source, {
|
|
2797
|
+
get(target, key) {
|
|
2798
|
+
const value = Reflect.get(target, key, target)
|
|
2799
|
+
if (typeof value !== 'function') return value
|
|
2800
|
+
return (...args: unknown[]) => {
|
|
2801
|
+
if (typeof key === 'string' && key in calls) calls[key]! += 1
|
|
2802
|
+
return value.apply(target, args)
|
|
2803
|
+
}
|
|
2804
|
+
},
|
|
2805
|
+
})
|
|
2806
|
+
// Every ready ticket is blocked by one unresolved ticket, so ticks claim nothing.
|
|
2807
|
+
const blocker = await source.create({ title: 'Unresolved blocker', body: 'Budget' })
|
|
2808
|
+
for (const [index, title] of ['N1', 'N2', 'U1'].entries()) {
|
|
2809
|
+
const ticket = await source.create({
|
|
2810
|
+
title,
|
|
2811
|
+
body: 'Budget',
|
|
2812
|
+
...(urgent && index === 2 ? { priority: 'urgent' as const } : {}),
|
|
2813
|
+
})
|
|
2814
|
+
await source.addBlocker(ticket.ref.id, blocker.ref.id)
|
|
2815
|
+
await source.transition(ticket.ref.id, 'ready')
|
|
2816
|
+
}
|
|
2817
|
+
|
|
2818
|
+
let now = 1_800_000_000_000
|
|
2819
|
+
const clock = () => new Date(now)
|
|
2820
|
+
const store = new MemoryBuildStore({ clock })
|
|
2821
|
+
const repo = `https://github.com/budget/urgent-intake-${urgent}-${length}`
|
|
2822
|
+
await store.ensureRepo(repo)
|
|
2823
|
+
for (let i = 0; i < length; i++)
|
|
2824
|
+
await store.appendRepo(repo, {
|
|
2825
|
+
actor: humanActor('budget'),
|
|
2826
|
+
type: 'dispatcher.intake-set',
|
|
2827
|
+
payload: { enabled: true },
|
|
2828
|
+
})
|
|
2829
|
+
// The one serialized reduction per key happens before the measured ticks.
|
|
2830
|
+
await readRepositoryFacts(store, repo)
|
|
2831
|
+
await readBuildDigests(store, repo)
|
|
2832
|
+
const counter = memoryRepositoryReadCounter(store, repo)
|
|
2833
|
+
const perTick: Record<string, number>[] = []
|
|
2834
|
+
const rows: number[] = []
|
|
2835
|
+
for (let tick = 0; tick < 2; tick++) {
|
|
2836
|
+
now += 60_000
|
|
2837
|
+
const forge = new FakeForge()
|
|
2838
|
+
forge.seedBranch('main', sha)
|
|
2839
|
+
const dispatcher = new Dispatcher({
|
|
2840
|
+
store,
|
|
2841
|
+
tickets,
|
|
2842
|
+
workspaces: new FakeWorkspaceProvider({
|
|
2843
|
+
root: '/urgent-intake-budget',
|
|
2844
|
+
mode: 'logical',
|
|
2845
|
+
base: { source: 'remote', sha },
|
|
2846
|
+
}),
|
|
2847
|
+
forge,
|
|
2848
|
+
config,
|
|
2849
|
+
repo,
|
|
2850
|
+
exec: async () => ({ stdout: `${sha}\trefs/heads/main\n`, stderr: '', exitCode: 0 }),
|
|
2851
|
+
launchRunner: async () => {
|
|
2852
|
+
throw new Error('no launches in the urgent intake budget')
|
|
2853
|
+
},
|
|
2854
|
+
ids: sequentialIds(),
|
|
2855
|
+
clock,
|
|
2856
|
+
})
|
|
2857
|
+
const before = { ...calls }
|
|
2858
|
+
counter.reset()
|
|
2859
|
+
const report = await dispatcher.tick()
|
|
2860
|
+
perTick.push(
|
|
2861
|
+
Object.fromEntries(methods.map((name) => [name, calls[name]! - before[name]!])),
|
|
2862
|
+
)
|
|
2863
|
+
rows.push(counter.rows)
|
|
2864
|
+
expect(report.dispatched).toBe(0)
|
|
2865
|
+
expect(report.dependencyBlocked).toBe(3)
|
|
2866
|
+
expect(counter.rows).toBeLessThanOrEqual(32)
|
|
2867
|
+
// Prepare the tick's own tail, then prove an unchanged read costs zero rows.
|
|
2868
|
+
await readRepositoryFacts(store, repo)
|
|
2869
|
+
await readBuildDigests(store, repo)
|
|
2870
|
+
counter.reset()
|
|
2871
|
+
await readRepositoryFacts(store, repo)
|
|
2872
|
+
await readBuildDigests(store, repo)
|
|
2873
|
+
expect(counter.rows).toBe(0)
|
|
2874
|
+
}
|
|
2875
|
+
results.set(`${urgent}:${length}`, { calls: perTick, rows })
|
|
2876
|
+
await store.close()
|
|
2877
|
+
}
|
|
2878
|
+
}
|
|
2879
|
+
const [baseline, ...rest] = [...results.values()]
|
|
2880
|
+
for (const result of rest) expect(result).toEqual(baseline!)
|
|
2881
|
+
return baseline!.calls[0]!
|
|
2882
|
+
}
|
|
2883
|
+
|
|
2884
|
+
/** Native identity maintenance (SPEC §15.7) adds one forge identity read per
|
|
2885
|
+
* armed, eligible poll and nothing else: a fresh dispatcher's quiet
|
|
2886
|
+
* maintenance tick reads no history, spends exactly the store reads of the same
|
|
2887
|
+
* tick with the native block skipped, appends nothing, and costs the same at
|
|
2888
|
+
* 100 and 10,000 events. */
|
|
2889
|
+
export async function nativeMaintenanceReadBudget(opts: {
|
|
2890
|
+
store: import('../store/memory').MemoryBuildStore
|
|
2891
|
+
slug: string
|
|
2892
|
+
forge: FakeForge
|
|
2893
|
+
tick: () => Promise<unknown>
|
|
2894
|
+
}) {
|
|
2895
|
+
const { store, slug, forge } = opts
|
|
2896
|
+
const events = buildEventRows(store, slug)
|
|
2897
|
+
let baseline: number[] | undefined
|
|
2898
|
+
for (const length of [100, 10_000]) {
|
|
2899
|
+
let filler = 0
|
|
2900
|
+
while (events.length < length)
|
|
2901
|
+
await store.append(slug, {
|
|
2902
|
+
actor: KERNEL,
|
|
2903
|
+
type: 'observation.recorded',
|
|
2904
|
+
payload: { id: `obs_budget_${length}_${filler++}`, kind: 'followup', summary: 'filler' },
|
|
2905
|
+
})
|
|
2906
|
+
// Warm the saved reduced values past the filler before measuring.
|
|
2907
|
+
await opts.tick()
|
|
2908
|
+
const boundary = events.at(-1)!.seq
|
|
2909
|
+
const metrics = { historicalRows: 0, tailRows: 0 }
|
|
2910
|
+
let calls = 0
|
|
2911
|
+
const getReduced = store.getReducerValue.bind(store)
|
|
2912
|
+
store.getReducerValue = async (...args) => {
|
|
2913
|
+
calls++
|
|
2914
|
+
return getReduced(...args)
|
|
2915
|
+
}
|
|
2916
|
+
const restore = instrumentBuildRows(store, slug, () => boundary, metrics)
|
|
2917
|
+
const getPrState = forge.getPrState.bind(forge)
|
|
2918
|
+
const measure = async () => {
|
|
2919
|
+
metrics.historicalRows = metrics.tailRows = calls = 0
|
|
2920
|
+
const reads = forge.identityReads.length
|
|
2921
|
+
await opts.tick()
|
|
2922
|
+
expect(metrics.historicalRows).toBe(0)
|
|
2923
|
+
return {
|
|
2924
|
+
rows: metrics.tailRows,
|
|
2925
|
+
calls,
|
|
2926
|
+
identityReads: forge.identityReads.length - reads,
|
|
2927
|
+
}
|
|
2928
|
+
}
|
|
2929
|
+
try {
|
|
2930
|
+
const maintenance = await measure()
|
|
2931
|
+
forge.getPrState = async (...args) => {
|
|
2932
|
+
const { nativeAutoMerge: _omitted, ...state } = (await getPrState(...args)) as PrStateLike
|
|
2933
|
+
return state
|
|
2934
|
+
}
|
|
2935
|
+
const skipped = await measure()
|
|
2936
|
+
expect(maintenance.identityReads).toBe(1)
|
|
2937
|
+
expect(skipped.identityReads).toBe(0)
|
|
2938
|
+
expect(maintenance.calls).toBe(skipped.calls)
|
|
2939
|
+
expect(maintenance.rows).toBe(skipped.rows)
|
|
2940
|
+
expect(events.at(-1)!.seq).toBe(boundary)
|
|
2941
|
+
const costs = [maintenance.rows, maintenance.calls]
|
|
2942
|
+
if (baseline) expect(costs).toEqual(baseline)
|
|
2943
|
+
baseline = costs
|
|
2944
|
+
} finally {
|
|
2945
|
+
restore()
|
|
2946
|
+
store.getReducerValue = getReduced
|
|
2947
|
+
Reflect.deleteProperty(forge, 'getPrState')
|
|
2948
|
+
}
|
|
2949
|
+
}
|
|
2950
|
+
}
|
|
2951
|
+
|
|
2952
|
+
type PrStateLike = Awaited<ReturnType<FakeForge['getPrState']>> & { nativeAutoMerge?: boolean }
|
|
2953
|
+
/** The bounded replaced-head record rides in the saved build facts: a warm
|
|
2954
|
+
* read touches no event rows, and its size is fixed at any rewrite count. */
|
|
2955
|
+
export async function replacedHeadsReadBudget(opts: {
|
|
2956
|
+
store: BuildStore
|
|
2957
|
+
costs: ReducedReadCosts
|
|
2958
|
+
fresh: () => Promise<BuildStore>
|
|
2959
|
+
}) {
|
|
2960
|
+
const { store, costs } = opts
|
|
2961
|
+
const node = 'replaced-heads-budget'
|
|
2962
|
+
const oid = (n: number) => n.toString(16).padStart(40, '0')
|
|
2963
|
+
await store.createBuild({ slug: node, repo, branch: 'ab-node/replaced-heads-budget' })
|
|
2964
|
+
const log = nodeRestackLog()
|
|
2965
|
+
for (const event of log.slice(0, 2)) await store.append(node, event)
|
|
2966
|
+
const replaced: string[] = []
|
|
2967
|
+
let appended = 0
|
|
2968
|
+
let transaction = 0
|
|
2969
|
+
const sizes = new Map<number, number>()
|
|
2970
|
+
// Both journal lengths hold more rewrites than the record's capacity.
|
|
2971
|
+
for (const length of [1_000, 10_000]) {
|
|
2972
|
+
while (appended < length) {
|
|
2973
|
+
const id = transaction++
|
|
2974
|
+
for (const event of log.slice(2)) {
|
|
2975
|
+
const payload = JSON.parse(
|
|
2976
|
+
JSON.stringify(event.payload)
|
|
2977
|
+
.replaceAll('node-tx', `rewrite-${id}`)
|
|
2978
|
+
.replaceAll('a'.repeat(40), oid(id * 2 + 1))
|
|
2979
|
+
.replaceAll('c'.repeat(40), oid(id * 2 + 2)),
|
|
2980
|
+
)
|
|
2981
|
+
await store.append(node, { actor: event.actor, type: event.type, payload })
|
|
2982
|
+
appended++
|
|
2983
|
+
}
|
|
2984
|
+
replaced.push(oid(id * 2 + 1))
|
|
2985
|
+
}
|
|
2986
|
+
expect(replaced.length).toBeGreaterThan(REPLACED_HEADS_CAP)
|
|
2987
|
+
for (const reader of [store, await opts.fresh()]) {
|
|
2988
|
+
await readBuildFacts(reader, node)
|
|
2989
|
+
costs.events = costs.metadata = costs.bytes = 0
|
|
2990
|
+
const facts = (await readBuildFacts(reader, node)).value
|
|
2991
|
+
expect(costs.events).toBe(0)
|
|
2992
|
+
expect(facts.replacedHeads).toEqual(replaced.slice(-REPLACED_HEADS_CAP))
|
|
2993
|
+
const size = JSON.stringify(facts.replacedHeads).length
|
|
2994
|
+
if (length === 1_000) sizes.set(0, size)
|
|
2995
|
+
else expect(size).toBe(sizes.get(0)!)
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
}
|
|
2999
|
+
|
|
3000
|
+
/** A repository with no dispatcher run answers its dashboard poll from the
|
|
3001
|
+
* saved reduction: zero event rows once warm, at any journal length. */
|
|
3002
|
+
export async function noDispatcherRunDashboardBudget() {
|
|
3003
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
3004
|
+
for (const size of [10, 300]) {
|
|
3005
|
+
const store = new MemoryBuildStore({ clock: () => new Date(1000) })
|
|
3006
|
+
await store.ensureRepo(repo)
|
|
3007
|
+
const toggle = async (count: number) => {
|
|
3008
|
+
for (let i = 0; i < count; i++)
|
|
3009
|
+
await store.appendRepo(repo, {
|
|
3010
|
+
actor: humanActor('operator'),
|
|
3011
|
+
type: 'dispatcher.intake-set',
|
|
3012
|
+
payload: { enabled: i % 2 === 1 },
|
|
3013
|
+
})
|
|
3014
|
+
}
|
|
3015
|
+
await toggle(size)
|
|
3016
|
+
const counter = memoryRepositoryReadCounter(store, repo)
|
|
3017
|
+
const poll = () => getOperatorDashboard({ store, repo, clock: () => new Date(1000) })
|
|
3018
|
+
const warm = await poll()
|
|
3019
|
+
expect(warm.model.configuration).toBe('no-dispatcher-run')
|
|
3020
|
+
counter.reset()
|
|
3021
|
+
for (let i = 0; i < 3; i++) await poll()
|
|
3022
|
+
expect(counter.rows).toBe(0)
|
|
3023
|
+
// New facts advance the saved value by their delta only.
|
|
3024
|
+
await toggle(4)
|
|
3025
|
+
counter.reset()
|
|
3026
|
+
expect((await poll()).settingsHeader.intake).toBe(true)
|
|
3027
|
+
expect(counter.rows).toBeLessThanOrEqual(4)
|
|
3028
|
+
counter.reset()
|
|
3029
|
+
await poll()
|
|
3030
|
+
expect(counter.rows).toBe(0)
|
|
3031
|
+
}
|
|
3032
|
+
}
|
|
3033
|
+
|
|
3034
|
+
/** Tally the store requests callers make, by method name: every
|
|
3035
|
+
* function-valued store method is counted when entered from outside the store,
|
|
3036
|
+
* never when the adapter calls its own methods. `restore` removes the
|
|
3037
|
+
* instrumentation. */
|
|
3038
|
+
export function memoryStoreRequestCounter(store: BuildStore) {
|
|
3039
|
+
const inside = new AsyncLocalStorage<true>()
|
|
3040
|
+
const counts = new Map<string, number>()
|
|
3041
|
+
const names = new Set<string>()
|
|
3042
|
+
for (
|
|
3043
|
+
let proto: object | null = store;
|
|
3044
|
+
proto && proto !== Object.prototype;
|
|
3045
|
+
proto = Object.getPrototypeOf(proto)
|
|
3046
|
+
)
|
|
3047
|
+
for (const name of Object.getOwnPropertyNames(proto))
|
|
3048
|
+
if (name !== 'constructor' && typeof Reflect.get(store, name) === 'function') names.add(name)
|
|
3049
|
+
const wrapped = new Map<string, { own: boolean; original: (...args: unknown[]) => unknown }>()
|
|
3050
|
+
for (const name of names) {
|
|
3051
|
+
const original = Reflect.get(store, name) as (...args: unknown[]) => unknown
|
|
3052
|
+
wrapped.set(name, { own: Object.hasOwn(store, name), original })
|
|
3053
|
+
Reflect.set(store, name, (...args: unknown[]) => {
|
|
3054
|
+
if (inside.getStore()) return original.apply(store, args)
|
|
3055
|
+
counts.set(name, (counts.get(name) ?? 0) + 1)
|
|
3056
|
+
return inside.run(true, () => original.apply(store, args))
|
|
3057
|
+
})
|
|
3058
|
+
}
|
|
3059
|
+
return {
|
|
3060
|
+
/** Calls since the last reset, by method name, in sorted order. */
|
|
3061
|
+
vector(): Record<string, number> {
|
|
3062
|
+
return Object.fromEntries([...counts].sort(([a], [b]) => a.localeCompare(b)))
|
|
3063
|
+
},
|
|
3064
|
+
reset() {
|
|
3065
|
+
counts.clear()
|
|
3066
|
+
},
|
|
3067
|
+
restore() {
|
|
3068
|
+
for (const [name, { own, original }] of wrapped)
|
|
3069
|
+
if (own) Reflect.set(store, name, original)
|
|
3070
|
+
else Reflect.deleteProperty(store, name)
|
|
3071
|
+
},
|
|
3072
|
+
}
|
|
3073
|
+
}
|
|
3074
|
+
|
|
3075
|
+
/** A janitor that keeps failing for one build costs every fresh-dispatcher tick
|
|
3076
|
+
* the same store requests at 100 and at 100,000 events. The vectors are
|
|
3077
|
+
* returned per tick class so a caller can pin them against an earlier
|
|
3078
|
+
* implementation: episode start, a failure before attention, the attention
|
|
3079
|
+
* failure, a failure before the escalation limit, the threshold failure, a
|
|
3080
|
+
* failure after it, and the recovering attempt. */
|
|
3081
|
+
export async function janitorEscalationRequestBudget(opts: {
|
|
3082
|
+
store: import('../store/memory').MemoryBuildStore
|
|
3083
|
+
repo: string
|
|
3084
|
+
slug: string
|
|
3085
|
+
/** One tick on a fresh dispatcher. */
|
|
3086
|
+
tick: () => Promise<unknown>
|
|
3087
|
+
now: () => Date
|
|
3088
|
+
advance: (ms: number) => void
|
|
3089
|
+
/** Make the build's janitor work fail (true) or succeed (false). */
|
|
3090
|
+
failing: (value: boolean) => void
|
|
3091
|
+
/** Episode age at which the threshold failure is expected. */
|
|
3092
|
+
limitSeconds: number
|
|
3093
|
+
attentionSeconds: number
|
|
3094
|
+
}) {
|
|
3095
|
+
const { store, repo, slug } = opts
|
|
3096
|
+
type Vectors = Record<
|
|
3097
|
+
'start' | 'preAttention' | 'attention' | 'preLimit' | 'threshold' | 'escalated' | 'recovery',
|
|
3098
|
+
Record<string, number>
|
|
3099
|
+
>
|
|
3100
|
+
const escalations = async () =>
|
|
3101
|
+
(await store.getEvents(slug)).filter(
|
|
3102
|
+
(event) => String(event.type) === 'build.janitor-escalated',
|
|
3103
|
+
).length
|
|
3104
|
+
const results: { length: number; vectors: Vectors; escalations: number }[] = []
|
|
3105
|
+
await store.ensureRepo(repo)
|
|
3106
|
+
let seeded = 0
|
|
3107
|
+
for (const length of [100, 100_000]) {
|
|
3108
|
+
for (; seeded < length; seeded++) {
|
|
3109
|
+
await store.appendRepo(repo, {
|
|
3110
|
+
actor: humanActor('budget'),
|
|
3111
|
+
type: 'dispatcher.intake-set',
|
|
3112
|
+
payload: { enabled: true },
|
|
3113
|
+
})
|
|
3114
|
+
if (seeded % 10 === 0)
|
|
3115
|
+
await store.append(slug, {
|
|
3116
|
+
actor: KERNEL,
|
|
3117
|
+
type: 'observation.recorded',
|
|
3118
|
+
payload: { id: `obs-${seeded}`, kind: 'followup', summary: `budget padding ${seeded}` },
|
|
3119
|
+
})
|
|
3120
|
+
}
|
|
3121
|
+
// Warm up: a fresh dispatcher folds the padding once while nothing fails.
|
|
3122
|
+
opts.failing(false)
|
|
3123
|
+
await opts.tick()
|
|
3124
|
+
opts.failing(true)
|
|
3125
|
+
const before = await escalations()
|
|
3126
|
+
const counter = memoryStoreRequestCounter(store)
|
|
3127
|
+
const vectors: Partial<Vectors> = {}
|
|
3128
|
+
try {
|
|
3129
|
+
const measure = async () => {
|
|
3130
|
+
counter.reset()
|
|
3131
|
+
await opts.tick()
|
|
3132
|
+
return counter.vector()
|
|
3133
|
+
}
|
|
3134
|
+
const due = async () => {
|
|
3135
|
+
const { state } = (await readBuildFacts(store, slug)).value
|
|
3136
|
+
const next = state.janitor && Date.parse(state.janitor.nextAttemptAt)
|
|
3137
|
+
if (next) opts.advance(Math.max(0, next - opts.now().getTime()))
|
|
3138
|
+
return state.janitor ? Date.parse(state.janitor.firstFailureAt) : undefined
|
|
3139
|
+
}
|
|
3140
|
+
vectors.start = await measure()
|
|
3141
|
+
const first = (await due())!
|
|
3142
|
+
vectors.preAttention = await measure()
|
|
3143
|
+
for (;;) {
|
|
3144
|
+
await due()
|
|
3145
|
+
const age = opts.now().getTime() - first
|
|
3146
|
+
const vector = await measure()
|
|
3147
|
+
if (age >= opts.limitSeconds * 1000) {
|
|
3148
|
+
vectors.threshold = vector
|
|
3149
|
+
break
|
|
3150
|
+
}
|
|
3151
|
+
if (age >= opts.attentionSeconds * 1000 && !vectors.attention) vectors.attention = vector
|
|
3152
|
+
else if (vectors.attention) vectors.preLimit = vector
|
|
3153
|
+
}
|
|
3154
|
+
await due()
|
|
3155
|
+
vectors.escalated = await measure()
|
|
3156
|
+
opts.failing(false)
|
|
3157
|
+
await due()
|
|
3158
|
+
vectors.recovery = await measure()
|
|
3159
|
+
} finally {
|
|
3160
|
+
counter.restore()
|
|
3161
|
+
}
|
|
3162
|
+
expect((await readBuildFacts(store, slug)).value.state.janitor).toBeUndefined()
|
|
3163
|
+
results.push({
|
|
3164
|
+
length,
|
|
3165
|
+
vectors: vectors as Vectors,
|
|
3166
|
+
escalations: (await escalations()) - before,
|
|
3167
|
+
})
|
|
3168
|
+
}
|
|
3169
|
+
expect(results[1]!.vectors).toEqual(results[0]!.vectors)
|
|
3170
|
+
return { vectors: results[0]!.vectors, escalations: results.map((r) => r.escalations) }
|
|
3171
|
+
}
|
|
3172
|
+
|
|
3173
|
+
/** AUT-1152: a prepared hosted guest re-reads its execution authority at its
|
|
3174
|
+
* durable boundaries. Proves the probe is one constant-size served value:
|
|
3175
|
+
* after the one-time reduction per key, an unchanged re-read issues the same
|
|
3176
|
+
* single request and reads zero event rows, and its response is the same size
|
|
3177
|
+
* whether the repository has had one harvest execution or a thousand; one new
|
|
3178
|
+
* fact costs exactly one row. */
|
|
3179
|
+
export async function hostedHarvestAuthorityReadBudget() {
|
|
3180
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
3181
|
+
const repo = '/repo'
|
|
3182
|
+
const guest = { execution: 'guest', run: 'h_guest', leaseHolder: 'inv-1' }
|
|
3183
|
+
const sizes = [
|
|
3184
|
+
{ cycles: 1, filler: 100 },
|
|
3185
|
+
{ cycles: 1_000, filler: 10_000 },
|
|
3186
|
+
]
|
|
3187
|
+
const results: Array<{
|
|
3188
|
+
warmRows: number
|
|
3189
|
+
unchanged: { vector: Record<string, number>; rows: number; size: number }
|
|
3190
|
+
appended: { rows: number; size: number }
|
|
3191
|
+
replaced: { rows: number; decision: ReturnType<typeof decideHostedHarvestAuthority> }
|
|
3192
|
+
}> = []
|
|
3193
|
+
for (const { cycles, filler } of sizes) {
|
|
3194
|
+
const store = new MemoryBuildStore()
|
|
3195
|
+
await seedPreparationHistory(store, repo, filler)
|
|
3196
|
+
for (let i = 0; i < cycles; i++) {
|
|
3197
|
+
const run = `h_old_${i}`
|
|
3198
|
+
const execution = `old-${i}`
|
|
3199
|
+
await store.appendRepo(repo, {
|
|
3200
|
+
actor: KERNEL,
|
|
3201
|
+
type: 'harvest.started',
|
|
3202
|
+
payload: {
|
|
3203
|
+
run,
|
|
3204
|
+
observations: [{ build: `b-${i}`, seq: 1 }],
|
|
3205
|
+
scan: { kind: 'harvest-scan', rev: i },
|
|
3206
|
+
},
|
|
3207
|
+
})
|
|
3208
|
+
await store.appendRepo(repo, {
|
|
3209
|
+
actor: DISPATCHER,
|
|
3210
|
+
type: 'harvest.execution.authorized',
|
|
3211
|
+
payload: { execution, run, launch: 'started', leaseHolder: `inv-old-${i}` },
|
|
3212
|
+
})
|
|
3213
|
+
await store.appendRepo(repo, {
|
|
3214
|
+
actor: DISPATCHER,
|
|
3215
|
+
type: 'harvest.execution.started',
|
|
3216
|
+
payload: { execution, provider: 'p', environmentId: `env-${i}` },
|
|
3217
|
+
})
|
|
3218
|
+
await store.appendRepo(repo, {
|
|
3219
|
+
actor: DISPATCHER,
|
|
3220
|
+
type: 'harvest.execution.released',
|
|
3221
|
+
payload: { execution, environmentId: `env-${i}`, snapshots: { outcome: 'confirmed' } },
|
|
3222
|
+
})
|
|
3223
|
+
}
|
|
3224
|
+
await store.appendRepo(repo, {
|
|
3225
|
+
actor: DISPATCHER,
|
|
3226
|
+
type: 'harvest.execution.authorized',
|
|
3227
|
+
payload: { ...guest, launch: 'started' },
|
|
3228
|
+
})
|
|
3229
|
+
const rows = memoryRepositoryReadCounter(store, repo)
|
|
3230
|
+
const requests = memoryStoreRequestCounter(store)
|
|
3231
|
+
try {
|
|
3232
|
+
const probe = async () => {
|
|
3233
|
+
rows.reset()
|
|
3234
|
+
requests.reset()
|
|
3235
|
+
const { value } = await readHostedHarvestAuthority(store, repo)
|
|
3236
|
+
return {
|
|
3237
|
+
vector: requests.vector(),
|
|
3238
|
+
rows: rows.rows,
|
|
3239
|
+
size: JSON.stringify(value).length,
|
|
3240
|
+
decision: decideHostedHarvestAuthority(value, guest),
|
|
3241
|
+
}
|
|
3242
|
+
}
|
|
3243
|
+
// The one-time reduction of this (repo, reducer) key.
|
|
3244
|
+
const warm = await probe()
|
|
3245
|
+
const unchanged = await probe()
|
|
3246
|
+
expect(unchanged.decision).toEqual({ kind: 'authorized' })
|
|
3247
|
+
await store.appendRepo(repo, {
|
|
3248
|
+
actor: humanActor('budget'),
|
|
3249
|
+
type: 'dispatcher.intake-set',
|
|
3250
|
+
payload: { enabled: true },
|
|
3251
|
+
})
|
|
3252
|
+
const appended = await probe()
|
|
3253
|
+
expect(appended.decision).toEqual({ kind: 'authorized' })
|
|
3254
|
+
await store.appendRepo(repo, {
|
|
3255
|
+
actor: DISPATCHER,
|
|
3256
|
+
type: 'harvest.execution.authorized',
|
|
3257
|
+
payload: {
|
|
3258
|
+
execution: 'successor',
|
|
3259
|
+
run: guest.run,
|
|
3260
|
+
launch: 'resumed',
|
|
3261
|
+
leaseHolder: 'inv-2',
|
|
3262
|
+
},
|
|
3263
|
+
})
|
|
3264
|
+
const replaced = await probe()
|
|
3265
|
+
results.push({
|
|
3266
|
+
warmRows: warm.rows,
|
|
3267
|
+
unchanged: { vector: unchanged.vector, rows: unchanged.rows, size: unchanged.size },
|
|
3268
|
+
appended: { rows: appended.rows, size: appended.size },
|
|
3269
|
+
replaced: { rows: replaced.rows, decision: replaced.decision },
|
|
3270
|
+
})
|
|
3271
|
+
} finally {
|
|
3272
|
+
requests.restore()
|
|
3273
|
+
}
|
|
3274
|
+
}
|
|
3275
|
+
const [small, large] = results as [(typeof results)[0], (typeof results)[0]]
|
|
3276
|
+
for (const result of results) {
|
|
3277
|
+
expect(result.unchanged.vector).toEqual({ getReducerValue: 1 })
|
|
3278
|
+
expect(result.unchanged.rows).toBe(0)
|
|
3279
|
+
expect(result.appended.rows).toBe(1)
|
|
3280
|
+
expect(result.replaced.rows).toBe(1)
|
|
3281
|
+
expect(result.replaced.decision).toEqual({ kind: 'fenced', reason: 'replaced' })
|
|
3282
|
+
}
|
|
3283
|
+
expect(large.unchanged.size).toBe(small.unchanged.size)
|
|
3284
|
+
expect(large.appended.size).toBe(small.appended.size)
|
|
3285
|
+
return { small, large }
|
|
3286
|
+
}
|