phase3(契约层): protocol.ts + 落盘状态 + store 失败策略/判活原语

多进程执行解耦的 Phase 0 共享契约(worker 与 daemon 都 import 它):
- executor/protocol.ts: JobSpec(daemon→worker 唯一输入) + OutboxRecord(worker→daemon) +
  文件 IO(job/outbox/heartbeat) + isWorkerAlive(心跳为主/boot 窗口 pid 兜底/防 pid 复用)
- schema+db+types+mappers: runs.worker_pid/last_seq、tasks.next_eligible_at(持久化退避)
- store: failTaskAttempt(失败/重试策略唯一落点) + setNextEligibleAt/setWorkerPid/setLastSeq +
  countExecuting + executingWithLatestExecutorRun + reconcileInterrupted(isAlive 注入,默认保守回收)

纯增量,140 测试全绿。worker.ts/pipeline.ts(worker 侧) 与 orchestrator/ingest/index(daemon 侧) 待接。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-06-13 12:51:09 +08:00
parent d49192344f
commit 007dffac39
7 changed files with 269 additions and 12 deletions
+4 -1
View File
@@ -36,6 +36,7 @@ CREATE TABLE IF NOT EXISTS tasks (
result TEXT, -- JSON TaskResult
assignee TEXT, -- agent | human
retry_baseline INTEGER NOT NULL DEFAULT 0, -- 上次手动重投时已有的失败 run 数(重置重试计数用)
next_eligible_at TEXT, -- 持久化退避:早于此时间不被领取(null=即刻可领)
created_at TEXT NOT NULL,
updated_at TEXT NOT NULL,
source_ref TEXT -- 旧 todo 来源标识(todo:17 / todo:17/1A),项目内唯一
@@ -66,7 +67,9 @@ CREATE TABLE IF NOT EXISTS runs (
ended_at TEXT,
transcript_ref TEXT,
claude_session_id TEXT,
error TEXT
error TEXT,
worker_pid INTEGER, -- 多进程执行:worker 进程 piddaemon 写,判活用)
last_seq INTEGER NOT NULL DEFAULT 0 -- 已 ingest 的 outbox 最大 seq(幂等游标)
);
CREATE INDEX IF NOT EXISTS idx_runs_task ON runs(task_id, started_at);