Skip to content

fix(smithy): orphan recovery dispatches highest-priority task first#9

Open
komoreka wants to merge 1 commit into
masterfrom
fix/orphan-recovery-priority-ordering
Open

fix(smithy): orphan recovery dispatches highest-priority task first#9
komoreka wants to merge 1 commit into
masterfrom
fix/orphan-recovery-priority-ordering

Conversation

@komoreka
Copy link
Copy Markdown
Owner

Summary

  • recoverOrphanedAssignments was selecting workerTasks[0] without sorting, so the recovered task depended on storage insertion order (P3 created before P1 would be dispatched first)
  • Adds ascending sort by task.priority before selection — lower number = higher priority = dispatched first
  • Adds a regression test: P3 task created before P1 task, confirms P1 is always recovered first

Context

Observed during dogfooding: el-4i50 (CodeDelivery persistent worker) had a P1 bug task and a P3 visual task assigned. After session restart, orphan recovery spawned the worker for the P3 task instead of P1. The fix matches the intent of the priority field throughout the rest of dispatch (e.g. pollWorkerAvailability already uses priority ordering via api.ready()).

Test plan

  • bun test src/services/dispatch-daemon.bun.test.ts -t "recoverOrphanedAssignments" — 38 tests pass including the new regression
  • bun test src/services/dispatch-daemon.bun.test.ts — 141 pass, 0 fail
  • NODE_ENV=development npx turbo run typecheck — 16/16 clean

🤖 Generated with Claude Code

`recoverOrphanedAssignments` selected the first element from
`getAgentTasks` without sorting, so the recovered task depended on
storage insertion order rather than priority (P3 before P1 if created
first). Adds ascending sort by `task.priority` before selecting the
task. Adds a regression test: P3 created before P1 — confirms P1 is
always recovered first.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant