pi-spine 1.8.0 → 1.8.1
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-doctor.mjs +4 -0
- package/package.json +1 -1
- package/skills/create-spine-tasks/SKILL.md +1 -0
- package/skills/spine-autonomous-operator/SKILL.md +5 -2
- package/skills/spine-release-operator/SKILL.md +1 -1
- package/src/batch/attached-runner.mjs +99 -2
- package/src/batch/diagnosis-tail-state.mjs +5 -0
- package/src/batch/diagnosis.mjs +3 -2
- package/src/batch/journal-rebuild.mjs +117 -0
- package/src/batch/macro-phase.mjs +40 -2
- package/src/batch/orphan-detect.mjs +105 -2
- package/src/batch/reconcile.mjs +152 -10
- package/src/dashboard/snapshot-waves.mjs +32 -5
- package/src/dashboard/snapshot.mjs +4 -1
- package/src/doctor/attached-orphan-risk.mjs +114 -0
- package/src/doctor/run-doctor-checks.mjs +2 -0
- package/src/tasks/packet/validate-contract.mjs +8 -1
- package/src/tasks/packet/validate-prompt.mjs +1 -0
- package/src/tasks/validate-contract-warn.mjs +50 -0
package/bin/spine-doctor.mjs
CHANGED
|
@@ -11,6 +11,10 @@ import {
|
|
|
11
11
|
} from "./spine-cli/shared.mjs";
|
|
12
12
|
import { runDoctorChecks } from "../src/doctor/run-doctor-checks.mjs";
|
|
13
13
|
|
|
14
|
+
export {
|
|
15
|
+
buildAttachedOrphanRiskDoctorCheck,
|
|
16
|
+
detectAttachedOrphanRiskPatterns,
|
|
17
|
+
} from "../src/doctor/attached-orphan-risk.mjs";
|
|
14
18
|
export { buildTestingEvidenceDoctorChecks, runDoctorChecks } from "../src/doctor/run-doctor-checks.mjs";
|
|
15
19
|
|
|
16
20
|
export function cmdDoctor() {
|
package/package.json
CHANGED
|
@@ -501,6 +501,7 @@ Hydration commits (STATUS.md expansions) may happen mid-step for crash recovery.
|
|
|
501
501
|
|
|
502
502
|
- **Self-contained PROMPT.md** — the worker has no memory of this conversation. Cross-model reviewers receive a **fresh spawn** (FR-REV-04) with only the review request, diff, and Contract — not `referenceDocs` or worker rules. Place acceptance criteria and spec references in PROMPT `## Mission`, `## Contract`, and step checkboxes.
|
|
503
503
|
- **Scoped `testCommand` for cross-model batches** — lane worktrees differ from dev checkouts; broad `flutter test` / `npm test` can fail in lanes even when targeted tests pass. See [cross-model authoring guidance](references/contract-template.md#cross-model-authoring-worker--reviewer) for the `testCommand` decision table.
|
|
504
|
+
- **S/M patch tasks: no coverage gate in Contract** — do not chain `npm run coverage:check` or bare `npm test` in `## Contract` `testCommand` on Size S/M tasks; integrate gate owns full coverage at merge. Use scoped `node --test path/to.test.mjs` (SP-521 / [#141](https://github.com/beettlle/pi-spine/issues/141)). `spine tasks validate` warns when violated.
|
|
504
505
|
- **Testing step required (never omit)** — every task packet needs `### Step N: Testing & Verification` inside `## Steps`, before `## Completion Criteria`. **Do not skip this for docs-only or Review Level 0 tasks** — the worker rejects packets without a Testing step. Use `testing.test` from spine config; for **code deliverables**, also include `testing.testWithCoverage` and a **≥77% line coverage** checkbox (see prompt template). Docs-only tasks may omit the coverage checkbox.
|
|
505
506
|
- **Documentation in every task** — "Must Update" / "Check If Affected" prevent doc drift.
|
|
506
507
|
- **Concrete deliverables** — name files to create/modify; avoid shortcuttable vague steps.
|
|
@@ -32,6 +32,7 @@ Invoke explicitly: `/skill:spine-autonomous-operator`
|
|
|
32
32
|
- **Do not** use unattended `spine run sequence --auto-approve-gate --force` without monitoring
|
|
33
33
|
- **Do not** start a second batch while another batch is **running** on the same repo
|
|
34
34
|
- **Never** background `spine batch resume --attached` or `resume --attached --force` ([#163](https://github.com/beettlle/pi-spine/issues/163))
|
|
35
|
+
- **Release and agent batches:** use **detached** `spine batch start|resume` (omit `--attached`) unless the operator shell blocks until batch completion; then `spine wait --until …` ([#163](https://github.com/beettlle/pi-spine/issues/163), [#185](https://github.com/beettlle/pi-spine/issues/185)). `spine doctor` warns in non-interactive and agent-harness contexts.
|
|
35
36
|
|
|
36
37
|
## Phase 0 — Baseline
|
|
37
38
|
|
|
@@ -128,13 +129,15 @@ For each wave `N` until `spine plan pending` shows 0 tasks:
|
|
|
128
129
|
|
|
129
130
|
```text
|
|
130
131
|
MonitorCreate:
|
|
131
|
-
command: spine batch start pending --wave N --attached
|
|
132
|
+
command: spine batch start pending --wave N # detached — omit --attached (#163)
|
|
132
133
|
description: Pending wave N
|
|
133
134
|
timeout: 0
|
|
134
135
|
onDone: spine status --diagnose → land loop (§3.3) or recovery (§4)
|
|
135
136
|
```
|
|
136
137
|
|
|
137
|
-
|
|
138
|
+
After detached start, monitor with `spine wait --until completed,needs_integrate,failed,aborted --timeout 4h` or `spine status --diagnose`.
|
|
139
|
+
|
|
140
|
+
**Foreground fallback** (interactive terminal only — keep shell in foreground for full batch):
|
|
138
141
|
|
|
139
142
|
```bash
|
|
140
143
|
spine batch start pending --wave N --attached
|
|
@@ -304,7 +304,7 @@ Always: `spine status --diagnose`
|
|
|
304
304
|
| `needs_retry` | Fix packet; `spine batch retry <taskId>` |
|
|
305
305
|
| `worker_orphaned` | abort → dismiss → prune worktree → retry |
|
|
306
306
|
| `needs_integrate` | Land loop |
|
|
307
|
-
| `state_drift` | `spine batch retry <taskId>`
|
|
307
|
+
| `state_drift` | Follow `suggestedCommand` from diagnose: `spine batch retry <taskId>` when drift task is not `running`; `spine batch resume --force` when still `running` (SP-512 — not `pause && retry`). Then **`spine batch resume --attached --force` in foreground** if engine remains detached (never MonitorCreate) |
|
|
308
308
|
| `failed` / `aborted` | Inspect journal; fix packet; dismiss; retry |
|
|
309
309
|
| Contract fail | Fix PROMPT on main, commit, abort, dismiss, retry |
|
|
310
310
|
|
|
@@ -13,11 +13,25 @@ import { detectPostMergeLimboForResume } from "./resume-multi-validate.mjs";
|
|
|
13
13
|
import { isProcessAlive } from "../process/liveness.mjs";
|
|
14
14
|
import { terminateStaleDetachedEngine } from "./resume-engine.mjs";
|
|
15
15
|
import { reconcileBatch } from "./reconcile.mjs";
|
|
16
|
-
import { readJournalEventsCached } from "./journal.mjs";
|
|
16
|
+
import { readJournalEventsCached, readJournalEvents, appendJournalEvent } from "./journal.mjs";
|
|
17
17
|
import { enforceOperatorPauseOnDisk } from "./pause.mjs";
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
loadSpineBatchState,
|
|
20
|
+
readBatchEnginePid,
|
|
21
|
+
saveSpineBatchState,
|
|
22
|
+
updateSegmentForTask,
|
|
23
|
+
recomputeTaskCounters,
|
|
24
|
+
clearBatchEnginePid,
|
|
25
|
+
} from "./state.mjs";
|
|
19
26
|
import { loadSpineConfig } from "../config/spine-config-load.mjs";
|
|
20
27
|
import { resolveAttachedMilestonePollMs } from "../config/spine-config-schema.mjs";
|
|
28
|
+
import {
|
|
29
|
+
journalHasContractVerified,
|
|
30
|
+
journalIndicatesPausedForceResume,
|
|
31
|
+
} from "./orphan-detect.mjs";
|
|
32
|
+
import { classifyTaskDoneSemantics } from "./diagnosis-task-done.mjs";
|
|
33
|
+
import { resolveTasksRoot } from "../config/spine-preflight-lib.mjs";
|
|
34
|
+
import { journalHasTaskCompleted } from "./resume-common.mjs";
|
|
21
35
|
|
|
22
36
|
export { DEFAULT_ATTACHED_MILESTONE_POLL_MS } from "../config/spine-config-schema.mjs";
|
|
23
37
|
|
|
@@ -215,6 +229,81 @@ export function enforceAttachedEngineSingleOwner({ projectRoot, force = false, o
|
|
|
215
229
|
};
|
|
216
230
|
}
|
|
217
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Promote running cache tasks with lane `.DONE` and contract verify after paused force resume (SP-513 / #184).
|
|
234
|
+
*
|
|
235
|
+
* @param {object} params
|
|
236
|
+
* @param {string} params.projectRoot
|
|
237
|
+
* @param {object} params.state
|
|
238
|
+
* @param {string} params.batchId
|
|
239
|
+
* @returns {{ reconciled: boolean, taskIds?: string[] }}
|
|
240
|
+
*/
|
|
241
|
+
export function reconcilePausedResumeDoneInLane({ projectRoot, state, batchId }) {
|
|
242
|
+
if (!state || typeof state !== "object" || !batchId) {
|
|
243
|
+
return { reconciled: false };
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const journalEvents = readJournalEvents(projectRoot, batchId);
|
|
247
|
+
if (!journalIndicatesPausedForceResume(journalEvents)) {
|
|
248
|
+
return { reconciled: false };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const configResult = loadSpineConfig(projectRoot);
|
|
252
|
+
const tasksRoot = resolveTasksRoot(projectRoot, configResult);
|
|
253
|
+
const lanes = state.lanes ?? [];
|
|
254
|
+
/** @type {string[]} */
|
|
255
|
+
const promotedTaskIds = [];
|
|
256
|
+
let changed = false;
|
|
257
|
+
|
|
258
|
+
for (const task of state.tasks ?? []) {
|
|
259
|
+
const status = String(task?.status ?? "").toLowerCase();
|
|
260
|
+
if (status !== "running" && status !== "pending") continue;
|
|
261
|
+
|
|
262
|
+
const classified = classifyTaskDoneSemantics(task, {
|
|
263
|
+
tasksRoot,
|
|
264
|
+
projectRoot,
|
|
265
|
+
batchId,
|
|
266
|
+
lanes,
|
|
267
|
+
});
|
|
268
|
+
if (classified.doneInLane !== true) continue;
|
|
269
|
+
if (!journalHasContractVerified(journalEvents, task.taskId)) continue;
|
|
270
|
+
|
|
271
|
+
task.status = "succeeded";
|
|
272
|
+
task.doneFileFound = true;
|
|
273
|
+
task.exitReason = task.exitReason ?? "done";
|
|
274
|
+
if (!task.endedAt) task.endedAt = Date.now();
|
|
275
|
+
updateSegmentForTask(state, task.taskId, "succeeded");
|
|
276
|
+
promotedTaskIds.push(task.taskId);
|
|
277
|
+
changed = true;
|
|
278
|
+
|
|
279
|
+
if (!journalHasTaskCompleted(journalEvents, task.taskId)) {
|
|
280
|
+
const laneNumber = Number(task.laneNumber ?? 1);
|
|
281
|
+
const lane = lanes.find((entry) => Number(entry?.laneNumber) === laneNumber);
|
|
282
|
+
appendJournalEvent(projectRoot, batchId, "task.completed", {
|
|
283
|
+
taskId: task.taskId,
|
|
284
|
+
laneNumber,
|
|
285
|
+
laneId: lane?.laneId ?? `lane-${laneNumber}`,
|
|
286
|
+
resumed: true,
|
|
287
|
+
skippedDoneOnDisk: true,
|
|
288
|
+
reconciled: true,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (!changed) {
|
|
294
|
+
return { reconciled: false };
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const enginePid = readBatchEnginePid(state);
|
|
298
|
+
if (enginePid != null && !isProcessAlive(enginePid)) {
|
|
299
|
+
clearBatchEnginePid(state);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
recomputeTaskCounters(state);
|
|
303
|
+
saveSpineBatchState(projectRoot, state);
|
|
304
|
+
return { reconciled: true, taskIds: promotedTaskIds };
|
|
305
|
+
}
|
|
306
|
+
|
|
218
307
|
/**
|
|
219
308
|
* Run an attached foreground engine while streaming land-loop journal milestones to stdout.
|
|
220
309
|
*
|
|
@@ -279,6 +368,14 @@ function resolveAttachedBatchExitCode(result, reconciliation) {
|
|
|
279
368
|
* @param {boolean} [params.json]
|
|
280
369
|
*/
|
|
281
370
|
export function formatAttachedBatchCliResult({ projectRoot, operation, result, json = false }) {
|
|
371
|
+
const loaded = loadSpineBatchState(projectRoot);
|
|
372
|
+
if (loaded.raw?.batchId) {
|
|
373
|
+
reconcilePausedResumeDoneInLane({
|
|
374
|
+
projectRoot,
|
|
375
|
+
state: loaded.raw,
|
|
376
|
+
batchId: String(loaded.raw.batchId),
|
|
377
|
+
});
|
|
378
|
+
}
|
|
282
379
|
const reconciliation = reconcileBatch({ projectRoot });
|
|
283
380
|
const mergeBlocked = reconciliation.phase === "merge_blocked";
|
|
284
381
|
|
|
@@ -45,6 +45,11 @@ export function buildRunningTailHeadline(batchLabel, ctx = {}) {
|
|
|
45
45
|
return `${batchLabel} planning — no workers scheduled`;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
// Macro Failed must not surface in running tail — drift/orphan may still be recoverable (#165).
|
|
49
|
+
if (macroPhase === "failed") {
|
|
50
|
+
return `${batchLabel} finalizing batch — no active workers`;
|
|
51
|
+
}
|
|
52
|
+
|
|
48
53
|
if (macroPhase != null && macroPhase !== "executing") {
|
|
49
54
|
const label = macroPhaseLabel(macroPhase);
|
|
50
55
|
return `${batchLabel} ${label.toLowerCase()} — finalizing batch`;
|
package/src/batch/diagnosis.mjs
CHANGED
|
@@ -169,8 +169,9 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
|
|
|
169
169
|
return "spine batch dismiss";
|
|
170
170
|
case "state_drift":
|
|
171
171
|
if (ctx.failedTaskId) {
|
|
172
|
-
|
|
173
|
-
|
|
172
|
+
const driftStatus = String(ctx.driftTaskStatus ?? "").toLowerCase();
|
|
173
|
+
if (driftStatus === "running" || ctx.phase === "running") {
|
|
174
|
+
return "spine batch resume --force";
|
|
174
175
|
}
|
|
175
176
|
return `spine batch retry ${ctx.failedTaskId}`;
|
|
176
177
|
}
|
|
@@ -6,10 +6,13 @@
|
|
|
6
6
|
import fs from "node:fs";
|
|
7
7
|
import { appendJournalEvent, readJournalEvents, STRUCTURAL_JOURNAL_EVENT_TYPES } from "./journal.mjs";
|
|
8
8
|
import { parseReviewVerdict } from "./review-shared.mjs";
|
|
9
|
+
import { journalHasTaskCompleted } from "./resume-common.mjs";
|
|
9
10
|
import {
|
|
10
11
|
clearTaskFailureMetadata,
|
|
11
12
|
createInitialBatchState,
|
|
13
|
+
recordTaskSucceeded,
|
|
12
14
|
recomputeTaskCounters,
|
|
15
|
+
saveSpineBatchState,
|
|
13
16
|
updateSegmentForTask,
|
|
14
17
|
} from "./state.mjs";
|
|
15
18
|
|
|
@@ -542,3 +545,117 @@ export function detectBatchStateDrift(cachedState, rebuiltState, events = [], cl
|
|
|
542
545
|
|
|
543
546
|
return { drifted: entries.length > 0, entries };
|
|
544
547
|
}
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Journal evidence that lane work finished and review/contract passed (FR-STA-01 / #170).
|
|
551
|
+
*
|
|
552
|
+
* @param {object[]} events
|
|
553
|
+
* @param {string} taskId
|
|
554
|
+
*/
|
|
555
|
+
export function journalShowsDoneInLaneTerminalArtifacts(events, taskId) {
|
|
556
|
+
let hasApprovedReview = false;
|
|
557
|
+
let hasLaneCompleted = false;
|
|
558
|
+
let hasContractVerified = false;
|
|
559
|
+
|
|
560
|
+
for (const event of events ?? []) {
|
|
561
|
+
const type = String(event?.type ?? "");
|
|
562
|
+
const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
|
|
563
|
+
const eventTaskId = event.taskId ?? payload.taskId;
|
|
564
|
+
if (eventTaskId !== taskId) continue;
|
|
565
|
+
|
|
566
|
+
if (type === "review.completed" && APPROVED_VERDICTS.has(String(payload.verdict ?? ""))) {
|
|
567
|
+
hasApprovedReview = true;
|
|
568
|
+
}
|
|
569
|
+
if (type === "task.verdict_recorded" && APPROVED_VERDICTS.has(String(payload.verdict ?? ""))) {
|
|
570
|
+
hasApprovedReview = true;
|
|
571
|
+
}
|
|
572
|
+
if (type === "lane.completed") {
|
|
573
|
+
hasLaneCompleted = true;
|
|
574
|
+
}
|
|
575
|
+
if (type === "contract.verified" && payload.ok === true) {
|
|
576
|
+
hasContractVerified = true;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
return hasLaneCompleted && (hasApprovedReview || hasContractVerified);
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* Promote batch-state tasks when lane on-disk truth and journal show terminal success
|
|
585
|
+
* but cache still shows pending/running (idempotent; FR-STA-01 / SP-512).
|
|
586
|
+
*
|
|
587
|
+
* @param {object} params
|
|
588
|
+
* @param {string} params.projectRoot
|
|
589
|
+
* @param {object} params.state
|
|
590
|
+
* @param {object[]} [params.classifiedTasks]
|
|
591
|
+
* @param {object[]} [params.journalEvents]
|
|
592
|
+
* @param {{ drifted?: boolean, entries?: Array<{ taskId: string, field: string, rebuilt?: unknown }> }} [params.drift]
|
|
593
|
+
* @returns {{ reconciled: boolean, taskIds: string[] }}
|
|
594
|
+
*/
|
|
595
|
+
export function reconcileBatchStateDrift({
|
|
596
|
+
projectRoot,
|
|
597
|
+
state,
|
|
598
|
+
classifiedTasks = [],
|
|
599
|
+
journalEvents = [],
|
|
600
|
+
drift = null,
|
|
601
|
+
}) {
|
|
602
|
+
if (!state || typeof state !== "object" || !drift?.drifted || !Array.isArray(drift.entries)) {
|
|
603
|
+
return { reconciled: false, taskIds: [] };
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
const batchId = String(state.batchId ?? "");
|
|
607
|
+
if (!batchId) {
|
|
608
|
+
return { reconciled: false, taskIds: [] };
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
const classifiedById = new Map(
|
|
612
|
+
(classifiedTasks ?? []).map((task) => [String(task?.taskId ?? ""), task]),
|
|
613
|
+
);
|
|
614
|
+
/** @type {string[]} */
|
|
615
|
+
const reconciledTaskIds = [];
|
|
616
|
+
let changed = false;
|
|
617
|
+
|
|
618
|
+
for (const entry of drift.entries) {
|
|
619
|
+
const taskId = String(entry?.taskId ?? "");
|
|
620
|
+
if (!taskId || taskId === "*") continue;
|
|
621
|
+
|
|
622
|
+
const task = (state.tasks ?? []).find((row) => row?.taskId === taskId);
|
|
623
|
+
if (!task) continue;
|
|
624
|
+
|
|
625
|
+
if (entry.field === "status" && String(entry.rebuilt ?? "") === "succeeded") {
|
|
626
|
+
if (String(task.status ?? "") === "succeeded") continue;
|
|
627
|
+
if (!recordTaskSucceeded(state, taskId, { doneFileFound: true, exitReason: "done" })) continue;
|
|
628
|
+
reconciledTaskIds.push(taskId);
|
|
629
|
+
changed = true;
|
|
630
|
+
continue;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
if (entry.field !== "doneInLane") continue;
|
|
634
|
+
|
|
635
|
+
const classified = classifiedById.get(taskId);
|
|
636
|
+
if (!classifiedShowsDoneInLaneDrift(classified)) continue;
|
|
637
|
+
if (classified?.doneInLane !== true) continue;
|
|
638
|
+
if (journalHasTaskCompleted(journalEvents, taskId)) continue;
|
|
639
|
+
if (!journalShowsDoneInLaneTerminalArtifacts(journalEvents, taskId)) continue;
|
|
640
|
+
if (String(task.status ?? "") === "succeeded") continue;
|
|
641
|
+
|
|
642
|
+
if (!recordTaskSucceeded(state, taskId, { doneFileFound: true, exitReason: "done" })) continue;
|
|
643
|
+
|
|
644
|
+
appendJournalEvent(projectRoot, batchId, "task.completed", {
|
|
645
|
+
taskId,
|
|
646
|
+
laneNumber: task.laneNumber ?? null,
|
|
647
|
+
reconciled: true,
|
|
648
|
+
reconcileReason: "done_in_lane_terminal",
|
|
649
|
+
skippedDoneOnDisk: true,
|
|
650
|
+
});
|
|
651
|
+
|
|
652
|
+
reconciledTaskIds.push(taskId);
|
|
653
|
+
changed = true;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
if (changed) {
|
|
657
|
+
saveSpineBatchState(projectRoot, state);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
return { reconciled: changed, taskIds: reconciledTaskIds };
|
|
661
|
+
}
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* |--------------|---------|
|
|
12
12
|
* | idle | diagnosis null/undefined (no active batch) |
|
|
13
13
|
* | aborted | batchPhase or diagnosis `aborted` |
|
|
14
|
-
* | failed | batchPhase `failed`, or terminal-failure diagnoses
|
|
14
|
+
* | failed | batchPhase `failed`, or terminal-failure diagnoses when not recoverable drift/orphan (#165) |
|
|
15
15
|
* | paused | batchPhase or diagnosis `paused` (when not failed) |
|
|
16
16
|
* | gating | integrate gate record `pending`, or postMergeLimbo awaiting operator gate approval |
|
|
17
17
|
* | integrating | open `integrate.started` journal event, or diagnosis `needs_integrate` |
|
|
@@ -66,6 +66,15 @@ const FAILED_DIAGNOSES = new Set([
|
|
|
66
66
|
"git_unavailable",
|
|
67
67
|
]);
|
|
68
68
|
|
|
69
|
+
/** Drift/orphan diagnoses that may still be progressing while batch phase is active (#165). */
|
|
70
|
+
const RECOVERABLE_DRIFT_ORPHAN_DIAGNOSES = new Set([
|
|
71
|
+
"state_drift",
|
|
72
|
+
"engine_orphaned",
|
|
73
|
+
"worker_orphaned",
|
|
74
|
+
]);
|
|
75
|
+
|
|
76
|
+
const ACTIVE_BATCH_PHASES = new Set(["running", "merging"]);
|
|
77
|
+
|
|
69
78
|
const INTEGRATE_EVENT_TYPES = new Set(["integrate.started", "integrate.completed", "integrate.failed"]);
|
|
70
79
|
|
|
71
80
|
/**
|
|
@@ -193,6 +202,31 @@ function isGatingState(gateRecord, postMergeLimbo, diagnosis) {
|
|
|
193
202
|
return false;
|
|
194
203
|
}
|
|
195
204
|
|
|
205
|
+
/**
|
|
206
|
+
* Drift/orphan under an active batch may still be executing, merging, or gating — not macro Failed.
|
|
207
|
+
*
|
|
208
|
+
* @param {DeriveMacroPhaseInput} input
|
|
209
|
+
* @returns {boolean}
|
|
210
|
+
*/
|
|
211
|
+
function isRecoverableDriftOrphanWhileActive(input) {
|
|
212
|
+
const diagnosis = input.diagnosis ?? null;
|
|
213
|
+
const batchPhase = input.batchPhase ?? null;
|
|
214
|
+
if (diagnosis == null || !RECOVERABLE_DRIFT_ORPHAN_DIAGNOSES.has(diagnosis)) {
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
if (!ACTIVE_BATCH_PHASES.has(batchPhase ?? "")) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
if (input.hasActiveWorkerTasks === true) {
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
// All lanes terminal — defer to gating/integrating/merging tail derivation.
|
|
224
|
+
if (input.allTasksTerminalSuccess === true) {
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
|
|
196
230
|
/**
|
|
197
231
|
* @param {DeriveMacroPhaseInput} input
|
|
198
232
|
* @returns {MacroPhase|null}
|
|
@@ -262,7 +296,11 @@ export function deriveMacroPhase(input) {
|
|
|
262
296
|
return "aborted";
|
|
263
297
|
}
|
|
264
298
|
|
|
265
|
-
if (
|
|
299
|
+
if (
|
|
300
|
+
batchPhase === "failed" ||
|
|
301
|
+
batchPhase === "merge_blocked" ||
|
|
302
|
+
(diagnosis != null && FAILED_DIAGNOSES.has(diagnosis) && !isRecoverableDriftOrphanWhileActive(input))
|
|
303
|
+
) {
|
|
266
304
|
return "failed";
|
|
267
305
|
}
|
|
268
306
|
|
|
@@ -66,6 +66,99 @@ function readEngineStartedAt(raw) {
|
|
|
66
66
|
return Number.isFinite(startedAt) && startedAt > 0 ? startedAt : null;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* @param {unknown} event
|
|
71
|
+
* @returns {string|null}
|
|
72
|
+
*/
|
|
73
|
+
function eventFromPhase(event) {
|
|
74
|
+
if (!event || typeof event !== "object") return null;
|
|
75
|
+
const payload = /** @type {{ fromPhase?: unknown, payload?: { fromPhase?: unknown } }} */ (event);
|
|
76
|
+
const direct = payload.fromPhase ?? payload.payload?.fromPhase;
|
|
77
|
+
return typeof direct === "string" && direct ? direct : null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Paused batch resumed with --force after intentional engine handoff (SP-513 / #184).
|
|
82
|
+
*
|
|
83
|
+
* @param {object[]} journalEvents
|
|
84
|
+
*/
|
|
85
|
+
export function journalIndicatesPausedForceResume(journalEvents) {
|
|
86
|
+
if (!Array.isArray(journalEvents) || journalEvents.length === 0) return false;
|
|
87
|
+
return journalEvents.some((event) => {
|
|
88
|
+
if (String(event?.type ?? "") !== "batch.resumed") return false;
|
|
89
|
+
const payload =
|
|
90
|
+
event.payload && typeof event.payload === "object"
|
|
91
|
+
? /** @type {Record<string, unknown>} */ (event.payload)
|
|
92
|
+
: {};
|
|
93
|
+
const resumeForced = payload.resumeForced === true || event.resumeForced === true;
|
|
94
|
+
const fromPhase = eventFromPhase(event);
|
|
95
|
+
return resumeForced && fromPhase === "paused";
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @param {object[]} journalEvents
|
|
101
|
+
* @param {string} taskId
|
|
102
|
+
*/
|
|
103
|
+
export function journalHasContractVerified(journalEvents, taskId) {
|
|
104
|
+
if (!Array.isArray(journalEvents) || !taskId) return false;
|
|
105
|
+
return journalEvents.some((event) => {
|
|
106
|
+
if (String(event?.type ?? "") !== "contract.verified") return false;
|
|
107
|
+
const matchedTaskId = eventTaskId(event) ?? event.payload?.taskId;
|
|
108
|
+
if (matchedTaskId !== taskId) return false;
|
|
109
|
+
const payload =
|
|
110
|
+
event.payload && typeof event.payload === "object"
|
|
111
|
+
? /** @type {Record<string, unknown>} */ (event.payload)
|
|
112
|
+
: {};
|
|
113
|
+
if (payload.ok === false || event.ok === false) return false;
|
|
114
|
+
return true;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Running cache tasks with lane `.DONE` and contract verify should not surface engine_orphaned
|
|
120
|
+
* after a paused force-resume handoff (SP-513 / #184).
|
|
121
|
+
*
|
|
122
|
+
* @param {object} ctx
|
|
123
|
+
* @param {object[]} scopedJournalEvents
|
|
124
|
+
*/
|
|
125
|
+
export function shouldSuppressPausedResumeEngineOrphan(ctx, scopedJournalEvents) {
|
|
126
|
+
if (!journalIndicatesPausedForceResume(scopedJournalEvents)) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const cacheTasks = Array.isArray(ctx.raw?.tasks) ? ctx.raw.tasks : [];
|
|
131
|
+
const runningCacheTasks = cacheTasks.filter(
|
|
132
|
+
(task) => String(task?.status ?? "").toLowerCase() === "running",
|
|
133
|
+
);
|
|
134
|
+
if (runningCacheTasks.length === 0) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const classifiedById = new Map(
|
|
139
|
+
(ctx.tasks ?? [])
|
|
140
|
+
.filter((task) => typeof task?.taskId === "string" && task.taskId)
|
|
141
|
+
.map((task) => [task.taskId, task]),
|
|
142
|
+
);
|
|
143
|
+
const journalEvents = Array.isArray(ctx.fullJournalEvents)
|
|
144
|
+
? ctx.fullJournalEvents
|
|
145
|
+
: scopedJournalEvents;
|
|
146
|
+
|
|
147
|
+
for (const task of runningCacheTasks) {
|
|
148
|
+
const taskId = String(task.taskId ?? "");
|
|
149
|
+
if (!taskId) return false;
|
|
150
|
+
const classified = classifiedById.get(taskId);
|
|
151
|
+
if (classified?.doneInLane !== true) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
if (!journalHasContractVerified(journalEvents, taskId)) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
|
|
69
162
|
/**
|
|
70
163
|
* Journal events for the current detached engine session only.
|
|
71
164
|
* Prefers the latest `batch.resumed`; otherwise filters from `engineStartedAt`.
|
|
@@ -255,7 +348,16 @@ export function detectOrphanRunning(ctx) {
|
|
|
255
348
|
}
|
|
256
349
|
|
|
257
350
|
const enginePid = readBatchEnginePid(ctx.raw);
|
|
258
|
-
|
|
351
|
+
const suppressPausedResumeEngineOrphan = shouldSuppressPausedResumeEngineOrphan(
|
|
352
|
+
ctx,
|
|
353
|
+
scopedJournalEvents,
|
|
354
|
+
);
|
|
355
|
+
if (
|
|
356
|
+
enginePid &&
|
|
357
|
+
!isProcessAlive(enginePid) &&
|
|
358
|
+
!journalHasTerminalBatchEvent(scopedJournalEvents) &&
|
|
359
|
+
!suppressPausedResumeEngineOrphan
|
|
360
|
+
) {
|
|
259
361
|
/** @type {OrphanRunningSignal} */
|
|
260
362
|
return {
|
|
261
363
|
kind: "engine",
|
|
@@ -271,7 +373,8 @@ export function detectOrphanRunning(ctx) {
|
|
|
271
373
|
enginePid == null &&
|
|
272
374
|
!hasFiniteWorkerPidForRunningTasks(ctx.lanes, runningTasks) &&
|
|
273
375
|
engineStartedAt != null &&
|
|
274
|
-
journalIndicatesStalledSession(scopedJournalEvents)
|
|
376
|
+
journalIndicatesStalledSession(scopedJournalEvents) &&
|
|
377
|
+
!suppressPausedResumeEngineOrphan
|
|
275
378
|
) {
|
|
276
379
|
/** @type {OrphanRunningSignal} */
|
|
277
380
|
return {
|
package/src/batch/reconcile.mjs
CHANGED
|
@@ -34,6 +34,7 @@ import { computeStatusProgress } from "./status-json.mjs";
|
|
|
34
34
|
import {
|
|
35
35
|
detectBatchStateDrift,
|
|
36
36
|
rebuildBatchStateFromJournal,
|
|
37
|
+
reconcileBatchStateDrift,
|
|
37
38
|
} from "./journal-rebuild.mjs";
|
|
38
39
|
import { appendJournalEvent, extractJournalDiagnosisHints, findPlanReviewNestedSpawnBlockedFailure, journalPath, readJournalEvents } from "./journal.mjs";
|
|
39
40
|
import { findLatestSalvageInspection } from "./salvage.mjs";
|
|
@@ -163,6 +164,34 @@ export function resolveTasksRoot(projectRoot, configResult) {
|
|
|
163
164
|
return resolveTasksRootPath(projectRoot, loaded.config);
|
|
164
165
|
}
|
|
165
166
|
|
|
167
|
+
/**
|
|
168
|
+
* Align computed classification with reconciled batch-state status (SP-516 / #166).
|
|
169
|
+
* Stale lane `.DONE` markers must not imply terminal-success when cache status is
|
|
170
|
+
* failed or pending. Running + done markers stays terminal-success for drift (SP-512).
|
|
171
|
+
*
|
|
172
|
+
* @param {object} classified
|
|
173
|
+
*/
|
|
174
|
+
export function alignTaskClassificationWithStatus(classified) {
|
|
175
|
+
const status = String(classified.status ?? "").toLowerCase();
|
|
176
|
+
let classification = classified.classification;
|
|
177
|
+
|
|
178
|
+
if (status === "succeeded" || status === "skipped") {
|
|
179
|
+
classification = "terminal-success";
|
|
180
|
+
} else if (status === "failed") {
|
|
181
|
+
classification = "terminal-failure";
|
|
182
|
+
} else if (status === "running") {
|
|
183
|
+
if (classified.doneOnMain || classified.doneInLane || classified.doneFileFound) {
|
|
184
|
+
classification = "terminal-success";
|
|
185
|
+
} else {
|
|
186
|
+
classification = "running";
|
|
187
|
+
}
|
|
188
|
+
} else {
|
|
189
|
+
classification = "pending";
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return { ...classified, classification };
|
|
193
|
+
}
|
|
194
|
+
|
|
166
195
|
/**
|
|
167
196
|
* @param {NormalizedBatchState} batch
|
|
168
197
|
* @param {string|null} tasksRoot
|
|
@@ -170,15 +199,83 @@ export function resolveTasksRoot(projectRoot, configResult) {
|
|
|
170
199
|
*/
|
|
171
200
|
export function classifyTasks(batch, tasksRoot, projectRoot = "") {
|
|
172
201
|
return batch.tasks.map((task) =>
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
202
|
+
alignTaskClassificationWithStatus(
|
|
203
|
+
classifyTaskDoneSemantics(task, {
|
|
204
|
+
tasksRoot,
|
|
205
|
+
projectRoot,
|
|
206
|
+
batchId: batch.batchId,
|
|
207
|
+
lanes: batch.lanes,
|
|
208
|
+
}),
|
|
209
|
+
),
|
|
179
210
|
);
|
|
180
211
|
}
|
|
181
212
|
|
|
213
|
+
/**
|
|
214
|
+
* Clear stale persisted task classification fields that contradict reconciled status.
|
|
215
|
+
*
|
|
216
|
+
* @param {object} params
|
|
217
|
+
* @param {string} params.projectRoot
|
|
218
|
+
* @param {object} params.state
|
|
219
|
+
* @returns {{ changed: boolean }}
|
|
220
|
+
*/
|
|
221
|
+
export function syncPersistedClassifications({ projectRoot, state }) {
|
|
222
|
+
if (!state || typeof state !== "object") {
|
|
223
|
+
return { changed: false };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const batch = parseBatchState(state, "");
|
|
227
|
+
if (!batch) {
|
|
228
|
+
return { changed: false };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const tasksRoot = resolveTasksRoot(projectRoot);
|
|
232
|
+
const classified = classifyTasks(batch, tasksRoot, projectRoot);
|
|
233
|
+
const alignedById = new Map(classified.map((task) => [String(task.taskId), task]));
|
|
234
|
+
let changed = false;
|
|
235
|
+
|
|
236
|
+
for (const task of state.tasks ?? []) {
|
|
237
|
+
if (!task?.taskId) continue;
|
|
238
|
+
const aligned = alignedById.get(String(task.taskId));
|
|
239
|
+
if (!aligned) continue;
|
|
240
|
+
|
|
241
|
+
const status = String(task.status ?? "").toLowerCase();
|
|
242
|
+
if (status === "succeeded" || status === "skipped") {
|
|
243
|
+
if ("classification" in task) {
|
|
244
|
+
delete task.classification;
|
|
245
|
+
changed = true;
|
|
246
|
+
}
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (!("classification" in task)) continue;
|
|
251
|
+
|
|
252
|
+
const persisted = String(task.classification ?? "");
|
|
253
|
+
if (persisted === aligned.classification) continue;
|
|
254
|
+
|
|
255
|
+
if (status === "failed" || status === "pending") {
|
|
256
|
+
delete task.classification;
|
|
257
|
+
changed = true;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
for (const segment of state.segments ?? []) {
|
|
262
|
+
if (!segment?.taskId || !("classification" in segment)) continue;
|
|
263
|
+
const aligned = alignedById.get(String(segment.taskId));
|
|
264
|
+
if (!aligned) continue;
|
|
265
|
+
const segmentStatus = String(segment.status ?? "").toLowerCase();
|
|
266
|
+
if (segmentStatus === "failed" || segmentStatus === "pending") {
|
|
267
|
+
delete segment.classification;
|
|
268
|
+
changed = true;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (changed) {
|
|
273
|
+
saveSpineBatchState(projectRoot, state);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return { changed };
|
|
277
|
+
}
|
|
278
|
+
|
|
182
279
|
/**
|
|
183
280
|
* @param {string} projectRoot
|
|
184
281
|
*/
|
|
@@ -1083,7 +1180,7 @@ export function reconcileBatch(ctx, _lightRetry = false) {
|
|
|
1083
1180
|
}
|
|
1084
1181
|
|
|
1085
1182
|
const tasksRoot = resolveTasksRoot(projectRoot);
|
|
1086
|
-
|
|
1183
|
+
let classifiedTasks = classifyTasks(batch, tasksRoot, projectRoot);
|
|
1087
1184
|
const useLightGit =
|
|
1088
1185
|
ctx.light === true &&
|
|
1089
1186
|
!_lightRetry &&
|
|
@@ -1149,15 +1246,53 @@ export function reconcileBatch(ctx, _lightRetry = false) {
|
|
|
1149
1246
|
const engineSessionJournalEvents = journalEventsSinceResume(journalEvents, batch.raw);
|
|
1150
1247
|
|
|
1151
1248
|
if (journalEvents.length > 0 && batch.raw) {
|
|
1152
|
-
|
|
1153
|
-
|
|
1249
|
+
let rebuilt = rebuildBatchStateFromJournal(batch.raw, journalEvents);
|
|
1250
|
+
let drift = detectBatchStateDrift(batch.raw, rebuilt, journalEvents, classifiedTasks);
|
|
1251
|
+
const healed = reconcileBatchStateDrift({
|
|
1252
|
+
projectRoot,
|
|
1253
|
+
state: batch.raw,
|
|
1254
|
+
classifiedTasks,
|
|
1255
|
+
journalEvents,
|
|
1256
|
+
drift,
|
|
1257
|
+
});
|
|
1258
|
+
if (healed.reconciled) {
|
|
1259
|
+
journalEvents = readJournalEvents(projectRoot, batch.batchId);
|
|
1260
|
+
const refreshed = parseBatchState(batch.raw, loaded.path ?? ctx.batchStatePath ?? "");
|
|
1261
|
+
if (refreshed) {
|
|
1262
|
+
batch.tasks = refreshed.tasks;
|
|
1263
|
+
batch.segments = refreshed.segments;
|
|
1264
|
+
batch.succeededTasks = refreshed.succeededTasks;
|
|
1265
|
+
batch.failedTasks = refreshed.failedTasks;
|
|
1266
|
+
batch.lanes = refreshed.lanes;
|
|
1267
|
+
}
|
|
1268
|
+
classifiedTasks = classifyTasks(batch, tasksRoot, projectRoot);
|
|
1269
|
+
rebuilt = rebuildBatchStateFromJournal(batch.raw, journalEvents);
|
|
1270
|
+
drift = detectBatchStateDrift(batch.raw, rebuilt, journalEvents, classifiedTasks);
|
|
1271
|
+
}
|
|
1154
1272
|
signals.stateDrift = drift;
|
|
1155
1273
|
signals.rebuiltFromJournal = rebuilt;
|
|
1274
|
+
if (healed.reconciled) {
|
|
1275
|
+
signals.journalEvents = journalEvents;
|
|
1276
|
+
signals.tasks = classifiedTasks;
|
|
1277
|
+
signals.hasRunningTasks = classifiedTasks.some((task) => task.classification === "running");
|
|
1278
|
+
signals.hasPendingTasks = classifiedTasks.some((task) => task.classification === "pending");
|
|
1279
|
+
signals.allTasksTerminalSuccess =
|
|
1280
|
+
classifiedTasks.length > 0 &&
|
|
1281
|
+
classifiedTasks.every((task) => task.classification === "terminal-success");
|
|
1282
|
+
const healedFailedTask = classifiedTasks.find(
|
|
1283
|
+
(task) => task.classification === "terminal-failure",
|
|
1284
|
+
);
|
|
1285
|
+
signals.failedTaskId = healedFailedTask?.taskId ?? signals.failedTaskId;
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
if (batch.raw) {
|
|
1290
|
+
syncPersistedClassifications({ projectRoot, state: batch.raw });
|
|
1156
1291
|
}
|
|
1157
1292
|
|
|
1158
1293
|
signals.orphanRunning = detectOrphanRunning({
|
|
1159
1294
|
phase: batch.phase,
|
|
1160
|
-
hasRunningTasks,
|
|
1295
|
+
hasRunningTasks: signals.hasRunningTasks,
|
|
1161
1296
|
tasks: classifiedTasks,
|
|
1162
1297
|
lanes: batch.lanes,
|
|
1163
1298
|
raw: batch.raw,
|
|
@@ -1282,12 +1417,19 @@ export function reconcileBatch(ctx, _lightRetry = false) {
|
|
|
1282
1417
|
failedTaskId != null
|
|
1283
1418
|
? laneTaskBranchForDiagnosis(batch.raw, batch.batchId, failedTaskId)
|
|
1284
1419
|
: null;
|
|
1420
|
+
const driftTaskStatus =
|
|
1421
|
+
failedTaskId != null
|
|
1422
|
+
? String(
|
|
1423
|
+
(batch.raw?.tasks ?? []).find((entry) => entry?.taskId === failedTaskId)?.status ?? "",
|
|
1424
|
+
)
|
|
1425
|
+
: null;
|
|
1285
1426
|
|
|
1286
1427
|
const output = buildDiagnosisOutput(diagnosis, {
|
|
1287
1428
|
batchId: batch.batchId,
|
|
1288
1429
|
phase: batch.phase,
|
|
1289
1430
|
failedTasks: signals.failedTasks,
|
|
1290
1431
|
failedTaskId,
|
|
1432
|
+
driftTaskStatus,
|
|
1291
1433
|
exitReason,
|
|
1292
1434
|
launchFailureKind: resolvedLaunchFailureKind,
|
|
1293
1435
|
gitMerged: git.orchMergedToBase,
|
|
@@ -15,17 +15,34 @@ function waveTasksAllTerminalSuccess(taskIds, classifiedTasks) {
|
|
|
15
15
|
return taskIds.every((taskId) => byId.get(String(taskId))?.classification === "terminal-success");
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/** Diagnoses where terminal-success on disk must not imply wave completed (GitHub #186). */
|
|
19
|
+
const DRIFT_BLOCKING_DIAGNOSES = new Set(["state_drift", "engine_orphaned", "needs_retry"]);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {string|null|undefined} diagnosis
|
|
23
|
+
* @param {string|null|undefined} endedAt
|
|
24
|
+
*/
|
|
25
|
+
function blocksOptimisticWaveCompletion(diagnosis, endedAt) {
|
|
26
|
+
if (!diagnosis || !DRIFT_BLOCKING_DIAGNOSES.has(diagnosis)) return false;
|
|
27
|
+
if (endedAt != null) return false;
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
|
|
18
31
|
/**
|
|
19
32
|
* @param {number} index
|
|
20
33
|
* @param {number} currentWaveIndex
|
|
21
34
|
* @param {string[]} taskIds
|
|
22
35
|
* @param {import("../batch/reconcile.mjs").NormalizedTask[]} [classifiedTasks]
|
|
36
|
+
* @param {{ diagnosis?: string|null, endedAt?: string|null }} [options]
|
|
23
37
|
*/
|
|
24
|
-
function resolveWaveStatus(index, currentWaveIndex, taskIds, classifiedTasks) {
|
|
25
|
-
|
|
38
|
+
function resolveWaveStatus(index, currentWaveIndex, taskIds, classifiedTasks, options = {}) {
|
|
39
|
+
const { diagnosis = null, endedAt = null } = options;
|
|
40
|
+
const blocked = blocksOptimisticWaveCompletion(diagnosis, endedAt);
|
|
41
|
+
|
|
42
|
+
if (!blocked && classifiedTasks?.length && waveTasksAllTerminalSuccess(taskIds, classifiedTasks)) {
|
|
26
43
|
return "completed";
|
|
27
44
|
}
|
|
28
|
-
if (index < currentWaveIndex) return "completed";
|
|
45
|
+
if (!blocked && index < currentWaveIndex) return "completed";
|
|
29
46
|
if (index === currentWaveIndex) return "active";
|
|
30
47
|
return "pending";
|
|
31
48
|
}
|
|
@@ -33,8 +50,9 @@ function resolveWaveStatus(index, currentWaveIndex, taskIds, classifiedTasks) {
|
|
|
33
50
|
/**
|
|
34
51
|
* @param {import("../batch/reconcile.mjs").NormalizedBatchState | Record<string, unknown> | null} batchState
|
|
35
52
|
* @param {import("../batch/reconcile.mjs").NormalizedTask[]} [classifiedTasks]
|
|
53
|
+
* @param {{ diagnosis?: string|null, endedAt?: string|null }} [options]
|
|
36
54
|
*/
|
|
37
|
-
export function buildWaveProgress(batchState, classifiedTasks) {
|
|
55
|
+
export function buildWaveProgress(batchState, classifiedTasks, options = {}) {
|
|
38
56
|
const raw =
|
|
39
57
|
batchState && typeof batchState === "object" && "raw" in batchState
|
|
40
58
|
? /** @type {Record<string, unknown>} */ (batchState.raw)
|
|
@@ -43,6 +61,12 @@ export function buildWaveProgress(batchState, classifiedTasks) {
|
|
|
43
61
|
const wavePlan = Array.isArray(raw.wavePlan) ? raw.wavePlan : [];
|
|
44
62
|
const currentWaveIndex = Number(raw.currentWaveIndex ?? 0);
|
|
45
63
|
const totalWaves = Number(raw.totalWaves ?? wavePlan.length);
|
|
64
|
+
const diagnosis = options.diagnosis ?? null;
|
|
65
|
+
const endedAt =
|
|
66
|
+
options.endedAt ??
|
|
67
|
+
(batchState && typeof batchState === "object" && "endedAt" in batchState
|
|
68
|
+
? /** @type {{ endedAt?: string|null }} */ (batchState).endedAt ?? null
|
|
69
|
+
: null);
|
|
46
70
|
|
|
47
71
|
return {
|
|
48
72
|
currentWaveIndex,
|
|
@@ -52,7 +76,10 @@ export function buildWaveProgress(batchState, classifiedTasks) {
|
|
|
52
76
|
return {
|
|
53
77
|
index,
|
|
54
78
|
taskIds,
|
|
55
|
-
status: resolveWaveStatus(index, currentWaveIndex, taskIds, classifiedTasks
|
|
79
|
+
status: resolveWaveStatus(index, currentWaveIndex, taskIds, classifiedTasks, {
|
|
80
|
+
diagnosis,
|
|
81
|
+
endedAt,
|
|
82
|
+
}),
|
|
56
83
|
};
|
|
57
84
|
}),
|
|
58
85
|
};
|
|
@@ -125,7 +125,10 @@ export function buildDashboardSnapshot(projectRoot) {
|
|
|
125
125
|
now,
|
|
126
126
|
}),
|
|
127
127
|
);
|
|
128
|
-
const waves = buildWaveProgress(batch, classifiedTasks
|
|
128
|
+
const waves = buildWaveProgress(batch, classifiedTasks, {
|
|
129
|
+
diagnosis: reconciliation.diagnosis,
|
|
130
|
+
endedAt: batch?.endedAt ?? null,
|
|
131
|
+
});
|
|
129
132
|
const defaultView = buildDefaultViewStatus(reconciliation, gate);
|
|
130
133
|
|
|
131
134
|
const macroPhase = deriveMacroPhase({
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attached batch orphan risk advisory (GitHub #163, SP-518).
|
|
3
|
+
*
|
|
4
|
+
* When the parent shell backgrounds or exits (SIGKILL / exit 137), an attached
|
|
5
|
+
* engine is orphaned. Doctor warns in non-interactive and agent-harness contexts.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** @typedef {{ id: string, label: string }} AttachedOrphanRiskPattern */
|
|
9
|
+
|
|
10
|
+
/** @type {ReadonlyArray<{ env: string, match?: (value: string) => boolean, id: string, label: string }>} */
|
|
11
|
+
const AUTOMATION_ENV_PATTERNS = [
|
|
12
|
+
{
|
|
13
|
+
env: "SPINE_IS_WORKER",
|
|
14
|
+
match: (value) => value === "1" || value === "true",
|
|
15
|
+
id: "spine_worker_context",
|
|
16
|
+
label: "SPINE_IS_WORKER set (lane worker session)",
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
env: "SPINE_WORKER_RUNNER",
|
|
20
|
+
match: (value) => value.trim().length > 0,
|
|
21
|
+
id: "pi_worker_runner",
|
|
22
|
+
label: "SPINE_WORKER_RUNNER set (pi worker harness)",
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
env: "CI",
|
|
26
|
+
match: (value) => value === "1" || value === "true" || value.length > 0,
|
|
27
|
+
id: "ci_environment",
|
|
28
|
+
label: "CI environment",
|
|
29
|
+
},
|
|
30
|
+
{ env: "GITHUB_ACTIONS", id: "github_actions", label: "GitHub Actions runner" },
|
|
31
|
+
{ env: "GITLAB_CI", id: "gitlab_ci", label: "GitLab CI runner" },
|
|
32
|
+
{ env: "JENKINS_URL", id: "jenkins", label: "Jenkins runner" },
|
|
33
|
+
{ env: "BUILDKITE", id: "buildkite", label: "Buildkite runner" },
|
|
34
|
+
{ env: "CURSOR_TRACE_ID", id: "cursor_agent_shell", label: "Cursor agent shell" },
|
|
35
|
+
{ env: "CURSOR_SESSION_ID", id: "cursor_agent_shell", label: "Cursor agent shell" },
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
const DETACHED_RESUME_SUGGESTED =
|
|
39
|
+
"spine batch start|resume (omit --attached); spine wait --until completed,needs_integrate,failed,aborted --timeout 2h";
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {object} [options]
|
|
43
|
+
* @param {boolean} [options.stdinIsTTY]
|
|
44
|
+
* @param {NodeJS.ProcessEnv} [options.env]
|
|
45
|
+
* @returns {{ risky: boolean, patterns: AttachedOrphanRiskPattern[] }}
|
|
46
|
+
*/
|
|
47
|
+
export function detectAttachedOrphanRiskPatterns({
|
|
48
|
+
stdinIsTTY = process.stdin.isTTY === true,
|
|
49
|
+
env = process.env,
|
|
50
|
+
} = {}) {
|
|
51
|
+
/** @type {AttachedOrphanRiskPattern[]} */
|
|
52
|
+
const patterns = [];
|
|
53
|
+
/** @type {Set<string>} */
|
|
54
|
+
const seen = new Set();
|
|
55
|
+
|
|
56
|
+
if (!stdinIsTTY) {
|
|
57
|
+
patterns.push({
|
|
58
|
+
id: "non_interactive_shell",
|
|
59
|
+
label: "stdin is not a TTY (background or piped shell)",
|
|
60
|
+
});
|
|
61
|
+
seen.add("non_interactive_shell");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
for (const entry of AUTOMATION_ENV_PATTERNS) {
|
|
65
|
+
const raw = env[entry.env];
|
|
66
|
+
if (raw === undefined || raw === "") {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (entry.match && !entry.match(String(raw))) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (seen.has(entry.id)) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
seen.add(entry.id);
|
|
76
|
+
patterns.push({ id: entry.id, label: entry.label });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
risky: patterns.length > 0,
|
|
81
|
+
patterns,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Doctor advisory for attached orphan risk (#163 partial mitigation).
|
|
87
|
+
*
|
|
88
|
+
* @param {object} [options]
|
|
89
|
+
* @param {boolean} [options.stdinIsTTY]
|
|
90
|
+
* @param {NodeJS.ProcessEnv} [options.env]
|
|
91
|
+
*/
|
|
92
|
+
export function buildAttachedOrphanRiskDoctorCheck({
|
|
93
|
+
stdinIsTTY = process.stdin.isTTY === true,
|
|
94
|
+
env = process.env,
|
|
95
|
+
} = {}) {
|
|
96
|
+
const { risky, patterns } = detectAttachedOrphanRiskPatterns({ stdinIsTTY, env });
|
|
97
|
+
|
|
98
|
+
if (!risky) {
|
|
99
|
+
return {
|
|
100
|
+
label: "batch --attached orphan risk (#163)",
|
|
101
|
+
ok: true,
|
|
102
|
+
detail: "interactive terminal — keep --attached in foreground for full batch duration",
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const summary = patterns.map((pattern) => pattern.label).join("; ");
|
|
107
|
+
return {
|
|
108
|
+
label: "batch --attached orphan risk (#163)",
|
|
109
|
+
ok: true,
|
|
110
|
+
warning: true,
|
|
111
|
+
detail: `${summary} — parent shell exit orphans attached engine (exit 137)`,
|
|
112
|
+
suggestedCommand: DETACHED_RESUME_SUGGESTED,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
@@ -32,6 +32,7 @@ import { buildInheritProviderAuthDoctorCheck } from "./agents-model-inherit.mjs"
|
|
|
32
32
|
import { buildAgentModelIdsDoctorCheck } from "./agent-models.mjs";
|
|
33
33
|
import { buildPiExtensionConflictDoctorCheck } from "./pi-extension-conflict.mjs";
|
|
34
34
|
import { buildSupervisorConfigDoctorCheck } from "./supervisor.mjs";
|
|
35
|
+
import { buildAttachedOrphanRiskDoctorCheck } from "./attached-orphan-risk.mjs";
|
|
35
36
|
import { CURSOR_RULES_ROOT_REL } from "../config/cursor-rules/discover.mjs";
|
|
36
37
|
import { RULES_PROFILE_REL_PATH } from "../config/cursor-rules/profile.mjs";
|
|
37
38
|
import {
|
|
@@ -254,6 +255,7 @@ export function runDoctorChecks(projectRoot = process.cwd()) {
|
|
|
254
255
|
record("git worktree support", gitSupportsWorktrees(), { detail: getVersion("git") });
|
|
255
256
|
record("pi installed", commandExists("pi"), { detail: getVersion("pi") });
|
|
256
257
|
checks.push(buildPiExtensionConflictDoctorCheck({ projectRoot }));
|
|
258
|
+
checks.push(buildAttachedOrphanRiskDoctorCheck());
|
|
257
259
|
|
|
258
260
|
const piVersionText = getVersion("pi");
|
|
259
261
|
const minPiVersion = getMinPiVersion();
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import micromatch from "micromatch";
|
|
7
7
|
|
|
8
8
|
import { matchesContractPattern } from "../../batch/contract-verify.mjs";
|
|
9
|
+
import { collectTestCommandScopeWarnings } from "../validate-contract-warn.mjs";
|
|
9
10
|
import { detectCommaInSingleBacktickPathLists } from "./parse-prompt.mjs";
|
|
10
11
|
|
|
11
12
|
/** Operator-facing hint when must-not-change blocks worker orchestration artifacts. */
|
|
@@ -48,7 +49,7 @@ export function resolveContractMode(options = {}) {
|
|
|
48
49
|
|
|
49
50
|
/**
|
|
50
51
|
* @param {ReturnType<import("./parse-prompt.mjs").parseContract>} parsed
|
|
51
|
-
* @param {{ mode?: string, taskId?: string | null, legacyTaskIdPrefixes?: string[] }} [options]
|
|
52
|
+
* @param {{ mode?: string, taskId?: string | null, taskSize?: "S"|"M"|"L"|"XL"|null, legacyTaskIdPrefixes?: string[] }} [options]
|
|
52
53
|
* @returns {{ ok: boolean, errors: string[], warnings: string[], mode: "required" | "optional" | "legacy" }}
|
|
53
54
|
*/
|
|
54
55
|
export function validateContract(parsed, options = {}) {
|
|
@@ -115,6 +116,12 @@ export function validateContract(parsed, options = {}) {
|
|
|
115
116
|
}),
|
|
116
117
|
);
|
|
117
118
|
|
|
119
|
+
warnings.push(
|
|
120
|
+
...collectTestCommandScopeWarnings(parsed, {
|
|
121
|
+
taskSize: options.taskSize ?? null,
|
|
122
|
+
}),
|
|
123
|
+
);
|
|
124
|
+
|
|
118
125
|
return { ok: errors.length === 0, errors, warnings, mode };
|
|
119
126
|
}
|
|
120
127
|
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* Validate-time warnings for Contract testCommand scope on patch-sized tasks (issue #141).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** S/M patch tasks should not chain the integrate-owned full coverage gate in Contract. */
|
|
7
|
+
export const TEST_COMMAND_COVERAGE_FIX_HINT =
|
|
8
|
+
"Remove coverage:check from Contract testCommand on S/M patch tasks; integrate gate runs full coverage at merge. Use scoped node --test for task tests.";
|
|
9
|
+
|
|
10
|
+
/** S/M patch tasks should prefer node --test over npm test (full suite in lane worktrees). */
|
|
11
|
+
export const TEST_COMMAND_NPM_TEST_FIX_HINT =
|
|
12
|
+
"Use scoped node --test path/to.test.mjs instead of npm test on S/M patch tasks.";
|
|
13
|
+
|
|
14
|
+
const PATCH_TASK_SIZES = new Set(["S", "M"]);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Warn when S/M task contracts chain full-suite gates in testCommand.
|
|
18
|
+
*
|
|
19
|
+
* @param {ReturnType<import("./packet/parse-prompt.mjs").parseContract>} parsed
|
|
20
|
+
* @param {{ taskSize?: "S"|"M"|"L"|"XL"|null }} [options]
|
|
21
|
+
* @returns {string[]}
|
|
22
|
+
*/
|
|
23
|
+
export function collectTestCommandScopeWarnings(parsed, options = {}) {
|
|
24
|
+
const taskSize = options.taskSize ?? null;
|
|
25
|
+
if (!PATCH_TASK_SIZES.has(taskSize)) {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const testCommand = parsed?.testCommand;
|
|
30
|
+
if (!testCommand || testCommand === "true") {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** @type {string[]} */
|
|
35
|
+
const warnings = [];
|
|
36
|
+
|
|
37
|
+
if (/\bcoverage:check\b/.test(testCommand)) {
|
|
38
|
+
warnings.push(
|
|
39
|
+
`Contract testCommand chains full coverage gate (coverage:check) on Size ${taskSize} patch task. ${TEST_COMMAND_COVERAGE_FIX_HINT}`,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (/\bnpm test\b/.test(testCommand)) {
|
|
44
|
+
warnings.push(
|
|
45
|
+
`Contract testCommand uses npm test on Size ${taskSize} patch task. ${TEST_COMMAND_NPM_TEST_FIX_HINT}`,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return warnings;
|
|
50
|
+
}
|