@defrex/autobuild 1.20.0 → 1.21.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.
@@ -12,13 +12,14 @@ import release9 from './1.18.0.json'
12
12
  import release10 from './1.19.0.json'
13
13
  import release11 from './1.2.0.json'
14
14
  import release12 from './1.20.0.json'
15
- import release13 from './1.3.0.json'
16
- import release14 from './1.4.0.json'
17
- import release15 from './1.5.0.json'
18
- import release16 from './1.6.0.json'
19
- import release17 from './1.7.0.json'
20
- import release18 from './1.8.0.json'
21
- import release19 from './1.9.0.json'
15
+ import release13 from './1.21.0.json'
16
+ import release14 from './1.3.0.json'
17
+ import release15 from './1.4.0.json'
18
+ import release16 from './1.5.0.json'
19
+ import release17 from './1.6.0.json'
20
+ import release18 from './1.7.0.json'
21
+ import release19 from './1.8.0.json'
22
+ import release20 from './1.9.0.json'
22
23
  import type { ReducerValueCatalog } from '../../reducer-value-validation'
23
24
  export interface ReleasedReducerValues extends ReducerValueCatalog {
24
25
  versions: Record<string, number>
@@ -37,11 +38,12 @@ export const RELEASED_REDUCER_VALUES: Readonly<Record<string, ReleasedReducerVal
37
38
  '1.19.0.json': release10,
38
39
  '1.2.0.json': release11,
39
40
  '1.20.0.json': release12,
40
- '1.3.0.json': release13,
41
- '1.4.0.json': release14,
42
- '1.5.0.json': release15,
43
- '1.6.0.json': release16,
44
- '1.7.0.json': release17,
45
- '1.8.0.json': release18,
46
- '1.9.0.json': release19,
41
+ '1.21.0.json': release13,
42
+ '1.3.0.json': release14,
43
+ '1.4.0.json': release15,
44
+ '1.5.0.json': release16,
45
+ '1.6.0.json': release17,
46
+ '1.7.0.json': release18,
47
+ '1.8.0.json': release19,
48
+ '1.9.0.json': release20,
47
49
  }
@@ -1989,6 +1989,8 @@ export async function sampledMeasurementReadBudget(opts: {
1989
1989
  * by its build and sequence, and rows read from any repository journal. */
1990
1990
  export interface StoreReadMetrics {
1991
1991
  calls: Record<string, number>
1992
+ /** `calls` made by the caller, without the store's calls to itself. */
1993
+ requests: Record<string, number>
1992
1994
  slugs: Record<string, number>
1993
1995
  bytes: number
1994
1996
  rows: number
@@ -2013,6 +2015,7 @@ export async function measureStoreReads(
2013
2015
  ): Promise<StoreReadMetrics> {
2014
2016
  const metrics: StoreReadMetrics = {
2015
2017
  calls: {},
2018
+ requests: {},
2016
2019
  slugs: {},
2017
2020
  bytes: 0,
2018
2021
  rows: 0,
@@ -2082,6 +2085,7 @@ export async function measureStoreReads(
2082
2085
  if (slug !== undefined && builds.has(slug))
2083
2086
  metrics.slugs[slug] = (metrics.slugs[slug] ?? 0) + 1
2084
2087
  const internal = inside.getStore() === true
2088
+ if (!internal) metrics.requests[name] = (metrics.requests[name] ?? 0) + 1
2085
2089
  const result = inside.run(true, () => original.apply(store, args))
2086
2090
  return result instanceof Promise ? result.then(measure(internal)) : measure(internal)(result)
2087
2091
  })
@@ -2785,9 +2789,280 @@ export async function deferredWorkReadBudget(): Promise<void> {
2785
2789
  ),
2786
2790
  queuedCallsPerTick: { withHint: queuedWithHint, withoutHint: queuedWithoutHint },
2787
2791
  carriedPreparationCalls: await carriedPreparationReadBudget(),
2792
+ carriedAdmissionCalls: await carriedAdmissionReadBudget(),
2788
2793
  })
2789
2794
  }
2790
2795
 
2796
+ /** #1435: a parked admission an earlier bounded pass carried, with the
2797
+ * occupancy it measured. The early stage rebuilds occupancy from that
2798
+ * witness and the changed-builds feed, never by measuring the fleet: what a
2799
+ * carry adds to a whole bounded pass is the same at 2 and 40 unrelated idle
2800
+ * builds (a quarter of them idle collecting nodes) and at 100 and 100,000
2801
+ * repository events, while the janitor, recovery and the sweep each stop at
2802
+ * their first item and leave most builds unread. The stage reads only the
2803
+ * witness holders and the carried waiter; the feed reads no event row; with
2804
+ * nothing carried it makes no store request. */
2805
+ async function carriedAdmissionReadBudget(): Promise<Record<string, unknown>> {
2806
+ const { MemoryBuildStore } = await import('../store/memory')
2807
+ const repo = '/repos/carried-admission'
2808
+ const sha = 'a'.repeat(40)
2809
+ const config = parseConfig('capacity = 8\n[tickets]\nsource = "file"\nreadyState = "Ready"\n')
2810
+ const holders = ['holder-1', 'holder-2', 'holder-3']
2811
+ // Last in key order, so the sweep's first item is never the waiter.
2812
+ const waiter = 'zz-waiter'
2813
+ async function world(length: number, unrelated: number, carried: boolean) {
2814
+ let now = Date.parse('2026-12-01T00:00:00.000Z')
2815
+ const clock = () => new Date(now)
2816
+ const store = new MemoryBuildStore({ clock })
2817
+ await store.ensureRepo(repo)
2818
+ const create = async (slug: string, kind?: 'node') => {
2819
+ const ticket = { source: 'fake', id: `T-${slug}`, title: slug }
2820
+ await store.createBuild({
2821
+ slug,
2822
+ repo,
2823
+ ticket,
2824
+ branch: slug,
2825
+ created: {
2826
+ actor: DISPATCHER,
2827
+ type: 'build.created',
2828
+ payload: { ticket, repo, baseBranch: 'main', ...(kind ? { kind } : {}) },
2829
+ },
2830
+ })
2831
+ if (kind === 'node') {
2832
+ await store.append(slug, { actor: DISPATCHER, type: 'node.opened', payload: { sha } })
2833
+ return
2834
+ }
2835
+ await store.append(slug, {
2836
+ actor: DISPATCHER,
2837
+ type: 'workspace.provisioned',
2838
+ payload: {
2839
+ provider: 'remote-test',
2840
+ ref: `${slug}-g0`,
2841
+ path: '/remote/workspace',
2842
+ branch: slug,
2843
+ base: { source: 'existing', sha },
2844
+ },
2845
+ })
2846
+ await store.append(slug, {
2847
+ actor: DISPATCHER,
2848
+ type: 'spec.imported',
2849
+ payload: { artifact: { kind: 'spec', rev: 0 }, ticket },
2850
+ })
2851
+ await store.append(slug, {
2852
+ actor: DISPATCHER,
2853
+ type: 'target.moved',
2854
+ payload: { branch: 'main', sha },
2855
+ })
2856
+ await store.append(slug, { actor: DISPATCHER, type: 'slot.admitted', payload: {} })
2857
+ await store.append(slug, {
2858
+ actor: DISPATCHER,
2859
+ type: 'execution.started',
2860
+ payload: { provider: 'remote-test', workspaceRef: `${slug}-g0`, instance: `${slug}-i` },
2861
+ })
2862
+ }
2863
+ const ended = (slug: string) =>
2864
+ store.append(slug, {
2865
+ actor: DISPATCHER,
2866
+ type: 'execution.ended',
2867
+ payload: {
2868
+ instance: `${slug}-i`,
2869
+ workspaceRef: `${slug}-g0`,
2870
+ outcome: 'completed',
2871
+ exitCode: 0,
2872
+ },
2873
+ })
2874
+ const raise = (slug: string) =>
2875
+ store.append(slug, {
2876
+ actor: KERNEL,
2877
+ type: 'escalation.raised',
2878
+ payload: { id: `esc_${slug}`, phase: 'plan', source: 'agent', question: 'which way?' },
2879
+ })
2880
+ // Holders: running under a live runner.
2881
+ for (const slug of holders) {
2882
+ await create(slug)
2883
+ await store.append(slug, { actor: KERNEL, type: 'plan.started', payload: { round: 1 } })
2884
+ await store.claimLease(slug, `${slug}-runner`, 86_400_000)
2885
+ }
2886
+ // Unrelated idle builds: leaves blocked on a question and collecting nodes.
2887
+ for (let i = 1; i <= unrelated; i++) {
2888
+ const slug = `idle-${String(i).padStart(2, '0')}`
2889
+ if (i % 4 === 0) await create(slug, 'node')
2890
+ else {
2891
+ await create(slug)
2892
+ await store.append(slug, { actor: KERNEL, type: 'plan.started', payload: { round: 1 } })
2893
+ await ended(slug)
2894
+ await raise(slug)
2895
+ }
2896
+ }
2897
+ // The waiter: its escalation was answered, so it requests a slot to resume.
2898
+ await create(waiter)
2899
+ await store.append(waiter, { actor: KERNEL, type: 'plan.started', payload: { round: 1 } })
2900
+ await ended(waiter)
2901
+ await raise(waiter)
2902
+ await store.append(waiter, {
2903
+ actor: humanActor('operator'),
2904
+ type: 'escalation.answered',
2905
+ payload: { id: `esc_${waiter}`, answer: 'this way', resolution: 'guidance' },
2906
+ })
2907
+ await seedRepoFiller(store, repo, length)
2908
+ const position = await store.getRepoChangePosition(repo)
2909
+ if (carried)
2910
+ await store.appendRepo(repo, {
2911
+ actor: DISPATCHER,
2912
+ type: 'dispatcher.work-deferred',
2913
+ payload: {
2914
+ builds: [],
2915
+ parked: {
2916
+ slugs: [waiter],
2917
+ witness: {
2918
+ position,
2919
+ holders,
2920
+ waiters: [{ slug: waiter, level: 'normal' }],
2921
+ volatile: [],
2922
+ },
2923
+ },
2924
+ },
2925
+ })
2926
+ now += 60_000
2927
+ const launches: string[] = []
2928
+ const dispatcher = () =>
2929
+ new Dispatcher({
2930
+ store,
2931
+ tickets: new FakeTicketSource([]),
2932
+ workspaces: {
2933
+ name: 'remote-test',
2934
+ preservation: async () => ({ outcome: 'preserved', heads: [] }),
2935
+ recovery: {
2936
+ fence: async () => ({ outcome: 'confirmed' }),
2937
+ reap: async () => ({
2938
+ outcome: 'confirmed',
2939
+ snapshots: { outcome: 'confirmed', deleted: 0 },
2940
+ }),
2941
+ },
2942
+ provision: async (input) => ({
2943
+ provider: 'remote-test',
2944
+ ref: `${input.branch}-g${input.generation ?? 0}`,
2945
+ path: '/remote/workspace',
2946
+ branch: input.branch,
2947
+ base: { source: 'existing' as const, sha },
2948
+ }),
2949
+ release: async () => {},
2950
+ },
2951
+ forge: (() => {
2952
+ const forge = new FakeForge()
2953
+ forge.seedBranch('main', sha)
2954
+ return forge
2955
+ })(),
2956
+ config,
2957
+ repo,
2958
+ exec: async () => ({ stdout: `${sha}\trefs/heads/main\n`, stderr: '', exitCode: 0 }),
2959
+ launchRunner: async (launched: string) => {
2960
+ launches.push(launched)
2961
+ return 'scheduled' as const
2962
+ },
2963
+ ids: sequentialIds(),
2964
+ clock,
2965
+ })
2966
+ // One canonical reduction per key happens before anything is measured.
2967
+ await readRepositoryFacts(store, repo)
2968
+ await readBuildDigests(store, repo)
2969
+ for (const record of await store.listBuilds()) await readBuildFacts(store, record.slug)
2970
+ /** One bounded pass on a fresh dispatcher whose janitor, recovery and
2971
+ * sweep each stop at their first item: the clock passes the stage's cut
2972
+ * once that item started. */
2973
+ const pass = async () => {
2974
+ const ticking = dispatcher()
2975
+ const gate = Reflect.get(ticking, 'stageGate') as (
2976
+ opts: { deadlineAt?: number },
2977
+ part: string,
2978
+ ) => boolean
2979
+ const tracker = () => Reflect.get(ticking, 'pass') as { started: (part: string) => number }
2980
+ Reflect.set(ticking, 'stageGate', (opts: { deadlineAt?: number }, part: string) => {
2981
+ if (
2982
+ ['janitor', 'handbacks', 'dispatches', 'resume', 'sweep'].includes(part) &&
2983
+ tracker().started(part) > 0 &&
2984
+ opts.deadlineAt !== undefined &&
2985
+ now <= opts.deadlineAt
2986
+ )
2987
+ now = opts.deadlineAt + 1
2988
+ return gate.call(ticking, opts, part)
2989
+ })
2990
+ const service = Reflect.get(ticking, 'serviceCarriedAdmissions') as (
2991
+ ...args: unknown[]
2992
+ ) => Promise<void>
2993
+ let early: StoreReadMetrics | undefined
2994
+ Reflect.set(ticking, 'serviceCarriedAdmissions', async (...args: unknown[]) => {
2995
+ early = await measureStoreReads(store, () => service.apply(ticking, args))
2996
+ })
2997
+ const whole = await measureStoreReads(store, () =>
2998
+ ticking
2999
+ .tick({ acceptNewWork: false, deadlineAt: now + 250_000 })
3000
+ .then(() => ticking.drainProvisioning()),
3001
+ )
3002
+ return { whole, early }
3003
+ }
3004
+ return { store, launches, position, pass }
3005
+ }
3006
+
3007
+ /** What the carry adds to the whole pass: external store requests, every
3008
+ * store call including the store's calls to itself (a roster listing costs
3009
+ * one record snapshot per build), and bytes returned. */
3010
+ const added: Record<string, { requests: number; calls: Record<string, number>; bytes: number }> =
3011
+ {}
3012
+ let stage: Record<string, number> | undefined
3013
+ for (const length of [100, 100_000])
3014
+ for (const unrelated of [2, 40]) {
3015
+ const plain = await world(length, unrelated, false)
3016
+ const without = await plain.pass()
3017
+ // Nothing carried: the stage makes no store request at all.
3018
+ expect(without.early).toBeUndefined()
3019
+ expect(plain.launches).toEqual([])
3020
+ const carrying = await world(length, unrelated, true)
3021
+ const feed = await measureStoreReads(carrying.store, async () => {
3022
+ await carrying.store.listBuildsChangedSince(repo, carrying.position)
3023
+ })
3024
+ expect(feed.rows + feed.repoRows).toBe(0)
3025
+ const withCarry = await carrying.pass()
3026
+ expect(carrying.launches).toEqual([waiter])
3027
+ // The stage reads the witness holders and the waiter, nothing else.
3028
+ expect(Object.keys(withCarry.early!.slugs).sort()).toEqual([...holders, waiter].sort())
3029
+ stage ??= withCarry.early!.calls
3030
+ expect(withCarry.early!.calls).toEqual(stage)
3031
+ const total = (metrics: StoreReadMetrics) =>
3032
+ Object.values(metrics.requests).reduce((sum, calls) => sum + calls, 0)
3033
+ const calls: Record<string, number> = {}
3034
+ for (const name of new Set([
3035
+ ...Object.keys(withCarry.whole.calls),
3036
+ ...Object.keys(without.whole.calls),
3037
+ ])) {
3038
+ const more = (withCarry.whole.calls[name] ?? 0) - (without.whole.calls[name] ?? 0)
3039
+ if (more !== 0) calls[name] = more
3040
+ }
3041
+ added[`${length}:${unrelated}`] = {
3042
+ requests: total(withCarry.whole) - total(without.whole),
3043
+ calls,
3044
+ bytes: withCarry.whole.bytes - without.whole.bytes,
3045
+ }
3046
+ // The carry reads no build event row the same pass without it did not.
3047
+ const seen = new Set(without.whole.read.map((row) => `${row.slug}:${row.seq}`))
3048
+ expect(withCarry.whole.read.filter((row) => !seen.has(`${row.slug}:${row.seq}`))).toEqual([])
3049
+ }
3050
+ // The same at every fleet size and log length: no added roster re-listing.
3051
+ // The same at every fleet size and log length: no added roster re-listing
3052
+ // (a listing snapshots every build) and no data that grows with the fleet.
3053
+ // Returned bytes vary only by the digit widths of positions, sequence numbers
3054
+ // and timestamps inside the reduced values, a few dozen bytes at most.
3055
+ const [first, ...rest] = Object.values(added)
3056
+ for (const other of rest) {
3057
+ expect({ requests: other.requests, calls: other.calls }).toEqual({
3058
+ requests: first!.requests,
3059
+ calls: first!.calls,
3060
+ })
3061
+ expect(Math.abs(other.bytes - first!.bytes)).toBeLessThan(200)
3062
+ }
3063
+ return { stageCalls: stage, addedPerPass: first }
3064
+ }
3065
+
2791
3066
  /** #1431: carried ticket-preparation attempts. The early stage resumes each
2792
3067
  * from its durable boundaries: one `tickets.get`, no ready listing, no
2793
3068
  * capacity measurement and no read of any build but the one it creates,
@@ -3902,9 +4177,13 @@ export async function nodeChildDiscoveryReadBudget(opts: {
3902
4177
  'getLatestArtifactMeta',
3903
4178
  'listArtifacts',
3904
4179
  'getRepoBuildDigests',
4180
+ // A roster listing reads every build; a write must not add one.
4181
+ 'listBuilds',
3905
4182
  ] as const
3906
4183
  let baseline: Record<string, number> | undefined
3907
- for (const count of [10, 1000]) {
4184
+ // The first round is a warm-up: after it, every observation records the
4185
+ // same node write, so the 10- and 1,000-build rounds compare steady state.
4186
+ for (const [round, count] of [10, 10, 1000].entries()) {
3908
4187
  while (unrelated.size <= count) {
3909
4188
  const slug = `unrelated-${unrelated.size}`
3910
4189
  await terminal(slug, unrelated.size % 2 ? 'unrelated-node' : undefined)
@@ -3969,7 +4248,7 @@ export async function nodeChildDiscoveryReadBudget(opts: {
3969
4248
  expect(rows).toBe(0)
3970
4249
  expect(strays).toBe(0)
3971
4250
  if (baseline) expect(costs).toEqual(baseline)
3972
- baseline = costs
4251
+ if (round > 0) baseline = costs
3973
4252
  } finally {
3974
4253
  for (const { events } of logs) Reflect.deleteProperty(events, 'slice')
3975
4254
  for (const method of methods) Reflect.deleteProperty(store, method)
@@ -110,7 +110,11 @@ spec → plan ⇄ plan-review → implement ⇄ code-review → verify:* → fin
110
110
  other steps of its verify stage, or a recorded launch and its execution.
111
111
  Such a build keeps its slot through the answer and requests nothing. When
112
112
  a wait ends it waits for a slot again ahead of ticket claims at its level, so
113
- occupancy never exceeds `capacity`. Priority never preempts a running build.
113
+ occupancy never exceeds `capacity`. In a hosted invocation whose intake does
114
+ not finish, a parked leaf build held back for higher-level tickets is
115
+ carried, and a later invocation decides it without waiting for intake,
116
+ against the last recorded ticket demand. Waiting nodes and proposals are not
117
+ carried. Priority never preempts a running build.
114
118
  With `[policy].maxOpenPrs` set, open-PR backpressure pauses new ordinary
115
119
  claims of `high`, `normal` and `low` tickets (not `ab start` requests) once that many root PRs are open and unmerged, until
116
120
  the count drains to `resumeOpenPrs` (below `maxOpenPrs` when the two are
@@ -1326,6 +1330,16 @@ re-checking capacity. A carried ticket keeps its slot and is held from other
1326
1330
  claims until its preparation resolves, even across several invocations, and is
1327
1331
  never handed back to Ready for the interruption. It is released untouched if it left
1328
1332
  Ready or gained unresolved blockers before its claim.
1333
+ Parked leaf admissions are carried too; waiting nodes and proposals are not.
1334
+ Below urgent, a parked leaf build that fits a free slot waits for the pass's
1335
+ intake to rank higher-level tickets first. When that intake does not finish,
1336
+ the build is logged as `build <slug> (<level>): parked admission carried to the
1337
+ next pass` and recorded in the hint with the occupancy the pass measured. A
1338
+ later invocation decides it without waiting for intake: in its deferred stage
1339
+ when it can rebuild occupancy from that record and the builds changed since,
1340
+ otherwise on the lease sweep's ordinary visit. It is admitted only into a free
1341
+ slot that recorded higher-level ticket demand, start requests and higher-level
1342
+ waiters do not take.
1329
1343
  No stage consumes a bounded invocation: each starts items only within its share
1330
1344
  of the time left when it begins (half for deferred work, the janitor and the
1331
1345
  lease sweep, a quarter for the others; intake runs to the work deadline), and
@@ -1334,7 +1348,9 @@ and harvest settlement, the janitor, hand-backs, dispatch recovery, resume, the
1334
1348
  lease sweep) continue next invocation after the last item they started,
1335
1349
  through the latest-only `dispatcher.pass-cursors` fact, so every build is
1336
1350
  visited within a bounded number of passes. Each pass logs `stages:` with time
1337
- and items per stage; a pass the work deadline cuts short logs `tick: work
1351
+ and items per stage, and each stage names the parked builds it decided, with
1352
+ their level, grouped as `admitted`, `deferred` or `carried`; a pass the work
1353
+ deadline cuts short logs `tick: work
1338
1354
  deadline reached during <stage>` naming the part in flight, and `ab repository
1339
1355
  status` shows the latest as `last pass stages:`. A hosted store service's
1340
1356
  request logs attribute each store request to its caller and pass stage
@@ -1176,6 +1176,13 @@ finish preparing that ticket, so it holds the ticket and the next invocation
1176
1176
  prepares it first. Do not retry, move or re-file the ticket. The same ticket
1177
1177
  carried across several invocations means its preparation outlasts the hosted
1178
1178
  budget: report it with the stage the line names.
1179
+ A line `build X (<level>): parked admission carried to the next pass` is normal
1180
+ too: that invocation's intake did not finish ranking ticket claims, so a later
1181
+ invocation decides the parked build without waiting for intake (early when it
1182
+ can rebuild slot occupancy, otherwise on its lease-sweep visit) and admits it
1183
+ into a free slot that higher-level ticket demand, start requests and waiters do
1184
+ not take. Do not raise it with `ab priority … urgent`
1185
+ for that; priority is for expediting, not for a build carried this way.
1179
1186
  Each hosted invocation logs `stages:` with time and items per stage, and `ab
1180
1187
  repository status` shows the latest as `last pass stages:`. `(share)` on a
1181
1188
  stage is normal under load. Settlement, janitor, hand-back, recovery, resume
@@ -4,8 +4,8 @@
4
4
  "build": "ab-hosted-service-build"
5
5
  },
6
6
  "dependencies": {
7
- "@defrex/autobuild-hosted-store-service": "1.20.0",
8
- "@defrex/autobuild": "1.20.0",
7
+ "@defrex/autobuild-hosted-store-service": "1.21.0",
8
+ "@defrex/autobuild": "1.21.0",
9
9
  "next": "16.1.6",
10
10
  "react": "19.2.4",
11
11
  "react-dom": "19.2.4"