fix(smithy): orphan recovery dispatches highest-priority task first#9
Open
komoreka wants to merge 1 commit into
Open
fix(smithy): orphan recovery dispatches highest-priority task first#9komoreka wants to merge 1 commit into
komoreka wants to merge 1 commit into
Conversation
`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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
recoverOrphanedAssignmentswas selectingworkerTasks[0]without sorting, so the recovered task depended on storage insertion order (P3 created before P1 would be dispatched first)task.prioritybefore selection — lower number = higher priority = dispatched firstContext
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.pollWorkerAvailabilityalready uses priority ordering viaapi.ready()).Test plan
bun test src/services/dispatch-daemon.bun.test.ts -t "recoverOrphanedAssignments"— 38 tests pass including the new regressionbun test src/services/dispatch-daemon.bun.test.ts— 141 pass, 0 failNODE_ENV=development npx turbo run typecheck— 16/16 clean🤖 Generated with Claude Code