pi-spine 1.10.1 → 2.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-spine",
3
- "version": "1.10.1",
3
+ "version": "2.0.0",
4
4
  "description": "Orchestration spine for long-running pi development",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -298,6 +298,7 @@ Use [references/prompt-template.md](references/prompt-template.md). Spine-specif
298
298
  - **Coverage gate** — when the task changes application code, add a coverage verification checkbox in the Testing step using `testing.testWithCoverage` (≥77% line coverage policy)
299
299
  - **Contract (required for new SP-\* tasks)** — add `## Contract` after `## File Scope` using [references/contract-template.md](references/contract-template.md). Include `testCommand` for code tasks; use `` `true` `` for docs-only S tasks. When `testCommand` is `` `true` `` (docs-only), **always** include `fileScopeMustChange` listing at least one documentation deliverable path — without it, workers can pass contract by creating only `.DONE` (SP-214 batch `20260612T204048`, SP-457 batch `20260703T022335`). When using `fileScopeMustNotChange`, follow parallel-only semantics and never ban `spine-tasks/**` (see contract template and [File Scope and parallel batches](#file-scope-and-parallel-batches)). Legacy `TP-*` packets may omit Contract when `contract.legacyTaskIdPrefixes` includes `TP-`.
300
300
  - **Completion** — worker creates `{task-folder}/.DONE`; batch engine may auto-commit remaining work
301
+ - **Documentation Requirements ↔ File Scope ([#144](https://github.com/beettlle/pi-spine/issues/144))** — every path under **Must Update** in `## Documentation Requirements` **must** also appear in `## File Scope`. Advisory docs belong in **Check If Affected**, not Must Update. Example: if Must Update lists `docs/adoption/operator-runbook.md`, add that path to File Scope alongside code paths — otherwise workers must choose between scope and documentation obligations (SP-435, SP-451).
301
302
 
302
303
  ### Step 5: Create STATUS.md
303
304
 
@@ -20,16 +20,6 @@ Review Level 0 is ONLY for trivial changes. Most M+ tasks need Level ≥1.
20
20
 
21
21
  > **Real-pi batches (SP-195/SP-278):** Do **not** add per-step "Call `spine_review_step`" checkboxes for Review Level ≥ 1. The batch engine runs plan, code, and final reviews after worker `.DONE`. Stub batches (`SPINE_WORKER_STUB=1`) may still use in-worker stub plan review via the tool when a checkpoint marker requires it.
22
22
 
23
- ## Canonical Task Folder
24
-
25
- ```
26
- [FULL_PATH_TO_TASK_FOLDER]/
27
- ├── PROMPT.md ← This file (immutable above --- divider)
28
- ├── STATUS.md ← Execution state (worker updates this)
29
- ├── .reviews/ ← Reviewer output (created by the orchestrator runtime)
30
- └── .DONE ← Created when complete
31
- ```
32
-
33
23
  ## Mission
34
24
 
35
25
  [One paragraph: what you're building and why it matters]
@@ -50,10 +40,7 @@ Review Level 0 is ONLY for trivial changes. Most M+ tasks need Level ≥1.
50
40
 
51
41
  > Only list docs the worker actually needs. Less is better.
52
42
 
53
- **Tier 2 (area context):**
54
43
  - `[path/to/CONTEXT.md]`
55
-
56
- **Tier 3 (load only if needed):**
57
44
  - `[path/to/specific-doc.md]` — [why needed]
58
45
 
59
46
  ## Environment
@@ -69,6 +56,7 @@ Review Level 0 is ONLY for trivial changes. Most M+ tasks need Level ≥1.
69
56
 
70
57
  - `[path/to/file.ext]`
71
58
  - `[path/to/directory/*]`
59
+ - `[docs/adoption/operator-runbook.md]` — include when listed under Documentation Requirements **Must Update**
72
60
 
73
61
  ## Contract
74
62
 
@@ -109,7 +97,6 @@ Review Level 0 is ONLY for trivial changes. Most M+ tasks need Level ≥1.
109
97
  - [ ] [Specific, verifiable task]
110
98
  - [ ] [Specific, verifiable task]
111
99
  - [ ] [Specific, verifiable task]
112
- - [ ] Run targeted tests: `[test command] --changed` or specific test files
113
100
 
114
101
  **Artifacts:**
115
102
  - `path/to/file` (new | modified)
@@ -118,9 +105,7 @@ Review Level 0 is ONLY for trivial changes. Most M+ tasks need Level ≥1.
118
105
 
119
106
  > **Required for every task** — including docs-only and Review Level 0 packets.
120
107
  > ZERO test failures allowed. This step runs the FULL test suite as a quality gate.
121
- > Earlier steps should use **targeted** tests for fast feedback — e.g.
122
- > `node --experimental-strip-types --test tests/feature.test.mjs` (not `npm test -- path`,
123
- > which runs the full suite in lane worktrees; see SP-522).
108
+ > Use `testCommand` from `## Contract` (often chains `npm run typecheck` with tests).
124
109
  >
125
110
  > **Docs-only tasks:** keep this step; run the full test suite. Omit the coverage-gate
126
111
  > checkbox below when the task does not change application code.
@@ -129,7 +114,6 @@ Review Level 0 is ONLY for trivial changes. Most M+ tasks need Level ≥1.
129
114
  - [ ] Run coverage gate: `[testWithCoverage command, e.g. npm run coverage:check]` — **≥77% line coverage** on in-scope changed code (code-related tasks only; omit for docs-only)
130
115
  - [ ] Run integration tests (if applicable)
131
116
  - [ ] Fix all failures
132
- - [ ] Build passes: `[build command]`
133
117
 
134
118
  ### Step [N]: Documentation & Delivery
135
119
 
@@ -139,8 +123,12 @@ Review Level 0 is ONLY for trivial changes. Most M+ tasks need Level ≥1.
139
123
 
140
124
  ## Documentation Requirements
141
125
 
126
+ > **File Scope rule ([#144](https://github.com/beettlle/pi-spine/issues/144)):** Every path under **Must Update**
127
+ > **must** also appear in `## File Scope`. If a doc is advisory only, list it under **Check If Affected**
128
+ > instead — do not require workers to edit paths outside File Scope.
129
+
142
130
  **Must Update:**
143
- - `[path/to/doc.md]` — [what to add/change]
131
+ - `[path/to/doc.md]` — [what to add/change] *(also list this path in `## File Scope`)*
144
132
 
145
133
  **Check If Affected:**
146
134
  - `[path/to/doc.md]` — [update if relevant]
@@ -173,6 +161,8 @@ for this task MUST include the task ID for traceability:
173
161
 
174
162
  ## Amendments (Added During Execution)
175
163
 
164
+ > Rarely used — workers normally log discoveries in STATUS.md Notes instead.
165
+
176
166
  <!-- Workers add amendments here if issues discovered during execution.
177
167
  Format:
178
168
  ### Amendment N — YYYY-MM-DD HH:MM
@@ -233,7 +223,6 @@ this from PROMPT.md.
233
223
  - [ ] Coverage gate passes (≥77% line coverage on in-scope code, when applicable)
234
224
  - [ ] Integration tests (if applicable)
235
225
  - [ ] All failures fixed
236
- - [ ] Build passes
237
226
 
238
227
  ---
239
228
 
@@ -2,7 +2,7 @@
2
2
  * Lane worker watch helpers — stall anchor slides on worker_alive while running (SP-341 / #32).
3
3
  */
4
4
 
5
- /** @typedef {"launching" | "pi" | "verify" | "unknown"} WorkerPhase */
5
+ /** @typedef {"launching" | "pi" | "verify" | "subprocess" | "unknown"} WorkerPhase */
6
6
  /** @typedef {"worker_alive" | "checkpoint" | "file_scope_activity"} HeartbeatKind */
7
7
 
8
8
  /**
@@ -11,7 +11,9 @@
11
11
  * @param {HeartbeatKind} params.heartbeatKind
12
12
  */
13
13
  export function shouldSlideStallAnchorOnHeartbeat({ workerPhase, heartbeatKind }) {
14
- return workerPhase === "pi" && heartbeatKind === "worker_alive";
14
+ return (
15
+ (workerPhase === "pi" || workerPhase === "subprocess") && heartbeatKind === "worker_alive"
16
+ );
15
17
  }
16
18
 
17
19
  /**
@@ -0,0 +1,214 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * Subprocess heartbeat signals for long-running worker steps (issue #134 / SP-548).
4
+ */
5
+
6
+ /** @typedef {"launching" | "pi" | "verify" | "subprocess" | "unknown"} WorkerPhase */
7
+
8
+ const SUBPROCESS_COMMAND_MAX_LEN = 120;
9
+
10
+ const SUBPROCESS_FRIENDLY_LABELS = Object.freeze([
11
+ [/^npm\s+run\s+coverage(?::\w+)?/i, "coverage"],
12
+ [/^npm\s+run\s+typecheck/i, "typecheck"],
13
+ [/^npm\s+test\b/i, "tests"],
14
+ [/^node\s+--test\b/i, "tests"],
15
+ ]);
16
+
17
+ const SUBPROCESS_STRING_REDACT_PATTERNS = [
18
+ /(?:bearer|token|secret|password|api[_-]?key)\s*[:=]\s*\S+/gi,
19
+ /sk-[a-zA-Z0-9]{20,}/g,
20
+ /ghp_[a-zA-Z0-9]{20,}/g,
21
+ /\b[A-Z][A-Z0-9_]*=\S+/g,
22
+ ];
23
+
24
+ /**
25
+ * @param {string} text
26
+ */
27
+ function redactSubprocessCommandText(text) {
28
+ let out = text;
29
+ for (const pattern of SUBPROCESS_STRING_REDACT_PATTERNS) {
30
+ out = out.replace(pattern, "[REDACTED]");
31
+ }
32
+ return out.replace(/\s+/g, " ").trim();
33
+ }
34
+
35
+ /**
36
+ * @param {string} raw
37
+ */
38
+ function stripLeadingEnvAssignments(command) {
39
+ let rest = command.trim();
40
+ while (/^[A-Za-z_][A-Za-z0-9_]*=\S+\s+/.test(rest)) {
41
+ rest = rest.replace(/^[A-Za-z_][A-Za-z0-9_]*=\S+\s+/, "");
42
+ }
43
+ return rest.trim();
44
+ }
45
+
46
+ /**
47
+ * Redact secrets and shorten a subprocess command for heartbeat payloads.
48
+ *
49
+ * @param {string} raw
50
+ */
51
+ export function redactSubprocessCommand(raw) {
52
+ if (!raw || typeof raw !== "string") return null;
53
+ const head = raw.split(/\s*(?:&&|;|\|)\s*/)[0]?.trim() ?? "";
54
+ if (!head) return null;
55
+ const withoutEnv = stripLeadingEnvAssignments(head);
56
+ const redacted = redactSubprocessCommandText(withoutEnv);
57
+ const trimmed =
58
+ redacted.length > SUBPROCESS_COMMAND_MAX_LEN
59
+ ? `${redacted.slice(0, SUBPROCESS_COMMAND_MAX_LEN - 1)}…`
60
+ : redacted;
61
+ for (const [pattern, label] of SUBPROCESS_FRIENDLY_LABELS) {
62
+ if (pattern.test(trimmed)) return label;
63
+ }
64
+ return trimmed;
65
+ }
66
+
67
+ /**
68
+ * @param {object} event
69
+ * @param {object} filter
70
+ * @param {number} [filter.laneNumber]
71
+ * @param {string} [filter.laneId]
72
+ * @param {string} [filter.taskId]
73
+ */
74
+ function subprocessEventMatches(event, { laneNumber, laneId, taskId }) {
75
+ const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
76
+ const expectedLaneId =
77
+ laneNumber != null ? `lane-${laneNumber}` : typeof laneId === "string" ? laneId : null;
78
+ if (taskId && event.taskId && event.taskId !== taskId) return false;
79
+ if (payload.taskId && taskId && payload.taskId !== taskId) return false;
80
+ if (expectedLaneId && event.laneId && event.laneId !== expectedLaneId) return false;
81
+ if (expectedLaneId && payload.laneId && payload.laneId !== expectedLaneId) return false;
82
+ if (laneNumber != null && payload.laneNumber != null && payload.laneNumber !== laneNumber) {
83
+ return false;
84
+ }
85
+ return true;
86
+ }
87
+
88
+ /**
89
+ * Latest active subprocess signal from worker journal events (issue #134 / SP-548).
90
+ *
91
+ * @param {object[]} events
92
+ * @param {object} filter
93
+ * @param {number} [filter.laneNumber]
94
+ * @param {string} [filter.laneId]
95
+ * @param {string} [filter.taskId]
96
+ */
97
+ export function findLatestSubprocessSignal(events, { laneNumber, laneId, taskId }) {
98
+ for (let index = events.length - 1; index >= 0; index -= 1) {
99
+ const event = events[index];
100
+ if (!subprocessEventMatches(event, { laneNumber, laneId, taskId })) continue;
101
+
102
+ const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
103
+ const ts = Date.parse(event.timestamp);
104
+ if (Number.isNaN(ts)) continue;
105
+
106
+ if (event.type === "task.subprocess_ended") {
107
+ return null;
108
+ }
109
+
110
+ const rawCommand =
111
+ typeof payload.subprocessCommand === "string"
112
+ ? payload.subprocessCommand
113
+ : typeof payload.subprocessLabel === "string"
114
+ ? payload.subprocessLabel
115
+ : null;
116
+ if (!rawCommand) continue;
117
+
118
+ if (event.type === "task.subprocess_active" || event.type === "task.step_completed") {
119
+ const subprocessCommand = redactSubprocessCommand(rawCommand);
120
+ if (!subprocessCommand) continue;
121
+ return { subprocessCommand, subprocessStartedAtMs: ts };
122
+ }
123
+ }
124
+
125
+ return null;
126
+ }
127
+
128
+ /**
129
+ * @param {WorkerPhase} enginePhase
130
+ * @param {object | null | undefined} signals
131
+ */
132
+ export function resolveEffectiveWorkerPhase(enginePhase, signals) {
133
+ if (signals?.subprocessCommand) return "subprocess";
134
+ return enginePhase;
135
+ }
136
+
137
+ /**
138
+ * Progress-class heartbeat fields are omitted during launcher preflight so retries
139
+ * do not reuse stale STATUS / git checkpoint signals from a prior attempt.
140
+ *
141
+ * @param {object} signals
142
+ * @param {WorkerPhase} workerPhase
143
+ * @param {"worker_alive" | "checkpoint" | "file_scope_activity"} heartbeatKind
144
+ */
145
+ export function buildHeartbeatPayloadFields(signals, workerPhase, heartbeatKind) {
146
+ const effectivePhase = resolveEffectiveWorkerPhase(workerPhase, signals);
147
+ const includeProgressFields =
148
+ effectivePhase !== "launching" &&
149
+ (heartbeatKind === "checkpoint" || heartbeatKind === "file_scope_activity");
150
+
151
+ /** @type {Record<string, unknown>} */
152
+ const payload = {
153
+ statusMtimeMs: null,
154
+ lastCommitAtMs: null,
155
+ fileScopeMtimeMs: null,
156
+ dirtyPathCount: 0,
157
+ };
158
+
159
+ if (effectivePhase === "subprocess" && signals?.subprocessCommand) {
160
+ payload.subprocessCommand = signals.subprocessCommand;
161
+ payload.subprocessStartedAtMs = signals.subprocessStartedAtMs ?? null;
162
+ }
163
+
164
+ if (!includeProgressFields) {
165
+ return payload;
166
+ }
167
+
168
+ return {
169
+ ...payload,
170
+ statusMtimeMs: signals.statusMtimeMs,
171
+ lastCommitAtMs: signals.lastCommitAtMs,
172
+ fileScopeMtimeMs: signals.fileScopeMtimeMs,
173
+ dirtyPathCount: signals.dirtyPaths?.length ?? 0,
174
+ };
175
+ }
176
+
177
+ /**
178
+ * Bounded lane.progress_snapshot payload (issue #48).
179
+ *
180
+ * @param {object} signals
181
+ * @param {WorkerPhase} workerPhase
182
+ */
183
+ export function buildProgressSnapshotPayload(signals, workerPhase) {
184
+ const effectivePhase = resolveEffectiveWorkerPhase(workerPhase, signals);
185
+ /** @type {Record<string, unknown>} */
186
+ const payload = {
187
+ workerPhase: effectivePhase,
188
+ dirtyPathCount: signals.dirtyPaths?.length ?? 0,
189
+ lastCommitAtMs: signals.lastCommitAtMs ?? null,
190
+ statusMtimeMs: signals.statusMtimeMs ?? null,
191
+ stepCompletedAtMs: signals.stepCompletedAtMs ?? null,
192
+ };
193
+ if (effectivePhase === "subprocess" && signals?.subprocessCommand) {
194
+ payload.subprocessCommand = signals.subprocessCommand;
195
+ payload.subprocessStartedAtMs = signals.subprocessStartedAtMs ?? null;
196
+ }
197
+ return payload;
198
+ }
199
+
200
+ /**
201
+ * @param {object | null} prev
202
+ * @param {object} next
203
+ */
204
+ export function progressSnapshotPayloadChanged(prev, next) {
205
+ if (!prev) return true;
206
+ if (prev.workerPhase !== next.workerPhase) return true;
207
+ if (prev.dirtyPathCount !== next.dirtyPathCount) return true;
208
+ if (prev.lastCommitAtMs !== next.lastCommitAtMs) return true;
209
+ if (prev.statusMtimeMs !== next.statusMtimeMs) return true;
210
+ if (prev.stepCompletedAtMs !== next.stepCompletedAtMs) return true;
211
+ if (prev.subprocessCommand !== next.subprocessCommand) return true;
212
+ if (prev.subprocessStartedAtMs !== next.subprocessStartedAtMs) return true;
213
+ return false;
214
+ }
@@ -11,6 +11,12 @@ import {
11
11
  resolveDebouncedScopedDirtyPaths,
12
12
  resolveFileScopeMtimeMs,
13
13
  } from "./heartbeat-git-debounce.mjs";
14
+ import {
15
+ findLatestSubprocessSignal,
16
+ resolveEffectiveWorkerPhase,
17
+ buildHeartbeatPayloadFields,
18
+ buildProgressSnapshotPayload,
19
+ } from "./heartbeat-subprocess.mjs";
14
20
 
15
21
  export {
16
22
  clearGitPorcelainDebounceCache,
@@ -18,6 +24,15 @@ export {
18
24
  resetGitPorcelainCallCount,
19
25
  } from "./heartbeat-git-debounce.mjs";
20
26
 
27
+ export {
28
+ findLatestSubprocessSignal,
29
+ redactSubprocessCommand,
30
+ resolveEffectiveWorkerPhase,
31
+ buildHeartbeatPayloadFields,
32
+ buildProgressSnapshotPayload,
33
+ progressSnapshotPayloadChanged,
34
+ } from "./heartbeat-subprocess.mjs";
35
+
21
36
  const DEFAULT_STALL_TIMEOUT_MIN = 60;
22
37
  const DEFAULT_GRACE_AFTER_PROGRESS_MIN = 15;
23
38
  const DEFAULT_HEARTBEAT_INTERVAL_MIN = 10;
@@ -30,7 +45,7 @@ const CHECKPOINT_WARNING_SUGGESTION =
30
45
  "Commit step work and call spine_report_progress so stall grace tracks checkpoints, not file edits alone.";
31
46
 
32
47
  /** @typedef {"worker_alive" | "checkpoint" | "file_scope_activity"} HeartbeatKind */
33
- /** @typedef {"launching" | "pi" | "verify" | "unknown"} WorkerPhase */
48
+ /** @typedef {"launching" | "pi" | "verify" | "subprocess" | "unknown"} WorkerPhase */
34
49
 
35
50
  /** @type {readonly HeartbeatKind[]} */
36
51
  export const HEARTBEAT_KINDS = Object.freeze([
@@ -40,7 +55,13 @@ export const HEARTBEAT_KINDS = Object.freeze([
40
55
  ]);
41
56
 
42
57
  /** @type {readonly WorkerPhase[]} */
43
- export const WORKER_PHASES = Object.freeze(["launching", "pi", "verify", "unknown"]);
58
+ export const WORKER_PHASES = Object.freeze([
59
+ "launching",
60
+ "pi",
61
+ "verify",
62
+ "subprocess",
63
+ "unknown",
64
+ ]);
44
65
 
45
66
  /**
46
67
  * @param {object} [config]
@@ -196,6 +217,8 @@ export function collectProgressSignals({
196
217
  );
197
218
 
198
219
  let stepCompletedAtMs = null;
220
+ let subprocessCommand = null;
221
+ let subprocessStartedAtMs = null;
199
222
  if (journalContext?.projectRoot && journalContext?.batchId) {
200
223
  const events = readJournalEventsCached(journalContext.projectRoot, journalContext.batchId);
201
224
  stepCompletedAtMs = findLatestStepCompletedMs(events, {
@@ -203,6 +226,15 @@ export function collectProgressSignals({
203
226
  laneId: journalContext.laneId,
204
227
  taskId: journalContext.taskId,
205
228
  });
229
+ const subprocess = findLatestSubprocessSignal(events, {
230
+ laneNumber: journalContext.laneNumber,
231
+ laneId: journalContext.laneId,
232
+ taskId: journalContext.taskId,
233
+ });
234
+ if (subprocess) {
235
+ subprocessCommand = subprocess.subprocessCommand;
236
+ subprocessStartedAtMs = subprocess.subprocessStartedAtMs;
237
+ }
206
238
  }
207
239
 
208
240
  return {
@@ -211,6 +243,8 @@ export function collectProgressSignals({
211
243
  fileScopeMtimeMs,
212
244
  stepCompletedAtMs,
213
245
  dirtyPaths,
246
+ subprocessCommand,
247
+ subprocessStartedAtMs,
214
248
  };
215
249
  }
216
250
 
@@ -323,66 +357,6 @@ export function resolveHeartbeatKind({
323
357
  return "worker_alive";
324
358
  }
325
359
 
326
- /**
327
- * Progress-class heartbeat fields are omitted during launcher preflight so retries
328
- * do not reuse stale STATUS / git checkpoint signals from a prior attempt.
329
- *
330
- * @param {object} signals
331
- * @param {WorkerPhase} workerPhase
332
- * @param {HeartbeatKind} heartbeatKind
333
- */
334
- export function buildHeartbeatPayloadFields(signals, workerPhase, heartbeatKind) {
335
- const includeProgressFields =
336
- workerPhase !== "launching" &&
337
- (heartbeatKind === "checkpoint" || heartbeatKind === "file_scope_activity");
338
-
339
- if (!includeProgressFields) {
340
- return {
341
- statusMtimeMs: null,
342
- lastCommitAtMs: null,
343
- fileScopeMtimeMs: null,
344
- dirtyPathCount: 0,
345
- };
346
- }
347
-
348
- return {
349
- statusMtimeMs: signals.statusMtimeMs,
350
- lastCommitAtMs: signals.lastCommitAtMs,
351
- fileScopeMtimeMs: signals.fileScopeMtimeMs,
352
- dirtyPathCount: signals.dirtyPaths?.length ?? 0,
353
- };
354
- }
355
-
356
- /**
357
- * Bounded lane.progress_snapshot payload (issue #48).
358
- *
359
- * @param {object} signals
360
- * @param {WorkerPhase} workerPhase
361
- */
362
- export function buildProgressSnapshotPayload(signals, workerPhase) {
363
- return {
364
- workerPhase,
365
- dirtyPathCount: signals.dirtyPaths?.length ?? 0,
366
- lastCommitAtMs: signals.lastCommitAtMs ?? null,
367
- statusMtimeMs: signals.statusMtimeMs ?? null,
368
- stepCompletedAtMs: signals.stepCompletedAtMs ?? null,
369
- };
370
- }
371
-
372
- /**
373
- * @param {object | null} prev
374
- * @param {object} next
375
- */
376
- export function progressSnapshotPayloadChanged(prev, next) {
377
- if (!prev) return true;
378
- if (prev.workerPhase !== next.workerPhase) return true;
379
- if (prev.dirtyPathCount !== next.dirtyPathCount) return true;
380
- if (prev.lastCommitAtMs !== next.lastCommitAtMs) return true;
381
- if (prev.statusMtimeMs !== next.statusMtimeMs) return true;
382
- if (prev.stepCompletedAtMs !== next.stepCompletedAtMs) return true;
383
- return false;
384
- }
385
-
386
360
  /**
387
361
  * @param {object} params
388
362
  * @param {number} params.now
@@ -430,13 +404,14 @@ export function recordLaneHeartbeat({
430
404
  workerPhase = "unknown",
431
405
  heartbeatKind = "worker_alive",
432
406
  }) {
407
+ const effectivePhase = resolveEffectiveWorkerPhase(workerPhase, signals);
433
408
  const progressFields = buildHeartbeatPayloadFields(signals, workerPhase, heartbeatKind);
434
409
  appendJournalEvent(projectRoot, batchId, "lane.heartbeat", {
435
410
  laneNumber,
436
411
  taskId,
437
412
  correlationId,
438
413
  heartbeatKind,
439
- workerPhase,
414
+ workerPhase: effectivePhase,
440
415
  ...progressFields,
441
416
  });
442
417
  }
@@ -227,8 +227,12 @@ function renderLanes(lanes, laneTableSummary, tailActivity, expandedLaneId) {
227
227
  tr.dataset.laneId = lane.laneId;
228
228
  tr.setAttribute("aria-expanded", lane.laneId === expandedLaneId ? "true" : "false");
229
229
  const throughput = lane.throughput ?? {};
230
- const failedCount = throughput.failedCount ?? 0;
231
- const isTaskFailed = failedCount > 0 || lane.activityPhase === "failed";
230
+ const isTerminalFailure = lane.activityPhase === "failed";
231
+ // Completed lanes use terminal outcome only; failedCount stays a retry metric.
232
+ const isTaskFailed =
233
+ lane.status === "completed"
234
+ ? isTerminalFailure
235
+ : (throughput.failedCount ?? 0) > 0 || isTerminalFailure;
232
236
  const isTaskSucceeded = lane.status === "completed" && !isTaskFailed;
233
237
  const isTaskRunning = lane.status === "running" && !isTaskFailed;
234
238
  if (isTaskFailed) tr.classList.add("task-failed");
@@ -17,6 +17,7 @@ import {
17
17
  } from "../batch/journal.mjs";
18
18
  import { resolveStallConfig } from "../batch/heartbeat.mjs";
19
19
  import { loadSpineConfig } from "../config/spine-config-load.mjs";
20
+ import { formatElapsedMs } from "./lane-throughput.mjs";
20
21
  import {
21
22
  deriveLanesThroughput,
22
23
  summarizeLaneThroughput,
@@ -39,6 +40,75 @@ import {
39
40
  /** Last N journal events included in dashboard snapshot tail (not full journal per client). */
40
41
  export const DASHBOARD_JOURNAL_TAIL_LIMIT = 20;
41
42
 
43
+ /**
44
+ * @param {number} laneNumber
45
+ * @param {object[]} journalEvents
46
+ */
47
+ export function resolveSubprocessHeartbeatMeta(laneNumber, journalEvents) {
48
+ for (let index = journalEvents.length - 1; index >= 0; index -= 1) {
49
+ const event = journalEvents[index];
50
+ if (event.type !== "lane.heartbeat") continue;
51
+ const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
52
+ if (payload.laneNumber != null && payload.laneNumber !== laneNumber) continue;
53
+ if (event.laneId && event.laneId !== `lane-${laneNumber}`) continue;
54
+ return {
55
+ workerPhase: typeof payload.workerPhase === "string" ? payload.workerPhase : null,
56
+ subprocessCommand:
57
+ typeof payload.subprocessCommand === "string" ? payload.subprocessCommand : null,
58
+ subprocessStartedAtMs:
59
+ payload.subprocessStartedAtMs != null ? Number(payload.subprocessStartedAtMs) : null,
60
+ };
61
+ }
62
+ return { workerPhase: null, subprocessCommand: null, subprocessStartedAtMs: null };
63
+ }
64
+
65
+ /**
66
+ * @param {object} params
67
+ * @param {string} params.subprocessCommand
68
+ * @param {number | null} [params.subprocessStartedAtMs]
69
+ * @param {number} [params.now]
70
+ */
71
+ export function formatSubprocessHeartbeatDisplay({
72
+ subprocessCommand,
73
+ subprocessStartedAtMs,
74
+ now = Date.now(),
75
+ }) {
76
+ const elapsedMs =
77
+ subprocessStartedAtMs != null && Number.isFinite(subprocessStartedAtMs)
78
+ ? Math.max(0, now - subprocessStartedAtMs)
79
+ : null;
80
+ const elapsed = elapsedMs != null ? formatElapsedMs(elapsedMs) : null;
81
+ if (elapsed && elapsed !== "—") {
82
+ return `running ${subprocessCommand} (${elapsed})`;
83
+ }
84
+ return `running ${subprocessCommand}`;
85
+ }
86
+
87
+ /**
88
+ * @param {object[]} lanes
89
+ * @param {object[]} journalEvents
90
+ * @param {number} [now]
91
+ */
92
+ export function enrichLaneRowsWithSubprocessHeartbeat(lanes, journalEvents, now = Date.now()) {
93
+ return (lanes ?? []).map((lane) => {
94
+ const subprocessMeta = resolveSubprocessHeartbeatMeta(lane.laneNumber, journalEvents);
95
+ if (subprocessMeta.workerPhase !== "subprocess" || !subprocessMeta.subprocessCommand) {
96
+ return lane;
97
+ }
98
+ return {
99
+ ...lane,
100
+ workerPhase: subprocessMeta.workerPhase,
101
+ subprocessCommand: subprocessMeta.subprocessCommand,
102
+ subprocessStartedAtMs: subprocessMeta.subprocessStartedAtMs,
103
+ heartbeatDisplay: formatSubprocessHeartbeatDisplay({
104
+ subprocessCommand: subprocessMeta.subprocessCommand,
105
+ subprocessStartedAtMs: subprocessMeta.subprocessStartedAtMs,
106
+ now,
107
+ }),
108
+ };
109
+ });
110
+ }
111
+
42
112
  /**
43
113
  * @param {string} projectRoot
44
114
  */
@@ -105,19 +175,23 @@ export function buildDashboardSnapshot(projectRoot) {
105
175
  });
106
176
  }
107
177
 
108
- const lanes = buildLaneRows({
109
- lanes: batch?.lanes ?? [],
110
- classifiedTasks,
111
- stallConfig,
112
- currentWaveTaskIds,
113
- journalTail,
178
+ const lanes = enrichLaneRowsWithSubprocessHeartbeat(
179
+ buildLaneRows({
180
+ lanes: batch?.lanes ?? [],
181
+ classifiedTasks,
182
+ stallConfig,
183
+ currentWaveTaskIds,
184
+ journalTail,
185
+ journalEvents,
186
+ metricsLines,
187
+ projectRoot,
188
+ batchId: reconciliation.batchId,
189
+ now,
190
+ diagnosis: reconciliation.diagnosis,
191
+ }),
114
192
  journalEvents,
115
- metricsLines,
116
- projectRoot,
117
- batchId: reconciliation.batchId,
118
193
  now,
119
- diagnosis: reconciliation.diagnosis,
120
- });
194
+ );
121
195
  const laneThroughputSummary = summarizeLaneThroughput(
122
196
  deriveLanesThroughput({
123
197
  lanes: batch?.lanes ?? [],