@defrex/autobuild 1.5.0 → 1.7.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 +192 -24
- package/docs/agent-runtimes.md +1 -1
- package/docs/answering-blocked-builds.md +7 -4
- package/docs/architecture.md +100 -32
- package/docs/configuration-overview.md +10 -0
- package/docs/configuration.md +340 -10
- package/docs/dispatcher.md +2 -2
- package/docs/forges.md +1 -0
- package/docs/glossary.md +1 -1
- package/docs/operating.md +1 -1
- package/docs/operator-api.md +33 -10
- package/docs/operator-surfaces.md +6 -3
- package/docs/plugin-authoring.md +48 -6
- package/docs/remote-store-protocol.md +33 -10
- package/docs/restacking.md +16 -7
- package/docs/ticket-sources.md +34 -6
- package/docs/tickets.md +7 -1
- package/docs/troubleshooting.md +1 -1
- package/docs/workspaces.md +1 -1
- package/package.json +3 -3
- package/packages/core/src/cli/attention.ts +3 -0
- package/packages/core/src/cli/binary-direct.ts +1 -0
- package/packages/core/src/cli/dashboard/model.ts +14 -4
- package/packages/core/src/cli/dashboard/poll.ts +14 -0
- package/packages/core/src/cli/dashboard/render.ts +3 -0
- package/packages/core/src/cli/dispatch-frontend.ts +10 -14
- package/packages/core/src/cli/dispatch-preflight.ts +5 -1
- package/packages/core/src/cli/dispatch-repository-feed.ts +145 -109
- 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 +377 -101
- package/packages/core/src/cli/help.ts +15 -6
- package/packages/core/src/cli/init-validation.ts +14 -1
- package/packages/core/src/cli/repo-lease.ts +225 -0
- package/packages/core/src/cli/repository-status.ts +40 -3
- package/packages/core/src/cli/status.ts +21 -13
- package/packages/core/src/cli/ticket.ts +22 -4
- package/packages/core/src/cli/wait.ts +4 -1
- package/packages/core/src/cli/watch.ts +17 -4
- package/packages/core/src/config/live.ts +4 -0
- package/packages/core/src/config/profiles.ts +96 -0
- package/packages/core/src/config/ready-assignee.ts +43 -11
- package/packages/core/src/config/roles.ts +33 -10
- package/packages/core/src/config/schema.ts +204 -26
- package/packages/core/src/events/catalog.ts +2 -0
- package/packages/core/src/events/compatibility.ts +3 -1
- package/packages/core/src/events/forge-degradation-policy.ts +16 -2
- package/packages/core/src/events/payloads.ts +23 -0
- package/packages/core/src/events/policy.ts +3 -0
- package/packages/core/src/events/repository.ts +19 -0
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +267 -352
- package/packages/core/src/kernel/build-creation.ts +29 -0
- package/packages/core/src/kernel/dispatch-capacity.ts +134 -30
- package/packages/core/src/kernel/engine.ts +13 -6
- package/packages/core/src/kernel/forge-health.ts +47 -0
- package/packages/core/src/kernel/generators/build-log.ts +9 -0
- package/packages/core/src/kernel/guarded-forge.ts +76 -18
- package/packages/core/src/kernel/incremental-fixtures.ts +1 -0
- package/packages/core/src/kernel/janitor-failure.ts +85 -5
- 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-landing.ts +2 -1
- package/packages/core/src/kernel/node-parent.ts +2 -0
- package/packages/core/src/kernel/read-facts.ts +9 -1
- package/packages/core/src/kernel/reducer-registry.ts +6 -1
- package/packages/core/src/kernel/reducer.ts +75 -4
- package/packages/core/src/kernel/ticket-preparation.ts +15 -8
- package/packages/core/src/operator/protocol.ts +10 -0
- package/packages/core/src/operator/query.ts +16 -13
- package/packages/core/src/operator/registry.ts +25 -5
- package/packages/core/src/operator/sandbox-host.ts +3 -0
- package/packages/core/src/operator/tickets.ts +15 -3
- package/packages/core/src/plugin-sdk/index.ts +4 -0
- package/packages/core/src/ports/forge/create.ts +6 -0
- package/packages/core/src/ports/forge/github-transport.ts +40 -3
- package/packages/core/src/ports/forge/github.ts +12 -1
- package/packages/core/src/ports/forge/workspace-ancestry.ts +60 -0
- package/packages/core/src/ports/forge-failure.ts +31 -2
- package/packages/core/src/ports/runner/routing.ts +66 -5
- package/packages/core/src/ports/tickets/assignees.ts +54 -0
- package/packages/core/src/ports/tickets/contract.ts +164 -4
- package/packages/core/src/ports/tickets/create.ts +35 -7
- package/packages/core/src/ports/tickets/github-fake.ts +18 -2
- package/packages/core/src/ports/tickets/github.ts +247 -29
- package/packages/core/src/ports/tickets/hosted-index.ts +1 -0
- package/packages/core/src/ports/tickets/operations.ts +6 -1
- package/packages/core/src/ports/tickets/tree.ts +12 -2
- package/packages/core/src/ports/tickets/update.ts +6 -2
- package/packages/core/src/ports/types.ts +37 -3
- package/packages/core/src/ports/workspace/commit-preservation.ts +28 -12
- package/packages/core/src/ports/workspace/git-worktree.ts +3 -1
- package/packages/core/src/ports/workspace/harvest-execution.ts +4 -2
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +12 -0
- package/packages/core/src/processes/build-child.ts +28 -7
- package/packages/core/src/processes/build-execution-state.ts +4 -1
- package/packages/core/src/processes/build-runner.ts +17 -2
- package/packages/core/src/processes/dispatcher.ts +329 -59
- package/packages/core/src/processes/execution-no-progress.ts +2 -0
- package/packages/core/src/processes/harvest-child.ts +8 -2
- package/packages/core/src/processes/harvest-execution-state.ts +104 -0
- package/packages/core/src/processes/harvest-runner.ts +251 -17
- package/packages/core/src/processes/repo-view.ts +2 -0
- package/packages/core/src/scenarios/harness.ts +160 -36
- package/packages/core/src/store/reduced-reads.ts +10 -0
- package/packages/core/src/store/reducer-value-shapes.json +3339 -2898
- package/packages/core/src/store/remote/client.ts +21 -8
- package/packages/core/src/store/remote/index.ts +4 -0
- package/packages/core/src/store/remote/protocol.ts +7 -0
- package/packages/core/src/store/remote/released-clients.json +22 -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/1.7.0.json +27366 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +4 -0
- package/packages/core/src/store/repo-state-events.ts +1 -0
- package/packages/core/src/store/types.ts +11 -0
- package/packages/core/src/testing/dispatch-read-budget.ts +84 -58
- package/packages/core/src/testing/index.ts +2 -0
- package/packages/core/src/testing/reduced-read-budget.ts +411 -11
- package/skills/guide/SKILL.md +166 -35
- package/skills/guide/references/operator-api.md +33 -10
- package/skills/guide/references/plugin-authoring.md +48 -6
- package/skills/guide/references/remote-store-protocol.md +33 -10
- package/skills/guide/references/restacking.md +16 -7
- package/skills/operate/SKILL.md +79 -14
- package/skills/tickets/SKILL.md +22 -4
- package/templates/hosted-service/package.json +2 -2
|
@@ -9,6 +9,7 @@ import { REPLACED_HEADS_CAP } from '../kernel/read-facts'
|
|
|
9
9
|
import { observeTarget } from '../kernel/target-observation'
|
|
10
10
|
import { autoMergeDeferralObservation } from '../kernel/auto-merge'
|
|
11
11
|
import { mkdtemp, writeFile, rm } from 'node:fs/promises'
|
|
12
|
+
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
12
13
|
import { tmpdir } from 'node:os'
|
|
13
14
|
import { join } from 'node:path'
|
|
14
15
|
import { DashboardBuildPollCache } from '../cli/dashboard/poll'
|
|
@@ -43,7 +44,9 @@ import {
|
|
|
43
44
|
readBuildDigests,
|
|
44
45
|
readDispatcherRunFacts,
|
|
45
46
|
readOpenTick,
|
|
47
|
+
readHostedHarvestAuthority,
|
|
46
48
|
} from '../store/reduced-reads'
|
|
49
|
+
import { decideHostedHarvestAuthority } from '../processes/harvest-execution-state'
|
|
47
50
|
import { RepoViewStore } from '../processes/repo-view'
|
|
48
51
|
import { settlePendingPublication } from '../cli/publication-settlement'
|
|
49
52
|
import {
|
|
@@ -277,6 +280,20 @@ export async function reducedReadBudget(opts: {
|
|
|
277
280
|
const factsBytes = Buffer.byteLength(JSON.stringify(stableFacts))
|
|
278
281
|
if (repositoryBytes !== undefined) expect(factsBytes).toBeLessThan(repositoryBytes + 512)
|
|
279
282
|
repositoryBytes = factsBytes
|
|
283
|
+
// A credential limit seen outside the dispatcher joins the saved
|
|
284
|
+
// repository value; it adds no read to the guarded-call health check.
|
|
285
|
+
await store.appendRepo(repo, {
|
|
286
|
+
actor: KERNEL,
|
|
287
|
+
type: 'forge.credential-limited',
|
|
288
|
+
payload: {
|
|
289
|
+
forge: 'github',
|
|
290
|
+
process: 'build-runner budget',
|
|
291
|
+
credential: 'unauthenticated',
|
|
292
|
+
missingCredential: 'GITHUB_TOKEN and GH_TOKEN are unset',
|
|
293
|
+
message: 'API rate limit exceeded',
|
|
294
|
+
resetAt: new Date(Date.parse('2026-01-01T00:00:00.000Z') + length * 1000).toISOString(),
|
|
295
|
+
},
|
|
296
|
+
})
|
|
280
297
|
// Warm persisted values independently of any consumer instance.
|
|
281
298
|
await readBuildStreamSeed(store, slug)
|
|
282
299
|
await readBuildFacts(store, slug)
|
|
@@ -341,11 +358,22 @@ export async function reducedReadBudget(opts: {
|
|
|
341
358
|
actor: KERNEL,
|
|
342
359
|
}),
|
|
343
360
|
).toBe('unchanged')
|
|
344
|
-
|
|
361
|
+
// Latest per (forge, process): repeated limits replace, never accumulate.
|
|
362
|
+
expect((await readRepositoryFacts(cold, repo)).value.forgeCredentialLimits).toHaveLength(1)
|
|
345
363
|
}
|
|
346
364
|
expect(costs.events).toBe(0)
|
|
347
365
|
expect(costs.metadata).toBeLessThan(operations * 20)
|
|
348
366
|
}
|
|
367
|
+
// The guarded-call health check stays clear and flat per call beside
|
|
368
|
+
// a saved credential limit.
|
|
369
|
+
for (const operations of [1, 8]) {
|
|
370
|
+
reset()
|
|
371
|
+
for (let n = 0; n < operations; n++) {
|
|
372
|
+
expect(await readForgeHealth(cold, repo)).toBeUndefined()
|
|
373
|
+
}
|
|
374
|
+
expect(costs.events).toBe(0)
|
|
375
|
+
expect(costs.metadata).toBeLessThan(operations * 10)
|
|
376
|
+
}
|
|
349
377
|
// Account holds survive fresh consumers and reconcile without idle journal reads or writes.
|
|
350
378
|
const missing = missingAccountCredentials(
|
|
351
379
|
{ billing: { kind: 'claude-subscription', credentialEnv: 'BILLING_TOKEN' } },
|
|
@@ -1383,6 +1411,7 @@ export async function parkedSweepReadBudget(opts: {
|
|
|
1383
1411
|
},
|
|
1384
1412
|
})
|
|
1385
1413
|
let seeded = 0
|
|
1414
|
+
const idleRequests: Record<string, number>[] = []
|
|
1386
1415
|
for (const length of [100, 100_000]) {
|
|
1387
1416
|
for (; seeded < length; seeded++) {
|
|
1388
1417
|
await store.append(slugs[0]!, {
|
|
@@ -1469,6 +1498,31 @@ export async function parkedSweepReadBudget(opts: {
|
|
|
1469
1498
|
expect(metrics.bodies).toBe(slugs.length)
|
|
1470
1499
|
expect(blobReads).toBe(slugs.length)
|
|
1471
1500
|
expect(metrics.historicalRows).toBe(0)
|
|
1501
|
+
// Idle admission ticks over settled parked builds: capacity adds no
|
|
1502
|
+
// recurring read and writes nothing, at either history length.
|
|
1503
|
+
reset()
|
|
1504
|
+
await dispatcher.tick({ acceptNewWork: false })
|
|
1505
|
+
const baseline = { meta: metrics.meta, bodies: metrics.bodies }
|
|
1506
|
+
const idle = opts.dispatcher()
|
|
1507
|
+
opts.advance()
|
|
1508
|
+
// Warm intake's own projections and persist their snapshots.
|
|
1509
|
+
for (const _ of [0, 1]) {
|
|
1510
|
+
await idle.tick({ acceptNewWork: true })
|
|
1511
|
+
opts.advance()
|
|
1512
|
+
}
|
|
1513
|
+
for (const _ of [0, 1]) {
|
|
1514
|
+
opts.advance()
|
|
1515
|
+
reset()
|
|
1516
|
+
const requests = await countStoreRequests(store, () =>
|
|
1517
|
+
idle.tick({ acceptNewWork: true }).then(() => undefined),
|
|
1518
|
+
)
|
|
1519
|
+
expect(requests.append ?? 0).toBe(0)
|
|
1520
|
+
expect(requests.appendIfCurrent ?? 0).toBe(0)
|
|
1521
|
+
expect(metrics.historicalRows).toBe(0)
|
|
1522
|
+
expect({ meta: metrics.meta, bodies: metrics.bodies }).toEqual(baseline)
|
|
1523
|
+
if (idleRequests.length) expect(requests).toEqual(idleRequests[0]!)
|
|
1524
|
+
idleRequests.push(requests)
|
|
1525
|
+
}
|
|
1472
1526
|
console.log('parked sweep read budget', {
|
|
1473
1527
|
history: length,
|
|
1474
1528
|
builds: slugs.length,
|
|
@@ -1483,6 +1537,35 @@ export async function parkedSweepReadBudget(opts: {
|
|
|
1483
1537
|
}
|
|
1484
1538
|
}
|
|
1485
1539
|
|
|
1540
|
+
/** Count every MemoryBuildStore method call made while `run` executes. */
|
|
1541
|
+
async function countStoreRequests(
|
|
1542
|
+
store: import('../store/memory').MemoryBuildStore,
|
|
1543
|
+
run: () => Promise<void>,
|
|
1544
|
+
): Promise<Record<string, number>> {
|
|
1545
|
+
const counts: Record<string, number> = {}
|
|
1546
|
+
const names = Object.getOwnPropertyNames(Object.getPrototypeOf(store)).filter(
|
|
1547
|
+
(name) => name !== 'constructor' && typeof Reflect.get(store, name) === 'function',
|
|
1548
|
+
)
|
|
1549
|
+
const restore: (() => void)[] = []
|
|
1550
|
+
for (const name of names) {
|
|
1551
|
+
const own = Object.getOwnPropertyDescriptor(store, name)
|
|
1552
|
+
const original = Reflect.get(store, name) as (...args: unknown[]) => unknown
|
|
1553
|
+
Reflect.set(store, name, (...args: unknown[]) => {
|
|
1554
|
+
counts[name] = (counts[name] ?? 0) + 1
|
|
1555
|
+
return original.apply(store, args)
|
|
1556
|
+
})
|
|
1557
|
+
restore.push(() =>
|
|
1558
|
+
own ? Object.defineProperty(store, name, own) : Reflect.deleteProperty(store, name),
|
|
1559
|
+
)
|
|
1560
|
+
}
|
|
1561
|
+
try {
|
|
1562
|
+
await run()
|
|
1563
|
+
} finally {
|
|
1564
|
+
for (const undo of restore) undo()
|
|
1565
|
+
}
|
|
1566
|
+
return counts
|
|
1567
|
+
}
|
|
1568
|
+
|
|
1486
1569
|
/** Append filler facts to one build until its log holds `length` events. */
|
|
1487
1570
|
async function seedBuildFiller(
|
|
1488
1571
|
store: import('../store/memory').MemoryBuildStore,
|
|
@@ -1724,7 +1807,13 @@ export async function provisionContinuationGuardReadBudget(opts: {
|
|
|
1724
1807
|
}
|
|
1725
1808
|
|
|
1726
1809
|
/** In-memory history seeding for preparation budgets; never used as a recurring read. */
|
|
1727
|
-
export async function seedPreparationHistory(
|
|
1810
|
+
export async function seedPreparationHistory(
|
|
1811
|
+
store: BuildStore,
|
|
1812
|
+
repo: string,
|
|
1813
|
+
facts: number,
|
|
1814
|
+
/** Record the pending attempt's creation identity, keyed when `creationKey` is set. */
|
|
1815
|
+
creation?: { slug: string; creationKey?: string },
|
|
1816
|
+
) {
|
|
1728
1817
|
await store.ensureRepo(repo)
|
|
1729
1818
|
for (let i = 0; i < facts / 2; i++) {
|
|
1730
1819
|
const ticket = { source: 'fake', id: `old-${i}` }
|
|
@@ -1750,6 +1839,12 @@ export async function seedPreparationHistory(store: BuildStore, repo: string, fa
|
|
|
1750
1839
|
claimedState: 'Doing',
|
|
1751
1840
|
},
|
|
1752
1841
|
})
|
|
1842
|
+
if (creation)
|
|
1843
|
+
await store.appendRepo(repo, {
|
|
1844
|
+
actor: DISPATCHER,
|
|
1845
|
+
type: 'ticket-preparation.creation-selected',
|
|
1846
|
+
payload: { attempt: 'pending', ticket: { source: 'fake', id: 'pending' }, ...creation },
|
|
1847
|
+
})
|
|
1753
1848
|
await store.appendRepo(repo, {
|
|
1754
1849
|
actor: DISPATCHER,
|
|
1755
1850
|
type: 'ticket-preparation.recovery-failed',
|
|
@@ -2121,21 +2216,39 @@ export async function kernelGitOutageReadBudget(opts: {
|
|
|
2121
2216
|
}
|
|
2122
2217
|
}
|
|
2123
2218
|
|
|
2124
|
-
/** Expired sampled owners resolve once through exact persisted run values
|
|
2219
|
+
/** Expired sampled owners resolve once through exact persisted run values;
|
|
2220
|
+
* historical abandoned preparations never replay and a new one reports once. */
|
|
2125
2221
|
export async function stoppedOwnerWatchReadBudget() {
|
|
2126
2222
|
const { MemoryBuildStore } = await import('../store/memory')
|
|
2127
2223
|
const { manualClock } = await import('./fixed')
|
|
2128
2224
|
let previousBytes: number | undefined
|
|
2225
|
+
const abandon = (store: BuildStore, attempt: string) =>
|
|
2226
|
+
store.appendRepo(repo, {
|
|
2227
|
+
actor: DISPATCHER,
|
|
2228
|
+
type: 'ticket-preparation.resolved',
|
|
2229
|
+
payload: {
|
|
2230
|
+
attempt,
|
|
2231
|
+
ticket: { source: 'fake', id: attempt },
|
|
2232
|
+
outcome: 'abandoned',
|
|
2233
|
+
reason: 'Ticket no longer exists; ticket unchanged.',
|
|
2234
|
+
claimed: false,
|
|
2235
|
+
},
|
|
2236
|
+
})
|
|
2129
2237
|
for (const length of [100, 100_000]) {
|
|
2130
2238
|
const clock = manualClock()
|
|
2131
2239
|
const store = new MemoryBuildStore({ clock })
|
|
2132
2240
|
await store.ensureRepo(repo)
|
|
2133
|
-
for (let i = 0; i < length; i++)
|
|
2241
|
+
for (let i = 0; i < length; i++) {
|
|
2242
|
+
if (i % 1000 === 50) {
|
|
2243
|
+
await abandon(store, `historical-${i}`)
|
|
2244
|
+
continue
|
|
2245
|
+
}
|
|
2134
2246
|
await store.appendRepo(repo, {
|
|
2135
2247
|
actor: humanActor('human'),
|
|
2136
2248
|
type: 'dispatcher.intake-set',
|
|
2137
2249
|
payload: { enabled: true },
|
|
2138
2250
|
})
|
|
2251
|
+
}
|
|
2139
2252
|
const start = async (run: string) => {
|
|
2140
2253
|
await store.appendRepo(repo, {
|
|
2141
2254
|
actor: DISPATCHER,
|
|
@@ -2191,6 +2304,7 @@ export async function stoppedOwnerWatchReadBudget() {
|
|
|
2191
2304
|
await stop('B')
|
|
2192
2305
|
await start('C')
|
|
2193
2306
|
}
|
|
2307
|
+
if (tick === 3) await abandon(store, 'fresh')
|
|
2194
2308
|
if (tick === 6) {
|
|
2195
2309
|
counter.reset()
|
|
2196
2310
|
quietCalls = counter.reducedCalls
|
|
@@ -2203,6 +2317,12 @@ export async function stoppedOwnerWatchReadBudget() {
|
|
|
2203
2317
|
.filter((r) => r.observation)
|
|
2204
2318
|
.map((r) => r.observation.run),
|
|
2205
2319
|
).toEqual(['C'])
|
|
2320
|
+
expect(
|
|
2321
|
+
output
|
|
2322
|
+
.map((line) => JSON.parse(line))
|
|
2323
|
+
.filter((r) => r.event?.type === 'ticket-preparation.resolved')
|
|
2324
|
+
.map((r) => r.event.payload.attempt),
|
|
2325
|
+
).toEqual(['fresh'])
|
|
2206
2326
|
expect(counter.rows).toBe(0)
|
|
2207
2327
|
expect(counter.reducedCalls - quietCalls).toBeLessThan(20)
|
|
2208
2328
|
await readDispatcherRunFacts(store, repo, 'missing')
|
|
@@ -2701,12 +2821,22 @@ export async function ticketRoleTickBudget(
|
|
|
2701
2821
|
export async function urgentIntakeReadBudget() {
|
|
2702
2822
|
const { MemoryBuildStore } = await import('../store/memory')
|
|
2703
2823
|
const sha = 'a'.repeat(40)
|
|
2704
|
-
const
|
|
2705
|
-
'[tickets]\nsource = "hosted"\nteamKey = "ENG"\n[verify]\nsteps = []\n[finalize]\nsteps = []\n'
|
|
2706
|
-
|
|
2824
|
+
const plain =
|
|
2825
|
+
'[tickets]\nsource = "hosted"\nteamKey = "ENG"\n[verify]\nsteps = []\n[finalize]\nsteps = []\n'
|
|
2826
|
+
// Profile selection is pure label matching over the listing the scan
|
|
2827
|
+
// already holds (SPEC §9): one selected and one conflicting ticket must
|
|
2828
|
+
// cost no extra source request or store row.
|
|
2829
|
+
const profiled = `${plain}[profiles.deep]\nlabel = "deep"\n[profiles.cheap]\nlabel = "cheap"\n`
|
|
2707
2830
|
const methods = ['listReady', 'get', 'dependencyStates', 'listAll'] as const
|
|
2708
2831
|
const results = new Map<string, { calls: Record<string, number>[]; rows: number[] }>()
|
|
2709
|
-
|
|
2832
|
+
const profileResults = new Map<string, { calls: Record<string, number>[]; rows: number[] }>()
|
|
2833
|
+
for (const [urgent, profiles] of [
|
|
2834
|
+
[false, false],
|
|
2835
|
+
[true, false],
|
|
2836
|
+
[false, true],
|
|
2837
|
+
[true, true],
|
|
2838
|
+
] as const) {
|
|
2839
|
+
const config = parseConfig(profiles ? profiled : plain)
|
|
2710
2840
|
for (const length of [100, 100_000]) {
|
|
2711
2841
|
const source = new FakeTicketSource([], { createState: 'triage', doneState: 'done' })
|
|
2712
2842
|
const calls: Record<string, number> = Object.fromEntries(methods.map((name) => [name, 0]))
|
|
@@ -2727,6 +2857,9 @@ export async function urgentIntakeReadBudget() {
|
|
|
2727
2857
|
title,
|
|
2728
2858
|
body: 'Budget',
|
|
2729
2859
|
...(urgent && index === 2 ? { priority: 'urgent' as const } : {}),
|
|
2860
|
+
...(profiles
|
|
2861
|
+
? { labels: index === 0 ? ['deep'] : index === 1 ? ['deep', 'cheap'] : [] }
|
|
2862
|
+
: {}),
|
|
2730
2863
|
})
|
|
2731
2864
|
await source.addBlocker(ticket.ref.id, blocker.ref.id)
|
|
2732
2865
|
await source.transition(ticket.ref.id, 'ready')
|
|
@@ -2735,7 +2868,7 @@ export async function urgentIntakeReadBudget() {
|
|
|
2735
2868
|
let now = 1_800_000_000_000
|
|
2736
2869
|
const clock = () => new Date(now)
|
|
2737
2870
|
const store = new MemoryBuildStore({ clock })
|
|
2738
|
-
const repo = `https://github.com/budget/urgent-intake-${urgent}-${length}`
|
|
2871
|
+
const repo = `https://github.com/budget/urgent-intake-${urgent}-${profiles}-${length}`
|
|
2739
2872
|
await store.ensureRepo(repo)
|
|
2740
2873
|
for (let i = 0; i < length; i++)
|
|
2741
2874
|
await store.appendRepo(repo, {
|
|
@@ -2779,7 +2912,9 @@ export async function urgentIntakeReadBudget() {
|
|
|
2779
2912
|
)
|
|
2780
2913
|
rows.push(counter.rows)
|
|
2781
2914
|
expect(report.dispatched).toBe(0)
|
|
2782
|
-
|
|
2915
|
+
// A conflicting ticket is withheld before dependency checks.
|
|
2916
|
+
expect(report.dependencyBlocked).toBe(profiles ? 2 : 3)
|
|
2917
|
+
expect(report.invalidTickets).toBe(profiles ? 1 : 0)
|
|
2783
2918
|
expect(counter.rows).toBeLessThanOrEqual(32)
|
|
2784
2919
|
// Prepare the tick's own tail, then prove an unchanged read costs zero rows.
|
|
2785
2920
|
await readRepositoryFacts(store, repo)
|
|
@@ -2789,12 +2924,23 @@ export async function urgentIntakeReadBudget() {
|
|
|
2789
2924
|
await readBuildDigests(store, repo)
|
|
2790
2925
|
expect(counter.rows).toBe(0)
|
|
2791
2926
|
}
|
|
2792
|
-
results.set(`${urgent}:${length}`, {
|
|
2927
|
+
;(profiles ? profileResults : results).set(`${urgent}:${length}`, {
|
|
2928
|
+
calls: perTick,
|
|
2929
|
+
rows,
|
|
2930
|
+
})
|
|
2793
2931
|
await store.close()
|
|
2794
2932
|
}
|
|
2795
2933
|
}
|
|
2796
2934
|
const [baseline, ...rest] = [...results.values()]
|
|
2797
2935
|
for (const result of rest) expect(result).toEqual(baseline!)
|
|
2936
|
+
const [profileBaseline, ...profileRest] = [...profileResults.values()]
|
|
2937
|
+
for (const result of profileRest) expect(result).toEqual(profileBaseline!)
|
|
2938
|
+
// Profiles never add a request or a row; withholding a conflict can only save.
|
|
2939
|
+
profileBaseline!.calls.forEach((tick, index) => {
|
|
2940
|
+
for (const name of methods)
|
|
2941
|
+
expect(tick[name]).toBeLessThanOrEqual(baseline!.calls[index]![name]!)
|
|
2942
|
+
expect(profileBaseline!.rows[index]).toBeLessThanOrEqual(baseline!.rows[index]!)
|
|
2943
|
+
})
|
|
2798
2944
|
return baseline!.calls[0]!
|
|
2799
2945
|
}
|
|
2800
2946
|
|
|
@@ -2947,3 +3093,257 @@ export async function noDispatcherRunDashboardBudget() {
|
|
|
2947
3093
|
expect(counter.rows).toBe(0)
|
|
2948
3094
|
}
|
|
2949
3095
|
}
|
|
3096
|
+
|
|
3097
|
+
/** Tally the store requests callers make, by method name: every
|
|
3098
|
+
* function-valued store method is counted when entered from outside the store,
|
|
3099
|
+
* never when the adapter calls its own methods. `restore` removes the
|
|
3100
|
+
* instrumentation. */
|
|
3101
|
+
export function memoryStoreRequestCounter(store: BuildStore) {
|
|
3102
|
+
const inside = new AsyncLocalStorage<true>()
|
|
3103
|
+
const counts = new Map<string, number>()
|
|
3104
|
+
const names = new Set<string>()
|
|
3105
|
+
for (
|
|
3106
|
+
let proto: object | null = store;
|
|
3107
|
+
proto && proto !== Object.prototype;
|
|
3108
|
+
proto = Object.getPrototypeOf(proto)
|
|
3109
|
+
)
|
|
3110
|
+
for (const name of Object.getOwnPropertyNames(proto))
|
|
3111
|
+
if (name !== 'constructor' && typeof Reflect.get(store, name) === 'function') names.add(name)
|
|
3112
|
+
const wrapped = new Map<string, { own: boolean; original: (...args: unknown[]) => unknown }>()
|
|
3113
|
+
for (const name of names) {
|
|
3114
|
+
const original = Reflect.get(store, name) as (...args: unknown[]) => unknown
|
|
3115
|
+
wrapped.set(name, { own: Object.hasOwn(store, name), original })
|
|
3116
|
+
Reflect.set(store, name, (...args: unknown[]) => {
|
|
3117
|
+
if (inside.getStore()) return original.apply(store, args)
|
|
3118
|
+
counts.set(name, (counts.get(name) ?? 0) + 1)
|
|
3119
|
+
return inside.run(true, () => original.apply(store, args))
|
|
3120
|
+
})
|
|
3121
|
+
}
|
|
3122
|
+
return {
|
|
3123
|
+
/** Calls since the last reset, by method name, in sorted order. */
|
|
3124
|
+
vector(): Record<string, number> {
|
|
3125
|
+
return Object.fromEntries([...counts].sort(([a], [b]) => a.localeCompare(b)))
|
|
3126
|
+
},
|
|
3127
|
+
reset() {
|
|
3128
|
+
counts.clear()
|
|
3129
|
+
},
|
|
3130
|
+
restore() {
|
|
3131
|
+
for (const [name, { own, original }] of wrapped)
|
|
3132
|
+
if (own) Reflect.set(store, name, original)
|
|
3133
|
+
else Reflect.deleteProperty(store, name)
|
|
3134
|
+
},
|
|
3135
|
+
}
|
|
3136
|
+
}
|
|
3137
|
+
|
|
3138
|
+
/** A janitor that keeps failing for one build costs every fresh-dispatcher tick
|
|
3139
|
+
* the same store requests at 100 and at 100,000 events. The vectors are
|
|
3140
|
+
* returned per tick class so a caller can pin them against an earlier
|
|
3141
|
+
* implementation: episode start, a failure before attention, the attention
|
|
3142
|
+
* failure, a failure before the escalation limit, the threshold failure, a
|
|
3143
|
+
* failure after it, and the recovering attempt. */
|
|
3144
|
+
export async function janitorEscalationRequestBudget(opts: {
|
|
3145
|
+
store: import('../store/memory').MemoryBuildStore
|
|
3146
|
+
repo: string
|
|
3147
|
+
slug: string
|
|
3148
|
+
/** One tick on a fresh dispatcher. */
|
|
3149
|
+
tick: () => Promise<unknown>
|
|
3150
|
+
now: () => Date
|
|
3151
|
+
advance: (ms: number) => void
|
|
3152
|
+
/** Make the build's janitor work fail (true) or succeed (false). */
|
|
3153
|
+
failing: (value: boolean) => void
|
|
3154
|
+
/** Episode age at which the threshold failure is expected. */
|
|
3155
|
+
limitSeconds: number
|
|
3156
|
+
attentionSeconds: number
|
|
3157
|
+
}) {
|
|
3158
|
+
const { store, repo, slug } = opts
|
|
3159
|
+
type Vectors = Record<
|
|
3160
|
+
'start' | 'preAttention' | 'attention' | 'preLimit' | 'threshold' | 'escalated' | 'recovery',
|
|
3161
|
+
Record<string, number>
|
|
3162
|
+
>
|
|
3163
|
+
const escalations = async () =>
|
|
3164
|
+
(await store.getEvents(slug)).filter(
|
|
3165
|
+
(event) => String(event.type) === 'build.janitor-escalated',
|
|
3166
|
+
).length
|
|
3167
|
+
const results: { length: number; vectors: Vectors; escalations: number }[] = []
|
|
3168
|
+
await store.ensureRepo(repo)
|
|
3169
|
+
let seeded = 0
|
|
3170
|
+
for (const length of [100, 100_000]) {
|
|
3171
|
+
for (; seeded < length; seeded++) {
|
|
3172
|
+
await store.appendRepo(repo, {
|
|
3173
|
+
actor: humanActor('budget'),
|
|
3174
|
+
type: 'dispatcher.intake-set',
|
|
3175
|
+
payload: { enabled: true },
|
|
3176
|
+
})
|
|
3177
|
+
if (seeded % 10 === 0)
|
|
3178
|
+
await store.append(slug, {
|
|
3179
|
+
actor: KERNEL,
|
|
3180
|
+
type: 'observation.recorded',
|
|
3181
|
+
payload: { id: `obs-${seeded}`, kind: 'followup', summary: `budget padding ${seeded}` },
|
|
3182
|
+
})
|
|
3183
|
+
}
|
|
3184
|
+
// Warm up: a fresh dispatcher folds the padding once while nothing fails.
|
|
3185
|
+
opts.failing(false)
|
|
3186
|
+
await opts.tick()
|
|
3187
|
+
opts.failing(true)
|
|
3188
|
+
const before = await escalations()
|
|
3189
|
+
const counter = memoryStoreRequestCounter(store)
|
|
3190
|
+
const vectors: Partial<Vectors> = {}
|
|
3191
|
+
try {
|
|
3192
|
+
const measure = async () => {
|
|
3193
|
+
counter.reset()
|
|
3194
|
+
await opts.tick()
|
|
3195
|
+
return counter.vector()
|
|
3196
|
+
}
|
|
3197
|
+
const due = async () => {
|
|
3198
|
+
const { state } = (await readBuildFacts(store, slug)).value
|
|
3199
|
+
const next = state.janitor && Date.parse(state.janitor.nextAttemptAt)
|
|
3200
|
+
if (next) opts.advance(Math.max(0, next - opts.now().getTime()))
|
|
3201
|
+
return state.janitor ? Date.parse(state.janitor.firstFailureAt) : undefined
|
|
3202
|
+
}
|
|
3203
|
+
vectors.start = await measure()
|
|
3204
|
+
const first = (await due())!
|
|
3205
|
+
vectors.preAttention = await measure()
|
|
3206
|
+
for (;;) {
|
|
3207
|
+
await due()
|
|
3208
|
+
const age = opts.now().getTime() - first
|
|
3209
|
+
const vector = await measure()
|
|
3210
|
+
if (age >= opts.limitSeconds * 1000) {
|
|
3211
|
+
vectors.threshold = vector
|
|
3212
|
+
break
|
|
3213
|
+
}
|
|
3214
|
+
if (age >= opts.attentionSeconds * 1000 && !vectors.attention) vectors.attention = vector
|
|
3215
|
+
else if (vectors.attention) vectors.preLimit = vector
|
|
3216
|
+
}
|
|
3217
|
+
await due()
|
|
3218
|
+
vectors.escalated = await measure()
|
|
3219
|
+
opts.failing(false)
|
|
3220
|
+
await due()
|
|
3221
|
+
vectors.recovery = await measure()
|
|
3222
|
+
} finally {
|
|
3223
|
+
counter.restore()
|
|
3224
|
+
}
|
|
3225
|
+
expect((await readBuildFacts(store, slug)).value.state.janitor).toBeUndefined()
|
|
3226
|
+
results.push({
|
|
3227
|
+
length,
|
|
3228
|
+
vectors: vectors as Vectors,
|
|
3229
|
+
escalations: (await escalations()) - before,
|
|
3230
|
+
})
|
|
3231
|
+
}
|
|
3232
|
+
expect(results[1]!.vectors).toEqual(results[0]!.vectors)
|
|
3233
|
+
return { vectors: results[0]!.vectors, escalations: results.map((r) => r.escalations) }
|
|
3234
|
+
}
|
|
3235
|
+
|
|
3236
|
+
/** AUT-1152: a prepared hosted guest re-reads its execution authority at its
|
|
3237
|
+
* durable boundaries. Proves the probe is one constant-size served value:
|
|
3238
|
+
* after the one-time reduction per key, an unchanged re-read issues the same
|
|
3239
|
+
* single request and reads zero event rows, and its response is the same size
|
|
3240
|
+
* whether the repository has had one harvest execution or a thousand; one new
|
|
3241
|
+
* fact costs exactly one row. */
|
|
3242
|
+
export async function hostedHarvestAuthorityReadBudget() {
|
|
3243
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
3244
|
+
const repo = '/repo'
|
|
3245
|
+
const guest = { execution: 'guest', run: 'h_guest', leaseHolder: 'inv-1' }
|
|
3246
|
+
const sizes = [
|
|
3247
|
+
{ cycles: 1, filler: 100 },
|
|
3248
|
+
{ cycles: 1_000, filler: 10_000 },
|
|
3249
|
+
]
|
|
3250
|
+
const results: Array<{
|
|
3251
|
+
warmRows: number
|
|
3252
|
+
unchanged: { vector: Record<string, number>; rows: number; size: number }
|
|
3253
|
+
appended: { rows: number; size: number }
|
|
3254
|
+
replaced: { rows: number; decision: ReturnType<typeof decideHostedHarvestAuthority> }
|
|
3255
|
+
}> = []
|
|
3256
|
+
for (const { cycles, filler } of sizes) {
|
|
3257
|
+
const store = new MemoryBuildStore()
|
|
3258
|
+
await seedPreparationHistory(store, repo, filler)
|
|
3259
|
+
for (let i = 0; i < cycles; i++) {
|
|
3260
|
+
const run = `h_old_${i}`
|
|
3261
|
+
const execution = `old-${i}`
|
|
3262
|
+
await store.appendRepo(repo, {
|
|
3263
|
+
actor: KERNEL,
|
|
3264
|
+
type: 'harvest.started',
|
|
3265
|
+
payload: {
|
|
3266
|
+
run,
|
|
3267
|
+
observations: [{ build: `b-${i}`, seq: 1 }],
|
|
3268
|
+
scan: { kind: 'harvest-scan', rev: i },
|
|
3269
|
+
},
|
|
3270
|
+
})
|
|
3271
|
+
await store.appendRepo(repo, {
|
|
3272
|
+
actor: DISPATCHER,
|
|
3273
|
+
type: 'harvest.execution.authorized',
|
|
3274
|
+
payload: { execution, run, launch: 'started', leaseHolder: `inv-old-${i}` },
|
|
3275
|
+
})
|
|
3276
|
+
await store.appendRepo(repo, {
|
|
3277
|
+
actor: DISPATCHER,
|
|
3278
|
+
type: 'harvest.execution.started',
|
|
3279
|
+
payload: { execution, provider: 'p', environmentId: `env-${i}` },
|
|
3280
|
+
})
|
|
3281
|
+
await store.appendRepo(repo, {
|
|
3282
|
+
actor: DISPATCHER,
|
|
3283
|
+
type: 'harvest.execution.released',
|
|
3284
|
+
payload: { execution, environmentId: `env-${i}`, snapshots: { outcome: 'confirmed' } },
|
|
3285
|
+
})
|
|
3286
|
+
}
|
|
3287
|
+
await store.appendRepo(repo, {
|
|
3288
|
+
actor: DISPATCHER,
|
|
3289
|
+
type: 'harvest.execution.authorized',
|
|
3290
|
+
payload: { ...guest, launch: 'started' },
|
|
3291
|
+
})
|
|
3292
|
+
const rows = memoryRepositoryReadCounter(store, repo)
|
|
3293
|
+
const requests = memoryStoreRequestCounter(store)
|
|
3294
|
+
try {
|
|
3295
|
+
const probe = async () => {
|
|
3296
|
+
rows.reset()
|
|
3297
|
+
requests.reset()
|
|
3298
|
+
const { value } = await readHostedHarvestAuthority(store, repo)
|
|
3299
|
+
return {
|
|
3300
|
+
vector: requests.vector(),
|
|
3301
|
+
rows: rows.rows,
|
|
3302
|
+
size: JSON.stringify(value).length,
|
|
3303
|
+
decision: decideHostedHarvestAuthority(value, guest),
|
|
3304
|
+
}
|
|
3305
|
+
}
|
|
3306
|
+
// The one-time reduction of this (repo, reducer) key.
|
|
3307
|
+
const warm = await probe()
|
|
3308
|
+
const unchanged = await probe()
|
|
3309
|
+
expect(unchanged.decision).toEqual({ kind: 'authorized' })
|
|
3310
|
+
await store.appendRepo(repo, {
|
|
3311
|
+
actor: humanActor('budget'),
|
|
3312
|
+
type: 'dispatcher.intake-set',
|
|
3313
|
+
payload: { enabled: true },
|
|
3314
|
+
})
|
|
3315
|
+
const appended = await probe()
|
|
3316
|
+
expect(appended.decision).toEqual({ kind: 'authorized' })
|
|
3317
|
+
await store.appendRepo(repo, {
|
|
3318
|
+
actor: DISPATCHER,
|
|
3319
|
+
type: 'harvest.execution.authorized',
|
|
3320
|
+
payload: {
|
|
3321
|
+
execution: 'successor',
|
|
3322
|
+
run: guest.run,
|
|
3323
|
+
launch: 'resumed',
|
|
3324
|
+
leaseHolder: 'inv-2',
|
|
3325
|
+
},
|
|
3326
|
+
})
|
|
3327
|
+
const replaced = await probe()
|
|
3328
|
+
results.push({
|
|
3329
|
+
warmRows: warm.rows,
|
|
3330
|
+
unchanged: { vector: unchanged.vector, rows: unchanged.rows, size: unchanged.size },
|
|
3331
|
+
appended: { rows: appended.rows, size: appended.size },
|
|
3332
|
+
replaced: { rows: replaced.rows, decision: replaced.decision },
|
|
3333
|
+
})
|
|
3334
|
+
} finally {
|
|
3335
|
+
requests.restore()
|
|
3336
|
+
}
|
|
3337
|
+
}
|
|
3338
|
+
const [small, large] = results as [(typeof results)[0], (typeof results)[0]]
|
|
3339
|
+
for (const result of results) {
|
|
3340
|
+
expect(result.unchanged.vector).toEqual({ getReducerValue: 1 })
|
|
3341
|
+
expect(result.unchanged.rows).toBe(0)
|
|
3342
|
+
expect(result.appended.rows).toBe(1)
|
|
3343
|
+
expect(result.replaced.rows).toBe(1)
|
|
3344
|
+
expect(result.replaced.decision).toEqual({ kind: 'fenced', reason: 'replaced' })
|
|
3345
|
+
}
|
|
3346
|
+
expect(large.unchanged.size).toBe(small.unchanged.size)
|
|
3347
|
+
expect(large.appended.size).toBe(small.appended.size)
|
|
3348
|
+
return { small, large }
|
|
3349
|
+
}
|