@defrex/autobuild 1.1.0 → 1.3.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 (157) hide show
  1. package/README.md +5 -13
  2. package/SPEC.md +249 -15
  3. package/bin/ab-dispatch-generation.ts +11 -2
  4. package/docs/accounts.md +130 -0
  5. package/docs/agent-runtimes.md +4 -4
  6. package/docs/answering-blocked-builds.md +4 -1
  7. package/docs/architecture.md +224 -12
  8. package/docs/build-store.md +3 -41
  9. package/docs/builds.md +2 -0
  10. package/docs/cli.md +14 -0
  11. package/docs/configuration-overview.md +117 -0
  12. package/docs/configuration.md +266 -141
  13. package/docs/dispatcher-hosting.md +18 -33
  14. package/docs/intake.md +2 -0
  15. package/docs/integration-tree.md +16 -5
  16. package/docs/merge-policy.md +1 -3
  17. package/docs/operating.md +1 -2
  18. package/docs/operator-api.md +144 -53
  19. package/docs/operator-surfaces.md +32 -20
  20. package/docs/overview.md +1 -1
  21. package/docs/plugin-authoring.md +27 -1
  22. package/docs/remote-store-protocol.md +259 -91
  23. package/docs/remote-ticket-protocol.md +29 -49
  24. package/docs/restacking.md +45 -0
  25. package/docs/seams.md +8 -8
  26. package/docs/setup.md +34 -129
  27. package/docs/spec-standard.md +4 -2
  28. package/docs/ticket-dependencies.md +8 -0
  29. package/docs/ticket-sources.md +18 -0
  30. package/docs/troubleshooting.md +7 -11
  31. package/docs/upgrading.md +1 -1
  32. package/docs/workspaces.md +4 -4
  33. package/package.json +14 -5
  34. package/packages/core/src/accounts/chatgpt-oauth.ts +216 -0
  35. package/packages/core/src/accounts/chatgpt-state.ts +41 -0
  36. package/packages/core/src/accounts/local-credentials.ts +194 -0
  37. package/packages/core/src/accounts/local-inference.ts +106 -0
  38. package/packages/core/src/accounts/local-owner.ts +123 -0
  39. package/packages/core/src/accounts/sensitive.ts +2 -0
  40. package/packages/core/src/cli/accounts.ts +147 -0
  41. package/packages/core/src/cli/binary.ts +3 -1
  42. package/packages/core/src/cli/connect.ts +3 -3
  43. package/packages/core/src/cli/dispatch-frontend.ts +1 -0
  44. package/packages/core/src/cli/dispatch-handoff.ts +125 -44
  45. package/packages/core/src/cli/dispatch-launch-contract.ts +187 -0
  46. package/packages/core/src/cli/dispatch-launcher.ts +54 -21
  47. package/packages/core/src/cli/dispatch-preflight.ts +6 -1
  48. package/packages/core/src/cli/dispatch-repository-feed.ts +107 -26
  49. package/packages/core/src/cli/dispatch.ts +135 -27
  50. package/packages/core/src/cli/dispatcher-liveness.ts +6 -1
  51. package/packages/core/src/cli/forge-clear.ts +30 -0
  52. package/packages/core/src/cli/help.ts +17 -0
  53. package/packages/core/src/cli/init-readiness-remote.ts +22 -1
  54. package/packages/core/src/cli/init-readiness-shared.ts +5 -1
  55. package/packages/core/src/cli/init-validation.ts +160 -18
  56. package/packages/core/src/cli/main.ts +72 -0
  57. package/packages/core/src/cli/publication-settlement.ts +4 -1
  58. package/packages/core/src/cli/secrets.ts +173 -0
  59. package/packages/core/src/cli/store-opening.ts +11 -1
  60. package/packages/core/src/cli/upgrade-agent.ts +9 -1
  61. package/packages/core/src/cli/watch.ts +12 -14
  62. package/packages/core/src/config/accounts.ts +101 -0
  63. package/packages/core/src/config/live.ts +14 -1
  64. package/packages/core/src/config/roles.ts +54 -3
  65. package/packages/core/src/config/schema.ts +60 -0
  66. package/packages/core/src/events/catalog.ts +1 -0
  67. package/packages/core/src/events/compatibility.ts +2 -1
  68. package/packages/core/src/events/forge-degradation-policy.ts +11 -0
  69. package/packages/core/src/events/payloads.ts +13 -0
  70. package/packages/core/src/events/policy.ts +9 -0
  71. package/packages/core/src/events/repository.ts +75 -2
  72. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +278 -0
  73. package/packages/core/src/kernel/change-presence.ts +74 -8
  74. package/packages/core/src/kernel/engine.ts +8 -0
  75. package/packages/core/src/kernel/generators/node-restack-log.ts +14 -0
  76. package/packages/core/src/kernel/node-polling.ts +40 -7
  77. package/packages/core/src/kernel/node-restack-demand.ts +74 -0
  78. package/packages/core/src/kernel/node-restack-state.ts +5 -1
  79. package/packages/core/src/kernel/node-restack-transaction.ts +33 -1
  80. package/packages/core/src/kernel/read-facts.ts +6 -0
  81. package/packages/core/src/kernel/reducer-registry.ts +3 -0
  82. package/packages/core/src/kernel/reducer.ts +4 -1
  83. package/packages/core/src/kernel/ticket-preparation.ts +66 -0
  84. package/packages/core/src/operator/annotations.ts +6 -0
  85. package/packages/core/src/operator/control.ts +20 -0
  86. package/packages/core/src/operator/index.ts +4 -0
  87. package/packages/core/src/operator/protocol.ts +6 -0
  88. package/packages/core/src/operator/registry.ts +42 -1
  89. package/packages/core/src/operator/tickets.ts +25 -4
  90. package/packages/core/src/plugins/manifest.ts +2 -1
  91. package/packages/core/src/ports/runner/account-env.ts +139 -0
  92. package/packages/core/src/ports/runner/chatgpt-provider.ts +85 -0
  93. package/packages/core/src/ports/runner/claude.ts +70 -42
  94. package/packages/core/src/ports/runner/codex.ts +63 -31
  95. package/packages/core/src/ports/runner/one-shot.ts +2 -0
  96. package/packages/core/src/ports/runner/provider-error.ts +5 -0
  97. package/packages/core/src/ports/runner/routing.ts +35 -4
  98. package/packages/core/src/ports/tickets/contract.ts +58 -0
  99. package/packages/core/src/ports/tickets/tree.ts +1 -1
  100. package/packages/core/src/ports/types.ts +28 -7
  101. package/packages/core/src/ports/workspace/account-policy.ts +72 -0
  102. package/packages/core/src/ports/workspace/build-execution.ts +6 -1
  103. package/packages/core/src/ports/workspace/builtin-capabilities.ts +1 -0
  104. package/packages/core/src/ports/workspace/create.ts +2 -0
  105. package/packages/core/src/ports/workspace/git-worktree.ts +6 -1
  106. package/packages/core/src/ports/workspace/provider-capabilities.ts +1 -0
  107. package/packages/core/src/ports/workspace/vercel-sandbox.ts +125 -35
  108. package/packages/core/src/processes/build-runner.ts +32 -1
  109. package/packages/core/src/processes/dispatcher.ts +493 -121
  110. package/packages/core/src/processes/execution-no-progress.ts +1 -0
  111. package/packages/core/src/processes/execution-settlement.ts +21 -3
  112. package/packages/core/src/processes/harvest-runner.ts +68 -8
  113. package/packages/core/src/processes/harvest.ts +11 -16
  114. package/packages/core/src/processes/repo-view.ts +3 -0
  115. package/packages/core/src/project-secrets.ts +105 -0
  116. package/packages/core/src/secret-name.ts +41 -0
  117. package/packages/core/src/store/account-redaction.ts +156 -0
  118. package/packages/core/src/store/artifact-meta.ts +7 -0
  119. package/packages/core/src/store/contract.ts +60 -1
  120. package/packages/core/src/store/memory.ts +4 -0
  121. package/packages/core/src/store/reducer-value-shapes.json +7389 -6647
  122. package/packages/core/src/store/reducer-value-validation.ts +106 -6
  123. package/packages/core/src/store/remote/client.ts +85 -50
  124. package/packages/core/src/store/remote/compatibility.ts +57 -0
  125. package/packages/core/src/store/remote/index.ts +6 -0
  126. package/packages/core/src/store/remote/protocol.ts +8 -1
  127. package/packages/core/src/store/remote/released-reducer-values/1.2.0.json +8129 -0
  128. package/packages/core/src/store/remote/version.ts +4 -0
  129. package/packages/core/src/store/repo-state-events.ts +4 -2
  130. package/packages/core/src/store/snapshots.ts +16 -3
  131. package/packages/core/src/store/types.ts +2 -0
  132. package/packages/core/src/testing/dispatch-read-budget.ts +266 -5
  133. package/packages/core/src/testing/index.ts +2 -1
  134. package/packages/core/src/testing/reduced-read-budget.ts +560 -5
  135. package/skills/guide/SKILL.md +164 -37
  136. package/skills/guide/references/accounts.md +130 -0
  137. package/skills/guide/references/integration-tree.md +16 -5
  138. package/skills/guide/references/merge-policy.md +1 -3
  139. package/skills/guide/references/operator-api.md +144 -53
  140. package/skills/guide/references/plugin-authoring.md +27 -1
  141. package/skills/guide/references/remote-store-protocol.md +259 -91
  142. package/skills/guide/references/remote-ticket-protocol.md +29 -49
  143. package/skills/guide/references/restacking.md +45 -0
  144. package/skills/guide/references/setup.md +34 -129
  145. package/skills/guide/references/spec-standard.md +4 -2
  146. package/skills/guide/references/ticket-dependencies.md +8 -0
  147. package/skills/harvest/SKILL.md +3 -1
  148. package/skills/harvest-review/SKILL.md +3 -1
  149. package/skills/operate/SKILL.md +26 -11
  150. package/skills/reconcile/SKILL.md +6 -0
  151. package/skills/spec/SKILL.md +1 -1
  152. package/skills/tickets/SKILL.md +10 -5
  153. package/templates/hosted-service/package.json +2 -2
  154. package/docs/hosted-dispatcher-cutover-validation.md +0 -178
  155. package/docs/hosted-dispatcher.md +0 -278
  156. package/docs/hosted-service.md +0 -304
  157. package/docs/mcp.md +0 -150
@@ -52,7 +52,8 @@ When `[tickets].source = "hosted"`, use readable ids such as `ENG-12` with
52
52
  `ab ticket show`, `update`, `move`, `block`, and `unblock`. Inputs accept any
53
53
  letter case and old UUID ids remain aliases. Output shows canonical readable
54
54
  ids; blocker references use the same identity. Numbering belongs to each project
55
- and never resets or reuses deleted numbers. A `teamKey` change affects future
55
+ and never resets or reuses deleted numbers within a project lifetime. Permanent
56
+ project deletion removes the counter; browser-approved reconnection starts at 1. A `teamKey` change affects future
56
57
  prefixes only. File and Linear id rules are unchanged. See the
57
58
  [hosted ticket protocol](../ab-guide/references/remote-ticket-protocol.md).
58
59
 
@@ -69,7 +70,7 @@ dispatcher never moves tickets into it and never dispatches from it unless
69
70
  .autobuild/tickets/
70
71
  triage/ # filed, not groomed — the inbox
71
72
  ready/ # groomed; file lifecycle-state gate satisfied
72
- doing/ # claimed; a build is running
73
+ doing/ # claimed; preparing or running a build
73
74
  done/ # merged
74
75
  icebox/ # example of a repo-added state, present only once created
75
76
  ```
@@ -97,7 +98,7 @@ succeeds.
97
98
 
98
99
  For dependencies on any source, follow the
99
100
  [safe blocker-filing workflow](../ab-guide/references/ticket-dependencies.md).
100
- Direct and hosted Linear record blockers after creating the issue, so a ready
101
+ Direct Linear record blockers after creating the issue, so a ready
101
102
  issue can be claimed before `create --blocked-by` returns. Stage dependents in a
102
103
  known non-ready state, verify all blockers with `ab ticket show --json`, then use
103
104
  `ab ticket move` to publish the intended ready destination. Do not use the local
@@ -164,9 +165,13 @@ capacity. Blocker edits must use the source-agnostic `ab ticket block` and
164
165
 
165
166
  When the dispatcher claims an eligible file ticket, it moves it to `doing/`,
166
167
  then to `done/` on merge or back to `triage/` if the build aborts or the spec
167
- bounces.
168
+ bounces. A caught failure before build creation returns it to configured Ready
169
+ after safe ownership checks; unfinished recovery stays durably tracked and
170
+ withheld from another claim. Uncertain ownership or externally changed/missing
171
+ tickets end automatic recovery with an `abandoned` resolution, leaving the
172
+ ticket unchanged for operator inspection. See [preparation recovery](../ab-guide/references/restacking.md#ticket-preparation-before-build-creation).
168
173
 
169
- **Don't hand-move anything out of `doing/`** — a build owns it. If you need to
174
+ **Don't hand-move anything out of `doing/`** — dispatch preparation or a build owns it. If you need to
170
175
  stop a build, that's `ab` (or a human), not `mv`.
171
176
 
172
177
  Before moving work into `ready/` (or any source's configured ready state),
@@ -4,8 +4,8 @@
4
4
  "build": "ab-hosted-service-build"
5
5
  },
6
6
  "dependencies": {
7
- "@defrex/autobuild-hosted-store-service": "1.1.0",
8
- "@defrex/autobuild": "1.1.0",
7
+ "@defrex/autobuild-hosted-store-service": "1.3.0",
8
+ "@defrex/autobuild": "1.3.0",
9
9
  "next": "16.1.6",
10
10
  "react": "19.2.4",
11
11
  "react-dom": "19.2.4"
@@ -1,178 +0,0 @@
1
- # Hosted dispatcher cutover validation — AUT-320
2
-
3
- - **Validation run:** 2026-09-11, window 19:06:24Z – 19:41:52Z; verification re-derived from fresh Store snapshots at 22:41Z and again at 23:29Z after the implement phase re-ran in a fresh workspace (the durable log below is live and keeps accumulating)
4
- - **Build:** `validate-hosted-dispatcher` on `https://autobuild.defrex.com` (durable event log: `GET /builds/validate-hosted-dispatcher/events` or the web dashboard)
5
- - **Branch:** `ab/validate-hosted-dispatcher` (PR publication requested with auto-merge; publication and merge happen after the implement session — the build slug carries the final merged state)
6
- - **Tickets:** [AUT-320](https://linear.app/issue/AUT-320) (this validation), [AUT-304](https://linear.app/issue/AUT-304) (acceptance evidence attached to its body)
7
- - **Method note:** all numbers below were re-derived from fresh Store snapshots at implement time, at the guidance round (repository journal seq 1–926, build event log seq 1–45, as of 2026-09-11T22:41Z), and again at 23:29Z on the re-run implement session (journal seq 1–1117, build event log seq 1–60). Snapshots are labeled as-of; the durable event log is authoritative.
8
-
9
- ## Checklist verdicts
10
-
11
- | Checklist item | Verdict | Evidence |
12
- | --- | --- | --- |
13
- | Environment variables set | ✅ | Hosted ticks deposit `dispatcher-effective-config` artifacts (rev 50 as of 19:54:50Z) declaring workspace provider `vercel-sandbox`, env var `AI_GATEWAY_API_KEY`, AI-gateway model sessions (`vercel-ai-gateway/zai/glm-5.3-flash`, `vercel-ai-gateway/meta/muse-spark-1.3`), and runtime provisioning with preflight checks. Every hosted tick since 19:06 completes and deposits the artifact. |
14
- | Cron live | ✅ | 265 `dispatcher.run-started` events at ≈60 s median cadence from 19:06:24Z through 23:28:50Z (latest snapshot), all run ids `hosted-dispatcher-<uuid>`, all 265 ending `run-stopped outcome=normal`. |
15
- | Harvest gate off | ✅ | Last `harvest.completed` at 03:05:04Z (journal seq 59); no `harvest.*` event since. |
16
- | Local `ab-dispatch-kernel` stopped on every maintainer machine | ✅ (store-side layers + maintainer attestation with attached evidence) | Three-layer verification below. The store-side layers prove no interactive local dispatcher ever wrote to this repository and no dispatcher of any mode claimed build work in the window; the process-level residue on maintainer machines is covered by the maintainer's attestation with attached command output (see Process evidence). |
17
-
18
- ## Three-layer verification
19
-
20
- The journal alone cannot prove absence of local dispatchers: only the interactive
21
- frontend's child kernel carries a `kernelRunId`, so a headless local run
22
- (`ab dispatch --once --plain`) writes no `dispatcher.run-started`/tick events at
23
- all. The verification therefore stacks three bounded layers.
24
-
25
- ### Layer 1 — Repository journal (proves: hosted cadence live; no *interactive* local dispatcher)
26
-
27
- Journal seq 1–1117, complete from 2026-09-11T02:17:59Z (no gaps; the hosted
28
- repository store came up that morning). Re-derived 22:41Z and again 23:29Z.
29
- Findings:
30
-
31
- - 265 `dispatcher.run-started` events — **every one** with run id prefixed
32
- `hosted-dispatcher-`; zero bare-UUID (interactive local) run ids in the
33
- entire journal history.
34
- - Cadence ≈60 s median (min 11 s, max 63 s; first 19:06:24Z, last in snapshot
35
- 23:28:50Z); 265/265 `run-stopped` with `outcome=normal`.
36
- - The only two `dispatcher.tick-yielded` events (seq 144, 19:25:50Z; seq 1111,
37
- 23:27:52Z) are both hosted→hosted (run/holder ids all `hosted-dispatcher-*`).
38
- - No `harvest.*` event after 03:05:04Z (none after the window opened).
39
- - Zero journal events mention any maintainer hostname (`aron-desktop` does not
40
- appear anywhere in the journal).
41
-
42
- **Bound:** proves nothing about headless local dispatchers, which never write
43
- journal events.
44
-
45
- ### Layer 2 — Build-scoped execution facts (proves: no dispatcher of *any* mode claimed work in the window)
46
-
47
- A dispatcher that actually claims and works a build writes build-scoped facts
48
- regardless of interactive/headless mode: `workspace.provision-started` and,
49
- decisively, `execution.started` whose `instance` is
50
- `${hostname()}-${slug}-inst_<id>` — a plain store append, never gated on
51
- `kernelRunId`. The hosted deployment stamps the Vercel function's hostname
52
- (link-local `169.254.x.x` form); a maintainer machine's dispatcher would stamp
53
- its own hostname.
54
-
55
- - Build census (store `GET /builds`): the only build created after the window
56
- opened is `validate-hosted-dispatcher` (19:06:33Z); no older build was
57
- updated during the window (re-derived 22:41Z and again 23:29Z).
58
- - This build's `execution.started` events both stamp hosted instances:
59
- seq 21 (19:26:06Z, generation 0)
60
- `instance=169.254.67.163-validate-hosted-dispatcher-inst_e031dd81`,
61
- `provider=vercel-sandbox`, `sessionId=sbx_d4pBpd0TAJQyKxBW0setr3e8F7sE`;
62
- seq 56 (23:28:09Z, generation 1)
63
- `instance=169.254.30.93-validate-hosted-dispatcher-inst_d69843ce` —
64
- the hosted host component in both cases.
65
- - Zero `execution.started` events with a foreign hostname in the window;
66
- zero `workspace.provision-started` events anywhere in the store's builds
67
- outside this build during the window.
68
-
69
- **Bound:** an idle local dispatcher that claims nothing still leaves no trace;
70
- that residue is covered by Layer 3.
71
-
72
- **Recovery-fact caveat (recorded for honesty):** `infrastructure.failed`
73
- recovery facts carry the fixed instance name `dispatcher-recovery` and are
74
- attributed to the supervising (hosted) tick, so they are bounded by the hosted
75
- tick cadence rather than their own instance string. This build's three
76
- `infrastructure.failed` events are all provision failures of the incident
77
- below.
78
-
79
- ### Layer 3 — Maintainer-machine process evidence (supplied by the maintainer)
80
-
81
- An idle local `ab dispatch` process that claims nothing leaves no store trace,
82
- so this layer cannot be derived from the Store. The implementer escalated
83
- (`esc_e93b2831`, raised from this build) asking the maintainer to run, on every
84
- maintainer machine during the window, `pgrep -fl "ab-dispatch-kernel|ab
85
- dispatch"` plus scheduler listings (launchd/cron/systemd user timers) and
86
- attach the output to the escalation answer. The maintainer answered with a
87
- full attestation **and attached command output**, folded into the Process
88
- evidence section below.
89
-
90
- ## Process evidence (maintainer attestation, escalation esc_e93b2831)
91
-
92
- The maintainer collected the evidence at 2026-09-11T19:49Z on **aron-desktop**
93
- — the **only** maintainer machine (Linux; there is no macOS or Windows
94
- maintainer machine, so launchd/launchctl and PowerShell checks do not apply).
95
- Summary of the attached evidence:
96
-
97
- 1. **Processes.** `pgrep -fl "ab-dispatch-kernel|ab dispatch"` found exactly
98
- two processes (1096539 `bun …/bin/ab.ts dispatch`, 1096573
99
- `bun …/bin/ab-dispatch-kernel.ts`), both started 19:39:54Z, both with
100
- working directory `/home/defrex/code/parakeeto` — a **different
101
- repository's checkout** with its own Store repository identity. They cannot
102
- claim or supervise builds for `https://github.com/defrex/autobuild`. No `ab
103
- dispatch` process with cwd `/home/defrex/code/autobuild` exists.
104
- 2. **Last local dispatcher for this repository.** A headless `ab dispatch
105
- --plain --auto-merge` (kernel run id prefix `aron-desktop-*`) exited at
106
- 18:06:13Z — its log ends "dispatcher superseded by another invocation —
107
- detaching / ab dispatch stopped" — 60 minutes **before** the validation
108
- window opened at 19:06Z. It was never restarted.
109
- 3. **User schedulers.** `crontab -l` → crontab is not installed on the machine
110
- (no user cron entries possible); `systemctl --user list-timers --all` → "0
111
- timers listed". No launchd (not macOS).
112
- 4. **Corroborating durable evidence.** Every `dispatcher.run-started` /
113
- tick / `run-stopped` fact for this repository from 19:06:24Z onward carries
114
- a `hosted-dispatcher-<uuid>` run id (first:
115
- `hosted-dispatcher-c5fa724f-fa11-4250-8dbb-3274510a2022`); no
116
- `aron-desktop-*` holder appears in the journal after 18:06Z. This build's
117
- own `execution.started` (seq 21) names instance
118
- `169.254.67.163-validate-hosted-dispatcher-inst_e031dd81` — a hosted
119
- function address, not a maintainer host.
120
-
121
- **Maintainer conclusion (verbatim intent):** no local `ab dispatch` process for
122
- this repository was running during 19:06–19:42Z, and none is running now.
123
- Recorded as maintainer attestation with the attached outputs; the store-side
124
- Layers 1–2 independently prove no dispatcher of any mode claimed or executed
125
- build work in the window.
126
-
127
- ## Provision incident (honest record)
128
-
129
- The first three provision attempts failed with
130
- `Executable not found in $PATH: "bun"` (19:06–19:15Z) — the exact symptom
131
- `docs/hosted-dispatcher.md` documents for a deployment that skipped
132
- `pack-distribution`. After `maxInfrastructureAttempts` (3) was exhausted the
133
- kernel raised escalation `esc_84b0cddf` (19:15:51Z, policy guard
134
- `infrastructure-failure-limit`); the operator answered with a bare retry at
135
- 19:24:37Z, and provisioning succeeded at 19:25:51Z on the next hosted tick.
136
- The generation-1 re-provision (23:26:54Z → 23:27:53Z, after the publication
137
- note below) succeeded with no operator intervention.
138
- **Verdict: the cutover works, with one operator intervention.** A follow-up
139
- observation was recorded for the deployment's build/pack step.
140
-
141
- ## Publication note (honest record)
142
-
143
- The implement phase requested publication at 22:43:01Z (event seq 49,
144
- `publication.requested`; auto-merge had been requested at build creation,
145
- seq 2). That first publication did not complete before the implement
146
- workspace's environment lifetime ended: `execution.ended` at 23:26:51Z
147
- (seq 51), the workspace was released, and a fresh generation-1 workspace was
148
- provisioned for the re-run implement session. The prior workspace's un-pushed
149
- commits were lost with it; store-side deposits (build artifacts, observations,
150
- the escalation answer, the AUT-304 evidence section) persisted. This session
151
- re-committed the repository deliverable (this document) and re-requests
152
- publication. Publication, verify, review, and merge happen after this
153
- session; the build slug `validate-hosted-dispatcher` carries the final state.
154
- A follow-up observation was recorded for the publication path.
155
-
156
- ## Cutover outcome (as of implement time)
157
-
158
- - Ticket moved to Todo → claimed and built by the hosted deployment alone:
159
- **confirmed** (Layers 1–2; single active build, hosted execution instances).
160
- - Published as a PR, and merged: PR publication is **requested** (auto-merge
161
- requested at build creation; publication re-requested by this session) from
162
- branch `ab/validate-hosted-dispatcher` into `main`; verify, review,
163
- publication, and merge happen after this session, and the build slug
164
- `validate-hosted-dispatcher` on the dashboard carries the final state. This
165
- document deliberately does not claim "published" or "merged".
166
-
167
- ## Evidence index
168
-
169
- - Build event log (durable, live): `https://autobuild.defrex.com` → build
170
- `validate-hosted-dispatcher` (API: `GET /builds/validate-hosted-dispatcher/events`)
171
- - Repository journal (durable, live): `GET /repos/https%3A%2F%2Fgithub.com%2Fdefrex%2Fautobuild/events`
172
- - Deposited build artifacts: `cutover-build-event-log`, `cutover-repository-journal`,
173
- `cutover-validation-report` (attached to the PR description at finalize)
174
- - Dispatcher effective config: repository artifact kind
175
- `dispatcher-effective-config`, rev 50 as of 2026-09-11T19:54:50Z
176
- - Branch: `ab/validate-hosted-dispatcher` → PR into `main` (auto-merge requested)
177
- - Tickets: [AUT-320](https://linear.app/issue/AUT-320),
178
- [AUT-304](https://linear.app/issue/AUT-304) (evidence section appended to body)
@@ -1,278 +0,0 @@
1
- # The hosted dispatcher
2
-
3
- The optional [`@defrex/autobuild-hosted-dispatcher`](../packages/hosted-dispatcher/README.md)
4
- package lets a deployment own the dispatch kernel. Installing it and mounting
5
- its route — `GET /api/dispatch`, backed by the package's
6
- `dispatcherEndpoint()` singleton — makes the hosted deployment the kernel
7
- owner. One authenticated HTTP invocation runs, for each configured
8
- repository, one bounded origin-mode dispatcher
9
- tick: the kernel claims ready tickets, provisions and launches sandboxes,
10
- observes running builds, settles publications, opens and merges PRs, and runs
11
- the janitor, exactly as a local `ab dispatch --once --repository <origin>`
12
- pass does. The schedule is what you attach to that endpoint (Vercel Cron calls
13
- it once a minute by default), so builds no longer depend on a maintainer's
14
- machine. A deployment that does not install the package serves the hosted
15
- store, ticket, operator, and web endpoints and never attempts a dispatch tick.
16
-
17
- The [minimal hosted service deployment](hosted-service.md) defaults to store-only
18
- mode and supplies no cron. The source-checkout deployment below retains the
19
- opt-in dispatcher packing and shipping pipeline.
20
-
21
- For a dispatcher running as a local user or service manager, first
22
- [connect the project](hosted-service.md#connect-a-project). Origin-mode dispatch
23
- can read the committed `[store] url` and the same user credential by origin.
24
- A deployment running under another identity needs its own project credential;
25
- `AB_TOKEN` remains the explicit CI override.
26
-
27
- ## Enabling the schedule
28
-
29
- 1. Deploy the hosted service with the dispatcher package installed and the
30
- dispatcher variables from
31
- [its README](../packages/hosted-dispatcher/README.md)
32
- — `AB_DISPATCHER_ORIGIN`, the repository set, `CRON_SECRET`, and the forge
33
- credentials the kernel needs (`GITHUB_TOKEN` or `GH_TOKEN`, plus any
34
- guest-forwarded variables such as `AI_GATEWAY_API_KEY`). A deployment
35
- serving repositories across GitHub identities configures per-repository
36
- tokens with `AB_DISPATCHER_GITHUB_TOKENS`; repositories without an
37
- override keep using the shared credential. A served repository with
38
- neither fails its tick: origin-mode dispatch requires an exported token
39
- and never falls back to the gh CLI login of whoever runs the service.
40
- 2. Schedule the route by adding a `crons` entry to the deployment's
41
- `vercel.json` and redeploying. Vercel issues a plain GET with
42
- `Authorization: Bearer <CRON_SECRET>` once per minute:
43
-
44
- ```json
45
- {
46
- "crons": [{ "path": "/api/dispatch", "schedule": "* * * * *" }]
47
- }
48
- ```
49
-
50
- 3. Verify: `curl -H "Authorization: Bearer $CRON_SECRET" https://YOUR_ORIGIN/api/dispatch`
51
- returns `200 {"ok":true,"repositories":[{"repository":"…","outcome":"ticked","runId":"hosted-dispatcher-…"}]}`.
52
- Unauthenticated or wrongly authorized calls are rejected (401) and do no
53
- work; a deployment without `CRON_SECRET` answers 403 with the endpoint
54
- disabled. One repository's failure never prevents another's tick.
55
-
56
- ## Shipping the guest distribution
57
-
58
- Every sandbox installs the Autobuild distribution the launching dispatcher
59
- runs. A local dispatcher packs it from its source checkout with `bun pm pack`;
60
- a bundled deployment has neither `bun` nor a source tree at runtime, so it
61
- must pack the archive while both exist — in its build step — and carry it into
62
- the function bundle. The script lives in the hosted store service package
63
- (`packages/hosted-store-service/package.json`), whose directory is the Next.js
64
- project directory and the deployment build's working directory:
65
-
66
- ```json
67
- { "scripts": { "deploy:build": "bun ../../packages/hosted-dispatcher/src/bin.ts pack-distribution --root . && bun ../../packages/postgres-store/src/bin.ts migrate && bun run build && bun ../../packages/hosted-dispatcher/src/ship-packed-distribution.ts && bun ../../packages/hosted-dispatcher/src/ship-provider-plugin.ts" } }
68
- ```
69
-
70
- `pack-distribution` (the `ab-hosted-dispatcher` bin) writes
71
- `.autobuild-dist/autobuild-<version>.tgz` under the
72
- distribution root (`--root DIR` overrides) — this deployment passes
73
- `--root .`, because the packer's default root is the repository's distribution
74
- root while the trace step below and the Next config's
75
- `outputFileTracingIncludes: { '/api/dispatch': ['./.autobuild-dist/**'] }`
76
- resolve against the deployment build's working directory, where the archive
77
- must merge beside the built output. The Next.js config's
78
- `outputFileTracingIncludes` records the intent to include that directory in the cron route's bundle, but
79
- Next 16's default Turbopack builds never apply `outputFileTracingIncludes`
80
- (only webpack builds do), so a deployment cannot rely on the config alone. The
81
- autobuild-api pipeline therefore ends `deploy:build` with a post-build trace
82
- step (`bun ../../packages/hosted-dispatcher/src/ship-packed-distribution.ts`) that appends the archive to the
83
- dispatch route's `route.js.nft.json` — the trace file Vercel's Next builder
84
- consumes when assembling the function bundle — and fails the deploy loudly if
85
- nothing was packed or the trace file is missing. The same step appends the
86
- distribution root's `package.json`, which provisioning reads for the running
87
- version and which no import traces once the Next.js project directory sits
88
- below the repository root. A deployment using this
89
- pipeline cannot ship without the archive; deployments that skip both packing
90
- and the trace step still fail at runtime.
91
-
92
- A second post-build trace step ships the provider plugin package (AUT-517):
93
- `bun ../../packages/hosted-dispatcher/src/ship-provider-plugin.ts` locates the
94
- plugin's source through the repository root's `workspaces` tree (never through
95
- `node_modules`, so a previous run's staged directory cannot shadow the source),
96
- bundles its entrypoint with `bun build --target=bun --format=esm` into a
97
- single self-contained module (the plugin-sdk closure inlines — the
98
- deployment's repository-root `node_modules` carries no `@defrex/autobuild`
99
- either — while node builtins stay external), stages it into
100
- `<repoRoot>/node_modules/@defrex/autobuild-vercel-sandbox/` (replacing the
101
- workspace symlink a local `bun install` leaves there — or a previous run's
102
- staged directory, which `bun install` does not relink; the deployment never
103
- runs `bun install` again), and appends the staged files to the dispatch
104
- route's trace at the same repository-root depth as the existing
105
- `node_modules/.bun/**` entries. A bare plugin specifier resolves only
106
- through a `node_modules/` path, and the compiled dispatcher's
107
- `distributionRoot()` is the repository root, so only this staging makes
108
- `plugins = ["@defrex/autobuild-vercel-sandbox"]` loadable inside the
109
- deployed function. The step is idempotent across runs — including in a
110
- fresh process after an earlier run consumed the workspace link — and fails
111
- the deploy loudly when the package, its entrypoint, or the trace file is
112
- missing. The npm published package remains the real `src` — only the
113
- deployment stages the bundle.
114
-
115
- What the staged directory does afterwards depends on the build environment.
116
- Inside a Vercel deployment build (which always sets `VERCEL`, including a
117
- local `vercel build` run) the staged directory stays: the deployment never
118
- runs `bun install` again and the function bundle's runtime resolution needs
119
- it — a deployment building outside Vercel must set `VERCEL=1` in its build
120
- environment to keep the staged bundle. A plain local `bun run deploy:build`
121
- (no `VERCEL` environment) removes the staged directory afterwards and
122
- restores the workspace symlink, so a local run leaves the checkout exactly
123
- as `bun install` had it and local test runs keep resolving the workspace
124
- source (the capability parity test's reference equality holds). On checkouts
125
- of older versions the staged directory stayed behind and survived `bun
126
- install` — it reports "no changes" because the staged package satisfies the
127
- manifest — so later local runs resolved the plugin to the self-contained
128
- bundle and the parity test failed on its reference-equality assertion; the
129
- recovery is `rm -rf node_modules/@defrex/autobuild-vercel-sandbox && bun
130
- install`, or simply re-run `deploy:build` locally on a version with this
131
- fix, which restores the symlink itself.
132
-
133
- At runtime the kernel takes, in order: `AB_DISTRIBUTION_ARCHIVE` (an explicit
134
- archive path), the single archive under `.autobuild-dist/` of the
135
- distribution root or working directory, a source checkout packed on the spot,
136
- and finally the running version's published distribution — the npm registry
137
- tarball, else the GitHub release asset. A tick that
138
- reports `Executable not found in $PATH: "bun"` during `provision` is a
139
- deployment that skipped the pack step (or, outside this pipeline, the trace
140
- step that ships the archive).
141
-
142
- ## Bounding the invocation
143
-
144
- The endpoint is pinned to `maxDuration = 300` seconds (Vercel Pro's default
145
- function duration). `AB_DISPATCHER_BUDGET_SECONDS` (default 240) bounds the
146
- kernel's work inside that: an already-expired budget skips the tick, a budget
147
- reached mid-drain stops awaiting running builds, and a repository whose budget
148
- no longer covers a minimum-remaining floor is answered as `skipped`. Unfinished
149
- work resumes on the next invocation: guests keep running while the supervising
150
- function detaches, and the next tick settles their completion from the Store
151
- plus provider liveness. Raise `maxDuration` and the budget **together** (e.g.
152
- `"maxDuration": 800` with a budget of 780 — the parser clamps 10–780); keep the
153
- budget at least ~20 s below the function duration so the response always
154
- returns.
155
-
156
- ## Overlap and missed ticks
157
-
158
- Invocations are serialized by the durable repository supervisor lease: a second
159
- overlapping invocation yields (it records `dispatcher.tick-yielded` naming the
160
- holder in the repository journal and performs no claims, launches, or
161
- publications), and the loser's response still answers 200. A missed or late
162
- invocation is never incorrect: a build whose guest finished while no invocation
163
- ran is settled — completion facts, lease, publication — by the next
164
- invocation's settlement stage, and a build whose sandbox timed out is recovered
165
- by the lease sweep as with any dispatcher.
166
-
167
- One provider behavior matters for that settlement: Vercel's plain command
168
- lookup reports no exit code for a command that finished while no client was
169
- waiting on it, and keeps reporting none until some client issues a wait on the
170
- command. The dispatcher's execution observation therefore issues one bounded
171
- (~5 s) wait on the recorded command whenever the lookup shows no exit: a wait
172
- that resolves proves the guest command's end (with its exit code). Before
173
- settlement the provider must also confirm that the whole sandbox has stopped,
174
- including descendants. A failed or ambiguous stop leaves the execution and lease
175
- open, with publication and relaunch deferred until a later tick confirms teardown.
176
- A timed-out command wait leaves the guest running — one
177
- observation never approaches the tick's operation timeout, and the next tick
178
- retries. Settlement of a guest that exited after the launching invocation
179
- detached is expected within one tick of its exit.
180
-
181
- ## Pausing during an incident
182
-
183
- - **Stop the schedule**: remove the `crons` entry (or disable the cron in the
184
- Vercel dashboard) and redeploy.
185
- - **Revoke the credential**: rotate `CRON_SECRET` — every in-flight schedule
186
- call starts answering 401.
187
- - **Soft stop**: turn repository intake OFF (operator API `PUT
188
- /operator/v1/repos/{repo}/settings/intake` with `{"enabled": false}`, or the
189
- web dashboard) — running builds finish their current phases but no new ticket
190
- is claimed. A repository-wide or per-build pause holds queued work the same
191
- way and takes effect on the next invocation.
192
-
193
- ## Observing the hosted dispatcher
194
-
195
- Every invocation is durable: tick reports
196
- (`dispatcher.tick-started`/`-completed`/`-yielded`), run boundaries
197
- (`dispatcher.run-started`/`-stopped`), and a per-minute
198
- `dispatcher-effective-config` artifact deposit all carry the
199
- `hosted-dispatcher-<uuid>` run id, so the web dashboard's repository journal
200
- and the operator API show hosted activity exactly as they show a local
201
- dispatcher. Expect the repository journal to grow by roughly one config
202
- artifact per minute per repository; the dispatcher run/config artifacts
203
- themselves are retention-bounded (see below), while the journal's events keep
204
- accumulating by design.
205
-
206
- This is true of *every* dispatcher, not only the hosted one. A local `ab
207
- dispatch` pointed at the hosted Store — a watch, an operator cron on a host,
208
- a manual one-shot — synthesizes its own `<host>-dispatch-<id>` run id and
209
- journals the same run boundaries and tick facts under it. That makes cutover
210
- verification answerable from the journal alone:
211
-
212
- - Every `dispatcher.*` event with a non-`hosted-dispatcher` run id is direct
213
- evidence that another dispatcher was writing to the hosted Store.
214
- - A journal window with no `dispatcher.*` events at all means no dispatcher
215
- ran against the Store in that window.
216
- - The launch-flag facts (`dispatcher.intake-set`,
217
- `dispatcher.auto-merge-default-set`) carry the writing invocation's run id
218
- alongside their human actor, so even those writes identify the dispatcher
219
- that performed them.
220
-
221
- ### Runtime logs
222
-
223
- Every invocation also writes to the deployment's runtime logs (Vercel's
224
- **Logs** tab, or `vercel logs`), which is where to look first when the journal
225
- shows no hosted activity at all — a rejected or misconfigured invocation never
226
- reaches the journal. Every line starts with `hosted-dispatcher <invocation id>`
227
- so one invocation's lines can be filtered together:
228
-
229
- - the request line (`GET /api/dispatch agent="vercel-cron/1.0"`) — the user
230
- agent tells a cron call apart from an operator's curl;
231
- - `rejected 401|403|405 <kind>: <reason>` at error level, with whether the
232
- authorization header was absent or present-but-wrong (never its value);
233
- - `500 configuration invalid: <error>` naming the offending variable;
234
- - `tick start repositories=N budgetSeconds=S origin=…`, then per repository
235
- `tick run=hosted-dispatcher-…`, `ticked … ms=…`, `skipped`, or
236
- `failed … : <error with stack>` at error level, then
237
- `tick complete ticked=… failed=… skipped=…` and `200 ok ms=…`;
238
- - the kernel's own report lines (the same lines `ab dispatch --plain` prints
239
- locally) prefixed `<repository> [kernel]`, warnings at error level.
240
-
241
- Secrets, forge tokens, and minted guest tokens never appear in any line.
242
-
243
- ## Artifact retention
244
-
245
- Dispatcher-generated run/config artifacts — the repository-scoped
246
- `dispatcher-effective-config` and `dispatcher-config` kinds and the
247
- build-scoped `build-runner-effective-config` kind — keep the **latest 200
248
- revisions per kind** (per repository, respectively per build). When a new
249
- revision of one of these kinds is deposited, the store prunes the older
250
- revisions past the bound at deposit time, inside the same transaction.
251
- Events and journal entries are never pruned, so historical event payloads may
252
- reference a pruned revision; the current run's snapshot is always among the
253
- newest deposits and stays retrievable, and every existing read surface
254
- (latest-by-default artifact reads, listings) works unchanged. The bound is
255
- overridable per deployment with `AB_ARTIFACT_RETENTION_MAX_REVISIONS` (a
256
- positive integer; see the store environment documentation). All other
257
- artifact kinds (build logs, `pr-description`, phase artifacts) are not
258
- subject to retention.
259
-
260
- ## Sandbox authentication
261
-
262
- Inside a Vercel Function the Sandbox SDK authenticates with the deployment's
263
- own OIDC identity: Vercel hands each invocation its token on the
264
- `x-vercel-oidc-token` request header (not as a `VERCEL_OIDC_TOKEN` environment
265
- variable), and the endpoint passes it to the kernel under that name for the
266
- duration of the tick. The tick log line reports which credential the kernel
267
- presents (`sandboxAuth=oidc-header`, `oidc-env`, `token`, or `none`); `none`
268
- means the project has OIDC federation disabled (Settings → Security). No
269
- long-lived `VERCEL_TOKEN` belongs on the service. Guests never receive a Vercel
270
- token or forge credential; they authenticate to the Store with the short-TTL
271
- stored project credential the dispatcher issues for each repository tick
272
- (`AB_DISPATCHER_TOKEN_TTL_SECONDS`, default 7 days — keep it longer than your
273
- largest `timeoutSeconds` guest lifetime). Its immutable dispatcher purpose
274
- permits raw Store and hosted tickets only, never operator controls. The service
275
- checks registration and revocation on each request. Tick return does not revoke
276
- it; spawned builds may outlive the tick. Owner-issued project credentials and
277
- the owner-only break-glass admin are documented in the
278
- [remote Store protocol](remote-store-protocol.md#7-authentication-and-project-authority).