@defrex/autobuild 1.16.0 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +91 -7
  3. package/docs/answering-blocked-builds.md +34 -1
  4. package/docs/architecture.md +15 -1
  5. package/docs/configuration.md +33 -4
  6. package/docs/operator-api.md +15 -5
  7. package/docs/plugin-authoring.md +1 -0
  8. package/docs/remote-store-protocol.md +13 -3
  9. package/docs/remote-ticket-protocol.md +3 -1
  10. package/docs/restacking.md +41 -1
  11. package/docs/setup.md +15 -6
  12. package/docs/troubleshooting.md +39 -2
  13. package/docs/workspaces.md +2 -0
  14. package/package.json +3 -3
  15. package/packages/core/src/cli/accounts.ts +3 -0
  16. package/packages/core/src/cli/binary-direct.ts +14 -1
  17. package/packages/core/src/cli/binary.ts +10 -7
  18. package/packages/core/src/cli/dispatch.ts +503 -334
  19. package/packages/core/src/cli/secrets.ts +2 -0
  20. package/packages/core/src/config/schema.ts +15 -2
  21. package/packages/core/src/events/payloads.ts +8 -5
  22. package/packages/core/src/kernel/engine.ts +118 -0
  23. package/packages/core/src/kernel/reconcile-restack.ts +72 -9
  24. package/packages/core/src/kernel/tracked-dirt.ts +173 -0
  25. package/packages/core/src/ontology.ts +1 -0
  26. package/packages/core/src/operator/index.ts +10 -0
  27. package/packages/core/src/operator/merged-builds.ts +51 -0
  28. package/packages/core/src/operator/registry.ts +190 -101
  29. package/packages/core/src/operator/repo-argument.ts +43 -0
  30. package/packages/core/src/ports/tickets/grants.ts +2 -0
  31. package/packages/core/src/ports/tickets/remote.ts +2 -0
  32. package/packages/core/src/ports/types.ts +15 -0
  33. package/packages/core/src/ports/workspace/vercel-command-diagnostics.ts +144 -0
  34. package/packages/core/src/ports/workspace/vercel-sandbox.ts +576 -140
  35. package/packages/core/src/processes/build-child.ts +15 -1
  36. package/packages/core/src/processes/build-runner.ts +349 -20
  37. package/packages/core/src/processes/dispatcher.ts +28 -7
  38. package/packages/core/src/processes/harvest-child.ts +21 -1
  39. package/packages/core/src/processes/harvest-runner.ts +82 -35
  40. package/packages/core/src/processes/phase-failure-budget.ts +1 -0
  41. package/packages/core/src/processes/provisioning-progress.ts +23 -0
  42. package/packages/core/src/processes/repo-view.ts +25 -4
  43. package/packages/core/src/processes/workspace-preparation.ts +1 -0
  44. package/packages/core/src/store/adapter.ts +34 -5
  45. package/packages/core/src/store/build-feed.ts +148 -22
  46. package/packages/core/src/store/build-scope.ts +12 -3
  47. package/packages/core/src/store/caller-attribution.ts +170 -0
  48. package/packages/core/src/store/contract.ts +1038 -165
  49. package/packages/core/src/store/local/schema.ts +12 -1
  50. package/packages/core/src/store/local/store.ts +260 -25
  51. package/packages/core/src/store/memory.ts +156 -9
  52. package/packages/core/src/store/phase-session.ts +23 -3
  53. package/packages/core/src/store/reducer-value-shapes.json +3184 -3175
  54. package/packages/core/src/store/remote/client.ts +90 -11
  55. package/packages/core/src/store/remote/credentials.ts +2 -0
  56. package/packages/core/src/store/remote/index.ts +31 -5
  57. package/packages/core/src/store/remote/protocol.ts +45 -8
  58. package/packages/core/src/store/remote/released-clients.json +11 -0
  59. package/packages/core/src/store/remote/released-reducer-values/1.17.0.json +36367 -0
  60. package/packages/core/src/store/remote/released-reducer-values/index.ts +18 -16
  61. package/packages/core/src/store/session-handle.ts +12 -3
  62. package/packages/core/src/store/types.ts +48 -3
  63. package/packages/core/src/testing/reduced-read-budget.ts +222 -4
  64. package/skills/guide/SKILL.md +46 -8
  65. package/skills/guide/references/operator-api.md +15 -5
  66. package/skills/guide/references/plugin-authoring.md +1 -0
  67. package/skills/guide/references/remote-store-protocol.md +13 -3
  68. package/skills/guide/references/remote-ticket-protocol.md +3 -1
  69. package/skills/guide/references/restacking.md +41 -1
  70. package/skills/guide/references/setup.md +15 -6
  71. package/skills/operate/SKILL.md +24 -3
  72. package/templates/hosted-service/package.json +2 -2
@@ -150,11 +150,30 @@ A repeating `fence deferred by the invocation budget` line with an infrastructur
150
150
 
151
151
  ## A provision is cut off at teardown on several invocations
152
152
 
153
- **Symptom.** A STARTING build's provisioning is abandoned at dispatcher teardown on more than one invocation.
153
+ **Symptom.** A STARTING build records `provisioning abandoned at dispatcher teardown during <stage> after <N>s` on more than one invocation.
154
154
 
155
155
  **Cause.** The provision is longer than one invocation. That is normal: each invocation resumes the same sandbox after its last completed stage, at the commit it cloned, so the provision still finishes.
156
156
 
157
- **Action.** If teardown keeps cutting off the same stage, that one stage outlasts the invocation budget. Report the stage to the instance operator.
157
+ **Action.** If the same stage repeats, it outlasts the invocation or hangs, for example a `provisioning` step stuck on an unreachable package mirror:
158
+
159
+ 1. Set that step's `timeoutSeconds` below the invocation budget. A hang then fails promptly as a charged infrastructure failure with its output, and escalates after `maxInfrastructureAttempts`.
160
+ 2. Report the stage to the instance operator.
161
+
162
+ ## A sandbox provisioning command fails or times out
163
+
164
+ **Symptom.** `bun ab build status`, `dispatch.failed`, a `requires dispatcher-authorized cleanup` message, an infrastructure failure, or a setup escalation quotes `sandbox command <cmd> exited <N>` or `sandbox command <cmd> exceeded its <T>s provisioning timeout after <E>s`.
165
+
166
+ **Reading it.** The message carries:
167
+
168
+ - `stage:` the provisioning stage, such as `checkout`, `bun install`, `system provisioning step <name>`, `dependency install` or `runtime bootstrap <runtime> preflight`
169
+ - `argv:` the command line, with tokens, passwords and authorization headers redacted
170
+ - `cwd:` the guest working directory
171
+ - `stderr (tail):` and `stdout (tail):` the last lines of output, or `output: unavailable (…)` when it could not be read
172
+
173
+ **Action.**
174
+
175
+ - **Exit status:** fix the cause the stderr tail names. For a `provisioning` step, reproduce with `bun ab init --validate`.
176
+ - **Timeout:** check the upstream service the step depends on. Raise its `timeoutSeconds` (at most 840) only when it is genuinely that slow.
158
177
 
159
178
  ## A stage keeps stopping at the work deadline
160
179
 
@@ -174,6 +193,24 @@ stages: settlement 3.1s 6/11 (executions 5/9, harvest 1/2, sandboxes 0/0) · jan
174
193
 
175
194
  **Action.** Report the stage and part to the instance operator with the `stages:` lines from several invocations. A stage stopped by `share` alone is normal under load.
176
195
 
196
+ ## Store traffic burst or database pressure
197
+
198
+ **Symptom.** The store's database is saturated, store requests answer `503`, or request volume jumps with no obvious cause.
199
+
200
+ **Reading the lines.** Every Autobuild client names itself on store and ticket requests with the [`X-Autobuild-Caller` header](remote-store-protocol.md#1-transport-and-conventions). The hosted store service logs one `"type":"autobuild.store-request"` line per request:
201
+
202
+ ```json
203
+ {"type":"autobuild.store-request","method":"GET","path":"/repos/…/events","backend":"store","status":200,"ms":41,"caller":{"kind":"dispatcher","run":"host-dispatch-a1","stage":"janitor"},"principal":{"kind":"project","purpose":"dispatcher","credential":"…"}}
204
+ ```
205
+
206
+ - **`caller.kind`:** `dispatcher` (with `invocation`, `run` and pass `stage`), `runner` (`build` or `harvest`, with the build slug or harvest run), or `operator` (`cli`, `mcp` or `web`).
207
+ - **`caller.stage`:** the pass stage that made the request, `setup` before a hosted run starts, or `teardown`. Work a stage starts, such as provisioning or a harvest trigger, carries that stage.
208
+ - **`caller: null`:** an older client or a non-Autobuild caller. `principal` still names the credential kind.
209
+
210
+ **Cause.** Usually one caller polling or replaying: a stage revisiting many builds, an operator watch, or an older client.
211
+
212
+ **Action.** Count a window of lines by `caller.kind` and `caller.stage` (or `caller.run`, `caller.build`), and report the callers and stages that dominate to the instance operator with a few sample lines.
213
+
177
214
  ## Remote project access
178
215
 
179
216
  **Symptom.** Remote requests refuse a project despite a configured URL.
@@ -116,6 +116,7 @@ Sandbox preparation order:
116
116
  - **Runtimes.** Every primary and alternate runtime needs a pinned install and exact-version preflight, and gets only the credentials named in `environmentVariables`, except declared [accounts](configuration-overview.md#accounts), whose credentials remain on the host and are brokered by egress policy using guest placeholders.
117
117
  - **Repetition.** New sandboxes repeat provisioning and preflights rerun before each build-runner; keep setup idempotent.
118
118
  - **Resumption.** A provision cut off by a dispatcher teardown resumes in place on the next invocation, at the commit it cloned. Stages already completed with unchanged inputs (checkout, Bun, each `provisioning` step, distribution, dependencies, runtime installs) are skipped; a stage whose inputs changed reruns with every stage after it.
119
+ - **Timeouts.** Each `provisioning` step runs under its `timeoutSeconds` (default 600 s, at most 840 s); Bun, distribution, dependency and runtime stages have fixed bounds. The sandbox kills a step that overruns, and provisioning fails with the stage, command, elapsed time and output so far, charged like any infrastructure failure. A dispatcher teardown instead abandons the stage uncharged and names it, with its elapsed time, in `dispatch.failed`.
119
120
  - **Validation.** `bun ab init --validate` runs named provisioning, setup, runtime and Store checks in a disposable environment, deletes it even on failure, and starts no build. For every declared account, including unused accounts, it runs a tool-free model probe through the account's runtime (Claude Code for Claude/Kimi, Codex for ChatGPT); these probes create no ordinary build phase or persistent agent session. Hosted ChatGPT, Claude and Kimi project secrets report readiness from write-only status metadata instead; the first hosted build is the live check.
120
121
  - **Lifetime.** `timeoutSeconds` bounds a sandbox; provider operations have their own timeouts. An intact sandbox resumes. Before replacement, the dispatcher fences it, preserves reachable unpublished commits to build-private archive refs or, where the forge refuses them, BuildStore copies, and records a receipt; the next workspace restores those commits. Loss is limited to already absent or unrecoverable work and uncommitted files; known loss appears in the next session's recovery context. See the [workspace recovery contract](architecture.md#key-boundaries).
121
122
 
@@ -155,4 +156,5 @@ The suite certifies only the basic working copy. Remote execution adds trusted s
155
156
  - Publication reports confirmed SHA and cache tips and supports the required guarded rewrites.
156
157
  - Store grants go through the host's `delegateCredential` callback; never serialize host tokens into execution identity.
157
158
  - An optional `provisionEstimateMs` declares the expected wall time of one `provision`; a bounded dispatcher invocation does not start provisioning with less budget left.
159
+ - `provision` may receive `signal`, the invocation's teardown token: abort in-flight work promptly and record nothing, since the dispatcher records the abandonment. It may also receive `onProgress`: report each stage just before it runs, so a teardown can name it; never throw from it.
158
160
  - `provision` may receive `adoptAbandoned` when the previous attempt at the same generation was cut off by a recorded dispatcher teardown. Finish that environment in place only after verifying it, resuming from verified progress and keeping the commit it already holds; otherwise throw `WorkspaceCleanupRequired`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defrex/autobuild",
3
- "version": "1.16.0",
3
+ "version": "1.17.0",
4
4
  "description": "Agent-driven software delivery from groomed ticket to merged PR",
5
5
  "repository": {
6
6
  "type": "git",
@@ -162,8 +162,8 @@
162
162
  },
163
163
  "devDependencies": {
164
164
  "@biomejs/biome": "2.5.5",
165
- "@defrex/autobuild-postgres-store": "1.16.0",
166
- "@defrex/autobuild-vercel-sandbox": "1.16.0",
165
+ "@defrex/autobuild-postgres-store": "1.17.0",
166
+ "@defrex/autobuild-vercel-sandbox": "1.17.0",
167
167
  "@resvg/resvg-js": "2.6.2",
168
168
  "@types/bun": "^1.3.14",
169
169
  "@types/node": "^24.0.0",
@@ -1,3 +1,4 @@
1
+ import { storeCallerHeaders } from '../store/caller-attribution'
1
2
  import { join } from 'node:path'
2
3
  import { connectedProject } from './connect'
3
4
  import { parseLayeredConfig, readLocalConfig } from '../config/local'
@@ -55,6 +56,7 @@ export async function abAccountsLogin(
55
56
  {
56
57
  headers: {
57
58
  authorization: `Bearer ${credential!.token}`,
59
+ ...storeCallerHeaders(),
58
60
  [AUTOBUILD_VERSION_HEADER]: AUTOBUILD_VERSION,
59
61
  [REMOTE_STORE_PROTOCOL_VERSION_HEADER]: REMOTE_STORE_PROTOCOL_VERSION,
60
62
  },
@@ -125,6 +127,7 @@ export async function abAccountsLogin(
125
127
  headers: {
126
128
  'content-type': 'application/json',
127
129
  authorization: `Bearer ${credential!.token}`,
130
+ ...storeCallerHeaders(),
128
131
  [AUTOBUILD_VERSION_HEADER]: AUTOBUILD_VERSION,
129
132
  [REMOTE_STORE_PROTOCOL_VERSION_HEADER]: REMOTE_STORE_PROTOCOL_VERSION,
130
133
  },
@@ -10,6 +10,7 @@ import { openProductionStore } from './store-opening'
10
10
  */
11
11
  import { join } from 'node:path'
12
12
  import { isSessionlessInvocation, runCli } from './main'
13
+ import { cliStoreCaller, withStoreCaller } from '../store/caller-attribution'
13
14
  import { createUpgradeAgentResolver } from './upgrade-agent'
14
15
  import { loadDotEnv } from './dotenv'
15
16
  import {
@@ -43,10 +44,22 @@ import {
43
44
  withDispatchTerminalRestore,
44
45
  } from './binary-lifecycle'
45
46
 
46
- export async function runDirectBinary(
47
+ /** Every hosted request this invocation makes is attributed to the command
48
+ * that made it (a runner session, an operator command, or a dispatcher). */
49
+ export function runDirectBinary(
47
50
  argv: string[],
48
51
  resolveDashboardRenderer?: DashboardRendererResolver,
49
52
  options: { supervised?: boolean } = {},
53
+ ): Promise<number> {
54
+ return withStoreCaller(cliStoreCaller(argv, process.env), () =>
55
+ runDirectBinaryInScope(argv, resolveDashboardRenderer, options),
56
+ )
57
+ }
58
+
59
+ async function runDirectBinaryInScope(
60
+ argv: string[],
61
+ resolveDashboardRenderer: DashboardRendererResolver | undefined,
62
+ options: { supervised?: boolean },
50
63
  ): Promise<number> {
51
64
  const command = argv[0]
52
65
  // Version identity is installation-local and offline; do not inspect even a
@@ -3,6 +3,7 @@ import { join } from 'node:path'
3
3
  import type { DashboardRendererResolver } from './dashboard/render'
4
4
  import { loadDotEnv } from './dotenv'
5
5
  import { parseDispatchArgs } from './dispatch-args'
6
+ import { withStoreCaller } from '../store/caller-attribution'
6
7
  import { DISPATCH_GENERATION_ENV, DISPATCH_CONDITIONAL_ENV } from './dispatch-launch-contract'
7
8
  export {
8
9
  usesGenericSessionlessSigintHandler,
@@ -29,13 +30,15 @@ export async function runBinary(
29
30
  const args = parseDispatchArgs(argv.slice(1), process.env)
30
31
  if (!args.viewer && !args.once && !args.repository) {
31
32
  const { selectDispatchMode } = await import('./dispatch-mode')
32
- const mode = await selectDispatchMode({
33
- ...args,
34
- targetRepo: process.cwd(),
35
- env: process.env,
36
- exec: spawnExec,
37
- stderr: console.error,
38
- })
33
+ const mode = await withStoreCaller({ kind: 'dispatcher' }, () =>
34
+ selectDispatchMode({
35
+ ...args,
36
+ targetRepo: process.cwd(),
37
+ env: process.env,
38
+ exec: spawnExec,
39
+ stderr: console.error,
40
+ }),
41
+ )
39
42
  if (!mode.viewer) {
40
43
  const { launchDispatcher } = await import('./dispatch-launcher')
41
44
  return await launchDispatcher(argv)