AI Agents SDE Task Viewer
      • Pr description
  1. Home
  2. AgentSDE
  3. agent-core
  4. gh-441
  5. changes
  6. pr_description.md
pr_description.md(1.9 KB)· Apr 12, 2026· 1 min read
  • AW-5: Consume phase-result queue and handle crash recovery
  • Problem
  • Task / Link
  • Changes
  • Notes
  • Testing

AW-5: Consume phase-result queue and handle crash recovery#

Closes #441

Problem#

When agent-core restarts while AI invocations are in flight, in-memory promise resolvers are lost. Phase results arriving after restart were silently dropped, leaving tasks stuck.

Task / Link#

GitHub Issue #441 — AW-5 (parent: #437 AW-1)

Changes#

  • src/invoke/invocation-result.listener.ts — New service with waitForResult() (timeout-backed promise), handleResult() (resolves pending resolver or falls back to crash recovery), and recoverResult() (duplicate-delivery guard + pipeline advancement via InternalAdapterService)
  • src/queue/sqlite-job-queue.ts — Replaced blind "mark-all-failed" stale detection with smart logic: checks ai-done.json (emit recovery event), live ai.pid (leave as processing), otherwise mark failed
  • src/queue/job-queue.interface.ts — Added taskDir?: string to DispatchEvent for stale job recovery
  • src/invoke/invoke.module.ts — Registered InvocationResultListener with required module imports
  • src/invoke/invocation-result.listener.spec.ts — New: 13 tests covering timeout, happy path, duplicate delivery, no-task-found, and event handler
  • src/queue/sqlite-job-queue.spec.ts — Added 5 tests for smart stale detection scenarios

Notes#

  • Depends on AW-4 (#440) for full queue integration; InvocationResultListener is a standalone service ready to be wired into BullMQ processor once AW-4 merges
  • PID liveness check uses process.kill(pid, 0) combined with a job age heuristic (lockedAt age > CLAUDE_TIMEOUT_SECS + 100s) to guard against recycled PIDs
  • ai-done.json format expected: { taskId: number, phase: string, signalKind: string }

Testing#

  • Unit tests: npm run test — 27 new tests across 2 spec files, all passing
  • Build: npm run build — no TypeScript errors
  • Lint: npm run lint — zero warnings
PrdAgent-runner