omp-conductor 0.15.13 → 0.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.
Files changed (47) hide show
  1. package/REFERENCE.md +72 -2
  2. package/package.json +2 -1
  3. package/schema/config.schema.json +6 -0
  4. package/src/admission.ts +745 -0
  5. package/src/ask.ts +47 -0
  6. package/src/backups.ts +19 -7
  7. package/src/board.ts +1 -2
  8. package/src/briefs/orchestrator.md +62 -4
  9. package/src/cli.ts +26 -0
  10. package/src/commands/context.ts +3 -0
  11. package/src/commands/decision.ts +10 -1
  12. package/src/commands/doctor.ts +2 -0
  13. package/src/commands/message.ts +8 -1
  14. package/src/commands/restart.ts +15 -3
  15. package/src/commands/restore-db.ts +146 -0
  16. package/src/commands/stop.ts +24 -15
  17. package/src/commands/unfreeze.ts +56 -0
  18. package/src/commands/watch.ts +77 -0
  19. package/src/config-schema.ts +9 -0
  20. package/src/config.ts +24 -0
  21. package/src/daemon.ts +239 -530
  22. package/src/dashboard/server.ts +2 -1
  23. package/src/decisions.ts +32 -7
  24. package/src/depends-on.ts +73 -0
  25. package/src/doctor.ts +178 -5
  26. package/src/escalate.ts +114 -15
  27. package/src/failure-class.ts +47 -0
  28. package/src/fleet.ts +41 -410
  29. package/src/gitops.ts +86 -1
  30. package/src/log.ts +40 -0
  31. package/src/model-fallback.ts +3 -2
  32. package/src/omp-settings.ts +114 -0
  33. package/src/omp.ts +39 -0
  34. package/src/orchestrator-tick.ts +7 -1
  35. package/src/reports.ts +124 -12
  36. package/src/session-host.ts +6 -0
  37. package/src/setup-wizard.ts +36 -0
  38. package/src/setup.ts +58 -1
  39. package/src/status-render.ts +445 -0
  40. package/src/stop-provenance.ts +53 -0
  41. package/src/store.ts +352 -11
  42. package/src/types.ts +187 -4
  43. package/src/unblock.ts +1 -1
  44. package/src/upgrade-verify.ts +1 -1
  45. package/src/upgrade.ts +1 -2
  46. package/src/verbs/server.ts +25 -0
  47. package/src/worker.ts +162 -10
package/src/daemon.ts CHANGED
@@ -47,6 +47,7 @@ import {
47
47
  createReportOutbox,
48
48
  enqueueAvailableHeldNotices,
49
49
  formatOpenReports,
50
+ reliabilitySettlementLine,
50
51
  type ReportOutbox,
51
52
  } from "./reports.ts";
52
53
  import {
@@ -56,6 +57,10 @@ import {
56
57
  } from "./release-policy.ts";
57
58
  import { branchName, effectiveLabels, route } from "./routing.ts";
58
59
  import type { Routed, UnroutableReason } from "./routing.ts";
60
+ import { admitCandidates, hasContinuationBudget, hasFailedAttemptBudget } from "./admission.ts";
61
+ import type { Admission, AdmissionHold } from "./admission.ts";
62
+ import { log, errText, safeEscalate } from "./log.ts";
63
+ import { materializeOmpSettings } from "./omp-settings.ts";
59
64
  import { evaluateDecisionConditions, probeNpmVersion, probeRateLimitReset } from "./decisions.ts";
60
65
  import { classifyRun, providerCreditRefusal, providerTransientFault, type ClassifyFacts } from "./failure-class.ts";
61
66
  import {
@@ -71,6 +76,7 @@ import { dbPath, LIVE_STATES, openStore, utcDay } from "./store.ts";
71
76
  import { makeTracker, type RateLimitStatus } from "./tracker/github.ts";
72
77
  import { DEFAULT_REPORT_POLICY, RELEASE_SHAPES } from "./types.ts";
73
78
  import type {
79
+ BaseFreeze,
74
80
  BaseHealth,
75
81
  AdmissionHoldReason,
76
82
  Caps,
@@ -140,10 +146,12 @@ import { homedir } from "node:os";
140
146
 
141
147
  import {
142
148
  probeCriticalBase,
149
+ probeRunLane,
143
150
  pushRunBranch,
144
151
  readBaseChain,
145
152
  type CriticalBaseProbe,
146
153
  type CriticalBaseVerdict,
154
+ type RunLaneProbe,
147
155
  type RunRepoRef,
148
156
  } from "./gitops.ts";
149
157
  import {
@@ -172,6 +180,13 @@ const DISPATCH_INFRA_MAX_STRIKES = 3;
172
180
  * provider itself is degraded, not unlucky, and the sweep escalates to a
173
181
  * human instead of requeueing into a down provider forever (#220). */
174
182
  const PROVIDER_TRANSIENT_MAX_STRIKES = 3;
183
+ /** A provider-capacity requeue (sustained in-session rate limiting) is retried,
184
+ * but only a bounded number of times: three throttled runs for one issue mean
185
+ * the provider is at capacity, not unlucky, and the sweep escalates to a human
186
+ * instead of requeueing into a throttled provider forever (#573). The issue's
187
+ * own chain moves onto its next model per strike (via {@link FAILOVER_CLASSES}),
188
+ * so a bounded chain is exhaustible; this caps the unbounded no-chain case. */
189
+ const PROVIDER_CAPACITY_MAX_STRIKES = 3;
175
190
  /** Terminal rows inspected for a salvaged PR per tick. GitHub provenance reads
176
191
  * are maintenance, but a backlog must not turn one tick into an API burst. */
177
192
  const SALVAGED_PR_ADOPTION_BATCH = 10;
@@ -271,6 +286,16 @@ interface Deps {
271
286
  * a marker (a safety interlock must not silently weaken).
272
287
  */
273
288
  probeCriticalBase?: CriticalBaseProbe;
289
+ /**
290
+ * Reads one active run's file lane for the admission file-lane interlock
291
+ * (#555): the union of its uncommitted worktree changes and its branch-vs-base
292
+ * diff. Wired by `runDaemon` to the mirror/worktree-backed
293
+ * {@link probeRunLane}; a test injects a fake. Absent, the interlock is inert
294
+ * (no lane is ever known occupied), which is the issue's "fail open": the
295
+ * gate adds holds, it never refuses a well-formed issue for lack of this
296
+ * probe the way `criticalBase` does.
297
+ */
298
+ probeWorktreeLane?: RunLaneProbe;
274
299
  }
275
300
 
276
301
  /**
@@ -681,14 +706,6 @@ export function markPaged(
681
706
 
682
707
  // ---------------------------------------------------------------------- helpers
683
708
 
684
- function log(msg: string): void {
685
- process.stderr.write(`[conductor ${new Date().toISOString()}] ${msg}\n`);
686
- }
687
-
688
- function errText(e: unknown): string {
689
- return e instanceof Error ? (e.stack ?? e.message) : String(e);
690
- }
691
-
692
709
  /**
693
710
  * Local midnight, matching how a human reads "today".
694
711
  *
@@ -841,15 +858,6 @@ export function recordOperatorStop(
841
858
  * gate on the attempt turns one failed delivery into permanent silence about a
842
859
  * condition that is still true.
843
860
  */
844
- async function safeEscalate(d: Pick<Deps, "escalate">, e: Escalation): Promise<boolean> {
845
- try {
846
- await d.escalate(e);
847
- return true;
848
- } catch (err) {
849
- log(`escalation for ${escalationIssueRef(e.issue)} could not be delivered: ${errText(err)}`);
850
- return false;
851
- }
852
- }
853
861
 
854
862
  async function reactToProviderCredit(
855
863
  d: Deps,
@@ -1108,18 +1116,6 @@ export async function buildBrief(
1108
1116
 
1109
1117
  // ------------------------------------------------------------------- one issue
1110
1118
 
1111
- /** `stops` are the operational ends that each require one resume. */
1112
- export function hasContinuationBudget(stops: number, maxContinuations: number): boolean {
1113
- return stops <= maxContinuations;
1114
- }
1115
-
1116
- /** True while unspent failed-implementation attempts remain. This is the
1117
- * dispatcher's admission gate: once every `maxAttemptsPerIssue` slot is
1118
- * spent, the issue is held as `failed-attempts` forever, and the `unblock`
1119
- * verb withholds the queue label on the same predicate (#348). */
1120
- export function hasFailedAttemptBudget(failures: number, maxAttempts: number): boolean {
1121
- return failures < maxAttempts;
1122
- }
1123
1119
 
1124
1120
  /** The failure classes `countContinuations` deliberately does not charge — the
1125
1121
  * inverted copy of its exclusions, kept beside the breakdown that consumes it
@@ -1133,6 +1129,7 @@ const NON_CONTINUATION_CLASSES: Partial<Record<FailureClass, true>> = {
1133
1129
  "dispatch-infra": true,
1134
1130
  "provider-credit": true,
1135
1131
  "provider-transient": true,
1132
+ "provider-capacity": true,
1136
1133
  };
1137
1134
 
1138
1135
  /** How one issue spent its continuation budget, grouped by failure class —
@@ -1978,6 +1975,16 @@ export async function handleIssue(d: Deps, r: Routed, attempt: number): Promise<
1978
1975
  : dirname(resuming.sessionFile!);
1979
1976
  mkdirSync(sessionDir, { recursive: true });
1980
1977
 
1978
+ // The fleet-owned omp settings overlay (#537): the project's `ompSettings`
1979
+ // map (plus the retry keys derived from `modelFallbacks`, #539's staging
1980
+ // half) materialised to YAML under the run's session directory — never
1981
+ // inside the worktree, whose diff is the PR a worker ships. Rewritten on
1982
+ // every attempt, so a config edit takes effect on the next dispatch and a
1983
+ // resumed attempt reuses the kept session dir with the *current* config.
1984
+ // Absent `ompSettings` and `modelFallbacks`, no file is written, nothing
1985
+ // is passed, and dispatch is byte-for-byte today's.
1986
+ const ompSettingsFile = materializeOmpSettings(project, sessionDir);
1987
+
1981
1988
  // ---- the run's mutation channel (#126) -------------------------------
1982
1989
  // A shared, daemon-owned 0711 parent with one 0600 socket per run, never a
1983
1990
  // per-run *directory*: a directory owned by the run principal would hand
@@ -2091,6 +2098,12 @@ export async function handleIssue(d: Deps, r: Routed, attempt: number): Promise<
2091
2098
  log(`#${issue} ${line}`);
2092
2099
  },
2093
2100
  ...(choice.model === undefined ? {} : { model: choice.model }),
2101
+ // The fleet-owned omp settings overlay (#537): the staged YAML the
2102
+ // session loads through `Settings.init({ configFiles: [<path>] })` —
2103
+ // the project's `ompSettings` map plus the within-run failover keys
2104
+ // #581 staged directly (the project's own chain, not an empty default).
2105
+ // Absent both, nothing is staged, today's dispatch byte for byte.
2106
+ ...(ompSettingsFile === undefined ? {} : { ompSettingsFile }),
2094
2107
  releaseGrants: resolveReleaseGrants(project),
2095
2108
  onReleaseBlocked: workerReleaseBlockRecorder(project.name, issue, runId),
2096
2109
  onTurn: (n) => store.updateRun(runId, { turns: n }),
@@ -2177,10 +2190,27 @@ export async function handleIssue(d: Deps, r: Routed, attempt: number): Promise<
2177
2190
  // worker's, the disclosure becomes the diff's (#488). A diff that could
2178
2191
  // not be read leaves the worker's text untouched and the audit's
2179
2192
  // `changed-line-missing` flag says so.
2180
- const settlementReport =
2193
+ // The within-run reliability sentence, appended where a human reads it
2194
+ // (#584): which model the run finished on and whether it swapped
2195
+ // mid-flight. Empty (undefined) for a clean run, so a run that never
2196
+ // retried, swapped or compacted keeps today's settlement report byte for
2197
+ // byte — the "additive" claim asserted rather than assumed.
2198
+ const reliabilityLine = reliabilitySettlementLine({
2199
+ resolvedModel: result.model,
2200
+ resolvedProvider: result.provider,
2201
+ retryFallbacks: result.retryFallbacks,
2202
+ retryFallbackSucceeded: result.retryFallbackSucceeded,
2203
+ modelRecoveries: result.modelRecoveries,
2204
+ autoRetryCount: result.autoRetryCount,
2205
+ autoCompactionCount: result.autoCompactionCount,
2206
+ });
2207
+
2208
+ const settlementReport = [
2181
2209
  audit?.changedLine === undefined
2182
2210
  ? result.report
2183
- : withDerivedChangedLine(result.report, audit.changedLine);
2211
+ : withDerivedChangedLine(result.report, audit.changedLine),
2212
+ ...(reliabilityLine === undefined ? [] : ["", reliabilityLine]),
2213
+ ].join("\n");
2184
2214
 
2185
2215
  const finalReport = [
2186
2216
  ...(verified.reason === undefined ? [] : [verified.reason, ""]),
@@ -2230,6 +2260,24 @@ export async function handleIssue(d: Deps, r: Routed, attempt: number): Promise<
2230
2260
  endedAt: Date.now(),
2231
2261
  turns: result.turns,
2232
2262
  spendUsd: result.spendUsd,
2263
+ // The count of in-session provider 429s the worker metered live, so a
2264
+ // run the provider throttled into the ground carries its own diagnosis
2265
+ // instead of landing `unknown` — the classifier reads it straight off
2266
+ // this column (#573).
2267
+ provider429Count: result.provider429Count,
2268
+ // The within-run harness reliability surface #581 collected, persisted
2269
+ // now that settlement owns the row (#584). The resolved model/provider
2270
+ // only travel when some assistant message carried them (the run recorded
2271
+ // no model, or the worker never established one); the count fields always
2272
+ // travel, 0 for a clean run, so an absent column can never be read as a
2273
+ // quiet fleet. Written for every terminal state, clean or not.
2274
+ ...(result.model === undefined ? {} : { resolvedModel: result.model }),
2275
+ ...(result.provider === undefined ? {} : { resolvedProvider: result.provider }),
2276
+ retryFallbacks: result.retryFallbacks,
2277
+ retryFallbackSucceeded: result.retryFallbackSucceeded,
2278
+ modelRecoveries: result.modelRecoveries,
2279
+ autoRetryCount: result.autoRetryCount,
2280
+ autoCompactionCount: result.autoCompactionCount,
2233
2281
  // The worker only reports these when it actually established them; a kill
2234
2282
  // or a settle whose report named no PR must not wipe what a verb recorded
2235
2283
  // earlier in the same run (#468). The sink in `updateRun` skips undefined
@@ -2272,6 +2320,22 @@ export async function handleIssue(d: Deps, r: Routed, attempt: number): Promise<
2272
2320
 
2273
2321
  const salvaged = settlement?.lines ?? [];
2274
2322
 
2323
+ // The run's reliability news, surfaced where the tick digest reads it
2324
+ // (#584): the digest is model-authored but consumes the store's material
2325
+ // ledger, so a run that swapped mid-flight or rode out a throttled
2326
+ // provider lands one event the digest can name. Clean runs record nothing
2327
+ // here, so a quiet fleet's digest is unchanged.
2328
+ if (reliabilityLine !== undefined) {
2329
+ store.recordMaterialEvent({
2330
+ project: project.name,
2331
+ category: "reliability",
2332
+ summary: `#${issue} ${reliabilityLine}`,
2333
+ evidence: `${r.issue.title}\n${r.issue.url}\n\n${reliabilityLine}`,
2334
+ occurredAt: Date.now(),
2335
+ recordedAt: Date.now(),
2336
+ });
2337
+ }
2338
+
2275
2339
  if (state === "stopped") {
2276
2340
  log(`#${issue} stopped by operator on attempt ${attempt}: ${result.stoppedReason}`);
2277
2341
  } else if (state === "blocked") {
@@ -2693,6 +2757,31 @@ export async function watchMergedBase(d: Pick<Deps, "project" | "tracker" | "sto
2693
2757
  `${failed.name} failed at ${run.mergeSha} — ${failed.url}` +
2694
2758
  (preexisting ? " (already red before this merge)" : "");
2695
2759
  const flag: SettlementFlag = { kind: "base-branch-red", file: "(base branch)", detail };
2760
+ // Freeze merges to this repo while the base it merged into is red (#283).
2761
+ // The freeze is repo-scoped and sets independently of escalation delivery:
2762
+ // a merge that broke the base must not be followed by another merge onto
2763
+ // the same red base, even if paging the operator fails.
2764
+ if (
2765
+ d.store.setBaseFreeze(d.project.name, {
2766
+ repo: run.repo,
2767
+ culpritSha: run.mergeSha,
2768
+ detail,
2769
+ setAt: now,
2770
+ })
2771
+ ) {
2772
+ d.store.recordMaterialEvent({
2773
+ project: d.project.name,
2774
+ category: "base-red-freeze",
2775
+ summary: `merges to ${run.repo} frozen — base ${run.baseRef} red at ${run.mergeSha.slice(0, 8)}`,
2776
+ evidence:
2777
+ `${detail} This freeze names ${run.mergeSha.slice(0, 8)} as the suspected culprit merge. ` +
2778
+ "Merges to this repo are refused until the base is green again; reverting the culprit is the " +
2779
+ "likely remedy. The freeze lifts automatically on a green re-observation, or the operator can " +
2780
+ "override it with `omp-conductor unfreeze <repo>`.",
2781
+ occurredAt: now,
2782
+ recordedAt: now,
2783
+ });
2784
+ }
2696
2785
  const delivered = await safeEscalate(d, {
2697
2786
  tier: 1,
2698
2787
  project: d.project.name,
@@ -2751,7 +2840,16 @@ export async function watchBaseHealth(
2751
2840
  }
2752
2841
 
2753
2842
  const previous = previousByRepo.get(repo);
2843
+ const freeze = d.store.baseFreeze(d.project.name, repo);
2844
+ const frozen = freeze !== undefined && freeze.clearedAt === undefined;
2845
+ // The same-head/age shortcut exists to avoid re-querying GitHub when a
2846
+ // terminal verdict has not moved. It must NOT skip a frozen repo: a freeze
2847
+ // keyed on one red observation has to keep re-evaluating the same head so a
2848
+ // green rerun clears it without operator action (tonight's evidence — a
2849
+ // red/unknown read two minutes after the same SHA's CI succeeded — is why
2850
+ // it cannot be trusted as terminal).
2754
2851
  if (
2852
+ !frozen &&
2755
2853
  previous?.branch === branch &&
2756
2854
  previous.headSha === head &&
2757
2855
  (previous.verdict === "green" || previous.verdict === "red")
@@ -2811,6 +2909,43 @@ export async function watchBaseHealth(
2811
2909
  };
2812
2910
  d.store.upsertBaseHealth(d.project.name, health);
2813
2911
  previousByRepo.set(repo, health);
2912
+
2913
+ // The freeze follows the live base verdict: red arms (or re-arms) the
2914
+ // repo-scoped freeze, green lifts it. pending/unknown leave it untouched —
2915
+ // a stale or in-flight reading must neither create a freeze nor clear one.
2916
+ if (verdict === "green") {
2917
+ if (d.store.clearBaseFreeze(d.project.name, repo, "daemon", "base-green", now)) {
2918
+ d.store.recordMaterialEvent({
2919
+ project: d.project.name,
2920
+ category: "base-recovered",
2921
+ summary: `merges to ${repo} unfrozen — base ${branch} observed green at ${head.slice(0, 8)}`,
2922
+ evidence: `The base-red freeze on ${repo} lifted automatically: ${branch} is green at ${head.slice(0, 8)}. Merges resume.`,
2923
+ occurredAt: now,
2924
+ recordedAt: now,
2925
+ });
2926
+ }
2927
+ } else if (verdict === "red") {
2928
+ if (
2929
+ d.store.setBaseFreeze(d.project.name, {
2930
+ repo,
2931
+ culpritSha: head,
2932
+ detail,
2933
+ setAt: now,
2934
+ })
2935
+ ) {
2936
+ d.store.recordMaterialEvent({
2937
+ project: d.project.name,
2938
+ category: "base-red-freeze",
2939
+ summary: `merges to ${repo} frozen — base ${branch} red at ${head.slice(0, 8)}`,
2940
+ evidence:
2941
+ `${detail ?? `workflow failed at ${head.slice(0, 8)}`} This freeze names ` +
2942
+ `${head.slice(0, 8)} as the suspected culprit. Reverting it is the likely remedy; the freeze ` +
2943
+ "lifts automatically on green or with `omp-conductor unfreeze <repo>`.",
2944
+ occurredAt: now,
2945
+ recordedAt: now,
2946
+ });
2947
+ }
2948
+ }
2814
2949
  }
2815
2950
  }
2816
2951
 
@@ -3130,22 +3265,6 @@ export async function cleanupRetainedRuns(
3130
3265
 
3131
3266
  // -------------------------------------------------------------------- admission
3132
3267
 
3133
- /** A candidate cleared for dispatch, with the attempt number it will run as. */
3134
- export interface Admission {
3135
- r: Routed;
3136
- attempt: number;
3137
- }
3138
-
3139
- export interface AdmissionHold {
3140
- issue: number;
3141
- reason: AdmissionHoldReason;
3142
- }
3143
-
3144
- export interface AdmissionPass {
3145
- admitted: Admission[];
3146
- holds: AdmissionHold[];
3147
- }
3148
-
3149
3268
  const HOLD_SAMPLE_SIZE = 5;
3150
3269
  const DEGRADED_HOLDS: ReadonlySet<AdmissionHoldReason> = new Set([
3151
3270
  "parent-lookup-error",
@@ -3163,11 +3282,16 @@ export function summarizeDispatch(
3163
3282
  completedAt = Date.now(),
3164
3283
  settled = 0,
3165
3284
  ): DispatchSummary {
3166
- const groups = new Map<AdmissionHoldReason, { count: number; issues: number[] }>();
3285
+ const groups = new Map<AdmissionHoldReason, { count: number; issues: number[]; details: string[] }>();
3167
3286
  for (const hold of holds) {
3168
- const group = groups.get(hold.reason) ?? { count: 0, issues: [] };
3287
+ const group = groups.get(hold.reason) ?? { count: 0, issues: [], details: [] };
3169
3288
  group.count += 1;
3170
- if (group.issues.length < HOLD_SAMPLE_SIZE) group.issues.push(hold.issue);
3289
+ if (group.issues.length < HOLD_SAMPLE_SIZE) {
3290
+ // `issues` and `details` share the sample: the detail is only kept when
3291
+ // the issue it explains is, so the arrays stay index-aligned.
3292
+ group.issues.push(hold.issue);
3293
+ if (hold.detail !== undefined) group.details.push(hold.detail);
3294
+ }
3171
3295
  groups.set(hold.reason, group);
3172
3296
  }
3173
3297
  return {
@@ -3179,7 +3303,12 @@ export function summarizeDispatch(
3179
3303
  degraded: holds.some((hold) => DEGRADED_HOLDS.has(hold.reason)),
3180
3304
  holds: [...groups]
3181
3305
  .sort(([a], [b]) => a.localeCompare(b))
3182
- .map(([reason, group]) => ({ reason, ...group })),
3306
+ .map(([reason, group]) => ({
3307
+ reason,
3308
+ count: group.count,
3309
+ issues: group.issues,
3310
+ ...(group.details.length === 0 ? {} : { details: group.details }),
3311
+ })),
3183
3312
  settled,
3184
3313
  };
3185
3314
  }
@@ -3204,484 +3333,6 @@ export function summarizeHeldPass(settled: number, completedAt = Date.now()): Di
3204
3333
  };
3205
3334
  }
3206
3335
 
3207
- /**
3208
- * What a held plan-usage gate says to a human, if anything.
3209
- *
3210
- * Three different problems hide behind one hold, and they want different
3211
- * tiers. Reaching the threshold is the guard *working*: tier 1, because the
3212
- * fleet resumes on its own at the provider's reset and nobody needs to get
3213
- * out of bed. Everything else — a window nothing reports, a window that
3214
- * resolves to two allowances, a meter that has been unreadable for half an
3215
- * hour — is dispatch stopped with no self-recovery, which is tier 2.
3216
- *
3217
- * Each summary carries the fact that will change when the situation does (the
3218
- * reset instant, the configured id, the date), because the escalation ledger
3219
- * dedupes on the summary: a stable one pages once and then goes quiet, which
3220
- * is right for a repeated tick and wrong for the next window.
3221
- */
3222
- function planUsageEscalation(project: string, plan: PlanUsageStatus): Escalation | undefined {
3223
- const base = { project, issue: NO_ISSUE };
3224
- if (plan.state === "at-cap") {
3225
- const window = plan.window?.id ?? plan.cap?.windowId ?? "the configured window";
3226
- const resets =
3227
- plan.resetsAt === undefined
3228
- ? new Date().toISOString().slice(0, 10)
3229
- : new Date(plan.resetsAt).toISOString();
3230
- return {
3231
- ...base,
3232
- tier: 1,
3233
- summary: `Plan allowance cap reached on ${window} — ${project} is not claiming new work (window ${resets})`,
3234
- detail: [
3235
- plan.detail,
3236
- "Running workers finish normally; only new claims are held.",
3237
- "Dispatch resumes by itself once the provider reports the window reset or usage below the threshold —",
3238
- "no `resume` needed. Raise `caps.planUsage.maxUsedFraction` only if you mean to spend the rest.",
3239
- ].join("\n"),
3240
- };
3241
- }
3242
- if (plan.state === "blind") {
3243
- return {
3244
- ...base,
3245
- tier: 2,
3246
- category: "fleet-stopped",
3247
- // Dated: a meter that breaks again next month is a new incident, not a
3248
- // repeat of this one.
3249
- summary: `Plan usage source unreadable — ${project} is not claiming new work (${new Date().toISOString().slice(0, 10)})`,
3250
- detail: [
3251
- plan.detail,
3252
- "The guard admitted work while the failure looked transient and has now stopped.",
3253
- "Check `omp usage --json` on the fleet host, or set `caps.planUsage` to null if this fleet is unmetered.",
3254
- ].join("\n"),
3255
- };
3256
- }
3257
- if (
3258
- plan.state === "window-missing" ||
3259
- plan.state === "window-ambiguous" ||
3260
- plan.state === "window-uncomparable"
3261
- ) {
3262
- return {
3263
- ...base,
3264
- tier: 2,
3265
- category: "fleet-stopped",
3266
- summary: `Plan usage cap names an unusable window "${plan.cap?.windowId ?? "?"}" — ${project} is not claiming new work`,
3267
- detail: [
3268
- plan.detail,
3269
- "Run `omp usage --json` and copy an allowance `id` into `caps.planUsage.windowId`,",
3270
- "or set `caps.planUsage` to null if this fleet is unmetered.",
3271
- ].join("\n"),
3272
- };
3273
- }
3274
- return undefined;
3275
- }
3276
-
3277
- /**
3278
- * Which routed candidates get a worker this tick — in queue order, never more
3279
- * than `slots` of them. Every non-admission receives a stable reason code.
3280
- *
3281
- * Exported so the admission rules can be pinned without spawning a worker.
3282
- * Every one of them exists because of a live incident, and each guards a
3283
- * different way the same issue gets worked twice — including epic siblings
3284
- * racing onto the same files (#48).
3285
- *
3286
- * Takes the slice of `Deps` it actually reads rather than the whole thing: what
3287
- * admission is allowed to consult is the point of the function, and a `Deps`
3288
- * that grows a field has no business breaking these tests.
3289
- */
3290
- export async function admitCandidates(
3291
- d: Pick<Deps, "project" | "caps" | "tracker" | "store" | "escalate" | "usage" | "probeCriticalBase">,
3292
- routed: Routed[],
3293
- slots: number,
3294
- ): Promise<AdmissionPass> {
3295
- const { project, caps, tracker, store } = d;
3296
- const activeRuns = store.activeRuns(project.name);
3297
- const busyIssues = activeRuns.map((r) => r.issue);
3298
- const busy = new Set(busyIssues);
3299
- // issue -> its active run rows, for the pushed-green admission bypass (#175):
3300
- // only a worker-free pushed-green row may be bypassed, and only when *every*
3301
- // active run for the issue is worker-free. A live (claimed/running) row still
3302
- // holds unconditionally.
3303
- const activeByIssue = new Map<number, RunRecord[]>();
3304
- for (const run of activeRuns) {
3305
- const list = activeByIssue.get(run.issue);
3306
- if (list === undefined) activeByIssue.set(run.issue, [run]);
3307
- else list.push(run);
3308
- }
3309
- // Live worker count per repo, seeded from live runs and incremented as this
3310
- // same pass admits — so two same-repo candidates can never both clear the
3311
- // per-repo cap in one tick (#186).
3312
- const liveByRepo = new Map<string, number>();
3313
- for (const run of store.liveRuns(project.name)) {
3314
- liveByRepo.set(run.repo, (liveByRepo.get(run.repo) ?? 0) + 1);
3315
- }
3316
- const holds: AdmissionHold[] = [];
3317
- const hold = (issue: number, reason: AdmissionHoldReason): void => {
3318
- holds.push({ issue, reason });
3319
- };
3320
-
3321
- // The plan allowance is a fleet-wide question, so it is asked once per pass
3322
- // and answers for every candidate — unlike every gate below it, which is
3323
- // per-issue. It sits here rather than beside the spend cap in `tick` for one
3324
- // reason: the spend cap *pauses the daemon* and waits for a human, and a
3325
- // weekly plan window resets by itself. A guard that demanded `resume` after
3326
- // every rollover would cost more operator attention than the guard saves
3327
- // (#110). Already-running workers are untouched and settle normally.
3328
- //
3329
- // Placed after the cheap local busy-set read and before the first tracker
3330
- // call, so a held fleet spends no GitHub API budget discovering it is held.
3331
- const plan = await readPlanUsage(caps.planUsage, d.usage);
3332
- if (plan.blocking) {
3333
- for (const r of routed) hold(r.issue.number, "plan-usage-cap");
3334
- log(`plan usage gate holding ${String(routed.length)} candidate(s): ${plan.detail}`);
3335
- const escalation = planUsageEscalation(project.name, plan);
3336
- if (escalation !== undefined) await safeEscalate(d, escalation);
3337
- return { admitted: [], holds };
3338
- }
3339
-
3340
- // parent -> repo name -> blocking issue. Seeded from active runs (including
3341
- // pushed-green), then extended by candidates admitted earlier in this same
3342
- // pass so two siblings of one epic never both clear the gate in one tick.
3343
- // A busy issue whose run row cannot be resolved occupies the sentinel repo
3344
- // "" — treated as matching every repo, failing toward holding (#197).
3345
- const occupiedParents = new Map<number, Map<string, number>>();
3346
- const parentCache = new Map<number, number | undefined>();
3347
-
3348
- const resolveParent = async (issue: number): Promise<number | undefined> => {
3349
- if (parentCache.has(issue)) return parentCache.get(issue);
3350
- const parent = await tracker.parentOf(issue);
3351
- parentCache.set(issue, parent);
3352
- return parent;
3353
- };
3354
-
3355
- // Bounded by concurrent workers, not queue depth. A failed lookup here cannot
3356
- // mark an epic occupied; candidates still fail closed on their own parentOf.
3357
- for (const issue of busyIssues) {
3358
- try {
3359
- const parent = await resolveParent(issue);
3360
- if (parent === undefined) continue;
3361
- // The runs table records which repo each attempt worked in, and sibling
3362
- // holds are now per-repo, so a busy child only occupies its epic under
3363
- // that repo's name (same spelling as `createRun` writes from
3364
- // `r.repo.name`). A busy issue with no resolvable run row occupies the
3365
- // sentinel "" instead — matching every repo, failing toward holding.
3366
- const repo = store.latestRun(project.name, issue)?.repo ?? "";
3367
- const siblings = occupiedParents.get(parent);
3368
- if (siblings === undefined) {
3369
- occupiedParents.set(parent, new Map([[repo, issue]]));
3370
- } else if (!siblings.has(repo) && !siblings.has("")) {
3371
- siblings.set(repo, issue);
3372
- }
3373
- } catch (err) {
3374
- log(`#${issue} parent lookup failed while seeding epic occupancy (${errText(err)})`);
3375
- }
3376
- }
3377
-
3378
- const admitted: Admission[] = [];
3379
- for (const r of routed) {
3380
- const issue = r.issue.number;
3381
- if (admitted.length >= slots) {
3382
- hold(issue, "capacity");
3383
- continue;
3384
- }
3385
- if (busy.has(issue)) {
3386
- // A pushed-green row is worker-free by definition (it is not in
3387
- // LIVE_STATES): its PR is live but no process is writing to its branch.
3388
- // So an issue whose active runs are ALL pushed-green is not actually
3389
- // occupied — the corrective attempt the operator unblocked may be
3390
- // admitted as a continuation of that PR, and the open-PR gate below
3391
- // decides the identity. Any live row still holds (#175).
3392
- const allWorkerFree = (activeByIssue.get(issue) ?? []).every((r) => r.state === "pushed-green");
3393
- if (!allWorkerFree) {
3394
- hold(issue, "issue-active");
3395
- continue;
3396
- }
3397
- }
3398
-
3399
- // Per-repo concurrency: the mirror, branch-protection staleness and shared
3400
- // CI egress are all per-repo collision domains, so extra slots should land
3401
- // on other repos rather than stacking workers into the same one (#186).
3402
- const liveInRepo = liveByRepo.get(r.repo.name) ?? 0;
3403
- if (liveInRepo >= caps.maxConcurrentWorkersPerRepo) {
3404
- hold(issue, "repo-active");
3405
- log(`#${issue} skipped: ${liveInRepo} live worker(s) already in ${r.repo.name} (cap ${caps.maxConcurrentWorkersPerRepo})`);
3406
- continue;
3407
- }
3408
-
3409
- const priorRuns = store.attemptsFor(project.name, issue);
3410
- const failures = store.failuresFor(project.name, issue);
3411
- if (!hasFailedAttemptBudget(failures, caps.maxAttemptsPerIssue)) {
3412
- hold(issue, "failed-attempts");
3413
- await safeEscalate(d, {
3414
- tier: 1,
3415
- project: project.name,
3416
- issue,
3417
- summary: `#${issue} has used all ${caps.maxAttemptsPerIssue} failed attempts`,
3418
- detail: [
3419
- r.issue.title,
3420
- r.issue.url,
3421
- "Another implementation attempt almost always means the issue itself is underspecified.",
3422
- "Rewrite the acceptance criteria, or take it off the queue.",
3423
- ].join("\n"),
3424
- });
3425
- continue;
3426
- }
3427
-
3428
- const continuations = store.continuationsFor(project.name, issue);
3429
- if (!hasContinuationBudget(continuations, caps.maxContinuationsPerIssue)) {
3430
- hold(issue, "continuations");
3431
- await safeEscalate(d, {
3432
- tier: 1,
3433
- project: project.name,
3434
- issue,
3435
- summary: `#${issue} exceeded its ${caps.maxContinuationsPerIssue}-continuation budget`,
3436
- detail: [
3437
- r.issue.title,
3438
- r.issue.url,
3439
- "Repeated cap kills, daemon orphans, or answered blocks need an operator to inspect progress.",
3440
- ].join("\n"),
3441
- });
3442
- continue;
3443
- }
3444
-
3445
- // Fail closed on work that exists only in a run repo. `addRunRepo` clears
3446
- // the tree at <workspaceRoot>/<issue> before it provisions, so admitting
3447
- // this issue is what finally destroys the copy the salvage could not save
3448
- // (#118). Nothing here can recover it — git already refused once — so the
3449
- // only safe move is to refuse the claim and keep saying why until an
3450
- // operator has looked and run `unblock --force`.
3451
- const newest = store.latestRun(project.name, issue);
3452
- if (newest?.salvageError !== undefined && newest.salvageAckAt === undefined) {
3453
- hold(issue, "unsalvaged-wip");
3454
- await safeEscalate(d, {
3455
- tier: 1,
3456
- project: project.name,
3457
- issue,
3458
- summary: `#${issue} is holding unsalvaged work and will not be re-claimed`,
3459
- detail: [
3460
- r.issue.title,
3461
- r.issue.url,
3462
- `Attempt ${newest.attempt} could not commit its uncommitted changes: ${newest.salvageError}`,
3463
- `The only copy is the worktree ${newest.worktree === "" ? "(path not recorded)" : newest.worktree}.`,
3464
- "Dispatch is held because claiming this issue removes that tree.",
3465
- "Recover it by hand, then `omp-conductor unblock <n> --force` to release the hold.",
3466
- ].join("\n"),
3467
- });
3468
- continue;
3469
- }
3470
-
3471
- // #428 half (a): a preserved continuation that predates a configured
3472
- // critical-base/safety marker must not be reattached. A base safety fix
3473
- // protects only branches forked after it landed — a continuation forked
3474
- // before it still carries the dangerous test/runtime code, and re-running
3475
- // it on the shared host is what SIGTERMed the production daemon. Fail
3476
- // closed: only a probe that proves every marker is in the reattach
3477
- // source's ancestry admits, and a project that names a marker but has no
3478
- // probe wired (never happens outside tests) holds. Both the hold and the
3479
- // escalation are durable across restart and orphan recovery because this
3480
- // gate runs every admission pass; the branch is re-admitted automatically
3481
- // once the operator updates it to contain the marker, without losing work.
3482
- const markers = project.criticalBase ?? [];
3483
- if (markers.length > 0) {
3484
- const branch = branchName(r.issue);
3485
- let verdict: CriticalBaseVerdict;
3486
- if (d.probeCriticalBase === undefined) {
3487
- verdict = { state: "unknown", error: "no critical-base probe is wired in this deployment" };
3488
- } else {
3489
- try {
3490
- verdict = await d.probeCriticalBase(r.repo, markers, branch);
3491
- } catch (err) {
3492
- verdict = { state: "unknown", error: errText(err) };
3493
- }
3494
- }
3495
- if (verdict.state === "stale") {
3496
- hold(issue, "stale-base");
3497
- log(
3498
- `#${issue} held (stale-base): continuation branch ${branch} predates critical-base marker ${verdict.marker}`,
3499
- );
3500
- await safeEscalate(d, {
3501
- tier: 1,
3502
- project: project.name,
3503
- issue,
3504
- summary: `#${issue} continuation branch predates a critical base safety commit and is held (stale-base)`,
3505
- detail: [
3506
- r.issue.title,
3507
- r.issue.url,
3508
- `The retained branch ${branch} does not contain critical-base marker ${verdict.marker}.`,
3509
- ...(verdict.range.length > 0
3510
- ? [`Base commits the branch is missing: ${verdict.range.join(", ")}`]
3511
- : []),
3512
- "Recovery: merge current base into the branch so it contains the marker, and the next",
3513
- "admission pass re-admits it automatically without losing the branch's work; or review",
3514
- "the branch by hand and clear the hold once the fix is present.",
3515
- ].join("\n"),
3516
- });
3517
- continue;
3518
- }
3519
- if (verdict.state === "unknown") {
3520
- // Fail closed: a branch that cannot be *proven* to contain the marker
3521
- // is refused, and the reason names the unverifiable marker so the
3522
- // operator can fix the fetch or the marker rather than guess.
3523
- hold(issue, "stale-base");
3524
- log(
3525
- `#${issue} held (stale-base): continuation branch ${branch} could not be verified ` +
3526
- `against critical-base marker(s) ${markers.join(", ")} (${verdict.error})`,
3527
- );
3528
- await safeEscalate(d, {
3529
- tier: 1,
3530
- project: project.name,
3531
- issue,
3532
- summary: `#${issue} continuation branch could not be verified against a critical base safety commit and is held (stale-base)`,
3533
- detail: [
3534
- r.issue.title,
3535
- r.issue.url,
3536
- `The retained branch ${branch} could not be verified against critical-base marker(s) ${markers.join(", ")}: ${verdict.error}`,
3537
- "Recovery: merge current base into the branch so it contains the marker, and the next",
3538
- "admission pass re-admits it automatically without losing the branch's work; or review",
3539
- "the branch by hand and clear the hold once the fix is present.",
3540
- ].join("\n"),
3541
- });
3542
- continue;
3543
- }
3544
- }
3545
-
3546
- // Soft concurrency per epic, per repository: at most one in-flight child of
3547
- // a given parent in each repo. Children of one epic in *different* repos
3548
- // parallelise freely — `repo-active` / `maxConcurrentWorkersPerRepo` owns
3549
- // the same-repo collision domain (#197). The "" sentinel matches every
3550
- // repo. No parent means today's concurrent admission. Cheap local filters
3551
- // already ran; this sits before the open-PR API call so a held sibling
3552
- // frees the slot for unrelated work without spending a closers query.
3553
- let parent: number | undefined;
3554
- try {
3555
- parent = await resolveParent(issue);
3556
- } catch (err) {
3557
- hold(issue, "parent-lookup-error");
3558
- log(`#${issue} held: parent check failed (${errText(err)}) — retrying next tick`);
3559
- continue;
3560
- }
3561
- if (parent !== undefined) {
3562
- const occupied = occupiedParents.get(parent);
3563
- const blocker = occupied?.get(r.repo.name) ?? occupied?.get("");
3564
- // The gate serializes siblings under one epic: a held candidate must not
3565
- // proceed while a *different* child of the parent is occupied. But a
3566
- // candidate's own worker-free pushed-green row is exactly the work it is
3567
- // continuing, not a rival — the unblocked continuation of that same
3568
- // issue must not be rejected by its own occupancy, or the retained
3569
- // continuation deadlocks forever with the PR open.
3570
- if (blocker !== undefined && blocker !== issue) {
3571
- hold(issue, "sibling-active");
3572
- log(`#${issue} skipped: sibling #${blocker} in flight under epic #${parent} in ${r.repo.name}`);
3573
- continue;
3574
- }
3575
- }
3576
-
3577
- // The busy set is built from run rows, so it can only speak for work this
3578
- // database recorded. Work pushed before this store existed — a migration, a
3579
- // wiped or relocated state dir, a restore onto a new host — looks exactly
3580
- // like fresh work, and a worker sent at it re-implements a finished PR. The
3581
- // tracker is the only party that remembers, so it is asked. The cost is
3582
- // bounded by free slots, not by queue depth: the call sits behind the two
3583
- // cheap local filters and candidates beyond capacity skip it.
3584
- let closer: OpenCloser | undefined;
3585
- try {
3586
- closer = await tracker.openCloserFor(issue);
3587
- } catch (err) {
3588
- // Fail closed, per candidate. An API error means "unknown whether
3589
- // finished work exists", and admitting on unknown recreates precisely the
3590
- // duplicate-work failure this guard exists to kill: the worst case of
3591
- // holding is a five-minute delay, the worst case of admitting is a burned
3592
- // attempt and a second PR on the same issue. Holding one candidate rather
3593
- // than aborting the loop keeps a transient GitHub failure from deadlocking
3594
- // the whole dispatcher; the next tick retries by itself.
3595
- hold(issue, "open-pr-lookup-error");
3596
- log(`#${issue} held: open-PR check failed (${errText(err)}) — retrying next tick`);
3597
- continue;
3598
- }
3599
- if (closer !== undefined) {
3600
- const latest = store.latestRun(project.name, issue);
3601
- // Terminality is the first half of the test and is not negotiable: while a
3602
- // run is live its worker is still pushing to that branch, and a second
3603
- // worker sent at the same PR is exactly the duplicate-work failure this
3604
- // guard exists to kill. Only a run that has stopped can be continued.
3605
- const retained =
3606
- latest?.state === "blocked" ||
3607
- latest?.state === "failed" ||
3608
- latest?.state === "killed" ||
3609
- latest?.state === "orphaned" ||
3610
- latest?.state === "pushed-green"
3611
- ? latest
3612
- : undefined;
3613
- // The second half asks "is this open PR our retained work", and accepts
3614
- // two identities for it, because the branch is the durable artefact of a
3615
- // retained run and the PR is not. A cap kill can end a run before any PR
3616
- // exists: veltro#324 attempt 1 was killed at the turns cap on
3617
- // 2026-08-09T00:47Z before its worker opened one, so the row kept `branch`
3618
- // and `prUrl` stayed NULL. chad#438 was opened from that exact branch
3619
- // afterwards, and URL equality — the only test 0.3.20 had — can never match
3620
- // a URL the terminal run never recorded, so every tick held #324 as
3621
- // `open-pr` until an operator closed recoverable work to free the branch
3622
- // (#50). An ordinary issue whose open PR is unrelated still fails both
3623
- // identities and stays ineligible, and an empty `headRefName` (a reply that
3624
- // did not carry the field) is never a match: unknown is not identity.
3625
- let resume: string | undefined;
3626
- if (retained !== undefined) {
3627
- if (retained.prUrl === closer.url) {
3628
- resume = `from ${retained.state} run (matched recorded PR URL)`;
3629
- } else if (closer.headRefName !== "" && retained.branch === closer.headRefName) {
3630
- resume = `from ${retained.state} run (matched retained branch ${closer.headRefName})`;
3631
- }
3632
- }
3633
- if (resume === undefined) {
3634
- hold(issue, "open-pr");
3635
- log(`#${issue} skipped: open PR ${closer.url} already closes it`);
3636
- continue;
3637
- }
3638
- log(`#${issue} continuing retained PR ${closer.url} ${resume}`);
3639
- }
3640
-
3641
- // The queue comes from GitHub's eventually-consistent search index. Re-read
3642
- // state and labels directly at the last possible moment so a just-closed or
3643
- // explicitly dequeued issue cannot turn a stale candidate into another
3644
- // attempt (#247).
3645
- let snapshot: IssueSnapshot | undefined;
3646
- try {
3647
- snapshot = await tracker.issueSnapshot(issue);
3648
- } catch {
3649
- snapshot = undefined;
3650
- }
3651
- if (snapshot === undefined) {
3652
- hold(issue, "issue-state-lookup-error");
3653
- log(`#${issue} held: issue snapshot check failed — retrying next tick`);
3654
- continue;
3655
- }
3656
- if (snapshot.state === "closed") {
3657
- hold(issue, "issue-closed");
3658
- log(`#${issue} skipped: issue is closed (search index lag)`);
3659
- continue;
3660
- }
3661
- if (!snapshot.labels.includes(project.queueLabel)) {
3662
- hold(issue, "issue-dequeued");
3663
- log(`#${issue} skipped: queue label ${project.queueLabel} was removed (search index lag)`);
3664
- continue;
3665
- }
3666
-
3667
- admitted.push({ r, attempt: priorRuns + 1 });
3668
- liveByRepo.set(r.repo.name, (liveByRepo.get(r.repo.name) ?? 0) + 1);
3669
- if (parent !== undefined) {
3670
- // Extend the epic's occupancy under this repo (slot empty by construction
3671
- // here — the gate above would have held the candidate otherwise) so a
3672
- // same-repo sibling later in this pass does not clear the gate (#197).
3673
- let siblings = occupiedParents.get(parent);
3674
- if (siblings === undefined) {
3675
- siblings = new Map();
3676
- occupiedParents.set(parent, siblings);
3677
- }
3678
- if (!siblings.has(r.repo.name)) siblings.set(r.repo.name, issue);
3679
- }
3680
- }
3681
-
3682
- return { admitted, holds };
3683
- }
3684
-
3685
3336
  export interface WorkerPool {
3686
3337
  launch(work: Promise<void>): void;
3687
3338
  activeCount(): number;
@@ -4576,6 +4227,8 @@ export interface StatusSnapshot {
4576
4227
  */
4577
4228
  /** Current live-head push-workflow verdict per recently merged repository. */
4578
4229
  baseHealth: BaseHealth[];
4230
+ /** Per-repo base-red merge freezes, active first (#283). */
4231
+ freezes: BaseFreeze[];
4579
4232
  verbLedger: VerbLedgerEntry[];
4580
4233
  /** Runs backed by a worker process — the number capacity compares against. */
4581
4234
  liveWorkers: number;
@@ -4671,6 +4324,7 @@ export function statusSnapshotFromStore(
4671
4324
  ? {}
4672
4325
  : { labelOps: { pending: labelOpsPending, oldestAgeMs: now - oldestLabelOpAt } }),
4673
4326
  baseHealth: store.baseHealth(p.name),
4327
+ freezes: store.freezes(p.name),
4674
4328
  ...(orchestratorDown === undefined ? {} : { orchestratorDown }),
4675
4329
  };
4676
4330
  }
@@ -4714,6 +4368,11 @@ export function formatDispatchSummary(summary?: DispatchSummary): string {
4714
4368
  ? ""
4715
4369
  : ` (#${hold.issues.join(", #")}${hold.count > hold.issues.length ? ", …" : ""})`;
4716
4370
  lines.push(` ${hold.reason} ${hold.count}${sample}`);
4371
+ // A `file-lane` hold groups several issues, each blocked by a different
4372
+ // file and holder; the grouped line says how many, this says which.
4373
+ if ((hold.details?.length ?? 0) > 0) {
4374
+ lines.push(` ${hold.details!.join(" | ")}`);
4375
+ }
4717
4376
  }
4718
4377
  }
4719
4378
  }
@@ -4783,6 +4442,25 @@ export function formatBaseHealth(rows: readonly BaseHealth[]): string[] {
4783
4442
  });
4784
4443
  }
4785
4444
 
4445
+ /**
4446
+ * The active base-red freezes as status lines — merges refused until the base
4447
+ * is green again or the operator overrides. Active freezes only: a cleared
4448
+ * freeze is history the ledger and digest already told an operator about.
4449
+ */
4450
+ export function formatFreezes(freezes: readonly BaseFreeze[]): string[] {
4451
+ const active = freezes.filter((f) => f.clearedAt === undefined);
4452
+ if (active.length === 0) return [];
4453
+ return [
4454
+ "frozen repos (merges refused until base green)",
4455
+ ...active.map(
4456
+ (f) =>
4457
+ ` ${f.repo} base red at ${f.culpritSha.slice(0, 8)}` +
4458
+ (f.detail === undefined ? "" : ` ${f.detail}`) +
4459
+ ` — override: omp-conductor unfreeze ${f.repo}`,
4460
+ ),
4461
+ ];
4462
+ }
4463
+
4786
4464
 
4787
4465
  export function formatStatus(s: StatusSnapshot): string {
4788
4466
  const lines = [
@@ -4832,6 +4510,7 @@ export function formatStatus(s: StatusSnapshot): string {
4832
4510
  }
4833
4511
  }
4834
4512
  lines.push(...formatBaseHealth(s.baseHealth));
4513
+ lines.push(...formatFreezes(s.freezes));
4835
4514
  lines.push(...formatSalvagedRuns(s.salvagedRuns));
4836
4515
  lines.push(...formatOpenReports(s.openReports));
4837
4516
  lines.push(...formatVerbLedger(s.verbLedger));
@@ -5267,6 +4946,35 @@ async function recoverRun(
5267
4946
  log(`#${run.issue} escalated from persistent ${cls}: ${evidence}`);
5268
4947
  return;
5269
4948
  }
4949
+ // Same bound for provider-capacity: a run the provider throttled into the
4950
+ // ground is requeued free (no attempt charged) — but a provider that
4951
+ // throttles the same issue three times is at capacity, and a human has to
4952
+ // check its status before hand-requeueing (#573). On a chain-configured
4953
+ // project each requeue already moved the next attempt to the next chain
4954
+ // model, so this escalation is what catches the no-chain case and the
4955
+ // exhausted chain; it names every model the chain tried.
4956
+ if (
4957
+ cls === "provider-capacity" &&
4958
+ store.classCountFor(project.name, run.issue, "provider-capacity") >= PROVIDER_CAPACITY_MAX_STRIKES
4959
+ ) {
4960
+ const tried = formatModelsTried(modelsTried(store.runsForIssue(project.name, run.issue)));
4961
+ await safeEscalate(d, {
4962
+ tier: 1,
4963
+ project: project.name,
4964
+ issue: run.issue,
4965
+ summary: `[provider-capacity] #${run.issue}: the model provider is throttling this run into the ground — ${evidence}`,
4966
+ detail: [
4967
+ `The provider answered #${run.issue} with sustained in-session rate limits ${PROVIDER_CAPACITY_MAX_STRIKES} times in a row; the harness retried each and was exhausted.`,
4968
+ ...(tried === ""
4969
+ ? []
4970
+ : [`Models tried: ${tried}.`]),
4971
+ "Check the provider's rate-limit status (and its throughput-oriented routes) before requeueing by hand.",
4972
+ ].join("\n"),
4973
+ });
4974
+ store.updateRun(run.id, { recoveredAt: Date.now() });
4975
+ log(`#${run.issue} escalated from persistent ${cls}: ${evidence}`);
4976
+ return;
4977
+ }
5270
4978
  // Only when the tracker still shows this issue as ours to hand back. An
5271
4979
  // issue that is closed, or has no state label, was resolved by another route
5272
4980
  // and requeueing it would dispatch work nobody asked for.
@@ -5875,6 +5583,7 @@ export async function runDaemon(o: DaemonOpts = {}): Promise<void> {
5875
5583
  cleanup: { next: 0 },
5876
5584
  probeCriticalBase: (repo, markers, branch) =>
5877
5585
  probeCriticalBase(project, repo, branch, markers),
5586
+ probeWorktreeLane: (input) => probeRunLane(input),
5878
5587
  ...(verbPeerReader === undefined ? {} : { verbPeerReader }),
5879
5588
  verbActions,
5880
5589
  };
@@ -5970,7 +5679,7 @@ export async function runDaemon(o: DaemonOpts = {}): Promise<void> {
5970
5679
  // when it resumes and cannot create the work this shutdown is about to
5971
5680
  // wait for (#374).
5972
5681
  drain.draining = true;
5973
- log("shutting down after active workers finish");
5682
+ log("shutdown requested draining dispatch; live worker sessions are not waited for");
5974
5683
  pace.requestWake();
5975
5684
  };
5976
5685
  process.on("SIGINT", stop);