@defrex/autobuild 1.14.0 → 1.15.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.14.0
29
+ bun add -d --exact @defrex/autobuild@1.15.0
30
30
  ```
31
31
 
32
32
  <!-- release-install:end -->
package/SPEC.md CHANGED
@@ -2008,8 +2008,31 @@ written in teardown, under the cleanup deadline, while the repository lease is
2008
2008
  still held), and the next invocation sweeps 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
- finishes without deferring again. Several carried recoveries can use most of
2012
- that invocation's window before the janitor runs.
2011
+ finishes without deferring again. Carried recoveries start within half of the
2012
+ window that remains.
2013
+ No stage consumes a bounded pass. Its stages run in order (deferred work,
2014
+ settlement, ticket preparations, janitor, recovery, lease sweep, admission,
2015
+ intake), and each may start new items only until its share of the time left
2016
+ when it starts: a half for deferred work, the janitor and the lease sweep, a
2017
+ quarter for the others, and intake runs to the work deadline. Each helper in a
2018
+ stage still starts its first item while the work deadline has not passed, and
2019
+ in-flight work is never cancelled at a share. Loops whose items stay listed
2020
+ after handling (execution, harvest and operator-sandbox settlement, the
2021
+ janitor, hand-back settlement, dispatch recovery, startup resume and the lease
2022
+ sweep) visit their items in key order from the last item they started, so
2023
+ every item is reached within a bounded number of passes whatever order the
2024
+ listing returns; their positions are the latest-only, advisory
2025
+ `dispatcher.pass-cursors` fact, written at most once per pass and only when
2026
+ one changed; a pass the work deadline abandons mid-visit records them in
2027
+ teardown, so the visit cut short is not retried first. Priority-ordered loops (node admission, start requests, ready
2028
+ tickets, parked admission, ticket waits) keep their order. In a bounded pass a
2029
+ node's integration receipts are recovered at the start of its own janitor
2030
+ visit, and listings are not filtered for mixed-version deferral: the build a
2031
+ decision reads, writes or acts on is checked itself, at most once a pass. Each
2032
+ bounded pass logs `stages:` with each stage's time and items; a pass the work
2033
+ deadline cuts short logs `tick: work deadline reached during <stage>` with the
2034
+ part in flight and how far it got, records that partial summary in teardown,
2035
+ and `ab repository status` shows the latest pass as `last pass stages:`.
2013
2036
  A budget stop is a normal run stop. Credential deletion then gets the remaining
2014
2037
  budget and at least 5 seconds; issuance or deletion unsettled by then is
2015
2038
  reported and left to the capped expiry. Each served tick
@@ -842,6 +842,23 @@ pass for those builds before settlement and the janitor; the lease sweep and
842
842
  settlement skip what it took up. A resume the deadline cuts short is stopped or
843
843
  left uncertain, and observation reports a budget deferral as a `running`
844
844
  observation marked `deferred`.
845
+ Stage fairness lives in `processes/pass-stages.ts` (pure: shares, rotation,
846
+ the stage record and its rendering). `Dispatcher.runTick` wraps each stage in
847
+ `runStage`, which hands its helpers a copy of the tick options whose
848
+ `deadlineAt` is the stage's cut, and every per-item loop gates on `stageGate`,
849
+ which stops at the invocation budget or, past the cut, after the part's first
850
+ item. Rotated loops go through `rotated()`, which orders items after the
851
+ position read from the reduced `dispatcher.pass-cursors` fact;
852
+ `persistPassCursors` appends changed positions once a pass, through the same
853
+ hint-write discipline as the deferral hint. Each started item's key becomes the
854
+ live position at once, and bounded teardown calls `persistPassPositions`, so a
855
+ pass abandoned mid-visit still records where its loops reached. In a bounded pass `tickDigests()`
856
+ lists unfiltered and `checkCompatibility` checks the build each decision acts
857
+ on, memoized per pass. `passSummary()` closes a stage still in flight as
858
+ stopped by the deadline; bounded teardown in `cli/dispatch.ts` prints it and
859
+ closes the open tick boundary with that partial summary under the cleanup
860
+ scope. Those advisory writes race beside provisioning abandonment and
861
+ execution teardown, so a stalled one never postpones them.
845
862
  Fencing is revalidated after restart; a saved receipt alone never authorizes
846
863
  cleanup of a newer execution. Current recovery notes are linked by the session
847
864
  manifest's `workspaceRecovery` field. Recovery notes apply to the next session
@@ -1628,7 +1628,7 @@ 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 before anything else.
1631
+ invocation sweeps those builds first, within half of the window.
1632
1632
  - **No redundant stops.** Fence and cleanup skip `stop()` for a sandbox the
1633
1633
  provider already reports stopped.
1634
1634
  - **Failures name their step.** `infrastructure.failed` and the exhaustion
@@ -87,6 +87,16 @@ next tick recovers automatically without spending build infrastructure attempts.
87
87
  Project account slots never fall back to service-environment credentials.
88
88
  Observation, controls and cleanup continue during the hold.
89
89
 
90
+ Each hosted invocation is one bounded pass. Its stages share the window: the
91
+ janitor, the lease sweep and deferred work may each start items for half of the
92
+ time left when they begin, the other stages for a quarter, and intake runs to
93
+ the work deadline. Loops whose items stay listed (settlement, the janitor,
94
+ hand-backs, dispatch recovery, resume and the lease sweep) continue on the next
95
+ invocation after the last item they started; priority-ordered loops (node
96
+ admission, start requests, ready tickets, ticket waits) keep their order. Each
97
+ pass logs a `stages:` line; see
98
+ [a stage keeps stopping at the work deadline](troubleshooting.md#a-stage-keeps-stopping-at-the-work-deadline).
99
+
90
100
  ### Origin-mode dispatcher with remote workspaces
91
101
 
92
102
  Commit a remote-compatible configuration to the base branch:
@@ -776,7 +776,7 @@ builds.
776
776
  | `appendRepo` | `POST /repos/{repo}/events` | event write | `201` + repository event envelope |
777
777
  | `appendRepoIfCurrent` | `POST /repos/{repo}/events/conditional` | `{"expectedSeq": nonnegative integer, "event": event write}` | appended: `201` + repository event envelope; journal advanced: `200 null` (mirroring section 3's build compare-and-append). A server without the route answers `404`; callers report it and never fall back to an unconditional append |
778
778
  | `getRepoEvents` / `getRepositoryTail` | `GET /repos/{repo}/events?since={n}&through={n}&wait={s}` | optional `since` query value, parsed as in section 3; absence defaults to `0`. Optional `wait` in whole seconds, per the event-wait rules of section 3 | `200` + envelopes with `seq > since`, up to the frozen head; optional `through` caps the response at `seq <= through`; `409 cursor-too-old` below `max(0, head - 1000)` |
779
- | `getRepoStateEvents` | `GET /repos/{repo}/state-events` | none | `200` + the bounded repository-journal subset (AUT-489): every durable event type (`ticket-preparation.*`, `harvest.*`, `orchestrator.sandbox.*`, the three dispatcher setting types, and cross-generation handoff correlation facts: target-prepared, yield-requested, upgrade-failed, handoff-started, terminal-released, takeover, drain-deadline, drain-settled and handoff-completed) plus the latest-only `dispatcher.ticket-scan-completed`, `dispatcher.placement-set` and `dispatcher.work-deferred` facts and, when the journal has one, the tail from the latest `dispatcher.run-started`, in increasing sequence order; served inside the repository-existence gate like `GET events`, so an unknown repository is `404` |
779
+ | `getRepoStateEvents` | `GET /repos/{repo}/state-events` | none | `200` + the bounded repository-journal subset (AUT-489): every durable event type (`ticket-preparation.*`, `harvest.*`, `orchestrator.sandbox.*`, the three dispatcher setting types, and cross-generation handoff correlation facts: target-prepared, yield-requested, upgrade-failed, handoff-started, terminal-released, takeover, drain-deadline, drain-settled and handoff-completed) plus the latest-only `dispatcher.ticket-scan-completed`, `dispatcher.placement-set`, `dispatcher.work-deferred` and `dispatcher.pass-cursors` facts and, when the journal has one, the tail from the latest `dispatcher.run-started`, in increasing sequence order; served inside the repository-existence gate like `GET events`, so an unknown repository is `404` |
780
780
  | `getReducerSnapshot` (repo scope) | `GET /repos/{repo}/snapshots/{reducer}?version={n}` | required `version` query value, a positive integer; `reducer` is a registry name (`^[A-Za-z][A-Za-z0-9._-]{0,63}$`) | `200` + `{"version", "cursor", "state"}` or `200 null` when absent, written by another reducer version, ahead of the journal's tail, or the repository has no journal record; an unknown repository is `404`, which the shipped client also maps to `null` |
781
781
  | `putReducerSnapshot` (repo scope) | `PUT /repos/{repo}/snapshots/{reducer}` | `{"version": int >= 1, "cursor": int >= 0, "state": JSON}`, at most 16 MiB (`413` above) | `200 {"written": boolean}`; the stored cursor never decreases, so a write at an equal or lower cursor (or an equal cursor at an equal or lower version) and one past the journal's tail answer `written: false` |
782
782
  | `appendRepoWithArtifacts` | `POST /repos/{repo}/deposits` | atomic deposit request | `201` + `{event, artifacts}` using repository shapes |
@@ -60,6 +60,7 @@ bun ab harvest status
60
60
  - **Forge cooldown:** `forge landing/polling paused until <reset>` means a GitHub rate limit holds forge work until that reset, whether a request was refused or a successful response reported the quota exhausted. `forge rate limit <resource>` lines show the last observed quota and when it was seen.
61
61
  - **Capacity:** a build holds a slot while Autobuild owes its next move. Paused builds, builds blocked on a question once nothing is still working on them, builds waiting for a merge decision or on other tickets, and idle collecting nodes hold none. An answered or resumed build, a finished build that must re-verify or reconcile, and a build whose ticket wait ended wait as parked work for a slot ahead of claims at its level; higher-level work, including higher-level ready tickets, goes first, and `ab priority <slug> urgent` expedites a waiting build. Occupancy never exceeds `capacity`.
62
62
  - **Harvest:** check the acknowledged harvest gate and unclaimed observations. Harvest triggers at `policy.harvestThreshold` observations, or `policy.harvestMaxDrift` other merged builds since the oldest observation (zero disables drift), and uses no build slot.
63
+ - **Bounded passes:** a hosted invocation also prints `stages:`. If `intake` is missing from it, see [a stage keeps stopping at the work deadline](#a-stage-keeps-stopping-at-the-work-deadline).
63
64
 
64
65
  ## Worktree destination not isolated
65
66
 
@@ -144,6 +145,24 @@ See [Vercel sandbox recovery](configuration.md#vercel-sandbox).
144
145
 
145
146
  **Action.** Report it to the instance operator: the invocation budget is too small for this work. Retrying the build doesn't help.
146
147
 
148
+ ## A stage keeps stopping at the work deadline
149
+
150
+ **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.
151
+
152
+ **Reading the lines.** Every bounded pass prints one `stages:` line, for example:
153
+
154
+ ```text
155
+ stages: settlement 3.1s 6/11 (executions 5/9, harvest 1/2, sandboxes 0/0) · janitor 131.4s 4/12 (share) · sweep 40.2s 9/9 · intake 12.0s 1/1
156
+ ```
157
+
158
+ - **Time and items:** each stage's seconds and the items it reached out of those it listed.
159
+ - **`(share)`:** the stage used its share of the window and stopped starting items. In settlement, the janitor, hand-backs, dispatch recovery, resume and the lease sweep, the loop continues on the next invocation after the last item it started, so it works through its whole listing over successive passes. Priority-ordered loops (node admission, start requests, ready tickets, ticket waits) start from the top again.
160
+ - **`(deadline)`:** the work deadline stopped the pass inside that stage. The `tick: work deadline reached during …` line names the part in flight, such as `settlement: harvest 1 of 2 (6 of 11 overall)`.
161
+
162
+ **Cause.** One visit in the named stage takes most of the window: usually a slow forge or provider call for one build.
163
+
164
+ **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.
165
+
147
166
  ## Remote project access
148
167
 
149
168
  **Symptom.** Remote requests refuse a project despite a configured URL.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defrex/autobuild",
3
- "version": "1.14.0",
3
+ "version": "1.15.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.14.0",
166
- "@defrex/autobuild-vercel-sandbox": "1.14.0",
165
+ "@defrex/autobuild-postgres-store": "1.15.0",
166
+ "@defrex/autobuild-vercel-sandbox": "1.15.0",
167
167
  "@resvg/resvg-js": "2.6.2",
168
168
  "@types/bun": "^1.3.14",
169
169
  "@types/node": "^24.0.0",
@@ -234,6 +234,11 @@ import {
234
234
  type LaunchRunnerResult,
235
235
  type TickReport,
236
236
  } from '../processes/dispatcher'
237
+ import {
238
+ formatDeadlineStop,
239
+ formatPassStages,
240
+ type PassStageRecord,
241
+ } from '../processes/pass-stages'
237
242
  import { RepoViewStore } from '../processes/repo-view'
238
243
  import {
239
244
  BuildControlError,
@@ -1600,6 +1605,7 @@ class DispatchLoop {
1600
1605
 
1601
1606
  private dispatcherTick(resumeCurrent: boolean): Promise<Awaited<ReturnType<Dispatcher['tick']>>> {
1602
1607
  return this.serialize(async () => {
1608
+ this.stagesPrinted = false
1603
1609
  // The yield observer may have accepted while this tick was queued.
1604
1610
  if (this.retirement !== undefined) return emptyTickReport()
1605
1611
  // Refresh before every watch decision. The owner publishes atomically;
@@ -1646,7 +1652,10 @@ class DispatchLoop {
1646
1652
  const readyObservation =
1647
1653
  settings.intake || (!this.dashboard && this.opts.kernelRunId === undefined)
1648
1654
  ? undefined
1649
- : await this.dispatcher.observeReady({ viewRefreshed: true })
1655
+ : await this.dispatcher.observeReady({
1656
+ viewRefreshed: true,
1657
+ ...(this.opts.deadlineAt !== undefined ? { deadlineAt: this.opts.deadlineAt } : {}),
1658
+ })
1650
1659
  await this.wiring.renewAccounts?.({ repo: this.repoIdentity, run: this.runId })
1651
1660
  const report = await this.dispatcher.tick({
1652
1661
  resumeCurrent,
@@ -4333,7 +4342,31 @@ class DispatchLoop {
4333
4342
  }
4334
4343
  }
4335
4344
 
4345
+ /** Whether this pass's `stages:` line was printed, by its report or by
4346
+ * bounded teardown; a pass prints it once. */
4347
+ private stagesPrinted = false
4348
+
4336
4349
  private printReport(report: Awaited<ReturnType<Dispatcher['tick']>>, printIdle = true): boolean {
4350
+ const printed = this.printReportLines(report, printIdle)
4351
+ // A bounded pass's per-stage time and items (#1409): display only, never
4352
+ // a counter.
4353
+ if (report.stages !== undefined && !this.stagesPrinted) this.printStages(report.stages)
4354
+ return printed
4355
+ }
4356
+
4357
+ /** A bounded pass's deadline line, when the work deadline stopped a stage,
4358
+ * then its `stages:` line; once per pass. */
4359
+ private printStages(stages: readonly PassStageRecord[]): void {
4360
+ this.stagesPrinted = true
4361
+ const stop = formatDeadlineStop(stages)
4362
+ if (stop !== undefined) this.say(`tick: ${stop}`)
4363
+ this.say(`stages: ${formatPassStages(stages)}`)
4364
+ }
4365
+
4366
+ private printReportLines(
4367
+ report: Awaited<ReturnType<Dispatcher['tick']>>,
4368
+ printIdle: boolean,
4369
+ ): boolean {
4337
4370
  // `queued` is a standing depth, not a tick action — the header owns it;
4338
4371
  // repeating it in the notice would make every saturated tick look busy.
4339
4372
  const {
@@ -4345,6 +4378,7 @@ class DispatchLoop {
4345
4378
  agentContextDiagnostics,
4346
4379
  deferredDiagnostics,
4347
4380
  queued: _queued,
4381
+ stages: _stages,
4348
4382
  ...counts
4349
4383
  } = report
4350
4384
  for (const line of janitorDiagnostics) this.routineDiagnostic(line)
@@ -5526,7 +5560,9 @@ class DispatchLoop {
5526
5560
  for (const report of settledReports) {
5527
5561
  settledPrinted = this.printReport(report, false) || settledPrinted
5528
5562
  }
5529
- if (!initialPrinted && !settledPrinted) {
5563
+ // A pass the work deadline cut short is reported by bounded teardown,
5564
+ // never as idle.
5565
+ if (!initialPrinted && !settledPrinted && !this.budgetStopped()) {
5530
5566
  this.printReport(emptyTickReport())
5531
5567
  }
5532
5568
  // One delivery pass per configured hook; the next invocation retries.
@@ -5570,6 +5606,9 @@ class DispatchLoop {
5570
5606
  // Whether or not the deadline fired, no launch may start during
5571
5607
  // teardown: provisioning abandonment runs beside execution teardown.
5572
5608
  this.onWorkDeadline()
5609
+ // The cut pass's lines print now; its advisory writes race beside the
5610
+ // other cleanup, so a stalled write never postpones unrelated teardown.
5611
+ const summary = this.reportCutPass(budget)
5573
5612
  const provisioning = untilAborted(
5574
5613
  withInvocationSignal(budget.cleanup, () => this.dispatcher.stopProvisioning()),
5575
5614
  budget.cleanup,
@@ -5585,7 +5624,7 @@ class DispatchLoop {
5585
5624
  }),
5586
5625
  budget.cleanup,
5587
5626
  )
5588
- const cleanup = await Promise.allSettled([provisioning, optional])
5627
+ const cleanup = await Promise.allSettled([provisioning, optional, summary])
5589
5628
  await untilAborted(
5590
5629
  withInvocationSignal(budget.final, () => this.releaseRepoLease()),
5591
5630
  budget.final,
@@ -5594,6 +5633,48 @@ class DispatchLoop {
5594
5633
  if (failed !== undefined) throw failed.reason
5595
5634
  }
5596
5635
 
5636
+ /** A pass the work deadline abandoned before its report printed (#1409):
5637
+ * name the stage and part in flight and print the stages so far, at once;
5638
+ * then, as a teardown racer bounded by the cleanup deadline, record where
5639
+ * the pass's loops reached and close the still-open tick boundary with
5640
+ * that partial summary, so `ab repository status` shows it. Never rejects:
5641
+ * a concurrent abandoned publication may already have closed the boundary. */
5642
+ private reportCutPass(budget: InvocationBudget): Promise<void> {
5643
+ const writes: Promise<void>[] = []
5644
+ const write = (what: string, run: () => Promise<unknown>) =>
5645
+ writes.push(
5646
+ untilAborted(run(), budget.cleanup).then(
5647
+ () => undefined,
5648
+ (error: unknown) => this.warn(`${what} not recorded: ${formatDispatcherError(error)}`),
5649
+ ),
5650
+ )
5651
+ // The next invocation continues after the visit the deadline cut short.
5652
+ // A no-op when the pass already recorded its positions; the write itself
5653
+ // goes through teardownWrite.
5654
+ 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)
5658
+ 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
+ )
5673
+ }
5674
+ }
5675
+ return Promise.all(writes).then(() => undefined)
5676
+ }
5677
+
5597
5678
  async run(): Promise<void> {
5598
5679
  // Before the `--once` branch, so both modes report it exactly once.
5599
5680
  this.reportRoleDiagnostics()
@@ -1,3 +1,4 @@
1
+ import { deadlineStopDetail, formatPassStages } from '../processes/pass-stages'
1
2
  import { startTierOf, type StartTier } from '../ports/tickets/priority'
2
3
  import { repositoryReadFactsReducer } from '../kernel/read-facts'
3
4
  import {
@@ -525,6 +526,19 @@ function renderUpgradeStatus({ handoff, current, previous }: RepositoryUpgradeSt
525
526
  ]
526
527
  }
527
528
 
529
+ /** The latest bounded pass's per-stage time and items (#1409), and where the
530
+ * work deadline stopped it. */
531
+ function passStagesStatus(
532
+ tick: NonNullable<RepositoryStatus['dispatcher']['latestRun']>['lastTick'] | undefined,
533
+ ): string[] {
534
+ const stages = tick?.outcome === 'completed' ? tick.counters.stages : undefined
535
+ if (stages === undefined || stages.length === 0) return []
536
+ const stop = deadlineStopDetail(stages)
537
+ return [
538
+ `last pass stages: ${formatPassStages(stages)}${stop === undefined ? '' : `; stopped by the work deadline during ${stop}`}`,
539
+ ]
540
+ }
541
+
528
542
  export function renderRepositoryStatus(status: RepositoryStatus): string[] {
529
543
  const tick = (
530
544
  status.dispatcher.holder ??
@@ -611,6 +625,7 @@ export function renderRepositoryStatus(status: RepositoryStatus): string[] {
611
625
  ]
612
626
  : [],
613
627
  ),
628
+ ...passStagesStatus(tick),
614
629
  ...(status.dispatcher.latestStoppedRun
615
630
  ? [
616
631
  `last dispatcher stop: ${status.dispatcher.latestStoppedRun.stoppedAt}; ${status.dispatcher.latestStoppedRun.stop?.outcome}; signal ${status.dispatcher.latestStoppedRun.stop?.signal ?? 'none'}`,
@@ -329,6 +329,7 @@ export const repositoryEventPolicy = {
329
329
  'dispatcher.tick-completed': 'advisory',
330
330
  'dispatcher.ticket-scan-completed': 'advisory',
331
331
  'dispatcher.work-deferred': 'advisory',
332
+ 'dispatcher.pass-cursors': 'advisory',
332
333
  'dispatcher.ticket-source-dependency-limited': 'decisive',
333
334
  'dispatcher.forge-degraded': 'decisive',
334
335
  'dispatcher.forge-recovered': 'decisive',
@@ -53,8 +53,74 @@ const dispatcherSetting = z.strictObject({ enabled: z.boolean(), run: dispatchRu
53
53
  const boundedDiagnostics = z.array(z.string().min(1)).max(1_000)
54
54
  export { forgeRequestCountsSchema } from '../ports/forge-telemetry'
55
55
  import { forgeRequestCountsSchema } from '../ports/forge-telemetry'
56
+ /** The stages of one bounded dispatcher pass, in run order (#1409). */
57
+ export const PASS_STAGE_NAMES = [
58
+ 'deferred',
59
+ 'settlement',
60
+ 'preparations',
61
+ 'janitor',
62
+ 'recovery',
63
+ 'sweep',
64
+ 'admission',
65
+ 'intake',
66
+ ] as const
67
+ /** The per-item loops and single-call helpers a pass stage groups. */
68
+ export const PASS_STAGE_PART_NAMES = [
69
+ 'deferred',
70
+ 'executions',
71
+ 'harvest',
72
+ 'sandboxes',
73
+ 'preparations',
74
+ 'janitor',
75
+ 'handbacks',
76
+ 'dispatches',
77
+ 'resume',
78
+ 'waits',
79
+ 'sweep',
80
+ 'nodes',
81
+ 'starts',
82
+ 'tickets',
83
+ 'parked',
84
+ 'harvest-trigger',
85
+ 'context',
86
+ ] as const
87
+ /** The loops that continue from a saved position on the next bounded pass:
88
+ * handling one of their items does not remove it. */
89
+ export const ROTATED_PASS_PARTS = [
90
+ 'executions',
91
+ 'harvest',
92
+ 'sandboxes',
93
+ 'janitor',
94
+ 'handbacks',
95
+ 'dispatches',
96
+ 'resume',
97
+ 'sweep',
98
+ ] as const
99
+ const passCount = z.number().int().nonnegative()
100
+ const passStopSchema = z.enum(['share', 'deadline'])
101
+ const passStageRecordSchema = z.strictObject({
102
+ stage: z.enum(PASS_STAGE_NAMES),
103
+ ms: passCount,
104
+ items: passCount,
105
+ total: passCount.optional(),
106
+ stopped: passStopSchema.optional(),
107
+ parts: z
108
+ .array(
109
+ z.strictObject({
110
+ part: z.enum(PASS_STAGE_PART_NAMES),
111
+ items: passCount,
112
+ total: passCount.optional(),
113
+ stopped: passStopSchema.optional(),
114
+ }),
115
+ )
116
+ .max(8)
117
+ .optional(),
118
+ })
56
119
  const tickCountersSchema = z.strictObject({
57
120
  forgeRequests: forgeRequestCountsSchema.optional(),
121
+ /** Per-stage time and items of a bounded pass (#1409); display only.
122
+ * Optional so historical tick facts replay. */
123
+ stages: z.array(passStageRecordSchema).max(16).optional(),
58
124
  merged: z.number().int().nonnegative(),
59
125
  closed: z.number().int().nonnegative(),
60
126
  conflicted: z.number().int().nonnegative(),
@@ -518,6 +584,22 @@ export const dispatcherStatusEventPayloadSchemas = {
518
584
  )
519
585
  .max(64),
520
586
  }),
587
+ /** A latest-only scheduling hint: where each rotated loop of a bounded
588
+ * pass continues on the next pass, the key of the last item it started.
589
+ * Never authority; every visit re-derives its decision from fresh state.
590
+ * An empty `cursors` object clears every position. */
591
+ 'dispatcher.pass-cursors': z.strictObject({
592
+ cursors: z.strictObject({
593
+ executions: z.string().min(1).optional(),
594
+ harvest: z.string().min(1).optional(),
595
+ sandboxes: z.string().min(1).optional(),
596
+ janitor: z.string().min(1).optional(),
597
+ handbacks: z.string().min(1).optional(),
598
+ dispatches: z.string().min(1).optional(),
599
+ resume: z.string().min(1).optional(),
600
+ sweep: z.string().min(1).optional(),
601
+ }),
602
+ }),
521
603
  /** Completed ticket-source measurement, independent of dispatcher runs. */
522
604
  'dispatcher.ticket-scan-completed': z.strictObject({
523
605
  startedAt: z.iso.datetime(),
@@ -1266,6 +1348,7 @@ const allowedActorKinds: Record<RepositoryEventType, readonly ActorKind[]> = {
1266
1348
  'dispatcher.tick-completed': ['dispatcher'],
1267
1349
  'dispatcher.ticket-scan-completed': ['dispatcher'],
1268
1350
  'dispatcher.work-deferred': ['dispatcher'],
1351
+ 'dispatcher.pass-cursors': ['dispatcher'],
1269
1352
  'dispatcher.ticket-source-dependency-limited': ['dispatcher'],
1270
1353
  'dispatcher.forge-degraded': ['dispatcher', 'kernel'],
1271
1354
  'dispatcher.forge-recovered': ['dispatcher', 'kernel', 'human'],
@@ -0,0 +1,107 @@
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/7hbgb52kw8",
15
+ "repositoryReadFacts/shape/e2u2pgiup3",
16
+ "repositoryReadFacts/shape/ez3eddcdoo",
17
+ "repositoryReadFacts/shape/hgw4spz5c0",
18
+ "repositoryReadFacts/shape/mggr8x6l5z",
19
+ "repositoryReadFacts/shape/o7791nz2gt",
20
+ "repositoryReadFacts/shape/se5kk44boc",
21
+ "repositoryReadFacts/shape/xyn7875cxw",
22
+ "sandboxStates/fold/hjdgop7xoh",
23
+ "sandboxStates/shape/gbrf8k4qxq",
24
+ "ticketStarts/fold/8fp156vze2",
25
+ "ticketStarts/fold/eglrhnb0ta",
26
+ "ticketStarts/shape/dzxrbuuq7e",
27
+ "ticketStarts/shape/eecofz22vy"
28
+ ],
29
+ "entries": {
30
+ "017d8dd5bb6dd80b": "9b19c8eb254d503fbe74d8de7039566f",
31
+ "10a4657408d4e121": "218f9c92364c4b9176b70c9bee8a29f8",
32
+ "1411d1cdbdd9911e": "a5b60fa55d3c1d3999e4ee947878bd23",
33
+ "1444fe1fa7fc802c": "81c89822174d63012aa06ad744fae9e6",
34
+ "178e12f1759b7552": "61197c43eb41d8451ce5182402f23373",
35
+ "1921f86f752428c9": "abf8d370c9d94b6a50ab70d52d33454b",
36
+ "1972c1d66008ef6b": "56c634f6d1a0076256c385b2a9feab7c",
37
+ "19e8e43e7f3f1a06": "b18b2ccd2d11b39684f2fc991526b0d6",
38
+ "21ce2c0bf58318e1": "8eedb8f516b89cb65230c9cedb1bd903",
39
+ "293dcb3a94fb3470": "203e641af713b42a0e5369f9486f2301",
40
+ "2ab7436356267118": "fc4031327a07006ccdc946bf07aba04f",
41
+ "2d084641735caaff": "1061299214f493d5d51f9c11afae68ab",
42
+ "3237bcecf68e5db9": "79f6d09249036fd77dc5d3400e18124a",
43
+ "33d0cc593610e56f": "bd88ed40c1ada79d8657af1b339a6a9f",
44
+ "35cf9ccc4478b2d2": "5a2279bc99403d0f7d40cede4c8bb573",
45
+ "3649e7bd1203f154": "9d3742c0e29c7a3e999c9c9a8c6eac27",
46
+ "38c75099d9191471": "203e641af713b42a0e5369f9486f2301",
47
+ "431c9bb2ee8838e0": "0715d441ad523323105867bf09108797",
48
+ "49064fc079964a5c": "844ca8b44174ab640ce17a713b580d7d",
49
+ "4932c70a2af97faf": "0c732c6ead43fcb8d5f34159ac5e0e0b",
50
+ "4f00c0f2c8afd159": "9688f560966f37d57b4177bf5aa4b7f0",
51
+ "516a5a7aadf97587": "e63f56f546ed51d4e04df1e86c9fc476",
52
+ "536085773daf6b58": "57901f1d28ee614272cc8915a80e38ff",
53
+ "59ffaa6974094c72": "d1757ea5344f9164aca22e3ca6ca165a",
54
+ "5f0ca42af862c4ee": "840d8a2c1947ef0941e1ab8bf3afd42e",
55
+ "6118031132db9bfc": "8c44d3ef5b8a0241b5c712f994d56907",
56
+ "643d70429ce03dad": "c2b7bfc98da1427b6a3858d814d3f57b",
57
+ "677ea92572c29082": "4067b95ee98f33bc298d71c7489fabba",
58
+ "6ae5bf60504d6467": "58975765e668c4f361659977261d56ed",
59
+ "6bd6275061aaffa5": "c84c2528779e3ecc21e549e0ef2adedd",
60
+ "6efdc8defc75fccb": "d5b512d4f4c16b9d4bcadbee8f8206ad",
61
+ "7833e42d16301424": "b32c86839cd9044a4d7757d51b62db14",
62
+ "7d4edad0614adaf1": "54a48a0b441082d54a07d786c217153e",
63
+ "837365898d04f45a": "54a48a0b441082d54a07d786c217153e",
64
+ "85f9f0c921b8b5bb": "0926918433e11ebd637e34dae2a2d615",
65
+ "8879f57a24733897": "58975765e668c4f361659977261d56ed",
66
+ "88cb9e71bdec972d": "3f7ed5a476e6457efedb7cdf6412fd23",
67
+ "89625654b02e9ac1": "bac4fc52c015d8cb7b9f833dda540b85",
68
+ "8cc15eb1807c0157": "10c221f0b9db3782b1dca2ed6eb1f5c9",
69
+ "8ced97c44bc0af3a": "d998291081ba51e1bef3205aae7595ef",
70
+ "8d4144004720b9f8": "ef6389a96f072b54e91a0e0f19c827b8",
71
+ "8db633ead1807f8b": "c4fe43ef3276b5877db1b08a38d607cb",
72
+ "8e42cdbd0994ab0c": "e12aa5b2f6373eceb51f303a929e8d5a",
73
+ "9539b995af5c54a9": "1061299214f493d5d51f9c11afae68ab",
74
+ "9ee3919fbd4f9458": "a553618f38080bfcb814cb4a5416cfb1",
75
+ "a0b32c12e4e6edb6": "d323237478cd65b159eda1faab172bcf",
76
+ "a55218252707bdd3": "54a48a0b441082d54a07d786c217153e",
77
+ "a98af134be2da8a9": "9a0830cc47de7a66b3c2f1a85a7eb852",
78
+ "af953392d81911da": "58975765e668c4f361659977261d56ed",
79
+ "b0d877c44810ecb0": "64a155224f6c8526212f92f64e7ef575",
80
+ "be211f0e31a65006": "64a155224f6c8526212f92f64e7ef575",
81
+ "c68b7ee2e2610f30": "05034ebd16ae9bf93b398663b30aea92",
82
+ "c7f7e0378aeea237": "1061299214f493d5d51f9c11afae68ab",
83
+ "c98cb1659eb142b6": "64a155224f6c8526212f92f64e7ef575",
84
+ "ca830adf06ed55a1": "54a48a0b441082d54a07d786c217153e",
85
+ "cb3a219f33e437ca": "feab7b027da5be2ecf041dd93fb55f1d",
86
+ "cf1e0c0d82567e0c": "cac9aba9f25adeb55568e902396839a4",
87
+ "d1432a819d8e48c5": "203e641af713b42a0e5369f9486f2301",
88
+ "d185ed6aa9192aff": "235467b1c87a46b383a7fa8550d8a2f8",
89
+ "d5d5ccca80a893d8": "0fdfd82c7426fd151bbb7544cd415187",
90
+ "d873fad29d6c7e55": "3f7ed5a476e6457efedb7cdf6412fd23",
91
+ "e2f18fa32fe1f6d0": "e5878dff98f5f30c5f82c1656fa82737",
92
+ "e37393fed29e84c5": "b32c86839cd9044a4d7757d51b62db14",
93
+ "e6a8585e2a054ff6": "ed2947f48b407a9a4f3bbfd151d8bc63",
94
+ "eb7ddd5319d09e27": "e7fa56dec140a7688e4a7d470b419aba",
95
+ "eca4959b2b87ae15": "5d66240a5fdec0ca59deafae16615bc5",
96
+ "ee10d7959ec4843c": "7a0b8bf4fb7a11ea26c5431bc205f96d",
97
+ "ef1b68347966ab26": "3f7ed5a476e6457efedb7cdf6412fd23",
98
+ "f3e55425cc41f230": "54a48a0b441082d54a07d786c217153e",
99
+ "f5b9ace9b59351e7": "3f7ed5a476e6457efedb7cdf6412fd23",
100
+ "f8155387eb5f375c": "5c119a1b47ade210ed5517f68b3babfc",
101
+ "fa8f1475a55be935": "8ecd3e416726e4af9b75f8eaa983f171",
102
+ "fb21116a15d0b1f1": "22c5ba7ef2445e8d6a9e7bbeb1b06d52",
103
+ "fe95444fbeabe592": "4b033ccb2ce1d4edc32bb44601049293"
104
+ }
105
+ }
106
+ ]
107
+ }
@@ -96,4 +96,6 @@ export const REDUCER_REVISIONS: Readonly<Record<string, string>> = {
96
96
  'doneEscalationEntry/fold/9mnmr74oat': '#1387 the first abort closes the escalations open then',
97
97
  'repositoryReadFacts/shape/e2u2pgiup3': '#1406 deferred work hint and recoveryDeferred counter',
98
98
  'repositoryReadFacts/fold/5porrk9y1h': '#1406 latest dispatcher.work-deferred is carried forward',
99
+ 'repositoryReadFacts/shape/ez3eddcdoo': '#1409 pass cursors and stage timings',
100
+ 'repositoryReadFacts/fold/0xl1c98cpy': '#1409 latest dispatcher.pass-cursors is carried forward',
99
101
  }
@@ -94,6 +94,12 @@ export interface RepositoryReadAcc {
94
94
  seq: number
95
95
  builds: Extract<RepositoryEvent, { type: 'dispatcher.work-deferred' }>['payload']['builds']
96
96
  }
97
+ /** The latest `dispatcher.pass-cursors` hint: where each rotated loop of
98
+ * the next bounded pass continues. */
99
+ passCursors?: {
100
+ seq: number
101
+ cursors: Extract<RepositoryEvent, { type: 'dispatcher.pass-cursors' }>['payload']['cursors']
102
+ }
97
103
  recentRuns: [string, DispatcherRunFacts][]
98
104
  latestRun?: string
99
105
  latestStoppedRun?: string
@@ -254,6 +260,8 @@ export const repositoryReadFactsReducer = defineReducer({
254
260
  }
255
261
  if (event.type === 'dispatcher.work-deferred')
256
262
  acc.deferredWork = { seq: event.seq, builds: event.payload.builds }
263
+ if (event.type === 'dispatcher.pass-cursors')
264
+ acc.passCursors = { seq: event.seq, cursors: event.payload.cursors }
257
265
  if (event.type === 'dispatcher.run-started') acc.latestRun = event.payload.run
258
266
  if (event.type === 'dispatcher.run-stopped') acc.latestStoppedRun = event.payload.run
259
267
  if (
@@ -322,6 +330,7 @@ export const repositoryReadFactsReducer = defineReducer({
322
330
  scan: acc.scan,
323
331
  scanSeq: acc.scanSeq,
324
332
  deferredWork: acc.deferredWork === undefined ? undefined : structuredClone(acc.deferredWork),
333
+ passCursors: acc.passCursors === undefined ? undefined : structuredClone(acc.passCursors),
325
334
  recentRuns: structuredClone(acc.recentRuns),
326
335
  latestRun: acc.latestRun,
327
336
  latestStoppedRun: acc.latestStoppedRun,