@defrex/autobuild 1.19.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.
Files changed (63) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +88 -11
  3. package/docs/architecture.md +48 -8
  4. package/docs/assets/headline-wide.png +0 -0
  5. package/docs/dispatcher-hosting.md +6 -1
  6. package/docs/dispatcher.md +2 -2
  7. package/docs/merge-policy.md +2 -1
  8. package/docs/operator-surfaces.md +1 -1
  9. package/docs/plugin-authoring.md +11 -4
  10. package/docs/process-ownership.md +43 -0
  11. package/docs/remote-store-protocol.md +7 -0
  12. package/docs/restacking.md +11 -2
  13. package/docs/setup.md +7 -2
  14. package/docs/troubleshooting.md +6 -0
  15. package/docs/verification.md +1 -1
  16. package/package.json +3 -3
  17. package/packages/core/src/cli/dashboard/model.ts +1 -0
  18. package/packages/core/src/cli/dashboard/vocabulary.ts +3 -0
  19. package/packages/core/src/cli/dispatch.ts +3 -0
  20. package/packages/core/src/events/repository.ts +45 -1
  21. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +1 -0
  22. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/3f0c4e6d1d54e5bf.json +92 -0
  23. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/b440840a01ea216f.json +115 -0
  24. package/packages/core/src/kernel/dispatch-capacity.ts +47 -6
  25. package/packages/core/src/kernel/engine.ts +15 -2
  26. package/packages/core/src/kernel/janitor-failure.ts +1 -0
  27. package/packages/core/src/kernel/reducer-revisions.ts +3 -0
  28. package/packages/core/src/kernel/repository-read-facts.ts +6 -1
  29. package/packages/core/src/processes/build-runner.ts +67 -7
  30. package/packages/core/src/processes/check-termination.ts +44 -0
  31. package/packages/core/src/processes/dispatcher.ts +472 -57
  32. package/packages/core/src/processes/pass-stages.ts +94 -4
  33. package/packages/core/src/processes/publication-loss.ts +29 -0
  34. package/packages/core/src/processes/repo-view.ts +50 -10
  35. package/packages/core/src/store/contract.ts +43 -0
  36. package/packages/core/src/store/digest.ts +19 -1
  37. package/packages/core/src/store/reducer-value-shapes.json +5605 -5454
  38. package/packages/core/src/store/remote/protocol.ts +3 -0
  39. package/packages/core/src/store/remote/released-clients.json +22 -0
  40. package/packages/core/src/store/remote/released-reducer-values/1.20.0.json +36469 -0
  41. package/packages/core/src/store/remote/released-reducer-values/1.21.0.json +36612 -0
  42. package/packages/core/src/store/remote/released-reducer-values/index.ts +18 -14
  43. package/packages/core/src/store/types.ts +5 -0
  44. package/packages/core/src/testing/reduced-read-budget.ts +412 -2
  45. package/skills/code-review/SKILL.md +5 -0
  46. package/skills/finalize/SKILL.md +5 -0
  47. package/skills/guide/SKILL.md +36 -9
  48. package/skills/guide/references/merge-policy.md +2 -1
  49. package/skills/guide/references/plugin-authoring.md +11 -4
  50. package/skills/guide/references/process-ownership.md +43 -0
  51. package/skills/guide/references/remote-store-protocol.md +7 -0
  52. package/skills/guide/references/restacking.md +11 -2
  53. package/skills/guide/references/setup.md +7 -2
  54. package/skills/harvest/SKILL.md +5 -0
  55. package/skills/harvest-review/SKILL.md +5 -0
  56. package/skills/implement/SKILL.md +5 -0
  57. package/skills/judge/SKILL.md +4 -0
  58. package/skills/operate/SKILL.md +12 -0
  59. package/skills/plan/SKILL.md +5 -0
  60. package/skills/plan-review/SKILL.md +5 -0
  61. package/skills/propose/SKILL.md +5 -0
  62. package/skills/reconcile/SKILL.md +5 -0
  63. package/templates/hosted-service/package.json +2 -2
@@ -11,13 +11,15 @@ import release8 from './1.17.0.json'
11
11
  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
- import release12 from './1.3.0.json'
15
- import release13 from './1.4.0.json'
16
- import release14 from './1.5.0.json'
17
- import release15 from './1.6.0.json'
18
- import release16 from './1.7.0.json'
19
- import release17 from './1.8.0.json'
20
- import release18 from './1.9.0.json'
14
+ import release12 from './1.20.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'
21
23
  import type { ReducerValueCatalog } from '../../reducer-value-validation'
22
24
  export interface ReleasedReducerValues extends ReducerValueCatalog {
23
25
  versions: Record<string, number>
@@ -35,11 +37,13 @@ export const RELEASED_REDUCER_VALUES: Readonly<Record<string, ReleasedReducerVal
35
37
  '1.18.0.json': release9,
36
38
  '1.19.0.json': release10,
37
39
  '1.2.0.json': release11,
38
- '1.3.0.json': release12,
39
- '1.4.0.json': release13,
40
- '1.5.0.json': release14,
41
- '1.6.0.json': release15,
42
- '1.7.0.json': release16,
43
- '1.8.0.json': release17,
44
- '1.9.0.json': release18,
40
+ '1.20.0.json': release12,
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,
45
49
  }
@@ -205,6 +205,11 @@ export interface BuildDigest {
205
205
  * has not moved to the rejected role yet: a post-terminal duty that keeps
206
206
  * a completed node polled, like `reclaimPending`. Absent otherwise. */
207
207
  rejectionsPending?: true
208
+ /** A completed build whose PR merged still has an open workspace (its
209
+ * latest `workspace.provisioned` / `workspace.cleanup-required` has no
210
+ * later `workspace.released`): a post-terminal cleanup duty that keeps the
211
+ * build janitor-visited, like `reclaimPending`. Absent otherwise. */
212
+ releasePending?: true
208
213
  }
209
214
 
210
215
  export type RepoTickCompletion =
@@ -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)
@@ -10861,3 +11140,134 @@ export async function waivedTargetObservationReadBudget(): Promise<void> {
10861
11140
  expect(metrics).toEqual({ historicalRows: 0, tailRows: 0 })
10862
11141
  }
10863
11142
  }
11143
+
11144
+ /** #1443: a completed merged build whose workspace release is still pending
11145
+ * (`releasePending`) is revisited by the janitor on every pass until its
11146
+ * cleanup lands. Each such visit reads only that build's saved values: no
11147
+ * event row at or below the pass's boundary, and the same reduced reads at
11148
+ * 100 and 100,000 events. The digest that clears it advances over the new
11149
+ * rows alone, and once released nothing is read for it again. Fresh
11150
+ * dispatchers per pass: no per-process cache. */
11151
+ export async function mergedReleaseReadBudget(): Promise<void> {
11152
+ const { MemoryBuildStore } = await import('../store/memory')
11153
+ const { WorkspaceRecoveryDeferred } = await import('../ports/workspace/recovery-step')
11154
+ const { isWorkDigest } = await import('../processes/repo-view')
11155
+ const repo = '/repos/merged-release'
11156
+ const slug = 'merged-release'
11157
+ const base = 'a'.repeat(40)
11158
+ const perPass: Record<number, number[]> = {}
11159
+ for (const length of [100, 100_000]) {
11160
+ const clock = (() => {
11161
+ let now = Date.parse('2026-12-01T00:00:00Z')
11162
+ return Object.assign(() => new Date(now), { advance: (ms: number) => (now += ms) })
11163
+ })()
11164
+ const store = new MemoryBuildStore({ clock })
11165
+ await store.ensureRepo(repo)
11166
+ const forge = new FakeForge()
11167
+ forge.seedBranch('main', base)
11168
+ let deferred = true
11169
+ const dispatcher = () =>
11170
+ new Dispatcher({
11171
+ store,
11172
+ tickets: new FakeTicketSource([]),
11173
+ workspaces: {
11174
+ name: 'remote-test',
11175
+ preservation: async () => {
11176
+ throw new Error('a merged build is never preserved')
11177
+ },
11178
+ recovery: {
11179
+ fence: async () => {
11180
+ throw new Error('a merged build is never fenced')
11181
+ },
11182
+ reap: async () => {
11183
+ if (deferred) throw new WorkspaceRecoveryDeferred('cleanup', { remainingMs: 0 })
11184
+ return { outcome: 'confirmed', snapshots: { outcome: 'confirmed', deleted: 0 } }
11185
+ },
11186
+ },
11187
+ async provision() {
11188
+ throw new Error('not used')
11189
+ },
11190
+ async release() {},
11191
+ },
11192
+ forge,
11193
+ config: parseConfig('[tickets]\nsource = "file"\nreadyState = "Ready"'),
11194
+ repo,
11195
+ exec: async () => ({ stdout: `${base}\trefs/heads/main\n`, stderr: '', exitCode: 0 }),
11196
+ launchRunner: async () => 'scheduled',
11197
+ ids: sequentialIds(),
11198
+ clock,
11199
+ })
11200
+ const pass = async () => {
11201
+ clock.advance(60_000)
11202
+ await dispatcher().tick({ acceptNewWork: false })
11203
+ }
11204
+ await store.createBuild({ slug, repo, branch: `ab/${slug}` })
11205
+ const append = (type: string, payload: unknown, actor = DISPATCHER) =>
11206
+ store.append(slug, { actor, type, payload } as never)
11207
+ await append('build.created', {
11208
+ ticket: { source: 'fake', id: 'T-1', title: slug },
11209
+ repo,
11210
+ baseBranch: 'main',
11211
+ })
11212
+ await append('workspace.provisioned', {
11213
+ provider: 'remote-test',
11214
+ ref: `${slug}-g0`,
11215
+ path: '/remote/workspace',
11216
+ branch: `ab/${slug}`,
11217
+ base: { source: 'existing', sha: base },
11218
+ })
11219
+ await append('spec.imported', {
11220
+ artifact: { kind: 'spec', rev: 0 },
11221
+ ticket: { source: 'fake', id: 'T-1', title: slug },
11222
+ })
11223
+ await append('finalize.completed', { pr: { number: 3, url: 'u', headSha: 'h' } }, KERNEL)
11224
+ await seedBuildFiller(store, slug, length, INERT_BUILD_FILLER)
11225
+ forge.setPrState(3, { state: 'merged', sha: 'b'.repeat(40), headSha: 'h' })
11226
+ await pass() // completes; the cleanup defers
11227
+ let digest = (await readBuildDigests(store, repo)).get(slug)!
11228
+ expect(digest.terminal).toBe('done')
11229
+ expect(digest.releasePending).toBe(true)
11230
+ expect(isWorkDigest(digest)).toBe(true)
11231
+
11232
+ const metrics = { historicalRows: 0, tailRows: 0 }
11233
+ let reducerReads = 0
11234
+ const getReducerValue = store.getReducerValue.bind(store)
11235
+ store.getReducerValue = async (...args) => {
11236
+ reducerReads++
11237
+ return getReducerValue(...args)
11238
+ }
11239
+ let boundary = buildEventRows(store, slug).at(-1)!.seq
11240
+ await pass() // warm durable projections
11241
+ const restore = instrumentBuildRows(store, slug, () => boundary, metrics)
11242
+ perPass[length] = []
11243
+ for (let visit = 0; visit < 3; visit++) {
11244
+ boundary = buildEventRows(store, slug).at(-1)!.seq
11245
+ metrics.historicalRows = metrics.tailRows = reducerReads = 0
11246
+ await pass()
11247
+ perPass[length]!.push(reducerReads)
11248
+ expect(metrics.historicalRows).toBe(0)
11249
+ }
11250
+ expect(new Set(perPass[length]).size).toBe(1)
11251
+
11252
+ // The release lands: the digest advances over the new rows alone and
11253
+ // drops the build from the work set.
11254
+ deferred = false
11255
+ boundary = buildEventRows(store, slug).at(-1)!.seq
11256
+ await pass()
11257
+ metrics.historicalRows = metrics.tailRows = 0
11258
+ digest = (await readBuildDigests(store, repo)).get(slug)!
11259
+ expect(digest.releasePending).toBeUndefined()
11260
+ expect(isWorkDigest(digest)).toBe(false)
11261
+ expect(metrics.historicalRows).toBe(0)
11262
+
11263
+ // Released and settled: later passes read nothing of it.
11264
+ boundary = Number.POSITIVE_INFINITY
11265
+ await pass()
11266
+ metrics.historicalRows = metrics.tailRows = 0
11267
+ for (let idle = 0; idle < 2; idle++) await pass()
11268
+ expect(metrics).toEqual({ historicalRows: 0, tailRows: 0 })
11269
+ restore()
11270
+ Reflect.deleteProperty(store, 'getReducerValue')
11271
+ }
11272
+ expect(perPass[100]).toEqual(perPass[100_000])
11273
+ }
@@ -18,6 +18,11 @@ repositories or configuration through parent directories, including focused test
18
18
  and Git probes. Do not relocate required installed tooling or retained evidence;
19
19
  manifest-directed artifact paths remain authoritative. Never commit scratch.
20
20
 
21
+ Other builds' agents and verify commands share this host. Stop only processes
22
+ your session started, by the PID or process group you recorded; never by name
23
+ or pattern (`pkill`, `pkill -f`, `killall`, `kill $(pgrep …)`). See
24
+ [process ownership](../ab-guide/references/process-ownership.md).
25
+
21
26
  ## Session shape
22
27
 
23
28
  1. Run `ab context`. You get `$AB_CONTEXT_DIR/spec.md`, `$AB_CONTEXT_DIR/plan.md`, the commit range
@@ -11,6 +11,11 @@ never touch the forge).
11
11
 
12
12
  Guidance is an external operator answer, from the operator agent or a human.
13
13
 
14
+ Other builds' agents and verify commands share this host. Stop only processes
15
+ your session started, by the PID or process group you recorded; never by name
16
+ or pattern (`pkill`, `pkill -f`, `killall`, `kill $(pgrep …)`). See
17
+ [process ownership](../ab-guide/references/process-ownership.md).
18
+
14
19
  ## Session shape
15
20
 
16
21
  1. Run `ab context`. You get `$AB_CONTEXT_DIR/spec.md`, `$AB_CONTEXT_DIR/plan.md`, every verify report (including earlier failed cycles),
@@ -25,6 +25,7 @@ Idle nodes consume no runner capacity and empty nodes have no PR.
25
25
  - [Optimization nodes](references/optimization-nodes.md): when to use one, a run end to end, grooming the objective, the `autobuild-objective` marker, objective schema, refusals, paired harness-pinned measurement and the noise check, revisions, derived progress, the proposer phase, attempt priority, and the landing gate and attempt settlement, active hours, stopping and completion.
26
26
  - [Migration from 0.x](references/migration-1.0.md)
27
27
  - [Moving ticket sources](references/ticket-migration.md): recorded migrations preserve in-flight build continuity.
28
+ - [Process ownership](references/process-ownership.md): on a shared host, stop only processes your session started, by recorded PID; never by name or pattern. Also how to read a signal-killed verify report.
28
29
 
29
30
  ## How to use this skill
30
31
 
@@ -109,7 +110,11 @@ spec → plan ⇄ plan-review → implement ⇄ code-review → verify:* → fin
109
110
  other steps of its verify stage, or a recorded launch and its execution.
110
111
  Such a build keeps its slot through the answer and requests nothing. When
111
112
  a wait ends it waits for a slot again ahead of ticket claims at its level, so
112
- 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.
113
118
  With `[policy].maxOpenPrs` set, open-PR backpressure pauses new ordinary
114
119
  claims of `high`, `normal` and `low` tickets (not `ab start` requests) once that many root PRs are open and unmerged, until
115
120
  the count drains to `resumeOpenPrs` (below `maxOpenPrs` when the two are
@@ -585,8 +590,10 @@ The distinctions that change an administrator's answer:
585
590
  `node.history-retained` (node) record the non-forge outcomes. Workspace
586
591
  preservation of unpublished commits is strict: archive ref, else store copy
587
592
  (`workspace.commits-retained`), else the release is refused. Abort cleanup
588
- is the one exception: when preservation fails it records
589
- `workspace.commits-lost` and releases.
593
+ is one exception: when preservation fails it records
594
+ `workspace.commits-lost` and releases. Merged completion is the other: a
595
+ merged build completes first and its workspace is released without
596
+ preservation, since the merged commit is on the target.
590
597
  `github` publishes through GitHub. `local-git` performs no remote/network/`gh`
591
598
  operation: durable PR records live under private Git refs, and the review
592
599
  locator is `refs/heads/ab/<slug>`. Once merge authorization (auto or consent;
@@ -1031,7 +1038,7 @@ subtables are part of this section — their fields are listed here.
1031
1038
  | `steps` | `[]` | strings or nonempty arrays of names; no duplicate names | Ordered stages. Members start together; every pass or skip is required before the next stage. Each name needs a matching table. |
1032
1039
  | `failFast` | `false` | optional boolean on either verify kind | A failure cancels unfinished members of its stage, then tears down and relaunches the whole execution before implement. |
1033
1040
  | `kind` | — | **required**, `"check"` \| `"agent"` | Discriminator. `check` is deterministic (command + pass/fail, never an agent); `agent` runs a skill that returns `pass`, `fail`, or `skip`. |
1034
- | `command` | — | **required when `kind = "check"`**, nonempty string | Ref into `[commands]` — the key, not a shell string. Pass/fail is the command's exit status. Runs with `AB_VERIFY_BASE` set to the verify diff base when one exists. |
1041
+ | `command` | — | **required when `kind = "check"`**, nonempty string | Ref into `[commands]` — the key, not a shell string. Pass/fail is the command's exit status. A command killed by a signal names the signal in its report and whether the runner's own shutdown was in effect; a check the runner's shutdown stops leaves an uncounted report and reruns. Runs with `AB_VERIFY_BASE` set to the verify diff base when one exists. |
1035
1042
  | `skill` | — | **required when `kind = "agent"`**, nonempty string | Installed skill name to run (e.g. a repository-authored `"verify-acceptance"`). |
1036
1043
  | `paths` | — | optional nonempty array of positive repository-relative globs | Makes either step kind apply when any changed path matches any selector. Omitted means unconditional. |
1037
1044
  | `afterReconcile` | repository: `true`; step: inherited | boolean | Step override wins over `[verify].afterReconcile`; false skips this step after reconciliation only. |
@@ -1107,6 +1114,9 @@ repositories or configuration through parent directories, including focused test
1107
1114
  and Git probes. Do not relocate required installed tooling or retained evidence;
1108
1115
  manifest-directed artifact paths remain authoritative. Never commit scratch.
1109
1116
 
1117
+ Stop only processes the session started, by recorded PID or process group;
1118
+ see [process ownership](references/process-ownership.md).
1119
+
1110
1120
  Keep concurrent verifiers in their distinct context directories.
1111
1121
 
1112
1122
  An agent verify step is handed the build's pinned ticket assets under
@@ -1246,8 +1256,8 @@ phase failure or retrying the completed phase. Without a terminal, the oversized
1246
1256
  write follows the parking policy above. Other store statuses retain their
1247
1257
  existing retry policy.
1248
1258
 
1249
- Before releasing or replacing a build workspace, the dispatcher confirms a
1250
- non-destructive execution fence for the exact workspace and execution generation.
1259
+ Before releasing or replacing a build workspace, other than completing a
1260
+ merged build, the dispatcher confirms a non-destructive execution fence for the exact workspace and execution generation.
1251
1261
  It preserves unpublished branch commits and distinct detached producer candidates
1252
1262
  under immutable `refs/autobuild/archive/<build>/<sha>` refs, verifies their exact
1253
1263
  readback, and records `workspace.commits-preserved` before cleanup. Where the
@@ -1273,7 +1283,12 @@ cleanup records `workspace.commits-preserved` (or `workspace.commits-retained`)
1273
1283
  carrying forward earlier preserved heads, then releases and replaces it. Unknown fencing, inspection, transport, or
1274
1284
  receipt-write outcomes leave the workspace and snapshots intact, except under
1275
1285
  abort cleanup, which records `workspace.commits-lost` and tears the workspace
1276
- down. A workspace
1286
+ down. Merged completion skips this ordering: the janitor records
1287
+ `build.completed` first, then releases the workspace without a fence,
1288
+ preservation or resume, since the merged commit is on the target. A pending
1289
+ publication still passes the merged pre-release guard before cleanup, and a
1290
+ cleanup the pass cannot finish stays pending (`releasePending`) and retries
1291
+ on later janitor visits. A workspace
1277
1292
  flagged by `workspace.cleanup-required` is never launched into: the dispatcher
1278
1293
  releases it and provisions the next generation. Provisioning cut off by a
1279
1294
  recorded dispatcher teardown is the exception: the next invocation asks the
@@ -1315,6 +1330,16 @@ re-checking capacity. A carried ticket keeps its slot and is held from other
1315
1330
  claims until its preparation resolves, even across several invocations, and is
1316
1331
  never handed back to Ready for the interruption. It is released untouched if it left
1317
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.
1318
1343
  No stage consumes a bounded invocation: each starts items only within its share
1319
1344
  of the time left when it begins (half for deferred work, the janitor and the
1320
1345
  lease sweep, a quarter for the others; intake runs to the work deadline), and
@@ -1323,7 +1348,9 @@ and harvest settlement, the janitor, hand-backs, dispatch recovery, resume, the
1323
1348
  lease sweep) continue next invocation after the last item they started,
1324
1349
  through the latest-only `dispatcher.pass-cursors` fact, so every build is
1325
1350
  visited within a bounded number of passes. Each pass logs `stages:` with time
1326
- 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
1327
1354
  deadline reached during <stage>` naming the part in flight, and `ab repository
1328
1355
  status` shows the latest as `last pass stages:`. A hosted store service's
1329
1356
  request logs attribute each store request to its caller and pass stage
@@ -2859,7 +2886,7 @@ parenthesized note beside it (`merge decision`) says which case. The header's
2859
2886
  | green | held | `ABORTING` | an abort was requested and the runner is still stopping |
2860
2887
  | teal | requested | `QUEUED` | parked work waiting for admission; the note names the request (`resume`, `reconcile`, `verification`, `reopen`, `propose`) and marks urgent, high and low waiters |
2861
2888
  | amber | none | `WAITING` | a finished pipeline waiting for a merge decision (`merge decision`) or on hold (`on hold`), an entered ticket wait (`on <ids>`), or a `revise-spec` answer waiting for its revision (`spec revision`) |
2862
- | amber | none | `MERGING` | a finished pipeline with merge consent, waiting for merge gates or the forge |
2889
+ | amber | none | `MERGING` | a finished pipeline with merge consent, waiting for merge gates or the forge, or a merged PR whose completion is pending (`merged`) |
2863
2890
  | amber | none | `PAUSED` | an acknowledged pause |
2864
2891
  | amber | none | `COLLECTING` | an integration build collecting child work |
2865
2892
  | red | none | `BLOCKED` | an open escalation other than a ticket wait's own, or a failed node verification waiting for a repair child; the note `done` marks a completed build whose open escalation awaits acknowledgement |