@defrex/autobuild 1.4.2 → 1.5.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 +432 -92
- 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 +2 -1
- package/docs/architecture.md +282 -127
- 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 +163 -102
- package/docs/dispatcher-hosting.md +19 -3
- package/docs/dispatcher.md +9 -4
- package/docs/integration-overview.md +2 -2
- package/docs/integration-tree.md +91 -28
- package/docs/merge-policy.md +28 -9
- package/docs/operator-api.md +43 -18
- package/docs/operator-surfaces.md +1 -1
- package/docs/plugin-authoring.md +85 -8
- package/docs/remote-store-protocol.md +25 -7
- package/docs/remote-ticket-protocol.md +126 -12
- package/docs/restacking.md +20 -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 +2 -2
- 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 +1 -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 +40 -10
- package/packages/core/src/cli/dashboard/queue.ts +21 -0
- package/packages/core/src/cli/dashboard/render.ts +40 -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-repository-feed.ts +40 -11
- package/packages/core/src/cli/dispatch.ts +154 -47
- package/packages/core/src/cli/help.ts +59 -22
- 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/repository-status.ts +201 -49
- package/packages/core/src/cli/status.ts +41 -3
- 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/watch.ts +4 -0
- 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 +164 -36
- package/packages/core/src/distribution-packaging.ts +1 -1
- package/packages/core/src/events/catalog.ts +5 -0
- package/packages/core/src/events/compatibility.ts +2 -1
- package/packages/core/src/events/payloads.ts +70 -0
- package/packages/core/src/events/policy.ts +8 -0
- package/packages/core/src/events/repository.ts +91 -28
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +41 -0
- 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 +80 -14
- 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 +4 -2
- package/packages/core/src/kernel/finalize-pr-rejection.ts +95 -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/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 +11 -0
- 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/log-index.ts +1 -1
- package/packages/core/src/kernel/node-issue-links.ts +142 -0
- 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 +31 -1
- package/packages/core/src/kernel/reducer.ts +90 -2
- package/packages/core/src/kernel/ticket-preparation.ts +12 -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 +66 -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 +72 -17
- 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 +190 -9
- package/packages/core/src/ports/workspace/commit-preservation.ts +135 -13
- package/packages/core/src/ports/workspace/git-worktree.ts +3 -1
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +118 -27
- package/packages/core/src/processes/build-runner.ts +99 -21
- package/packages/core/src/processes/dispatcher.ts +822 -338
- package/packages/core/src/processes/execution-no-progress.ts +5 -0
- package/packages/core/src/processes/harvest-runner.ts +17 -8
- 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 +4 -0
- 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/reducer-value-shapes.json +4187 -3391
- package/packages/core/src/store/remote/protocol.ts +2 -0
- package/packages/core/src/store/remote/released-clients.json +11 -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/index.ts +2 -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 +1085 -31
- 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 +374 -136
- 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 +43 -18
- package/skills/guide/references/plugin-authoring.md +85 -8
- package/skills/guide/references/remote-store-protocol.md +25 -7
- package/skills/guide/references/remote-ticket-protocol.md +126 -12
- package/skills/guide/references/restacking.md +20 -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 +103 -28
- 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 +114 -37
- package/templates/autobuild.toml +5 -0
- package/templates/hosted-service/package.json +2 -2
|
@@ -5,6 +5,7 @@ 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'
|
|
@@ -15,7 +16,8 @@ import { abDispatch } from '../cli/dispatch'
|
|
|
15
16
|
import { createTerminalModeController } from '../cli/terminal-restore'
|
|
16
17
|
import { randomUuids } from '../ids'
|
|
17
18
|
import { ScriptedAgentRunner, defaultTurnResult } from '../ports/runner/fake'
|
|
18
|
-
import { Dispatcher } from '../processes/dispatcher'
|
|
19
|
+
import { Dispatcher, defaultTriageState } from '../processes/dispatcher'
|
|
20
|
+
import { boundedStateCount } from '../ports/tickets/states'
|
|
19
21
|
import { FakeTicketSource } from '../ports/tickets/fake'
|
|
20
22
|
import { FakeWorkspaceProvider } from '../ports/workspace/fake'
|
|
21
23
|
import { FakeForge } from '../ports/forge/fake'
|
|
@@ -34,6 +36,7 @@ import { KERNEL, DISPATCHER, humanActor } from '../events/envelope'
|
|
|
34
36
|
import {
|
|
35
37
|
readBuildFacts,
|
|
36
38
|
readBuildStreamSeed,
|
|
39
|
+
readDispatchBudget,
|
|
37
40
|
readRepositoryFacts,
|
|
38
41
|
readForgeHealth,
|
|
39
42
|
readRepositoryAttention,
|
|
@@ -42,9 +45,19 @@ import {
|
|
|
42
45
|
readOpenTick,
|
|
43
46
|
} from '../store/reduced-reads'
|
|
44
47
|
import { RepoViewStore } from '../processes/repo-view'
|
|
48
|
+
import { settlePendingPublication } from '../cli/publication-settlement'
|
|
49
|
+
import {
|
|
50
|
+
readLaunchFence,
|
|
51
|
+
refreshSummaryBoundary,
|
|
52
|
+
settleSummaryRequests,
|
|
53
|
+
summaryHandoffPending,
|
|
54
|
+
} from '../cli/pr-summary-publication'
|
|
55
|
+
import { ForgeRequestDeferred } from '../ports/forge-request-context'
|
|
45
56
|
import { abWatch, decodeCursor } from '../cli/watch'
|
|
46
57
|
import { abWait } from '../cli/wait'
|
|
58
|
+
import { TRIAGE_COUNT_REFRESH_MS } from '../cli/triage-count-sampler'
|
|
47
59
|
import type { Exec } from '../ports/workspace/git-worktree'
|
|
60
|
+
export { syntheticPresenceObservation } from './presence-history'
|
|
48
61
|
|
|
49
62
|
export interface ReducedReadCosts {
|
|
50
63
|
events: number
|
|
@@ -209,6 +222,7 @@ export async function reducedReadBudget(opts: {
|
|
|
209
222
|
costs.bytes = 0
|
|
210
223
|
}
|
|
211
224
|
let repositoryBytes: number | undefined
|
|
225
|
+
let deferredScanProbe: { metadata: number; bytes: number } | undefined
|
|
212
226
|
for (const length of [32, 256]) {
|
|
213
227
|
for (let i = 0; i < length; i++) {
|
|
214
228
|
await store.append(slug, {
|
|
@@ -404,10 +418,18 @@ export async function reducedReadBudget(opts: {
|
|
|
404
418
|
launchRunner: async () => 'scheduled',
|
|
405
419
|
})
|
|
406
420
|
await dispatcher().observeReady()
|
|
421
|
+
// A fresh journal anchor per length keeps the cadence counts identical.
|
|
422
|
+
const latest = (await readRepositoryFacts(cold, repo)).value.scan
|
|
423
|
+
if (latest === undefined) throw new Error('missing ticket scan fact')
|
|
424
|
+
await store.appendRepo(repo, {
|
|
425
|
+
actor: DISPATCHER,
|
|
426
|
+
type: 'dispatcher.ticket-scan-completed',
|
|
427
|
+
payload: { ...latest, startedAt: new Date(scanTime).toISOString() },
|
|
428
|
+
})
|
|
407
429
|
const scanSeq = (await readRepositoryFacts(cold, repo)).value.scanSeq
|
|
408
430
|
let cadenceReads = 0
|
|
409
431
|
let cadenceWrites = 0
|
|
410
|
-
|
|
432
|
+
const countedHandle = async () => {
|
|
411
433
|
const freshHandle = await opts.fresh()
|
|
412
434
|
const counted = new Proxy(freshHandle, {
|
|
413
435
|
get(target, key) {
|
|
@@ -425,19 +447,56 @@ export async function reducedReadBudget(opts: {
|
|
|
425
447
|
return typeof value === 'function' ? value.bind(target) : value
|
|
426
448
|
},
|
|
427
449
|
})
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
450
|
+
return { freshHandle, counted }
|
|
451
|
+
}
|
|
452
|
+
const scanDispatcher = (counted: BuildStore) =>
|
|
453
|
+
new Dispatcher({
|
|
454
|
+
store: counted,
|
|
455
|
+
repo,
|
|
456
|
+
config,
|
|
457
|
+
tickets: new FakeTicketSource([]),
|
|
458
|
+
workspaces: new FakeWorkspaceProvider({ root: '/budget-workspaces', mode: 'logical' }),
|
|
459
|
+
forge: new FakeForge(),
|
|
460
|
+
ids: sequentialIds(),
|
|
461
|
+
clock: () => new Date(scanTime),
|
|
462
|
+
exec,
|
|
463
|
+
launchRunner: async () => 'scheduled',
|
|
464
|
+
})
|
|
465
|
+
// While the journal measurement alone proves the scan is not due, fresh
|
|
466
|
+
// processes make no cadence request and read no event rows.
|
|
467
|
+
const anchorTime = scanTime
|
|
468
|
+
let deferred: { metadata: number; bytes: number } | undefined
|
|
469
|
+
for (let k = 1; k < 6; k++) {
|
|
470
|
+
scanTime = anchorTime + k * 10_000
|
|
471
|
+
const { freshHandle, counted } = await countedHandle()
|
|
472
|
+
reset()
|
|
473
|
+
await scanDispatcher(counted).observeReady()
|
|
474
|
+
deferred ??= { metadata: costs.metadata, bytes: costs.bytes }
|
|
475
|
+
expect(costs.events).toBe(0)
|
|
476
|
+
expect(cadenceReads).toBe(0)
|
|
477
|
+
expect((await readRepositoryFacts(freshHandle, repo)).value.scanSeq).toBe(scanSeq)
|
|
478
|
+
}
|
|
479
|
+
if (deferredScanProbe === undefined) deferredScanProbe = deferred
|
|
480
|
+
else {
|
|
481
|
+
// Flat with history: the repository facts value is bounded, as above.
|
|
482
|
+
expect(deferred!.metadata).toBe(deferredScanProbe!.metadata)
|
|
483
|
+
expect(deferred!.bytes).toBeLessThan(deferredScanProbe!.bytes + 512)
|
|
484
|
+
}
|
|
485
|
+
// At the interval the row is consulted; the unchanged scan advances only it.
|
|
486
|
+
scanTime = anchorTime + 60_000
|
|
487
|
+
{
|
|
488
|
+
const { freshHandle, counted } = await countedHandle()
|
|
489
|
+
reset()
|
|
490
|
+
await scanDispatcher(counted).observeReady()
|
|
491
|
+
expect(costs.events).toBe(0)
|
|
492
|
+
expect(cadenceReads).toBe(1)
|
|
493
|
+
expect(cadenceWrites).toBe(1)
|
|
494
|
+
expect(deferred!.metadata).toBeLessThan(costs.metadata)
|
|
495
|
+
expect((await readRepositoryFacts(freshHandle, repo)).value.scanSeq).toBe(scanSeq)
|
|
496
|
+
}
|
|
497
|
+
for (let interval = 0; interval < 3; interval++) {
|
|
498
|
+
const { freshHandle, counted } = await countedHandle()
|
|
499
|
+
const observe = () => scanDispatcher(counted).observeReady()
|
|
441
500
|
scanTime += 30_000
|
|
442
501
|
reset()
|
|
443
502
|
await observe()
|
|
@@ -450,8 +509,8 @@ export async function reducedReadBudget(opts: {
|
|
|
450
509
|
expect(costs.metadata).toBeLessThan(100)
|
|
451
510
|
expect((await readRepositoryFacts(freshHandle, repo)).value.scanSeq).toBe(scanSeq)
|
|
452
511
|
}
|
|
453
|
-
expect(cadenceReads).toBe(
|
|
454
|
-
expect(cadenceWrites).toBe(
|
|
512
|
+
expect(cadenceReads).toBe(7)
|
|
513
|
+
expect(cadenceWrites).toBe(4)
|
|
455
514
|
await dispatcher().tick({ acceptNewWork: false })
|
|
456
515
|
await getOperatorDashboard({ store: cold, repo, clock: () => new Date(1000) })
|
|
457
516
|
reset()
|
|
@@ -732,6 +791,240 @@ export async function targetLineageReadBudget(opts: {
|
|
|
732
791
|
/** Exercise the real outer DispatchLoop with a new invocation identity, either
|
|
733
792
|
* once or for cold and warmed interactive ticks. Only shared values are warmed:
|
|
734
793
|
* no parameterized run value may hide a cold replay. */
|
|
794
|
+
/** A finalize request parked behind its forge-rejection escalation costs the
|
|
795
|
+
* same at every journal length and reads no event rows while nothing changes:
|
|
796
|
+
* no provider probe, description read or forge request per tick. */
|
|
797
|
+
export async function finalizePrRejectionReadBudget(opts: {
|
|
798
|
+
store: BuildStore
|
|
799
|
+
costs: ReducedReadCosts
|
|
800
|
+
fresh: () => Promise<BuildStore>
|
|
801
|
+
}) {
|
|
802
|
+
const { store, costs } = opts
|
|
803
|
+
const build = 'finalize-rejection-budget'
|
|
804
|
+
const branch = `ab/${build}`
|
|
805
|
+
const sha = 'f'.repeat(40)
|
|
806
|
+
await store.createBuild({ slug: build, repo, branch })
|
|
807
|
+
await store.append(build, {
|
|
808
|
+
actor: DISPATCHER,
|
|
809
|
+
type: 'build.created',
|
|
810
|
+
payload: { ticket: { source: 'file', id: 'BUDGET-PR' }, repo, baseBranch: 'main' },
|
|
811
|
+
})
|
|
812
|
+
await store.append(build, {
|
|
813
|
+
actor: KERNEL,
|
|
814
|
+
type: 'workspace.provisioned',
|
|
815
|
+
payload: {
|
|
816
|
+
provider: 'vercel-sandbox',
|
|
817
|
+
remote: true,
|
|
818
|
+
ref: 'sandbox-budget',
|
|
819
|
+
branch,
|
|
820
|
+
base: { source: 'remote', sha: 'e'.repeat(40) },
|
|
821
|
+
},
|
|
822
|
+
})
|
|
823
|
+
const description = await store.putArtifact(build, {
|
|
824
|
+
kind: 'pr-description',
|
|
825
|
+
content: '# Budget\n\nBody.\n',
|
|
826
|
+
})
|
|
827
|
+
await store.append(build, {
|
|
828
|
+
actor: { kind: 'agent', role: 'finalize', session: 'budget-finalize' },
|
|
829
|
+
type: 'publication.requested',
|
|
830
|
+
payload: {
|
|
831
|
+
operation: 'finalize',
|
|
832
|
+
branch,
|
|
833
|
+
sha,
|
|
834
|
+
description: { kind: description.kind, rev: description.revision },
|
|
835
|
+
},
|
|
836
|
+
})
|
|
837
|
+
const forge = new FakeForge()
|
|
838
|
+
forge.setHeadSha(sha)
|
|
839
|
+
forge.rejectNextOpenPr(422, 'Validation Failed: No commits between main and ab/x', 'GitHub')
|
|
840
|
+
let probes = 0
|
|
841
|
+
const settle = (reader: BuildStore) =>
|
|
842
|
+
settlePendingPublication(
|
|
843
|
+
{
|
|
844
|
+
store: reader,
|
|
845
|
+
storeRef: 'budget',
|
|
846
|
+
publication: {
|
|
847
|
+
isPublished: async () => {
|
|
848
|
+
probes++
|
|
849
|
+
return true
|
|
850
|
+
},
|
|
851
|
+
publish: async () => {},
|
|
852
|
+
},
|
|
853
|
+
forge,
|
|
854
|
+
workspacePath: '/budget',
|
|
855
|
+
checkoutless: true,
|
|
856
|
+
exec: async () => ({ stdout: '', stderr: '', exitCode: 0 }),
|
|
857
|
+
ids: sequentialIds(),
|
|
858
|
+
runId: 'budget',
|
|
859
|
+
},
|
|
860
|
+
build,
|
|
861
|
+
)
|
|
862
|
+
await expect(settle(store)).rejects.toBeInstanceOf(ForgeRequestDeferred)
|
|
863
|
+
const raised = async () =>
|
|
864
|
+
(await store.getEvents(build)).filter((event) => event.type === 'escalation.raised').length
|
|
865
|
+
expect(await raised()).toBe(1)
|
|
866
|
+
const bytes = new Map<string, number>()
|
|
867
|
+
let metadata: number | undefined
|
|
868
|
+
let seeded = (await store.getEvents(build)).length
|
|
869
|
+
for (const length of [100, 10_000]) {
|
|
870
|
+
for (; seeded < length; seeded++)
|
|
871
|
+
await store.append(build, {
|
|
872
|
+
actor: humanActor('budget'),
|
|
873
|
+
type: 'build.auto-merge-cancelled',
|
|
874
|
+
payload: {},
|
|
875
|
+
})
|
|
876
|
+
for (const [name, reader] of [
|
|
877
|
+
['live', store],
|
|
878
|
+
['fresh', await opts.fresh()],
|
|
879
|
+
] as const) {
|
|
880
|
+
// Catching up to the padded tail is allowed once per reader.
|
|
881
|
+
await expect(settle(reader)).rejects.toBeInstanceOf(ForgeRequestDeferred)
|
|
882
|
+
costs.events = costs.metadata = costs.bytes = 0
|
|
883
|
+
probes = 0
|
|
884
|
+
const attempts = forge.openPrAttempts
|
|
885
|
+
for (let tick = 0; tick < 3; tick++)
|
|
886
|
+
await expect(settle(reader)).rejects.toBeInstanceOf(ForgeRequestDeferred)
|
|
887
|
+
expect(costs.events).toBe(0)
|
|
888
|
+
expect(probes).toBe(0)
|
|
889
|
+
expect(forge.openPrAttempts).toBe(attempts)
|
|
890
|
+
if (length === 100) {
|
|
891
|
+
metadata ??= costs.metadata
|
|
892
|
+
expect(costs.metadata).toBeLessThan(20)
|
|
893
|
+
bytes.set(name, costs.bytes)
|
|
894
|
+
} else {
|
|
895
|
+
// Seq digits grow in the saved value; allow 100 bytes per measured call.
|
|
896
|
+
expect(costs.bytes).toBeLessThanOrEqual(bytes.get(name)! + 300)
|
|
897
|
+
}
|
|
898
|
+
expect(costs.metadata).toBe(metadata!)
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
expect(forge.openPrAttempts).toBe(1)
|
|
902
|
+
expect(await raised()).toBe(1)
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
/** Remote summary handoff: the dispatcher's launch fence and exit
|
|
906
|
+
* classification plus the guest's coalescing boundary read reduced values
|
|
907
|
+
* only, at constant cost in build length. */
|
|
908
|
+
export async function summaryHandoffReadBudget(opts: {
|
|
909
|
+
store: BuildStore
|
|
910
|
+
costs: ReducedReadCosts
|
|
911
|
+
fresh: () => Promise<BuildStore>
|
|
912
|
+
}) {
|
|
913
|
+
const { store, costs } = opts
|
|
914
|
+
const build = 'summary-handoff-budget'
|
|
915
|
+
const branch = `ab/${build}`
|
|
916
|
+
await store.createBuild({ slug: build, repo, branch })
|
|
917
|
+
await store.append(build, {
|
|
918
|
+
actor: DISPATCHER,
|
|
919
|
+
type: 'build.created',
|
|
920
|
+
payload: { ticket: { source: 'file', id: 'BUDGET-SUMMARY' }, repo, baseBranch: 'main' },
|
|
921
|
+
})
|
|
922
|
+
await store.append(build, {
|
|
923
|
+
actor: KERNEL,
|
|
924
|
+
type: 'workspace.provisioned',
|
|
925
|
+
payload: {
|
|
926
|
+
provider: 'vercel-sandbox',
|
|
927
|
+
remote: true,
|
|
928
|
+
ref: 'sandbox-summary',
|
|
929
|
+
branch,
|
|
930
|
+
base: { source: 'remote', sha: 'e'.repeat(40) },
|
|
931
|
+
},
|
|
932
|
+
})
|
|
933
|
+
const forge = new FakeForge()
|
|
934
|
+
const pr = await forge.openPr({
|
|
935
|
+
workspacePath: '/budget',
|
|
936
|
+
head: branch,
|
|
937
|
+
base: 'main',
|
|
938
|
+
title: 'Budget',
|
|
939
|
+
body: '',
|
|
940
|
+
})
|
|
941
|
+
await store.append(build, { actor: KERNEL, type: 'finalize.completed', payload: { pr } })
|
|
942
|
+
await store.append(build, {
|
|
943
|
+
actor: KERNEL,
|
|
944
|
+
type: 'verify.started',
|
|
945
|
+
payload: { step: 'unit', attempt: 1 },
|
|
946
|
+
})
|
|
947
|
+
await store.append(build, {
|
|
948
|
+
actor: KERNEL,
|
|
949
|
+
type: 'verify.completed',
|
|
950
|
+
payload: { step: 'unit', attempt: 1, outcome: 'pass' },
|
|
951
|
+
})
|
|
952
|
+
const deps = (reader: BuildStore) => ({
|
|
953
|
+
store: reader,
|
|
954
|
+
forge,
|
|
955
|
+
slug: build,
|
|
956
|
+
workspacePath: '/budget',
|
|
957
|
+
storeRef: 'budget',
|
|
958
|
+
clock: () => new Date(),
|
|
959
|
+
})
|
|
960
|
+
// Launch fence, then the guest writes its request and exits.
|
|
961
|
+
const fence = await readLaunchFence(store, build)
|
|
962
|
+
expect(await refreshSummaryBoundary(deps(store))).toBe(true)
|
|
963
|
+
expect(summaryHandoffPending((await readBuildFacts(store, build)).value, fence)).toBe(true)
|
|
964
|
+
await settleSummaryRequests({ ...deps(store), holder: 'budget-host' })
|
|
965
|
+
expect(forge.comments).toHaveLength(1)
|
|
966
|
+
// One launch and exit: fence, completion classification, guest boundary.
|
|
967
|
+
const sequence = async (reader: BuildStore, launchFence: number) => {
|
|
968
|
+
const next = await readLaunchFence(reader, build)
|
|
969
|
+
const pending = summaryHandoffPending((await readBuildFacts(reader, build)).value, launchFence)
|
|
970
|
+
const yielded = await refreshSummaryBoundary(deps(reader), {
|
|
971
|
+
continuesVerifyCycle: true,
|
|
972
|
+
reassert: true,
|
|
973
|
+
})
|
|
974
|
+
return { next, pending, yielded }
|
|
975
|
+
}
|
|
976
|
+
const bytes = new Map<string, number>()
|
|
977
|
+
let metadata: number | undefined
|
|
978
|
+
let seeded = (await store.getEvents(build)).length
|
|
979
|
+
for (const length of [100, 10_000]) {
|
|
980
|
+
for (; seeded < length; seeded++)
|
|
981
|
+
await store.append(build, {
|
|
982
|
+
actor: humanActor('budget'),
|
|
983
|
+
type: 'build.auto-merge-cancelled',
|
|
984
|
+
payload: {},
|
|
985
|
+
})
|
|
986
|
+
for (const [name, reader] of [
|
|
987
|
+
['live', store],
|
|
988
|
+
['fresh', await opts.fresh()],
|
|
989
|
+
] as const) {
|
|
990
|
+
// Catching up to the padded tail is allowed once per reader.
|
|
991
|
+
const launchFence = (await sequence(reader, fence)).next
|
|
992
|
+
costs.events = costs.metadata = costs.bytes = 0
|
|
993
|
+
for (let exit = 0; exit < 3; exit++)
|
|
994
|
+
expect(await sequence(reader, launchFence)).toEqual({
|
|
995
|
+
next: launchFence,
|
|
996
|
+
pending: false,
|
|
997
|
+
yielded: false,
|
|
998
|
+
})
|
|
999
|
+
expect(costs.events).toBe(0)
|
|
1000
|
+
if (length === 100) {
|
|
1001
|
+
metadata ??= costs.metadata
|
|
1002
|
+
expect(costs.metadata).toBeLessThan(20)
|
|
1003
|
+
bytes.set(name, costs.bytes)
|
|
1004
|
+
} else {
|
|
1005
|
+
// Seq digits grow in the saved value; allow 100 bytes per measured call.
|
|
1006
|
+
expect(costs.bytes).toBeLessThanOrEqual(bytes.get(name)! + 300)
|
|
1007
|
+
}
|
|
1008
|
+
expect(costs.metadata).toBe(metadata!)
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
// A guest-written request is the only new tail the next exit reads.
|
|
1012
|
+
const launchFence = await readLaunchFence(store, build)
|
|
1013
|
+
const fresh = await opts.fresh()
|
|
1014
|
+
await sequence(fresh, launchFence)
|
|
1015
|
+
await store.append(build, {
|
|
1016
|
+
actor: KERNEL,
|
|
1017
|
+
type: 'pr-summary.requested',
|
|
1018
|
+
payload: (await readBuildFacts(store, build)).value.summaryBoundary!,
|
|
1019
|
+
})
|
|
1020
|
+
for (const reader of [store, fresh]) {
|
|
1021
|
+
costs.events = 0
|
|
1022
|
+
expect((await sequence(reader, launchFence)).pending).toBe(true)
|
|
1023
|
+
expect(costs.events).toBeLessThanOrEqual(3)
|
|
1024
|
+
}
|
|
1025
|
+
expect(forge.comments).toHaveLength(1)
|
|
1026
|
+
}
|
|
1027
|
+
|
|
735
1028
|
async function coldDispatchOnceBudget(
|
|
736
1029
|
store: BuildStore,
|
|
737
1030
|
cold: BuildStore,
|
|
@@ -775,6 +1068,23 @@ steps = []
|
|
|
775
1068
|
let ticketScanWrites = 0
|
|
776
1069
|
let deferredAttempts = 0
|
|
777
1070
|
let tickAcquisitions = { facts: 0, digests: 0 }
|
|
1071
|
+
// The display-only triage sample is read only by a dispatcher that feeds
|
|
1072
|
+
// an interactive frontend, between ticks and at most once per
|
|
1073
|
+
// TRIAGE_COUNT_REFRESH_MS; no read ever lands inside a tick window.
|
|
1074
|
+
const startedAt = Date.now()
|
|
1075
|
+
let stateReads = 0
|
|
1076
|
+
let stateReadsInTick = 0
|
|
1077
|
+
let tickOpen = false
|
|
1078
|
+
const tickets = Object.assign(new FakeTicketSource([]), {
|
|
1079
|
+
countStates: async (names: readonly string[]) => {
|
|
1080
|
+
stateReads++
|
|
1081
|
+
if (tickOpen) stateReadsInTick++
|
|
1082
|
+
return names.map((name) => ({ name, tickets: 2 }))
|
|
1083
|
+
},
|
|
1084
|
+
listStates: async () => {
|
|
1085
|
+
throw new Error('the triage sample never lists ticket states')
|
|
1086
|
+
},
|
|
1087
|
+
})
|
|
778
1088
|
const checked = new Proxy(cold, {
|
|
779
1089
|
get(target, key) {
|
|
780
1090
|
if (interactive && key === 'beginRepoTick')
|
|
@@ -786,14 +1096,19 @@ steps = []
|
|
|
786
1096
|
expect(costs.historicalEvents).toBe(0)
|
|
787
1097
|
acquisitions.facts = acquisitions.digests = ticketScanWrites = 0
|
|
788
1098
|
costs.events = costs.historicalEvents = 0
|
|
1099
|
+
tickOpen = true
|
|
789
1100
|
return target.beginRepoTick(...args)
|
|
790
1101
|
}
|
|
791
1102
|
if (interactive && key === 'finishRepoTick')
|
|
792
|
-
return (...args: Parameters<BuildStore['finishRepoTick']>) => {
|
|
1103
|
+
return async (...args: Parameters<BuildStore['finishRepoTick']>) => {
|
|
793
1104
|
// Close the kernel window before the independent dashboard poll.
|
|
794
1105
|
tickAcquisitions = { ...acquisitions, facts: acquisitions.facts - ticketScanWrites }
|
|
795
|
-
|
|
796
|
-
|
|
1106
|
+
try {
|
|
1107
|
+
if (outage && ticks === 0) throw new Error('budget tick write refused')
|
|
1108
|
+
return await target.finishRepoTick(...args)
|
|
1109
|
+
} finally {
|
|
1110
|
+
tickOpen = false
|
|
1111
|
+
}
|
|
797
1112
|
}
|
|
798
1113
|
if (interactive && key === 'appendRepo')
|
|
799
1114
|
return (...args: Parameters<BuildStore['appendRepo']>) => {
|
|
@@ -861,6 +1176,11 @@ steps = []
|
|
|
861
1176
|
// Drain the asynchronous launch gate before closing each tick window.
|
|
862
1177
|
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
863
1178
|
expect(tickAcquisitions).toEqual({ facts: 1, digests: 1 })
|
|
1179
|
+
expect(stateReadsInTick).toBe(0)
|
|
1180
|
+
expect(stateReads).toBeLessThanOrEqual(
|
|
1181
|
+
interactive ? Math.ceil((Date.now() - startedAt) / TRIAGE_COUNT_REFRESH_MS) + 1 : 0,
|
|
1182
|
+
)
|
|
1183
|
+
if (interactive) expect(stateReads).toBeGreaterThan(0)
|
|
864
1184
|
expect(costs.historicalEvents).toBe(0)
|
|
865
1185
|
expect(costs.events).toBeLessThanOrEqual(32)
|
|
866
1186
|
// Prepare the newly written tick-completed tail, then prove an
|
|
@@ -874,11 +1194,12 @@ steps = []
|
|
|
874
1194
|
if (++ticks === (outage ? 3 : 2)) stop.abort()
|
|
875
1195
|
},
|
|
876
1196
|
kernelRunId: run,
|
|
1197
|
+
...(interactive ? { frontendStatus: true } : {}),
|
|
877
1198
|
storeRef: '/budget',
|
|
878
1199
|
wire: () => ({
|
|
879
1200
|
store: checked,
|
|
880
1201
|
storeRef: '/budget',
|
|
881
|
-
tickets
|
|
1202
|
+
tickets,
|
|
882
1203
|
forge: new FakeForge(),
|
|
883
1204
|
workspaces: new FakeWorkspaceProvider({ root: '/once-workspaces', mode: 'logical' }),
|
|
884
1205
|
buildExecution: {
|
|
@@ -903,6 +1224,8 @@ steps = []
|
|
|
903
1224
|
([id]) => id === run,
|
|
904
1225
|
)?.[1]
|
|
905
1226
|
expect(finished?.completed?.type).toBe('dispatcher.tick-completed')
|
|
1227
|
+
if (interactive) expect(finished?.completed?.payload).toMatchObject({ triage: 2 })
|
|
1228
|
+
else expect(finished?.completed?.payload).not.toHaveProperty('triage')
|
|
906
1229
|
expect(finished?.stop?.type).toBe('dispatcher.run-stopped')
|
|
907
1230
|
// The same fresh invocation may fail before writing its start fact.
|
|
908
1231
|
expect(
|
|
@@ -1272,6 +1595,134 @@ export async function flaggedWorkspaceSweepReadBudget(opts: {
|
|
|
1272
1595
|
})
|
|
1273
1596
|
}
|
|
1274
1597
|
|
|
1598
|
+
/** A provision continuation that reaches its launch for a build at the
|
|
1599
|
+
* no-progress limit applies the guard instead of starting a runner. Each
|
|
1600
|
+
* continuation is a recurring invocation (every re-provision, every remote
|
|
1601
|
+
* dispatch), so it must read no seeded history and the same reduced values,
|
|
1602
|
+
* artifacts and tail rows at 100 and 100,000 events, both in the whole tick
|
|
1603
|
+
* and in the guarded launch window after `workspace.provisioned`. */
|
|
1604
|
+
export async function provisionContinuationGuardReadBudget(opts: {
|
|
1605
|
+
store: import('../store/memory').MemoryBuildStore
|
|
1606
|
+
/** Seeds a fresh build whose next tick kicks a remote provision
|
|
1607
|
+
* continuation with `tail`, and returns its slug. Called before filler. */
|
|
1608
|
+
seed: (tail: 'launch' | 'dispatch', length: number) => Promise<string>
|
|
1609
|
+
/** A fresh dispatcher per measured invocation: no per-process cache. */
|
|
1610
|
+
dispatcher: () => Dispatcher
|
|
1611
|
+
advance: () => void
|
|
1612
|
+
launches: () => number
|
|
1613
|
+
}) {
|
|
1614
|
+
const { store } = opts
|
|
1615
|
+
const configKind = 'build-runner-effective-config'
|
|
1616
|
+
type Counts = { reduced: Record<string, number>; configReads: number; tailRows: number }
|
|
1617
|
+
const results: Record<string, { tick: Counts; launchWindow: Counts }> = {}
|
|
1618
|
+
for (const tail of ['launch', 'dispatch'] as const) {
|
|
1619
|
+
for (const length of [100, 100_000]) {
|
|
1620
|
+
const slug = await opts.seed(tail, length)
|
|
1621
|
+
// Filler is a progress fact, so it precedes the no-progress streak.
|
|
1622
|
+
await seedBuildFiller(store, slug, length)
|
|
1623
|
+
for (const instance of ['empty-a', 'empty-b', 'empty-c']) {
|
|
1624
|
+
await store.append(slug, {
|
|
1625
|
+
actor: DISPATCHER,
|
|
1626
|
+
type: 'execution.started',
|
|
1627
|
+
payload: { instance, provider: 'remote-test', workspaceRef: 'sandbox-g0' },
|
|
1628
|
+
})
|
|
1629
|
+
await store.append(slug, {
|
|
1630
|
+
actor: DISPATCHER,
|
|
1631
|
+
type: 'execution.ended',
|
|
1632
|
+
payload: { instance, workspaceRef: 'sandbox-g0', outcome: 'completed', exitCode: 0 },
|
|
1633
|
+
})
|
|
1634
|
+
}
|
|
1635
|
+
// Materialize every build-scoped value the tick reads once, without a
|
|
1636
|
+
// tick, which would itself kick the continuation being measured. A
|
|
1637
|
+
// first reduction per key is canonical; the measured tick must only
|
|
1638
|
+
// advance saved values over its own tail.
|
|
1639
|
+
expect((await readBuildFacts(store, slug)).value.executionNoProgress.count).toBe(3)
|
|
1640
|
+
for (const reducer of ['buildDigest', 'baseBranchValue', 'publishedBranchHeadValue'])
|
|
1641
|
+
await store.getReducerValue({ kind: 'build', slug }, { reducer })
|
|
1642
|
+
// The remote provider is recovery-capable, so it owns the workspace.
|
|
1643
|
+
await readDispatchBudget(store, slug, true)
|
|
1644
|
+
const boundary = buildEventRows(store, slug).at(-1)!.seq
|
|
1645
|
+
const rows = { historicalRows: 0, tailRows: 0 }
|
|
1646
|
+
const counts = (): Counts => ({ reduced: {}, configReads: 0, tailRows: 0 })
|
|
1647
|
+
const tick = counts()
|
|
1648
|
+
let atProvision: Counts | undefined
|
|
1649
|
+
const getReducerValue = store.getReducerValue.bind(store)
|
|
1650
|
+
store.getReducerValue = async (scope, request) => {
|
|
1651
|
+
if (scope.kind === 'build' && scope.slug === slug)
|
|
1652
|
+
tick.reduced[request.reducer] = (tick.reduced[request.reducer] ?? 0) + 1
|
|
1653
|
+
return getReducerValue(scope, request)
|
|
1654
|
+
}
|
|
1655
|
+
const getArtifact = store.getArtifact.bind(store)
|
|
1656
|
+
store.getArtifact = async (...args) => {
|
|
1657
|
+
if (args[0] === slug && args[1] === configKind) tick.configReads++
|
|
1658
|
+
return getArtifact(...args)
|
|
1659
|
+
}
|
|
1660
|
+
const append = store.append.bind(store)
|
|
1661
|
+
store.append = (async (...args: Parameters<typeof append>) => {
|
|
1662
|
+
const result = await append(...args)
|
|
1663
|
+
if (args[0] === slug && args[1].type === 'workspace.provisioned')
|
|
1664
|
+
atProvision = { ...structuredClone(tick), tailRows: rows.tailRows }
|
|
1665
|
+
return result
|
|
1666
|
+
}) as typeof store.append
|
|
1667
|
+
const restoreRows = instrumentBuildRows(store, slug, () => boundary, rows)
|
|
1668
|
+
const launchesBefore = opts.launches()
|
|
1669
|
+
try {
|
|
1670
|
+
opts.advance()
|
|
1671
|
+
const dispatcher = opts.dispatcher()
|
|
1672
|
+
await dispatcher.tick({ acceptNewWork: false })
|
|
1673
|
+
await dispatcher.drainProvisioning()
|
|
1674
|
+
} finally {
|
|
1675
|
+
restoreRows()
|
|
1676
|
+
Reflect.deleteProperty(store, 'getReducerValue')
|
|
1677
|
+
Reflect.deleteProperty(store, 'getArtifact')
|
|
1678
|
+
Reflect.deleteProperty(store, 'append')
|
|
1679
|
+
}
|
|
1680
|
+
tick.tailRows = rows.tailRows
|
|
1681
|
+
const appended = buildEventRows(store, slug).at(-1)!.seq - boundary
|
|
1682
|
+
expect(rows.historicalRows).toBe(0)
|
|
1683
|
+
expect(atProvision).toBeDefined()
|
|
1684
|
+
const launchWindow: Counts = {
|
|
1685
|
+
reduced: Object.fromEntries(
|
|
1686
|
+
Object.entries(tick.reduced).map(([reducer, n]) => [
|
|
1687
|
+
reducer,
|
|
1688
|
+
n - (atProvision!.reduced[reducer] ?? 0),
|
|
1689
|
+
]),
|
|
1690
|
+
),
|
|
1691
|
+
configReads: tick.configReads - atProvision!.configReads,
|
|
1692
|
+
tailRows: tick.tailRows - atProvision!.tailRows,
|
|
1693
|
+
}
|
|
1694
|
+
const events = buildEventRows(store, slug).filter((event) => event.seq > boundary)
|
|
1695
|
+
expect(
|
|
1696
|
+
events.filter(
|
|
1697
|
+
(event) =>
|
|
1698
|
+
event.type === 'escalation.raised' &&
|
|
1699
|
+
event.payload.policyCause === 'execution-no-progress',
|
|
1700
|
+
),
|
|
1701
|
+
).toHaveLength(1)
|
|
1702
|
+
expect(opts.launches()).toBe(launchesBefore)
|
|
1703
|
+
// The guarded launch window reads the reduced build facts twice on
|
|
1704
|
+
// either tail: the continuation's own queued check, and the guard's
|
|
1705
|
+
// read after its refresh. The dispatch tail's completion boundaries
|
|
1706
|
+
// already add three on main: the mixed-version check, the discard
|
|
1707
|
+
// check, and the pre-launch re-read. The guard's decision reads the
|
|
1708
|
+
// pinned config once (the fixture carries no verify pin).
|
|
1709
|
+
expect(launchWindow.reduced.buildReadFacts).toBe(tail === 'launch' ? 2 : 5)
|
|
1710
|
+
expect(launchWindow.configReads).toBe(1)
|
|
1711
|
+
// Tail rows are only rows this invocation appended (each read at most
|
|
1712
|
+
// once per reduced read that advances over it).
|
|
1713
|
+
expect(launchWindow.tailRows).toBeLessThanOrEqual(appended * tick.reduced.buildReadFacts!)
|
|
1714
|
+
results[`${tail}:${length}`] = { tick, launchWindow }
|
|
1715
|
+
}
|
|
1716
|
+
expect(results[`${tail}:100`]).toEqual(results[`${tail}:100000`]!)
|
|
1717
|
+
}
|
|
1718
|
+
console.log('provision continuation guard read budget', {
|
|
1719
|
+
histories: [100, 100_000],
|
|
1720
|
+
launch: results['launch:100000'],
|
|
1721
|
+
dispatch: results['dispatch:100000'],
|
|
1722
|
+
historicalRows: 0,
|
|
1723
|
+
})
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1275
1726
|
/** In-memory history seeding for preparation budgets; never used as a recurring read. */
|
|
1276
1727
|
export async function seedPreparationHistory(store: BuildStore, repo: string, facts: number) {
|
|
1277
1728
|
await store.ensureRepo(repo)
|
|
@@ -1386,6 +1837,13 @@ export async function nodePollingReadBudget(opts: {
|
|
|
1386
1837
|
slug: string
|
|
1387
1838
|
tick: () => Promise<unknown>
|
|
1388
1839
|
advance: (ms: number) => void
|
|
1840
|
+
/** Seed every 10th event as a recorded child's issue links: 10 children at
|
|
1841
|
+
* 100 events and 10,000 at 100,000, over a bounded issue set. */
|
|
1842
|
+
issueLinkChildren?: boolean
|
|
1843
|
+
/** Proves the node still waits for a runner slot after each measured tick,
|
|
1844
|
+
* so the every-tick admission stage is measured on its waiting path. Its
|
|
1845
|
+
* own reads are excluded from the measurement. */
|
|
1846
|
+
slotWaiting?: () => Promise<boolean>
|
|
1389
1847
|
}) {
|
|
1390
1848
|
const { store, slug } = opts
|
|
1391
1849
|
const checkpoint = (await readBuildFacts(store, slug)).value.state.nodePolling!
|
|
@@ -1393,16 +1851,32 @@ export async function nodePollingReadBudget(opts: {
|
|
|
1393
1851
|
let baseline: number[] | undefined
|
|
1394
1852
|
for (const length of [100, 100_000]) {
|
|
1395
1853
|
for (; seeded < length; seeded++)
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1854
|
+
if (opts.issueLinkChildren && seeded % 10 === 0)
|
|
1855
|
+
await store.append(slug, {
|
|
1856
|
+
actor: DISPATCHER,
|
|
1857
|
+
type: 'node.issue-links-recorded',
|
|
1858
|
+
payload: {
|
|
1859
|
+
build: `child-${seeded}`,
|
|
1860
|
+
issueLinks: [
|
|
1861
|
+
{
|
|
1862
|
+
issue: (seeded % 50) + 1,
|
|
1863
|
+
intent: seeded % 7 ? 'closes' : 'refs',
|
|
1864
|
+
...(seeded % 11 === 0 ? { downgraded: true as const } : {}),
|
|
1865
|
+
},
|
|
1866
|
+
],
|
|
1867
|
+
},
|
|
1868
|
+
})
|
|
1869
|
+
else
|
|
1870
|
+
await store.append(slug, {
|
|
1871
|
+
actor: DISPATCHER,
|
|
1872
|
+
type: 'node.poll-checked',
|
|
1873
|
+
payload: {
|
|
1874
|
+
activityKey: checkpoint.activityKey,
|
|
1875
|
+
unchangedSince: checkpoint.unchangedSince,
|
|
1876
|
+
nodeIdleAfterSeconds: checkpoint.nodeIdleAfterSeconds,
|
|
1877
|
+
nodeIdlePollSeconds: checkpoint.nodeIdlePollSeconds,
|
|
1878
|
+
},
|
|
1879
|
+
})
|
|
1406
1880
|
await store.append(slug, {
|
|
1407
1881
|
actor: humanActor('budget'),
|
|
1408
1882
|
type: 'build.hold-requested',
|
|
@@ -1438,11 +1912,210 @@ export async function nodePollingReadBudget(opts: {
|
|
|
1438
1912
|
expect(rows).toBeLessThanOrEqual(8)
|
|
1439
1913
|
if (elapsed === 10_000) expect(rows).toBe(0)
|
|
1440
1914
|
costs.push(rows, calls)
|
|
1915
|
+
if (opts.slotWaiting) expect(await opts.slotWaiting()).toBe(true)
|
|
1916
|
+
history = 0
|
|
1441
1917
|
}
|
|
1442
1918
|
} finally {
|
|
1443
1919
|
Reflect.deleteProperty(events, 'slice')
|
|
1444
1920
|
store.getReducerValue = getReduced
|
|
1445
1921
|
}
|
|
1922
|
+
// A status-style read serves the saved reduced value without history.
|
|
1923
|
+
history = 0
|
|
1924
|
+
events.slice = (start, end) => {
|
|
1925
|
+
const selected = slice(start, end)
|
|
1926
|
+
history += selected.filter((event) => event.seq <= boundary).length
|
|
1927
|
+
return selected
|
|
1928
|
+
}
|
|
1929
|
+
try {
|
|
1930
|
+
const status = (await readBuildFacts(store, slug)).value.state
|
|
1931
|
+
if (opts.issueLinkChildren) expect(status.nodeIssueLinks?.builds).toHaveLength(length / 10)
|
|
1932
|
+
expect(history).toBe(0)
|
|
1933
|
+
} finally {
|
|
1934
|
+
Reflect.deleteProperty(events, 'slice')
|
|
1935
|
+
}
|
|
1936
|
+
if (baseline) expect(costs).toEqual(baseline)
|
|
1937
|
+
baseline = costs
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1941
|
+
/** Node child discovery (AUT-1129) reads only the digest batch plus facts for
|
|
1942
|
+
* builds whose digest names the node. Fresh dispatchers (one per hosted
|
|
1943
|
+
* invocation) observing an open node spend the same store reads at 10 and at
|
|
1944
|
+
* 1,000 unrelated builds, never read an unrelated build outside the digest
|
|
1945
|
+
* batch, and read zero event rows on an unchanged tick. */
|
|
1946
|
+
export async function nodeChildDiscoveryReadBudget(opts: {
|
|
1947
|
+
store: import('../store/memory').MemoryBuildStore
|
|
1948
|
+
repo: string
|
|
1949
|
+
/** One tick on a fresh dispatcher. */
|
|
1950
|
+
tick: () => Promise<unknown>
|
|
1951
|
+
advance: (ms: number) => void
|
|
1952
|
+
/** Exhaustive ticket listings so far: proves observation actually ran. */
|
|
1953
|
+
observed: () => number
|
|
1954
|
+
}) {
|
|
1955
|
+
const { store, repo } = opts
|
|
1956
|
+
const ticket = { source: 'fake', id: 'UNRELATED' }
|
|
1957
|
+
const created = (target?: string, kind?: 'node') => ({
|
|
1958
|
+
actor: DISPATCHER,
|
|
1959
|
+
type: 'build.created' as const,
|
|
1960
|
+
payload: {
|
|
1961
|
+
ticket,
|
|
1962
|
+
repo,
|
|
1963
|
+
baseBranch: 'main',
|
|
1964
|
+
...(kind ? { kind } : {}),
|
|
1965
|
+
...(target ? { target: { ticket, build: target } } : {}),
|
|
1966
|
+
},
|
|
1967
|
+
})
|
|
1968
|
+
const terminal = async (slug: string, target?: string, kind?: 'node') => {
|
|
1969
|
+
await store.createBuild({ slug, repo, ticket, created: created(target, kind) })
|
|
1970
|
+
await store.append(slug, {
|
|
1971
|
+
actor: DISPATCHER,
|
|
1972
|
+
type: 'build.completed',
|
|
1973
|
+
payload: { outcome: 'merged' },
|
|
1974
|
+
})
|
|
1975
|
+
}
|
|
1976
|
+
// Half the unrelated builds target a different, finished node: the filter
|
|
1977
|
+
// is per node, not "has any target".
|
|
1978
|
+
await terminal('unrelated-node', undefined, 'node')
|
|
1979
|
+
const unrelated = new Set(['unrelated-node'])
|
|
1980
|
+
const methods = [
|
|
1981
|
+
'getReducerValue',
|
|
1982
|
+
'getEvents',
|
|
1983
|
+
'getBuild',
|
|
1984
|
+
'getArtifact',
|
|
1985
|
+
'getLatestArtifactMeta',
|
|
1986
|
+
'listArtifacts',
|
|
1987
|
+
'getRepoBuildDigests',
|
|
1988
|
+
] as const
|
|
1989
|
+
let baseline: Record<string, number> | undefined
|
|
1990
|
+
for (const count of [10, 1000]) {
|
|
1991
|
+
while (unrelated.size <= count) {
|
|
1992
|
+
const slug = `unrelated-${unrelated.size}`
|
|
1993
|
+
await terminal(slug, unrelated.size % 2 ? 'unrelated-node' : undefined)
|
|
1994
|
+
unrelated.add(slug)
|
|
1995
|
+
}
|
|
1996
|
+
// Saved reduced values for the new builds settle once.
|
|
1997
|
+
await opts.tick()
|
|
1998
|
+
const calls: Record<string, number> = {}
|
|
1999
|
+
let strays = 0
|
|
2000
|
+
const originals = new Map<string, unknown>()
|
|
2001
|
+
for (const method of methods) {
|
|
2002
|
+
const original = Reflect.get(store, method) as (...args: unknown[]) => Promise<unknown>
|
|
2003
|
+
originals.set(method, original)
|
|
2004
|
+
Reflect.set(store, method, (...args: unknown[]) => {
|
|
2005
|
+
const [first, second] = args as [unknown, { reducer?: string } | undefined]
|
|
2006
|
+
// The per-key reads behind the digest batch are the listing every
|
|
2007
|
+
// tick already pays; they are not per-build discovery reads.
|
|
2008
|
+
if (method !== 'getReducerValue' || second?.reducer !== 'buildDigest') {
|
|
2009
|
+
calls[method] = (calls[method] ?? 0) + 1
|
|
2010
|
+
const slug =
|
|
2011
|
+
typeof first === 'string'
|
|
2012
|
+
? first
|
|
2013
|
+
: first && typeof first === 'object' && 'slug' in first
|
|
2014
|
+
? first.slug
|
|
2015
|
+
: undefined
|
|
2016
|
+
if (typeof slug === 'string' && unrelated.has(slug)) strays++
|
|
2017
|
+
}
|
|
2018
|
+
return original.apply(store, args)
|
|
2019
|
+
})
|
|
2020
|
+
}
|
|
2021
|
+
const logs = [
|
|
2022
|
+
...(
|
|
2023
|
+
Reflect.get(store, 'builds') as Map<
|
|
2024
|
+
string,
|
|
2025
|
+
{ events: import('../events/catalog').AbEvent[] }
|
|
2026
|
+
>
|
|
2027
|
+
).values(),
|
|
2028
|
+
]
|
|
2029
|
+
let rows = 0
|
|
2030
|
+
for (const { events } of logs) {
|
|
2031
|
+
const slice = events.slice.bind(events)
|
|
2032
|
+
events.slice = (start, end) => {
|
|
2033
|
+
const selected = slice(start, end)
|
|
2034
|
+
rows += selected.length
|
|
2035
|
+
return selected
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
try {
|
|
2039
|
+
const listings = opts.observed()
|
|
2040
|
+
// Past the integration poll window, so the node observes its children.
|
|
2041
|
+
opts.advance(301_000)
|
|
2042
|
+
await opts.tick()
|
|
2043
|
+
expect(opts.observed()).toBeGreaterThan(listings)
|
|
2044
|
+
expect(strays).toBe(0)
|
|
2045
|
+
const costs = { ...calls }
|
|
2046
|
+
// Nothing changes: a fresh process reads no event rows.
|
|
2047
|
+
opts.advance(10_000)
|
|
2048
|
+
await opts.tick()
|
|
2049
|
+
rows = 0
|
|
2050
|
+
opts.advance(10_000)
|
|
2051
|
+
await opts.tick()
|
|
2052
|
+
expect(rows).toBe(0)
|
|
2053
|
+
expect(strays).toBe(0)
|
|
2054
|
+
if (baseline) expect(costs).toEqual(baseline)
|
|
2055
|
+
baseline = costs
|
|
2056
|
+
} finally {
|
|
2057
|
+
for (const { events } of logs) Reflect.deleteProperty(events, 'slice')
|
|
2058
|
+
for (const method of methods) Reflect.deleteProperty(store, method)
|
|
2059
|
+
for (const [method, original] of originals)
|
|
2060
|
+
if (Reflect.get(store, method) !== original) Reflect.set(store, method, original)
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2064
|
+
|
|
2065
|
+
/** A kernel Git outage is one durable repository condition. Fresh
|
|
2066
|
+
* dispatchers (one per hosted invocation) read it from the saved repository
|
|
2067
|
+
* value: while nothing changes each tick spends at most one failed Git spawn
|
|
2068
|
+
* and reads zero event rows, at 100 and at 100,000 events. */
|
|
2069
|
+
export async function kernelGitOutageReadBudget(opts: {
|
|
2070
|
+
store: import('../store/memory').MemoryBuildStore
|
|
2071
|
+
repo: string
|
|
2072
|
+
slug: string
|
|
2073
|
+
/** One tick on a fresh dispatcher whose kernel Git cannot execute. */
|
|
2074
|
+
tick: () => Promise<unknown>
|
|
2075
|
+
advance: (ms: number) => void
|
|
2076
|
+
/** Kernel Git spawns attempted so far. */
|
|
2077
|
+
spawns: () => number
|
|
2078
|
+
}) {
|
|
2079
|
+
const { store, repo, slug } = opts
|
|
2080
|
+
const unavailable = async () =>
|
|
2081
|
+
(await store.getRepoEvents(repo)).filter(
|
|
2082
|
+
(event) => event.type === 'dispatcher.kernel-git-unavailable',
|
|
2083
|
+
).length
|
|
2084
|
+
let seeded = 0
|
|
2085
|
+
let baseline: number[] | undefined
|
|
2086
|
+
for (const length of [100, 100_000]) {
|
|
2087
|
+
for (; seeded < length; seeded++) {
|
|
2088
|
+
await store.appendRepo(repo, {
|
|
2089
|
+
actor: humanActor('budget'),
|
|
2090
|
+
type: 'dispatcher.intake-set',
|
|
2091
|
+
payload: { enabled: true },
|
|
2092
|
+
})
|
|
2093
|
+
if (seeded % 10 === 0)
|
|
2094
|
+
await store.append(slug, {
|
|
2095
|
+
actor: KERNEL,
|
|
2096
|
+
type: 'observation.recorded',
|
|
2097
|
+
payload: { id: `obs-${seeded}`, kind: 'followup', summary: `budget padding ${seeded}` },
|
|
2098
|
+
})
|
|
2099
|
+
}
|
|
2100
|
+
// Warm up: the outage tick, then one fresh read that catches up its own
|
|
2101
|
+
// append. Nothing changes after that.
|
|
2102
|
+
for (let n = 0; n < 2; n++) {
|
|
2103
|
+
opts.advance(120_000)
|
|
2104
|
+
await opts.tick()
|
|
2105
|
+
}
|
|
2106
|
+
const counter = memoryRepositoryReadCounter(store, repo)
|
|
2107
|
+
const costs: number[] = []
|
|
2108
|
+
for (let n = 0; n < 3; n++) {
|
|
2109
|
+
opts.advance(120_000)
|
|
2110
|
+
counter.reset()
|
|
2111
|
+
const before = opts.spawns()
|
|
2112
|
+
await opts.tick()
|
|
2113
|
+
expect(counter.rows).toBe(0)
|
|
2114
|
+
expect(counter.buildRows).toBe(0)
|
|
2115
|
+
expect(opts.spawns() - before).toBeLessThanOrEqual(1)
|
|
2116
|
+
costs.push(counter.rows, counter.buildRows, counter.reducedCalls, opts.spawns() - before)
|
|
2117
|
+
}
|
|
2118
|
+
expect(await unavailable()).toBe(1)
|
|
1446
2119
|
if (baseline) expect(costs).toEqual(baseline)
|
|
1447
2120
|
baseline = costs
|
|
1448
2121
|
}
|
|
@@ -1893,3 +2566,384 @@ export async function hostedSeedReadBudget() {
|
|
|
1893
2566
|
}
|
|
1894
2567
|
expect(gapCosts).toEqual([14, 14])
|
|
1895
2568
|
}
|
|
2569
|
+
|
|
2570
|
+
/** The backlog and rejected roles ride the dispatcher's existing ticket reads:
|
|
2571
|
+
* a role-aware tick issues exactly as many ticket-source requests as a
|
|
2572
|
+
* role-free one, at 100 and at 100,000 repository events, and an unchanged
|
|
2573
|
+
* read after it costs zero event rows. `open` returns the source a project
|
|
2574
|
+
* with `config` dispatches over and a running count of its source requests.
|
|
2575
|
+
*
|
|
2576
|
+
* Each tick is followed by the interactive dispatcher's triage sample: exactly
|
|
2577
|
+
* `sampleRequests` source requests (one bounded count, or none for a source
|
|
2578
|
+
* without counts), never a listing, zero event rows, and the same cost at
|
|
2579
|
+
* every log length. */
|
|
2580
|
+
export async function ticketRoleTickBudget(
|
|
2581
|
+
open: (
|
|
2582
|
+
config: import('../config/schema').Config,
|
|
2583
|
+
) => Promise<{ tickets: import('../ports/types').TicketSource; requests: () => number }>,
|
|
2584
|
+
sampleRequests: 0 | 1,
|
|
2585
|
+
) {
|
|
2586
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
2587
|
+
const sha = 'a'.repeat(40)
|
|
2588
|
+
const perTick = new Map<string, number[]>()
|
|
2589
|
+
for (const roles of [false, true]) {
|
|
2590
|
+
for (const length of [100, 100_000]) {
|
|
2591
|
+
const config = parseConfig(
|
|
2592
|
+
`[tickets]\nsource = "hosted"\nteamKey = "ENG"\n${
|
|
2593
|
+
roles ? 'backlogState = "icebox"\nrejectedState = "rejected"\n' : ''
|
|
2594
|
+
}[verify]\nsteps = []\n[finalize]\nsteps = []\n`,
|
|
2595
|
+
)
|
|
2596
|
+
const { tickets, requests } = await open(config)
|
|
2597
|
+
// Every ready ticket is blocked, so ticks claim nothing and change nothing.
|
|
2598
|
+
const seed = async (title: string, state: string, blocker?: string) => {
|
|
2599
|
+
const ticket = await tickets.create({ title, body: 'Budget' })
|
|
2600
|
+
if (blocker !== undefined) await tickets.addBlocker(ticket.ref.id, blocker)
|
|
2601
|
+
await tickets.transition(ticket.ref.id, state)
|
|
2602
|
+
return ticket.ref.id
|
|
2603
|
+
}
|
|
2604
|
+
const rejected = await seed('Rejected blocker', 'rejected')
|
|
2605
|
+
const pending = await seed('Incomplete blocker', 'triage')
|
|
2606
|
+
await seed('Blocked by rejected', 'ready', rejected)
|
|
2607
|
+
await seed('Blocked by incomplete', 'ready', pending)
|
|
2608
|
+
await seed('Deferred', 'icebox')
|
|
2609
|
+
|
|
2610
|
+
let now = 1_800_000_000_000
|
|
2611
|
+
const clock = () => new Date(now)
|
|
2612
|
+
const store = new MemoryBuildStore({ clock })
|
|
2613
|
+
const repo = `https://github.com/budget/ticket-roles-${roles}-${length}`
|
|
2614
|
+
await store.ensureRepo(repo)
|
|
2615
|
+
for (let i = 0; i < length; i++)
|
|
2616
|
+
await store.appendRepo(repo, {
|
|
2617
|
+
actor: humanActor('budget'),
|
|
2618
|
+
type: 'dispatcher.intake-set',
|
|
2619
|
+
payload: { enabled: true },
|
|
2620
|
+
})
|
|
2621
|
+
// The one serialized reduction per key happens before the measured ticks.
|
|
2622
|
+
await readRepositoryFacts(store, repo)
|
|
2623
|
+
await readBuildDigests(store, repo)
|
|
2624
|
+
const counter = memoryRepositoryReadCounter(store, repo)
|
|
2625
|
+
const costs: number[] = []
|
|
2626
|
+
for (let tick = 0; tick < 2; tick++) {
|
|
2627
|
+
now += 60_000
|
|
2628
|
+
const forge = new FakeForge()
|
|
2629
|
+
forge.seedBranch('main', sha)
|
|
2630
|
+
const dispatcher = new Dispatcher({
|
|
2631
|
+
store,
|
|
2632
|
+
tickets,
|
|
2633
|
+
workspaces: new FakeWorkspaceProvider({
|
|
2634
|
+
root: '/ticket-role-budget',
|
|
2635
|
+
mode: 'logical',
|
|
2636
|
+
base: { source: 'remote', sha },
|
|
2637
|
+
}),
|
|
2638
|
+
forge,
|
|
2639
|
+
config,
|
|
2640
|
+
repo,
|
|
2641
|
+
exec: async () => ({ stdout: `${sha}\trefs/heads/main\n`, stderr: '', exitCode: 0 }),
|
|
2642
|
+
launchRunner: async () => {
|
|
2643
|
+
throw new Error('no launches in the ticket role budget')
|
|
2644
|
+
},
|
|
2645
|
+
ids: sequentialIds(),
|
|
2646
|
+
clock,
|
|
2647
|
+
})
|
|
2648
|
+
const before = requests()
|
|
2649
|
+
counter.reset()
|
|
2650
|
+
const report = await dispatcher.tick()
|
|
2651
|
+
costs.push(requests() - before)
|
|
2652
|
+
expect(report.dispatched).toBe(0)
|
|
2653
|
+
expect(report.dependencyBlocked).toBe(2)
|
|
2654
|
+
expect(
|
|
2655
|
+
report.dependencyDiagnostics.some((line) => line.endsWith('which was rejected')),
|
|
2656
|
+
).toBe(roles)
|
|
2657
|
+
expect(counter.rows).toBeLessThanOrEqual(32)
|
|
2658
|
+
// The interactive dispatcher's per-tick triage sample, exactly as it
|
|
2659
|
+
// calls it: one bounded count at most, never a listing or an event read.
|
|
2660
|
+
const listStates = Object.getOwnPropertyDescriptor(tickets, 'listStates')
|
|
2661
|
+
Object.defineProperty(tickets, 'listStates', {
|
|
2662
|
+
configurable: true,
|
|
2663
|
+
writable: true,
|
|
2664
|
+
value: async () => {
|
|
2665
|
+
throw new Error('the triage sample never lists ticket states')
|
|
2666
|
+
},
|
|
2667
|
+
})
|
|
2668
|
+
try {
|
|
2669
|
+
const sampleBefore = requests()
|
|
2670
|
+
counter.reset()
|
|
2671
|
+
const triage = await boundedStateCount(tickets, defaultTriageState(config))
|
|
2672
|
+
expect(requests() - sampleBefore).toBe(sampleRequests)
|
|
2673
|
+
expect(triage === undefined).toBe(sampleRequests === 0)
|
|
2674
|
+
expect(counter.rows).toBe(0)
|
|
2675
|
+
} finally {
|
|
2676
|
+
if (listStates === undefined) Reflect.deleteProperty(tickets, 'listStates')
|
|
2677
|
+
else Object.defineProperty(tickets, 'listStates', listStates)
|
|
2678
|
+
}
|
|
2679
|
+
// Prepare the tick's own tail, then prove an unchanged read costs zero rows.
|
|
2680
|
+
await readRepositoryFacts(store, repo)
|
|
2681
|
+
await readBuildDigests(store, repo)
|
|
2682
|
+
counter.reset()
|
|
2683
|
+
await readRepositoryFacts(store, repo)
|
|
2684
|
+
await readBuildDigests(store, repo)
|
|
2685
|
+
expect(counter.rows).toBe(0)
|
|
2686
|
+
}
|
|
2687
|
+
perTick.set(`${roles}:${length}`, costs)
|
|
2688
|
+
await store.close()
|
|
2689
|
+
}
|
|
2690
|
+
}
|
|
2691
|
+
const [baseline, ...rest] = [...perTick.values()]
|
|
2692
|
+
for (const costs of rest) expect(costs).toEqual(baseline!)
|
|
2693
|
+
return baseline!
|
|
2694
|
+
}
|
|
2695
|
+
|
|
2696
|
+
/** Urgent intake order (AUT-1027) is an in-memory partition of the one ready
|
|
2697
|
+
* listing a due scan already reads: with and without an urgent ticket present,
|
|
2698
|
+
* a quiet intake tick makes the same source calls and the same store reads, at
|
|
2699
|
+
* 100 and 100,000 repository events, and an unchanged follow-up read costs zero
|
|
2700
|
+
* rows. Returns the per-method source calls of one tick. */
|
|
2701
|
+
export async function urgentIntakeReadBudget() {
|
|
2702
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
2703
|
+
const sha = 'a'.repeat(40)
|
|
2704
|
+
const config = parseConfig(
|
|
2705
|
+
'[tickets]\nsource = "hosted"\nteamKey = "ENG"\n[verify]\nsteps = []\n[finalize]\nsteps = []\n',
|
|
2706
|
+
)
|
|
2707
|
+
const methods = ['listReady', 'get', 'dependencyStates', 'listAll'] as const
|
|
2708
|
+
const results = new Map<string, { calls: Record<string, number>[]; rows: number[] }>()
|
|
2709
|
+
for (const urgent of [false, true]) {
|
|
2710
|
+
for (const length of [100, 100_000]) {
|
|
2711
|
+
const source = new FakeTicketSource([], { createState: 'triage', doneState: 'done' })
|
|
2712
|
+
const calls: Record<string, number> = Object.fromEntries(methods.map((name) => [name, 0]))
|
|
2713
|
+
const tickets = new Proxy(source, {
|
|
2714
|
+
get(target, key) {
|
|
2715
|
+
const value = Reflect.get(target, key, target)
|
|
2716
|
+
if (typeof value !== 'function') return value
|
|
2717
|
+
return (...args: unknown[]) => {
|
|
2718
|
+
if (typeof key === 'string' && key in calls) calls[key]! += 1
|
|
2719
|
+
return value.apply(target, args)
|
|
2720
|
+
}
|
|
2721
|
+
},
|
|
2722
|
+
})
|
|
2723
|
+
// Every ready ticket is blocked by one unresolved ticket, so ticks claim nothing.
|
|
2724
|
+
const blocker = await source.create({ title: 'Unresolved blocker', body: 'Budget' })
|
|
2725
|
+
for (const [index, title] of ['N1', 'N2', 'U1'].entries()) {
|
|
2726
|
+
const ticket = await source.create({
|
|
2727
|
+
title,
|
|
2728
|
+
body: 'Budget',
|
|
2729
|
+
...(urgent && index === 2 ? { priority: 'urgent' as const } : {}),
|
|
2730
|
+
})
|
|
2731
|
+
await source.addBlocker(ticket.ref.id, blocker.ref.id)
|
|
2732
|
+
await source.transition(ticket.ref.id, 'ready')
|
|
2733
|
+
}
|
|
2734
|
+
|
|
2735
|
+
let now = 1_800_000_000_000
|
|
2736
|
+
const clock = () => new Date(now)
|
|
2737
|
+
const store = new MemoryBuildStore({ clock })
|
|
2738
|
+
const repo = `https://github.com/budget/urgent-intake-${urgent}-${length}`
|
|
2739
|
+
await store.ensureRepo(repo)
|
|
2740
|
+
for (let i = 0; i < length; i++)
|
|
2741
|
+
await store.appendRepo(repo, {
|
|
2742
|
+
actor: humanActor('budget'),
|
|
2743
|
+
type: 'dispatcher.intake-set',
|
|
2744
|
+
payload: { enabled: true },
|
|
2745
|
+
})
|
|
2746
|
+
// The one serialized reduction per key happens before the measured ticks.
|
|
2747
|
+
await readRepositoryFacts(store, repo)
|
|
2748
|
+
await readBuildDigests(store, repo)
|
|
2749
|
+
const counter = memoryRepositoryReadCounter(store, repo)
|
|
2750
|
+
const perTick: Record<string, number>[] = []
|
|
2751
|
+
const rows: number[] = []
|
|
2752
|
+
for (let tick = 0; tick < 2; tick++) {
|
|
2753
|
+
now += 60_000
|
|
2754
|
+
const forge = new FakeForge()
|
|
2755
|
+
forge.seedBranch('main', sha)
|
|
2756
|
+
const dispatcher = new Dispatcher({
|
|
2757
|
+
store,
|
|
2758
|
+
tickets,
|
|
2759
|
+
workspaces: new FakeWorkspaceProvider({
|
|
2760
|
+
root: '/urgent-intake-budget',
|
|
2761
|
+
mode: 'logical',
|
|
2762
|
+
base: { source: 'remote', sha },
|
|
2763
|
+
}),
|
|
2764
|
+
forge,
|
|
2765
|
+
config,
|
|
2766
|
+
repo,
|
|
2767
|
+
exec: async () => ({ stdout: `${sha}\trefs/heads/main\n`, stderr: '', exitCode: 0 }),
|
|
2768
|
+
launchRunner: async () => {
|
|
2769
|
+
throw new Error('no launches in the urgent intake budget')
|
|
2770
|
+
},
|
|
2771
|
+
ids: sequentialIds(),
|
|
2772
|
+
clock,
|
|
2773
|
+
})
|
|
2774
|
+
const before = { ...calls }
|
|
2775
|
+
counter.reset()
|
|
2776
|
+
const report = await dispatcher.tick()
|
|
2777
|
+
perTick.push(
|
|
2778
|
+
Object.fromEntries(methods.map((name) => [name, calls[name]! - before[name]!])),
|
|
2779
|
+
)
|
|
2780
|
+
rows.push(counter.rows)
|
|
2781
|
+
expect(report.dispatched).toBe(0)
|
|
2782
|
+
expect(report.dependencyBlocked).toBe(3)
|
|
2783
|
+
expect(counter.rows).toBeLessThanOrEqual(32)
|
|
2784
|
+
// Prepare the tick's own tail, then prove an unchanged read costs zero rows.
|
|
2785
|
+
await readRepositoryFacts(store, repo)
|
|
2786
|
+
await readBuildDigests(store, repo)
|
|
2787
|
+
counter.reset()
|
|
2788
|
+
await readRepositoryFacts(store, repo)
|
|
2789
|
+
await readBuildDigests(store, repo)
|
|
2790
|
+
expect(counter.rows).toBe(0)
|
|
2791
|
+
}
|
|
2792
|
+
results.set(`${urgent}:${length}`, { calls: perTick, rows })
|
|
2793
|
+
await store.close()
|
|
2794
|
+
}
|
|
2795
|
+
}
|
|
2796
|
+
const [baseline, ...rest] = [...results.values()]
|
|
2797
|
+
for (const result of rest) expect(result).toEqual(baseline!)
|
|
2798
|
+
return baseline!.calls[0]!
|
|
2799
|
+
}
|
|
2800
|
+
|
|
2801
|
+
/** Native identity maintenance (SPEC §15.7) adds one forge identity read per
|
|
2802
|
+
* armed, eligible poll and nothing else: a fresh dispatcher's quiet
|
|
2803
|
+
* maintenance tick reads no history, spends exactly the store reads of the same
|
|
2804
|
+
* tick with the native block skipped, appends nothing, and costs the same at
|
|
2805
|
+
* 100 and 10,000 events. */
|
|
2806
|
+
export async function nativeMaintenanceReadBudget(opts: {
|
|
2807
|
+
store: import('../store/memory').MemoryBuildStore
|
|
2808
|
+
slug: string
|
|
2809
|
+
forge: FakeForge
|
|
2810
|
+
tick: () => Promise<unknown>
|
|
2811
|
+
}) {
|
|
2812
|
+
const { store, slug, forge } = opts
|
|
2813
|
+
const events = buildEventRows(store, slug)
|
|
2814
|
+
let baseline: number[] | undefined
|
|
2815
|
+
for (const length of [100, 10_000]) {
|
|
2816
|
+
let filler = 0
|
|
2817
|
+
while (events.length < length)
|
|
2818
|
+
await store.append(slug, {
|
|
2819
|
+
actor: KERNEL,
|
|
2820
|
+
type: 'observation.recorded',
|
|
2821
|
+
payload: { id: `obs_budget_${length}_${filler++}`, kind: 'followup', summary: 'filler' },
|
|
2822
|
+
})
|
|
2823
|
+
// Warm the saved reduced values past the filler before measuring.
|
|
2824
|
+
await opts.tick()
|
|
2825
|
+
const boundary = events.at(-1)!.seq
|
|
2826
|
+
const metrics = { historicalRows: 0, tailRows: 0 }
|
|
2827
|
+
let calls = 0
|
|
2828
|
+
const getReduced = store.getReducerValue.bind(store)
|
|
2829
|
+
store.getReducerValue = async (...args) => {
|
|
2830
|
+
calls++
|
|
2831
|
+
return getReduced(...args)
|
|
2832
|
+
}
|
|
2833
|
+
const restore = instrumentBuildRows(store, slug, () => boundary, metrics)
|
|
2834
|
+
const getPrState = forge.getPrState.bind(forge)
|
|
2835
|
+
const measure = async () => {
|
|
2836
|
+
metrics.historicalRows = metrics.tailRows = calls = 0
|
|
2837
|
+
const reads = forge.identityReads.length
|
|
2838
|
+
await opts.tick()
|
|
2839
|
+
expect(metrics.historicalRows).toBe(0)
|
|
2840
|
+
return {
|
|
2841
|
+
rows: metrics.tailRows,
|
|
2842
|
+
calls,
|
|
2843
|
+
identityReads: forge.identityReads.length - reads,
|
|
2844
|
+
}
|
|
2845
|
+
}
|
|
2846
|
+
try {
|
|
2847
|
+
const maintenance = await measure()
|
|
2848
|
+
forge.getPrState = async (...args) => {
|
|
2849
|
+
const { nativeAutoMerge: _omitted, ...state } = (await getPrState(...args)) as PrStateLike
|
|
2850
|
+
return state
|
|
2851
|
+
}
|
|
2852
|
+
const skipped = await measure()
|
|
2853
|
+
expect(maintenance.identityReads).toBe(1)
|
|
2854
|
+
expect(skipped.identityReads).toBe(0)
|
|
2855
|
+
expect(maintenance.calls).toBe(skipped.calls)
|
|
2856
|
+
expect(maintenance.rows).toBe(skipped.rows)
|
|
2857
|
+
expect(events.at(-1)!.seq).toBe(boundary)
|
|
2858
|
+
const costs = [maintenance.rows, maintenance.calls]
|
|
2859
|
+
if (baseline) expect(costs).toEqual(baseline)
|
|
2860
|
+
baseline = costs
|
|
2861
|
+
} finally {
|
|
2862
|
+
restore()
|
|
2863
|
+
store.getReducerValue = getReduced
|
|
2864
|
+
Reflect.deleteProperty(forge, 'getPrState')
|
|
2865
|
+
}
|
|
2866
|
+
}
|
|
2867
|
+
}
|
|
2868
|
+
|
|
2869
|
+
type PrStateLike = Awaited<ReturnType<FakeForge['getPrState']>> & { nativeAutoMerge?: boolean }
|
|
2870
|
+
/** The bounded replaced-head record rides in the saved build facts: a warm
|
|
2871
|
+
* read touches no event rows, and its size is fixed at any rewrite count. */
|
|
2872
|
+
export async function replacedHeadsReadBudget(opts: {
|
|
2873
|
+
store: BuildStore
|
|
2874
|
+
costs: ReducedReadCosts
|
|
2875
|
+
fresh: () => Promise<BuildStore>
|
|
2876
|
+
}) {
|
|
2877
|
+
const { store, costs } = opts
|
|
2878
|
+
const node = 'replaced-heads-budget'
|
|
2879
|
+
const oid = (n: number) => n.toString(16).padStart(40, '0')
|
|
2880
|
+
await store.createBuild({ slug: node, repo, branch: 'ab-node/replaced-heads-budget' })
|
|
2881
|
+
const log = nodeRestackLog()
|
|
2882
|
+
for (const event of log.slice(0, 2)) await store.append(node, event)
|
|
2883
|
+
const replaced: string[] = []
|
|
2884
|
+
let appended = 0
|
|
2885
|
+
let transaction = 0
|
|
2886
|
+
const sizes = new Map<number, number>()
|
|
2887
|
+
// Both journal lengths hold more rewrites than the record's capacity.
|
|
2888
|
+
for (const length of [1_000, 10_000]) {
|
|
2889
|
+
while (appended < length) {
|
|
2890
|
+
const id = transaction++
|
|
2891
|
+
for (const event of log.slice(2)) {
|
|
2892
|
+
const payload = JSON.parse(
|
|
2893
|
+
JSON.stringify(event.payload)
|
|
2894
|
+
.replaceAll('node-tx', `rewrite-${id}`)
|
|
2895
|
+
.replaceAll('a'.repeat(40), oid(id * 2 + 1))
|
|
2896
|
+
.replaceAll('c'.repeat(40), oid(id * 2 + 2)),
|
|
2897
|
+
)
|
|
2898
|
+
await store.append(node, { actor: event.actor, type: event.type, payload })
|
|
2899
|
+
appended++
|
|
2900
|
+
}
|
|
2901
|
+
replaced.push(oid(id * 2 + 1))
|
|
2902
|
+
}
|
|
2903
|
+
expect(replaced.length).toBeGreaterThan(REPLACED_HEADS_CAP)
|
|
2904
|
+
for (const reader of [store, await opts.fresh()]) {
|
|
2905
|
+
await readBuildFacts(reader, node)
|
|
2906
|
+
costs.events = costs.metadata = costs.bytes = 0
|
|
2907
|
+
const facts = (await readBuildFacts(reader, node)).value
|
|
2908
|
+
expect(costs.events).toBe(0)
|
|
2909
|
+
expect(facts.replacedHeads).toEqual(replaced.slice(-REPLACED_HEADS_CAP))
|
|
2910
|
+
const size = JSON.stringify(facts.replacedHeads).length
|
|
2911
|
+
if (length === 1_000) sizes.set(0, size)
|
|
2912
|
+
else expect(size).toBe(sizes.get(0)!)
|
|
2913
|
+
}
|
|
2914
|
+
}
|
|
2915
|
+
}
|
|
2916
|
+
|
|
2917
|
+
/** A repository with no dispatcher run answers its dashboard poll from the
|
|
2918
|
+
* saved reduction: zero event rows once warm, at any journal length. */
|
|
2919
|
+
export async function noDispatcherRunDashboardBudget() {
|
|
2920
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
2921
|
+
for (const size of [10, 300]) {
|
|
2922
|
+
const store = new MemoryBuildStore({ clock: () => new Date(1000) })
|
|
2923
|
+
await store.ensureRepo(repo)
|
|
2924
|
+
const toggle = async (count: number) => {
|
|
2925
|
+
for (let i = 0; i < count; i++)
|
|
2926
|
+
await store.appendRepo(repo, {
|
|
2927
|
+
actor: humanActor('operator'),
|
|
2928
|
+
type: 'dispatcher.intake-set',
|
|
2929
|
+
payload: { enabled: i % 2 === 1 },
|
|
2930
|
+
})
|
|
2931
|
+
}
|
|
2932
|
+
await toggle(size)
|
|
2933
|
+
const counter = memoryRepositoryReadCounter(store, repo)
|
|
2934
|
+
const poll = () => getOperatorDashboard({ store, repo, clock: () => new Date(1000) })
|
|
2935
|
+
const warm = await poll()
|
|
2936
|
+
expect(warm.model.configuration).toBe('no-dispatcher-run')
|
|
2937
|
+
counter.reset()
|
|
2938
|
+
for (let i = 0; i < 3; i++) await poll()
|
|
2939
|
+
expect(counter.rows).toBe(0)
|
|
2940
|
+
// New facts advance the saved value by their delta only.
|
|
2941
|
+
await toggle(4)
|
|
2942
|
+
counter.reset()
|
|
2943
|
+
expect((await poll()).settingsHeader.intake).toBe(true)
|
|
2944
|
+
expect(counter.rows).toBeLessThanOrEqual(4)
|
|
2945
|
+
counter.reset()
|
|
2946
|
+
await poll()
|
|
2947
|
+
expect(counter.rows).toBe(0)
|
|
2948
|
+
}
|
|
2949
|
+
}
|