@defrex/autobuild 1.14.0 → 1.15.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.
@@ -5,14 +5,15 @@ import release2 from './1.11.1.json'
5
5
  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
- import release6 from './1.2.0.json'
9
- import release7 from './1.3.0.json'
10
- import release8 from './1.4.0.json'
11
- import release9 from './1.5.0.json'
12
- import release10 from './1.6.0.json'
13
- import release11 from './1.7.0.json'
14
- import release12 from './1.8.0.json'
15
- import release13 from './1.9.0.json'
8
+ import release6 from './1.15.0.json'
9
+ import release7 from './1.2.0.json'
10
+ import release8 from './1.3.0.json'
11
+ import release9 from './1.4.0.json'
12
+ import release10 from './1.5.0.json'
13
+ import release11 from './1.6.0.json'
14
+ import release12 from './1.7.0.json'
15
+ import release13 from './1.8.0.json'
16
+ import release14 from './1.9.0.json'
16
17
  import type { ReducerValueCatalog } from '../../reducer-value-validation'
17
18
  export interface ReleasedReducerValues extends ReducerValueCatalog {
18
19
  versions: Record<string, number>
@@ -24,12 +25,13 @@ export const RELEASED_REDUCER_VALUES: Readonly<Record<string, ReleasedReducerVal
24
25
  '1.12.0.json': release3,
25
26
  '1.13.0.json': release4,
26
27
  '1.14.0.json': release5,
27
- '1.2.0.json': release6,
28
- '1.3.0.json': release7,
29
- '1.4.0.json': release8,
30
- '1.5.0.json': release9,
31
- '1.6.0.json': release10,
32
- '1.7.0.json': release11,
33
- '1.8.0.json': release12,
34
- '1.9.0.json': release13,
28
+ '1.15.0.json': release6,
29
+ '1.2.0.json': release7,
30
+ '1.3.0.json': release8,
31
+ '1.4.0.json': release9,
32
+ '1.5.0.json': release10,
33
+ '1.6.0.json': release11,
34
+ '1.7.0.json': release12,
35
+ '1.8.0.json': release13,
36
+ '1.9.0.json': release14,
35
37
  }
@@ -67,6 +67,7 @@ export const REPOSITORY_LATEST_EVENT_TYPES: readonly RepositoryEventType[] = [
67
67
  'dispatcher.ticket-scan-completed',
68
68
  'dispatcher.placement-set',
69
69
  'dispatcher.work-deferred',
70
+ 'dispatcher.pass-cursors',
70
71
  ]
71
72
  const LATEST_TYPES = new Set<string>(REPOSITORY_LATEST_EVENT_TYPES)
72
73
 
@@ -2702,6 +2702,203 @@ export async function deferredWorkReadBudget(): Promise<void> {
2702
2702
  })
2703
2703
  }
2704
2704
 
2705
+ /** #1409: carrying the rotated loops' positions between bounded passes, and
2706
+ * checking mixed-version deferral only on the build acted on. Positions come
2707
+ * from the repository facts the tick's refresh already reduced, so carrying
2708
+ * one adds no read; a pass that cuts no loop writes nothing once they are
2709
+ * clear. No listing reads a build's facts for compatibility: settled builds
2710
+ * a newer writer's decisive fact defers are never read, however many there
2711
+ * are. Fresh dispatchers per tick: no per-process cache. */
2712
+ export async function passCursorsReadBudget(): Promise<void> {
2713
+ const { newerFact, seedNewerMemoryFact } = await import('./newer-writer')
2714
+ const { MemoryBuildStore } = await import('../store/memory')
2715
+ const repo = '/repos/pass-cursors'
2716
+ const sha = 'a'.repeat(40)
2717
+ const config = parseConfig('[tickets]\nsource = "file"\nreadyState = "Ready"\n')
2718
+ async function world(length: number, settled: number) {
2719
+ let now = Date.parse('2026-12-01T00:00:00.000Z')
2720
+ const clock = () => new Date(now)
2721
+ const store = new MemoryBuildStore({ clock })
2722
+ await store.ensureRepo(repo)
2723
+ const create = async (slug: string) => {
2724
+ const ticket = { source: 'fake', id: `T-${slug}`, title: slug }
2725
+ await store.createBuild({
2726
+ slug,
2727
+ repo,
2728
+ ticket,
2729
+ branch: `ab/${slug}`,
2730
+ created: {
2731
+ actor: DISPATCHER,
2732
+ type: 'build.created',
2733
+ payload: { ticket, repo, baseBranch: 'main' },
2734
+ },
2735
+ })
2736
+ return ticket
2737
+ }
2738
+ const running = async (slug: string) => {
2739
+ const ticket = await create(slug)
2740
+ for (const event of [
2741
+ {
2742
+ type: 'workspace.provisioned',
2743
+ payload: {
2744
+ provider: 'fake',
2745
+ ref: `/ws/ab/${slug}`,
2746
+ branch: `ab/${slug}`,
2747
+ base: { source: 'remote', sha },
2748
+ },
2749
+ },
2750
+ { type: 'spec.imported', payload: { artifact: { kind: 'spec', rev: 0 }, ticket } },
2751
+ { type: 'target.moved', payload: { branch: 'main', sha } },
2752
+ { type: 'slot.admitted', payload: {} },
2753
+ ])
2754
+ await store.append(slug, { actor: DISPATCHER, ...event } as never)
2755
+ await store.append(slug, { actor: KERNEL, type: 'plan.started', payload: { round: 1 } })
2756
+ }
2757
+ // The janitor's work: running leaves with live runners and long histories.
2758
+ const busy = ['busy-a', 'busy-b']
2759
+ for (const slug of busy) {
2760
+ await running(slug)
2761
+ await seedBuildFiller(store, slug, length, INERT_BUILD_FILLER)
2762
+ await store.claimLease(slug, `${slug}-runner`, 365 * 24 * 3_600_000)
2763
+ }
2764
+ // Settled builds a newer writer's decisive fact defers.
2765
+ const deferred: string[] = []
2766
+ for (let i = 1; i <= settled; i++) {
2767
+ const slug = `settled-${i}`
2768
+ await create(slug)
2769
+ await store.append(slug, {
2770
+ actor: DISPATCHER,
2771
+ type: 'build.completed',
2772
+ payload: { outcome: 'merged' },
2773
+ })
2774
+ seedNewerMemoryFact(store, newerFact(3, 'decisive', slug))
2775
+ deferred.push(slug)
2776
+ }
2777
+ // One live build it defers, which the stages reach.
2778
+ await running('live-mixed')
2779
+ seedNewerMemoryFact(
2780
+ store,
2781
+ newerFact((await store.getEvents('live-mixed')).length + 1, 'decisive', 'live-mixed'),
2782
+ )
2783
+ now += 3_600_000
2784
+ // One canonical reduction per key happens before anything is measured.
2785
+ await readRepositoryFacts(store, repo)
2786
+ await readBuildDigests(store, repo)
2787
+ for (const slug of [...busy, 'live-mixed', ...deferred]) await readBuildFacts(store, slug)
2788
+ const forge = new FakeForge()
2789
+ forge.seedBranch('main', sha)
2790
+ const tick = async () => {
2791
+ const dispatcher = new Dispatcher({
2792
+ store,
2793
+ tickets: new FakeTicketSource([]),
2794
+ workspaces: new FakeWorkspaceProvider({
2795
+ root: '/ws',
2796
+ mode: 'logical',
2797
+ base: { source: 'remote', sha },
2798
+ }),
2799
+ forge,
2800
+ config,
2801
+ repo,
2802
+ exec: async () => ({ stdout: `${sha}\trefs/heads/main\n`, stderr: '', exitCode: 0 }),
2803
+ launchRunner: async () => 'scheduled' as const,
2804
+ ids: sequentialIds(),
2805
+ clock,
2806
+ })
2807
+ const facts: Record<string, number> = {}
2808
+ const read = store.getReducerValue.bind(store)
2809
+ store.getReducerValue = async (...args: Parameters<typeof read>) => {
2810
+ const [scope, request] = args
2811
+ if (scope.kind === 'build' && request.reducer === 'buildReadFacts')
2812
+ facts[scope.slug] = (facts[scope.slug] ?? 0) + 1
2813
+ return read(...args)
2814
+ }
2815
+ const positions = async () =>
2816
+ (await store.getRepoEvents(repo)).filter((e) => e.type === 'dispatcher.pass-cursors').length
2817
+ const before = await positions()
2818
+ try {
2819
+ const metrics = await measureStoreReads(store, async () => {
2820
+ await dispatcher.tick({ acceptNewWork: false, deadlineAt: now + 250_000 })
2821
+ })
2822
+ // The store's public reads: what a remote store would serve.
2823
+ const calls = Object.fromEntries(
2824
+ Object.entries(metrics.calls).filter(([name]) =>
2825
+ [
2826
+ 'getReducerValue',
2827
+ 'getRepoBuildDigests',
2828
+ 'listBuilds',
2829
+ 'getArtifact',
2830
+ 'getRepo',
2831
+ 'getEvents',
2832
+ 'getRepoEvents',
2833
+ 'getBuild',
2834
+ ].includes(name),
2835
+ ),
2836
+ )
2837
+ return { calls, repoRows: metrics.repoRows, facts, wrote: (await positions()) - before }
2838
+ } finally {
2839
+ store.getReducerValue = read
2840
+ now += 60_000
2841
+ }
2842
+ }
2843
+ const carry = (cursors: Record<string, string>) =>
2844
+ store.appendRepo(repo, {
2845
+ actor: DISPATCHER,
2846
+ type: 'dispatcher.pass-cursors',
2847
+ payload: { cursors },
2848
+ })
2849
+ return { tick, carry, deferred }
2850
+ }
2851
+
2852
+ const measured: Record<string, unknown> = {}
2853
+ for (const length of [100, 100_000]) {
2854
+ for (const settled of [20, 200]) {
2855
+ const w = await world(length, settled)
2856
+ // Settle the first tick's own writes (deferral, observations).
2857
+ await w.tick()
2858
+ await w.tick()
2859
+ const plain = await w.tick()
2860
+ // Nothing cut and no position held: nothing written, no new row read.
2861
+ expect(plain.wrote).toBe(0)
2862
+ expect(plain.repoRows).toBe(0)
2863
+ // Settled deferred builds are never read; the live one at most once.
2864
+ for (const slug of w.deferred) expect(plain.facts[slug]).toBeUndefined()
2865
+ expect(plain.facts['live-mixed']).toBe(1)
2866
+ // A carried position reads what a pass after any other new repository
2867
+ // row reads, the refresh's tail, plus the later refresh of the one
2868
+ // append that clears it once every build was reached.
2869
+ await w.carry({})
2870
+ const baseline = await w.tick()
2871
+ expect(baseline.wrote).toBe(0)
2872
+ await w.carry({ janitor: 'busy-a', sweep: 'busy-a' })
2873
+ const carried = await w.tick()
2874
+ expect(carried.wrote).toBe(1)
2875
+ expect(carried.calls).toEqual({
2876
+ ...baseline.calls,
2877
+ getReducerValue: baseline.calls.getReducerValue! + 1,
2878
+ getRepo: baseline.calls.getRepo! + 1,
2879
+ })
2880
+ expect(carried.repoRows).toBe(baseline.repoRows + 1)
2881
+ // The clearing row is read at most once more, then nothing.
2882
+ expect((await w.tick()).repoRows).toBeLessThanOrEqual(baseline.repoRows)
2883
+ const idle = await w.tick()
2884
+ expect(idle).toMatchObject({ wrote: 0, repoRows: 0 })
2885
+ measured[`${length}:${settled}`] = { calls: plain.calls, facts: plain.facts }
2886
+ }
2887
+ }
2888
+ // The same reads at 100 and 100,000 events; the same facts reads whatever
2889
+ // the number of deferred builds (only the store's own digest batch grows
2890
+ // with the fleet).
2891
+ expect(measured['100:20']).toEqual(measured['100000:20'])
2892
+ expect(measured['100:200']).toEqual(measured['100000:200'])
2893
+ const facts = Object.values(measured).map((entry) => (entry as { facts: unknown }).facts)
2894
+ for (const other of facts) expect(other).toEqual(facts[0])
2895
+ console.log('pass cursors read budget', {
2896
+ histories: [100, 100_000],
2897
+ settledDeferred: [20, 200],
2898
+ tick: measured['100:20'],
2899
+ })
2900
+ }
2901
+
2705
2902
  /** A provision continuation that reaches its launch for a build at the
2706
2903
  * no-progress limit applies the guard instead of starting a runner. Each
2707
2904
  * continuation is a recurring invocation (every re-provision, every remote
@@ -1269,7 +1269,18 @@ cut short is stopped or left uncertain for a later fence. The tick counts the
1269
1269
  build as `recoveryDeferred` (or `provisioningDeferred` for a provision that
1270
1270
  needs about 150 s), logs `build <slug>: <step> deferred by the invocation
1271
1271
  budget`, never reports idle, and records it in `dispatcher.work-deferred`, so
1272
- the next invocation runs that build first.
1272
+ the next invocation runs that build first, within half of its window.
1273
+ No stage consumes a bounded invocation: each starts items only within its share
1274
+ of the time left when it begins (half for deferred work, the janitor and the
1275
+ lease sweep, a quarter for the others; intake runs to the work deadline), and
1276
+ each helper still gets its first item. Loops whose items stay listed (execution
1277
+ and harvest settlement, the janitor, hand-backs, dispatch recovery, resume, the
1278
+ lease sweep) continue next invocation after the last item they started,
1279
+ through the latest-only `dispatcher.pass-cursors` fact, so every build is
1280
+ visited within a bounded number of passes. Each pass logs `stages:` with time
1281
+ and items per stage; a pass the work deadline cuts short logs `tick: work
1282
+ deadline reached during <stage>` naming the part in flight, and `ab repository
1283
+ status` shows the latest as `last pass stages:`.
1273
1284
  Fencing is revalidated after restart; a saved receipt alone never authorizes
1274
1285
  cleanup of a newer execution. Current recovery notes are linked by the session
1275
1286
  manifest's `workspaceRecovery` field. Recovery notes apply to the next session
@@ -776,7 +776,7 @@ builds.
776
776
  | `appendRepo` | `POST /repos/{repo}/events` | event write | `201` + repository event envelope |
777
777
  | `appendRepoIfCurrent` | `POST /repos/{repo}/events/conditional` | `{"expectedSeq": nonnegative integer, "event": event write}` | appended: `201` + repository event envelope; journal advanced: `200 null` (mirroring section 3's build compare-and-append). A server without the route answers `404`; callers report it and never fall back to an unconditional append |
778
778
  | `getRepoEvents` / `getRepositoryTail` | `GET /repos/{repo}/events?since={n}&through={n}&wait={s}` | optional `since` query value, parsed as in section 3; absence defaults to `0`. Optional `wait` in whole seconds, per the event-wait rules of section 3 | `200` + envelopes with `seq > since`, up to the frozen head; optional `through` caps the response at `seq <= through`; `409 cursor-too-old` below `max(0, head - 1000)` |
779
- | `getRepoStateEvents` | `GET /repos/{repo}/state-events` | none | `200` + the bounded repository-journal subset (AUT-489): every durable event type (`ticket-preparation.*`, `harvest.*`, `orchestrator.sandbox.*`, the three dispatcher setting types, and cross-generation handoff correlation facts: target-prepared, yield-requested, upgrade-failed, handoff-started, terminal-released, takeover, drain-deadline, drain-settled and handoff-completed) plus the latest-only `dispatcher.ticket-scan-completed`, `dispatcher.placement-set` and `dispatcher.work-deferred` facts and, when the journal has one, the tail from the latest `dispatcher.run-started`, in increasing sequence order; served inside the repository-existence gate like `GET events`, so an unknown repository is `404` |
779
+ | `getRepoStateEvents` | `GET /repos/{repo}/state-events` | none | `200` + the bounded repository-journal subset (AUT-489): every durable event type (`ticket-preparation.*`, `harvest.*`, `orchestrator.sandbox.*`, the three dispatcher setting types, and cross-generation handoff correlation facts: target-prepared, yield-requested, upgrade-failed, handoff-started, terminal-released, takeover, drain-deadline, drain-settled and handoff-completed) plus the latest-only `dispatcher.ticket-scan-completed`, `dispatcher.placement-set`, `dispatcher.work-deferred` and `dispatcher.pass-cursors` facts and, when the journal has one, the tail from the latest `dispatcher.run-started`, in increasing sequence order; served inside the repository-existence gate like `GET events`, so an unknown repository is `404` |
780
780
  | `getReducerSnapshot` (repo scope) | `GET /repos/{repo}/snapshots/{reducer}?version={n}` | required `version` query value, a positive integer; `reducer` is a registry name (`^[A-Za-z][A-Za-z0-9._-]{0,63}$`) | `200` + `{"version", "cursor", "state"}` or `200 null` when absent, written by another reducer version, ahead of the journal's tail, or the repository has no journal record; an unknown repository is `404`, which the shipped client also maps to `null` |
781
781
  | `putReducerSnapshot` (repo scope) | `PUT /repos/{repo}/snapshots/{reducer}` | `{"version": int >= 1, "cursor": int >= 0, "state": JSON}`, at most 16 MiB (`413` above) | `200 {"written": boolean}`; the stored cursor never decreases, so a write at an equal or lower cursor (or an equal cursor at an equal or lower version) and one past the journal's tail answer `written: false` |
782
782
  | `appendRepoWithArtifacts` | `POST /repos/{repo}/deposits` | atomic deposit request | `201` + `{event, artifacts}` using repository shapes |
@@ -1135,6 +1135,15 @@ A dispatch log line `build X: resume deferred by the invocation budget` (or
1135
1135
  is normal: nothing is charged and the next invocation runs that build first.
1136
1136
  The same build deferring across several invocations means the hosted budget
1137
1137
  cannot fit that work: report it, and do not retry it.
1138
+ Each hosted invocation logs `stages:` with time and items per stage, and `ab
1139
+ repository status` shows the latest as `last pass stages:`. `(share)` on a
1140
+ stage is normal under load. Settlement, janitor, hand-back, recovery, resume
1141
+ and lease-sweep loops continue next invocation after the last item they
1142
+ started; priority-ordered admission and intake loops keep their order.
1143
+ `tick: work deadline reached during <stage>` names the stage and part the
1144
+ deadline stopped. The same stage or part stopping at the deadline on
1145
+ invocation after invocation means one visit there outlasts the window: report
1146
+ it with those lines.
1138
1147
 
1139
1148
  Leaf restack and reconcile publication retry classified transient forge or transport
1140
1149
  failures six times after the initial attempt, waiting 30, 60, 120, 240, 300 and
@@ -4,8 +4,8 @@
4
4
  "build": "ab-hosted-service-build"
5
5
  },
6
6
  "dependencies": {
7
- "@defrex/autobuild-hosted-store-service": "1.14.0",
8
- "@defrex/autobuild": "1.14.0",
7
+ "@defrex/autobuild-hosted-store-service": "1.15.0",
8
+ "@defrex/autobuild": "1.15.0",
9
9
  "next": "16.1.6",
10
10
  "react": "19.2.4",
11
11
  "react-dom": "19.2.4"