@defrex/autobuild 1.7.0 → 1.8.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 (115) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +316 -47
  3. package/docs/answering-blocked-builds.md +44 -3
  4. package/docs/architecture.md +62 -7
  5. package/docs/cli.md +1 -0
  6. package/docs/configuration-overview.md +1 -1
  7. package/docs/configuration.md +49 -9
  8. package/docs/dispatcher.md +1 -1
  9. package/docs/integration-overview.md +2 -2
  10. package/docs/integration-tree.md +7 -4
  11. package/docs/merge-policy.md +78 -6
  12. package/docs/migration-1.0.md +4 -2
  13. package/docs/operating.md +3 -2
  14. package/docs/operator-api.md +26 -5
  15. package/docs/operator-surfaces.md +10 -0
  16. package/docs/plugin-authoring.md +1 -1
  17. package/docs/remote-store-protocol.md +9 -1
  18. package/docs/restacking.md +23 -4
  19. package/docs/ticket-dependencies.md +9 -4
  20. package/docs/tickets.md +1 -1
  21. package/docs/troubleshooting.md +1 -1
  22. package/package.json +3 -3
  23. package/packages/core/src/cli/attention.ts +1 -0
  24. package/packages/core/src/cli/build-control.ts +65 -7
  25. package/packages/core/src/cli/context.ts +55 -14
  26. package/packages/core/src/cli/dashboard/actions.ts +13 -4
  27. package/packages/core/src/cli/dashboard/landing-display.ts +32 -8
  28. package/packages/core/src/cli/dashboard/model.ts +61 -8
  29. package/packages/core/src/cli/dashboard/render.ts +28 -3
  30. package/packages/core/src/cli/dashboard/tree.ts +9 -1
  31. package/packages/core/src/cli/help.ts +69 -7
  32. package/packages/core/src/cli/landings.ts +1 -1
  33. package/packages/core/src/cli/main.ts +60 -9
  34. package/packages/core/src/cli/publication-settlement.ts +10 -0
  35. package/packages/core/src/cli/status.ts +178 -12
  36. package/packages/core/src/cli/terminals.ts +197 -4
  37. package/packages/core/src/cli/wait.ts +1 -0
  38. package/packages/core/src/cli/watch.ts +71 -0
  39. package/packages/core/src/config/landing.ts +12 -0
  40. package/packages/core/src/config/path-selectors.ts +68 -0
  41. package/packages/core/src/config/schema.ts +40 -58
  42. package/packages/core/src/events/catalog.ts +17 -3
  43. package/packages/core/src/events/compatibility.ts +2 -1
  44. package/packages/core/src/events/head-paths-limits.ts +25 -0
  45. package/packages/core/src/events/payloads.ts +315 -20
  46. package/packages/core/src/events/policy.ts +21 -0
  47. package/packages/core/src/events/repository.ts +30 -1
  48. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +247 -6
  49. package/packages/core/src/kernel/consent-revocation.ts +72 -0
  50. package/packages/core/src/kernel/dispatch-capacity.ts +19 -8
  51. package/packages/core/src/kernel/engine.ts +48 -8
  52. package/packages/core/src/kernel/head-paths-state.ts +63 -0
  53. package/packages/core/src/kernel/head-paths.ts +401 -0
  54. package/packages/core/src/kernel/landing-policy-identity.ts +20 -0
  55. package/packages/core/src/kernel/landing-policy.ts +55 -2
  56. package/packages/core/src/kernel/landing-readiness.ts +104 -9
  57. package/packages/core/src/kernel/landing-state.ts +44 -4
  58. package/packages/core/src/kernel/leaf-restack-state.ts +50 -2
  59. package/packages/core/src/kernel/log-index.ts +27 -1
  60. package/packages/core/src/kernel/node-polling.ts +13 -3
  61. package/packages/core/src/kernel/node-restack-state.ts +8 -1
  62. package/packages/core/src/kernel/node-restack-transaction.ts +45 -0
  63. package/packages/core/src/kernel/read-deferrals.ts +3 -1
  64. package/packages/core/src/kernel/read-facts.ts +28 -1
  65. package/packages/core/src/kernel/reducer-registry.ts +22 -1
  66. package/packages/core/src/kernel/reducer.ts +316 -17
  67. package/packages/core/src/kernel/target-observation.ts +2 -5
  68. package/packages/core/src/kernel/terminal-guard.ts +52 -3
  69. package/packages/core/src/kernel/ticket-handbacks.ts +40 -0
  70. package/packages/core/src/kernel/ticket-preparation.ts +12 -1
  71. package/packages/core/src/kernel/ticket-wait.ts +345 -0
  72. package/packages/core/src/kernel/verify-applicability.ts +9 -19
  73. package/packages/core/src/ontology.ts +1 -0
  74. package/packages/core/src/operator/annotations.ts +6 -0
  75. package/packages/core/src/operator/index.ts +3 -0
  76. package/packages/core/src/operator/protocol.ts +15 -2
  77. package/packages/core/src/operator/registry.ts +97 -5
  78. package/packages/core/src/operator/repository-events.ts +67 -0
  79. package/packages/core/src/ports/tickets/fake.ts +5 -0
  80. package/packages/core/src/ports/types.ts +3 -2
  81. package/packages/core/src/processes/build-execution-state.ts +30 -1
  82. package/packages/core/src/processes/build-runner.ts +150 -18
  83. package/packages/core/src/processes/dispatcher.ts +739 -97
  84. package/packages/core/src/processes/execution-no-progress.ts +22 -2
  85. package/packages/core/src/processes/phase-failure-budget.ts +1 -0
  86. package/packages/core/src/processes/publication-state.ts +6 -1
  87. package/packages/core/src/store/digest.ts +41 -2
  88. package/packages/core/src/store/reduced-reads.ts +4 -1
  89. package/packages/core/src/store/reducer-value-shapes.json +10108 -8432
  90. package/packages/core/src/store/remote/client.ts +28 -2
  91. package/packages/core/src/store/remote/protocol.ts +11 -1
  92. package/packages/core/src/store/remote/released-clients.json +11 -0
  93. package/packages/core/src/store/remote/released-reducer-values/1.8.0.json +29043 -0
  94. package/packages/core/src/store/remote/released-reducer-values/index.ts +2 -0
  95. package/packages/core/src/store/repo-state-events.ts +2 -0
  96. package/packages/core/src/store/types.ts +16 -0
  97. package/packages/core/src/testing/reduced-read-budget.ts +347 -0
  98. package/skills/code-review/SKILL.md +8 -0
  99. package/skills/finalize/SKILL.md +4 -0
  100. package/skills/guide/SKILL.md +125 -26
  101. package/skills/guide/references/integration-tree.md +7 -4
  102. package/skills/guide/references/merge-policy.md +78 -6
  103. package/skills/guide/references/migration-1.0.md +4 -2
  104. package/skills/guide/references/operator-api.md +26 -5
  105. package/skills/guide/references/plugin-authoring.md +1 -1
  106. package/skills/guide/references/remote-store-protocol.md +9 -1
  107. package/skills/guide/references/restacking.md +23 -4
  108. package/skills/guide/references/ticket-dependencies.md +9 -4
  109. package/skills/implement/SKILL.md +15 -1
  110. package/skills/operate/SKILL.md +104 -13
  111. package/skills/plan/SKILL.md +17 -2
  112. package/skills/plan-review/SKILL.md +8 -0
  113. package/skills/reconcile/SKILL.md +21 -5
  114. package/skills/tickets/SKILL.md +5 -4
  115. package/templates/hosted-service/package.json +2 -2
@@ -3,7 +3,12 @@
3
3
  A leaf contributes one net change, independent of its WIP commit count. Before
4
4
  verification the kernel collapses its contribution relative to the effective
5
5
  diff base and replays it onto the sampled destination. Implementation and review
6
- do not rewrite history. Verification failures return to implementation; later
6
+ do not rewrite history; the one exception is a build resuming from a ticket
7
+ wait, which the kernel restacks between phases so the resumed phase sees the
8
+ merged blockers. A build with nothing published fast-forwards to the
9
+ destination only when its local branch has no commits the destination lacks and
10
+ its workspace has no uncommitted tracked changes; otherwise the restack fails
11
+ and that local work is never discarded. Verification failures return to implementation; later
7
12
  commits append until the next approved cycle. Later reviews use the effective
8
13
  base from the preceding successful restack; the original cut remains provenance.
9
14
 
@@ -49,7 +54,18 @@ polls read no receipts or event rows.
49
54
 
50
55
  Accepted destination observations are durable `target.moved` facts, including while an
51
56
  agent runs. Verify-entry restack freezes a current base before verification;
52
- path selection excludes upstream-only paths. After finalize and post-steps,
57
+ path selection excludes upstream-only paths. A build leaving a ticket wait
58
+ restacks with trigger `wait-resume` before its declaring phase resumes, when the
59
+ target moved from the base its work sits on; an unchanged target resumes
60
+ without a restack. Published work replays through the guarded restack, and a
61
+ conflict runs reconcile before the declaring phase resumes. With nothing
62
+ published, the local branch fast-forwards to the target (`restack.advanced`)
63
+ only when it has no commits the target lacks and the workspace has no
64
+ uncommitted tracked changes; unpublished local commits or uncommitted tracked
65
+ changes prevent the advance and are never discarded. A wait declared by a
66
+ reconcile session whose replay recorded no publish intent supersedes that
67
+ replay when the target moved, discarding its undeposited resolution, and
68
+ replays the published head onto the current target instead. After finalize and post-steps,
53
69
  waiting leaves restack when the target moves. Node-target finalize contributions
54
70
  are canonicalized before guarded merge even when the target SHA is unchanged.
55
71
  Clean replay starts no agent. A clean waiting leaf rewrite preserves completed
@@ -68,7 +84,7 @@ dependency presence requires an ancestor change; on `ab restack <node>`; or on
68
84
  accepted re-parenting. There is no eager mode or cadence option. Nested nodes
69
85
  need their own demand. Existing frozen transactions, including ones reserved
70
86
  before upgrade, finish first; later demand coalesces onto the latest parent.
71
- Leaves keep verify-entry and awaiting-merge restacks for every target.
87
+ Leaves keep verify-entry, wait-resume and awaiting-merge restacks for every target.
72
88
 
73
89
  For observation cadence, durable wakes and last-check evidence, see
74
90
  [node polling and status](integration-tree.md#polling-and-status).
@@ -240,7 +256,10 @@ Before claiming, the dispatcher journals a repository-scoped preparation intent;
240
256
  a won claim, the selected creation slug and, when the build store attests keyed
241
257
  creation, the attempt's creation key are durable boundaries. Caught
242
258
  asset-copy, spec-authoring, naming, and build-creation failures return the ticket
243
- to configured Ready; a nonconforming spec goes to configured Triage. Recovery
259
+ to configured Ready; a nonconforming spec goes to configured Triage. Once a
260
+ confirmed claim's ticket is back, one repository `ticket.handed-back` reports it
261
+ (cause `preparation-failed` or `spec-bounce`, with the missing spec parts) before
262
+ the attempt resolves; an attempt reports at most once. Recovery
244
263
  point-reads the selected slug and, for a keyed attempt, the canonical slug derived
245
264
  from the repository, selected slug and key: one matching record and atomic
246
265
  `build.created` retain ownership even if creation threw after committing or its
@@ -58,10 +58,15 @@ the ticket ready.
58
58
  ## Already-claimed work
59
59
 
60
60
  Adding blockers does not stop a build already claimed from an earlier listing.
61
- When the human authorizes restarting premature work: request `ab abort <slug>`,
62
- wait for dispatcher cleanup to finish and return the ticket to triage, verify
63
- or repair the blocker set, and only then move the ticket back to ready. Moving
64
- the ticket before cleanup finishes can be overwritten by cleanup. Ready with
61
+ When the human authorizes restarting premature work and the blocker set is
62
+ already right, request `ab abort <slug> --to ready`: cleanup moves the ticket
63
+ straight back to ready with its blockers kept, so no second move is needed.
64
+ If the ticket no longer meets the spec standard, cleanup returns it to triage
65
+ instead and the hand-back names the missing parts; groom it before moving it
66
+ to ready.
67
+ If the blockers need changing first, verify or repair them once the
68
+ `ticket.handed-back` repository event for that build arrives; the dispatcher
69
+ writes nothing to the ticket for that hand-back afterwards. Ready with
65
70
  unresolved blockers is the normal waiting state: dispatch rechecks dependencies
66
71
  and claims the ticket only after they resolve and other readiness gates pass.
67
72
 
package/docs/tickets.md CHANGED
@@ -82,7 +82,7 @@ Moving a ticket back to triage, backlog or ready restores ordinary behavior. "Bu
82
82
  The dispatcher claims only tickets in the ready state with the required labels and any source-specific filter. A ready ticket still waits on:
83
83
 
84
84
  - **Blockers.** Unresolved prerequisite tickets keep it queued; they don't create a blocked build. With nodes, prerequisites with builds must be present at the sampled destination; see [integration and blocker presence](integration-overview.md).
85
- - **Destination and capacity.** Its target must accept new work, and a capacity slot must be free and not reserved for an integration node awaiting verification or a finished build waiting to re-verify or reconcile.
85
+ - **Destination and capacity.** Its target must accept new work, and a capacity slot must be free and not reserved for an integration node awaiting verification, a finished build waiting to re-verify or reconcile, or a build resuming after its ticket wait ends; each of those is admitted before new claims.
86
86
 
87
87
  When a slot is free, the dispatcher takes urgent ready tickets first, then normal ones, each in the source's order. Priority changes only that order: a blocked urgent ticket waits like any other while normal work proceeds, and an urgent ticket never stops or pauses a running build. The web dashboard's Queue tab lists tickets in the same order and marks urgent ones `URGENT`; the mark shows priority, not that the ticket will dispatch next.
88
88
 
@@ -57,7 +57,7 @@ bun ab harvest status
57
57
  - **Ready state:** ticket in the exact ready state with every required label.
58
58
  - **Blockers and destination:** blockers done, target node open, required changes in the destination. A target node built by another dispatcher's store never opens here; see [several dispatchers](build-store.md#several-dispatchers-on-one-repository). `ab repository status` lists the queue diagnostics.
59
59
  - **Claims:** claimed tickets aren't reclaimed.
60
- - **Capacity:** paused or blocked unfinished work keeps its slot; builds waiting for a merge decision and idle collecting nodes take none. A finished build that must re-verify or reconcile reserves a slot ahead of new claims. Node verification and reconciliation account specially for descendants' slots.
60
+ - **Capacity:** paused unfinished work, and work blocked on a question, keeps its slot; builds waiting for a merge decision, builds waiting on other tickets, and idle collecting nodes take none. A finished build that must re-verify or reconcile, or a build whose ticket wait ended, reserves a slot ahead of new claims. Node verification and reconciliation account specially for descendants' slots.
61
61
  - **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.
62
62
 
63
63
  ## Authentication failures
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defrex/autobuild",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "Agent-driven software delivery from groomed ticket to merged PR",
5
5
  "repository": {
6
6
  "type": "git",
@@ -157,8 +157,8 @@
157
157
  },
158
158
  "devDependencies": {
159
159
  "@biomejs/biome": "2.5.5",
160
- "@defrex/autobuild-postgres-store": "1.7.0",
161
- "@defrex/autobuild-vercel-sandbox": "1.7.0",
160
+ "@defrex/autobuild-postgres-store": "1.8.0",
161
+ "@defrex/autobuild-vercel-sandbox": "1.8.0",
162
162
  "@resvg/resvg-js": "2.6.2",
163
163
  "@types/bun": "^1.3.14",
164
164
  "@types/node": "^24.0.0",
@@ -63,6 +63,7 @@ export function repositoryNeedsAttention(event: RepositoryEvent): boolean {
63
63
  case 'dispatcher.upgrade-failed':
64
64
  case 'dispatcher.kernel-git-unavailable':
65
65
  case 'forge.credential-limited':
66
+ case 'ticket.handed-back':
66
67
  return true
67
68
  case 'dispatcher.config-reloaded':
68
69
  return event.payload.restartRequired.length > 0
@@ -1,5 +1,9 @@
1
1
  import { integrationFailed } from '../kernel/integration-state'
2
- import { landRefusalReason } from '../kernel/landing-readiness'
2
+ import {
3
+ candidateHeadMatches,
4
+ currentCandidateHead,
5
+ landRefusalReason,
6
+ } from '../kernel/landing-readiness'
3
7
  import { observeIntegration } from '../kernel/integration-completeness'
4
8
  import type { TicketSource } from '../ports/types'
5
9
  import { readBuildFacts } from '../store/reduced-reads'
@@ -12,7 +16,7 @@ import { readBuildFacts } from '../store/reduced-reads'
12
16
  * normal runner and dispatcher consume them.
13
17
  */
14
18
  import type { AbEvent } from '../events/catalog'
15
- import type { PinnedAsset } from '../events/payloads'
19
+ import type { AbortDestination, PinnedAsset } from '../events/payloads'
16
20
  import { humanActor, KERNEL, type Via } from '../events/envelope'
17
21
  import { discardInFlight, type BuildState, type OpenEscalation } from '../kernel/reducer'
18
22
  import type { ArtifactRef, BuildOutcome, BuildStatus, TicketRef } from '../ontology'
@@ -22,6 +26,9 @@ import { samplePinnedAssets } from '../store/ticket-assets'
22
26
  import type { BuildStore } from '../store/types'
23
27
  import { withSessionlessStore, type StoreOpener } from './store-opening'
24
28
 
29
+ /** Matches the hand-back report's reason bound. */
30
+ export const ABORT_REASON_LIMIT = 2000
31
+
25
32
  const ACTIVE_STATUSES: readonly BuildStatus[] = ['running', 'collecting', 'paused', 'blocked']
26
33
 
27
34
  /** Retry carries no phase guidance, but the event schema still requires a
@@ -43,10 +50,16 @@ export type AnswerResolutionRequest =
43
50
 
44
51
  export type BuildControlAction =
45
52
  | { kind: 'hold' }
46
- | { kind: 'land' }
53
+ | { kind: 'land'; head?: string }
47
54
  | { kind: 'pause' }
48
55
  | { kind: 'resume' }
49
- | { kind: 'abort' }
56
+ | {
57
+ kind: 'abort'
58
+ /** Where cleanup hands the ticket back; omitted means triage. */
59
+ to?: AbortDestination
60
+ /** Recorded on the request and quoted in the hand-back comment. */
61
+ reason?: string
62
+ }
50
63
  | { kind: 'discard' }
51
64
  | { kind: 'auto-merge-on' }
52
65
  | { kind: 'auto-merge-off' }
@@ -124,6 +137,16 @@ export type BuildControlErrorCode =
124
137
  | 'incompatible-answer-options'
125
138
  | 'merge-not-ready'
126
139
  | 'node-incomplete'
140
+ | 'head-mismatch'
141
+ | 'invalid-argument'
142
+
143
+ /** Normalize an operator-given consent head (`ab merge --head`, the operator
144
+ * `head` field): trimmed and lowercased. Undefined when blank or containing
145
+ * whitespace, which every caller reports as a usage or validation error. */
146
+ export function parseConsentHead(raw: string): string | undefined {
147
+ const head = raw.trim().toLowerCase()
148
+ return /^\S+$/.test(head) ? head : undefined
149
+ }
127
150
 
128
151
  /** Typed codes let the dashboard turn stale selections/prompts into warnings
129
152
  * while the CLI can surface the same underlying conflict as a command error. */
@@ -161,6 +184,7 @@ async function appendCommand(
161
184
  user: string,
162
185
  command: BuildControlCommand,
163
186
  via?: Via,
187
+ abort: { to?: AbortDestination; reason?: string } = {},
164
188
  ): Promise<BuildControlResult> {
165
189
  const actor = humanActor(user, via)
166
190
  let event: AbEvent
@@ -186,7 +210,10 @@ async function appendCommand(
186
210
  event = await store.append(slug, {
187
211
  actor,
188
212
  type: 'build.abort-requested',
189
- payload: {},
213
+ payload: {
214
+ ...(abort.reason !== undefined ? { reason: abort.reason } : {}),
215
+ ...(abort.to !== undefined ? { to: abort.to } : {}),
216
+ },
190
217
  })
191
218
  break
192
219
  case 'discard':
@@ -295,7 +322,7 @@ function abortPending(slug: string): BuildControlError {
295
322
  return new BuildControlError(
296
323
  'abort-pending',
297
324
  `build "${slug}" is aborting; nothing was recorded. Abort is not revocable — ` +
298
- 'after cleanup returns the ticket to Triage, dispatch it as a fresh build',
325
+ 'after cleanup hands the ticket back, dispatch it as a fresh build',
299
326
  )
300
327
  }
301
328
 
@@ -521,12 +548,33 @@ export async function controlBuild(opts: ControlBuildOpts): Promise<BuildControl
521
548
  }
522
549
 
523
550
  if (opts.action.kind === 'abort') {
551
+ const reason = opts.action.reason?.trim()
552
+ if (opts.action.reason !== undefined && (!reason || reason.length > ABORT_REASON_LIMIT))
553
+ throw new BuildControlError(
554
+ 'invalid-argument',
555
+ `abort reason must be 1–${ABORT_REASON_LIMIT} characters after trimming; nothing was recorded`,
556
+ )
557
+ const to = opts.action.to
524
558
  if (state.status !== 'queued') activeState(opts.slug, state)
525
559
  const existing = events.latestAbort
526
560
  if (existing !== undefined) {
561
+ // An identical repeat is the same request; a different destination or
562
+ // reason would be silently ignored by cleanup, so it is refused.
563
+ const recordedTo = existing.payload.to ?? 'triage'
564
+ const recordedReason = existing.payload.reason?.trim() || undefined
565
+ if (recordedTo !== (to ?? 'triage') || recordedReason !== reason)
566
+ throw new BuildControlError(
567
+ 'abort-pending',
568
+ `build "${opts.slug}" already has an abort request returning its ticket to ` +
569
+ `${recordedTo}${recordedReason ? ` (reason: ${recordedReason})` : ''}; nothing was recorded. ` +
570
+ 'An abort request is not revocable or editable.',
571
+ )
527
572
  return { kind: 'command', slug: opts.slug, command: 'abort', event: existing }
528
573
  }
529
- return appendCommand(opts.store, opts.slug, user, 'abort', opts.via)
574
+ return appendCommand(opts.store, opts.slug, user, 'abort', opts.via, {
575
+ ...(to !== undefined ? { to } : {}),
576
+ ...(reason !== undefined ? { reason } : {}),
577
+ })
530
578
  }
531
579
 
532
580
  activeState(opts.slug, state)
@@ -542,6 +590,16 @@ export async function controlBuild(opts: ControlBuildOpts): Promise<BuildControl
542
590
  const current = facts.state
543
591
  activeState(opts.slug, current)
544
592
  if (opts.action.kind === 'land' && discardInFlight(current)) throw discardPending(opts.slug)
593
+ if (opts.action.kind === 'land' && opts.action.head !== undefined) {
594
+ const given = parseConsentHead(opts.action.head)
595
+ if (given === undefined) throw new Error('Merge consent head must be a nonblank SHA')
596
+ const live = currentCandidateHead(current)
597
+ if (!candidateHeadMatches(given, live))
598
+ throw new BuildControlError(
599
+ 'head-mismatch',
600
+ `Merge consent was not recorded: head ${given} is not the current candidate head of build "${opts.slug}"; the current head is ${live ?? 'not yet recorded'}. Review that head and retry.`,
601
+ )
602
+ }
545
603
  const decision = current.landing?.decision
546
604
  if (opts.action.kind === 'land') {
547
605
  const reason = landRefusalReason(current, facts.log.restack)
@@ -30,6 +30,7 @@ import {
30
30
  type TerminalCommand,
31
31
  } from '../kernel/phases'
32
32
  import type { BuildState } from '../kernel/reducer'
33
+ import { waitBlock, waitGuidance, waitSummary } from '../kernel/ticket-wait'
33
34
  import {
34
35
  isVerifyPhase,
35
36
  verifyReportKind,
@@ -503,6 +504,37 @@ export async function buildContext(deps: ContextDeps): Promise<ContextManifest>
503
504
  }
504
505
  }
505
506
 
507
+ // A ticket wait refused or ended for this phase occurrence (SPEC §11
508
+ // "Ticket waits"): every guidance.json naming its escalation or request id
509
+ // carries a `wait` block saying what the session waited on, including the
510
+ // answer to the dispatcher's unresolvable raise that ended the wait.
511
+ const wait = waitBlock(state, phase, round)
512
+ const waitIds = new Set([
513
+ wait?.id,
514
+ wait && state.wait?.escalation,
515
+ ...(wait?.outcome === 'ended'
516
+ ? state.answeredEscalations
517
+ .filter((escalation) => escalation.wait?.id === wait.id)
518
+ .map((escalation) => escalation.id)
519
+ : []),
520
+ ])
521
+ // seq of the refusal or end the wait block reports, and of the answer
522
+ // behind the guidance.json written so far: only a strictly newer answer
523
+ // may stand in for the wait's own guidance.
524
+ const waitSeq =
525
+ wait?.outcome === 'refused' ? state.waitRequest?.outcome?.seq : state.wait?.ended?.seq
526
+ let guidanceWritten: string | undefined
527
+ let guidanceSeq: number | undefined
528
+ const answeredSeq = (id: string) =>
529
+ [...state.answeredEscalations, ...waitGuidance(state)].find((item) => item.id === id)
530
+ ?.answeredSeq
531
+ const writeGuidance = async (guidance: { escalation: string; answer: string }) => {
532
+ guidanceWritten = guidance.escalation
533
+ guidanceSeq = answeredSeq(guidance.escalation)
534
+ const document = waitIds.has(guidance.escalation) ? { ...guidance, wait } : guidance
535
+ await writeDerived('guidance.json', `${JSON.stringify(document, null, 2)}\n`)
536
+ }
537
+
506
538
  if (inputs.findings === 'current' || inputs.currentFeedback === true) {
507
539
  if (phase === 'implement') {
508
540
  const receiptSeq = state.verifyStage.implementations[String(round)]
@@ -550,7 +582,7 @@ export async function buildContext(deps: ContextDeps): Promise<ContextManifest>
550
582
  )
551
583
  } else if ('guidance' in feedback) {
552
584
  // A human escalation answer fed in as authoritative feedback (§15.6-B).
553
- await writeDerived('guidance.json', `${JSON.stringify(feedback.guidance, null, 2)}\n`)
585
+ await writeGuidance(feedback.guidance)
554
586
  }
555
587
  }
556
588
  }
@@ -581,21 +613,16 @@ export async function buildContext(deps: ContextDeps): Promise<ContextManifest>
581
613
  (escalation) => escalation.resolution === 'guidance' && escalation.phase === phase,
582
614
  )
583
615
  const latest = answered.at(-1) // answeredEscalations is in answer order
584
- if (latest !== undefined) {
585
- await writeDerived(
586
- 'guidance.json',
587
- `${JSON.stringify({ escalation: latest.id, answer: latest.answer }, null, 2)}\n`,
588
- )
589
- }
616
+ if (latest !== undefined) await writeGuidance({ escalation: latest.id, answer: latest.answer })
590
617
  }
591
618
 
592
- // Read-deferral guidance repairs access for this same execution occurrence,
593
- // including reviewers, which have no producer-feedback carrier.
619
+ // Read-deferral and ticket-wait guidance resumes this same review occurrence,
620
+ // which has no producer-feedback carrier.
594
621
  if (manifest.feedback === undefined && (phase === 'plan-review' || phase === 'code-review')) {
595
622
  const latest = state.answeredEscalations
596
623
  .filter(
597
624
  (item) =>
598
- item.deferral === 'own-build-read' &&
625
+ (item.deferral === 'own-build-read' || item.wait !== undefined) &&
599
626
  item.resolution === 'guidance' &&
600
627
  item.phase === phase &&
601
628
  item.round === round,
@@ -603,11 +630,25 @@ export async function buildContext(deps: ContextDeps): Promise<ContextManifest>
603
630
  .at(-1)
604
631
  if (latest) {
605
632
  manifest.feedback = { guidance: { escalation: latest.id, answer: latest.answer } }
606
- await writeDerived(
607
- 'guidance.json',
608
- `${JSON.stringify(manifest.feedback.guidance, null, 2)}\n`,
609
- )
633
+ await writeGuidance(manifest.feedback.guidance)
634
+ }
635
+ }
636
+
637
+ // A refused wait, or a wait ended without guidance text (a bare retry or an
638
+ // automatic end), still tells the session what it waited on. Only guidance
639
+ // answered after the refusal or end keeps precedence; an older answer the
640
+ // blocks above found never hides the wait.
641
+ const waitSuperseded =
642
+ guidanceWritten !== undefined &&
643
+ (guidanceSeq === undefined || waitSeq === undefined || guidanceSeq >= waitSeq)
644
+ if (wait !== undefined && !waitSuperseded) {
645
+ const guidance = {
646
+ escalation: wait.outcome === 'refused' ? wait.id : (state.wait?.escalation ?? wait.id),
647
+ answer: waitSummary(wait),
610
648
  }
649
+ if (manifest.feedback === undefined || 'guidance' in manifest.feedback)
650
+ manifest.feedback = { guidance }
651
+ await writeGuidance(guidance)
611
652
  }
612
653
 
613
654
  if (inputs.commitRange === true && state.kind === 'node' && state.integration?.cycle) {
@@ -14,6 +14,7 @@ export function dashboardBuildControl(status: EffectiveStatus): DashboardBuildCo
14
14
  return { key: 'p', action: 'cancel-pause', label: 'cancel pause' }
15
15
  case 'paused':
16
16
  case 'blocked':
17
+ case 'waiting':
17
18
  return { key: 'r', action: 'resume', label: 'resume' }
18
19
  case 'collecting':
19
20
  case 'queued':
@@ -37,12 +38,20 @@ export function buildActionAvailability(build: DashboardBuild): DashboardActionA
37
38
  ...(dashboardBuildControl(build.status)
38
39
  ? { primary: dashboardBuildControl(build.status)!.action }
39
40
  : {}),
40
- abort: ['queued', 'running', 'collecting', 'pausing', 'paused', 'resuming', 'blocked'].includes(
41
- build.status,
42
- ),
41
+ abort: [
42
+ 'queued',
43
+ 'running',
44
+ 'collecting',
45
+ 'pausing',
46
+ 'paused',
47
+ 'resuming',
48
+ 'blocked',
49
+ 'waiting',
50
+ ].includes(build.status),
43
51
  discard: build.kind !== 'integration' && build.status === 'queued',
44
52
  autoMerge: !['aborting', 'cleaning'].includes(build.status),
45
- answer: build.blockers.length > 0,
53
+ // Answering an open ticket wait ends it early.
54
+ answer: build.blockers.length > 0 || build.wait !== undefined,
46
55
  }
47
56
  }
48
57
 
@@ -1,6 +1,19 @@
1
- import { evaluateLandingPolicy } from '../../kernel/landing-policy'
1
+ import { candidateHeadPaths } from '../../kernel/head-paths-state'
2
+ import { evaluateLandingPolicy, type LandingPaths } from '../../kernel/landing-policy'
2
3
  import type { BuildState } from '../../kernel/reducer'
3
4
 
5
+ /** The candidate's already-reduced changed paths; never an artifact read. */
6
+ function candidatePaths(state: BuildState): LandingPaths {
7
+ const answer = candidateHeadPaths(state)
8
+ return answer.recorded
9
+ ? {
10
+ recorded: true,
11
+ complete: answer.record.total === answer.record.preview.length,
12
+ paths: answer.record.preview,
13
+ }
14
+ : { recorded: false }
15
+ }
16
+
4
17
  export function landingPolicyDisplay(landing: BuildState['landing']): string {
5
18
  if (landing?.command?.kind === 'hold') return 'held'
6
19
  return landing?.decision?.mode ?? 'policy pending'
@@ -18,6 +31,11 @@ export function nodeLandingPolicyDisplay(
18
31
  ? { kind: 'node' as const, ticket: state.target.ticket.id }
19
32
  : { kind: 'root' as const }
20
33
  const input = { from: 'node' as const, into, labels: [] as string[] }
34
+ const paths = candidatePaths(state)
35
+ const mode = (labels: string[]) => {
36
+ const result = evaluateLandingPolicy(rules, { ...input, labels }, paths)
37
+ return 'deferred' in result ? 'policy pending' : result.mode
38
+ }
21
39
  const excluded = new Set<string>()
22
40
  const modes = new Set<string>()
23
41
  for (const rule of rules) {
@@ -31,15 +49,19 @@ export function nodeLandingPolicyDisplay(
31
49
  continue
32
50
  if (rule.label) {
33
51
  if (excluded.has(rule.label)) continue
34
- modes.add(evaluateLandingPolicy(rules, { ...input, labels: [rule.label] }).mode)
52
+ modes.add(mode([rule.label]))
35
53
  excluded.add(rule.label)
36
54
  } else {
37
- modes.add(evaluateLandingPolicy(rules, input).mode)
38
- return modes.size === 1 ? ([...modes][0] as 'auto' | 'consent') : 'policy pending'
55
+ modes.add(mode([]))
56
+ return modes.size === 1
57
+ ? ([...modes][0] as 'auto' | 'consent' | 'policy pending')
58
+ : 'policy pending'
39
59
  }
40
60
  }
41
- modes.add(evaluateLandingPolicy(rules, input).mode)
42
- return modes.size === 1 ? ([...modes][0] as 'auto' | 'consent') : 'policy pending'
61
+ modes.add(mode([]))
62
+ return modes.size === 1
63
+ ? ([...modes][0] as 'auto' | 'consent' | 'policy pending')
64
+ : 'policy pending'
43
65
  }
44
66
 
45
67
  /** Explain the durable rule when available; unknown labels must not invent a match. */
@@ -55,12 +77,14 @@ export function nodeLandingRuleDisplay(
55
77
  const into = state.target
56
78
  ? { kind: 'node' as const, ticket: state.target.ticket.id }
57
79
  : { kind: 'root' as const }
80
+ const paths = candidatePaths(state)
58
81
  const candidates = [
59
- evaluateLandingPolicy(rules, { from: 'node', into, labels: [] }),
82
+ evaluateLandingPolicy(rules, { from: 'node', into, labels: [] }, paths),
60
83
  ...rules
61
84
  .filter((r) => r.label)
62
- .map((r) => evaluateLandingPolicy(rules, { from: 'node', into, labels: [r.label!] })),
85
+ .map((r) => evaluateLandingPolicy(rules, { from: 'node', into, labels: [r.label!] }, paths)),
63
86
  ]
87
+ if (candidates.some((c) => 'deferred' in c)) return 'rule pending changed paths'
64
88
  const unique = new Map(candidates.map((c) => [JSON.stringify(c.rule), c.rule]))
65
89
  if (unique.size !== 1) return 'rule pending ticket labels'
66
90
  const rule = [...unique.values()][0]!
@@ -1,5 +1,6 @@
1
1
  import { repositoryReadFactsReducer } from '../../kernel/read-facts'
2
2
  import { workTargetDistance } from './target-distance'
3
+ import { openTicketWait, waitingOnLine } from '../../kernel/ticket-wait'
3
4
  import { migrationIdentity, ticketMigrationsReducer } from '../../kernel/ticket-migrations'
4
5
  import { projectRollback, type DashboardRollback } from './rollback'
5
6
  import { dispatchUpgradeReducer, type DispatchUpgradeState } from '../../kernel/dispatch-upgrade'
@@ -101,7 +102,9 @@ import {
101
102
 
102
103
  /** Every capacity-bearing build plus acknowledged abort cleanup is listed.
103
104
  * `aborting` and `cleaning` are display-only projections over durable abort
104
- * facts; neither extends the reducer's lifecycle vocabulary. */
105
+ * facts; neither extends the reducer's lifecycle vocabulary. `waiting` is
106
+ * likewise display-only: a build whose only open escalation is its open
107
+ * ticket wait. The reducer still calls it `blocked` (SPEC §11). */
105
108
  export type EffectiveStatus =
106
109
  | 'queued'
107
110
  | 'running'
@@ -110,6 +113,7 @@ export type EffectiveStatus =
110
113
  | 'paused'
111
114
  | 'resuming'
112
115
  | 'blocked'
116
+ | 'waiting'
113
117
  | 'aborting'
114
118
  | 'cleaning'
115
119
 
@@ -183,6 +187,37 @@ export interface DashboardHarvest {
183
187
  action?: HarvestRunAction
184
188
  }
185
189
 
190
+ /** An open ticket wait as every dashboard renders it. `text` is the shared
191
+ * wording; `question` is the wait escalation's, which answering ends early. */
192
+ export interface DashboardWait {
193
+ tickets: string[]
194
+ reason: string
195
+ since: string
196
+ escalation: string
197
+ question: string
198
+ text: string
199
+ }
200
+
201
+ /** The one builder of a row's wait, so captures and projections share text. */
202
+ export function dashboardWaitFrom(wait: Omit<DashboardWait, 'text'>): DashboardWait {
203
+ return { ...wait, text: waitingOnLine(wait.tickets, wait.reason) }
204
+ }
205
+
206
+ /** The build's open ticket wait, or undefined when none is open. */
207
+ export function dashboardWait(state: BuildState): DashboardWait | undefined {
208
+ const wait = openTicketWait(state)
209
+ if (wait === undefined) return undefined
210
+ const question =
211
+ state.openEscalations.find((escalation) => escalation.id === wait.escalation)?.question ?? ''
212
+ return dashboardWaitFrom({
213
+ tickets: wait.tickets.map((ticket) => ticket.id),
214
+ reason: wait.reason,
215
+ since: wait.enteredAt,
216
+ escalation: wait.escalation,
217
+ question,
218
+ })
219
+ }
220
+
186
221
  export interface DashboardBuild {
187
222
  draining?: boolean
188
223
  /** A work row's standing alert, such as a parked build waiting for a slot. */
@@ -220,10 +255,13 @@ export interface DashboardBuild {
220
255
  | 'unverified merge'
221
256
  slug: string
222
257
  status: EffectiveStatus
223
- /** True when the build is BOTH paused and blocked: blocked wins the status
224
- * (the spec's visual override), and this keeps the pause visible so no
225
- * information is lost. */
258
+ /** True when the build is BOTH paused and blocked or waiting: those win the
259
+ * status (the spec's visual override), and this keeps the pause visible so
260
+ * no information is lost. */
226
261
  alsoPaused: boolean
262
+ /** The open ticket wait, present even when another escalation makes the
263
+ * row `blocked`. Its question is never among `blockers`. */
264
+ wait?: DashboardWait
227
265
  ticketId?: string
228
266
  steps: PipelineStep[]
229
267
  /** Queued-only explanation of the dispatcher boundary currently pending. */
@@ -235,7 +273,8 @@ export interface DashboardBuild {
235
273
  * a later successful attachment proves recovery. */
236
274
  setupError?: string
237
275
  /** Every unresolved blocker's question. Resolved ones drop out by
238
- * construction — the reducer moves them to answeredEscalations. */
276
+ * construction — the reducer moves them to answeredEscalations. An open
277
+ * ticket wait's question is excluded; it is `wait.question`. */
239
278
  blockers: string[]
240
279
  /** Current-spec per-loop review budget overrides. */
241
280
  reviewRoundCeilings?: { plan?: number; code?: number }
@@ -390,6 +429,14 @@ export function effectiveStatus(state: BuildState): EffectiveStatus | BuildState
390
429
  if (state.status === 'aborted') return 'cleaning'
391
430
  if (state.pendingCommands.some((command) => command.command === 'abort')) return 'aborting'
392
431
  if (state.kind === 'node' && integrationFailed(state)) return 'blocked'
432
+ // A ticket wait whose escalation is the only one open reads as waiting; any
433
+ // other open question outranks it and the build reads blocked.
434
+ const wait = openTicketWait(state)
435
+ if (
436
+ wait !== undefined &&
437
+ state.openEscalations.every((escalation) => escalation.id === wait.escalation)
438
+ )
439
+ return 'waiting'
393
440
  if (
394
441
  (state.status === 'paused' || state.status === 'blocked') &&
395
442
  state.openEscalations.length > 0
@@ -418,6 +465,7 @@ function isVisible(status: EffectiveStatus | BuildState['status']): status is Ef
418
465
  status === 'paused' ||
419
466
  status === 'resuming' ||
420
467
  status === 'blocked' ||
468
+ status === 'waiting' ||
421
469
  status === 'aborting' ||
422
470
  status === 'cleaning'
423
471
  )
@@ -588,6 +636,7 @@ export function projectBuildFromFacts(
588
636
  const dashboard = facts.dashboard
589
637
  const status = effectiveStatus(state)
590
638
  if (!isVisible(status)) return null
639
+ const wait = dashboardWait(state)
591
640
  const abortProgress =
592
641
  status === 'aborting'
593
642
  ? state.status === 'queued'
@@ -713,7 +762,10 @@ export function projectBuildFromFacts(
713
762
  ...(record.ticket?.id !== undefined ? { ticketId: record.ticket.id } : {}),
714
763
  steps: [],
715
764
  abortProgress,
716
- blockers: state.openEscalations.map((escalation) => escalation.question),
765
+ ...(wait !== undefined ? { wait } : {}),
766
+ blockers: state.openEscalations
767
+ .filter((escalation) => escalation.id !== wait?.escalation)
768
+ .map((escalation) => escalation.question),
717
769
  ...(state.reviewRoundCeilings.plan !== undefined ||
718
770
  state.reviewRoundCeilings.code !== undefined
719
771
  ? { reviewRoundCeilings: { ...state.reviewRoundCeilings } }
@@ -1052,7 +1104,7 @@ export function projectBuildFromFacts(
1052
1104
  createdAt: record.createdAt,
1053
1105
  },
1054
1106
  status,
1055
- alsoPaused: state.status === 'paused' && status === 'blocked',
1107
+ alsoPaused: state.status === 'paused' && (status === 'blocked' || status === 'waiting'),
1056
1108
  ...(record.ticket?.id !== undefined ? { ticketId: record.ticket.id } : {}),
1057
1109
  steps:
1058
1110
  state.kind === 'node'
@@ -1075,8 +1127,9 @@ export function projectBuildFromFacts(
1075
1127
  ]
1076
1128
  : steps,
1077
1129
  ...(setupError !== undefined ? { setupError } : {}),
1130
+ ...(wait !== undefined ? { wait } : {}),
1078
1131
  blockers: [
1079
- ...state.openEscalations.map((e) => e.question),
1132
+ ...state.openEscalations.filter((e) => e.id !== wait?.escalation).map((e) => e.question),
1080
1133
  ...(state.kind === 'node' && integrationFailed(state)
1081
1134
  ? ['verification failed: file a repair child targeting this node']
1082
1135
  : []),