pi-spine 2.35.0 → 2.36.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-dashboard.mjs +87 -4
- package/package.json +1 -1
- package/src/batch/engine-lanes/queue.mjs +5 -0
- package/src/batch/engine-lanes/vl-slot-dispatch.mjs +227 -0
- package/src/batch/engine-lanes/vl-wave-dispatch.mjs +325 -0
- package/src/batch/engine-scope.mjs +116 -0
- package/src/batch/engine.mjs +28 -95
- package/src/batch/resume-multi-queue.mjs +276 -75
- package/src/dashboard/snapshot-lanes.mjs +97 -2
|
@@ -1,11 +1,42 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* VL slot-pool wiring for multi-task resume waves (SP-899 / #358 partial).
|
|
4
|
+
*
|
|
5
|
+
* Replaces the pre-#358 sticky per-lane resume queues (`Promise.all` across
|
|
6
|
+
* `task.laneNumber` lane queues — the same barrier pattern the engine tick
|
|
7
|
+
* loop had): on resume after pause/orphan, remaining ready virtual lanes
|
|
8
|
+
* (VLs) dispatch onto free physical slots `1..lanes.maxParallel` using the
|
|
9
|
+
* SP-897 helper API (`createVlSlotPool` / `selectReadyVl`) — the same rules
|
|
10
|
+
* as the SP-903 start path (`engine-lanes/vl-wave-dispatch.mjs`):
|
|
11
|
+
*
|
|
12
|
+
* 1. `lanes.maxParallel` caps in-flight VLs via the physical slot pool.
|
|
13
|
+
* 2. Two scope-overlapping VLs never run concurrently (`selectReadyVl`
|
|
14
|
+
* skips blockers; a freed slot journals `lane.slot_conflict_wait`).
|
|
15
|
+
* 3. Same-VL serial ordering: a VL holds at most one slot; its remaining
|
|
16
|
+
* tasks drain serially behind the running task (mid-run steal across a
|
|
17
|
+
* VL queue stays out of scope, #358).
|
|
18
|
+
* 4. No tick barriers: a VL that finishes early frees its slot immediately
|
|
19
|
+
* for the next dispatchable VL (uneven completion).
|
|
20
|
+
*
|
|
21
|
+
* Resume has no persisted `wave.laneAssignments` (planner-only field), so
|
|
22
|
+
* ready VLs are rebuilt from packet file scopes with the planner's own
|
|
23
|
+
* greedy packing predicate (`fileScopesOverlap` via `scopesOverlap`): tasks
|
|
24
|
+
* whose scopes overlap share one VL/serial queue; disjoint tasks get
|
|
25
|
+
* separate VLs and may run in parallel on different slots. Tasks whose
|
|
26
|
+
* packet scope cannot be re-read dispatch with empty scopes (never overlap
|
|
27
|
+
* — resume must not silently drop tasks the way the start path skips them).
|
|
28
|
+
*
|
|
29
|
+
* VL→slot binding (merge affinity): merge keys off
|
|
30
|
+
* `task.laneNumber === lane.laneNumber`, so a re-run task rebinds to its
|
|
31
|
+
* dispatch slot before the run persists state (SP-903 pattern). Already
|
|
32
|
+
* complete tasks keep their sticky lane — their committed evidence lives on
|
|
33
|
+
* that lane's branch.
|
|
4
34
|
*/
|
|
5
35
|
|
|
6
36
|
import path from "node:path";
|
|
7
37
|
import crypto from "node:crypto";
|
|
8
38
|
import {
|
|
39
|
+
loadResumeFileScopePaths,
|
|
9
40
|
resolveTaskFolderInWorktree,
|
|
10
41
|
taskAlreadyComplete,
|
|
11
42
|
taskTerminalSuccessInBatch,
|
|
@@ -18,10 +49,24 @@ import {
|
|
|
18
49
|
runResumedTaskOnLane,
|
|
19
50
|
} from "./resume-multi-lanes.mjs";
|
|
20
51
|
import { runWithQuotaFallback } from "./engine-lanes/quota-fallback-run.mjs";
|
|
52
|
+
import {
|
|
53
|
+
buildConflictWaitPayload,
|
|
54
|
+
createVlSlotPool,
|
|
55
|
+
selectReadyVl,
|
|
56
|
+
scopesOverlap,
|
|
57
|
+
VL_SLOT_CONFLICT_WAIT_EVENT,
|
|
58
|
+
} from "./engine-lanes/vl-slot-dispatch.mjs";
|
|
21
59
|
import { resolveWorkerBackend } from "../config/worker-backend.mjs";
|
|
22
60
|
|
|
23
61
|
/**
|
|
24
|
-
* Build
|
|
62
|
+
* Build resume VL queue entries for one wave and run them through the
|
|
63
|
+
* physical slot pool.
|
|
64
|
+
*
|
|
65
|
+
* Classification (per wave task, same filters as the sticky queue):
|
|
66
|
+
* terminal-success tasks skip; already-complete tasks queue a disk-marking
|
|
67
|
+
* run on their sticky lane; non-resumable tasks skip; remaining resumable
|
|
68
|
+
* tasks greedy-pack into VLs by file-scope overlap and dispatch onto free
|
|
69
|
+
* slots.
|
|
25
70
|
*
|
|
26
71
|
* @param {object} params
|
|
27
72
|
* @returns {Promise<{ ok: true, waveResults: object[], batchAborted: boolean } | { ok: false, result: object }>}
|
|
@@ -36,17 +81,63 @@ export async function executeResumeWave({
|
|
|
36
81
|
waveTaskIds,
|
|
37
82
|
events,
|
|
38
83
|
}) {
|
|
39
|
-
|
|
40
|
-
|
|
84
|
+
const lanes = state.lanes ?? [];
|
|
85
|
+
// Slot pool positions map onto provisioned lanes in laneNumber order, so
|
|
86
|
+
// slot N always resolves to a real lane even when legacy state provisioned
|
|
87
|
+
// fewer lanes than the current config maxParallel.
|
|
88
|
+
const provisionedLanes = [...lanes].sort(
|
|
89
|
+
(a, b) => Number(a?.laneNumber ?? 0) - Number(b?.laneNumber ?? 0),
|
|
90
|
+
);
|
|
41
91
|
let batchAborted = false;
|
|
42
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Ready VL entries in dispatch-priority (wave) order.
|
|
95
|
+
*
|
|
96
|
+
* @type {Array<{ vlId: string, scopes: string[], tasks: Array<{ taskId: string, bindsSlot: boolean, run: (slotLane: object, slotCorrelationId: string) => Promise<object> }> }>}
|
|
97
|
+
*/
|
|
98
|
+
const vlQueue = [];
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Resumable-task run: single-hop quota fallback retry (SP-809) wraps the
|
|
102
|
+
* resumed lane run; an aborted result flags the batch (abort short-
|
|
103
|
+
* circuit) exactly like the sticky queue did.
|
|
104
|
+
*
|
|
105
|
+
* @param {object} task
|
|
106
|
+
* @param {string} taskFolderRel
|
|
107
|
+
* @returns {(slotLane: object, slotCorrelationId: string) => Promise<object>}
|
|
108
|
+
*/
|
|
109
|
+
const makeResumableRun = (task, taskFolderRel) => async (slotLane, slotCorrelationId) =>
|
|
110
|
+
runWithQuotaFallback(
|
|
111
|
+
() =>
|
|
112
|
+
runResumedTaskOnLane({
|
|
113
|
+
projectRoot,
|
|
114
|
+
state,
|
|
115
|
+
batchId,
|
|
116
|
+
config,
|
|
117
|
+
task,
|
|
118
|
+
lane: slotLane,
|
|
119
|
+
taskFolderRel,
|
|
120
|
+
laneCorrelationId: slotCorrelationId,
|
|
121
|
+
}),
|
|
122
|
+
{
|
|
123
|
+
projectRoot,
|
|
124
|
+
batchId,
|
|
125
|
+
state,
|
|
126
|
+
taskId: task.taskId,
|
|
127
|
+
config,
|
|
128
|
+
workerBackend: resolveWorkerBackend(config),
|
|
129
|
+
},
|
|
130
|
+
).then((result) => {
|
|
131
|
+
if (result?.aborted) batchAborted = true;
|
|
132
|
+
return result;
|
|
133
|
+
});
|
|
134
|
+
|
|
43
135
|
for (const taskId of waveTaskIds) {
|
|
44
136
|
const task = (state.tasks ?? []).find((entry) => entry?.taskId === taskId);
|
|
45
137
|
if (!task) continue;
|
|
46
138
|
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
if (!lane) {
|
|
139
|
+
const stickyLane = lanes.find((entry) => entry.laneNumber === task.laneNumber);
|
|
140
|
+
if (!stickyLane) {
|
|
50
141
|
return {
|
|
51
142
|
ok: false,
|
|
52
143
|
result: {
|
|
@@ -55,7 +146,7 @@ export async function executeResumeWave({
|
|
|
55
146
|
batchId,
|
|
56
147
|
taskId,
|
|
57
148
|
error: "lane_not_found",
|
|
58
|
-
output: `No lane assigned for task ${taskId} (lane ${laneNumber}).\n`,
|
|
149
|
+
output: `No lane assigned for task ${taskId} (lane ${task.laneNumber}).\n`,
|
|
59
150
|
},
|
|
60
151
|
};
|
|
61
152
|
}
|
|
@@ -68,17 +159,12 @@ export async function executeResumeWave({
|
|
|
68
159
|
const taskFolderInWorktree = resolveTaskFolderInWorktree({
|
|
69
160
|
projectRoot,
|
|
70
161
|
task,
|
|
71
|
-
lane,
|
|
162
|
+
lane: stickyLane,
|
|
72
163
|
tasksRootRel,
|
|
73
164
|
batchId,
|
|
74
165
|
});
|
|
75
|
-
const laneCorrelationId =
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (!runsByLane.has(laneNumber)) {
|
|
79
|
-
runsByLane.set(laneNumber, { lane, runs: [] });
|
|
80
|
-
}
|
|
81
|
-
const laneQueue = runsByLane.get(laneNumber);
|
|
166
|
+
const laneCorrelationId = stickyLane.correlationId ?? crypto.randomUUID();
|
|
167
|
+
stickyLane.correlationId = laneCorrelationId;
|
|
82
168
|
|
|
83
169
|
if (
|
|
84
170
|
taskTerminalSuccessInBatch({
|
|
@@ -91,20 +177,30 @@ export async function executeResumeWave({
|
|
|
91
177
|
}
|
|
92
178
|
|
|
93
179
|
if (taskAlreadyComplete({ taskFolder: taskFolderInWorktree, events, task })) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
180
|
+
// Disk-marking run on the sticky lane: evidence and committed work
|
|
181
|
+
// live on that lane's branch, so no VL→slot rebind. Empty scopes —
|
|
182
|
+
// a complete-marking never conflicts with running work.
|
|
183
|
+
vlQueue.push({
|
|
184
|
+
vlId: `vl-resume-done:${taskId}`,
|
|
185
|
+
scopes: [],
|
|
186
|
+
tasks: [
|
|
187
|
+
{
|
|
188
|
+
taskId,
|
|
189
|
+
bindsSlot: false,
|
|
190
|
+
run: async () =>
|
|
191
|
+
markTaskCompleteFromDisk({
|
|
192
|
+
projectRoot,
|
|
193
|
+
state,
|
|
194
|
+
batchId,
|
|
195
|
+
config,
|
|
196
|
+
task,
|
|
197
|
+
lane: stickyLane,
|
|
198
|
+
taskBranch: stickyLane.branch ?? laneTaskBranch(batchId, stickyLane.laneNumber),
|
|
199
|
+
taskFolderInWorktree,
|
|
200
|
+
laneCorrelationId,
|
|
201
|
+
}),
|
|
202
|
+
},
|
|
203
|
+
],
|
|
108
204
|
});
|
|
109
205
|
continue;
|
|
110
206
|
}
|
|
@@ -113,62 +209,167 @@ export async function executeResumeWave({
|
|
|
113
209
|
continue;
|
|
114
210
|
}
|
|
115
211
|
|
|
116
|
-
|
|
212
|
+
// Resumable task: greedy-pack into the first VL whose scopes overlap
|
|
213
|
+
// (planner packing predicate), else open a new VL. Tasks whose packet
|
|
214
|
+
// scope cannot be re-read dispatch with empty scopes rather than
|
|
215
|
+
// being dropped from the wave.
|
|
216
|
+
const scopeResult = loadResumeFileScopePaths(path.join(projectRoot, taskFolderRel));
|
|
217
|
+
const scopes = scopeResult.ok ? scopeResult.fileScopePaths ?? [] : [];
|
|
218
|
+
const targetVl = vlQueue.find((vl) => scopesOverlap(scopes, vl.scopes));
|
|
219
|
+
const queuedTask = {
|
|
117
220
|
taskId,
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
{
|
|
134
|
-
projectRoot,
|
|
135
|
-
batchId,
|
|
136
|
-
state,
|
|
137
|
-
taskId,
|
|
138
|
-
config,
|
|
139
|
-
workerBackend: resolveWorkerBackend(config),
|
|
140
|
-
},
|
|
141
|
-
).then((result) => {
|
|
142
|
-
if (result.aborted) batchAborted = true;
|
|
143
|
-
return result;
|
|
144
|
-
}),
|
|
145
|
-
});
|
|
221
|
+
bindsSlot: true,
|
|
222
|
+
run: makeResumableRun(task, taskFolderRel),
|
|
223
|
+
};
|
|
224
|
+
if (targetVl) {
|
|
225
|
+
targetVl.tasks.push(queuedTask);
|
|
226
|
+
for (const scope of scopes) {
|
|
227
|
+
if (!targetVl.scopes.includes(scope)) targetVl.scopes.push(scope);
|
|
228
|
+
}
|
|
229
|
+
} else {
|
|
230
|
+
vlQueue.push({
|
|
231
|
+
vlId: `vl-resume:${taskId}`,
|
|
232
|
+
scopes: [...scopes],
|
|
233
|
+
tasks: [queuedTask],
|
|
234
|
+
});
|
|
235
|
+
}
|
|
146
236
|
}
|
|
147
237
|
|
|
148
|
-
const
|
|
149
|
-
|
|
238
|
+
const slotPool = createVlSlotPool(
|
|
239
|
+
// `lanes.maxParallel` caps in-flight VLs; the pool never exceeds the
|
|
240
|
+
// provisioned lanes so a slot always maps to a lane worktree (resumed
|
|
241
|
+
// batches may predate a maxParallel increase — fail closed to the
|
|
242
|
+
// provisioned lanes instead of dispatching into a missing worktree).
|
|
243
|
+
Math.min(config?.lanes?.maxParallel ?? 1, Math.max(1, provisionedLanes.length)),
|
|
244
|
+
);
|
|
245
|
+
/** @type {typeof vlQueue} */
|
|
246
|
+
const readyVls = [...vlQueue];
|
|
247
|
+
/** @type {Array<{ vlId: string, scopes: string[], tasks: unknown[] }>} */
|
|
248
|
+
const runningVls = [];
|
|
249
|
+
/** @type {Set<Promise<object[]>>} */
|
|
250
|
+
const inFlightVls = new Set();
|
|
251
|
+
/** @type {object[]} */
|
|
252
|
+
const waveResults = [];
|
|
253
|
+
/** @type {Error | null} */
|
|
254
|
+
let runError = null;
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Free a VL's slot, drop it from the running set, collect its results,
|
|
258
|
+
* and surface a thrown run error (first error wins) without rejecting
|
|
259
|
+
* the tracked completion.
|
|
260
|
+
*/
|
|
261
|
+
const settleVlSlot = (vl, slot, completion, results, error) => {
|
|
262
|
+
slotPool.release(slot);
|
|
263
|
+
const runningIndex = runningVls.indexOf(vl);
|
|
264
|
+
if (runningIndex >= 0) runningVls.splice(runningIndex, 1);
|
|
265
|
+
inFlightVls.delete(completion);
|
|
266
|
+
if (error && !runError) runError = error;
|
|
267
|
+
if (Array.isArray(results)) waveResults.push(...results);
|
|
268
|
+
return results;
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Run one VL's serial task queue on the physical lane bound to `slot`.
|
|
273
|
+
* Aborts (and a prior run error) short-circuit the queue's remaining
|
|
274
|
+
* tasks; a thrown run error rejects and is converted to a batch engine
|
|
275
|
+
* error by the settle handler.
|
|
276
|
+
*
|
|
277
|
+
* @returns {Promise<object[]>}
|
|
278
|
+
*/
|
|
279
|
+
const runVlOnSlot = async (vl, slot) => {
|
|
280
|
+
const slotLane = provisionedLanes[slot - 1] ?? null;
|
|
281
|
+
if (!slotLane) throw new Error(`no lane provisioned for slot ${slot} (resume dispatch)`);
|
|
282
|
+
|
|
283
|
+
// VL→slot bind (SP-903 pattern): merge (and downstream resume/
|
|
284
|
+
// dashboard consumers) key off `task.laneNumber`, so the runtime
|
|
285
|
+
// binding must replace the plan-time sticky value before any run
|
|
286
|
+
// persists state. Already-complete tasks keep their sticky lane.
|
|
287
|
+
for (const queued of vl.tasks) {
|
|
288
|
+
if (!queued.bindsSlot) continue;
|
|
289
|
+
const boundTask = (state.tasks ?? []).find((entry) => entry?.taskId === queued.taskId);
|
|
290
|
+
if (boundTask) boundTask.laneNumber = slotLane.laneNumber;
|
|
291
|
+
}
|
|
292
|
+
const slotCorrelationId = slotLane.correlationId ?? crypto.randomUUID();
|
|
293
|
+
slotLane.correlationId = slotCorrelationId;
|
|
294
|
+
|
|
295
|
+
if (vl.tasks.length > 1) {
|
|
150
296
|
appendJournalEvent(projectRoot, batchId, "lane.tasks_serialized", {
|
|
151
|
-
laneNumber,
|
|
152
|
-
laneId:
|
|
297
|
+
laneNumber: slotLane.laneNumber,
|
|
298
|
+
laneId: slotLane.laneId,
|
|
153
299
|
waveIndex,
|
|
154
|
-
taskIds:
|
|
155
|
-
correlationId:
|
|
300
|
+
taskIds: vl.tasks.map((queued) => queued.taskId),
|
|
301
|
+
correlationId: slotCorrelationId,
|
|
156
302
|
});
|
|
157
303
|
}
|
|
158
304
|
|
|
159
305
|
/** @type {object[]} */
|
|
160
|
-
const
|
|
161
|
-
for (const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
306
|
+
const results = [];
|
|
307
|
+
for (const queued of vl.tasks) {
|
|
308
|
+
if (batchAborted || runError) return results;
|
|
309
|
+
results.push(await queued.run(slotLane, slotCorrelationId));
|
|
310
|
+
}
|
|
311
|
+
return results;
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
while (readyVls.length > 0 || inFlightVls.size > 0) {
|
|
315
|
+
if (!batchAborted && !runError && readyVls.length > 0) {
|
|
316
|
+
const slot = slotPool.tryAcquire();
|
|
317
|
+
if (slot !== null) {
|
|
318
|
+
const selection = selectReadyVl(readyVls, runningVls);
|
|
319
|
+
if (selection.status === "dispatch" && selection.vl) {
|
|
320
|
+
const vl = selection.vl;
|
|
321
|
+
const readyIndex = readyVls.indexOf(vl);
|
|
322
|
+
if (readyIndex >= 0) readyVls.splice(readyIndex, 1);
|
|
323
|
+
runningVls.push(vl);
|
|
324
|
+
/** @type {Promise<object[]>} */
|
|
325
|
+
const completion = runVlOnSlot(vl, slot).then(
|
|
326
|
+
(outcome) => settleVlSlot(vl, slot, completion, outcome),
|
|
327
|
+
(error) =>
|
|
328
|
+
settleVlSlot(
|
|
329
|
+
vl,
|
|
330
|
+
slot,
|
|
331
|
+
completion,
|
|
332
|
+
[],
|
|
333
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
334
|
+
),
|
|
335
|
+
);
|
|
336
|
+
inFlightVls.add(completion);
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
// Slot free but no dispatchable VL: scope conflicts or same-VL
|
|
340
|
+
// serial queues are journalable (SP-897 payload).
|
|
341
|
+
if (selection.status === "conflict-wait") {
|
|
342
|
+
appendJournalEvent(
|
|
343
|
+
projectRoot,
|
|
344
|
+
batchId,
|
|
345
|
+
VL_SLOT_CONFLICT_WAIT_EVENT,
|
|
346
|
+
buildConflictWaitPayload({
|
|
347
|
+
slot,
|
|
348
|
+
blocked: selection.blocked,
|
|
349
|
+
waitingOn: selection.waitingOn,
|
|
350
|
+
runningVlIds: runningVls.map((running) => running.vlId ?? null),
|
|
351
|
+
readyCount: readyVls.length,
|
|
352
|
+
}),
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
slotPool.release(slot);
|
|
167
356
|
}
|
|
168
357
|
}
|
|
169
|
-
return laneResults;
|
|
170
|
-
});
|
|
171
358
|
|
|
172
|
-
|
|
359
|
+
if (inFlightVls.size > 0) {
|
|
360
|
+
// Slot pool full (or nothing dispatchable): wait for a running VL
|
|
361
|
+
// to free its slot, then re-select.
|
|
362
|
+
await Promise.race([...inFlightVls]);
|
|
363
|
+
} else if (readyVls.length === 0 || batchAborted || runError) {
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (runError) {
|
|
369
|
+
// Preserve the sticky-queue contract: a thrown run error propagates to
|
|
370
|
+
// resume-multi's engine error handler (failBatchFromEngineError) after
|
|
371
|
+
// in-flight VLs drain.
|
|
372
|
+
throw runError;
|
|
373
|
+
}
|
|
173
374
|
return { ok: true, waveResults, batchAborted };
|
|
174
375
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import fs from "node:fs";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { readJournalTail, summarizeJournalEvent } from "../batch/journal.mjs";
|
|
8
|
+
import { VL_SLOT_CONFLICT_WAIT_EVENT } from "../batch/engine-lanes/vl-slot-dispatch.mjs";
|
|
8
9
|
import {
|
|
9
10
|
deriveLanesThroughput,
|
|
10
11
|
emptyLaneThroughputStats,
|
|
@@ -39,8 +40,25 @@ const ACTIVITY_PHASE_LABELS = {
|
|
|
39
40
|
final_review: "final review",
|
|
40
41
|
rework: "rework",
|
|
41
42
|
failed: "failed",
|
|
43
|
+
conflict_wait: "conflict wait",
|
|
42
44
|
};
|
|
43
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Lane-scoped journal events that prove the physical slot holds (or just
|
|
48
|
+
* took) work: a VL bind, a live worker/task, or an open review running on
|
|
49
|
+
* the lane. Used to decide whether a `lane.slot_conflict_wait` for the slot
|
|
50
|
+
* is still the newest truth (free + blocked) or has been superseded by a
|
|
51
|
+
* fresh dispatch (SP-901 / #327).
|
|
52
|
+
*
|
|
53
|
+
* @type {Set<string>}
|
|
54
|
+
*/
|
|
55
|
+
const LANE_SLOT_OCCUPANCY_EVENTS = new Set([
|
|
56
|
+
"lane.tasks_serialized",
|
|
57
|
+
"task.started",
|
|
58
|
+
"lane.heartbeat",
|
|
59
|
+
"review.started",
|
|
60
|
+
]);
|
|
61
|
+
|
|
44
62
|
export function truncateWorktreePath(worktreePath) {
|
|
45
63
|
if (!worktreePath) return null;
|
|
46
64
|
const parts = String(worktreePath).split(/[/\\]/).filter(Boolean);
|
|
@@ -58,7 +76,7 @@ export function heartbeatAgeSeconds(lastHeartbeatAt, now = Date.now()) {
|
|
|
58
76
|
return Math.max(0, Math.floor((now - ts) / 1000));
|
|
59
77
|
}
|
|
60
78
|
|
|
61
|
-
export function classifyLaneStatus({ lane, classifiedTasks, stallConfig, now = Date.now(), diagnosis = null }) {
|
|
79
|
+
export function classifyLaneStatus({ lane, classifiedTasks, stallConfig, now = Date.now(), diagnosis = null, conflictWaitActive = false }) {
|
|
62
80
|
const taskIds = lane.taskIds ?? [];
|
|
63
81
|
const tasks = classifiedTasks.filter((task) => taskIds.includes(task.taskId));
|
|
64
82
|
|
|
@@ -87,6 +105,12 @@ export function classifyLaneStatus({ lane, classifiedTasks, stallConfig, now = D
|
|
|
87
105
|
);
|
|
88
106
|
if (!hasActive) return "completed";
|
|
89
107
|
|
|
108
|
+
// SP-901 (#327/#358): a free slot whose ready work is blocked only by a
|
|
109
|
+
// file-scope conflict is not live "running" and not "stale" (nothing is
|
|
110
|
+
// hung — progress resumes when the conflicting VL settles). Diagnosed
|
|
111
|
+
// lanes keep their batch-level status above.
|
|
112
|
+
if (conflictWaitActive) return "conflict_wait";
|
|
113
|
+
|
|
90
114
|
let referenceMs = null;
|
|
91
115
|
if (lane.lastHeartbeatAt != null) {
|
|
92
116
|
referenceMs =
|
|
@@ -204,11 +228,64 @@ function taskHasReworkMarker(laneNumber, taskId, journalEvents) {
|
|
|
204
228
|
return false;
|
|
205
229
|
}
|
|
206
230
|
|
|
231
|
+
/**
|
|
232
|
+
* Latest conflict-wait state for a physical slot (SP-901 / #327, #358 display AC).
|
|
233
|
+
*
|
|
234
|
+
* Slot-pool dispatch journals `lane.slot_conflict_wait` (payload `slot` = the
|
|
235
|
+
* free physical slot) each time a slot is free but every remaining ready VL
|
|
236
|
+
* is blocked by a file-scope conflict or a same-VL serial queue. A slot is
|
|
237
|
+
* conflict-waiting only while that event is the newest slot-relevant journal
|
|
238
|
+
* signal: any newer lane-scoped occupancy event (bind, task start, worker
|
|
239
|
+
* heartbeat, open review) means the slot took work and the wait is over.
|
|
240
|
+
*
|
|
241
|
+
* @param {number} laneNumber Physical slot / lane row number.
|
|
242
|
+
* @param {Array<object>} journalEvents Journal events in append order.
|
|
243
|
+
* @returns {{ active: boolean, payload: object | null }} `active` is true
|
|
244
|
+
* only when a conflict-wait for this slot is newer than any occupancy
|
|
245
|
+
* signal for the lane; `payload` is the raw conflict-wait event payload.
|
|
246
|
+
*/
|
|
247
|
+
export function resolveLaneConflictWait(laneNumber, journalEvents) {
|
|
248
|
+
const events = journalEvents ?? [];
|
|
249
|
+
for (let i = events.length - 1; i >= 0; i -= 1) {
|
|
250
|
+
const event = events[i];
|
|
251
|
+
if (event.type === VL_SLOT_CONFLICT_WAIT_EVENT) {
|
|
252
|
+
const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
|
|
253
|
+
if (Number(payload.slot) === laneNumber) {
|
|
254
|
+
return { active: true, payload };
|
|
255
|
+
}
|
|
256
|
+
continue; // conflict-wait for a different slot — irrelevant here
|
|
257
|
+
}
|
|
258
|
+
if (LANE_SLOT_OCCUPANCY_EVENTS.has(event.type) && laneEventMatches(laneNumber, event)) {
|
|
259
|
+
return { active: false, payload: null }; // slot took work after the wait
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return { active: false, payload: null };
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* @param {object} params
|
|
267
|
+
* @param {object} [params.conflictWait] Result of `resolveLaneConflictWait`.
|
|
268
|
+
* @returns {{ slot: number | null, reason: string, blockedByOverlap: object[], queuedBehindRunning: Array<string | number | null>, runningVlIds: Array<string | number | null>, readyCount: number } | null}
|
|
269
|
+
*/
|
|
270
|
+
function formatConflictWaitDetail(conflictWait) {
|
|
271
|
+
if (!conflictWait?.active || !conflictWait.payload) return null;
|
|
272
|
+
const payload = conflictWait.payload;
|
|
273
|
+
return {
|
|
274
|
+
slot: payload.slot != null ? Number(payload.slot) : null,
|
|
275
|
+
reason: typeof payload.reason === "string" ? payload.reason : "scope_conflict",
|
|
276
|
+
blockedByOverlap: Array.isArray(payload.blockedByOverlap) ? payload.blockedByOverlap : [],
|
|
277
|
+
queuedBehindRunning: Array.isArray(payload.queuedBehindRunning) ? payload.queuedBehindRunning : [],
|
|
278
|
+
runningVlIds: Array.isArray(payload.runningVlIds) ? payload.runningVlIds : [],
|
|
279
|
+
readyCount: Number(payload.readyCount) || 0,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
207
283
|
export function resolveLaneActivityPhase({
|
|
208
284
|
laneNumber,
|
|
209
285
|
activeTaskIds = [],
|
|
210
286
|
classifiedTasks = [],
|
|
211
287
|
journalEvents = [],
|
|
288
|
+
conflictWait = null,
|
|
212
289
|
}) {
|
|
213
290
|
const activeIds = new Set((activeTaskIds ?? []).map(String));
|
|
214
291
|
if (activeIds.size === 0) {
|
|
@@ -248,6 +325,13 @@ export function resolveLaneActivityPhase({
|
|
|
248
325
|
}
|
|
249
326
|
}
|
|
250
327
|
|
|
328
|
+
// SP-901 (#327): a slot whose newest signal is a conflict-wait has no live
|
|
329
|
+
// worker — do not fall through to heartbeat/worker phases that read as
|
|
330
|
+
// "running" at a round barrier.
|
|
331
|
+
if (conflictWait?.active) {
|
|
332
|
+
return { activityPhase: "conflict_wait", activityPhaseLabel: ACTIVITY_PHASE_LABELS.conflict_wait };
|
|
333
|
+
}
|
|
334
|
+
|
|
251
335
|
const heartbeatMeta = resolveLaneHeartbeatMeta(laneNumber, events);
|
|
252
336
|
if (heartbeatMeta.workerPhase === "launching") {
|
|
253
337
|
return { activityPhase: "launching", activityPhaseLabel: ACTIVITY_PHASE_LABELS.launching };
|
|
@@ -432,11 +516,13 @@ export function buildLaneRows({
|
|
|
432
516
|
laneTaskIds: lane.taskIds ?? [],
|
|
433
517
|
});
|
|
434
518
|
const activeTaskIds = computeActiveTaskIdsForLane({ lane, classifiedTasks, currentWaveTaskIds });
|
|
519
|
+
const conflictWait = resolveLaneConflictWait(lane.laneNumber, journalEvents);
|
|
435
520
|
const activity = resolveLaneActivityPhase({
|
|
436
521
|
laneNumber: lane.laneNumber,
|
|
437
522
|
activeTaskIds,
|
|
438
523
|
classifiedTasks,
|
|
439
524
|
journalEvents,
|
|
525
|
+
conflictWait,
|
|
440
526
|
});
|
|
441
527
|
const throughput =
|
|
442
528
|
throughputByLane.get(lane.laneNumber) ?? emptyLaneThroughputStats();
|
|
@@ -454,12 +540,21 @@ export function buildLaneRows({
|
|
|
454
540
|
return {
|
|
455
541
|
laneId: lane.laneId ?? `lane-${lane.laneNumber}`,
|
|
456
542
|
laneNumber: lane.laneNumber,
|
|
457
|
-
status: classifyLaneStatus({
|
|
543
|
+
status: classifyLaneStatus({
|
|
544
|
+
lane,
|
|
545
|
+
classifiedTasks,
|
|
546
|
+
stallConfig,
|
|
547
|
+
now,
|
|
548
|
+
diagnosis,
|
|
549
|
+
conflictWaitActive: conflictWait.active,
|
|
550
|
+
}),
|
|
458
551
|
activeTaskIds,
|
|
459
552
|
runningTaskId,
|
|
460
553
|
queuedTaskIds,
|
|
461
554
|
activityPhase: activity.activityPhase,
|
|
462
555
|
activityPhaseLabel: activity.activityPhaseLabel,
|
|
556
|
+
conflictWait: conflictWait.active,
|
|
557
|
+
conflictWaitDetail: formatConflictWaitDetail(conflictWait),
|
|
463
558
|
taskIds: lane.taskIds ?? [],
|
|
464
559
|
heartbeatAgeSeconds: heartbeatAgeSecondsValue,
|
|
465
560
|
heartbeatKind: heartbeatMeta.heartbeatKind,
|