@lsctech/polaris 0.5.6 → 0.5.8

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 (37) hide show
  1. package/dist/autoresearch/index.js +30 -1
  2. package/dist/autoresearch/proposal.js +5 -0
  3. package/dist/autoresearch/score.js +174 -2
  4. package/dist/autoresearch/sol-evaluation-writer.js +135 -0
  5. package/dist/autoresearch/sol-evidence-loader.js +40 -3
  6. package/dist/autoresearch/sol-evidence-normalizer.js +337 -0
  7. package/dist/autoresearch/sol-recommendations.js +212 -0
  8. package/dist/autoresearch/sol-report-renderer.js +282 -0
  9. package/dist/autoresearch/sol-report.js +44 -0
  10. package/dist/autoresearch/sol-scorecard-calculator.js +865 -0
  11. package/dist/autoresearch/sol-scorer.js +45 -1
  12. package/dist/cli/autoresearch.js +77 -0
  13. package/dist/cluster-state/store.js +56 -0
  14. package/dist/config/defaults.js +1 -0
  15. package/dist/config/validator.js +157 -0
  16. package/dist/finalize/artifact-policy.js +2 -0
  17. package/dist/finalize/github.js +13 -9
  18. package/dist/finalize/index.js +198 -4
  19. package/dist/finalize/linear.js +8 -4
  20. package/dist/finalize/steps/08-create-pr.js +2 -2
  21. package/dist/finalize/steps/11-update-linear.js +2 -2
  22. package/dist/loop/parent.js +189 -33
  23. package/dist/loop/worker-packet.js +75 -1
  24. package/dist/qc/artifacts.js +27 -0
  25. package/dist/qc/fixtures/repair-packets.js +170 -0
  26. package/dist/qc/index.js +2 -0
  27. package/dist/qc/orchestration.js +5 -2
  28. package/dist/qc/policy.js +30 -3
  29. package/dist/qc/providers/coderabbit.js +152 -17
  30. package/dist/qc/registry.js +36 -3
  31. package/dist/qc/repair-loop.js +458 -0
  32. package/dist/qc/repair-packets.js +420 -0
  33. package/dist/qc/runner.js +328 -37
  34. package/dist/qc/schemas.js +79 -1
  35. package/dist/types/sol-metrics.js +108 -0
  36. package/dist/types/sol-scorecard.js +148 -0
  37. package/package.json +1 -1
@@ -1,16 +1,49 @@
1
1
  "use strict";
2
2
  /**
3
- * Default QC provider registry.
3
+ * QC provider registry builders.
4
4
  *
5
- * Registers all built-in QC adapters. In the future this can be extended to
6
- * discover providers from configuration or installed plugins.
5
+ * `createDefaultQcRegistry` returns the static built-in registry for backward
6
+ * compatibility. `createQcRegistry` builds a registry from polaris.config.json
7
+ * qc.providers, wiring provider-agnostic command/output config into the
8
+ * matching built-in adapters.
7
9
  */
8
10
  Object.defineProperty(exports, "__esModule", { value: true });
9
11
  exports.createDefaultQcRegistry = createDefaultQcRegistry;
12
+ exports.createQcRegistry = createQcRegistry;
10
13
  const provider_js_1 = require("./provider.js");
11
14
  const coderabbit_js_1 = require("./providers/coderabbit.js");
15
+ function createProvider(name, config) {
16
+ // Only CodeRabbit is supported as a concrete provider in this child.
17
+ // Future providers can be registered here by name.
18
+ if (name === "coderabbit") {
19
+ return new coderabbit_js_1.CodeRabbitQcProvider(config);
20
+ }
21
+ return undefined;
22
+ }
12
23
  function createDefaultQcRegistry() {
13
24
  const registry = new provider_js_1.QcProviderRegistry();
14
25
  registry.register(new coderabbit_js_1.CodeRabbitQcProvider());
15
26
  return registry;
16
27
  }
28
+ /**
29
+ * Build a registry from configured QC providers.
30
+ *
31
+ * Disabled providers (enabled: false) are skipped. Unknown provider names are
32
+ * skipped; callers should validate config before dispatch and may report
33
+ * unknown providers as blockers at runtime.
34
+ */
35
+ function createQcRegistry(config) {
36
+ const registry = new provider_js_1.QcProviderRegistry();
37
+ if (!config?.enabled) {
38
+ return registry;
39
+ }
40
+ for (const [name, providerConfig] of Object.entries(config.providers ?? {})) {
41
+ if (providerConfig.enabled === false)
42
+ continue;
43
+ const provider = createProvider(name, providerConfig);
44
+ if (provider) {
45
+ registry.register(provider);
46
+ }
47
+ }
48
+ return registry;
49
+ }
@@ -0,0 +1,458 @@
1
+ "use strict";
2
+ /**
3
+ * QC repair loop orchestration.
4
+ *
5
+ * The Foreman calls `runQcRepairLoop` after a completed-cluster QC run produces
6
+ * findings. This module:
7
+ *
8
+ * 1. Discovers a compiled repair packet manifest for the current round.
9
+ * 2. Converts eligible repair packets into Foreman-dispatched repair workers.
10
+ * 3. Awaits repair worker completion (via sealed result files / adapter).
11
+ * 4. Reruns QC after all repair workers in a round have completed.
12
+ * 5. Loops until: pass, no repairable packets, max rounds reached,
13
+ * all providers failed, operator review required, or Medic referral.
14
+ *
15
+ * Dispatch boundary: the parent/orchestrator NEVER implements repair code.
16
+ * Each repair packet becomes a sealed WorkerPacket with worker_role: "repair".
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.DEFAULT_MAX_REPAIR_ROUNDS = void 0;
20
+ exports.partitionRepairPackets = partitionRepairPackets;
21
+ exports.initRepairLoopState = initRepairLoopState;
22
+ exports.runQcRepairLoop = runQcRepairLoop;
23
+ const node_fs_1 = require("node:fs");
24
+ const node_path_1 = require("node:path");
25
+ const repair_packets_js_1 = require("./repair-packets.js");
26
+ const orchestration_js_1 = require("./orchestration.js");
27
+ const store_js_1 = require("../cluster-state/store.js");
28
+ // ── Constants ─────────────────────────────────────────────────────────────────
29
+ /** Default maximum repair rounds when not configured. */
30
+ exports.DEFAULT_MAX_REPAIR_ROUNDS = 2;
31
+ // ── Helpers ────────────────────────────────────────────────────────────────────
32
+ function appendTelemetry(telemetryFile, event) {
33
+ (0, node_fs_1.mkdirSync)((0, node_path_1.dirname)(telemetryFile), { recursive: true });
34
+ (0, node_fs_1.appendFileSync)(telemetryFile, JSON.stringify(event) + "\n", "utf-8");
35
+ }
36
+ async function persistQcRepairOutcome(clusterId, repoRoot, outcome) {
37
+ try {
38
+ const clusterState = (0, store_js_1.readClusterStateSync)(clusterId, repoRoot);
39
+ if (!clusterState)
40
+ return;
41
+ await (0, store_js_1.writeClusterState)(clusterId, {
42
+ ...clusterState,
43
+ state_generation: clusterState.state_generation + 1,
44
+ qc_repair_outcome: outcome,
45
+ }, repoRoot);
46
+ }
47
+ catch {
48
+ // Best-effort: the loop outcome is already returned to the caller and
49
+ // recorded in the loop checkpoint. Do not block finalization on a
50
+ // cluster-state write race.
51
+ }
52
+ }
53
+ async function persistQcRepairManifest(clusterId, repoRoot, round, manifestPath) {
54
+ try {
55
+ const clusterState = (0, store_js_1.readClusterStateSync)(clusterId, repoRoot);
56
+ if (!clusterState)
57
+ return;
58
+ const manifests = { ...(clusterState.qc_repair_manifests ?? {}), [round]: manifestPath };
59
+ if (clusterState.qc_repair_manifests &&
60
+ clusterState.qc_repair_manifests[round] === manifestPath) {
61
+ return;
62
+ }
63
+ await (0, store_js_1.writeClusterState)(clusterId, {
64
+ ...clusterState,
65
+ state_generation: clusterState.state_generation + 1,
66
+ qc_repair_manifests: manifests,
67
+ }, repoRoot);
68
+ }
69
+ catch {
70
+ // Best-effort durability for repair-round manifest pointer.
71
+ }
72
+ }
73
+ /** Returns true when any finding in the results routes to repair-worker. */
74
+ function hasRepairableFindings(results) {
75
+ return results.some((r) => r.findings.some((f) => (f.routingDecision === "repair-worker" || f.routingDecision === "original-worker") &&
76
+ f.status !== "waived" &&
77
+ f.status !== "autofixed" &&
78
+ f.status !== "repaired"));
79
+ }
80
+ /** Returns true when all QC providers failed in every result. */
81
+ function allProvidersFailed(results) {
82
+ return (results.length > 0 &&
83
+ results.every((r) => r.allProvidersFailed || r.status === "failed"));
84
+ }
85
+ /** Returns true when any finding requires operator review. */
86
+ function requiresOperatorReview(results) {
87
+ return results.some((r) => r.findings.some((f) => f.routingDecision === "operator-review" &&
88
+ f.status !== "waived" &&
89
+ f.status !== "repaired"));
90
+ }
91
+ /** Returns true when the QC rerun passed (no open/blocking findings). */
92
+ function rerunPassed(results) {
93
+ if (results.length === 0)
94
+ return false;
95
+ return results.every((r) => r.status === "passed" || r.status === "skipped");
96
+ }
97
+ /** Partition packets into safe-to-parallel and must-serialize groups. */
98
+ function partitionRepairPackets(packets) {
99
+ // Medic (operator-review) packets are always serialized.
100
+ const serialized = packets.filter((p) => p.medic || p.routingTarget === "operator-review");
101
+ const parallelizable = packets.filter((p) => !p.medic && p.routingTarget !== "operator-review");
102
+ // Group by parallelGroup assignment from the compiler.
103
+ const groups = new Map();
104
+ for (const pkt of parallelizable) {
105
+ const key = pkt.parallelGroup ?? `solo-${pkt.packetId}`;
106
+ if (!groups.has(key))
107
+ groups.set(key, []);
108
+ groups.get(key).push(pkt);
109
+ }
110
+ return {
111
+ parallelGroups: Array.from(groups.values()),
112
+ serialized,
113
+ };
114
+ }
115
+ /** Initialize a fresh QcRepairLoopState. */
116
+ function initRepairLoopState(opts) {
117
+ const now = new Date().toISOString();
118
+ return {
119
+ current_round: 0,
120
+ max_rounds: opts.maxRounds,
121
+ source_qc_run_ids: opts.sourceQcRunIds,
122
+ manifest_path: null,
123
+ pending_packet_ids: [],
124
+ completed_packet_ids: [],
125
+ rerun_requested: false,
126
+ rerun_qc_run_ids: {},
127
+ terminal_outcome: null,
128
+ initiated_at: now,
129
+ updated_at: now,
130
+ };
131
+ }
132
+ // ── Main repair loop ───────────────────────────────────────────────────────────
133
+ /**
134
+ * Run the bounded QC repair loop.
135
+ *
136
+ * The loop is Foreman-owned: it coordinates dispatch, never implements repairs.
137
+ * Returns deterministically on pass, no-repairable, max-rounds, all-providers-failed,
138
+ * operator-review, or medic-referral.
139
+ */
140
+ async function runQcRepairLoop(options) {
141
+ const { clusterId, runId, branch, repoRoot, telemetryFile, config, registry, initialQcResults, dispatchRepairWorker, validationCommands = [], timeoutMs, maxRounds = exports.DEFAULT_MAX_REPAIR_ROUNDS, priorLoopState, onStateUpdate, } = options;
142
+ if (!config.enabled) {
143
+ const state = initRepairLoopState({
144
+ maxRounds,
145
+ sourceQcRunIds: initialQcResults.map((r) => r.qcRunId),
146
+ });
147
+ state.terminal_outcome = "qc-disabled";
148
+ state.updated_at = new Date().toISOString();
149
+ await persistQcRepairOutcome(clusterId, repoRoot, "qc-disabled");
150
+ return {
151
+ outcome: "qc-disabled",
152
+ rounds_completed: 0,
153
+ final_qc_results: initialQcResults,
154
+ loop_state: state,
155
+ summary: "QC repair loop skipped — QC disabled by configuration",
156
+ };
157
+ }
158
+ const sourceRunIds = initialQcResults.map((r) => r.qcRunId);
159
+ let loopState = priorLoopState ?? initRepairLoopState({ maxRounds, sourceQcRunIds: sourceRunIds });
160
+ let currentResults = initialQcResults;
161
+ let roundsCompleted = loopState.current_round;
162
+ appendTelemetry(telemetryFile, {
163
+ event: "qc-repair-loop-started",
164
+ run_id: runId,
165
+ cluster_id: clusterId,
166
+ max_rounds: maxRounds,
167
+ source_qc_run_ids: sourceRunIds,
168
+ timestamp: new Date().toISOString(),
169
+ });
170
+ // ── Main loop ──────────────────────────────────────────────────────────────
171
+ while (roundsCompleted < maxRounds) {
172
+ const round = roundsCompleted + 1;
173
+ // Check exit conditions at the top of each round.
174
+ if (rerunPassed(currentResults) && round > 1) {
175
+ // A rerun already passed in this call frame — exit.
176
+ break;
177
+ }
178
+ if (allProvidersFailed(currentResults)) {
179
+ loopState = { ...loopState, terminal_outcome: "all-providers-failed", updated_at: new Date().toISOString() };
180
+ onStateUpdate?.(loopState);
181
+ appendTelemetry(telemetryFile, {
182
+ event: "qc-repair-loop-terminal",
183
+ run_id: runId,
184
+ outcome: "all-providers-failed",
185
+ round,
186
+ timestamp: new Date().toISOString(),
187
+ });
188
+ await persistQcRepairOutcome(clusterId, repoRoot, "all-providers-failed");
189
+ return {
190
+ outcome: "all-providers-failed",
191
+ rounds_completed: roundsCompleted,
192
+ final_qc_results: currentResults,
193
+ loop_state: loopState,
194
+ summary: `QC repair loop halted: all QC providers failed at round ${round}`,
195
+ };
196
+ }
197
+ if (requiresOperatorReview(currentResults)) {
198
+ loopState = { ...loopState, terminal_outcome: "operator-review", updated_at: new Date().toISOString() };
199
+ onStateUpdate?.(loopState);
200
+ appendTelemetry(telemetryFile, {
201
+ event: "qc-repair-loop-terminal",
202
+ run_id: runId,
203
+ outcome: "operator-review",
204
+ round,
205
+ timestamp: new Date().toISOString(),
206
+ });
207
+ await persistQcRepairOutcome(clusterId, repoRoot, "operator-review");
208
+ return {
209
+ outcome: "operator-review",
210
+ rounds_completed: roundsCompleted,
211
+ final_qc_results: currentResults,
212
+ loop_state: loopState,
213
+ summary: `QC repair loop halted: unresolved operator-review findings at round ${round}`,
214
+ };
215
+ }
216
+ // ── Compile / discover repair packets ──────────────────────────────────
217
+ let manifest = null;
218
+ // Try to read an existing manifest for this round first (idempotent re-entry).
219
+ manifest = (0, repair_packets_js_1.readRepairPacketManifest)(clusterId, round, repoRoot);
220
+ if (!manifest) {
221
+ // Compile fresh repair packets from current QC results.
222
+ const compiled = (0, repair_packets_js_1.compileAndWriteRepairPackets)({
223
+ clusterId,
224
+ round,
225
+ qcResults: currentResults,
226
+ config,
227
+ validationCommands,
228
+ repoRoot,
229
+ });
230
+ manifest = compiled.manifest;
231
+ // Update cluster state with manifest path.
232
+ await persistQcRepairManifest(clusterId, repoRoot, round, compiled.manifestPath);
233
+ loopState = {
234
+ ...loopState,
235
+ current_round: round,
236
+ manifest_path: compiled.manifestPath,
237
+ pending_packet_ids: compiled.packets.map((p) => p.packetId),
238
+ updated_at: new Date().toISOString(),
239
+ };
240
+ onStateUpdate?.(loopState);
241
+ appendTelemetry(telemetryFile, {
242
+ event: "qc-repair-manifest-compiled",
243
+ run_id: runId,
244
+ cluster_id: clusterId,
245
+ round,
246
+ packet_count: compiled.packets.length,
247
+ manifest_path: compiled.manifestPath,
248
+ timestamp: new Date().toISOString(),
249
+ });
250
+ }
251
+ else {
252
+ const existingManifestPath = loopState.manifest_path ??
253
+ (0, node_path_1.join)(repoRoot, ".polaris", "clusters", clusterId, "qc", "repair-rounds", String(round), "repair-packets.json");
254
+ loopState = {
255
+ ...loopState,
256
+ current_round: round,
257
+ manifest_path: existingManifestPath,
258
+ updated_at: new Date().toISOString(),
259
+ };
260
+ onStateUpdate?.(loopState);
261
+ await persistQcRepairManifest(clusterId, repoRoot, round, existingManifestPath);
262
+ }
263
+ // ── Check for repairable packets ────────────────────────────────────────
264
+ const repairablePackets = manifest.packets.filter((p) => p.routingTarget === "repair-worker" &&
265
+ p.status === "pending" &&
266
+ !loopState.completed_packet_ids.includes(p.packetId));
267
+ if (repairablePackets.length === 0 && !hasRepairableFindings(currentResults)) {
268
+ loopState = { ...loopState, terminal_outcome: "no-repairable", updated_at: new Date().toISOString() };
269
+ onStateUpdate?.(loopState);
270
+ appendTelemetry(telemetryFile, {
271
+ event: "qc-repair-loop-terminal",
272
+ run_id: runId,
273
+ outcome: "no-repairable",
274
+ round,
275
+ timestamp: new Date().toISOString(),
276
+ });
277
+ await persistQcRepairOutcome(clusterId, repoRoot, "no-repairable");
278
+ return {
279
+ outcome: "no-repairable",
280
+ rounds_completed: roundsCompleted,
281
+ final_qc_results: currentResults,
282
+ loop_state: loopState,
283
+ summary: `QC repair loop: no repairable packets at round ${round}`,
284
+ };
285
+ }
286
+ // ── Dispatch repair workers (parallel groups, then serialized) ──────────
287
+ const { parallelGroups, serialized } = partitionRepairPackets(repairablePackets);
288
+ const allWorkerResults = [];
289
+ let hasMedicReferral = false;
290
+ // Dispatch parallel groups.
291
+ for (const group of parallelGroups) {
292
+ appendTelemetry(telemetryFile, {
293
+ event: "qc-repair-worker-group-start",
294
+ run_id: runId,
295
+ round,
296
+ parallel_group: group[0]?.parallelGroup ?? null,
297
+ packet_ids: group.map((p) => p.packetId),
298
+ timestamp: new Date().toISOString(),
299
+ });
300
+ // Within a group, packets are non-conflicting and can run concurrently.
301
+ const groupResults = await Promise.all(group.map((pkt) => dispatchRepairWorker(pkt, round, manifest)));
302
+ allWorkerResults.push(...groupResults);
303
+ }
304
+ // Dispatch serialized (medic/operator-review) packets sequentially.
305
+ for (const pkt of serialized) {
306
+ const result = await dispatchRepairWorker(pkt, round, manifest);
307
+ allWorkerResults.push(result);
308
+ }
309
+ // Record completed packet IDs.
310
+ const completedIds = allWorkerResults
311
+ .filter((r) => r.status !== "skipped")
312
+ .map((r) => r.packetId);
313
+ loopState = {
314
+ ...loopState,
315
+ completed_packet_ids: [...loopState.completed_packet_ids, ...completedIds],
316
+ pending_packet_ids: loopState.pending_packet_ids.filter((id) => !completedIds.includes(id)),
317
+ updated_at: new Date().toISOString(),
318
+ };
319
+ onStateUpdate?.(loopState);
320
+ // Check for failed repair workers → Medic referral.
321
+ const failedWorkers = allWorkerResults.filter((r) => r.status === "failure");
322
+ if (failedWorkers.length > 0) {
323
+ hasMedicReferral = true;
324
+ appendTelemetry(telemetryFile, {
325
+ event: "qc-repair-worker-failures",
326
+ run_id: runId,
327
+ round,
328
+ failed_packet_ids: failedWorkers.map((r) => r.packetId),
329
+ errors: failedWorkers.map((r) => r.errorMessage ?? "unknown"),
330
+ timestamp: new Date().toISOString(),
331
+ });
332
+ }
333
+ if (hasMedicReferral) {
334
+ loopState = { ...loopState, terminal_outcome: "medic-referral", updated_at: new Date().toISOString() };
335
+ onStateUpdate?.(loopState);
336
+ appendTelemetry(telemetryFile, {
337
+ event: "qc-repair-loop-terminal",
338
+ run_id: runId,
339
+ outcome: "medic-referral",
340
+ round,
341
+ failed_count: failedWorkers.length,
342
+ timestamp: new Date().toISOString(),
343
+ });
344
+ await persistQcRepairOutcome(clusterId, repoRoot, "medic-referral");
345
+ return {
346
+ outcome: "medic-referral",
347
+ rounds_completed: roundsCompleted + 1,
348
+ final_qc_results: currentResults,
349
+ loop_state: loopState,
350
+ summary: `QC repair loop: ${failedWorkers.length} repair worker(s) failed at round ${round} — Medic referral triggered`,
351
+ };
352
+ }
353
+ roundsCompleted += 1;
354
+ // ── QC rerun after successful repairs ───────────────────────────────────
355
+ loopState = { ...loopState, rerun_requested: true, updated_at: new Date().toISOString() };
356
+ onStateUpdate?.(loopState);
357
+ appendTelemetry(telemetryFile, {
358
+ event: "qc-repair-rerun-start",
359
+ run_id: runId,
360
+ cluster_id: clusterId,
361
+ round,
362
+ timestamp: new Date().toISOString(),
363
+ });
364
+ const rerunOptions = {
365
+ config,
366
+ registry,
367
+ trigger: "completed-cluster",
368
+ repoRoot,
369
+ runId,
370
+ clusterId,
371
+ branch,
372
+ telemetryFile,
373
+ timeoutMs,
374
+ };
375
+ let rerunResult;
376
+ try {
377
+ rerunResult = await (0, orchestration_js_1.runQcAtTrigger)(rerunOptions);
378
+ }
379
+ catch (err) {
380
+ const msg = err instanceof Error ? err.message : String(err);
381
+ appendTelemetry(telemetryFile, {
382
+ event: "qc-repair-rerun-error",
383
+ run_id: runId,
384
+ round,
385
+ error: msg,
386
+ timestamp: new Date().toISOString(),
387
+ });
388
+ // Treat rerun error as all-providers-failed.
389
+ loopState = { ...loopState, terminal_outcome: "all-providers-failed", updated_at: new Date().toISOString() };
390
+ onStateUpdate?.(loopState);
391
+ return {
392
+ outcome: "all-providers-failed",
393
+ rounds_completed: roundsCompleted,
394
+ final_qc_results: currentResults,
395
+ loop_state: loopState,
396
+ summary: `QC repair loop: rerun at round ${round} threw an error: ${msg}`,
397
+ };
398
+ }
399
+ // Record rerun QC run IDs.
400
+ const rerunIds = rerunResult.results.map((r) => r.qcRunId).filter(Boolean);
401
+ loopState = {
402
+ ...loopState,
403
+ rerun_requested: false,
404
+ rerun_qc_run_ids: { ...loopState.rerun_qc_run_ids, [round]: rerunIds },
405
+ updated_at: new Date().toISOString(),
406
+ };
407
+ onStateUpdate?.(loopState);
408
+ appendTelemetry(telemetryFile, {
409
+ event: "qc-repair-rerun-complete",
410
+ run_id: runId,
411
+ cluster_id: clusterId,
412
+ round,
413
+ action: rerunResult.action,
414
+ summary: rerunResult.summary,
415
+ rerun_qc_run_ids: rerunIds,
416
+ timestamp: new Date().toISOString(),
417
+ });
418
+ currentResults = rerunResult.results;
419
+ // Pass condition: rerun returned no blocking findings.
420
+ if (rerunResult.action === "pass") {
421
+ loopState = { ...loopState, terminal_outcome: "pass", updated_at: new Date().toISOString() };
422
+ onStateUpdate?.(loopState);
423
+ appendTelemetry(telemetryFile, {
424
+ event: "qc-repair-loop-terminal",
425
+ run_id: runId,
426
+ outcome: "pass",
427
+ round,
428
+ timestamp: new Date().toISOString(),
429
+ });
430
+ await persistQcRepairOutcome(clusterId, repoRoot, "pass");
431
+ return {
432
+ outcome: "pass",
433
+ rounds_completed: roundsCompleted,
434
+ final_qc_results: currentResults,
435
+ loop_state: loopState,
436
+ summary: `QC repair loop passed after ${roundsCompleted} round(s)`,
437
+ };
438
+ }
439
+ }
440
+ // ── Max rounds exhausted ──────────────────────────────────────────────────
441
+ loopState = { ...loopState, terminal_outcome: "max-rounds", updated_at: new Date().toISOString() };
442
+ onStateUpdate?.(loopState);
443
+ appendTelemetry(telemetryFile, {
444
+ event: "qc-repair-loop-terminal",
445
+ run_id: runId,
446
+ outcome: "max-rounds",
447
+ rounds_completed: roundsCompleted,
448
+ timestamp: new Date().toISOString(),
449
+ });
450
+ await persistQcRepairOutcome(clusterId, repoRoot, "max-rounds");
451
+ return {
452
+ outcome: "max-rounds",
453
+ rounds_completed: roundsCompleted,
454
+ final_qc_results: currentResults,
455
+ loop_state: loopState,
456
+ summary: `QC repair loop exhausted max rounds (${maxRounds}) without passing`,
457
+ };
458
+ }