@defrex/autobuild 1.15.0 → 1.17.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 +110 -10
- package/docs/answering-blocked-builds.md +34 -1
- package/docs/architecture.md +41 -7
- package/docs/configuration.md +41 -7
- package/docs/dispatcher-hosting.md +3 -0
- package/docs/operator-api.md +15 -5
- package/docs/plugin-authoring.md +1 -0
- package/docs/remote-store-protocol.md +13 -3
- package/docs/remote-ticket-protocol.md +3 -1
- package/docs/restacking.md +41 -1
- package/docs/setup.md +15 -6
- package/docs/troubleshooting.md +51 -3
- package/docs/workspaces.md +4 -1
- package/package.json +3 -3
- package/packages/core/src/cli/accounts.ts +3 -0
- package/packages/core/src/cli/binary-direct.ts +14 -1
- package/packages/core/src/cli/binary.ts +10 -7
- package/packages/core/src/cli/dispatch.ts +610 -356
- package/packages/core/src/cli/secrets.ts +2 -0
- package/packages/core/src/config/schema.ts +15 -2
- package/packages/core/src/events/payloads.ts +8 -5
- package/packages/core/src/events/repository.ts +12 -6
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/e28c68e63cbd265f.json +108 -0
- package/packages/core/src/kernel/engine.ts +118 -0
- package/packages/core/src/kernel/reconcile-restack.ts +72 -9
- package/packages/core/src/kernel/reducer-revisions.ts +1 -0
- package/packages/core/src/kernel/tracked-dirt.ts +173 -0
- package/packages/core/src/ontology.ts +1 -0
- package/packages/core/src/operator/index.ts +10 -0
- package/packages/core/src/operator/merged-builds.ts +51 -0
- package/packages/core/src/operator/registry.ts +190 -101
- package/packages/core/src/operator/repo-argument.ts +43 -0
- package/packages/core/src/ports/tickets/grants.ts +2 -0
- package/packages/core/src/ports/tickets/remote.ts +2 -0
- package/packages/core/src/ports/types.ts +25 -4
- package/packages/core/src/ports/workspace/vercel-command-diagnostics.ts +144 -0
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +811 -169
- package/packages/core/src/processes/build-child.ts +15 -1
- package/packages/core/src/processes/build-runner.ts +349 -20
- package/packages/core/src/processes/dispatcher.ts +509 -104
- package/packages/core/src/processes/harvest-child.ts +21 -1
- package/packages/core/src/processes/harvest-runner.ts +82 -35
- package/packages/core/src/processes/invocation-budget.ts +6 -0
- package/packages/core/src/processes/launch-cut.ts +37 -0
- package/packages/core/src/processes/phase-failure-budget.ts +1 -0
- package/packages/core/src/processes/provisioning-progress.ts +23 -0
- package/packages/core/src/processes/repo-view.ts +25 -4
- package/packages/core/src/processes/workspace-preparation.ts +1 -0
- package/packages/core/src/store/adapter.ts +34 -5
- package/packages/core/src/store/build-feed.ts +148 -22
- package/packages/core/src/store/build-scope.ts +12 -3
- package/packages/core/src/store/caller-attribution.ts +170 -0
- package/packages/core/src/store/contract.ts +1038 -165
- package/packages/core/src/store/local/schema.ts +12 -1
- package/packages/core/src/store/local/store.ts +260 -25
- package/packages/core/src/store/memory.ts +156 -9
- package/packages/core/src/store/phase-session.ts +23 -3
- package/packages/core/src/store/reducer-value-shapes.json +5351 -5338
- package/packages/core/src/store/remote/client.ts +90 -11
- package/packages/core/src/store/remote/credentials.ts +2 -0
- package/packages/core/src/store/remote/index.ts +31 -5
- package/packages/core/src/store/remote/protocol.ts +45 -8
- package/packages/core/src/store/remote/released-clients.json +22 -0
- package/packages/core/src/store/remote/released-reducer-values/1.16.0.json +36358 -0
- package/packages/core/src/store/remote/released-reducer-values/1.17.0.json +36367 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +20 -16
- package/packages/core/src/store/remote/released-value-policy.ts +7 -0
- package/packages/core/src/store/session-handle.ts +12 -3
- package/packages/core/src/store/types.ts +48 -3
- package/packages/core/src/testing/reduced-read-budget.ts +310 -12
- package/skills/guide/SKILL.md +58 -9
- package/skills/guide/references/operator-api.md +15 -5
- package/skills/guide/references/plugin-authoring.md +1 -0
- package/skills/guide/references/remote-store-protocol.md +13 -3
- package/skills/guide/references/remote-ticket-protocol.md +3 -1
- package/skills/guide/references/restacking.md +41 -1
- package/skills/guide/references/setup.md +15 -6
- package/skills/operate/SKILL.md +31 -7
- package/templates/hosted-service/package.json +2 -2
|
@@ -6,14 +6,16 @@ import release3 from './1.12.0.json'
|
|
|
6
6
|
import release4 from './1.13.0.json'
|
|
7
7
|
import release5 from './1.14.0.json'
|
|
8
8
|
import release6 from './1.15.0.json'
|
|
9
|
-
import release7 from './1.
|
|
10
|
-
import release8 from './1.
|
|
11
|
-
import release9 from './1.
|
|
12
|
-
import release10 from './1.
|
|
13
|
-
import release11 from './1.
|
|
14
|
-
import release12 from './1.
|
|
15
|
-
import release13 from './1.
|
|
16
|
-
import release14 from './1.
|
|
9
|
+
import release7 from './1.16.0.json'
|
|
10
|
+
import release8 from './1.17.0.json'
|
|
11
|
+
import release9 from './1.2.0.json'
|
|
12
|
+
import release10 from './1.3.0.json'
|
|
13
|
+
import release11 from './1.4.0.json'
|
|
14
|
+
import release12 from './1.5.0.json'
|
|
15
|
+
import release13 from './1.6.0.json'
|
|
16
|
+
import release14 from './1.7.0.json'
|
|
17
|
+
import release15 from './1.8.0.json'
|
|
18
|
+
import release16 from './1.9.0.json'
|
|
17
19
|
import type { ReducerValueCatalog } from '../../reducer-value-validation'
|
|
18
20
|
export interface ReleasedReducerValues extends ReducerValueCatalog {
|
|
19
21
|
versions: Record<string, number>
|
|
@@ -26,12 +28,14 @@ export const RELEASED_REDUCER_VALUES: Readonly<Record<string, ReleasedReducerVal
|
|
|
26
28
|
'1.13.0.json': release4,
|
|
27
29
|
'1.14.0.json': release5,
|
|
28
30
|
'1.15.0.json': release6,
|
|
29
|
-
'1.
|
|
30
|
-
'1.
|
|
31
|
-
'1.
|
|
32
|
-
'1.
|
|
33
|
-
'1.
|
|
34
|
-
'1.
|
|
35
|
-
'1.
|
|
36
|
-
'1.
|
|
31
|
+
'1.16.0.json': release7,
|
|
32
|
+
'1.17.0.json': release8,
|
|
33
|
+
'1.2.0.json': release9,
|
|
34
|
+
'1.3.0.json': release10,
|
|
35
|
+
'1.4.0.json': release11,
|
|
36
|
+
'1.5.0.json': release12,
|
|
37
|
+
'1.6.0.json': release13,
|
|
38
|
+
'1.7.0.json': release14,
|
|
39
|
+
'1.8.0.json': release15,
|
|
40
|
+
'1.9.0.json': release16,
|
|
37
41
|
}
|
|
@@ -40,6 +40,13 @@ export const RELEASED_VALUE_POLICY: readonly ReleasedValuePolicy[] = [
|
|
|
40
40
|
reason:
|
|
41
41
|
'Every supported release knows released, stopped and live. A provisioning or failed sandbox has no usable live environment, which older readers spell stopped: their repository status shows it as stopped, dispatcher idle settlement acts only on live, and an operator open of a stopped environment ensures it again, which is what a failed or unfinished one needs.',
|
|
42
42
|
},
|
|
43
|
+
{
|
|
44
|
+
kind: 'map',
|
|
45
|
+
sites: ['repositoryReadFacts:$.deferredWork.builds[].step'],
|
|
46
|
+
map: { launch: 'resume' },
|
|
47
|
+
reason:
|
|
48
|
+
'A launch the work deadline cut (#1415) is carried like any other deferred start. Released readers serve every carried entry through the lease sweep, re-deriving the decision from build state, and use the step only to name it; a resume entry takes exactly that path. They drop the optional cut instance, so they never release a cut holder: its lease expires and their ordinary sweep fences it.',
|
|
49
|
+
},
|
|
43
50
|
{
|
|
44
51
|
kind: 'refuse',
|
|
45
52
|
sites: [
|
|
@@ -30,7 +30,7 @@ import type {
|
|
|
30
30
|
SubscribeOptions,
|
|
31
31
|
Unsubscribe,
|
|
32
32
|
} from './types'
|
|
33
|
-
import type { BuildPage, ChangedBuilds } from './types'
|
|
33
|
+
import type { BuildPage, ChangedBuilds, MergedBuildPage } from './types'
|
|
34
34
|
import type {
|
|
35
35
|
TicketAsset,
|
|
36
36
|
TicketAssetInput,
|
|
@@ -129,6 +129,9 @@ export function createSessionScopedStore(store: BuildStore, scope: string): Sess
|
|
|
129
129
|
listBuildsPage(repo: string): Promise<BuildPage> {
|
|
130
130
|
return Promise.reject(new SessionScopeError(scope, 'listBuildsPage', repo))
|
|
131
131
|
},
|
|
132
|
+
listMergedBuildsPage(repo: string): Promise<MergedBuildPage> {
|
|
133
|
+
return Promise.reject(new SessionScopeError(scope, 'listMergedBuildsPage', repo))
|
|
134
|
+
},
|
|
132
135
|
listBuilds(): Promise<BuildRecord[]> {
|
|
133
136
|
return Promise.reject(new SessionScopeError(scope, 'listBuilds'))
|
|
134
137
|
},
|
|
@@ -229,7 +232,10 @@ export function createSessionScopedStore(store: BuildStore, scope: string): Sess
|
|
|
229
232
|
repo: string,
|
|
230
233
|
_artifacts: ArtifactInput[],
|
|
231
234
|
_makeEvent: (deposited: RepositoryArtifactMeta[]) => RepositoryEventWrite<T>,
|
|
232
|
-
): Promise<{
|
|
235
|
+
): Promise<{
|
|
236
|
+
event: RepositoryEventEnvelope<T>
|
|
237
|
+
artifacts: RepositoryArtifactMeta[]
|
|
238
|
+
}> {
|
|
233
239
|
return Promise.reject(new SessionScopeError(scope, 'appendRepoWithArtifacts', repo))
|
|
234
240
|
},
|
|
235
241
|
getRepoEvents(repo: string, _sinceSeq?: number): Promise<RepositoryEvent[]> {
|
|
@@ -392,7 +398,10 @@ export function createSessionScopedStore(store: BuildStore, scope: string): Sess
|
|
|
392
398
|
id: string,
|
|
393
399
|
artifacts: ArtifactInput[],
|
|
394
400
|
makeEvent: (deposited: SessionArtifactMeta[]) => SessionEventWrite<T>,
|
|
395
|
-
): Promise<{
|
|
401
|
+
): Promise<{
|
|
402
|
+
event: SessionEventEnvelope<T>
|
|
403
|
+
artifacts: SessionArtifactMeta[]
|
|
404
|
+
}> {
|
|
396
405
|
own('appendSessionWithArtifacts', id)
|
|
397
406
|
return store.appendSessionWithArtifacts(id, artifacts, makeEvent)
|
|
398
407
|
},
|
|
@@ -2,7 +2,13 @@ import type { ScanCadence } from './scan-cadence'
|
|
|
2
2
|
import type { BoundedEventReads } from './event-reads'
|
|
3
3
|
import type { OperatorIdentity, OperatorPresence } from './operator-presence'
|
|
4
4
|
export type { OperatorIdentity, OperatorPresence } from './operator-presence'
|
|
5
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
BuildPage,
|
|
7
|
+
BuildPageOptions,
|
|
8
|
+
ChangedBuilds,
|
|
9
|
+
MergedBuildPage,
|
|
10
|
+
MergedBuildPageOptions,
|
|
11
|
+
} from './build-feed'
|
|
6
12
|
export type {
|
|
7
13
|
BuildPage,
|
|
8
14
|
BuildPageFilters,
|
|
@@ -10,6 +16,10 @@ export type {
|
|
|
10
16
|
BuildPageOptions,
|
|
11
17
|
ChangedBuild,
|
|
12
18
|
ChangedBuilds,
|
|
19
|
+
MergedBuild,
|
|
20
|
+
MergedBuildPage,
|
|
21
|
+
MergedBuildPageOptions,
|
|
22
|
+
MergedBuildTarget,
|
|
13
23
|
} from './build-feed'
|
|
14
24
|
import type { ReducerValueRequest, ReducerValue } from './reducer-values'
|
|
15
25
|
/**
|
|
@@ -214,7 +224,11 @@ export interface RepoTickObservation {
|
|
|
214
224
|
run: string
|
|
215
225
|
open?: { startedAt: string }
|
|
216
226
|
/** Retained across begin, even when the next run has a different holder. */
|
|
217
|
-
finished?: RepoTickCompletion & {
|
|
227
|
+
finished?: RepoTickCompletion & {
|
|
228
|
+
run: string
|
|
229
|
+
startedAt: string
|
|
230
|
+
completedAt: string
|
|
231
|
+
}
|
|
218
232
|
}
|
|
219
233
|
export interface RepoTickFinish {
|
|
220
234
|
observation: RepoTickObservation
|
|
@@ -418,6 +432,34 @@ export interface BuildStore extends BoundedEventReads {
|
|
|
418
432
|
*/
|
|
419
433
|
listBuildsPage(repo: string, opts?: BuildPageOptions): Promise<BuildPage>
|
|
420
434
|
|
|
435
|
+
/**
|
|
436
|
+
* One page of `repo`'s merged builds, most recently merged first: merge
|
|
437
|
+
* time descending, then slug descending. Served from the same per-build
|
|
438
|
+
* listing facts as `listBuildsPage`, each written in the same transaction
|
|
439
|
+
* as the event that changes it:
|
|
440
|
+
*
|
|
441
|
+
* - `mergedAt`: the latest `build.completed` envelope `ts` when its outcome
|
|
442
|
+
* is merged; cleared by a non-merged completion or `build.reopened`. Later
|
|
443
|
+
* writes (workspace release, PR-attachment reclaim, escalations) never
|
|
444
|
+
* move it.
|
|
445
|
+
* - `pr`: number and url of the latest `pr.opened` or `finalize.completed`.
|
|
446
|
+
* - `target`: `build.created`'s target, replaced on a node build by each
|
|
447
|
+
* `node.parent-accepted` `next.target` (null clears it).
|
|
448
|
+
* - `kind`: `node` when `build.created` kind is `node`, else `leaf`.
|
|
449
|
+
*
|
|
450
|
+
* `since` is inclusive and `until` exclusive, both on merge time. Records
|
|
451
|
+
* match `listBuildsForRepo` records, including the ticket projection. A
|
|
452
|
+
* cursor is opaque and continues only a request with the same window. A
|
|
453
|
+
* page is one bounded range scan over at most `limit + 1` entries, and reads
|
|
454
|
+
* zero event rows and zero reduced values, whatever the repository's build
|
|
455
|
+
* count, a build's log length, or the writes after its merge. An unknown
|
|
456
|
+
* repository answers `{builds: [], next: null}` and creates no state. An
|
|
457
|
+
* invalid instant, `since` after `until`, a malformed cursor, a cursor of
|
|
458
|
+
* another order or a limit outside 1..100 rejects with
|
|
459
|
+
* `BuildFeedValidationError`. Scoped handles reject.
|
|
460
|
+
*/
|
|
461
|
+
listMergedBuildsPage(repo: string, opts?: MergedBuildPageOptions): Promise<MergedBuildPage>
|
|
462
|
+
|
|
421
463
|
/**
|
|
422
464
|
* Append one validated event; the store assigns `seq` (per-build,
|
|
423
465
|
* monotonic, starting at 1) and `ts` (§15.1). Writes must pass
|
|
@@ -785,7 +827,10 @@ export interface BuildStore extends BoundedEventReads {
|
|
|
785
827
|
id: string,
|
|
786
828
|
artifacts: ArtifactInput[],
|
|
787
829
|
makeEvent: (deposited: SessionArtifactMeta[]) => SessionEventWrite<T>,
|
|
788
|
-
): Promise<{
|
|
830
|
+
): Promise<{
|
|
831
|
+
event: SessionEventEnvelope<T>
|
|
832
|
+
artifacts: SessionArtifactMeta[]
|
|
833
|
+
}>
|
|
789
834
|
putSessionArtifact(id: string, artifact: ArtifactInput): Promise<SessionArtifactMeta>
|
|
790
835
|
/** Latest revision when `rev` is omitted; null if kind (or rev) absent. */
|
|
791
836
|
getSessionArtifact(id: string, kind: string, rev?: number): Promise<SessionArtifact | null>
|
|
@@ -2531,7 +2531,9 @@ export async function deferredWorkReadBudget(): Promise<void> {
|
|
|
2531
2531
|
const repo = '/repos/deferred-work'
|
|
2532
2532
|
const sha = 'a'.repeat(40)
|
|
2533
2533
|
const config = parseConfig('[tickets]\nsource = "file"\nreadyState = "Ready"\n')
|
|
2534
|
-
|
|
2534
|
+
/** `queued`: the carried build was claimed and admitted but never
|
|
2535
|
+
* provisioned (#1415). */
|
|
2536
|
+
async function world(length: number, unrelated: number, carried: 'leaf' | 'queued' = 'leaf') {
|
|
2535
2537
|
let now = Date.parse('2026-12-01T00:00:00.000Z')
|
|
2536
2538
|
const clock = () => new Date(now)
|
|
2537
2539
|
const store = new MemoryBuildStore({ clock })
|
|
@@ -2557,7 +2559,7 @@ export async function deferredWorkReadBudget(): Promise<void> {
|
|
|
2557
2559
|
await store.createBuild(created(slug))
|
|
2558
2560
|
await seedBuildFiller(store, slug, length, INERT_BUILD_FILLER)
|
|
2559
2561
|
const ticket = { source: 'fake', id: `T-${slug}`, title: slug }
|
|
2560
|
-
|
|
2562
|
+
const seeded = [
|
|
2561
2563
|
{
|
|
2562
2564
|
type: 'workspace.provisioned',
|
|
2563
2565
|
payload: {
|
|
@@ -2579,9 +2581,11 @@ export async function deferredWorkReadBudget(): Promise<void> {
|
|
|
2579
2581
|
type: 'execution.ended',
|
|
2580
2582
|
payload: { instance: 'i-1', workspaceRef: 'carried-g0', outcome: 'completed', exitCode: 0 },
|
|
2581
2583
|
},
|
|
2582
|
-
]
|
|
2584
|
+
]
|
|
2585
|
+
for (const event of carried === 'queued' ? seeded.slice(1, 3) : seeded)
|
|
2583
2586
|
await store.append(slug, { actor: DISPATCHER, ...event } as never)
|
|
2584
|
-
|
|
2587
|
+
if (carried === 'leaf')
|
|
2588
|
+
await store.append(slug, { actor: KERNEL, type: 'plan.started', payload: { round: 1 } })
|
|
2585
2589
|
now += 3_600_000
|
|
2586
2590
|
const launches: string[] = []
|
|
2587
2591
|
const dispatcher = () =>
|
|
@@ -2598,9 +2602,13 @@ export async function deferredWorkReadBudget(): Promise<void> {
|
|
|
2598
2602
|
snapshots: { outcome: 'confirmed', deleted: 0 },
|
|
2599
2603
|
}),
|
|
2600
2604
|
},
|
|
2601
|
-
provision: async () => {
|
|
2602
|
-
|
|
2603
|
-
|
|
2605
|
+
provision: async (input) => ({
|
|
2606
|
+
provider: 'remote-test',
|
|
2607
|
+
ref: `${input.branch}-g${input.generation ?? 0}`,
|
|
2608
|
+
path: '/remote/workspace',
|
|
2609
|
+
branch: input.branch,
|
|
2610
|
+
base: { source: 'existing' as const, sha },
|
|
2611
|
+
}),
|
|
2604
2612
|
release: async () => {},
|
|
2605
2613
|
},
|
|
2606
2614
|
forge: (() => {
|
|
@@ -2623,7 +2631,19 @@ export async function deferredWorkReadBudget(): Promise<void> {
|
|
|
2623
2631
|
await readBuildDigests(store, repo)
|
|
2624
2632
|
await readBuildFacts(store, slug)
|
|
2625
2633
|
for (let i = 1; i <= unrelated; i++) await readBuildFacts(store, `deferred-${i}`)
|
|
2626
|
-
|
|
2634
|
+
// The dispatch budget the carried build's dispatch completion reads.
|
|
2635
|
+
if (carried === 'queued')
|
|
2636
|
+
await store.getReducerValue(
|
|
2637
|
+
{ kind: 'build', slug },
|
|
2638
|
+
{ reducer: 'dispatchFailureBudget', args: { infrastructureOwnsWorkspace: true } },
|
|
2639
|
+
)
|
|
2640
|
+
const carry = (
|
|
2641
|
+
builds: {
|
|
2642
|
+
slug: string
|
|
2643
|
+
step: 'resume' | 'provision' | 'launch' | 'fence'
|
|
2644
|
+
instance?: string
|
|
2645
|
+
}[],
|
|
2646
|
+
) =>
|
|
2627
2647
|
store.appendRepo(repo, {
|
|
2628
2648
|
actor: DISPATCHER,
|
|
2629
2649
|
type: 'dispatcher.work-deferred',
|
|
@@ -2642,6 +2662,7 @@ export async function deferredWorkReadBudget(): Promise<void> {
|
|
|
2642
2662
|
})
|
|
2643
2663
|
const whole = await measureStoreReads(store, async () => {
|
|
2644
2664
|
await ticking.tick({ acceptNewWork: false })
|
|
2665
|
+
await ticking.drainProvisioning()
|
|
2645
2666
|
})
|
|
2646
2667
|
return { early: early!, carriedCalls: whole.slugs[slug] ?? 0 }
|
|
2647
2668
|
}
|
|
@@ -2694,11 +2715,70 @@ export async function deferredWorkReadBudget(): Promise<void> {
|
|
|
2694
2715
|
const withoutHint = (await swept.tick()).carriedCalls
|
|
2695
2716
|
expect(carried.launches).toEqual(swept.launches)
|
|
2696
2717
|
expect(withHint).toBeLessThanOrEqual(withoutHint)
|
|
2718
|
+
|
|
2719
|
+
// #1415: carried starts. A first provision on a claimed, never-provisioned
|
|
2720
|
+
// build; a launch the work deadline cut; and a cut launch whose fence is
|
|
2721
|
+
// still owed while its instance holds the lease. Each costs the same at
|
|
2722
|
+
// every history length and fleet size, reads only the carried build's
|
|
2723
|
+
// tail, and finishes its start in the early stage.
|
|
2724
|
+
const starts: Record<string, unknown[]> = {}
|
|
2725
|
+
const carriedStarts = [
|
|
2726
|
+
{ kind: 'provision', world: 'queued', entry: { step: 'provision' } },
|
|
2727
|
+
{ kind: 'launch', world: 'leaf', entry: { step: 'launch' } },
|
|
2728
|
+
{ kind: 'fence', world: 'leaf', entry: { step: 'fence', instance: 'cut' } },
|
|
2729
|
+
] as const
|
|
2730
|
+
// Both the history length and the fleet size differ between the two.
|
|
2731
|
+
for (const [length, unrelated] of [
|
|
2732
|
+
[100, 20],
|
|
2733
|
+
[100_000, 200],
|
|
2734
|
+
] as const)
|
|
2735
|
+
for (const { kind, world: shape, entry } of carriedStarts) {
|
|
2736
|
+
const w = await world(length, unrelated, shape)
|
|
2737
|
+
if (shape === 'leaf') {
|
|
2738
|
+
// Warm the leaf's launch values once, as the resume case does.
|
|
2739
|
+
await w.carry([])
|
|
2740
|
+
await w.tick()
|
|
2741
|
+
w.launches.length = 0
|
|
2742
|
+
}
|
|
2743
|
+
if (kind === 'fence') expect(await w.store.claimLease(w.slug, 'cut', 86_400_000)).toBe(true)
|
|
2744
|
+
await w.carry([{ slug: w.slug, ...entry }])
|
|
2745
|
+
const { early, carriedCalls } = await w.tick()
|
|
2746
|
+
expect(w.launches).toEqual([w.slug])
|
|
2747
|
+
expect((await w.store.getBuild(w.slug))?.lease).toBeUndefined()
|
|
2748
|
+
// Only the tail the setup appended, never the seeded history.
|
|
2749
|
+
expect({
|
|
2750
|
+
kind,
|
|
2751
|
+
history: early.read.filter((row) => row.slug === w.slug && row.seq <= length).length,
|
|
2752
|
+
}).toEqual({ kind, history: 0 })
|
|
2753
|
+
const latest = (await w.store.getRepoEvents(repo)).findLast(
|
|
2754
|
+
(event) => event.type === 'dispatcher.work-deferred',
|
|
2755
|
+
)
|
|
2756
|
+
expect(latest?.payload).toEqual({ builds: [] })
|
|
2757
|
+
const runs = starts[kind] ?? []
|
|
2758
|
+
runs.push({ calls: early.calls, slugs: early.slugs, carriedCalls })
|
|
2759
|
+
starts[kind] = runs
|
|
2760
|
+
}
|
|
2761
|
+
for (const runs of Object.values(starts))
|
|
2762
|
+
for (const other of runs.slice(1)) expect(other).toEqual(runs[0])
|
|
2763
|
+
|
|
2764
|
+
// The carried first provision replaces the recovery stage's dispatch
|
|
2765
|
+
// completion, which then skips the build: no extra reads of it.
|
|
2766
|
+
const queuedCarried = await world(100, 0, 'queued')
|
|
2767
|
+
await queuedCarried.carry([{ slug: queuedCarried.slug, step: 'provision' }])
|
|
2768
|
+
const queuedRecovered = await world(100, 0, 'queued')
|
|
2769
|
+
const queuedWithHint = (await queuedCarried.tick()).carriedCalls
|
|
2770
|
+
const queuedWithoutHint = (await queuedRecovered.tick()).carriedCalls
|
|
2771
|
+
expect(queuedCarried.launches).toEqual(queuedRecovered.launches)
|
|
2772
|
+
expect(queuedWithHint).toBeLessThanOrEqual(queuedWithoutHint)
|
|
2697
2773
|
console.log('deferred work read budget', {
|
|
2698
2774
|
histories: [100, 100_000],
|
|
2699
2775
|
unrelated: [20, 200],
|
|
2700
2776
|
earlyStageCalls: first!.calls,
|
|
2701
2777
|
carriedCallsPerTick: { withHint, withoutHint },
|
|
2778
|
+
carriedStartCalls: Object.fromEntries(
|
|
2779
|
+
Object.entries(starts).map(([kind, runs]) => [kind, runs[0]]),
|
|
2780
|
+
),
|
|
2781
|
+
queuedCallsPerTick: { withHint: queuedWithHint, withoutHint: queuedWithoutHint },
|
|
2702
2782
|
})
|
|
2703
2783
|
}
|
|
2704
2784
|
|
|
@@ -8943,7 +9023,8 @@ export async function agentContextReadBudget(): Promise<void> {
|
|
|
8943
9023
|
|
|
8944
9024
|
/** Count the build records and digest entries callers receive from a memory
|
|
8945
9025
|
* store: record entries from `listBuilds`, `listBuildsForRepo`, a found
|
|
8946
|
-
* `getBuild` and `
|
|
9026
|
+
* `getBuild`, `listOpenBuilds` and `listMergedBuildsPage` items; digest
|
|
9027
|
+
* entries from `getRepoBuildDigests`,
|
|
8947
9028
|
* `listOpenBuilds` and outer `buildDigest` reductions. Calls the adapter
|
|
8948
9029
|
* makes to itself are not counted. */
|
|
8949
9030
|
function memoryListingEntryCounter(store: import('../store/memory').MemoryBuildStore) {
|
|
@@ -8969,6 +9050,10 @@ function memoryListingEntryCounter(store: import('../store/memory').MemoryBuildS
|
|
|
8969
9050
|
digests += (result as unknown[]).length
|
|
8970
9051
|
})
|
|
8971
9052
|
wrap('getRepoBuildDigests', (result) => (digests += (result as Map<string, unknown>).size))
|
|
9053
|
+
wrap(
|
|
9054
|
+
'listMergedBuildsPage',
|
|
9055
|
+
(result) => (records += (result as { builds: unknown[] }).builds.length),
|
|
9056
|
+
)
|
|
8972
9057
|
wrap('getReducerValue', (_result, args) => {
|
|
8973
9058
|
if ((args[1] as { reducer: string }).reducer === 'buildDigest') digests++
|
|
8974
9059
|
})
|
|
@@ -9300,9 +9385,154 @@ export async function openBuildListingReadBudget(opts: { commands?: boolean } =
|
|
|
9300
9385
|
}
|
|
9301
9386
|
// The counter bites: the explicit history listing grows with settled builds.
|
|
9302
9387
|
expect(history.get(30)).toBeGreaterThan(history.get(1)!)
|
|
9388
|
+
await mergedBuildListingReadBudget()
|
|
9303
9389
|
return baseline!
|
|
9304
9390
|
}
|
|
9305
9391
|
|
|
9392
|
+
/** `builds.list` scope `merged` with `since`, `until` and `limit: 5`, cold
|
|
9393
|
+
* (nothing has read a reducer value) and again after post-merge writes, costs
|
|
9394
|
+
* the same store requests and entries at 10 and 1,000 merged builds and at 100
|
|
9395
|
+
* and 100,000 padding events: exactly one `listMergedBuildsPage` per page and
|
|
9396
|
+
* zero event rows. No warm-up: the first access is the measured one. */
|
|
9397
|
+
async function mergedBuildListingReadBudget() {
|
|
9398
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
9399
|
+
const repo = '/merged-listing-budget'
|
|
9400
|
+
const t0 = Date.parse('2026-11-30T00:00:00.000Z')
|
|
9401
|
+
const at = (ms: number) => new Date(t0 + ms).toISOString()
|
|
9402
|
+
type Item = { slug: string; mergedAt: string; kind: string; pr?: unknown; target?: unknown }
|
|
9403
|
+
type Vector = { records: number; digests: number; calls: Record<string, number> }
|
|
9404
|
+
let baseline: Vector[] | undefined
|
|
9405
|
+
for (const count of [10, 1000])
|
|
9406
|
+
for (const padding of [100, 100_000]) {
|
|
9407
|
+
let now = at(0)
|
|
9408
|
+
const store = new MemoryBuildStore({ clock: () => new Date(now) })
|
|
9409
|
+
await store.ensureRepo(repo)
|
|
9410
|
+
await seedRepoFiller(store, repo, padding)
|
|
9411
|
+
const ticket = (id: string) => ({ source: 'file', id })
|
|
9412
|
+
const create = (slug: string, extra: Record<string, unknown> = {}) =>
|
|
9413
|
+
store.createBuild({
|
|
9414
|
+
slug,
|
|
9415
|
+
repo,
|
|
9416
|
+
ticket: ticket(slug),
|
|
9417
|
+
created: {
|
|
9418
|
+
actor: DISPATCHER,
|
|
9419
|
+
type: 'build.created',
|
|
9420
|
+
payload: { ticket: ticket(slug), repo, baseBranch: 'main', ...extra },
|
|
9421
|
+
},
|
|
9422
|
+
})
|
|
9423
|
+
const merge = (slug: string, ms: number) => {
|
|
9424
|
+
now = at(ms)
|
|
9425
|
+
return store.append(slug, {
|
|
9426
|
+
actor: DISPATCHER,
|
|
9427
|
+
type: 'build.completed',
|
|
9428
|
+
payload: { outcome: 'merged' },
|
|
9429
|
+
})
|
|
9430
|
+
}
|
|
9431
|
+
for (let i = 0; i < count; i++) {
|
|
9432
|
+
const slug = `merged-${String(i).padStart(4, '0')}`
|
|
9433
|
+
await create(slug)
|
|
9434
|
+
// The most recently merged leaf carries a long log.
|
|
9435
|
+
if (i === count - 1) await seedBuildFiller(store, slug, padding, INERT_BUILD_FILLER)
|
|
9436
|
+
await store.append(slug, {
|
|
9437
|
+
actor: KERNEL,
|
|
9438
|
+
type: 'finalize.completed',
|
|
9439
|
+
payload: { pr: { number: i + 1, url: `https://forge/${i + 1}`, headSha: 'head' } },
|
|
9440
|
+
})
|
|
9441
|
+
await merge(slug, (i + 1) * 1000)
|
|
9442
|
+
}
|
|
9443
|
+
await create('merged-node', { kind: 'node' })
|
|
9444
|
+
await merge('merged-node', (count + 1) * 1000)
|
|
9445
|
+
await create('merged-child', {
|
|
9446
|
+
target: { build: 'merged-node', ticket: ticket('merged-node') },
|
|
9447
|
+
})
|
|
9448
|
+
await merge('merged-child', (count + 2) * 1000)
|
|
9449
|
+
const window = { since: at((count - 4) * 1000), until: at((count + 3) * 1000) }
|
|
9450
|
+
const expected = [
|
|
9451
|
+
[
|
|
9452
|
+
'merged-child',
|
|
9453
|
+
'merged-node',
|
|
9454
|
+
...[1, 2, 3].map((k) => `merged-${String(count - k).padStart(4, '0')}`),
|
|
9455
|
+
],
|
|
9456
|
+
[4, 5].map((k) => `merged-${String(count - k).padStart(4, '0')}`),
|
|
9457
|
+
]
|
|
9458
|
+
|
|
9459
|
+
const rows = memoryRepositoryReadCounter(store, repo)
|
|
9460
|
+
const entries = memoryListingEntryCounter(store)
|
|
9461
|
+
const calls = memoryStoreRequestCounter(store)
|
|
9462
|
+
const vectors: Vector[] = []
|
|
9463
|
+
const pages: Item[][] = []
|
|
9464
|
+
const walk = async () => {
|
|
9465
|
+
let cursor: string | undefined
|
|
9466
|
+
for (const slugs of expected) {
|
|
9467
|
+
// A fresh handle and registry: the stand-in for a fresh process.
|
|
9468
|
+
const fresh = new Proxy(store, {
|
|
9469
|
+
get(target, property) {
|
|
9470
|
+
const value = Reflect.get(target, property)
|
|
9471
|
+
return typeof value === 'function' ? value.bind(target) : value
|
|
9472
|
+
},
|
|
9473
|
+
})
|
|
9474
|
+
rows.reset()
|
|
9475
|
+
entries.reset()
|
|
9476
|
+
calls.reset()
|
|
9477
|
+
const page = (await buildRegistry({ store: fresh }).call('builds.list', {
|
|
9478
|
+
repo,
|
|
9479
|
+
scope: 'merged',
|
|
9480
|
+
limit: 5,
|
|
9481
|
+
...window,
|
|
9482
|
+
...(cursor === undefined ? {} : { cursor }),
|
|
9483
|
+
})) as { builds: Item[]; next: string | null }
|
|
9484
|
+
expect(page.builds.map((build) => build.slug)).toEqual(slugs)
|
|
9485
|
+
expect({ rows: rows.rows, buildRows: rows.buildRows }).toEqual({ rows: 0, buildRows: 0 })
|
|
9486
|
+
const vector = { ...entries.vector, calls: calls.vector() }
|
|
9487
|
+
expect(vector).toEqual({
|
|
9488
|
+
records: slugs.length,
|
|
9489
|
+
digests: 0,
|
|
9490
|
+
calls: { listMergedBuildsPage: 1 },
|
|
9491
|
+
})
|
|
9492
|
+
vectors.push(vector)
|
|
9493
|
+
pages.push(page.builds)
|
|
9494
|
+
cursor = page.next ?? undefined
|
|
9495
|
+
}
|
|
9496
|
+
expect(cursor).toBeUndefined()
|
|
9497
|
+
}
|
|
9498
|
+
try {
|
|
9499
|
+
await walk()
|
|
9500
|
+
// Post-merge writes move `updatedAt`, never the merge time.
|
|
9501
|
+
now = at((count + 10) * 1000)
|
|
9502
|
+
for (const slug of ['merged-child', 'merged-node']) {
|
|
9503
|
+
await store.append(slug, {
|
|
9504
|
+
actor: KERNEL,
|
|
9505
|
+
type: 'observation.recorded',
|
|
9506
|
+
payload: { id: `o-${slug}`, kind: 'followup', summary: 'after the merge' },
|
|
9507
|
+
})
|
|
9508
|
+
await store.append(slug, {
|
|
9509
|
+
actor: KERNEL,
|
|
9510
|
+
type: 'escalation.raised',
|
|
9511
|
+
payload: { id: `e-${slug}`, phase: 'implement', source: 'agent', question: 'q' },
|
|
9512
|
+
})
|
|
9513
|
+
}
|
|
9514
|
+
await walk()
|
|
9515
|
+
} finally {
|
|
9516
|
+
calls.restore()
|
|
9517
|
+
entries.restore()
|
|
9518
|
+
}
|
|
9519
|
+
const [cold, , warm] = pages
|
|
9520
|
+
expect(warm).toEqual(cold)
|
|
9521
|
+
expect(cold!.slice(0, 3)).toMatchObject([
|
|
9522
|
+
{
|
|
9523
|
+
slug: 'merged-child',
|
|
9524
|
+
mergedAt: at((count + 2) * 1000),
|
|
9525
|
+
kind: 'leaf',
|
|
9526
|
+
target: { build: 'merged-node', ticket: ticket('merged-node') },
|
|
9527
|
+
},
|
|
9528
|
+
{ slug: 'merged-node', mergedAt: at((count + 1) * 1000), kind: 'node' },
|
|
9529
|
+
{ kind: 'leaf', pr: { number: count, url: `https://forge/${count}` } },
|
|
9530
|
+
])
|
|
9531
|
+
if (baseline) expect(vectors).toEqual(baseline)
|
|
9532
|
+
baseline = vectors
|
|
9533
|
+
}
|
|
9534
|
+
}
|
|
9535
|
+
|
|
9306
9536
|
/** The repository-scoped MCP listing gate (`sandboxToolsListed`) over a
|
|
9307
9537
|
* repository holding `revisions` deposited effective configs, the latest
|
|
9308
9538
|
* enabling `[orchestrator]`. Proves the listing cost is one repository read
|
|
@@ -9469,12 +9699,17 @@ export async function buildFeedReadBudget(): Promise<{
|
|
|
9469
9699
|
return { builds, repeated, paging }
|
|
9470
9700
|
}
|
|
9471
9701
|
|
|
9702
|
+
const MERGED_LISTING_WALKS = new Set(['mergedAll', 'mergedSince', 'mergedWindow', 'mergedEmpty'])
|
|
9703
|
+
|
|
9472
9704
|
/**
|
|
9473
9705
|
* A filtered build page costs what its page costs: at most `limit + 1` listing
|
|
9474
9706
|
* entries and no event row, the same at 100 and 100,000 builds, however many
|
|
9475
9707
|
* builds match. Covers a rare filter matching only the oldest builds, a rare
|
|
9476
9708
|
* activity window, a large active set, a rare kind inside it, an empty
|
|
9477
|
-
* intersection and later pages.
|
|
9709
|
+
* intersection and later pages. The merged listing (`listMergedBuildsPage`)
|
|
9710
|
+
* is held to the same bound, unbounded, from a recent `since`, inside a
|
|
9711
|
+
* `since`/`until` window deep in history and over an empty window. Returns
|
|
9712
|
+
* each request's page costs by size.
|
|
9478
9713
|
*/
|
|
9479
9714
|
export async function filteredBuildPageReadBudget(): Promise<
|
|
9480
9715
|
Record<number, Record<string, BuildFeedReadCost[]>>
|
|
@@ -9486,6 +9721,7 @@ export async function filteredBuildPageReadBudget(): Promise<
|
|
|
9486
9721
|
const slug = (i: number) => `lf-${String(i).padStart(6, '0')}`
|
|
9487
9722
|
const t0 = '2026-11-24T00:00:00.000Z'
|
|
9488
9723
|
const t1 = '2026-11-24T01:00:00.000Z'
|
|
9724
|
+
const t2 = '2026-11-24T02:00:00.000Z'
|
|
9489
9725
|
const nodes = 30
|
|
9490
9726
|
const range = (from: number, to: number) =>
|
|
9491
9727
|
Array.from({ length: from - to + 1 }, (_, i) => slug(from - i))
|
|
@@ -9523,6 +9759,38 @@ export async function filteredBuildPageReadBudget(): Promise<
|
|
|
9523
9759
|
return costs
|
|
9524
9760
|
}
|
|
9525
9761
|
|
|
9762
|
+
/** The same walk over `listMergedBuildsPage`. */
|
|
9763
|
+
const walkMerged = async (
|
|
9764
|
+
store: Store,
|
|
9765
|
+
opts: import('../store/build-feed').MergedBuildPageOptions,
|
|
9766
|
+
expected: string[][],
|
|
9767
|
+
) => {
|
|
9768
|
+
const costs: BuildFeedReadCost[] = []
|
|
9769
|
+
let cursor: string | undefined
|
|
9770
|
+
for (const [index, slugs] of expected.entries()) {
|
|
9771
|
+
const feedReads = Reflect.get(store, 'feedReads') as { examined: number }
|
|
9772
|
+
feedReads.examined = 0
|
|
9773
|
+
let page: import('../store/build-feed').MergedBuildPage | undefined
|
|
9774
|
+
const metrics = await measureStoreReads(store, async () => {
|
|
9775
|
+
page = await store.listMergedBuildsPage(repo, {
|
|
9776
|
+
...opts,
|
|
9777
|
+
...(cursor === undefined ? {} : { cursor }),
|
|
9778
|
+
})
|
|
9779
|
+
})
|
|
9780
|
+
expect(page!.builds.map((build) => build.record.slug)).toEqual(slugs)
|
|
9781
|
+
expect(page!.next === null).toBe(index === expected.length - 1)
|
|
9782
|
+
cursor = page!.next ?? undefined
|
|
9783
|
+
costs.push({
|
|
9784
|
+
calls: metrics.calls,
|
|
9785
|
+
rows: metrics.rows,
|
|
9786
|
+
repoRows: metrics.repoRows,
|
|
9787
|
+
bytes: metrics.bytes,
|
|
9788
|
+
examined: feedReads.examined,
|
|
9789
|
+
})
|
|
9790
|
+
}
|
|
9791
|
+
return costs
|
|
9792
|
+
}
|
|
9793
|
+
|
|
9526
9794
|
const sizes = [100, 100_000] as const
|
|
9527
9795
|
const costs: Record<number, Record<string, BuildFeedReadCost[]>> = {}
|
|
9528
9796
|
for (const n of sizes) {
|
|
@@ -9578,18 +9846,48 @@ export async function filteredBuildPageReadBudget(): Promise<
|
|
|
9578
9846
|
]),
|
|
9579
9847
|
recentLeaf: await walk(store, { activeSince: t1, kind: 'leaf' }, [[]]),
|
|
9580
9848
|
}
|
|
9849
|
+
// The merged listing: thirty leaves merge a minute apart after the nodes,
|
|
9850
|
+
// so merge order differs from creation and update order.
|
|
9851
|
+
const mergedAt = (i: number) => new Date(Date.parse(t2) + i * 60_000).toISOString()
|
|
9852
|
+
for (let i = nodes; i < 2 * nodes; i++) {
|
|
9853
|
+
now = mergedAt(i)
|
|
9854
|
+
await store.append(slug(i), {
|
|
9855
|
+
actor: DISPATCHER,
|
|
9856
|
+
type: 'build.completed',
|
|
9857
|
+
payload: { outcome: 'merged' },
|
|
9858
|
+
})
|
|
9859
|
+
}
|
|
9860
|
+
Object.assign(costs[n]!, {
|
|
9861
|
+
mergedAll: await walkMerged(store, {}, [
|
|
9862
|
+
range(59, 35),
|
|
9863
|
+
[...range(34, 30), ...range(29, 10)],
|
|
9864
|
+
range(9, 0),
|
|
9865
|
+
]),
|
|
9866
|
+
mergedSince: await walkMerged(store, { since: mergedAt(50) }, [range(59, 50)]),
|
|
9867
|
+
mergedWindow: await walkMerged(store, { since: t0, until: mergedAt(40) }, [
|
|
9868
|
+
[...range(39, 30), ...range(29, 15)],
|
|
9869
|
+
range(14, 0),
|
|
9870
|
+
]),
|
|
9871
|
+
mergedEmpty: await walkMerged(store, { since: mergedAt(45), until: mergedAt(45) }, [[]]),
|
|
9872
|
+
})
|
|
9581
9873
|
}
|
|
9582
9874
|
for (const n of sizes)
|
|
9583
9875
|
for (const [name, pages] of Object.entries(costs[n]!))
|
|
9584
9876
|
for (const cost of pages) {
|
|
9585
9877
|
// `snapshot` is the memory store copying each returned record.
|
|
9586
9878
|
const { snapshot: copies = 0, ...reads } = cost.calls
|
|
9587
|
-
expect(reads).toEqual(
|
|
9879
|
+
expect(reads).toEqual(
|
|
9880
|
+
MERGED_LISTING_WALKS.has(name) ? { listMergedBuildsPage: 1 } : { listBuildsPage: 1 },
|
|
9881
|
+
)
|
|
9588
9882
|
expect(copies).toBeLessThanOrEqual(25)
|
|
9589
9883
|
expect(cost.rows).toBe(0)
|
|
9590
9884
|
expect(cost.repoRows).toBe(0)
|
|
9591
9885
|
expect(cost.examined).toBeLessThanOrEqual(
|
|
9592
|
-
name === 'recent'
|
|
9886
|
+
name === 'recent'
|
|
9887
|
+
? 4
|
|
9888
|
+
: name === 'mergedLeaf' || name === 'recentLeaf' || name === 'mergedEmpty'
|
|
9889
|
+
? 1
|
|
9890
|
+
: 26,
|
|
9593
9891
|
)
|
|
9594
9892
|
}
|
|
9595
9893
|
const shape = (pages: BuildFeedReadCost[]) =>
|