@defrex/autobuild 1.15.0 → 1.16.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.
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.15.0
29
+ bun add -d --exact @defrex/autobuild@1.16.0
30
30
  ```
31
31
 
32
32
  <!-- release-install:end -->
package/SPEC.md CHANGED
@@ -2005,11 +2005,26 @@ attempt. A tick that defers such work counts it as `provisioningDeferred` or
2005
2005
  reported idle. It records those builds in the latest-only, advisory
2006
2006
  `dispatcher.work-deferred` fact (a deferral noted after the work deadline is
2007
2007
  written in teardown, under the cleanup deadline, while the repository lease is
2008
- still held), and the next invocation sweeps them before its
2008
+ still held), and the next invocation serves them before its
2009
2009
  other stages, re-deriving every decision from build state. The fact is a
2010
2010
  scheduling hint, never authority; an entry leaves it only after its own pass
2011
2011
  finishes without deferring again. Carried recoveries start within half of the
2012
2012
  window that remains.
2013
+ Every start a bounded pass admits but does not finish is carried this way, so a
2014
+ held slot always has its start in progress or first in the next pass. A first
2015
+ provision the budget defers right after a claim is carried as `provision`, and
2016
+ the next invocation serves a carried build that is still queued by completing
2017
+ its dispatch. A launch the work deadline cuts after claiming the build's
2018
+ execution lease is carried as `launch`. Bounded teardown awaits it before the
2019
+ repository lease is released. A start never requested releases the exact-holder
2020
+ lease. A requested start is fenced first and released only after the fence is
2021
+ confirmed, because a released but running guest could re-claim the lease beside
2022
+ a replacement. When teardown cannot confirm the fence or the release, the entry
2023
+ keeps the cut execution's `instance` and the step still owed (`fence` or
2024
+ `launch`). The next invocation finishes that exact work first, and only while
2025
+ that instance still holds the lease; the lease never waits on its TTL. A
2026
+ carried entry retires without launching when its build is aborted, discarded,
2027
+ paused or no longer needs the start.
2013
2028
  No stage consumes a bounded pass. Its stages run in order (deferred work,
2014
2029
  settlement, ticket preparations, janitor, recovery, lease sweep, admission,
2015
2030
  intake), and each may start new items only until its share of the time left
@@ -6157,8 +6172,9 @@ down. A workspace
6157
6172
  flagged by `workspace.cleanup-required` is never launched into: the dispatcher
6158
6173
  releases it and provisions the next generation. Provisioning cut off by a
6159
6174
  recorded dispatcher teardown is the exception: the next invocation asks the
6160
- provider to verify and finish the same generation, and if it cannot, the
6161
- replacement consumes no infrastructure attempt. A preservation or release
6175
+ provider to verify and finish the same generation (the Vercel provider resumes
6176
+ after its last completed stage, at the commit it cloned), and if it cannot,
6177
+ the replacement consumes no infrastructure attempt. A preservation or release
6162
6178
  failure is recorded against its build, as an infrastructure failure or janitor
6163
6179
  attention, and never stops the dispatcher from advancing other builds.
6164
6180
  Fencing is revalidated after restart; a saved receipt alone never authorizes
@@ -826,8 +826,9 @@ down. A workspace
826
826
  flagged by `workspace.cleanup-required` is never launched into: the dispatcher
827
827
  releases it and provisions the next generation. Provisioning cut off by a
828
828
  recorded dispatcher teardown is the exception: the next invocation asks the
829
- provider to verify and finish the same generation, and if it cannot, the
830
- replacement consumes no infrastructure attempt. A preservation or release
829
+ provider to verify and finish the same generation (the Vercel provider resumes
830
+ after its last completed stage, at the commit it cloned), and if it cannot,
831
+ the replacement consumes no infrastructure attempt. A preservation or release
831
832
  failure is recorded against its build, as an infrastructure failure or janitor
832
833
  attention, and never stops the dispatcher from advancing other builds.
833
834
  Work a bounded invocation defers for budget (a provision, or a stopped-sandbox
@@ -837,11 +838,30 @@ counted as `provisioningDeferred` or `recoveryDeferred` with one diagnostic line
837
838
  per build, and carried in the latest-only `dispatcher.work-deferred` fact; one
838
839
  noted after the work signal aborts is written through the tick's
839
840
  `teardownWrite` scope under the cleanup signal. The
840
- next tick's first stage, `serviceDeferredWork`, runs the ordinary `sweepBuild`
841
- pass for those builds before settlement and the janitor; the lease sweep and
842
- settlement skip what it took up. A resume the deadline cuts short is stopped or
843
- left uncertain, and observation reports a budget deferral as a `running`
841
+ next tick's first stage, `serviceDeferredWork`, serves those builds before
842
+ settlement and the janitor through `serviceCarriedStart`: a carried cut
843
+ holder first, then `attemptDispatchCompletion` for a build still queued (a
844
+ first provision the budget gate deferred after a claim), and the ordinary
845
+ `sweepBuild` pass otherwise, with the facts it already read and without the
846
+ first-claim grace. Settlement, dispatch recovery (`recoverDispatches`) and the
847
+ lease sweep skip what it took up. A resume the deadline cuts short is stopped
848
+ or left uncertain, and observation reports a budget deferral as a `running`
844
849
  observation marked `deferred`.
850
+ A launch the work deadline cuts after `DispatchLoop.launchRunner` claimed the
851
+ build's execution lease records nothing itself: it throws `LaunchCutByDeadline`
852
+ (`processes/launch-cut.ts`) carrying the instance and whether the provider
853
+ start was requested, and `launchRunner` re-checks `acceptingBuildLaunches`
854
+ immediately before that start. `Dispatcher.startRunner` catches it and runs
855
+ `settleCutLaunch`, and `settleCutHolder` does the work through the tick's
856
+ teardown scope: it fences a requested start with the owning provider's
857
+ `recovery.fence` (passing `{ teardown: true }`, so Vercel bounds the calls by
858
+ its operation timeout and the cleanup scope), then releases the exact-holder
859
+ lease. What it cannot finish is noted with the cut `instance` and the step
860
+ still owed, and the next invocation's `serviceCarriedStart` settles that exact
861
+ holder before anything else. Starts are tracked in flight, and bounded
862
+ teardown awaits `Dispatcher.settleCutStarts()` as a racer beside provisioning
863
+ abandonment, before the repository lease is released; it prints each deferral
864
+ line the tick has not reported, and the cut pass's partial summary counts them.
845
865
  Stage fairness lives in `processes/pass-stages.ts` (pure: shares, rotation,
846
866
  the stage record and its rendering). `Dispatcher.runTick` wraps each stage in
847
867
  `runStage`, which hands its helpers a copy of the tick options whose
@@ -1628,7 +1628,10 @@ treated as running:
1628
1628
  the tick counts it as `recoveryDeferred`, logs
1629
1629
  `build <slug>: <step> deferred by the invocation budget`, and records the
1630
1630
  build in the latest-only `dispatcher.work-deferred` fact. The next
1631
- invocation sweeps those builds first, within half of the window.
1631
+ invocation runs those builds first, within half of the window. A launch the
1632
+ work deadline cuts after claiming the build's execution lease is carried
1633
+ the same way, as step `launch`: teardown fences the sandbox if the start was
1634
+ requested, then releases the lease, or the next invocation does both first.
1632
1635
  - **No redundant stops.** Fence and cleanup skip `stop()` for a sandbox the
1633
1636
  provider already reports stopped.
1634
1637
  - **Failures name their step.** `infrastructure.failed` and the exhaustion
@@ -1653,11 +1656,13 @@ The dispatcher releases it automatically, recording an empty
1653
1656
  checkout that never started executing lacks its objects, and provisions
1654
1657
  the next generation. A sandbox whose provisioning a dispatcher teardown cut off
1655
1658
  is different: the next invocation verifies it and finishes it in the same
1656
- generation. If it cannot be finished, it is released and replaced without
1659
+ generation, resuming after its last completed stage at the commit it cloned. If it cannot be finished, it is released and replaced without
1657
1660
  consuming `maxInfrastructureAttempts`. A bounded dispatcher invocation does not
1658
1661
  start provisioning with less than about 150 s of budget left; it records
1659
1662
  `provisioningDeferred` in the tick report, logs the build, and records it in
1660
- `dispatcher.work-deferred`, so the next invocation provisions it first.
1663
+ `dispatcher.work-deferred`, so the next invocation provisions it first. That
1664
+ includes the first provision of a build intake just claimed: the build keeps
1665
+ its slot, and the next invocation completes its dispatch first.
1661
1666
 
1662
1667
  The representative actual-provider check is opt-in and must point at an
1663
1668
  independent consuming repository whose `autobuild.toml` selects the universal
@@ -96,6 +96,9 @@ 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
102
 
100
103
  ### Origin-mode dispatcher with remote workspaces
101
104
 
@@ -131,20 +131,31 @@ See [answering blocked builds](operating.md#answer-and-pause). Preserve event lo
131
131
  A step the invocation deadline defers is not a failure:
132
132
 
133
133
  - It charges no infrastructure attempt.
134
- - The dispatch log names it: `build <slug>: <step> deferred by the invocation budget`.
134
+ - The dispatch log names it: `build <slug>: <step> deferred by the invocation budget`. The step is `provision`, `launch` or a recovery step.
135
135
  - The tick counts it as `recoveryDeferred` (or `provisioningDeferred`) and never reports `tick: idle`.
136
- - The next invocation runs that build first.
136
+ - The build keeps its slot, and the next invocation runs it first.
137
+ - A `launch` the deadline cut never waits on a lease TTL. Teardown fences the sandbox when the start was requested, then releases the lease; the next invocation's first stage finishes whatever teardown couldn't.
137
138
 
138
139
  See [Vercel sandbox recovery](configuration.md#vercel-sandbox).
139
140
 
140
141
  ## A build stays STARTING with repeated deferral lines
141
142
 
142
- **Symptom.** The same build logs `resume deferred by the invocation budget` or `provision deferred by the invocation budget` on several invocations in a row, and stays STARTING.
143
+ **Symptom.** The same build logs `resume`, `provision` or `launch deferred by the invocation budget` on several invocations in a row, and stays STARTING.
143
144
 
144
145
  **Cause.** Even with the build served first, the hosted invocation budget can't fit the work. A provision needs about 150 s; a resume needs about 105 s by default (a realistic resume plus the cleanup reserve).
145
146
 
146
147
  **Action.** Report it to the instance operator: the invocation budget is too small for this work. Retrying the build doesn't help.
147
148
 
149
+ A repeating `fence deferred by the invocation budget` line with an infrastructure failure at step `fence` is different: the provider can't confirm the sandbox stopped, so the cut launch's lease is kept and nothing relaunches. Check the sandbox in the provider.
150
+
151
+ ## A provision is cut off at teardown on several invocations
152
+
153
+ **Symptom.** A STARTING build's provisioning is abandoned at dispatcher teardown on more than one invocation.
154
+
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
+
157
+ **Action.** If teardown keeps cutting off the same stage, that one stage outlasts the invocation budget. Report the stage to the instance operator.
158
+
148
159
  ## A stage keeps stopping at the work deadline
149
160
 
150
161
  **Symptom.** Hosted invocations log `tick: work deadline reached during <stage>`, or `ab repository status` shows `last pass stages: … stopped by the work deadline during …` on pass after pass.
@@ -115,6 +115,7 @@ Sandbox preparation order:
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
117
  - **Repetition.** New sandboxes repeat provisioning and preflights rerun before each build-runner; keep setup idempotent.
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.
118
119
  - **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.
119
120
  - **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).
120
121
 
@@ -154,4 +155,4 @@ The suite certifies only the basic working copy. Remote execution adds trusted s
154
155
  - Publication reports confirmed SHA and cache tips and supports the required guarded rewrites.
155
156
  - Store grants go through the host's `delegateCredential` callback; never serialize host tokens into execution identity.
156
157
  - An optional `provisionEstimateMs` declares the expected wall time of one `provision`; a bounded dispatcher invocation does not start provisioning with less budget left.
157
- - `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; otherwise throw `WorkspaceCleanupRequired`.
158
+ - `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.15.0",
3
+ "version": "1.16.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.15.0",
166
- "@defrex/autobuild-vercel-sandbox": "1.15.0",
165
+ "@defrex/autobuild-postgres-store": "1.16.0",
166
+ "@defrex/autobuild-vercel-sandbox": "1.16.0",
167
167
  "@resvg/resvg-js": "2.6.2",
168
168
  "@types/bun": "^1.3.14",
169
169
  "@types/node": "^24.0.0",
@@ -258,6 +258,8 @@ import {
258
258
  budgetedFetch,
259
259
  DEFAULT_TIMERS,
260
260
  InvocationBudgetExhaustedError,
261
+ InvocationDeadlineError,
262
+ LaunchCutByDeadline,
261
263
  invocationSignal,
262
264
  untilAborted,
263
265
  withInvocationSignal,
@@ -442,6 +444,9 @@ export {
442
444
  budgetedFetch,
443
445
  InvocationDeadlineError,
444
446
  InvocationBudgetExhaustedError,
447
+ LaunchCutByDeadline,
448
+ isLaunchCutByDeadline,
449
+ type CutLaunch,
445
450
  type InvocationBudget,
446
451
  } from '../processes/invocation-budget'
447
452
 
@@ -883,6 +888,9 @@ interface ActiveBuildExecution {
883
888
  detaching?: boolean
884
889
  /** A wait failure being recorded; teardown lets it finish rather than drop it. */
885
890
  recording?: Promise<void>
891
+ /** Set immediately before the provider start is requested: from here a
892
+ * deadline-cut launch may have a guest running and must be fenced. */
893
+ startRequested?: boolean
886
894
  }
887
895
 
888
896
  /** The dispatch loop owns deterministic decisions and supervises one
@@ -3753,10 +3761,18 @@ class DispatchLoop {
3753
3761
  const active: ActiveBuildExecution = { reservation, instance, stopping: false }
3754
3762
  this.activeBuildRuns.set(slug, active)
3755
3763
  let leaseClaimed = false
3764
+ /** The claim was sent but not acknowledged: it may have committed. */
3765
+ let claimUnacknowledged = false
3766
+ let cutWorkspace: { provider: string; ref: string } | undefined
3767
+ /** Whether the owning provider can fence its workspace (stop a guest
3768
+ * that outlives this process). */
3769
+ let cutFenceable = false
3756
3770
 
3757
3771
  try {
3758
3772
  await this.publishBuildConfig(slug)
3773
+ claimUnacknowledged = true
3759
3774
  leaseClaimed = await this.repoView.claimLease(slug, instance, BUILD_EXECUTION_LEASE_TTL_MS)
3775
+ claimUnacknowledged = false
3760
3776
  if (!leaseClaimed) {
3761
3777
  this.activeBuildRuns.delete(slug)
3762
3778
  await this.appendStatus({
@@ -3775,7 +3791,11 @@ class DispatchLoop {
3775
3791
  // provisioned before a provider switch still runs where it lives.
3776
3792
  const owning =
3777
3793
  workspaceProvider === undefined || workspaceProvider === this.wiring.workspaces.name
3778
- ? { name: this.wiring.workspaces.name, execution: this.wiring.buildExecution }
3794
+ ? {
3795
+ name: this.wiring.workspaces.name,
3796
+ execution: this.wiring.buildExecution,
3797
+ recovery: this.wiring.workspaces.recovery,
3798
+ }
3779
3799
  : (() => {
3780
3800
  const retired = this.wiring.retiredWorkspaces?.find(
3781
3801
  (runtime) => runtime.provider.name === workspaceProvider,
@@ -3785,8 +3805,14 @@ class DispatchLoop {
3785
3805
  `build ${slug} workspace ${workspaceRef} belongs to provider "${workspaceProvider}", which is no longer configured`,
3786
3806
  )
3787
3807
  }
3788
- return { name: retired.provider.name, execution: retired.execution }
3808
+ return {
3809
+ name: retired.provider.name,
3810
+ execution: retired.execution,
3811
+ recovery: retired.provider.recovery,
3812
+ }
3789
3813
  })()
3814
+ cutWorkspace = { provider: owning.name, ref: workspaceRef }
3815
+ cutFenceable = owning.recovery !== undefined
3790
3816
  // A prior publication acknowledgement may have been lost after its push
3791
3817
  // reached the durable branch. Reconcile that fact before a replacement
3792
3818
  // runner can rerun the phase and create a non-fast-forward successor.
@@ -3804,6 +3830,9 @@ class DispatchLoop {
3804
3830
  ),
3805
3831
  }
3806
3832
  : undefined
3833
+ // No launch starts after the work deadline (teardown's invariant).
3834
+ if (!this.acceptingBuildLaunches) throw new InvocationDeadlineError('work')
3835
+ active.startRequested = true
3807
3836
  const handle = await owning.execution.start(
3808
3837
  {
3809
3838
  slug,
@@ -3960,6 +3989,25 @@ class DispatchLoop {
3960
3989
  if (isRecoveryDeferred(error)) throw error
3961
3990
  return 'already-active'
3962
3991
  }
3992
+ if (
3993
+ (leaseClaimed || claimUnacknowledged) &&
3994
+ this.opts.invocationBudget?.work.aborted === true &&
3995
+ (active.handle === undefined || (await this.releaseCutHandle(active.handle, cutFenceable)))
3996
+ ) {
3997
+ // The work deadline cut the launch after its lease claim — before
3998
+ // the claim's acknowledgement (it may have committed; the exact-holder
3999
+ // release is a no-op if not), before the provider returned, or
4000
+ // before `execution.started` committed.
4001
+ // Record nothing here: the dispatcher fences when the start was
4002
+ // requested, releases the exact holder in teardown and carries the
4003
+ // launch.
4004
+ throw new LaunchCutByDeadline({
4005
+ slug,
4006
+ instance,
4007
+ startRequested: active.startRequested === true,
4008
+ ...(cutWorkspace !== undefined ? { workspace: cutWorkspace } : {}),
4009
+ })
4010
+ }
3963
4011
  if (leaseClaimed) {
3964
4012
  // The runner appended through its own handle: take the delta.
3965
4013
  await this.repoView.refreshBuild(slug)
@@ -3994,6 +4042,28 @@ class DispatchLoop {
3994
4042
  }
3995
4043
  }
3996
4044
 
4045
+ /** A handle whose `execution.started` the work deadline cut: nothing will
4046
+ * settle it, so stop supervising it. A guest that outlives this process is
4047
+ * detached for the dispatcher's workspace fence; a local child is stopped
4048
+ * here. False when neither can prove the execution gone — the ordinary
4049
+ * start failure then keeps the lease until its TTL fences it. */
4050
+ private async releaseCutHandle(
4051
+ handle: BuildExecutionHandle,
4052
+ fenceable: boolean,
4053
+ ): Promise<boolean> {
4054
+ handle.completion.catch(() => {})
4055
+ if (handle.supervision === 'environment') {
4056
+ if (!fenceable) return false
4057
+ await handle.detach().catch(() => {})
4058
+ return true
4059
+ }
4060
+ try {
4061
+ return (await handle.stop())?.outcome !== 'unknown'
4062
+ } catch {
4063
+ return false
4064
+ }
4065
+ }
4066
+
3997
4067
  private get stopped(): boolean {
3998
4068
  return (
3999
4069
  this.cutoverRequested || this.opts.signal?.aborted === true || this.inputStop.signal.aborted
@@ -5606,9 +5676,18 @@ class DispatchLoop {
5606
5676
  // Whether or not the deadline fired, no launch may start during
5607
5677
  // teardown: provisioning abandonment runs beside execution teardown.
5608
5678
  this.onWorkDeadline()
5679
+ // Runner starts the work deadline cut mid-flight settle their execution
5680
+ // leases (fence, exact-holder release) and carry the launch in the
5681
+ // deferred-work hint while the repository lease is still held.
5682
+ const starts = untilAborted(
5683
+ withInvocationSignal(budget.cleanup, async () => {
5684
+ for (const line of await this.dispatcher.settleCutStarts()) this.say(line)
5685
+ }),
5686
+ budget.cleanup,
5687
+ )
5609
5688
  // The cut pass's lines print now; its advisory writes race beside the
5610
5689
  // other cleanup, so a stalled write never postpones unrelated teardown.
5611
- const summary = this.reportCutPass(budget)
5690
+ const summary = this.reportCutPass(budget, starts)
5612
5691
  const provisioning = untilAborted(
5613
5692
  withInvocationSignal(budget.cleanup, () => this.dispatcher.stopProvisioning()),
5614
5693
  budget.cleanup,
@@ -5624,7 +5703,7 @@ class DispatchLoop {
5624
5703
  }),
5625
5704
  budget.cleanup,
5626
5705
  )
5627
- const cleanup = await Promise.allSettled([provisioning, optional, summary])
5706
+ const cleanup = await Promise.allSettled([provisioning, optional, summary, starts])
5628
5707
  await untilAborted(
5629
5708
  withInvocationSignal(budget.final, () => this.releaseRepoLease()),
5630
5709
  budget.final,
@@ -5639,7 +5718,7 @@ class DispatchLoop {
5639
5718
  * the pass's loops reached and close the still-open tick boundary with
5640
5719
  * that partial summary, so `ab repository status` shows it. Never rejects:
5641
5720
  * a concurrent abandoned publication may already have closed the boundary. */
5642
- private reportCutPass(budget: InvocationBudget): Promise<void> {
5721
+ private reportCutPass(budget: InvocationBudget, starts: Promise<unknown>): Promise<void> {
5643
5722
  const writes: Promise<void>[] = []
5644
5723
  const write = (what: string, run: () => Promise<unknown>) =>
5645
5724
  writes.push(
@@ -5652,24 +5731,30 @@ class DispatchLoop {
5652
5731
  // A no-op when the pass already recorded its positions; the write itself
5653
5732
  // goes through teardownWrite.
5654
5733
  write('pass positions', () => this.dispatcher.persistPassPositions())
5655
- const partial = this.stagesPrinted ? undefined : this.dispatcher.passReport()
5656
- if (partial?.stages !== undefined && partial.stages.length > 0) {
5657
- this.printStages(partial.stages)
5734
+ const stages = this.stagesPrinted ? undefined : this.dispatcher.passReport()?.stages
5735
+ if (stages !== undefined && stages.length > 0) {
5736
+ this.printStages(stages)
5658
5737
  if (this.tickStartedAt !== undefined) {
5659
- const {
5660
- queued: _queued,
5661
- janitorDiagnostics: _janitorDiagnostics,
5662
- blockedDiagnostics: _blockedDiagnostics,
5663
- ticketDiagnostics: _ticketDiagnostics,
5664
- creationDiagnostics: _creationDiagnostics,
5665
- dependencyDiagnostics: _dependencyDiagnostics,
5666
- agentContextDiagnostics: _agentContextDiagnostics,
5667
- deferredDiagnostics: _deferredDiagnostics,
5668
- ...counters
5669
- } = partial
5670
- write('partial pass summary', () =>
5671
- this.teardownWrite(budget)(() => this.finishTick({ outcome: 'completed', counters }, [])),
5672
- )
5738
+ write('partial pass summary', async () => {
5739
+ // The closed tick counts the starts teardown carried.
5740
+ await starts.catch(() => {})
5741
+ const partial = this.dispatcher.passReport()
5742
+ if (partial === undefined) return
5743
+ const {
5744
+ queued: _queued,
5745
+ janitorDiagnostics: _janitorDiagnostics,
5746
+ blockedDiagnostics: _blockedDiagnostics,
5747
+ ticketDiagnostics: _ticketDiagnostics,
5748
+ creationDiagnostics: _creationDiagnostics,
5749
+ dependencyDiagnostics: _dependencyDiagnostics,
5750
+ agentContextDiagnostics: _agentContextDiagnostics,
5751
+ deferredDiagnostics: _deferredDiagnostics,
5752
+ ...counters
5753
+ } = partial
5754
+ await this.teardownWrite(budget)(() =>
5755
+ this.finishTick({ outcome: 'completed', counters }, []),
5756
+ )
5757
+ })
5673
5758
  }
5674
5759
  }
5675
5760
  return Promise.all(writes).then(() => undefined)
@@ -152,7 +152,9 @@ const tickCountersSchema = z.strictObject({
152
152
  * provisioning estimate. Optional so historical tick facts replay. */
153
153
  provisioningDeferred: z.number().int().nonnegative().optional(),
154
154
  /** Builds whose stopped-sandbox recovery (or a launch waiting on one) the
155
- * invocation budget deferred. Optional so historical tick facts replay. */
155
+ * invocation budget deferred, or whose launch the work deadline cut after
156
+ * its execution lease was claimed. Optional so historical tick facts
157
+ * replay. */
156
158
  recoveryDeferred: z.number().int().nonnegative().optional(),
157
159
  /** Operator sandboxes idly stopped this tick. Added with the operator
158
160
  * sandbox; optional so historical tick facts replay. */
@@ -570,16 +572,20 @@ export const orchestratorSandboxEventPayloadSchemas = {
570
572
 
571
573
  export const dispatcherStatusEventPayloadSchemas = {
572
574
  /** A latest-only scheduling hint: the builds whose deadline-gated work
573
- * (a provision or a stopped-sandbox recovery step) a bounded invocation
574
- * deferred for budget. The next tick sweeps these builds first, re-deriving
575
- * every decision from fresh build state; it is never authority. An empty
576
- * list clears it. */
575
+ * (a provision, a runner launch the work deadline cut, or a stopped-sandbox
576
+ * recovery step) a bounded invocation deferred for budget. The next tick
577
+ * serves these builds first, re-deriving every decision from fresh build
578
+ * state; it is never authority. An empty list clears it. `instance` names a
579
+ * deadline-cut execution whose exact-holder lease teardown could not
580
+ * 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. */
577
582
  'dispatcher.work-deferred': z.strictObject({
578
583
  builds: z
579
584
  .array(
580
585
  z.strictObject({
581
586
  slug: z.string().min(1),
582
- step: z.enum(['provision', 'resume', 'fence', 'preserve', 'cleanup']),
587
+ step: z.enum(['provision', 'launch', 'resume', 'fence', 'preserve', 'cleanup']),
588
+ instance: z.string().min(1).optional(),
583
589
  }),
584
590
  )
585
591
  .max(64),
@@ -0,0 +1,108 @@
1
+ {
2
+ "records": [
3
+ {
4
+ "name": "repositoryReadFacts",
5
+ "identity": "repositoryReadFacts",
6
+ "revisions": [
7
+ "repositoryAttention/fold/u6bhzf2af0",
8
+ "repositoryReadFacts/fold/0xl1c98cpy",
9
+ "repositoryReadFacts/fold/4gnmhbji3n",
10
+ "repositoryReadFacts/fold/5porrk9y1h",
11
+ "repositoryReadFacts/fold/fk3ka9gb3z",
12
+ "repositoryReadFacts/fold/vvcfmd23zp",
13
+ "repositoryReadFacts/shape/5yo149tiqz",
14
+ "repositoryReadFacts/shape/70jpyc3nd3",
15
+ "repositoryReadFacts/shape/7hbgb52kw8",
16
+ "repositoryReadFacts/shape/e2u2pgiup3",
17
+ "repositoryReadFacts/shape/ez3eddcdoo",
18
+ "repositoryReadFacts/shape/hgw4spz5c0",
19
+ "repositoryReadFacts/shape/mggr8x6l5z",
20
+ "repositoryReadFacts/shape/o7791nz2gt",
21
+ "repositoryReadFacts/shape/se5kk44boc",
22
+ "repositoryReadFacts/shape/xyn7875cxw",
23
+ "sandboxStates/fold/hjdgop7xoh",
24
+ "sandboxStates/shape/gbrf8k4qxq",
25
+ "ticketStarts/fold/8fp156vze2",
26
+ "ticketStarts/fold/eglrhnb0ta",
27
+ "ticketStarts/shape/dzxrbuuq7e",
28
+ "ticketStarts/shape/eecofz22vy"
29
+ ],
30
+ "entries": {
31
+ "017d8dd5bb6dd80b": "9b19c8eb254d503fbe74d8de7039566f",
32
+ "10a4657408d4e121": "218f9c92364c4b9176b70c9bee8a29f8",
33
+ "1411d1cdbdd9911e": "a5b60fa55d3c1d3999e4ee947878bd23",
34
+ "1444fe1fa7fc802c": "81c89822174d63012aa06ad744fae9e6",
35
+ "178e12f1759b7552": "61197c43eb41d8451ce5182402f23373",
36
+ "1921f86f752428c9": "abf8d370c9d94b6a50ab70d52d33454b",
37
+ "1972c1d66008ef6b": "56c634f6d1a0076256c385b2a9feab7c",
38
+ "19e8e43e7f3f1a06": "b18b2ccd2d11b39684f2fc991526b0d6",
39
+ "21ce2c0bf58318e1": "8eedb8f516b89cb65230c9cedb1bd903",
40
+ "293dcb3a94fb3470": "203e641af713b42a0e5369f9486f2301",
41
+ "2ab7436356267118": "fc4031327a07006ccdc946bf07aba04f",
42
+ "2d084641735caaff": "1061299214f493d5d51f9c11afae68ab",
43
+ "3237bcecf68e5db9": "79f6d09249036fd77dc5d3400e18124a",
44
+ "33d0cc593610e56f": "bd88ed40c1ada79d8657af1b339a6a9f",
45
+ "35cf9ccc4478b2d2": "5a2279bc99403d0f7d40cede4c8bb573",
46
+ "3649e7bd1203f154": "9d3742c0e29c7a3e999c9c9a8c6eac27",
47
+ "38c75099d9191471": "203e641af713b42a0e5369f9486f2301",
48
+ "431c9bb2ee8838e0": "0715d441ad523323105867bf09108797",
49
+ "49064fc079964a5c": "844ca8b44174ab640ce17a713b580d7d",
50
+ "4932c70a2af97faf": "0c732c6ead43fcb8d5f34159ac5e0e0b",
51
+ "4f00c0f2c8afd159": "9688f560966f37d57b4177bf5aa4b7f0",
52
+ "516a5a7aadf97587": "e63f56f546ed51d4e04df1e86c9fc476",
53
+ "536085773daf6b58": "57901f1d28ee614272cc8915a80e38ff",
54
+ "59ffaa6974094c72": "d1757ea5344f9164aca22e3ca6ca165a",
55
+ "5f0ca42af862c4ee": "840d8a2c1947ef0941e1ab8bf3afd42e",
56
+ "6118031132db9bfc": "8c44d3ef5b8a0241b5c712f994d56907",
57
+ "643d70429ce03dad": "c2b7bfc98da1427b6a3858d814d3f57b",
58
+ "677ea92572c29082": "4067b95ee98f33bc298d71c7489fabba",
59
+ "6ae5bf60504d6467": "58975765e668c4f361659977261d56ed",
60
+ "6bd6275061aaffa5": "c84c2528779e3ecc21e549e0ef2adedd",
61
+ "6efdc8defc75fccb": "d5b512d4f4c16b9d4bcadbee8f8206ad",
62
+ "7833e42d16301424": "b32c86839cd9044a4d7757d51b62db14",
63
+ "7d4edad0614adaf1": "54a48a0b441082d54a07d786c217153e",
64
+ "837365898d04f45a": "54a48a0b441082d54a07d786c217153e",
65
+ "85f9f0c921b8b5bb": "0926918433e11ebd637e34dae2a2d615",
66
+ "8879f57a24733897": "58975765e668c4f361659977261d56ed",
67
+ "88cb9e71bdec972d": "3f7ed5a476e6457efedb7cdf6412fd23",
68
+ "89625654b02e9ac1": "bac4fc52c015d8cb7b9f833dda540b85",
69
+ "8cc15eb1807c0157": "10c221f0b9db3782b1dca2ed6eb1f5c9",
70
+ "8ced97c44bc0af3a": "d998291081ba51e1bef3205aae7595ef",
71
+ "8d4144004720b9f8": "ef6389a96f072b54e91a0e0f19c827b8",
72
+ "8db633ead1807f8b": "c4fe43ef3276b5877db1b08a38d607cb",
73
+ "8e42cdbd0994ab0c": "e12aa5b2f6373eceb51f303a929e8d5a",
74
+ "9539b995af5c54a9": "1061299214f493d5d51f9c11afae68ab",
75
+ "9ee3919fbd4f9458": "a553618f38080bfcb814cb4a5416cfb1",
76
+ "a0b32c12e4e6edb6": "d323237478cd65b159eda1faab172bcf",
77
+ "a55218252707bdd3": "54a48a0b441082d54a07d786c217153e",
78
+ "a98af134be2da8a9": "9a0830cc47de7a66b3c2f1a85a7eb852",
79
+ "af953392d81911da": "58975765e668c4f361659977261d56ed",
80
+ "b0d877c44810ecb0": "64a155224f6c8526212f92f64e7ef575",
81
+ "be211f0e31a65006": "64a155224f6c8526212f92f64e7ef575",
82
+ "c68b7ee2e2610f30": "05034ebd16ae9bf93b398663b30aea92",
83
+ "c7f7e0378aeea237": "1061299214f493d5d51f9c11afae68ab",
84
+ "c98cb1659eb142b6": "64a155224f6c8526212f92f64e7ef575",
85
+ "ca830adf06ed55a1": "54a48a0b441082d54a07d786c217153e",
86
+ "cb3a219f33e437ca": "feab7b027da5be2ecf041dd93fb55f1d",
87
+ "cf1e0c0d82567e0c": "cac9aba9f25adeb55568e902396839a4",
88
+ "d1432a819d8e48c5": "203e641af713b42a0e5369f9486f2301",
89
+ "d185ed6aa9192aff": "235467b1c87a46b383a7fa8550d8a2f8",
90
+ "d5d5ccca80a893d8": "0fdfd82c7426fd151bbb7544cd415187",
91
+ "d873fad29d6c7e55": "3f7ed5a476e6457efedb7cdf6412fd23",
92
+ "e2f18fa32fe1f6d0": "e5878dff98f5f30c5f82c1656fa82737",
93
+ "e37393fed29e84c5": "b32c86839cd9044a4d7757d51b62db14",
94
+ "e6a8585e2a054ff6": "ed2947f48b407a9a4f3bbfd151d8bc63",
95
+ "eb7ddd5319d09e27": "e7fa56dec140a7688e4a7d470b419aba",
96
+ "eca4959b2b87ae15": "5d66240a5fdec0ca59deafae16615bc5",
97
+ "ee10d7959ec4843c": "7a0b8bf4fb7a11ea26c5431bc205f96d",
98
+ "ef1b68347966ab26": "3f7ed5a476e6457efedb7cdf6412fd23",
99
+ "f3e55425cc41f230": "54a48a0b441082d54a07d786c217153e",
100
+ "f5b9ace9b59351e7": "3f7ed5a476e6457efedb7cdf6412fd23",
101
+ "f8155387eb5f375c": "5c119a1b47ade210ed5517f68b3babfc",
102
+ "fa8f1475a55be935": "8ecd3e416726e4af9b75f8eaa983f171",
103
+ "fb21116a15d0b1f1": "22c5ba7ef2445e8d6a9e7bbeb1b06d52",
104
+ "fe95444fbeabe592": "4b033ccb2ce1d4edc32bb44601049293"
105
+ }
106
+ }
107
+ ]
108
+ }
@@ -98,4 +98,5 @@ export const REDUCER_REVISIONS: Readonly<Record<string, string>> = {
98
98
  'repositoryReadFacts/fold/5porrk9y1h': '#1406 latest dispatcher.work-deferred is carried forward',
99
99
  'repositoryReadFacts/shape/ez3eddcdoo': '#1409 pass cursors and stage timings',
100
100
  'repositoryReadFacts/fold/0xl1c98cpy': '#1409 latest dispatcher.pass-cursors is carried forward',
101
+ 'repositoryReadFacts/shape/70jpyc3nd3': '#1415 launch step, cut instance in deferred hint',
101
102
  }
@@ -665,8 +665,12 @@ export interface WorkspaceReapOutcome {
665
665
  }
666
666
 
667
667
  export interface WorkspaceRecovery {
668
- /** Stops execution without deleting the workspace or its snapshots. */
669
- fence?(handle: WorkspaceHandle): Promise<WorkspaceFenceOutcome>
668
+ /** Stops execution without deleting the workspace or its snapshots.
669
+ * `teardown`: the dispatcher calls it during a bounded invocation's
670
+ * teardown, after the work deadline, to settle a launch that deadline cut.
671
+ * Bound the calls by the provider's own operation timeout and the ambient
672
+ * teardown scope, not by the invocation's work deadline. */
673
+ fence?(handle: WorkspaceHandle, opts?: { teardown?: boolean }): Promise<WorkspaceFenceOutcome>
670
674
 
671
675
  /** Fence an unavailable environment. Unknown outcomes must reject so the
672
676
  * dispatcher retains the lease/workspace fact and retries after its fence. */
@@ -746,8 +750,10 @@ export interface WorkspaceProvider {
746
750
  generation?: number
747
751
  /** The previous attempt at this exact generation was abandoned at a
748
752
  * recorded dispatcher teardown and its lease is gone. A provider that can
749
- * verify the partial environment may finish it in place. Otherwise, or on
750
- * any doubt, it throws `WorkspaceCleanupRequired` as for any incomplete
753
+ * verify the partial environment may finish it in place, resuming from
754
+ * its own verified progress and keeping the commit the environment
755
+ * already holds, which the restack later advances. Otherwise, or on any
756
+ * doubt, it throws `WorkspaceCleanupRequired` as for any incomplete
751
757
  * environment. Never expose an unverified environment. */
752
758
  adoptAbandoned?: boolean
753
759
  /** The leaf build has no prior `workspace.provisioned` or cleanup-required