@defrex/autobuild 1.17.0 → 1.18.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 (55) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +41 -2
  3. package/docs/architecture.md +27 -2
  4. package/docs/configuration.md +11 -3
  5. package/docs/dispatcher-hosting.md +5 -3
  6. package/docs/operator-api.md +14 -1
  7. package/docs/plugin-authoring.md +29 -1
  8. package/docs/remote-ticket-protocol.md +34 -1
  9. package/docs/restacking.md +5 -0
  10. package/docs/setup.md +9 -3
  11. package/docs/ticket-sources.md +28 -1
  12. package/docs/troubleshooting.md +15 -0
  13. package/docs/workspaces.md +1 -1
  14. package/package.json +4 -4
  15. package/packages/core/src/cli/dashboard/refresh.ts +8 -0
  16. package/packages/core/src/config/schema.ts +2 -1
  17. package/packages/core/src/events/repository.ts +37 -1
  18. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/d41044cb2e54809c.json +194 -0
  19. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/e0f89f52e48cbf62.json +197 -0
  20. package/packages/core/src/kernel/reducer-revisions.ts +5 -0
  21. package/packages/core/src/kernel/repository-read-facts.ts +9 -2
  22. package/packages/core/src/kernel/ticket-preparation.ts +10 -0
  23. package/packages/core/src/operator/registry.ts +64 -9
  24. package/packages/core/src/operator/tickets.ts +139 -25
  25. package/packages/core/src/plugin-sdk/index.ts +4 -0
  26. package/packages/core/src/plugins/manifest.ts +1 -1
  27. package/packages/core/src/ports/tickets/completion.ts +71 -0
  28. package/packages/core/src/ports/tickets/contract.ts +73 -0
  29. package/packages/core/src/ports/tickets/github-fake.ts +8 -0
  30. package/packages/core/src/ports/tickets/github-issues.ts +1 -0
  31. package/packages/core/src/ports/tickets/github.ts +18 -6
  32. package/packages/core/src/ports/tickets/hosted-index.ts +8 -0
  33. package/packages/core/src/ports/tickets/linear.ts +18 -2
  34. package/packages/core/src/ports/tickets/remote-protocol.ts +37 -8
  35. package/packages/core/src/ports/tickets/remote.ts +41 -3
  36. package/packages/core/src/ports/tickets/tree.ts +11 -1
  37. package/packages/core/src/ports/types.ts +32 -4
  38. package/packages/core/src/ports/workspace/vercel-sandbox.ts +78 -25
  39. package/packages/core/src/processes/dispatcher.ts +852 -276
  40. package/packages/core/src/processes/pass-stages.ts +32 -6
  41. package/packages/core/src/store/reducer-value-shapes.json +8309 -8240
  42. package/packages/core/src/store/remote/released-clients.json +11 -0
  43. package/packages/core/src/store/remote/released-reducer-values/1.18.0.json +36436 -0
  44. package/packages/core/src/store/remote/released-reducer-values/index.ts +18 -16
  45. package/packages/core/src/testing/dispatch-read-budget.ts +143 -16
  46. package/packages/core/src/testing/index.ts +2 -0
  47. package/packages/core/src/testing/reduced-read-budget.ts +198 -2
  48. package/skills/guide/SKILL.md +21 -5
  49. package/skills/guide/references/operator-api.md +14 -1
  50. package/skills/guide/references/plugin-authoring.md +29 -1
  51. package/skills/guide/references/remote-ticket-protocol.md +34 -1
  52. package/skills/guide/references/restacking.md +5 -0
  53. package/skills/guide/references/setup.md +9 -3
  54. package/skills/operate/SKILL.md +18 -1
  55. package/templates/hosted-service/package.json +2 -2
package/README.md CHANGED
@@ -26,7 +26,7 @@ From the repository you want built, install Autobuild as a development dependenc
26
26
  <!-- release-install:start -->
27
27
 
28
28
  ```sh
29
- bun add -d --exact @defrex/autobuild@1.17.0
29
+ bun add -d --exact @defrex/autobuild@1.18.0
30
30
  ```
31
31
 
32
32
  <!-- release-install:end -->
package/SPEC.md CHANGED
@@ -99,7 +99,7 @@ Interfaces to the world, each with swappable adapters:
99
99
  | `TelemetrySource` | production signals | Sentry; later log streams |
100
100
  | `BuildStore` | per-build streams plus repository journals: events, artifacts, transcripts, leases (see §7) | local; remote HTTP |
101
101
 
102
- Ticket sources may optionally provide native `listPage(criteria, page)` windows with a matching total. Paged operator reads use it when present, otherwise slice the exhaustive listing; unpaged and dispatcher reads remain exhaustive.
102
+ Ticket sources may optionally provide native `listPage(criteria, page)` windows with a matching total. Paged operator reads use it when present, otherwise slice the exhaustive listing; unpaged and dispatcher reads remain exhaustive. A source declaring `completionPaging` also honours completion filters (`excludeLabels`, `since`/`until` over `Ticket.resolvedAt`, order `completed`) natively, capped per request; for other sources the operator filters the exhaustive listing.
103
103
  Ticket sources may optionally provide `search(query)`: title/body term matching with state/label filters, returning compact hits and an opaque cursor. Callers refuse sources without it and never fall back to listing.
104
104
  Integration-tree sources may optionally provide `listTargeting(nodeId)`, every ticket targeting one node in every state, equal to the exhaustive listing filtered by target. Integration observation uses it when present, otherwise `listAll`.
105
105
 
@@ -505,7 +505,11 @@ files, including development configs, remain exactly as installed.
505
505
  a won claim, the selected creation slug and, when the build store attests keyed
506
506
  creation, the attempt's creation key are durable boundaries. Caught
507
507
  asset-copy, spec-authoring, naming, and build-creation failures return the ticket
508
- to configured Ready; a nonconforming spec goes to configured Triage. Recovery
508
+ to configured Ready; a nonconforming spec goes to configured Triage. A bounded
509
+ invocation stamps each intent with its work deadline; an attempt that deadline
510
+ interrupted before `build.created`, with no failure or bounce recorded, is not a
511
+ failure and is never returned to Ready: it is carried and resumed (§8.1).
512
+ Recovery
509
513
  point-reads the selected slug and, for a keyed attempt, the canonical slug derived
510
514
  from the repository, selected slug and key: one matching record and atomic
511
515
  `build.created` retain ownership even if creation threw after committing or its
@@ -2049,6 +2053,41 @@ keeps the cut execution's `instance` and the step still owed (`fence` or
2049
2053
  that instance still holds the lease; the lease never waits on its TTL. A
2050
2054
  carried entry retires without launching when its build is aborted, discarded,
2051
2055
  paused or no longer needs the start.
2056
+ Ticket preparations are carried the same way, before `build.created`. Intake
2057
+ does not start a preparation with less time left before the work deadline than
2058
+ a preparation needs (about 30 s, the dispatcher's `preparationEstimateMs`).
2059
+ Once the ticket passes every admission gate, capacity included, intake journals
2060
+ the admission as a preparation intent with `claimDeferred`, makes no tracker
2061
+ call, carries the attempt and stops claiming. A preparation the work deadline
2062
+ cuts before `build.created` is carried too, with no failure recorded, no
2063
+ recovery and no tracker write. Carried attempts are listed, by ticket and
2064
+ attempt, in `dispatcher.work-deferred` and counted as `preparationsCarried`; the
2065
+ dispatch log names each ticket and the pass's stage record lists it as
2066
+ `carried`. The next invocation resumes each attempt first, after the carried
2067
+ builds, from its last durable boundary. An attempt never claimed is claimed
2068
+ now: a second intent for the same attempt, without `claimDeferred`, is
2069
+ journaled before the claim call, and from then on recovery treats the claim as
2070
+ possibly applied. A claim that applied but was never confirmed is confirmed
2071
+ from the ticket's state. A claimed attempt continues from its asset pin, and a
2072
+ selected creation is read back as in recovery. A deferred attempt whose ticket
2073
+ left Ready or reports unresolved blockers, or whose repository turned intake
2074
+ off, resolves `lost-claim` with no tracker write, and intake decides the ticket
2075
+ again. Admission is decided once, when the intent is written: the intent also
2076
+ records the admitted build level (a non-manual start request's own level, or
2077
+ the ticket's claim tier), and a carried attempt's build takes that level even
2078
+ after its start request settles. Finishing a carried attempt never re-measures
2079
+ capacity. Instead, every capacity measurement counts each unresolved carried
2080
+ attempt as an occupied slot until it resolves, however many passes its resume
2081
+ takes (a tracker outage included), so no intake claim, start request or slot
2082
+ admission spends it. A slot request or start request that appears in between
2083
+ waits, as it would behind an in-flight claim. The unresolved attempt withholds
2084
+ its ticket from other claims meanwhile. The
2085
+ work-deadline stamp is the backstop when the hint is lost: preparation recovery
2086
+ resumes an attempt whose stamp has passed and that recorded no failure or
2087
+ bounce, instead of handing it back. A resumed preparation that fails for real
2088
+ takes the ordinary failure path, and one the deadline cuts again is carried
2089
+ again under the same attempt. Start requests get the same estimate gate but
2090
+ journal nothing; their pending request is already the carry.
2052
2091
  No stage consumes a bounded pass. Its stages run in order (deferred work,
2053
2092
  settlement, ticket preparations, janitor, recovery, lease sweep, admission,
2054
2093
  intake), and each may start new items only until its share of the time left
@@ -866,6 +866,27 @@ holder before anything else. Starts are tracked in flight, and bounded
866
866
  teardown awaits `Dispatcher.settleCutStarts()` as a racer beside provisioning
867
867
  abandonment, before the repository lease is released; it prints each deferral
868
868
  line the tick has not reported, and the cut pass's partial summary counts them.
869
+ Ticket preparations are carried before `build.created` too (#1431). Intake's
870
+ claim loop calls `Dispatcher.prepareTicket`, the one preparation path from the
871
+ `intended` append to the first dispatch, tracked as a start in flight. In a
872
+ bounded pass `appendIntended` stamps `workDeadlineAt` and the admitted `level`,
873
+ which a resumed attempt reuses; `preparationWontFit`
874
+ compares the time left with `preparationEstimateMs` (default 30 s), and
875
+ `deferPreparation` journals the admission as `intended` with `claimDeferred`
876
+ and no tracker call. A preparation the deadline cuts takes `prepareTicket`'s
877
+ cut branch instead of `failPreparation`. Both note the attempt through
878
+ `notePreparationCarry`, which writes the hint's `tickets` list beside its
879
+ builds and records the ticket on the pass's stage part (`PassStageTracker.carry`).
880
+ `serviceDeferredWork` resumes carried attempts after carried builds through
881
+ `resumeCarriedPreparation`, which re-reads the ticket, confirms or claims as
882
+ the attempt's durable boundaries require (journaling a second `intended` as
883
+ the claim-started boundary of a deferred claim), and re-enters `prepareTicket`
884
+ with `resume`. It uses `creationReadback`, the readback it shares with
885
+ `recoverTicketPreparation`.
886
+ Every capacity measurement goes through `measureCapacity`, which adds
887
+ `reservedPreparations()` (unresolved, deadline-stamped attempts with no failure
888
+ or bounce) to the occupied slots, so a carried admission keeps its slot until
889
+ it resolves.
869
890
  Stage fairness lives in `processes/pass-stages.ts` (pure: shares, rotation,
870
891
  the stage record and its rendering). `Dispatcher.runTick` wraps each stage in
871
892
  `runStage`, which hands its helpers a copy of the tick options whose
@@ -1056,7 +1077,7 @@ dispatch is tolerated. `Ticket.creationKey` is the optional stable external
1056
1077
  create/adoption correlation, distinct from `Ticket.ref.id`; Linear projects its
1057
1078
  issue UUID and file/fake preserve their idempotency metadata through create,
1058
1079
  adoption, get, and list paths. Legacy/plugin tickets may omit it and dispatch
1059
- unchanged. The ticket-source port optionally exposes `listPage(criteria, page)` for paged operator reads. PostgreSQL counts matches and applies SQL LIMIT/OFFSET; the remote hosted client forwards pages over the `list-page` ticket operation; other sources retain exhaustive-read slicing. CLI and dispatcher reads stay exhaustive. The optional `search(query)` serves `tickets.search` and `ab ticket search`; PostgreSQL answers it with one keyset-paged bounded statement, the remote hosted client forwards it over the `search` ticket operation, and the Linear source answers it with one team-filtered GraphQL `issues` request per page; the GitHub source answers it with one GitHub issue-search request per page on GitHub's separate search quota; `ports/tickets/search.ts` holds the shared matcher and cursor pager, the `TicketSearchUnsupported` refusal for sources without it, and `searchTickets`, the caller entry point. See [ticket source contract](ticket-sources.md#writing-your-own).
1080
+ unchanged. The ticket-source port optionally exposes `listPage(criteria, page)` for paged operator reads, with completion filters (`ports/tickets/completion.ts`) for sources declaring `completionPaging`. PostgreSQL counts matches and applies SQL LIMIT/OFFSET, answering completion filters with at most two range scans over its completion index (a count and a window), each stopping at 5,001 rows, and refusing a state and range over 5,000 tickets; the remote hosted client forwards pages over the `list-page` ticket operation; other sources retain exhaustive-read slicing. CLI and dispatcher reads stay exhaustive. The optional `search(query)` serves `tickets.search` and `ab ticket search`; PostgreSQL answers it with one keyset-paged bounded statement, the remote hosted client forwards it over the `search` ticket operation, and the Linear source answers it with one team-filtered GraphQL `issues` request per page; the GitHub source answers it with one GitHub issue-search request per page on GitHub's separate search quota; `ports/tickets/search.ts` holds the shared matcher and cursor pager, the `TicketSearchUnsupported` refusal for sources without it, and `searchTickets`, the caller entry point. See [ticket source contract](ticket-sources.md#writing-your-own).
1060
1081
 
1061
1082
  The `github` source spans four modules. `ports/tickets/github.ts` is the
1062
1083
  adapter: REST over the forge's `GitHubRequest` transport and credential order,
@@ -1777,7 +1798,11 @@ and `ab context` writes them under `$AB_CONTEXT_DIR/assets/`.
1777
1798
 
1778
1799
  `kernel/ticket-preparation.ts` projects unfinished `ticket-preparation.*` facts
1779
1800
  through `repositoryReadFacts`; `processes/dispatcher.ts` retries them under the
1780
- existing repository ownership before intake. This pre-record recovery differs
1801
+ existing repository ownership before intake. An attempt stamped with a passed
1802
+ `workDeadlineAt` and no recorded failure or bounce was interrupted by its
1803
+ bounded invocation's deadline: `recoverTicketPreparations` resumes it through
1804
+ `resumeCarriedPreparation` instead of handing it back, unless the deferred
1805
+ stage already did this tick. This pre-record recovery differs
1781
1806
  from `dispatch.failed`, which completes an already established build.
1782
1807
  `kernel/ticket-starts.ts` reduces operator single-ticket start requests
1783
1808
  (`ticket.start-*`) and the durable canonical identities of hosted active builds
@@ -1460,7 +1460,7 @@ preflight = "test \"$(pi --version)\" = \"0.84.4\" && pi update --models"
1460
1460
  - **Reload:** Dispatcher restart required; startup adapters retain their configuration. Build-owned pipeline: captured from the execution checkout each verify cycle; later base-branch edits do not replace it. Workspace provisioning applies at the next build launch. A running invocation keeps its captured values.
1461
1461
  - **Local override:** Committed only: set in autobuild.toml.
1462
1462
 
1463
- **Description:** required nonblank shell command; use an immutable package version, digest, or commit
1463
+ **Description:** required nonblank shell command; use an immutable package version, digest, or commit; also reruns in place when the runtime's preflight fails at a relaunch, so it must be safe to run over an existing install
1464
1464
 
1465
1465
  **Constraints:** install must be nonblank
1466
1466
 
@@ -1561,7 +1561,10 @@ Autobuild distribution and dependency bootstrap. Then runtime provisioning runs
1561
1561
  each referenced runtime's `install` and `preflight` commands in sorted
1562
1562
  runtime-name order from the checkout. Only `environmentVariables` values enter
1563
1563
  runtime commands. The same sequence runs in fresh readiness sandboxes and every
1564
- replacement sandbox. Provisioning writes its readiness marker only after all
1564
+ replacement sandbox. A relaunch into an existing sandbox reruns each selected
1565
+ runtime's `preflight`; when one fails, that runtime's `install` runs in place
1566
+ and its `preflight` runs again, so a `[roles]` change that selects a new
1567
+ runtime reaches existing sandboxes at their next launch. Provisioning writes its readiness marker only after all
1565
1568
  scrubbing, Bun verification, system steps, distribution installation,
1566
1569
  dependency bootstrap, and runtime preflights complete; distribution
1567
1570
  packing/install disables package lifecycle scripts so
@@ -1676,7 +1679,12 @@ start provisioning with less than about 150 s of budget left; it records
1676
1679
  `provisioningDeferred` in the tick report, logs the build, and records it in
1677
1680
  `dispatcher.work-deferred`, so the next invocation provisions it first. That
1678
1681
  includes the first provision of a build intake just claimed: the build keeps
1679
- its slot, and the next invocation completes its dispatch first.
1682
+ its slot, and the next invocation completes its dispatch first. Intake starts a
1683
+ ticket preparation (claim, spec import, build creation) only with about 30 s
1684
+ left. Otherwise it holds the admitted ticket, logs
1685
+ `ticket <id>: preparation carried by the invocation budget`, and the next
1686
+ invocation prepares it first. A preparation the work deadline cuts is carried
1687
+ the same way. Neither is handed back to Ready.
1680
1688
 
1681
1689
  The representative actual-provider check is opt-in and must point at an
1682
1690
  independent consuming repository whose `autobuild.toml` selects the universal
@@ -96,9 +96,11 @@ invocation after the last item they started; priority-ordered loops (node
96
96
  admission, start requests, ready tickets, ticket waits) keep their order. Each
97
97
  pass logs a `stages:` line; see
98
98
  [a stage keeps stopping at the work deadline](troubleshooting.md#a-stage-keeps-stopping-at-the-work-deadline).
99
- Deferred work is every start a pass admitted but didn't finish (a provision, a
100
- launch the work deadline cut, or a stopped-sandbox recovery); the next
101
- invocation runs it first.
99
+ Deferred work is every start a pass admitted but didn't finish (a ticket
100
+ preparation, a provision, a launch the work deadline cut, or a stopped-sandbox
101
+ recovery); the next invocation runs it first. A ticket preparation that won't
102
+ fit, or that the deadline cuts, keeps its ticket and is never handed back to
103
+ Ready.
102
104
 
103
105
  ### Origin-mode dispatcher with remote workspaces
104
106
 
@@ -93,7 +93,7 @@ raw session-event append. External operator harnesses own agent execution.
93
93
  | `GET …/status` | Repository intake, pause, and default-auto-merge projection, plus `ticketStarts` (`{pending, recent}`, each entry with its `priority`) when single-ticket start requests are pending or recently settled. `capacity.slots`, when the held configuration is readable, maps each nonterminal build to its slot state; `capacity.occupied` counts its `held` entries. Its `operator` is `{presence: "unavailable", reason}`: this route does not load presence registrations, so it is not evidence that no operator is present. |
94
94
  | `GET …/harvest/status` | Harvest gate, runs, steps, recovery, and attention projection. |
95
95
  | `GET …/builds/{slug}/artifacts/{kind}?rev=N` | Raw bytes (`application/octet-stream`) plus content-disposition and `X-Autobuild-Artifact-*` metadata headers. Omit `rev` for latest. |
96
- | `GET …/tickets?state=S&label=L&limit=N&offset=K&order=O` | `{states,tickets,diagnostics,criteria,triageState,readyState,doneState,total}`. The three lifecycle names come from effective repository configuration (including provider fallback). With no `state`, `criteria.state` is `triageState`; repeated `label` parameters narrow that state with AND filters. An explicit `state` selects that exact backend workflow state. `limit` (0–200) returns one page, after skipping `offset`, in `order` `oldest` (the default: priority order, urgent, high, normal, then low tickets, each in the source order) or `newest` (newest filed first, regardless of priority; see paging below); `total` counts every match before paging. |
96
+ | `GET …/tickets?state=S&label=L&limit=N&offset=K&order=O` | `{states,tickets,diagnostics,criteria,triageState,readyState,doneState,total}`. The three lifecycle names come from effective repository configuration (including provider fallback). With no `state`, `criteria.state` is `triageState`; repeated `label` parameters narrow that state with AND filters. An explicit `state` selects that exact backend workflow state. `limit` (0–200) returns one page, after skipping `offset`, in `order` `oldest` (the default: priority order, urgent, high, normal, then low tickets, each in the source order) or `newest` (newest filed first, regardless of priority; see paging below); `total` counts every match before paging. Tickets carry `resolvedAt` and, beside `target`, `targetTitle` when known; see completion listings below. |
97
97
  | `GET …/tickets/states` | Full state metadata `{name,tickets,about?}[]`, including empty states (`tickets.states` in MCP). |
98
98
  | `GET …/tickets/{id}` | `{ticket,blockers,build,assets}`. Blockers include native `exists`/`resolved` status; `build` prefers an active matching repository build, otherwise the most recently updated one. `assets` lists the current ticket assets as `{kind,name,revision,size,layout,fileCount}`, as `ab ticket show --json` does. |
99
99
 
@@ -874,6 +874,19 @@ are successful cleanup; provider errors never count as completed deletion.
874
874
 
875
875
  Paged ticket listings use the source's optional native `listPage(criteria, page)` capability when present, otherwise read the full listing, order it, and slice it: by default priority order (urgent, high, normal, then low tickets, each in source order); for `newest`, the reversed listing. `newest` means newest filed first, regardless of priority, with a stable tie-break; it is not the reverse of priority order. A source that lists in filing order (file, GitHub, Linear) gets exactly that from the reversed listing. The remote `HostedTicketSource` pages natively through the service's `list-page` operation, and uses the fallback only against a service predating it. Native errors propagate. PostgreSQL counts matches without bodies and reads only the requested window. Zero limits and offsets past the end still report the full matching total. Unpaged listings remain exhaustive; the wire payload is the same for both paths.
876
876
 
877
+ Completion listings (`tickets.list` in MCP) answer "what shipped" digests:
878
+
879
+ | Input | Effect |
880
+ |---|---|
881
+ | `since`, `until` | ISO-8601 with offset; half-open `since <= resolvedAt < until`. Tickets without `resolvedAt` never match. Either one defaults `state` to the effective done state. `since` must precede `until`. |
882
+ | `order: "completed"` | Most recently completed first, ties newest filed first; tickets without a completion time follow, newest filed first. |
883
+ | `excludeLabels` | Drops any ticket carrying any named label; ANDed with `labels`, `state` and the range; `total` counts after it. |
884
+ | `summary: true` | Omits each ticket's `body` and `comments`; every other field, `revision` included, stays. |
885
+
886
+ - **Paging.** `order` and `offset` apply with or without `limit`. Any of `offset`, `order`, `since`, `until` or `excludeLabels` without `limit` pages at 200, the maximum; `total` still counts every match. A call with none of them stays exhaustive.
887
+ - **Fields.** `resolvedAt` is the ISO-8601 completion time, present only on resolved tickets whose source knows it (hosted, GitHub, Linear; never the file source). `targetTitle` is the target node's title, returned when resolvable: from the source's own read, a parent already in the listing, or one `get` per distinct remaining parent. A parent that is missing or whose read fails leaves `targetTitle` absent. `criteria` echoes the state, labels, `excludeLabels`, `since` and `until` applied.
888
+ - **Cost.** A source declaring completion paging (hosted) answers natively with at most two index range scans of the state and range, each stopping at 5,001 tickets: one counts the matches, a second reads the requested window. A zero `limit` or a refusal stops after the first. A range holding more than 5,000 tickets refuses with `code: "completion-range-too-broad"`; narrow `since`/`until`. `excludeLabels` or `order: "completed"` alone on a state holding more than 5,000 tickets refuses too. Other sources, and hosted services that predate completion listing, filter their full state listing and never refuse.
889
+
877
890
 
878
891
  ### Forge cooldown admission and explicit recovery
879
892
 
@@ -252,6 +252,7 @@ A plugin relying on a capability declares an `apiVersion` range containing its v
252
252
  - **1.10** Optional ticket-source ready-assignee capability (`readyAssignee`, with `prepareReadyAssignee`, `readyAssigneeRefusal` and `describeReadyAssignee`); sources without it refuse `[tickets].readyAssignee`. Also optional targeted ticket listing (`listTargeting`); older tree sources are observed through `listAll`.
253
253
  - **1.11** Optional ticket-source search (`search`); callers refuse sources without it and never fall back to a listing.
254
254
  - **1.12** Host-provided factory-context `fetch` and `invocationSignal` for bounded-invocation cancellation.
255
+ - **1.13** Optional ticket completion listing (`completionPaging`, with `TicketPageCriteria`, order `completed` and the `TicketCompletionRangeTooBroad` refusal), and the listing-time `Ticket.resolvedAt` and `Ticket.targetTitle`; callers filter the exhaustive listing for sources without it.
255
256
 
256
257
  ## 2. Create a repository-local module
257
258
 
@@ -651,7 +652,7 @@ for any other label.
651
652
  ## Optional ticket paging capability
652
653
 
653
654
  Native paging is an optional API 1.9 ticket-source capability:
654
- `listPage?(criteria: TicketCriteria, page: TicketPage): Promise<TicketPageListing>`.
655
+ `listPage?(criteria: TicketPageCriteria, page: TicketPage): Promise<TicketPageListing>`.
655
656
  The SDK exports these types; the result is `TicketListing & { total: number }`.
656
657
  Criteria retain state, labels (AND), and assignee semantics. The page has a
657
658
  nonnegative integer `limit`, optional nonnegative integer `offset` (default 0),
@@ -675,6 +676,33 @@ File, Linear and GitHub retain fallback; the remote `HostedTicketSource`
675
676
  forwards pages to the service's native paging (`list-page`), falling back only
676
677
  against a service predating it. The POST list-ready protocol stays exhaustive.
677
678
 
679
+ Completion listing is an optional API 1.13 extension of native paging.
680
+ `listPage` takes `TicketPageCriteria`: the criteria above plus
681
+ `excludeLabels` (drop any ticket carrying any named label), and `since`
682
+ (inclusive) and `until` (exclusive) bounds on `Ticket.resolvedAt`; tickets
683
+ without a completion time never match. `TicketPage.order` adds `completed`:
684
+ tickets with `resolvedAt` first, most recent first, ties newest filed first,
685
+ then the rest newest filed first. Declare `completionPaging: true` only when
686
+ `listPage` honours all of these; callers send them only to sources declaring it
687
+ and otherwise filter the exhaustive listing with the SDK's shared semantics. A
688
+ native source may refuse a range broader than its per-request cap with
689
+ `TicketCompletionRangeTooBroad` (the SDK exports it and
690
+ `TICKET_COMPLETION_SCAN_LIMIT`); callers surface it as the
691
+ `completion-range-too-broad` refusal and never fall back. The shared contract
692
+ suite checks declared completion paging.
693
+
694
+ Tickets may carry two listing-time facts outside `revision`: `resolvedAt`, the
695
+ ISO-8601 time the ticket entered its completed state (only when `resolved`),
696
+ and `targetTitle`, the target node's title (only beside `target`). Return them
697
+ when your read already has them. The hosted PostgreSQL source records
698
+ `resolvedAt` when a ticket enters the done state, uses the last update for done
699
+ tickets that predate it, and projects `targetTitle` in its listing statements.
700
+ GitHub reports `closed_at` for completed issues and the parent title it reads
701
+ for targeting; Linear reports `completedAt` (or `canceledAt`) and the parent's
702
+ title. The file source reports no `resolvedAt`; operator listings fill a
703
+ missing `targetTitle` from tickets already listed, then with one `get` per
704
+ remaining parent.
705
+
678
706
  ## Optional ticket search capability
679
707
 
680
708
  Text search is an optional API 1.11 ticket-source capability:
@@ -185,7 +185,7 @@ The operation names and `input` values are:
185
185
  | `state-counts` | `{names: string[]}` (1–16) | `{name, tickets}[]` for the names that resolve |
186
186
  | `list-ready` | `{labels?: string[], state?: string}` | `TicketListing` |
187
187
  | `list-targeting` | `{nodeId: string}` | `TicketListing` of every state |
188
- | `list-page` | `{criteria: {labels?, state?}, page: {limit, offset?, order?}}` | `TicketPageListing` (`{tickets, diagnostics, total}`) |
188
+ | `list-page` | `{criteria: {labels?, state?, excludeLabels?, since?, until?}, page: {limit, offset?, order?}}` | `TicketPageListing` (`{tickets, diagnostics, total}`) |
189
189
  | `search` | `{text, state?, labels?, limit, cursor?}` | `{tickets: {id, title, state?, labels, kind, target?, priority?}[], cursor?, diagnostics}` |
190
190
  | `get` | `{id}` | `Ticket \| null` |
191
191
  | `claim` | `{id}` | `{claimed: boolean}` |
@@ -532,6 +532,39 @@ listing takes the `list-ready` path by that explicit decision.
532
532
  The capability is additive. It does not change the remote BuildStore protocol
533
533
  version, and released clients, which never send `list-page`, are unaffected.
534
534
 
535
+ ## Completion listing
536
+
537
+ Recently completed work is listed through `list-page` with completion criteria,
538
+ negotiated by `x-autobuild-ticket-completion: 1`:
539
+
540
+ - **Ticket fields.** `resolvedAt` (ISO-8601, when the ticket entered its done
541
+ state) and `targetTitle` (the target node's title, beside `target`) appear on
542
+ tickets in every operation's answer, only for clients that send the header.
543
+ Released strict decoders never see them. PostgreSQL stamps the completion time
544
+ on entering the done state and clears it on leaving; a done ticket written
545
+ before that completes at its last update.
546
+ - **Criteria.** `excludeLabels` drops any ticket carrying any named label.
547
+ `since` (inclusive) and `until` (exclusive) bound `resolvedAt`, ISO-8601 with
548
+ an offset; tickets without a completion time never match. `order: "completed"`
549
+ is most recently completed first, ties newest filed first, then tickets
550
+ without a completion time, newest filed first. Any of them requires
551
+ `criteria.state`, or the request is a `400` validation error.
552
+ - **Cap.** The PostgreSQL backend accepts a state and range holding at most
553
+ 5,000 tickets. It answers with up to two index range scans, each stopping at
554
+ 5,001 rows: one counts the matches, the second reads the requested window. A
555
+ zero `limit` or a refusal stops after the first. When the count scan reaches
556
+ the 5,001st row, the request answers
557
+ `409 {kind: "conflict", code: "completion-range-too-broad", error, limit}`;
558
+ the client reports `TicketCompletionRangeTooBroad` with the `limit`. Narrow
559
+ `since`/`until`. Within the cap, `total` is exact.
560
+ - **Refusal.** A backing source that cannot honour completion criteria answers
561
+ `409` with `code: "paging-unsupported"`.
562
+ - **Negotiation.** Every `/tickets/*` response, including errors, carries the
563
+ header. A client sends completion criteria only after a response carried it
564
+ and `list-page` is declared; otherwise it fails with `HostedTicketPagingError`
565
+ (`service-predates`) before any request, and operator listings filter
566
+ `list-ready` instead.
567
+
535
568
  ## Search
536
569
 
537
570
  `search` answers one page of compact hits from the backing source's own search,
@@ -457,6 +457,11 @@ point-reads the selected slug and, for a keyed attempt, the canonical slug deriv
457
457
  from the repository, selected slug and key: one matching record and atomic
458
458
  `build.created` retain ownership even if creation threw after committing or its
459
459
  response was lost.
460
+ A bounded hosted invocation may journal an admission without a claim, when the
461
+ preparation would not fit before its work deadline, and stamps every intent with
462
+ that deadline. An attempt the deadline interrupted, with no failure or bounce
463
+ recorded, is carried: the next invocation resumes it first from its durable
464
+ boundaries, and it is never returned to Ready.
460
465
  Unavailable or conflicting readback never authorizes release or a replacement
461
466
  build. Pending attempts retain the original failure, latest recovery error and
462
467
  retry deadline in the canonical repository reduced value; resolved attempts
package/docs/setup.md CHANGED
@@ -113,9 +113,15 @@ already has required system tooling.
113
113
  Put each selected runtime's immutable install and executable/version check in
114
114
  its `runtimeProvisioning` entry. Autobuild runs install then preflight after
115
115
  checkout dependencies in every fresh/replacement sandbox and before the
116
- readiness probe, writes the marker only after success, and reruns every
117
- preflight before each build runner. A failure names the runtime, selecting
118
- role/alternate, and field and starts no agent. Runtime provisioning receives
116
+ readiness probe, and writes the marker only after success. Every build-runner
117
+ launch and harvest relaunch reruns each selected runtime's preflight. A
118
+ preflight that fails in an existing sandbox runs that runtime's install and
119
+ then its preflight again; only a failure after that install fails the launch.
120
+ A failure names the runtime, selecting role/alternate, and the failed field
121
+ (`install` or `preflight`) with the command output, and starts no agent. A
122
+ `[roles]` change that selects a new runtime, or a changed pin, takes effect in
123
+ existing workspaces at their next launch; no abort is needed, so keep each
124
+ install safe to run over an older install. Runtime provisioning receives
119
125
  allowlisted legacy API credentials named by
120
126
  `[workspace.config].environmentVariables` and automatically supplied placeholders
121
127
  for every declared account credential variable. Account variables need no
@@ -248,7 +248,7 @@ Declare `priority` only if you store all four levels natively; without it, Autob
248
248
  Declare tree support only if you keep the [optional tree contract](plugin-authoring.md#optional-ticket-tree-capability) on the same port and harness: exhaustive pagination, canonical targets, revision coverage and atomic rejection.
249
249
 
250
250
  Native paging is an optional API 1.9 ticket-source capability:
251
- `listPage?(criteria: TicketCriteria, page: TicketPage): Promise<TicketPageListing>`.
251
+ `listPage?(criteria: TicketPageCriteria, page: TicketPage): Promise<TicketPageListing>`.
252
252
  The SDK exports these types; the result is `TicketListing & { total: number }`.
253
253
  Criteria retain state, labels (AND), and assignee semantics. The page has a
254
254
  nonnegative integer `limit`, optional nonnegative integer `offset` (default 0),
@@ -272,6 +272,33 @@ File, Linear and GitHub retain fallback; the remote `HostedTicketSource`
272
272
  forwards pages to the service's native paging (`list-page`), falling back only
273
273
  against a service predating it. The POST list-ready protocol stays exhaustive.
274
274
 
275
+ Completion listing is an optional API 1.13 extension of native paging.
276
+ `listPage` takes `TicketPageCriteria`: the criteria above plus
277
+ `excludeLabels` (drop any ticket carrying any named label), and `since`
278
+ (inclusive) and `until` (exclusive) bounds on `Ticket.resolvedAt`; tickets
279
+ without a completion time never match. `TicketPage.order` adds `completed`:
280
+ tickets with `resolvedAt` first, most recent first, ties newest filed first,
281
+ then the rest newest filed first. Declare `completionPaging: true` only when
282
+ `listPage` honours all of these; callers send them only to sources declaring it
283
+ and otherwise filter the exhaustive listing with the SDK's shared semantics. A
284
+ native source may refuse a range broader than its per-request cap with
285
+ `TicketCompletionRangeTooBroad` (the SDK exports it and
286
+ `TICKET_COMPLETION_SCAN_LIMIT`); callers surface it as the
287
+ `completion-range-too-broad` refusal and never fall back. The shared contract
288
+ suite checks declared completion paging.
289
+
290
+ Tickets may carry two listing-time facts outside `revision`: `resolvedAt`, the
291
+ ISO-8601 time the ticket entered its completed state (only when `resolved`),
292
+ and `targetTitle`, the target node's title (only beside `target`). Return them
293
+ when your read already has them. The hosted PostgreSQL source records
294
+ `resolvedAt` when a ticket enters the done state, uses the last update for done
295
+ tickets that predate it, and projects `targetTitle` in its listing statements.
296
+ GitHub reports `closed_at` for completed issues and the parent title it reads
297
+ for targeting; Linear reports `completedAt` (or `canceledAt`) and the parent's
298
+ title. The file source reports no `resolvedAt`; operator listings fill a
299
+ missing `targetTitle` from tickets already listed, then with one `get` per
300
+ remaining parent.
301
+
275
302
  Search is an optional API 1.11 ticket-source capability:
276
303
  `search?(query: TicketSearchQuery): Promise<TicketSearchPage>`. It matches
277
304
  every query word against titles and bodies, filters by state and labels, and
@@ -138,6 +138,21 @@ A step the invocation deadline defers is not a failure:
138
138
 
139
139
  See [Vercel sandbox recovery](configuration.md#vercel-sandbox).
140
140
 
141
+ A ticket preparation the invocation deadline carries is not a failure either:
142
+
143
+ - The dispatch log names the ticket: `ticket <id>: preparation carried by the invocation budget`.
144
+ - The tick counts it as `preparationsCarried`, and the `stages:` line shows it, for example `tickets 0/22 carried FLINT-1490`.
145
+ - The ticket isn't handed back to Ready and no other pass claims it. The next invocation prepares it first, before settlement.
146
+ - Don't retry, move or re-file the ticket.
147
+
148
+ ## A ticket is carried on several invocations in a row
149
+
150
+ **Symptom.** The same ticket logs `preparation carried by the invocation budget` on several invocations in a row, and no build is created.
151
+
152
+ **Cause.** The deadline keeps cutting its preparation even though it runs first, so one preparation outlasts the hosted invocation budget. The usual culprit is a slow tracker claim or spec authoring.
153
+
154
+ **Action.** Report it to the instance operator with the stage the carry line names, such as `(claim)`. Retrying the ticket doesn't help.
155
+
141
156
  ## A build stays STARTING with repeated deferral lines
142
157
 
143
158
  **Symptom.** The same build logs `resume`, `provision` or `launch deferred by the invocation budget` on several invocations in a row, and stays STARTING.
@@ -114,7 +114,7 @@ Sandbox preparation order:
114
114
  5. `commands.setup`
115
115
 
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
- - **Repetition.** New sandboxes repeat provisioning and preflights rerun before each build-runner; keep setup idempotent.
117
+ - **Repetition.** New sandboxes repeat provisioning and preflights rerun before each build-runner. A failing preflight installs that runtime in place first, so a `[roles]` change reaches existing sandboxes at their next launch; keep setup and runtime installs 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
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`.
120
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defrex/autobuild",
3
- "version": "1.17.0",
3
+ "version": "1.18.0",
4
4
  "description": "Agent-driven software delivery from groomed ticket to merged PR",
5
5
  "repository": {
6
6
  "type": "git",
@@ -144,7 +144,7 @@
144
144
  "prepare": "husky",
145
145
  "test": "bun tools/test-temp-leaks.ts unit",
146
146
  "test:integration": "bun tools/test-temp-leaks.ts integration",
147
- "typecheck": "node --max-old-space-size=4096 ./node_modules/typescript/bin/tsc --noEmit",
147
+ "typecheck": "node --max-old-space-size=8192 ./node_modules/typescript/bin/tsc --noEmit",
148
148
  "ui:catalog": "bun packages/ui/scripts/catalog.ts",
149
149
  "ui:tokens": "bun packages/ui/scripts/tokens.ts",
150
150
  "ui:web": "bun packages/ui/scripts/web.ts"
@@ -162,8 +162,8 @@
162
162
  },
163
163
  "devDependencies": {
164
164
  "@biomejs/biome": "2.5.5",
165
- "@defrex/autobuild-postgres-store": "1.17.0",
166
- "@defrex/autobuild-vercel-sandbox": "1.17.0",
165
+ "@defrex/autobuild-postgres-store": "1.18.0",
166
+ "@defrex/autobuild-vercel-sandbox": "1.18.0",
167
167
  "@resvg/resvg-js": "2.6.2",
168
168
  "@types/bun": "^1.3.14",
169
169
  "@types/node": "^24.0.0",
@@ -7,6 +7,14 @@ export function interactionRead<T>(operation: () => T): T {
7
7
  return readIntent.run(true, operation)
8
8
  }
9
9
 
10
+ /** Whether the caller runs inside a presentation read: a scheduled dashboard
11
+ * refresh or an explicitly requested interaction read. Kernel work never
12
+ * does, so read-budget harnesses use this to tell the independent dashboard
13
+ * poll apart from a tick's own reads. */
14
+ export function inPresentationRead(): boolean {
15
+ return readIntent.getStore() !== undefined
16
+ }
17
+
10
18
  /** Presentation-only read scheduling. Kernel timers never use this controller. */
11
19
  export interface RefreshScheduler {
12
20
  now(): number
@@ -233,7 +233,8 @@ export const runtimeProvisioningEntrySchema = z.strictObject({
233
233
  })
234
234
 
235
235
  documentFields(runtimeProvisioningEntrySchema, {
236
- install: 'required nonblank shell command; use an immutable package version, digest, or commit',
236
+ install:
237
+ "required nonblank shell command; use an immutable package version, digest, or commit; also reruns in place when the runtime's preflight fails at a relaunch, so it must be safe to run over an existing install",
237
238
  preflight: 'required nonblank shell command; verify the expected executable and exact version',
238
239
  })
239
240
  documentSchema(runtimeProvisioningEntrySchema, {
@@ -98,12 +98,15 @@ export const ROTATED_PASS_PARTS = [
98
98
  ] as const
99
99
  const passCount = z.number().int().nonnegative()
100
100
  const passStopSchema = z.enum(['share', 'deadline'])
101
+ const passCarriedSchema = z.array(z.string().min(1)).max(8)
101
102
  const passStageRecordSchema = z.strictObject({
102
103
  stage: z.enum(PASS_STAGE_NAMES),
103
104
  ms: passCount,
104
105
  items: passCount,
105
106
  total: passCount.optional(),
106
107
  stopped: passStopSchema.optional(),
108
+ /** Tickets whose preparation the stage carried to the next pass (#1431). */
109
+ carried: passCarriedSchema.optional(),
107
110
  parts: z
108
111
  .array(
109
112
  z.strictObject({
@@ -111,6 +114,8 @@ const passStageRecordSchema = z.strictObject({
111
114
  items: passCount,
112
115
  total: passCount.optional(),
113
116
  stopped: passStopSchema.optional(),
117
+ /** Tickets whose preparation this part carried to the next pass. */
118
+ carried: passCarriedSchema.optional(),
114
119
  }),
115
120
  )
116
121
  .max(8)
@@ -156,6 +161,11 @@ const tickCountersSchema = z.strictObject({
156
161
  * its execution lease was claimed. Optional so historical tick facts
157
162
  * replay. */
158
163
  recoveryDeferred: z.number().int().nonnegative().optional(),
164
+ /** Ticket preparations a bounded invocation carried to the next one: an
165
+ * admission the work deadline left no time to prepare, or a preparation
166
+ * the deadline cut. Never handed back. Optional so historical tick facts
167
+ * replay. */
168
+ preparationsCarried: z.number().int().nonnegative().optional(),
159
169
  /** Operator sandboxes idly stopped this tick. Added with the operator
160
170
  * sandbox; optional so historical tick facts replay. */
161
171
  sandboxIdleStops: z.number().int().nonnegative().optional(),
@@ -578,7 +588,12 @@ export const dispatcherStatusEventPayloadSchemas = {
578
588
  * state; it is never authority. An empty list clears it. `instance` names a
579
589
  * deadline-cut execution whose exact-holder lease teardown could not
580
590
  * settle: the next tick fences it first (step `fence`) or only releases it
581
- * (step `launch`), and only while that instance still holds the lease. */
591
+ * (step `launch`), and only while that instance still holds the lease.
592
+ * `tickets` names carried ticket-preparation attempts (#1431): an admission
593
+ * intake journaled but did not start because the preparation would not fit
594
+ * before the work deadline, or a preparation the deadline cut. The next
595
+ * tick resumes each attempt first from its durable boundaries; absent when
596
+ * none is carried. */
582
597
  'dispatcher.work-deferred': z.strictObject({
583
598
  builds: z
584
599
  .array(
@@ -589,6 +604,10 @@ export const dispatcherStatusEventPayloadSchemas = {
589
604
  }),
590
605
  )
591
606
  .max(64),
607
+ tickets: z
608
+ .array(z.strictObject({ ticket: ticketRefSchema, attempt: z.string().min(1) }))
609
+ .max(8)
610
+ .optional(),
592
611
  }),
593
612
  /** A latest-only scheduling hint: where each rotated loop of a bounded
594
613
  * pass continues on the next pass, the key of the last item it started.
@@ -1042,10 +1061,27 @@ const preparationIdentity = {
1042
1061
  ticket: ticketRefSchema,
1043
1062
  }
1044
1063
  export const ticketPreparationEventPayloadSchemas = {
1064
+ /** An admitted ticket's preparation attempt. It may be appended again for
1065
+ * the same attempt, without `claimDeferred`, immediately before a carried
1066
+ * claim is made: the later event supersedes the earlier one, and from then
1067
+ * on recovery treats the claim as possibly applied. */
1045
1068
  'ticket-preparation.intended': z.strictObject({
1046
1069
  ...preparationIdentity,
1047
1070
  readyState: z.string().min(1),
1048
1071
  claimedState: z.string().min(1),
1072
+ /** The bounded invocation's work deadline, written only by a bounded
1073
+ * pass. Recovery tells a preparation that deadline interrupted (no
1074
+ * failure recorded) from a failed one, and resumes it instead of
1075
+ * handing it back. */
1076
+ workDeadlineAt: z.string().datetime().optional(),
1077
+ /** Intake admitted the ticket but made no claim call: the preparation
1078
+ * would not fit before the work deadline. The next pass claims it. */
1079
+ claimDeferred: z.literal(true).optional(),
1080
+ /** The build level admission decided, written beside `workDeadlineAt`:
1081
+ * a non-manual start request's own level, otherwise the ticket's claim
1082
+ * tier. A carried attempt resumes with it, so its build keeps the level
1083
+ * it was admitted at even after its start request settles. */
1084
+ level: z.enum(['urgent', 'high', 'normal', 'low']).optional(),
1049
1085
  }),
1050
1086
  'ticket-preparation.claimed': z.strictObject(preparationIdentity),
1051
1087
  'ticket-preparation.creation-selected': z.strictObject({