Agent: programmer (
programmer)
Confidence: 56%
Cost: $1.3222
Duration: 7m 25s
Task ID:ba7dc6c3-84cd-4772-ac58-7fe61ec1e5d4
✅ 所有測試通過!(88 個測試檔案, 1089 個測試)
📋 修復完成報告
✅ 任務完成
成功修復 Pipeline Stall Bug 並新增 stall recovery 機制。
📝 修改摘要
1. Debug Logging (pipeline-engine.ts 行 292, 364)
- 在
handleTaskCompleted加入 debug log,記錄 missing mapping - 在
handleTaskFailed加入 debug log,記錄 missing mapping - 目的:追蹤 mapping 丟失的時機點,協助除錯
2. Stall Recovery 機制 (pipeline-engine.ts 行 963+)
- 新增
recoverStalledPipelines()函數(82 行) - 功能:
- 掃描所有 active pipelines,找出
running狀態但 mapping 丟失的 stage - 交叉比對 queue.json 和 history.jsonl,找出已完成但未推進的 task
- 重放完成事件,更新 stage 狀態,呼叫
advancePipeline()推進流程
- 掃描所有 active pipelines,找出
- 恢復策略:
- Task completed → 重放 completion,恢復 output 和 cost
- Task failed → 標記為 failed
- Task in history → 標記為 completed(無 result)
3. 定期恢復呼叫 (worker-scheduler.ts 行 1076+)
- 在
pollAndExecute()的 stale task cleanup 之後加入 recovery 呼叫 - 使用 dynamic import 避免循環依賴
- 使用 try-catch 確保非致命錯誤不影響正常流程
- 只在 recovered > 0 時記錄 info log,避免噪音
🔍 驗證結果
1 | ✅ TypeScript 編譯檢查通過 (tsgo --noEmit) |
📊 改動量
- 修改檔案:2 個
src/agents/pipeline-engine.ts:+89 行src/agents/worker-scheduler.ts:+11 行
- 總計:+100 行(包含註釋和空行)
★ Insight ─────────────────────────────────────
防禦性程式設計的三層策略:
- 預防:使用 in-memory Map 提供快速的 event routing(正常路徑)
- 監測:debug log 記錄異常情況(missing mapping),提供可觀測性
- 恢復:periodic recovery scan 作為 safety net,從極端情況(crash + race condition)中恢復
這種設計確保了即使在 worst-case scenario(worker crash + event loss),pipeline 也能最終推進,避免永久 stall。─────────────────────────────────────────────────
⚠️ 注意事項
- 根據任務要求,未建立 commit(這是測試性修改)
- 所有修改嚴格遵守專案慣例(ESM、Result
、EventBus) - 使用現有的 helper functions(
loadQueueTasks(),loadCompletedTaskIds()) - Dynamic import 避免循環依賴問題
🎯 下一步建議
- 監控:觀察 production logs 中的 “Stall detected” 警告頻率
- 調優:如果 recovery 頻繁觸發,考慮調查 mapping 丟失的根本原因
- 測試:可以考慮新增 integration test 模擬 crash + recovery 場景
修復完成時間:2026-02-25
Programmer:一見生財