pi-spine 2.0.0 → 2.2.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/bin/spine-batch.mjs +74 -5
- package/bin/spine-cleanup.mjs +89 -0
- package/bin/spine-cli/verify.mjs +1 -0
- package/bin/spine-doctor.mjs +8 -0
- package/bin/spine.mjs +13 -0
- package/package.json +4 -1
- package/skills/create-spine-tasks/SKILL.md +28 -0
- package/skills/create-spine-tasks/references/contract-template.md +11 -0
- package/skills/create-spine-tasks/references/prompt-template.md +7 -1
- package/skills/spine-autonomous-operator/SKILL.md +19 -3
- package/skills/spine-autonomous-operator/references/agent-shell-batch-policy.md +18 -0
- package/skills/spine-orchestrate-waves/SKILL.md +9 -2
- package/skills/spine-orchestrate-waves/references/outer-loop.md +24 -2
- package/skills/spine-release-operator/SKILL.md +25 -2
- package/skills/spine-release-operator/references/post-integrate-regression-gate.md +96 -0
- package/skills/spine-release-operator/references/release-manifest-template.md +7 -3
- package/src/batch/abort.mjs +10 -14
- package/src/batch/attached-runner.mjs +12 -1
- package/src/batch/diagnosis-merge-failure.mjs +66 -0
- package/src/batch/diagnosis-parent-exit.mjs +125 -0
- package/src/batch/diagnosis.mjs +26 -73
- package/src/batch/engine-lanes/merge.mjs +25 -0
- package/src/batch/journal-rebuild.mjs +80 -1
- package/src/batch/lane-dirty-check.mjs +10 -0
- package/src/batch/lifecycle.mjs +1 -18
- package/src/batch/reconcile.mjs +11 -0
- package/src/batch/resume-multi-lanes.mjs +38 -1
- package/src/batch/review.mjs +20 -0
- package/src/batch/salvage-batch.mjs +691 -0
- package/src/batch/worktree.mjs +130 -1
- package/src/config/preflight/git-batch.mjs +14 -3
- package/src/doctor/duplicate-install.mjs +148 -0
- package/src/doctor/pi-cli-resolution.mjs +222 -0
- package/src/doctor/run-doctor-checks.mjs +4 -0
- package/src/doctor/stale-worktrees.mjs +1 -1
- package/src/tasks/packet/parse-prompt.mjs +29 -0
package/src/batch/diagnosis.mjs
CHANGED
|
@@ -15,11 +15,17 @@ import { buildAlternatives } from "./diagnosis-alternatives.mjs";
|
|
|
15
15
|
export { buildAlternatives } from "./diagnosis-alternatives.mjs";
|
|
16
16
|
import {
|
|
17
17
|
buildMergeFailureHeadline,
|
|
18
|
+
buildGitignoredMergeRepairCommand,
|
|
19
|
+
} from "./diagnosis-merge-failure.mjs";
|
|
20
|
+
export {
|
|
21
|
+
buildMergeFailureHeadline,
|
|
22
|
+
buildGitignoredMergeRepairCommand,
|
|
23
|
+
inferMergeGitignoredFailure,
|
|
24
|
+
summarizeMergeFailures,
|
|
18
25
|
} from "./diagnosis-merge-failure.mjs";
|
|
19
|
-
export { buildMergeFailureHeadline, summarizeMergeFailures } from "./diagnosis-merge-failure.mjs";
|
|
20
26
|
import { buildRunningTailHeadline } from "./diagnosis-tail-state.mjs";
|
|
21
27
|
export { buildRunningTailHeadline, isRunningWithoutActiveWorkers } from "./diagnosis-tail-state.mjs";
|
|
22
|
-
export { findLatestReviewHonorSignal } from "./review.mjs";
|
|
28
|
+
export { buildReviewHonorHeadlineSuffix, findLatestReviewHonorSignal } from "./review.mjs";
|
|
23
29
|
import {
|
|
24
30
|
buildStubFailureHeadline,
|
|
25
31
|
buildStubFailureSuggestedCommand,
|
|
@@ -36,6 +42,16 @@ import {
|
|
|
36
42
|
buildPrimaryFailureHeadline,
|
|
37
43
|
buildPrimaryFailureSuggestedCommand,
|
|
38
44
|
} from "./diagnosis-primary-failure.mjs";
|
|
45
|
+
import {
|
|
46
|
+
buildEngineOrphanParentExitHeadline,
|
|
47
|
+
buildEngineOrphanParentExitSuggestedCommand,
|
|
48
|
+
} from "./diagnosis-parent-exit.mjs";
|
|
49
|
+
export {
|
|
50
|
+
inferEngineOrphanCause,
|
|
51
|
+
journalHasEngineCrash,
|
|
52
|
+
journalIndicatesParentExit,
|
|
53
|
+
} from "./diagnosis-parent-exit.mjs";
|
|
54
|
+
import { buildReviewHonorHeadlineSuffix } from "./review.mjs";
|
|
39
55
|
export { inferLaunchFailureFromWorkerOutputTail, inferLaunchFailureKind } from "./diagnosis-launch-failure.mjs";
|
|
40
56
|
|
|
41
57
|
const INVALID_BARE_RETRY_FORCE = /^spine batch retry --force$/;
|
|
@@ -84,7 +100,6 @@ const NO_PAUSE_DIAGNOSES = new Set([
|
|
|
84
100
|
"engine_orphaned",
|
|
85
101
|
"integrate_isolated_ok",
|
|
86
102
|
]);
|
|
87
|
-
const GITIGNORED_MERGE_FAILURE_CLASSES = new Set(["merge_failed_gitignored", "GitignoredDirtyWorktree"]);
|
|
88
103
|
const REVIEW_SPAWN_FAILURE_EXIT_REASONS = new Set([
|
|
89
104
|
"code_review_spawn_failed",
|
|
90
105
|
"code_review_timeout",
|
|
@@ -92,74 +107,6 @@ const REVIEW_SPAWN_FAILURE_EXIT_REASONS = new Set([
|
|
|
92
107
|
"final_review_timeout",
|
|
93
108
|
]);
|
|
94
109
|
|
|
95
|
-
/**
|
|
96
|
-
* @param {object|null|undefined} reviewHonorSignal
|
|
97
|
-
* @returns {string|null}
|
|
98
|
-
*/
|
|
99
|
-
export function buildReviewHonorHeadlineSuffix(reviewHonorSignal) {
|
|
100
|
-
if (!reviewHonorSignal?.kind) return null;
|
|
101
|
-
const reviewLabel =
|
|
102
|
-
reviewHonorSignal.reviewType === "final" ? "final review" : "code review";
|
|
103
|
-
if (reviewHonorSignal.kind === "review.crash_recovered") {
|
|
104
|
-
return `recovered ${reviewLabel} crash — prior verdict honored from ${reviewHonorSignal.honorSource ?? "artifact"}`;
|
|
105
|
-
}
|
|
106
|
-
if (reviewHonorSignal.kind === "review.skipped_fresh_artifact") {
|
|
107
|
-
return `skipped redundant ${reviewLabel} — fresh artifact honored`;
|
|
108
|
-
}
|
|
109
|
-
if (reviewHonorSignal.kind === "review.resumed") {
|
|
110
|
-
return `${reviewLabel} resumed after operator retry`;
|
|
111
|
-
}
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* @param {object} [ctx]
|
|
117
|
-
* @param {string|null} [ctx.exitReason]
|
|
118
|
-
* @param {string|null} [ctx.failureClass]
|
|
119
|
-
* @param {string|null} [ctx.lastError]
|
|
120
|
-
* @param {object[]} [ctx.journalEvents]
|
|
121
|
-
* @returns {boolean}
|
|
122
|
-
*/
|
|
123
|
-
export function inferMergeGitignoredFailure(ctx = {}) {
|
|
124
|
-
const { exitReason, failureClass, lastError, journalEvents } = ctx;
|
|
125
|
-
if (GITIGNORED_MERGE_FAILURE_CLASSES.has(exitReason ?? "")) return true;
|
|
126
|
-
if (GITIGNORED_MERGE_FAILURE_CLASSES.has(failureClass ?? "")) return true;
|
|
127
|
-
|
|
128
|
-
const haystackParts = [exitReason, failureClass, lastError];
|
|
129
|
-
if (Array.isArray(journalEvents)) {
|
|
130
|
-
for (const event of journalEvents) {
|
|
131
|
-
if (event.type !== "batch.merge_failed" && event.type !== "task.failed") continue;
|
|
132
|
-
const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
|
|
133
|
-
haystackParts.push(
|
|
134
|
-
payload.failureClass,
|
|
135
|
-
payload.classification,
|
|
136
|
-
payload.error,
|
|
137
|
-
payload.output,
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
const haystack = haystackParts.filter(Boolean).join("\n").toLowerCase();
|
|
142
|
-
return (
|
|
143
|
-
haystack.includes("gitignored dirty files only") ||
|
|
144
|
-
haystack.includes("merge_failed_gitignored") ||
|
|
145
|
-
haystack.includes("gitignoreddirtyworktree") ||
|
|
146
|
-
(haystack.includes("git add") && haystack.includes("ignored"))
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* @param {string|null|undefined} taskBranch
|
|
152
|
-
* @param {string[]|null|undefined} gitignoredPaths
|
|
153
|
-
*/
|
|
154
|
-
export function buildGitignoredMergeRepairCommand(taskBranch, gitignoredPaths) {
|
|
155
|
-
const branchHint = taskBranch ? `git checkout ${taskBranch}` : "git checkout <task-branch>";
|
|
156
|
-
const pathHint =
|
|
157
|
-
Array.isArray(gitignoredPaths) && gitignoredPaths.length > 0
|
|
158
|
-
? `git rm -r --cached -- ${gitignoredPaths.slice(0, 5).join(" ")}`
|
|
159
|
-
: "git rm -r --cached -- <gitignored-paths>";
|
|
160
|
-
return `${branchHint} && ${pathHint} && spine batch resume --force`;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
110
|
/**
|
|
164
111
|
* @param {string} diagnosis
|
|
165
112
|
* @param {object} [ctx]
|
|
@@ -249,10 +196,13 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
|
|
|
249
196
|
: "spine batch abort";
|
|
250
197
|
case "worker_done_missing":
|
|
251
198
|
return buildWorkerDoneMissingSuggestedCommand(ctx);
|
|
252
|
-
case "engine_orphaned":
|
|
199
|
+
case "engine_orphaned": {
|
|
200
|
+
const parentExitCommand = buildEngineOrphanParentExitSuggestedCommand(ctx);
|
|
201
|
+
if (parentExitCommand) return parentExitCommand;
|
|
253
202
|
return ctx.failedTaskId
|
|
254
203
|
? `spine batch retry ${ctx.failedTaskId}`
|
|
255
204
|
: "spine batch resume --attached";
|
|
205
|
+
}
|
|
256
206
|
case "needs_merge":
|
|
257
207
|
return "/spine-resume --force";
|
|
258
208
|
case "needs_integrate":
|
|
@@ -391,10 +341,13 @@ export function buildHeadline(diagnosis, ctx = {}) {
|
|
|
391
341
|
: `${batchLabel} lane worker orphaned — retry or abort`;
|
|
392
342
|
case "worker_done_missing":
|
|
393
343
|
return buildWorkerDoneMissingHeadline(batchLabel, ctx);
|
|
394
|
-
case "engine_orphaned":
|
|
344
|
+
case "engine_orphaned": {
|
|
345
|
+
const parentExitHeadline = buildEngineOrphanParentExitHeadline(batchLabel, ctx);
|
|
346
|
+
if (parentExitHeadline) return parentExitHeadline;
|
|
395
347
|
return ctx.failedTaskId
|
|
396
348
|
? `${batchLabel} engine died mid-run (task ${ctx.failedTaskId} still running) — retry or abort`
|
|
397
349
|
: `${batchLabel} batch engine died while running — retry or abort`;
|
|
350
|
+
}
|
|
398
351
|
case "needs_merge":
|
|
399
352
|
if (ctx.mergeGitignoredFailure) {
|
|
400
353
|
return `${batchLabel} merge blocked by gitignored paths committed on a lane branch`;
|
|
@@ -31,6 +31,7 @@ import { maybeFinalizeAfterWaveMerge } from "../post-merge-limbo.mjs";
|
|
|
31
31
|
import { saveSpineBatchState } from "../state.mjs";
|
|
32
32
|
import { loadTaskFileScopePaths } from "./queue.mjs";
|
|
33
33
|
import { laneTaskBranch } from "../worktree.mjs";
|
|
34
|
+
import { laneDoneMarkerCommittedOnBranch, normalizeTaskFolderRel } from "../journal-rebuild.mjs";
|
|
34
35
|
|
|
35
36
|
/**
|
|
36
37
|
* @param {string} projectRoot
|
|
@@ -486,6 +487,7 @@ export function mergeLaneToOrch({
|
|
|
486
487
|
batchId,
|
|
487
488
|
requireLaneCommits = false,
|
|
488
489
|
laneFileScopePaths = [],
|
|
490
|
+
laneTaskFolders = [],
|
|
489
491
|
waveIndex,
|
|
490
492
|
}) {
|
|
491
493
|
const previous = gitStrict(projectRoot, ["rev-parse", "--abbrev-ref", "HEAD"]);
|
|
@@ -503,6 +505,21 @@ export function mergeLaneToOrch({
|
|
|
503
505
|
const orchHeadBefore = gitStrict(projectRoot, ["rev-parse", orchBranch]);
|
|
504
506
|
const commitsAhead = countCommitsAhead(projectRoot, orchBranch, taskBranch);
|
|
505
507
|
|
|
508
|
+
if (Array.isArray(laneTaskFolders) && laneTaskFolders.length > 0) {
|
|
509
|
+
for (const taskFolderRel of laneTaskFolders) {
|
|
510
|
+
if (laneDoneMarkerCommittedOnBranch(projectRoot, taskBranch, taskFolderRel)) {
|
|
511
|
+
continue;
|
|
512
|
+
}
|
|
513
|
+
return {
|
|
514
|
+
ok: false,
|
|
515
|
+
failureClass: "DoneMarkerMissing",
|
|
516
|
+
error:
|
|
517
|
+
`Task branch ${taskBranch} lacks committed ${normalizeTaskFolderRel(projectRoot, taskFolderRel) ?? taskFolderRel}/.DONE. ` +
|
|
518
|
+
"Worker must create .DONE on the lane branch before merge.",
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
506
523
|
if (requireLaneCommits && commitsAhead === 0) {
|
|
507
524
|
return {
|
|
508
525
|
ok: false,
|
|
@@ -628,6 +645,13 @@ export async function mergeWaveLanesToOrch({
|
|
|
628
645
|
|
|
629
646
|
const taskBranch = lane.branch ?? laneTaskBranch(batchId, laneNumber);
|
|
630
647
|
const laneFileScopePaths = collectLaneWaveFileScope(state, laneNumber, waveTaskIds);
|
|
648
|
+
const laneTaskFolders = waveTaskIds
|
|
649
|
+
.map((taskId) => {
|
|
650
|
+
const task = (state.tasks ?? []).find((entry) => entry?.taskId === taskId);
|
|
651
|
+
if (!task || task.laneNumber !== laneNumber || !task.taskFolder) return null;
|
|
652
|
+
return task.taskFolder;
|
|
653
|
+
})
|
|
654
|
+
.filter(Boolean);
|
|
631
655
|
appendJournalEvent(projectRoot, batchId, "batch.merge_started", {
|
|
632
656
|
taskBranch,
|
|
633
657
|
orchBranch,
|
|
@@ -644,6 +668,7 @@ export async function mergeWaveLanesToOrch({
|
|
|
644
668
|
batchId,
|
|
645
669
|
requireLaneCommits: false,
|
|
646
670
|
laneFileScopePaths,
|
|
671
|
+
laneTaskFolders,
|
|
647
672
|
waveIndex,
|
|
648
673
|
});
|
|
649
674
|
if (!merge.ok) {
|
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import fs from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { execFileSync } from "node:child_process";
|
|
7
9
|
import { appendJournalEvent, readJournalEvents, STRUCTURAL_JOURNAL_EVENT_TYPES } from "./journal.mjs";
|
|
10
|
+
import { laneTaskBranch } from "./worktree.mjs";
|
|
8
11
|
import { parseReviewVerdict } from "./review-shared.mjs";
|
|
9
12
|
import { journalHasTaskCompleted } from "./resume-common.mjs";
|
|
10
13
|
import {
|
|
@@ -390,6 +393,72 @@ function classifiedShowsDoneInLaneDrift(classified) {
|
|
|
390
393
|
);
|
|
391
394
|
}
|
|
392
395
|
|
|
396
|
+
export function normalizeTaskFolderRel(projectRoot, taskFolder) {
|
|
397
|
+
if (!taskFolder) return null;
|
|
398
|
+
if (path.isAbsolute(taskFolder)) {
|
|
399
|
+
return path.relative(projectRoot, taskFolder).replace(/\\/g, "/");
|
|
400
|
+
}
|
|
401
|
+
return String(taskFolder).replace(/\\/g, "/");
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* True when `.DONE` is committed on the lane task branch (fail-closed / #190).
|
|
406
|
+
*
|
|
407
|
+
* @param {string} projectRoot
|
|
408
|
+
* @param {string} taskBranch
|
|
409
|
+
* @param {string} taskFolderRel
|
|
410
|
+
*/
|
|
411
|
+
export function laneDoneMarkerCommittedOnBranch(projectRoot, taskBranch, taskFolderRel) {
|
|
412
|
+
const folderRel = normalizeTaskFolderRel(projectRoot, taskFolderRel);
|
|
413
|
+
if (!projectRoot || !taskBranch || !folderRel) return false;
|
|
414
|
+
const donePath = `${folderRel.replace(/\/+$/, "")}/.DONE`;
|
|
415
|
+
try {
|
|
416
|
+
execFileSync("git", ["cat-file", "-e", `${taskBranch}:${donePath}`], {
|
|
417
|
+
cwd: projectRoot,
|
|
418
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
419
|
+
timeout: 5000,
|
|
420
|
+
});
|
|
421
|
+
return true;
|
|
422
|
+
} catch {
|
|
423
|
+
return false;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* @param {object} task
|
|
429
|
+
* @param {string} batchId
|
|
430
|
+
* @param {unknown[]} lanes
|
|
431
|
+
* @param {string} projectRoot
|
|
432
|
+
*/
|
|
433
|
+
function laneTaskBranchForTask(task, batchId, lanes) {
|
|
434
|
+
const laneNumber = Number(task.laneNumber ?? 1);
|
|
435
|
+
const lane = Array.isArray(lanes)
|
|
436
|
+
? lanes.find((entry) => Number(entry?.laneNumber) === laneNumber)
|
|
437
|
+
: null;
|
|
438
|
+
if (lane && typeof lane.branch === "string" && lane.branch) {
|
|
439
|
+
return lane.branch;
|
|
440
|
+
}
|
|
441
|
+
return laneTaskBranch(batchId, laneNumber);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Fail-closed gate: filesystem `.DONE` in lane worktree and committed on lane branch.
|
|
446
|
+
*
|
|
447
|
+
* @param {object} params
|
|
448
|
+
* @param {string} params.projectRoot
|
|
449
|
+
* @param {string} params.batchId
|
|
450
|
+
* @param {object} params.task
|
|
451
|
+
* @param {unknown[]} [params.lanes]
|
|
452
|
+
* @param {object|null|undefined} params.classified
|
|
453
|
+
*/
|
|
454
|
+
export function laneDoneMarkerReadyForPromote({ projectRoot, batchId, task, lanes = [], classified }) {
|
|
455
|
+
if (classified?.doneInLane !== true) return false;
|
|
456
|
+
const taskFolder = normalizeTaskFolderRel(projectRoot, task?.taskFolder);
|
|
457
|
+
if (!taskFolder) return false;
|
|
458
|
+
const taskBranch = laneTaskBranchForTask(task, batchId, lanes);
|
|
459
|
+
return laneDoneMarkerCommittedOnBranch(projectRoot, taskBranch, taskFolder);
|
|
460
|
+
}
|
|
461
|
+
|
|
393
462
|
/**
|
|
394
463
|
* Detect review.started events that have no matching review.completed for the same
|
|
395
464
|
* taskId + reviewType. These represent engine crashes mid-review where the artifact
|
|
@@ -634,7 +703,17 @@ export function reconcileBatchStateDrift({
|
|
|
634
703
|
|
|
635
704
|
const classified = classifiedById.get(taskId);
|
|
636
705
|
if (!classifiedShowsDoneInLaneDrift(classified)) continue;
|
|
637
|
-
if (
|
|
706
|
+
if (
|
|
707
|
+
!laneDoneMarkerReadyForPromote({
|
|
708
|
+
projectRoot,
|
|
709
|
+
batchId,
|
|
710
|
+
task,
|
|
711
|
+
lanes: state.lanes ?? [],
|
|
712
|
+
classified,
|
|
713
|
+
})
|
|
714
|
+
) {
|
|
715
|
+
continue;
|
|
716
|
+
}
|
|
638
717
|
if (journalHasTaskCompleted(journalEvents, taskId)) continue;
|
|
639
718
|
if (!journalShowsDoneInLaneTerminalArtifacts(journalEvents, taskId)) continue;
|
|
640
719
|
if (String(task.status ?? "") === "succeeded") continue;
|
|
@@ -32,6 +32,10 @@ export const GITIGNORED_ARTIFACT_MARKERS = [
|
|
|
32
32
|
"__pycache__/",
|
|
33
33
|
"/graphify-out/",
|
|
34
34
|
"graphify-out/",
|
|
35
|
+
"/.review/",
|
|
36
|
+
".review/",
|
|
37
|
+
"/.spine/runtime/",
|
|
38
|
+
".spine/runtime/",
|
|
35
39
|
];
|
|
36
40
|
|
|
37
41
|
/** Flutter build output dir that can pollute unscoped `flutter analyze` (#78). */
|
|
@@ -516,6 +520,12 @@ function gitignoredArtifactRootForPath(filePath) {
|
|
|
516
520
|
if (normalized === "graphify-out" || normalized.startsWith("graphify-out/")) {
|
|
517
521
|
return "graphify-out";
|
|
518
522
|
}
|
|
523
|
+
if (normalized === ".review" || normalized.startsWith(".review/")) {
|
|
524
|
+
return ".review";
|
|
525
|
+
}
|
|
526
|
+
if (normalized === ".spine/runtime" || normalized.startsWith(".spine/runtime/")) {
|
|
527
|
+
return ".spine/runtime";
|
|
528
|
+
}
|
|
519
529
|
return null;
|
|
520
530
|
}
|
|
521
531
|
|
package/src/batch/lifecycle.mjs
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
readAliveBatchEnginePid,
|
|
19
19
|
} from "./batch-state-io.mjs";
|
|
20
20
|
import { terminateLaneWorkers } from "./worker-host.mjs";
|
|
21
|
-
import { removeLaneWorktrees } from "./worktree.mjs";
|
|
21
|
+
import { removeLaneWorktrees, maxLaneNumberFromBatchState } from "./worktree.mjs";
|
|
22
22
|
import { terminateSupervisorIfRunning } from "./supervisor-spawn.mjs";
|
|
23
23
|
import { bumpDashboardInvalidateSignal } from "../dashboard/cache-invalidate.mjs";
|
|
24
24
|
|
|
@@ -117,23 +117,6 @@ function clearCompletedBatchState(batchStatePath, batchId) {
|
|
|
117
117
|
clearActiveBatchStateIfMatches(batchStatePath, batchId);
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
/**
|
|
121
|
-
* @param {unknown} raw
|
|
122
|
-
*/
|
|
123
|
-
function maxLaneNumberFromBatchState(raw) {
|
|
124
|
-
const lanes = /** @type {{ lanes?: unknown }} */ (raw)?.lanes;
|
|
125
|
-
if (!Array.isArray(lanes) || lanes.length === 0) return 1;
|
|
126
|
-
let max = 1;
|
|
127
|
-
for (const lane of lanes) {
|
|
128
|
-
if (!lane || typeof lane !== "object") continue;
|
|
129
|
-
const laneNumber = Number(/** @type {{ laneNumber?: number }} */ (lane).laneNumber);
|
|
130
|
-
if (Number.isFinite(laneNumber) && laneNumber > max) {
|
|
131
|
-
max = laneNumber;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return max;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
120
|
/**
|
|
138
121
|
* @param {object|null|undefined} config
|
|
139
122
|
*/
|
package/src/batch/reconcile.mjs
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
import { findLatestReviewHonorSignal } from "./review.mjs";
|
|
24
24
|
import { summarizeMergeFailures } from "./diagnosis-merge-failure.mjs";
|
|
25
25
|
import { inferWorkerDoneMissingFailure } from "./diagnosis-worker-done-missing.mjs";
|
|
26
|
+
import { inferEngineOrphanCause } from "./diagnosis-parent-exit.mjs";
|
|
26
27
|
import {
|
|
27
28
|
findStubMarkedSucceededTask,
|
|
28
29
|
inferStubExitReasonForTask,
|
|
@@ -1434,6 +1435,14 @@ export function reconcileBatch(ctx, _lightRetry = false) {
|
|
|
1434
1435
|
signals.reviewHonor = reviewHonorSignal;
|
|
1435
1436
|
}
|
|
1436
1437
|
|
|
1438
|
+
const enginePid = readBatchEnginePid(batch.raw);
|
|
1439
|
+
const staleEnginePid =
|
|
1440
|
+
enginePid != null && !isProcessAlive(enginePid);
|
|
1441
|
+
const engineOrphanCause =
|
|
1442
|
+
diagnosis === "engine_orphaned"
|
|
1443
|
+
? inferEngineOrphanCause({ journalEvents, staleEnginePid })
|
|
1444
|
+
: null;
|
|
1445
|
+
|
|
1437
1446
|
const output = buildDiagnosisOutput(diagnosis, {
|
|
1438
1447
|
batchId: batch.batchId,
|
|
1439
1448
|
phase: batch.phase,
|
|
@@ -1467,6 +1476,8 @@ export function reconcileBatch(ctx, _lightRetry = false) {
|
|
|
1467
1476
|
macroPhase,
|
|
1468
1477
|
reviewHonorSignal,
|
|
1469
1478
|
...(doneMissingContext ?? {}),
|
|
1479
|
+
engineOrphanCause,
|
|
1480
|
+
staleEnginePid,
|
|
1470
1481
|
humanBaseSync,
|
|
1471
1482
|
overlapPaths: humanBaseSync?.overlapPaths ?? [],
|
|
1472
1483
|
});
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import crypto from "node:crypto";
|
|
8
|
+
import fs from "node:fs";
|
|
8
9
|
import {
|
|
9
10
|
journalHasTaskCompleted,
|
|
10
11
|
loadResumeFileScopePaths,
|
|
@@ -18,6 +19,7 @@ import { commitLaneWorktree, filterPorcelain, gitPorcelain } from "./lane-commit
|
|
|
18
19
|
import { recordTaskFailureSalvage } from "./salvage.mjs";
|
|
19
20
|
import { saveSpineBatchState, updateSegmentForTask } from "./state.mjs";
|
|
20
21
|
import { laneTaskBranch } from "./worktree.mjs";
|
|
22
|
+
import { laneDoneMarkerCommittedOnBranch } from "./journal-rebuild.mjs";
|
|
21
23
|
import { runWorker } from "./worker-host.mjs";
|
|
22
24
|
import { isTaskResumable } from "./resume-multi-validate.mjs";
|
|
23
25
|
import { runLaneReviewPhasesBeforeCommit } from "./resume-lane-reviews.mjs";
|
|
@@ -161,6 +163,41 @@ async function markTaskCompleteFromDisk({
|
|
|
161
163
|
};
|
|
162
164
|
}
|
|
163
165
|
|
|
166
|
+
const taskFolderRel = task.taskFolder;
|
|
167
|
+
const doneOnDisk = fs.existsSync(path.join(taskFolderInWorktree, ".DONE"));
|
|
168
|
+
if (
|
|
169
|
+
doneOnDisk &&
|
|
170
|
+
(!taskFolderRel ||
|
|
171
|
+
!laneDoneMarkerCommittedOnBranch(projectRoot, taskBranchResolved, taskFolderRel))
|
|
172
|
+
) {
|
|
173
|
+
const output =
|
|
174
|
+
`Lane task branch ${taskBranchResolved} lacks committed ${taskFolderRel ?? "<unknown>"}/.DONE — ` +
|
|
175
|
+
"worker must create and commit .DONE before resume can promote";
|
|
176
|
+
task.status = "failed";
|
|
177
|
+
task.endedAt = Date.now();
|
|
178
|
+
task.exitReason = "done_marker_missing";
|
|
179
|
+
updateSegmentForTask(state, taskId, "failed");
|
|
180
|
+
recomputeTaskCounters(state);
|
|
181
|
+
saveSpineBatchState(projectRoot, state);
|
|
182
|
+
appendJournalEvent(projectRoot, batchId, "task.failed", {
|
|
183
|
+
taskId,
|
|
184
|
+
laneNumber,
|
|
185
|
+
laneId: lane.laneId,
|
|
186
|
+
correlationId: laneCorrelationId,
|
|
187
|
+
classification: "done_marker_missing",
|
|
188
|
+
exitCode: 1,
|
|
189
|
+
output,
|
|
190
|
+
resumed: true,
|
|
191
|
+
});
|
|
192
|
+
return {
|
|
193
|
+
ok: false,
|
|
194
|
+
error: "done_marker_missing",
|
|
195
|
+
output,
|
|
196
|
+
taskId,
|
|
197
|
+
laneNumber,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
164
201
|
task.status = "succeeded";
|
|
165
202
|
task.doneFileFound = true;
|
|
166
203
|
task.exitReason = task.exitReason ?? "done";
|
|
@@ -176,7 +213,7 @@ async function markTaskCompleteFromDisk({
|
|
|
176
213
|
laneId: lane.laneId,
|
|
177
214
|
correlationId: laneCorrelationId,
|
|
178
215
|
resumed: true,
|
|
179
|
-
skippedDoneOnDisk: true,
|
|
216
|
+
...(doneOnDisk ? { skippedDoneOnDisk: true } : {}),
|
|
180
217
|
taskFolder: taskFolderInWorktree,
|
|
181
218
|
});
|
|
182
219
|
}
|
package/src/batch/review.mjs
CHANGED
|
@@ -363,6 +363,26 @@ export function findLatestReviewHonorSignal(journalEvents, activeTaskId = null)
|
|
|
363
363
|
return null;
|
|
364
364
|
}
|
|
365
365
|
|
|
366
|
+
/**
|
|
367
|
+
* @param {object|null|undefined} reviewHonorSignal
|
|
368
|
+
* @returns {string|null}
|
|
369
|
+
*/
|
|
370
|
+
export function buildReviewHonorHeadlineSuffix(reviewHonorSignal) {
|
|
371
|
+
if (!reviewHonorSignal?.kind) return null;
|
|
372
|
+
const reviewLabel =
|
|
373
|
+
reviewHonorSignal.reviewType === "final" ? "final review" : "code review";
|
|
374
|
+
if (reviewHonorSignal.kind === "review.crash_recovered") {
|
|
375
|
+
return `recovered ${reviewLabel} crash — prior verdict honored from ${reviewHonorSignal.honorSource ?? "artifact"}`;
|
|
376
|
+
}
|
|
377
|
+
if (reviewHonorSignal.kind === "review.skipped_fresh_artifact") {
|
|
378
|
+
return `skipped redundant ${reviewLabel} — fresh artifact honored`;
|
|
379
|
+
}
|
|
380
|
+
if (reviewHonorSignal.kind === "review.resumed") {
|
|
381
|
+
return `${reviewLabel} resumed after operator retry`;
|
|
382
|
+
}
|
|
383
|
+
return null;
|
|
384
|
+
}
|
|
385
|
+
|
|
366
386
|
/**
|
|
367
387
|
* Latest `.reviews/final-*.md` by mtime, if any.
|
|
368
388
|
* @param {string} taskFolder
|