pi-spine 2.25.0 → 2.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/spine-review-step.mjs +8 -1
- package/bin/spine-worker-runner.mjs +14 -1
- package/package.json +3 -3
- package/skills/spine-release-operator/SKILL.md +3 -0
- package/src/batch/abort.mjs +74 -38
- package/src/batch/attached-engine-handoff.mjs +2 -2
- package/src/batch/attached-runner-promote.mjs +1 -1
- package/src/batch/attached-runner-reconcile.mjs +1 -1
- package/src/batch/batch-meta-reconstruct.mjs +9 -1
- package/src/batch/batch-state-lock.mjs +173 -31
- package/src/batch/contract-exec.mjs +48 -47
- package/src/batch/contract-parse.mjs +2 -2
- package/src/batch/contract-prelanded.mjs +2 -2
- package/src/batch/contract-spawn.mjs +225 -0
- package/src/batch/contract-verify.mjs +2 -1
- package/src/batch/detached-wait.mjs +1 -1
- package/src/batch/diagnosis-handoff-packet.mjs +74 -0
- package/src/batch/diagnosis-pending-lane.mjs +34 -1
- package/src/batch/engine-lanes/matrix-run.mjs +6 -6
- package/src/batch/engine-lanes/merge.mjs +135 -34
- package/src/batch/engine-lanes/quota-fallback-run.mjs +153 -0
- package/src/batch/engine-lanes/quota-fallback-state.mjs +202 -0
- package/src/batch/engine-lanes/review-code.mjs +1 -0
- package/src/batch/engine-lanes/review-final.mjs +83 -46
- package/src/batch/engine-lanes/review-plan.mjs +22 -2
- package/src/batch/engine-lanes/review-poll.mjs +47 -1
- package/src/batch/engine-lanes.mjs +17 -16
- package/src/batch/engine.mjs +10 -10
- package/src/batch/journal.mjs +15 -0
- package/src/batch/lifecycle-archive.mjs +76 -1
- package/src/batch/lifecycle-cleanup.mjs +110 -0
- package/src/batch/lifecycle.mjs +100 -72
- package/src/batch/metrics.mjs +13 -1
- package/src/batch/parent-session-monitor.mjs +77 -70
- package/src/batch/pause.mjs +92 -25
- package/src/batch/post-merge-limbo.mjs +35 -5
- package/src/batch/provider-quota.mjs +220 -0
- package/src/batch/quota-fallback.mjs +319 -0
- package/src/batch/reconcile-diagnosis-context.mjs +22 -0
- package/src/batch/resume-gate-reopen.mjs +24 -8
- package/src/batch/resume-multi-queue.mjs +25 -10
- package/src/batch/resume-multi.mjs +1 -1
- package/src/batch/resume.mjs +1 -1
- package/src/batch/review-artifacts.mjs +93 -15
- package/src/batch/review-spawn-retry.mjs +106 -0
- package/src/batch/review-spawn.mjs +48 -2
- package/src/batch/review-step-run.mjs +96 -6
- package/src/batch/reviewer-output.mjs +162 -0
- package/src/batch/sequence-run.mjs +26 -8
- package/src/batch/sequence-wait.mjs +87 -8
- package/src/batch/state-guards.mjs +39 -7
- package/src/batch/state-io.mjs +131 -17
- package/src/batch/state.mjs +1 -0
- package/src/batch/worker-host.mjs +81 -7
- package/src/config/cursor-rules/discover.mjs +2 -2
- package/src/config/cursor-rules/match-globs.mjs +6 -4
- package/src/config/defaults.mjs +15 -1
- package/src/config/env-overrides.mjs +41 -4
- package/src/config/preflight/git-batch.mjs +47 -0
- package/src/config/settings-fields.mjs +6 -0
- package/src/config/spine-config-schema.mjs +91 -1
- package/src/doctor/quota-risk.mjs +45 -0
- package/src/fs/atomic-write.mjs +37 -1
- package/src/planner/file-scope.mjs +6 -6
- package/src/tasks/packet/validate-contract.mjs +3 -3
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reviewer re-spawn policy and failure diagnostics for runStepReview (SP-814 / #332).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import {
|
|
8
|
+
NESTED_REVIEW_SPAWN_REASON,
|
|
9
|
+
REVIEW_SPAWN_TIMEOUT_EXIT_CODE,
|
|
10
|
+
REVIEW_TIMEOUT_REASON,
|
|
11
|
+
} from "./review-spawn.mjs";
|
|
12
|
+
import { buildReviewerOutputTail, persistReviewerOutputLog } from "./reviewer-output.mjs";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {import("./reviewer-output.mjs").ReviewerSpawnResult & {
|
|
16
|
+
* honored?: boolean,
|
|
17
|
+
* reason?: string,
|
|
18
|
+
* }} ReviewSpawnAttemptResult
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/** Bounded automatic re-spawn budget for reviewer children (SP-814 / #332). */
|
|
22
|
+
export const REVIEW_SPAWN_MAX_ATTEMPTS = 2;
|
|
23
|
+
|
|
24
|
+
/** `review.spawn_retry` reason when the reviewer exited 0 without an artifact. */
|
|
25
|
+
export const REVIEW_SPAWN_RETRY_REASON_NO_ARTIFACT = "no_artifact";
|
|
26
|
+
|
|
27
|
+
/** `review.spawn_retry` reason fallback for a non-timeout spawn failure. */
|
|
28
|
+
export const REVIEW_SPAWN_RETRY_REASON_SPAWN_FAILED = "spawn_failed";
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A reviewer attempt may be re-spawned once when it exited 0 without writing
|
|
32
|
+
* the artifact, or failed for a reason other than a timeout (exit 124 /
|
|
33
|
+
* `review_timeout`) or the nested-spawn guard — those keep their dedicated
|
|
34
|
+
* honor/skip paths so engine classification is unchanged (SP-814 / #332).
|
|
35
|
+
*
|
|
36
|
+
* @param {object} params
|
|
37
|
+
* @param {ReviewSpawnAttemptResult|null|undefined} params.spawnResult
|
|
38
|
+
* @param {string} params.artifactPath
|
|
39
|
+
* @returns {boolean}
|
|
40
|
+
*/
|
|
41
|
+
export function isReviewSpawnRetryEligible({ spawnResult, artifactPath }) {
|
|
42
|
+
if (!spawnResult || spawnResult.honored) return false;
|
|
43
|
+
if (spawnResult.reason === NESTED_REVIEW_SPAWN_REASON) return false;
|
|
44
|
+
if (spawnResult.reason === REVIEW_TIMEOUT_REASON) return false;
|
|
45
|
+
if (spawnResult.exitCode === REVIEW_SPAWN_TIMEOUT_EXIT_CODE) return false;
|
|
46
|
+
if (spawnResult.spawnFailed) return true;
|
|
47
|
+
return !fs.existsSync(artifactPath);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Persist the reviewer log for a failed attempt when the journal context is
|
|
52
|
+
* available. Log persistence must never fail the review path itself, so a
|
|
53
|
+
* write error degrades to `null` (the journal event still carries outputTail).
|
|
54
|
+
*
|
|
55
|
+
* @param {object} params
|
|
56
|
+
* @param {{ projectRoot?: string, batchId?: string, laneNumber?: number, taskId?: string }|null|undefined} params.journal
|
|
57
|
+
* @param {string} params.taskFolder
|
|
58
|
+
* @param {number} params.stepNumber
|
|
59
|
+
* @param {string} params.reviewType
|
|
60
|
+
* @param {number} params.attempt
|
|
61
|
+
* @param {ReviewSpawnAttemptResult} params.spawnResult
|
|
62
|
+
* @param {object} [params.config]
|
|
63
|
+
* @returns {{ logPath: string, logRef: string }|null}
|
|
64
|
+
*/
|
|
65
|
+
export function persistReviewerLogForAttempt({
|
|
66
|
+
journal,
|
|
67
|
+
taskFolder,
|
|
68
|
+
stepNumber,
|
|
69
|
+
reviewType,
|
|
70
|
+
attempt,
|
|
71
|
+
spawnResult,
|
|
72
|
+
config,
|
|
73
|
+
}) {
|
|
74
|
+
if (!journal?.projectRoot || !journal?.batchId) return null;
|
|
75
|
+
try {
|
|
76
|
+
return persistReviewerOutputLog({
|
|
77
|
+
projectRoot: journal.projectRoot,
|
|
78
|
+
batchId: journal.batchId,
|
|
79
|
+
laneNumber: journal.laneNumber ?? 1,
|
|
80
|
+
taskId: journal.taskId ?? path.basename(taskFolder),
|
|
81
|
+
reviewType,
|
|
82
|
+
stepNumber,
|
|
83
|
+
attempt,
|
|
84
|
+
spawnResult,
|
|
85
|
+
config,
|
|
86
|
+
});
|
|
87
|
+
} catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Diagnostics shared by the `review.failed` payload and the returned result:
|
|
94
|
+
* reviewer duration plus a redacted combined output tail (≤ 2 KB).
|
|
95
|
+
*
|
|
96
|
+
* @param {ReviewSpawnAttemptResult} spawnResult
|
|
97
|
+
* @param {object} [config]
|
|
98
|
+
* @returns {{ durationMs?: number, outputTail?: string }}
|
|
99
|
+
*/
|
|
100
|
+
export function buildSpawnFailureDiagnostics(spawnResult, config) {
|
|
101
|
+
const outputTail = buildReviewerOutputTail(spawnResult, config);
|
|
102
|
+
return {
|
|
103
|
+
...(typeof spawnResult?.durationMs === "number" ? { durationMs: spawnResult.durationMs } : {}),
|
|
104
|
+
...(outputTail ? { outputTail } : {}),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
@@ -13,6 +13,11 @@ import {
|
|
|
13
13
|
resolveReviewerModelPin,
|
|
14
14
|
resolveReviewerThinkingPin,
|
|
15
15
|
} from "../config/agent-model-resolve.mjs";
|
|
16
|
+
import {
|
|
17
|
+
captureWorkerOutputTail,
|
|
18
|
+
redactWorkerOutput,
|
|
19
|
+
resolveWorkerOutputConfig,
|
|
20
|
+
} from "./worker-output.mjs";
|
|
16
21
|
import {
|
|
17
22
|
parseTaskSizeFromFolder,
|
|
18
23
|
resolveReviewArtifactPollIntervalMs,
|
|
@@ -35,6 +40,22 @@ export const DEFAULT_REVIEW_SPAWN_TIMEOUT_MS = 90 * 60 * 1000;
|
|
|
35
40
|
/** Grace period after SIGTERM before SIGKILL on hung reviewer children. */
|
|
36
41
|
const REVIEW_SPAWN_KILL_GRACE_MS = 5_000;
|
|
37
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Append a stdout/stderr chunk while keeping only the trailing `maxBytes` so a
|
|
45
|
+
* chatty reviewer child cannot grow engine memory without bound (SP-814 / #332).
|
|
46
|
+
* Mirrors the worker output tail budget from `resolveWorkerOutputConfig`.
|
|
47
|
+
*
|
|
48
|
+
* @param {string} current
|
|
49
|
+
* @param {string|Buffer} chunk
|
|
50
|
+
* @param {number} maxBytes
|
|
51
|
+
*/
|
|
52
|
+
function appendBoundedCapture(current, chunk, maxBytes) {
|
|
53
|
+
const next = current + String(chunk);
|
|
54
|
+
const encoded = Buffer.from(next, "utf-8");
|
|
55
|
+
if (encoded.byteLength <= maxBytes) return next;
|
|
56
|
+
return encoded.subarray(encoded.byteLength - maxBytes).toString("utf-8");
|
|
57
|
+
}
|
|
58
|
+
|
|
38
59
|
/** Set by {@link buildWorkerChildEnv} when the batch engine launches a pi worker child. */
|
|
39
60
|
export function isActiveWorkerSession() {
|
|
40
61
|
const marker = process.env.SPINE_WORKER_RUNNER;
|
|
@@ -199,6 +220,9 @@ export function spawnReviewerPi({
|
|
|
199
220
|
spawnFailed: true,
|
|
200
221
|
exitCode: 127,
|
|
201
222
|
error: "pi not available for reviewer spawn",
|
|
223
|
+
durationMs: 0,
|
|
224
|
+
stdoutTail: "",
|
|
225
|
+
stderrTail: "",
|
|
202
226
|
});
|
|
203
227
|
}
|
|
204
228
|
|
|
@@ -220,16 +244,21 @@ export function spawnReviewerPi({
|
|
|
220
244
|
});
|
|
221
245
|
const pollIntervalMs = resolveReviewArtifactPollIntervalMs({ config });
|
|
222
246
|
const quiescenceMs = resolveReviewArtifactQuiescenceMs({ config });
|
|
247
|
+
// Reviewer output capture reuses the worker output policy (redaction + tail
|
|
248
|
+
// caps) so spawn diagnostics obey the same conventions as worker logs.
|
|
249
|
+
const outputConfig = resolveWorkerOutputConfig(config);
|
|
223
250
|
/** @type {ArtifactPollState} */
|
|
224
251
|
const artifactPollState = { lastMtimeMs: null, quiescentSinceMs: null };
|
|
225
252
|
|
|
226
253
|
return new Promise((resolve) => {
|
|
254
|
+
const startedAtMs = Date.now();
|
|
227
255
|
const child = spawn("pi", piArgs, {
|
|
228
256
|
cwd: worktreePath || path.dirname(taskFolder),
|
|
229
257
|
env: buildReviewerChildEnv({ taskFolder, worktreePath }),
|
|
230
258
|
stdio: ["ignore", "pipe", "pipe"],
|
|
231
259
|
});
|
|
232
260
|
|
|
261
|
+
let stdout = "";
|
|
233
262
|
let stderr = "";
|
|
234
263
|
let timedOut = false;
|
|
235
264
|
let settled = false;
|
|
@@ -242,7 +271,20 @@ export function spawnReviewerPi({
|
|
|
242
271
|
clearTimeout(timer);
|
|
243
272
|
clearInterval(pollTimer);
|
|
244
273
|
clearTimeout(killTimer);
|
|
245
|
-
|
|
274
|
+
// Every result — including exit 0 — carries capture diagnostics so the
|
|
275
|
+
// engine can journal them when the reviewer produced no artifact.
|
|
276
|
+
resolve({
|
|
277
|
+
durationMs: Date.now() - startedAtMs,
|
|
278
|
+
stdoutTail: captureWorkerOutputTail(
|
|
279
|
+
redactWorkerOutput(stdout, outputConfig),
|
|
280
|
+
outputConfig,
|
|
281
|
+
),
|
|
282
|
+
stderrTail: captureWorkerOutputTail(
|
|
283
|
+
redactWorkerOutput(stderr, outputConfig),
|
|
284
|
+
outputConfig,
|
|
285
|
+
),
|
|
286
|
+
...result,
|
|
287
|
+
});
|
|
246
288
|
};
|
|
247
289
|
|
|
248
290
|
const terminateHungChild = () => {
|
|
@@ -278,8 +320,12 @@ export function spawnReviewerPi({
|
|
|
278
320
|
});
|
|
279
321
|
};
|
|
280
322
|
|
|
323
|
+
child.stdout?.on("data", (chunk) => {
|
|
324
|
+
stdout = appendBoundedCapture(stdout, chunk, outputConfig.maxBytes);
|
|
325
|
+
});
|
|
326
|
+
|
|
281
327
|
child.stderr?.on("data", (chunk) => {
|
|
282
|
-
stderr
|
|
328
|
+
stderr = appendBoundedCapture(stderr, chunk, outputConfig.maxBytes);
|
|
283
329
|
});
|
|
284
330
|
|
|
285
331
|
const pollTimer = setInterval(checkArtifact, pollIntervalMs);
|
|
@@ -13,6 +13,14 @@ import {
|
|
|
13
13
|
shouldBlockNestedReviewerSpawn,
|
|
14
14
|
spawnReviewerPi,
|
|
15
15
|
} from "./review-spawn.mjs";
|
|
16
|
+
import {
|
|
17
|
+
REVIEW_SPAWN_MAX_ATTEMPTS,
|
|
18
|
+
REVIEW_SPAWN_RETRY_REASON_NO_ARTIFACT,
|
|
19
|
+
REVIEW_SPAWN_RETRY_REASON_SPAWN_FAILED,
|
|
20
|
+
buildSpawnFailureDiagnostics,
|
|
21
|
+
isReviewSpawnRetryEligible,
|
|
22
|
+
persistReviewerLogForAttempt,
|
|
23
|
+
} from "./review-spawn-retry.mjs";
|
|
16
24
|
import {
|
|
17
25
|
buildFinalReviewArtifactPath,
|
|
18
26
|
buildReviewArtifactPath,
|
|
@@ -39,6 +47,12 @@ import {
|
|
|
39
47
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
40
48
|
const PACKAGE_ROOT = path.resolve(__dirname, "../..");
|
|
41
49
|
|
|
50
|
+
export {
|
|
51
|
+
REVIEW_SPAWN_MAX_ATTEMPTS,
|
|
52
|
+
REVIEW_SPAWN_RETRY_REASON_NO_ARTIFACT,
|
|
53
|
+
REVIEW_SPAWN_RETRY_REASON_SPAWN_FAILED,
|
|
54
|
+
};
|
|
55
|
+
|
|
42
56
|
/**
|
|
43
57
|
* @param {object} params
|
|
44
58
|
*/
|
|
@@ -213,7 +227,7 @@ export async function runStepReview({
|
|
|
213
227
|
});
|
|
214
228
|
}
|
|
215
229
|
|
|
216
|
-
const
|
|
230
|
+
const spawnParams = {
|
|
217
231
|
worktreePath,
|
|
218
232
|
taskFolder,
|
|
219
233
|
reviewPrompt,
|
|
@@ -222,16 +236,58 @@ export async function runStepReview({
|
|
|
222
236
|
artifactPath,
|
|
223
237
|
reviewType,
|
|
224
238
|
contractVerifyResult,
|
|
225
|
-
}
|
|
239
|
+
};
|
|
240
|
+
let spawnResult = await spawnReviewerPi(spawnParams);
|
|
226
241
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
242
|
+
/** @returns {ReturnType<typeof runStepReview>|null} */
|
|
243
|
+
const completeIfHonored = () =>
|
|
244
|
+
spawnResult.honored && spawnResult.honorReason === ARTIFACT_READY_HONOR_REASON
|
|
245
|
+
? completeReviewFromHonoredArtifact({
|
|
246
|
+
artifactPath: spawnResult.artifactPath ?? artifactPath,
|
|
247
|
+
reviewType,
|
|
248
|
+
journal,
|
|
249
|
+
stepNumber,
|
|
250
|
+
reviewLevel,
|
|
251
|
+
})
|
|
252
|
+
: null;
|
|
253
|
+
|
|
254
|
+
const honoredFirstAttempt = completeIfHonored();
|
|
255
|
+
if (honoredFirstAttempt) return honoredFirstAttempt;
|
|
256
|
+
|
|
257
|
+
// One bounded re-spawn for transient no-artifact exits and non-timeout
|
|
258
|
+
// spawn failures (SP-814 / #332): journal the retry with diagnostics, then
|
|
259
|
+
// spawn again with the same prompt and artifact path.
|
|
260
|
+
let attempt = 1;
|
|
261
|
+
while (
|
|
262
|
+
attempt < REVIEW_SPAWN_MAX_ATTEMPTS &&
|
|
263
|
+
isReviewSpawnRetryEligible({ spawnResult, artifactPath })
|
|
264
|
+
) {
|
|
265
|
+
const failedAttempt = attempt;
|
|
266
|
+
const log = persistReviewerLogForAttempt({
|
|
231
267
|
journal,
|
|
268
|
+
taskFolder,
|
|
232
269
|
stepNumber,
|
|
270
|
+
reviewType,
|
|
271
|
+
attempt: failedAttempt,
|
|
272
|
+
spawnResult,
|
|
273
|
+
config,
|
|
274
|
+
});
|
|
275
|
+
journalReviewEvent("review.spawn_retry", journal, {
|
|
276
|
+
stepNumber,
|
|
277
|
+
reviewType,
|
|
233
278
|
reviewLevel,
|
|
279
|
+
attempt: failedAttempt + 1,
|
|
280
|
+
reason: spawnResult.spawnFailed
|
|
281
|
+
? (spawnResult.reason ?? REVIEW_SPAWN_RETRY_REASON_SPAWN_FAILED)
|
|
282
|
+
: REVIEW_SPAWN_RETRY_REASON_NO_ARTIFACT,
|
|
283
|
+
exitCode: spawnResult.exitCode ?? 0,
|
|
284
|
+
durationMs: spawnResult.durationMs ?? null,
|
|
285
|
+
...(log?.logRef ? { reviewerOutputLogRef: log.logRef } : {}),
|
|
234
286
|
});
|
|
287
|
+
spawnResult = await spawnReviewerPi(spawnParams);
|
|
288
|
+
attempt += 1;
|
|
289
|
+
const honoredRetry = completeIfHonored();
|
|
290
|
+
if (honoredRetry) return honoredRetry;
|
|
235
291
|
}
|
|
236
292
|
|
|
237
293
|
if (spawnResult.spawnFailed) {
|
|
@@ -259,6 +315,19 @@ export async function runStepReview({
|
|
|
259
315
|
return honored;
|
|
260
316
|
}
|
|
261
317
|
|
|
318
|
+
const log = persistReviewerLogForAttempt({
|
|
319
|
+
journal,
|
|
320
|
+
taskFolder,
|
|
321
|
+
stepNumber,
|
|
322
|
+
reviewType,
|
|
323
|
+
attempt,
|
|
324
|
+
spawnResult,
|
|
325
|
+
config,
|
|
326
|
+
});
|
|
327
|
+
const diagnostics = {
|
|
328
|
+
...buildSpawnFailureDiagnostics(spawnResult, config),
|
|
329
|
+
...(log?.logRef ? { reviewerOutputLogRef: log.logRef } : {}),
|
|
330
|
+
};
|
|
262
331
|
journalReviewEvent("review.failed", journal, {
|
|
263
332
|
stepNumber,
|
|
264
333
|
reviewType,
|
|
@@ -267,6 +336,7 @@ export async function runStepReview({
|
|
|
267
336
|
spawnFailed: true,
|
|
268
337
|
exitCode: spawnResult.exitCode,
|
|
269
338
|
...(spawnResult.reason ? { reason: spawnResult.reason } : {}),
|
|
339
|
+
...diagnostics,
|
|
270
340
|
});
|
|
271
341
|
return {
|
|
272
342
|
ok: false,
|
|
@@ -279,17 +349,36 @@ export async function runStepReview({
|
|
|
279
349
|
error: spawnResult.error,
|
|
280
350
|
exitCode: spawnResult.exitCode ?? 1,
|
|
281
351
|
reason: spawnResult.reason,
|
|
352
|
+
...diagnostics,
|
|
282
353
|
};
|
|
283
354
|
}
|
|
284
355
|
|
|
285
356
|
if (!fs.existsSync(artifactPath)) {
|
|
286
357
|
const error = "reviewer exited but produced no artifact";
|
|
358
|
+
const log = persistReviewerLogForAttempt({
|
|
359
|
+
journal,
|
|
360
|
+
taskFolder,
|
|
361
|
+
stepNumber,
|
|
362
|
+
reviewType,
|
|
363
|
+
attempt,
|
|
364
|
+
spawnResult,
|
|
365
|
+
config,
|
|
366
|
+
});
|
|
367
|
+
const diagnostics = {
|
|
368
|
+
...buildSpawnFailureDiagnostics(spawnResult, config),
|
|
369
|
+
...(log?.logRef ? { reviewerOutputLogRef: log.logRef } : {}),
|
|
370
|
+
};
|
|
371
|
+
// The payload carries the reviewer's real exit code (typically 0) while
|
|
372
|
+
// the returned result keeps a non-zero exit code: the CLI and worker
|
|
373
|
+
// tools treat result exit 0 as success and must still fail closed.
|
|
287
374
|
journalReviewEvent("review.failed", journal, {
|
|
288
375
|
stepNumber,
|
|
289
376
|
reviewType,
|
|
290
377
|
reviewLevel,
|
|
291
378
|
error,
|
|
292
379
|
spawnFailed: true,
|
|
380
|
+
exitCode: spawnResult.exitCode ?? 0,
|
|
381
|
+
...diagnostics,
|
|
293
382
|
});
|
|
294
383
|
return {
|
|
295
384
|
ok: false,
|
|
@@ -301,6 +390,7 @@ export async function runStepReview({
|
|
|
301
390
|
spawnFailed: true,
|
|
302
391
|
error,
|
|
303
392
|
exitCode: 1,
|
|
393
|
+
...diagnostics,
|
|
304
394
|
};
|
|
305
395
|
}
|
|
306
396
|
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reviewer output log persistence (SP-814 / #332).
|
|
3
|
+
*
|
|
4
|
+
* Every failed reviewer attempt leaves a bounded, redacted log next to the
|
|
5
|
+
* worker output logs under `.spine/runtime/<batchId>/lanes/lane-<n>/`. The
|
|
6
|
+
* helpers reuse the worker output conventions from `worker-output.mjs`
|
|
7
|
+
* (redaction, tail caps, atomic writes) without modifying that module, which
|
|
8
|
+
* sits at its line-count policy cap.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import fs from "node:fs";
|
|
12
|
+
import path from "node:path";
|
|
13
|
+
import { writeTextAtomic } from "../fs/atomic-write.mjs";
|
|
14
|
+
import {
|
|
15
|
+
captureWorkerOutputTail,
|
|
16
|
+
redactWorkerOutput,
|
|
17
|
+
resolveWorkerOutputConfig,
|
|
18
|
+
} from "./worker-output.mjs";
|
|
19
|
+
|
|
20
|
+
/** Diagnostic output tail budget for `review.failed` payloads (SP-814 / #332). */
|
|
21
|
+
export const REVIEWER_FAILURE_OUTPUT_TAIL_MAX_BYTES = 2048;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Shape of the `spawnReviewerPi` result consumed by the log helpers.
|
|
25
|
+
*
|
|
26
|
+
* @typedef {object} ReviewerSpawnResult
|
|
27
|
+
* @property {boolean} [spawnFailed]
|
|
28
|
+
* @property {number} [exitCode]
|
|
29
|
+
* @property {number} [durationMs]
|
|
30
|
+
* @property {string} [stdoutTail]
|
|
31
|
+
* @property {string} [stderrTail]
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Absolute path of the reviewer output log for one (task, reviewType) pair.
|
|
36
|
+
*
|
|
37
|
+
* @param {string} projectRoot
|
|
38
|
+
* @param {string} batchId
|
|
39
|
+
* @param {number} laneNumber
|
|
40
|
+
* @param {string} taskId
|
|
41
|
+
* @param {string} reviewType
|
|
42
|
+
*/
|
|
43
|
+
export function reviewerOutputLogPath(projectRoot, batchId, laneNumber, taskId, reviewType) {
|
|
44
|
+
return path.join(
|
|
45
|
+
projectRoot,
|
|
46
|
+
".spine",
|
|
47
|
+
"runtime",
|
|
48
|
+
batchId,
|
|
49
|
+
"lanes",
|
|
50
|
+
`lane-${laneNumber}`,
|
|
51
|
+
`reviewer-output-${taskId}-${reviewType}.log`,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Root-relative journal/log reference for the reviewer output log.
|
|
57
|
+
*
|
|
58
|
+
* @param {string} batchId
|
|
59
|
+
* @param {number} laneNumber
|
|
60
|
+
* @param {string} taskId
|
|
61
|
+
* @param {string} reviewType
|
|
62
|
+
*/
|
|
63
|
+
export function reviewerOutputLogRef(batchId, laneNumber, taskId, reviewType) {
|
|
64
|
+
return path.join(
|
|
65
|
+
".spine",
|
|
66
|
+
"runtime",
|
|
67
|
+
batchId,
|
|
68
|
+
"lanes",
|
|
69
|
+
`lane-${laneNumber}`,
|
|
70
|
+
`reviewer-output-${taskId}-${reviewType}.log`,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Combined stderr + stdout diagnostic tail (redacted, ≤ 2 KB) for failure
|
|
76
|
+
* payloads. Stderr leads because reviewer diagnostics conventionally land
|
|
77
|
+
* there; stdout follows so silent reviewer exits stay explainable.
|
|
78
|
+
*
|
|
79
|
+
* @param {ReviewerSpawnResult} spawnResult Result from `spawnReviewerPi`.
|
|
80
|
+
* @param {object} [config]
|
|
81
|
+
*/
|
|
82
|
+
export function buildReviewerOutputTail(spawnResult, config = {}) {
|
|
83
|
+
const outputConfig = resolveWorkerOutputConfig(config);
|
|
84
|
+
const stderrTail = redactWorkerOutput(spawnResult?.stderrTail ?? "", outputConfig).trim();
|
|
85
|
+
const stdoutTail = redactWorkerOutput(spawnResult?.stdoutTail ?? "", outputConfig).trim();
|
|
86
|
+
|
|
87
|
+
const parts = [];
|
|
88
|
+
if (stderrTail) parts.push(`--- stderr ---\n${stderrTail}`);
|
|
89
|
+
if (stdoutTail) parts.push(`--- stdout ---\n${stdoutTail}`);
|
|
90
|
+
const joined = parts.join("\n");
|
|
91
|
+
if (!joined) return "";
|
|
92
|
+
|
|
93
|
+
const tailConfig = { ...outputConfig, maxBytes: REVIEWER_FAILURE_OUTPUT_TAIL_MAX_BYTES };
|
|
94
|
+
return captureWorkerOutputTail(joined, tailConfig);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Append one redacted, tail-capped attempt section to the reviewer log for a
|
|
99
|
+
* (task, reviewType) pair. One file per pair: attempts append so a re-spawn
|
|
100
|
+
* never erases the previous attempt's diagnostics.
|
|
101
|
+
*
|
|
102
|
+
* @param {object} params
|
|
103
|
+
* @param {string} params.projectRoot
|
|
104
|
+
* @param {string} params.batchId
|
|
105
|
+
* @param {number} params.laneNumber
|
|
106
|
+
* @param {string} params.taskId
|
|
107
|
+
* @param {string} params.reviewType
|
|
108
|
+
* @param {number|null} [params.stepNumber]
|
|
109
|
+
* @param {number} [params.attempt]
|
|
110
|
+
* @param {ReviewerSpawnResult} [params.spawnResult] Result from `spawnReviewerPi`.
|
|
111
|
+
* @param {object} [params.config]
|
|
112
|
+
* @returns {{ logPath: string, logRef: string }|null}
|
|
113
|
+
*/
|
|
114
|
+
export function persistReviewerOutputLog({
|
|
115
|
+
projectRoot,
|
|
116
|
+
batchId,
|
|
117
|
+
laneNumber,
|
|
118
|
+
taskId,
|
|
119
|
+
reviewType,
|
|
120
|
+
stepNumber = null,
|
|
121
|
+
attempt = 1,
|
|
122
|
+
spawnResult = {},
|
|
123
|
+
config = {},
|
|
124
|
+
}) {
|
|
125
|
+
const outputConfig = resolveWorkerOutputConfig(config);
|
|
126
|
+
const stderrTail = captureWorkerOutputTail(
|
|
127
|
+
redactWorkerOutput(spawnResult.stderrTail ?? "", outputConfig),
|
|
128
|
+
outputConfig,
|
|
129
|
+
);
|
|
130
|
+
const stdoutTail = captureWorkerOutputTail(
|
|
131
|
+
redactWorkerOutput(spawnResult.stdoutTail ?? "", outputConfig),
|
|
132
|
+
outputConfig,
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
const header = [
|
|
136
|
+
`# reviewer attempt ${attempt} — ${new Date().toISOString()}`,
|
|
137
|
+
`taskId=${taskId} reviewType=${reviewType} step=${stepNumber ?? "?"}`,
|
|
138
|
+
`spawnFailed=${spawnResult.spawnFailed === true} exitCode=${
|
|
139
|
+
spawnResult.exitCode ?? "null"
|
|
140
|
+
} durationMs=${spawnResult.durationMs ?? "null"}`,
|
|
141
|
+
].join("\n");
|
|
142
|
+
const section = [
|
|
143
|
+
header,
|
|
144
|
+
"--- stderr ---",
|
|
145
|
+
stderrTail.trim() || "(empty)",
|
|
146
|
+
"--- stdout ---",
|
|
147
|
+
stdoutTail.trim() || "(empty)",
|
|
148
|
+
].join("\n");
|
|
149
|
+
|
|
150
|
+
const logPath = reviewerOutputLogPath(projectRoot, batchId, laneNumber, taskId, reviewType);
|
|
151
|
+
let previous = "";
|
|
152
|
+
if (fs.existsSync(logPath)) {
|
|
153
|
+
previous = fs.readFileSync(logPath, "utf-8").trim();
|
|
154
|
+
}
|
|
155
|
+
const content = previous ? `${previous}\n\n${section}\n` : `${section}\n`;
|
|
156
|
+
writeTextAtomic(logPath, content);
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
logPath,
|
|
160
|
+
logRef: reviewerOutputLogRef(batchId, laneNumber, taskId, reviewType),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { loadSpineConfig } from "../config/spine-config-load.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
resolveSequenceMaxWaitMs,
|
|
8
|
+
resolveSequencePollMs,
|
|
9
|
+
resolveSequenceStallMs,
|
|
10
|
+
} from "../config/spine-config-schema.mjs";
|
|
7
11
|
import {
|
|
8
12
|
formatPreflightHuman,
|
|
9
13
|
runBatchPreflight,
|
|
@@ -67,6 +71,8 @@ export async function runSequence(ctx) {
|
|
|
67
71
|
profile: profileOverride = null,
|
|
68
72
|
pollIntervalMs: pollIntervalMsOverride,
|
|
69
73
|
timeoutMs = 120_000,
|
|
74
|
+
maxWaitMs: maxWaitMsOverride,
|
|
75
|
+
stallMs: stallMsOverride,
|
|
70
76
|
spineBin = null,
|
|
71
77
|
startBatchFn = startBatch,
|
|
72
78
|
} = ctx;
|
|
@@ -77,6 +83,12 @@ export async function runSequence(ctx) {
|
|
|
77
83
|
const pollIntervalMs =
|
|
78
84
|
pollIntervalMsOverride ??
|
|
79
85
|
resolveSequencePollMs({ config: configResult.config ?? {} });
|
|
86
|
+
const maxWaitMs =
|
|
87
|
+
maxWaitMsOverride ??
|
|
88
|
+
resolveSequenceMaxWaitMs({ config: configResult.config ?? {} });
|
|
89
|
+
const stallMs =
|
|
90
|
+
stallMsOverride ??
|
|
91
|
+
resolveSequenceStallMs({ config: configResult.config ?? {} });
|
|
80
92
|
|
|
81
93
|
let sequenceState = null;
|
|
82
94
|
let effectiveFromWave = fromWave;
|
|
@@ -334,7 +346,7 @@ export async function runSequence(ctx) {
|
|
|
334
346
|
batchId,
|
|
335
347
|
diagnosis: reconcileBatch({ projectRoot }).diagnosis ?? null,
|
|
336
348
|
}
|
|
337
|
-
: await waitForSequenceBatchTerminal({ projectRoot, pollIntervalMs, timeoutMs, enginePid: detachedEnginePid ?? null });
|
|
349
|
+
: await waitForSequenceBatchTerminal({ projectRoot, pollIntervalMs, timeoutMs, maxWaitMs, stallMs, enginePid: detachedEnginePid ?? null });
|
|
338
350
|
|
|
339
351
|
if (!wait.ok || isSequenceBatchFailure(wait.diagnosis)) {
|
|
340
352
|
const reconciliation = wait.reconciliation ?? reconcileBatch({ projectRoot });
|
|
@@ -347,13 +359,19 @@ export async function runSequence(ctx) {
|
|
|
347
359
|
continue;
|
|
348
360
|
}
|
|
349
361
|
if (!stopOnFailure) continue;
|
|
350
|
-
return haltSequenceAndPersist(
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
diagnosis: wait.diagnosis ?? null,
|
|
354
|
-
batchId: wait.batchId ?? batchId,
|
|
362
|
+
return haltSequenceAndPersist(
|
|
363
|
+
projectRoot,
|
|
364
|
+
sequenceState,
|
|
355
365
|
completedWaves,
|
|
356
|
-
|
|
366
|
+
{
|
|
367
|
+
waveIndex: wave.waveIndex,
|
|
368
|
+
error: wait.error ?? "batch_failed",
|
|
369
|
+
diagnosis: wait.diagnosis ?? null,
|
|
370
|
+
batchId: wait.batchId ?? batchId,
|
|
371
|
+
completedWaves,
|
|
372
|
+
},
|
|
373
|
+
wait.suggestedCommand ? { suggestedCommand: wait.suggestedCommand } : {},
|
|
374
|
+
);
|
|
357
375
|
}
|
|
358
376
|
|
|
359
377
|
const land = runSequenceWaveLandLoop({ projectRoot, batchId: wait.batchId ?? batchId, autoApproveGate });
|