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
|
@@ -20,10 +20,24 @@ Run all pending tasks across multiple dependency waves without manual interventi
|
|
|
20
20
|
|
|
21
21
|
For agent-driven batches (Cursor Agent, pi MonitorCreate, CI), use **detached** start/resume — omit `--attached`. The engine survives parent shell exit; monitor with `spine status --diagnose` and `spine wait`.
|
|
22
22
|
|
|
23
|
+
**Automation rule:** External agents must use `spine batch start|resume --force` (detached) unless the agent process will **block until batch completion**. Never pass `--attached` from subprocesses that return before the batch finishes (Cursor tool shells, CI steps with timeouts, `block_until_ms` backgrounds).
|
|
24
|
+
|
|
23
25
|
Cursor Agent shells may background long commands after **~120 seconds**; an attached engine dies with the parent shell (`engine_orphaned`, exit 137). Run `spine doctor` and heed the `batch --attached orphan risk (#163)` warning.
|
|
24
26
|
|
|
25
27
|
Full policy: [agent-shell-batch-policy.md](../../spine-autonomous-operator/references/agent-shell-batch-policy.md). Use `--attached` only from a persistent interactive terminal kept in foreground for the full batch.
|
|
26
28
|
|
|
29
|
+
### Orphan recovery recipe
|
|
30
|
+
|
|
31
|
+
When diagnosis shows `engine_orphaned` or `worker_orphaned` after a short-lived shell:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
spine batch retry <taskId> # reconciles orphan running → failed
|
|
35
|
+
spine batch resume --force # detached — omit --attached
|
|
36
|
+
spine status --diagnose # confirm diagnosis: running
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Inspect `.spine/runtime/detached-engine.log` when the headline links it — absence of `engine.crash` in the journal usually means parent shell exit, not an engine defect ([#185](https://github.com/beettlle/pi-spine/issues/185)).
|
|
40
|
+
|
|
27
41
|
---
|
|
28
42
|
|
|
29
43
|
## Responsibility split
|
|
@@ -57,7 +71,10 @@ spine gate status
|
|
|
57
71
|
# Inspect .spine/runtime/<batchId>/evidence/
|
|
58
72
|
spine gate approve
|
|
59
73
|
spine integrate
|
|
74
|
+
npm install
|
|
60
75
|
spine batch complete
|
|
76
|
+
npm run release:check 2>&1 | tee /tmp/pi-spine-post-integrate-wave-${WAVE}.log
|
|
77
|
+
test "${PIPESTATUS[0]}" -eq 0 # blocking — see post-integrate-regression-gate.md
|
|
61
78
|
git push origin main
|
|
62
79
|
```
|
|
63
80
|
|
|
@@ -98,7 +115,7 @@ After `spine wait` returns or `spine status --diagnose` reports a non-running st
|
|
|
98
115
|
| `failed` | Inspect journal (`spine journal follow`); fix contract/env before retry |
|
|
99
116
|
| `needs_replan` | Read reviewer feedback in `{taskFolder}/.reviews/final-*.md`; edit PROMPT scope, then retry |
|
|
100
117
|
| `merge_blocked` | Resolve conflicts on orch branch or lane worktree; `spine batch resume --force` |
|
|
101
|
-
| `engine_orphaned` | Do **not** start a second attached engine; `spine batch retry <taskId>`
|
|
118
|
+
| `engine_orphaned` | Do **not** start a second attached engine; follow recovery recipe above — `spine batch retry <taskId>` then `spine batch resume --force` (detached). Headline distinguishes parent shell exit from crash when journal has no `engine.crash` |
|
|
102
119
|
| `worker_orphaned` | `spine batch retry <taskId>` (reconciles orphan running → failed) |
|
|
103
120
|
| `worker_done_missing` | Read worker output log from headline; fix blocker, then `spine batch retry <taskId>` |
|
|
104
121
|
| `completed` | Already landed — run `spine batch complete` if not archived, then push |
|
|
@@ -111,12 +128,14 @@ After `spine wait` returns or `spine status --diagnose` reports a non-running st
|
|
|
111
128
|
| Anti-pattern | Why it fails | Correct approach |
|
|
112
129
|
|--------------|-------------|------------------|
|
|
113
130
|
| `spine batch start … --attached` from Cursor Agent or non-TTY shell | Parent shell backgrounds (~120s) or exits; engine orphaned | Detached start + `spine wait` / `spine status --diagnose` |
|
|
131
|
+
| Cursor background shell + `--attached` (tool `block_until_ms` backgrounds) | Parent exits in ~15–120s; `engine_orphaned` misread as crash | Detached start/resume + recovery recipe (retry → resume --force → diagnose) |
|
|
114
132
|
| Running `spine batch resume --attached` while `spine run sequence --attached` is active | Two engines on the same batch causes state corruption | Use one entry point; kill stale engines first (`spine status --diagnose` to check PIDs) |
|
|
115
133
|
| Approving gate without reading evidence | Merges untested or broken code to main | Always inspect `.spine/runtime/<batchId>/evidence/` before `spine gate approve` |
|
|
116
134
|
| Expecting workers to call `spine_request_gate` for integrate | Workers always receive `not_supported` (FR-SHIP-13) | Agent drives gate approval from the host shell |
|
|
117
135
|
| Using `--auto-approve-gate` with real pi workers | Bypasses evidence review; safety gates block this for real pi | Use per-wave agent loop with explicit gate approval |
|
|
118
|
-
| Starting next wave before land loop completes | Base branch diverges from orch; downstream waves may conflict | Complete `integrate` + `batch complete` + push before next wave |
|
|
136
|
+
| Starting next wave before land loop completes | Base branch diverges from orch; downstream waves may conflict | Complete `integrate` + `batch complete` + post-integrate `release:check` + push before next wave |
|
|
119
137
|
| Bare full-suite `testCommand` with large output | Contract verify exceeds `maxBuffer` (10MB) and fails | Scope `testCommand` to relevant test files |
|
|
138
|
+
| `release:check \| tail` for pass/fail | `tail` exits 0 even when `release:check` failed | Verify exit code; use `tee` + `${PIPESTATUS[0]}` — [post-integrate-regression-gate.md](../../spine-release-operator/references/post-integrate-regression-gate.md) |
|
|
120
139
|
|
|
121
140
|
---
|
|
122
141
|
|
|
@@ -143,7 +162,10 @@ for ((WAVE=0; WAVE<WAVES; WAVE++)); do
|
|
|
143
162
|
spine gate status
|
|
144
163
|
spine gate approve
|
|
145
164
|
spine integrate
|
|
165
|
+
npm install
|
|
146
166
|
spine batch complete
|
|
167
|
+
npm run release:check 2>&1 | tee "/tmp/pi-spine-post-integrate-wave-${WAVE}.log"
|
|
168
|
+
test "${PIPESTATUS[0]}" -eq 0
|
|
147
169
|
git push origin main
|
|
148
170
|
else
|
|
149
171
|
echo "Wave $WAVE ended with diagnosis: $DIAG"
|
|
@@ -23,6 +23,7 @@ Invoke explicitly: `/skill:spine-release-operator` or "run a spine release cycle
|
|
|
23
23
|
| Semver scope budgets | [references/release-profiles.md](references/release-profiles.md) |
|
|
24
24
|
| Issue intake queries | [references/issue-intake-checklist.md](references/issue-intake-checklist.md) |
|
|
25
25
|
| Manifest format | [references/release-manifest-template.md](references/release-manifest-template.md) |
|
|
26
|
+
| Post-integrate regression gate | [references/post-integrate-regression-gate.md](references/post-integrate-regression-gate.md) |
|
|
26
27
|
| npm publish mechanics | `docs/release/npm-publish.md` |
|
|
27
28
|
| Upstream bug filing | [references/issue-template.md](references/issue-template.md) |
|
|
28
29
|
|
|
@@ -48,6 +49,9 @@ Invoke explicitly: `/skill:spine-release-operator` or "run a spine release cycle
|
|
|
48
49
|
- **Always** prioritize documentation issues over enhancements
|
|
49
50
|
- **Always** run `spine gate approve` before `spine integrate`
|
|
50
51
|
- **Always** run `npm install` on `main` after successful integrate
|
|
52
|
+
- **Always** run post-integrate `npm run release:check` on `main` after each wave land loop before starting the next wave or pushing — see [post-integrate-regression-gate.md](references/post-integrate-regression-gate.md)
|
|
53
|
+
- **Never** use `| tail` or `| head` alone to judge `release:check` pass/fail — verify exit code (`$?` or `${PIPESTATUS[0]}`)
|
|
54
|
+
- **Never** `git push origin main` during a release until post-integrate `release:check` exits 0 on current `HEAD`
|
|
51
55
|
- **Do not** execute tasks outside the approved manifest scope
|
|
52
56
|
- **Do not** start a second batch while another batch is **running** on this repo
|
|
53
57
|
- **Never** background `spine batch resume --attached` or `resume --attached --force` ([#163](https://github.com/beettlle/pi-spine/issues/163))
|
|
@@ -308,6 +312,21 @@ spine batch complete
|
|
|
308
312
|
|
|
309
313
|
Verify: `git status` clean, `.DONE` count increased.
|
|
310
314
|
|
|
315
|
+
### 4.3a Post-integrate regression gate (blocking)
|
|
316
|
+
|
|
317
|
+
After **every** land loop (including manual merge / conflict resolution), on current `main`:
|
|
318
|
+
|
|
319
|
+
```bash
|
|
320
|
+
npm run release:check 2>&1 | tee /tmp/pi-spine-post-integrate-wave-${N}.log
|
|
321
|
+
test "${PIPESTATUS[0]}" -eq 0
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
Full reference: [post-integrate-regression-gate.md](references/post-integrate-regression-gate.md).
|
|
325
|
+
|
|
326
|
+
**If non-zero:** fix on `main`, commit, re-run gate. Do **not** start wave N+1, push, or proceed to Phase 5 until green.
|
|
327
|
+
|
|
328
|
+
**Do not** judge pass/fail from `tail` output — `tail` exits 0 even when `release:check` failed.
|
|
329
|
+
|
|
311
330
|
### 4.4 Recovery
|
|
312
331
|
|
|
313
332
|
Always: `spine status --diagnose`
|
|
@@ -335,14 +354,17 @@ spine preflight
|
|
|
335
354
|
git status
|
|
336
355
|
```
|
|
337
356
|
|
|
338
|
-
**pi async (preferred):** `MonitorCreate` with `npm run release:check 2>&1 | tee /tmp/pi-spine-release-check.log`, `timeout: 900000`, `onDone` to read log
|
|
357
|
+
**pi async (preferred):** `MonitorCreate` with `npm run release:check 2>&1 | tee /tmp/pi-spine-release-check.log`, `timeout: 900000`, `onDone` to read **full log** and verify exit 0 — not log tail alone.
|
|
339
358
|
|
|
340
359
|
**Foreground fallback:**
|
|
341
360
|
|
|
342
361
|
```bash
|
|
343
|
-
npm run release:check
|
|
362
|
+
npm run release:check 2>&1 | tee /tmp/pi-spine-release-check.log
|
|
363
|
+
test "${PIPESTATUS[0]}" -eq 0 # or: npm run release:check; echo $?
|
|
344
364
|
```
|
|
345
365
|
|
|
366
|
+
**Do not** use `npm run release:check 2>&1 | tail -20` for pass/fail — verify exit code explicitly.
|
|
367
|
+
|
|
346
368
|
### `release:check` gate (HARD STOP — blocking)
|
|
347
369
|
|
|
348
370
|
`npm run release:check` is **not advisory**. It is a **blocking gate** before any publish checklist or Phase 6.
|
|
@@ -461,6 +483,7 @@ check manifest at spine-tasks/_authoring/release-v{TARGET}/manifest.md →
|
|
|
461
483
|
spine status --diagnose (do not collide with running batch) →
|
|
462
484
|
preflight → for each wave: MonitorCreate batch start (or foreground) → onDone diagnose →
|
|
463
485
|
gate approve → integrate → npm install → batch complete →
|
|
486
|
+
post-integrate release:check (exit 0 required; no tail-only verification) →
|
|
464
487
|
MonitorCreate release:check → HARD STOP if non-zero (fix on main, re-run) → only if exit 0: verify ci.yml green on HEAD (gh run list/watch) → HARD STOP if not green → only then: STOP for publish approval.
|
|
465
488
|
resume --attached --force stays foreground. Post final report with composition table.
|
|
466
489
|
```
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Post-integrate regression gate
|
|
2
|
+
|
|
3
|
+
Operator-enforced full-suite check on `main` after each land loop. The spine CLI does **not** run this automatically — agents and humans must run it explicitly.
|
|
4
|
+
|
|
5
|
+
**Related:** manifest regression gate in [release-manifest-template.md](release-manifest-template.md); SP-560 / `detached-start-orphan-timeout.test.mjs` cross-file drift (v2.1.0).
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## When required (blocking)
|
|
10
|
+
|
|
11
|
+
Run on current `main` after:
|
|
12
|
+
|
|
13
|
+
1. **Standard land loop** — `spine gate approve` → `spine integrate` → `npm install` → `spine batch complete`
|
|
14
|
+
2. **Manual integrate** — `git merge orch/*`, conflict resolution, `human_base_diverged` recovery, or `spine batch complete --detect-manual-merge`
|
|
15
|
+
3. **Before next wave** — do not start wave N+1 until gate passes on `main`
|
|
16
|
+
4. **Before first `git push origin main`** during a release cycle
|
|
17
|
+
5. **Before `npm version`** — Phase 5 `release:check` (same command; re-run if `main` moved)
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Command
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
cd <repo-root>
|
|
25
|
+
npm run release:check 2>&1 | tee /tmp/pi-spine-post-integrate-wave-${WAVE:-main}.log
|
|
26
|
+
test "${PIPESTATUS[0]}" -eq 0
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Equivalent without `tee` (must capture exit code):
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm run release:check
|
|
33
|
+
echo "release:check exit: $?"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
**If exit is non-zero:** STOP. Fix on `main`, commit, re-run gate. Do not start the next wave, push, or tag.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Verification discipline
|
|
41
|
+
|
|
42
|
+
| Do | Do not |
|
|
43
|
+
|----|--------|
|
|
44
|
+
| Run full `npm run release:check` | Pipe through `tail` or `head` for pass/fail decisions |
|
|
45
|
+
| Verify exit code explicitly (`$?` or `${PIPESTATUS[0]}`) | Claim "passed" from truncated log tail |
|
|
46
|
+
| Save log path in manifest publish checklist | Assume scoped task `testCommand` covered full CI suite |
|
|
47
|
+
|
|
48
|
+
**Anti-pattern:** `npm run release:check 2>&1 | tail -20` — `tail` exits 0 even when `release:check` failed.
|
|
49
|
+
|
|
50
|
+
**Preferred in bash scripts:**
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
set -o pipefail
|
|
54
|
+
npm run release:check 2>&1 | tee /tmp/pi-spine-release-check.log
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Manual merge checklist
|
|
60
|
+
|
|
61
|
+
When any of these occurred on the current wave:
|
|
62
|
+
|
|
63
|
+
- [ ] `git merge orch/spine-*` into `main` (not only `spine integrate`)
|
|
64
|
+
- [ ] Merge conflict resolution in production or test files
|
|
65
|
+
- [ ] `spine batch complete --detect-manual-merge`
|
|
66
|
+
- [ ] Diagnosis `human_base_diverged` before integrate
|
|
67
|
+
|
|
68
|
+
Then post-integrate regression gate is **mandatory** before next wave or push. Record log path in manifest.
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Shared-module behavior changes
|
|
73
|
+
|
|
74
|
+
When production code changes user-visible strings, errors, or diagnosis headlines in modules consumed by multiple tests:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
rg -l 'old phrase|OldErrorClass' tests/ src/
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Every test file that asserts on the old behavior must either:
|
|
81
|
+
|
|
82
|
+
- Appear in the task's scoped `testCommand`, or
|
|
83
|
+
- Be covered by this post-integrate `release:check` on `main` before push
|
|
84
|
+
|
|
85
|
+
**Example (SP-560):** Changing orphan headlines in `src/batch/diagnosis*.mjs` required updating both `diagnosis-parent-exit.test.mjs` and `detached-start-orphan-timeout.test.mjs` — scoped contract on the new test alone was insufficient until full suite ran on `main`.
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## Skills that reference this doc
|
|
90
|
+
|
|
91
|
+
| Skill | Section |
|
|
92
|
+
|-------|---------|
|
|
93
|
+
| `spine-release-operator` | Phase 4.3a |
|
|
94
|
+
| `spine-autonomous-operator` | Phase 3.3a |
|
|
95
|
+
| `spine-orchestrate-waves` | Per-wave outer loop |
|
|
96
|
+
| `create-spine-tasks` | Shared-module contract rule |
|
|
@@ -51,12 +51,15 @@ spine status --diagnose
|
|
|
51
51
|
spine gate approve && spine integrate && npm install && spine batch complete
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
**Regression gate** (run after each integrate, before next wave):
|
|
54
|
+
**Regression gate** (run after each integrate, before next wave — full reference: [post-integrate-regression-gate.md](../../skills/spine-release-operator/references/post-integrate-regression-gate.md)):
|
|
55
55
|
|
|
56
56
|
```bash
|
|
57
|
-
npm run
|
|
57
|
+
npm run release:check 2>&1 | tee /tmp/pi-spine-post-integrate-wave-${WAVE:-main}.log
|
|
58
|
+
test "${PIPESTATUS[0]}" -eq 0
|
|
58
59
|
```
|
|
59
60
|
|
|
61
|
+
Do **not** use `| tail` alone for pass/fail — verify exit code.
|
|
62
|
+
|
|
60
63
|
**Operator gates** (human only — sequence does not auto-approve without explicit flags):
|
|
61
64
|
|
|
62
65
|
1. Approve this manifest (operator sign-off on scope)
|
|
@@ -104,8 +107,9 @@ Filled example: [`docs/release/manifest-v1.10.0-example.md`](../../../docs/relea
|
|
|
104
107
|
## Publish checklist (Phase 5–6)
|
|
105
108
|
|
|
106
109
|
- [ ] All release-scoped tasks `.DONE` on `main`
|
|
110
|
+
- [ ] Post-integrate `release:check` green after **each wave** (log paths recorded)
|
|
107
111
|
- [ ] `spine preflight` green
|
|
108
|
-
- [ ] `npm run release:check` green (typecheck, lint, tests, coverage — CI parity)
|
|
112
|
+
- [ ] `npm run release:check` green on final `HEAD` (typecheck, lint, tests, coverage — CI parity)
|
|
109
113
|
- [ ] `git status` clean
|
|
110
114
|
- [ ] Operator approved publish bump type: patch | minor | major
|
|
111
115
|
- [ ] `npm version <bump>` + `git push && git push --tags`
|
package/src/batch/abort.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import { archiveBatchStatePath } from "./lifecycle.mjs";
|
|
|
10
10
|
import { appendJournalEvent, journalPath, readJournalEvents, readJournalTail } from "./journal.mjs";
|
|
11
11
|
import { loadBatchStateFile } from "./reconcile.mjs";
|
|
12
12
|
import { appendBatchHistoryEntry } from "./state.mjs";
|
|
13
|
-
import {
|
|
13
|
+
import { removeLaneWorktrees, maxLaneNumberFromBatchState } from "./worktree.mjs";
|
|
14
14
|
import { terminateLaneWorkers } from "./worker-host.mjs";
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -230,19 +230,15 @@ export function abortBatch(ctx) {
|
|
|
230
230
|
|
|
231
231
|
if (hard) {
|
|
232
232
|
const configResult = loadSpineConfig(projectRoot);
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
} catch {
|
|
243
|
-
// best-effort cleanup
|
|
244
|
-
}
|
|
245
|
-
}
|
|
233
|
+
const config = configResult.config ?? {};
|
|
234
|
+
if (shouldCleanupWorktreesOnHardAbort(config)) {
|
|
235
|
+
const laneCount = maxLaneNumberFromBatchState(snapshot);
|
|
236
|
+
removeLaneWorktrees(projectRoot, batchId, laneCount);
|
|
237
|
+
appendJournalEvent(projectRoot, batchId, "batch.worktrees_cleaned", {
|
|
238
|
+
batchId,
|
|
239
|
+
laneCount,
|
|
240
|
+
reason: "hard_abort",
|
|
241
|
+
});
|
|
246
242
|
}
|
|
247
243
|
}
|
|
248
244
|
|
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
journalIndicatesPausedForceResume,
|
|
33
33
|
} from "./orphan-detect.mjs";
|
|
34
34
|
import { classifyTaskDoneSemantics } from "./diagnosis-task-done.mjs";
|
|
35
|
+
import { laneDoneMarkerReadyForPromote } from "./journal-rebuild.mjs";
|
|
35
36
|
import { resolveTasksRoot } from "../config/spine-preflight-lib.mjs";
|
|
36
37
|
import { journalHasTaskCompleted } from "./resume-common.mjs";
|
|
37
38
|
import { startParentSessionMonitor } from "./parent-session-monitor.mjs";
|
|
@@ -393,7 +394,17 @@ export function reconcilePausedResumeDoneInLane({ projectRoot, state, batchId })
|
|
|
393
394
|
batchId,
|
|
394
395
|
lanes,
|
|
395
396
|
});
|
|
396
|
-
if (
|
|
397
|
+
if (
|
|
398
|
+
!laneDoneMarkerReadyForPromote({
|
|
399
|
+
projectRoot,
|
|
400
|
+
batchId,
|
|
401
|
+
task,
|
|
402
|
+
lanes,
|
|
403
|
+
classified,
|
|
404
|
+
})
|
|
405
|
+
) {
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
397
408
|
if (!journalHasContractVerified(journalEvents, task.taskId)) continue;
|
|
398
409
|
|
|
399
410
|
task.status = "succeeded";
|
|
@@ -3,6 +3,72 @@
|
|
|
3
3
|
* Wave merge failure diagnosis helpers (SP-338 / GitHub #29).
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import {
|
|
7
|
+
isGitignoredArtifactPath,
|
|
8
|
+
listGitignoredArtifactRoots,
|
|
9
|
+
} from "./lane-dirty-check.mjs";
|
|
10
|
+
|
|
11
|
+
const GITIGNORED_MERGE_FAILURE_CLASSES = new Set(["merge_failed_gitignored", "GitignoredDirtyWorktree"]);
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {object} [ctx]
|
|
15
|
+
* @param {string|null} [ctx.exitReason]
|
|
16
|
+
* @param {string|null} [ctx.failureClass]
|
|
17
|
+
* @param {string|null} [ctx.lastError]
|
|
18
|
+
* @param {object[]} [ctx.journalEvents]
|
|
19
|
+
* @returns {boolean}
|
|
20
|
+
*/
|
|
21
|
+
export function inferMergeGitignoredFailure(ctx = {}) {
|
|
22
|
+
const { exitReason, failureClass, lastError, journalEvents } = ctx;
|
|
23
|
+
if (GITIGNORED_MERGE_FAILURE_CLASSES.has(exitReason ?? "")) return true;
|
|
24
|
+
if (GITIGNORED_MERGE_FAILURE_CLASSES.has(failureClass ?? "")) return true;
|
|
25
|
+
|
|
26
|
+
const haystackParts = [exitReason, failureClass, lastError];
|
|
27
|
+
if (Array.isArray(journalEvents)) {
|
|
28
|
+
for (const event of journalEvents) {
|
|
29
|
+
if (event.type !== "batch.merge_failed" && event.type !== "task.failed") continue;
|
|
30
|
+
const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
|
|
31
|
+
haystackParts.push(
|
|
32
|
+
payload.failureClass,
|
|
33
|
+
payload.classification,
|
|
34
|
+
payload.error,
|
|
35
|
+
payload.output,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const haystack = haystackParts.filter(Boolean).join("\n").toLowerCase();
|
|
40
|
+
return (
|
|
41
|
+
haystack.includes("gitignored dirty files only") ||
|
|
42
|
+
haystack.includes("merge_failed_gitignored") ||
|
|
43
|
+
haystack.includes("gitignoreddirtyworktree") ||
|
|
44
|
+
(haystack.includes("git add") && haystack.includes("ignored"))
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param {string|null|undefined} taskBranch
|
|
50
|
+
* @param {string[]|null|undefined} gitignoredPaths
|
|
51
|
+
*/
|
|
52
|
+
export function buildGitignoredMergeRepairCommand(taskBranch, gitignoredPaths) {
|
|
53
|
+
const branchHint = taskBranch ? `git checkout ${taskBranch}` : "git checkout <task-branch>";
|
|
54
|
+
const stetRuntimeCleanRoots = new Set([".review", ".spine/runtime"]);
|
|
55
|
+
if (Array.isArray(gitignoredPaths) && gitignoredPaths.length > 0) {
|
|
56
|
+
const artifactRoots = listGitignoredArtifactRoots(gitignoredPaths);
|
|
57
|
+
const stetRuntimeOnly =
|
|
58
|
+
artifactRoots.length > 0 &&
|
|
59
|
+
artifactRoots.every((root) => stetRuntimeCleanRoots.has(root)) &&
|
|
60
|
+
gitignoredPaths.every((p) => isGitignoredArtifactPath(p));
|
|
61
|
+
if (stetRuntimeOnly) {
|
|
62
|
+
const cleanHint = `git clean -fdX -- ${artifactRoots.join(" ")}`;
|
|
63
|
+
return `${branchHint} && ${cleanHint} && spine batch resume --force`;
|
|
64
|
+
}
|
|
65
|
+
const pathHint = `git rm -r --cached -- ${gitignoredPaths.slice(0, 5).join(" ")}`;
|
|
66
|
+
return `${branchHint} && ${pathHint} && spine batch resume --force`;
|
|
67
|
+
}
|
|
68
|
+
const pathHint = "git rm -r --cached -- <gitignored-paths>";
|
|
69
|
+
return `${branchHint} && ${pathHint} && spine batch resume --force`;
|
|
70
|
+
}
|
|
71
|
+
|
|
6
72
|
/**
|
|
7
73
|
* @param {unknown[]} mergeResults
|
|
8
74
|
* @param {string|null|undefined} lastError
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* Parent-shell exit vs engine crash hints for engine_orphaned diagnosis (SP-560 / #185).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { DETACHED_ENGINE_LOG_REL } from "./detached-spawn.mjs";
|
|
7
|
+
|
|
8
|
+
/** Journal types that indicate an uncaught engine crash (not parent shell exit). */
|
|
9
|
+
const ENGINE_CRASH_JOURNAL_TYPES = new Set(["engine.crash", "engine.uncaught_exception"]);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {object[]} [journalEvents]
|
|
13
|
+
* @returns {boolean}
|
|
14
|
+
*/
|
|
15
|
+
export function journalHasEngineCrash(journalEvents) {
|
|
16
|
+
if (!Array.isArray(journalEvents) || journalEvents.length === 0) return false;
|
|
17
|
+
return journalEvents.some((event) => ENGINE_CRASH_JOURNAL_TYPES.has(event.type));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {object[]} [journalEvents]
|
|
22
|
+
* @returns {boolean}
|
|
23
|
+
*/
|
|
24
|
+
export function journalIndicatesParentExit(journalEvents) {
|
|
25
|
+
if (!Array.isArray(journalEvents) || journalEvents.length === 0) return false;
|
|
26
|
+
return journalEvents.some((event) => {
|
|
27
|
+
if (event.type !== "engine.parent_died") return false;
|
|
28
|
+
const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
|
|
29
|
+
return payload.signal === "parent_exit" || event.signal === "parent_exit";
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {object[]} [journalEvents]
|
|
35
|
+
* @returns {boolean}
|
|
36
|
+
*/
|
|
37
|
+
export function journalHasBatchResumed(journalEvents) {
|
|
38
|
+
if (!Array.isArray(journalEvents) || journalEvents.length === 0) return false;
|
|
39
|
+
return journalEvents.some((event) => event.type === "batch.resumed");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Infer whether engine_orphaned is likely parent shell exit vs engine crash.
|
|
44
|
+
*
|
|
45
|
+
* @param {object} [ctx]
|
|
46
|
+
* @param {object[]} [ctx.journalEvents]
|
|
47
|
+
* @param {boolean} [ctx.staleEnginePid]
|
|
48
|
+
* @returns {{ kind: "parent_exit" | "parent_exit_likely" | "crash" | "unknown", detachedEngineLogRef: string|null }}
|
|
49
|
+
*/
|
|
50
|
+
export function inferEngineOrphanCause(ctx = {}) {
|
|
51
|
+
const { journalEvents, staleEnginePid } = ctx;
|
|
52
|
+
const logRef = staleEnginePid === true ? DETACHED_ENGINE_LOG_REL : null;
|
|
53
|
+
|
|
54
|
+
if (journalHasEngineCrash(journalEvents)) {
|
|
55
|
+
return { kind: "crash", detachedEngineLogRef: logRef };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (journalIndicatesParentExit(journalEvents)) {
|
|
59
|
+
return { kind: "parent_exit", detachedEngineLogRef: logRef };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Detached resume stall (SP-297) — not parent shell exit from attached mode.
|
|
63
|
+
if (journalHasBatchResumed(journalEvents)) {
|
|
64
|
+
return { kind: "unknown", detachedEngineLogRef: logRef };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Attached start orphan without crash journal (#185).
|
|
68
|
+
if (
|
|
69
|
+
Array.isArray(journalEvents) &&
|
|
70
|
+
journalEvents.some((event) => event.type === "batch.started")
|
|
71
|
+
) {
|
|
72
|
+
return { kind: "parent_exit_likely", detachedEngineLogRef: logRef };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return { kind: "unknown", detachedEngineLogRef: logRef };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @param {string} batchLabel
|
|
80
|
+
* @param {object} ctx
|
|
81
|
+
* @param {string|null} [ctx.failedTaskId]
|
|
82
|
+
* @param {{ kind: string, detachedEngineLogRef?: string|null }} [ctx.engineOrphanCause]
|
|
83
|
+
* @returns {string|null}
|
|
84
|
+
*/
|
|
85
|
+
export function buildEngineOrphanParentExitHeadline(batchLabel, ctx = {}) {
|
|
86
|
+
const cause = ctx.engineOrphanCause;
|
|
87
|
+
if (!cause) return null;
|
|
88
|
+
|
|
89
|
+
const taskHint = ctx.failedTaskId ? ` (task ${ctx.failedTaskId} still running)` : "";
|
|
90
|
+
const logHint = cause.detachedEngineLogRef ? ` — see ${cause.detachedEngineLogRef}` : "";
|
|
91
|
+
|
|
92
|
+
if (cause.kind === "parent_exit") {
|
|
93
|
+
return `${batchLabel} attached engine parent shell exited${taskHint} — use detached resume, not a crash${logHint}`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (cause.kind === "parent_exit_likely") {
|
|
97
|
+
return `${batchLabel} engine likely orphaned by parent shell exit${taskHint} — use detached resume (no engine.crash in journal)${logHint}`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (cause.kind === "crash") {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @param {object} ctx
|
|
109
|
+
* @param {string|null} [ctx.failedTaskId]
|
|
110
|
+
* @param {{ kind: string }} [ctx.engineOrphanCause]
|
|
111
|
+
* @returns {string|null}
|
|
112
|
+
*/
|
|
113
|
+
export function buildEngineOrphanParentExitSuggestedCommand(ctx = {}) {
|
|
114
|
+
const cause = ctx.engineOrphanCause;
|
|
115
|
+
if (!cause) return null;
|
|
116
|
+
|
|
117
|
+
if (cause.kind === "parent_exit" || cause.kind === "parent_exit_likely") {
|
|
118
|
+
if (ctx.failedTaskId) {
|
|
119
|
+
return `spine batch retry ${ctx.failedTaskId}`;
|
|
120
|
+
}
|
|
121
|
+
return "spine batch resume --force";
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return null;
|
|
125
|
+
}
|