@alpacachen/dsh-kanban 1.12.0 → 1.12.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/docs/workflow-guide.en.md +1 -1
- package/docs/workflow-guide.md +2 -0
- package/lib/client.js +65 -30
- package/package.json +1 -1
- package/workflow/runner.js +22 -23
package/package.json
CHANGED
package/workflow/runner.js
CHANGED
|
@@ -88,10 +88,12 @@ export function makeStagePrompt(task, previousStages, outputDirectory, artifacts
|
|
|
88
88
|
].join('\n\n')
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
const MAX_CONCURRENT_STAGES = 2
|
|
92
|
+
|
|
91
93
|
/** Host-owned scheduler. It never lives in a request or browser component. */
|
|
92
94
|
export function createWorkflowRunner({ store, executor, attachments, workspaceRegistry, runtimeSnapshot = {}, onError = () => {}, onChange = () => {}, ownerInstanceId = randomUUID() }) {
|
|
93
95
|
let stopped = false
|
|
94
|
-
|
|
96
|
+
const active = new Map()
|
|
95
97
|
let pumping = null
|
|
96
98
|
let pumpAgain = false
|
|
97
99
|
let lastError = null
|
|
@@ -212,22 +214,21 @@ export function createWorkflowRunner({ store, executor, attachments, workspaceRe
|
|
|
212
214
|
// Retry only the recorded result; storage failures never redispatch the Agent.
|
|
213
215
|
settlements.set(attempt.id, { taskId: task.id, payload: settlement, prepare })
|
|
214
216
|
await flushSettlements()
|
|
215
|
-
active
|
|
217
|
+
active.delete(task.id)
|
|
216
218
|
notify()
|
|
217
219
|
if (!stopped) kick()
|
|
218
220
|
}
|
|
219
221
|
}
|
|
220
222
|
|
|
221
223
|
async function pump() {
|
|
222
|
-
|
|
223
|
-
// measured demand without changing the durable per-workspace safety slots.
|
|
224
|
-
if (stopped || !started || active) return
|
|
224
|
+
if (stopped || !started || active.size >= MAX_CONCURRENT_STAGES) return
|
|
225
225
|
await flushSettlements()
|
|
226
226
|
void cleanupDeletedTasks()
|
|
227
227
|
if (stopped) return
|
|
228
228
|
const summaries = store.listTaskSummaries ? store.listTaskSummaries() : store.listTasks()
|
|
229
229
|
for (const queued of summaries.filter((task) => task.state === 'queued')) {
|
|
230
|
-
if (stopped || active) return
|
|
230
|
+
if (stopped || active.size >= MAX_CONCURRENT_STAGES) return
|
|
231
|
+
if (active.has(queued.id)) continue
|
|
231
232
|
const task = store.getTask(queued.id)
|
|
232
233
|
const workspace = workspaceRegistry.get(task.workspaceId)
|
|
233
234
|
let boundPath
|
|
@@ -278,10 +279,10 @@ export function createWorkflowRunner({ store, executor, attachments, workspaceRe
|
|
|
278
279
|
continue
|
|
279
280
|
}
|
|
280
281
|
const controller = new AbortController()
|
|
281
|
-
|
|
282
|
-
active.
|
|
282
|
+
const execution = { attemptId: attempt.id, controller, done: null }
|
|
283
|
+
active.set(task.id, execution)
|
|
284
|
+
execution.done = execute(attempt, task, controller.signal)
|
|
283
285
|
notify()
|
|
284
|
-
return
|
|
285
286
|
}
|
|
286
287
|
}
|
|
287
288
|
|
|
@@ -292,7 +293,7 @@ export function createWorkflowRunner({ store, executor, attachments, workspaceRe
|
|
|
292
293
|
report(error); retryLater()
|
|
293
294
|
}).finally(() => {
|
|
294
295
|
pumping = null
|
|
295
|
-
if (pumpAgain && !stopped &&
|
|
296
|
+
if (pumpAgain && !stopped && active.size < MAX_CONCURRENT_STAGES) kick()
|
|
296
297
|
})
|
|
297
298
|
return pumping
|
|
298
299
|
}
|
|
@@ -307,24 +308,24 @@ export function createWorkflowRunner({ store, executor, attachments, workspaceRe
|
|
|
307
308
|
},
|
|
308
309
|
kick,
|
|
309
310
|
cleanupDeletedTasks,
|
|
310
|
-
isExecutingTask: taskId => active
|
|
311
|
+
isExecutingTask: taskId => active.has(taskId),
|
|
311
312
|
hasPendingSettlement: taskId => [...settlements.values()].some(item => item.taskId === taskId),
|
|
312
313
|
settleTask: taskId => [...settlements.values()].some(item => item.taskId === taskId) ? flushSettlements() : Promise.resolve(),
|
|
313
314
|
async cancelTask(taskId) {
|
|
314
|
-
|
|
315
|
-
|
|
315
|
+
const current = active.get(taskId)
|
|
316
|
+
if (current) {
|
|
316
317
|
current.controller.abort()
|
|
317
318
|
return executor.cancel(current.attemptId)
|
|
318
319
|
}
|
|
319
320
|
if ([...settlements.values()].some(item => item.taskId === taskId)) await flushSettlements()
|
|
320
321
|
return { requested: false }
|
|
321
322
|
},
|
|
322
|
-
status: () => ({ policy: NATIVE_POLICY, running: active
|
|
323
|
+
status: () => ({ policy: NATIVE_POLICY, running: active.size > 0, settling: settlements.size > 0, cleanupPending, stopped, lastError }),
|
|
323
324
|
async whenIdle() {
|
|
324
325
|
// Deterministic test/shutdown barrier, never used as business success proof.
|
|
325
|
-
while (pumping || active || flushing || cleaning) {
|
|
326
|
+
while (pumping || active.size || flushing || cleaning) {
|
|
326
327
|
await pumping
|
|
327
|
-
|
|
328
|
+
await Promise.all([...active.values()].map(execution => execution.done))
|
|
328
329
|
await flushing
|
|
329
330
|
await cleaning
|
|
330
331
|
}
|
|
@@ -332,14 +333,12 @@ export function createWorkflowRunner({ store, executor, attachments, workspaceRe
|
|
|
332
333
|
async dispose() {
|
|
333
334
|
stopped = true
|
|
334
335
|
clearTimeout(retryTimer)
|
|
335
|
-
active
|
|
336
|
+
for (const execution of active.values()) execution.controller.abort()
|
|
336
337
|
await pumping
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
await current.done
|
|
342
|
-
}
|
|
338
|
+
await Promise.all([...active.values()].map(async execution => {
|
|
339
|
+
try { await executor.cancel(execution.attemptId) } catch (error) { report(error) }
|
|
340
|
+
await execution.done
|
|
341
|
+
}))
|
|
343
342
|
await executor.dispose()
|
|
344
343
|
await flushSettlements()
|
|
345
344
|
await cleaning
|