muse-crew 0.7.4 → 0.7.5
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/API.md +4 -2
- package/lib/crew-api.js +40 -2
- package/lib/schema.sql +11 -0
- package/package.json +1 -1
package/API.md
CHANGED
|
@@ -214,7 +214,7 @@ Update a dispatch reservation with the real platform workflow run ID. Called by
|
|
|
214
214
|
| `task_id` | string | Required. The task that was dispatched. |
|
|
215
215
|
| `run_id` | string | Required. The real platform run ID (e.g. `workflow-run-xxx`). Must not be `"pending-dispatch"`. |
|
|
216
216
|
|
|
217
|
-
Fails closed: throws if no reservation exists for the task (launching without a reservation is forbidden). Returns `{ ok: true, task_id, run_id }`.
|
|
217
|
+
Fails closed: throws if no reservation exists for the task (launching without a reservation is forbidden). Also records a durable platform run -> task mapping (`platform_run_tasks`) — the worker is the only party that ever knows both IDs at once, and the poll loop's platform-failure monitor resolves the task through this mapping, so a dead run is requeued on the next tick instead of waiting out the zombie-session sweep. Returns `{ ok: true, task_id, run_id }`.
|
|
218
218
|
|
|
219
219
|
### `clear-reservation`
|
|
220
220
|
|
|
@@ -295,7 +295,7 @@ The platform records workflow run status in `runtime.workflow_runs` — separate
|
|
|
295
295
|
|
|
296
296
|
### `record-platform-failure`
|
|
297
297
|
|
|
298
|
-
Record a platform workflow run failure. Correlates
|
|
298
|
+
Record a platform workflow run failure. Correlates the task in this order: (1) the durable `platform_run_tasks` mapping written by `acknowledge-dispatch-run`, (2) timestamp proximity (±60s) between `platform_created_at` and crew telemetry launch time (fallback for runs launched before the mapping existed), (3) an explicit `crew_run_id`/`task_id` when provided. A failure that correlates to no task is kept with `task_id: null` and reported as skipped by retry.
|
|
299
299
|
|
|
300
300
|
| Field | Type | Notes |
|
|
301
301
|
|-------|------|-------|
|
|
@@ -324,6 +324,8 @@ Returns `{ ok: true, failures: [...] }`.
|
|
|
324
324
|
|
|
325
325
|
Retry a task whose workflow died on a platform failure. Clears the stale reservation, re-queues the task to `todo`, and increments the retry count. If `retry_count` >= `max_retries` (default 3), parks the task instead.
|
|
326
326
|
|
|
327
|
+
**Supersede guard:** if a newer platform run has been linked for this task since this failure's run, the task is already owned by the successor — the retry is skipped instead of clobbering live work (a late detection of an old dead run never resets a redispatched task).
|
|
328
|
+
|
|
327
329
|
| Field | Type | Notes |
|
|
328
330
|
|-------|------|-------|
|
|
329
331
|
| `platform_run_id` | string | Required. |
|
package/lib/crew-api.js
CHANGED
|
@@ -628,6 +628,17 @@ commands["acknowledge-dispatch-run"] = (db, args) => {
|
|
|
628
628
|
if (info.changes === 0) {
|
|
629
629
|
throw usageError("no reservation exists for task_id — launch without reservation is forbidden.");
|
|
630
630
|
}
|
|
631
|
+
// Durable platform run -> task mapping (2026-09-13): the worker is the only
|
|
632
|
+
// party that ever knows both IDs at once. record-platform-failure resolves
|
|
633
|
+
// the task through this mapping instead of timestamp proximity, so a dead
|
|
634
|
+
// platform run is requeued on the next tick instead of waiting out the
|
|
635
|
+
// 1-hour zombie-session sweep.
|
|
636
|
+
db.prepare(
|
|
637
|
+
`INSERT INTO platform_run_tasks (platform_run_id, task_id)
|
|
638
|
+
VALUES (?, ?)
|
|
639
|
+
ON CONFLICT(platform_run_id) DO UPDATE SET
|
|
640
|
+
task_id = excluded.task_id, linked_at = datetime('now')`
|
|
641
|
+
).run(args.run_id, args.task_id);
|
|
631
642
|
return { ok: true, task_id: args.task_id, run_id: args.run_id };
|
|
632
643
|
};
|
|
633
644
|
|
|
@@ -735,11 +746,19 @@ commands["record-platform-failure"] = (db, args) => {
|
|
|
735
746
|
if (!args.platform_run_id) throw usageError("platform_run_id is required.");
|
|
736
747
|
if (!args.error_message) throw usageError("error_message is required.");
|
|
737
748
|
if (!args.platform_created_at) throw usageError("platform_created_at is required.");
|
|
738
|
-
//
|
|
739
|
-
//
|
|
749
|
+
// Correlate with a crew task. First the durable platform_run_tasks mapping
|
|
750
|
+
// (written by acknowledge-dispatch-run — the worker is the only party that
|
|
751
|
+
// ever knows both IDs at once). Timestamp proximity is the fallback for
|
|
752
|
+
// runs launched before the mapping existed.
|
|
740
753
|
let crewRunId = args.crew_run_id || null;
|
|
741
754
|
let taskId = args.task_id || null;
|
|
742
755
|
let workflow = args.workflow || null;
|
|
756
|
+
if (!taskId) {
|
|
757
|
+
const link = db.prepare(
|
|
758
|
+
"SELECT task_id FROM platform_run_tasks WHERE platform_run_id = ?"
|
|
759
|
+
).get(args.platform_run_id);
|
|
760
|
+
if (link) taskId = link.task_id;
|
|
761
|
+
}
|
|
743
762
|
if (!crewRunId) {
|
|
744
763
|
const match = db.prepare(
|
|
745
764
|
`SELECT run_id, task_id, workflow FROM workflow_runs
|
|
@@ -803,6 +822,25 @@ commands["retry-platform-failure"] = (db, args) => {
|
|
|
803
822
|
if (!failure.task_id) {
|
|
804
823
|
return { ok: true, action: "skipped", reason: "no task correlated" };
|
|
805
824
|
}
|
|
825
|
+
// Supersede guard: if a newer platform run was linked for this task after
|
|
826
|
+
// this failure's run, the task is already owned by the newer run —
|
|
827
|
+
// requeueing here would clobber live work. Skip instead of retrying.
|
|
828
|
+
// (Without this, a late Step-0 detection of an old dead run could reset a
|
|
829
|
+
// task its successor is already working.)
|
|
830
|
+
const myLink = db.prepare(
|
|
831
|
+
"SELECT linked_at, rowid AS rid FROM platform_run_tasks WHERE platform_run_id = ?"
|
|
832
|
+
).get(args.platform_run_id);
|
|
833
|
+
if (myLink) {
|
|
834
|
+
const newer = db.prepare(
|
|
835
|
+
`SELECT platform_run_id FROM platform_run_tasks
|
|
836
|
+
WHERE task_id = ? AND platform_run_id != ?
|
|
837
|
+
AND (linked_at > ? OR (linked_at = ? AND rowid > ?))
|
|
838
|
+
ORDER BY linked_at DESC, rowid DESC LIMIT 1`
|
|
839
|
+
).get(failure.task_id, args.platform_run_id, myLink.linked_at, myLink.linked_at, myLink.rid);
|
|
840
|
+
if (newer) {
|
|
841
|
+
return { ok: true, action: "skipped", reason: "superseded by newer run " + newer.platform_run_id };
|
|
842
|
+
}
|
|
843
|
+
}
|
|
806
844
|
if (failure.retry_count >= maxRetries) {
|
|
807
845
|
// Park the task — transient failures are not resolving.
|
|
808
846
|
const task = db.prepare("SELECT * FROM tasks WHERE id = ?").get(failure.task_id);
|
package/lib/schema.sql
CHANGED
|
@@ -161,3 +161,14 @@ CREATE TABLE IF NOT EXISTS platform_run_failures (
|
|
|
161
161
|
);
|
|
162
162
|
CREATE INDEX IF NOT EXISTS platform_run_failures_task_id_idx ON platform_run_failures(task_id);
|
|
163
163
|
CREATE INDEX IF NOT EXISTS platform_run_failures_detected_at_idx ON platform_run_failures(detected_at);
|
|
164
|
+
|
|
165
|
+
-- Durable platform run -> task mapping (2026-09-13). The poll worker is the
|
|
166
|
+
-- only party that ever knows both IDs at once, so acknowledge-dispatch-run
|
|
167
|
+
-- records the pairing here. record-platform-failure resolves the task through
|
|
168
|
+
-- this mapping; the old timestamp-proximity match is a fallback only.
|
|
169
|
+
CREATE TABLE IF NOT EXISTS platform_run_tasks (
|
|
170
|
+
platform_run_id TEXT PRIMARY KEY,
|
|
171
|
+
task_id TEXT NOT NULL REFERENCES tasks(id) ON DELETE CASCADE,
|
|
172
|
+
linked_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
173
|
+
);
|
|
174
|
+
CREATE INDEX IF NOT EXISTS platform_run_tasks_task_id_idx ON platform_run_tasks(task_id);
|
package/package.json
CHANGED