fix: handle 404 in waitForTaskActive when task is deleted by concurrent run#13
fix: handle 404 in waitForTaskActive when task is deleted by concurrent run#13
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a race condition where a task can be deleted by a concurrent workflow run while waitForTaskActive is polling, causing an unhandled 404 and action failure. It introduces an explicit error type so the action can detect the condition and fall back to creating a new task.
Changes:
- Add
TaskDeletedErrorand throw it fromwaitForTaskActivewhengetTaskByIdreturns a 404 during polling. - Update the existing-task path in
CoderTaskAction.run()to catchTaskDeletedErrorand proceed with creating a new task. - Add unit tests covering both the client-side 404 handling and the action-level fallback behavior.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/coder-client.ts | Converts polling-time 404s into a dedicated TaskDeletedError for explicit handling. |
| src/coder-client.test.ts | Adds coverage ensuring polling throws TaskDeletedError when the task disappears mid-loop. |
| src/action.ts | Catches TaskDeletedError on the existing-task path and falls through to task creation. |
| src/action.test.ts | Adds a test verifying the action creates a new task when waitForTaskActive fails with TaskDeletedError. |
| dist/index.js | Updates bundled output to include the new logic (but also includes unrelated bundler-helper changes). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
2d50ca8 to
cc40f97
Compare
The CI workflow used bun-version: latest, which recently jumped to 1.3.11. Bun 1.3.10 changed the bundler preamble (WeakMap caching, __accessProp, __exportSetter), so dist/index.js built locally with 1.2.x no longer matches what CI produces — instant check_unstaged failure for anyone not running bleeding-edge bun. ci: rebuild dist/index.js with bun 1.2.15
…nt run When a concurrent workflow run deletes a task while waitForTaskActive is polling getTaskById, the action now catches the 404 and falls through to create a new task instead of crashing. - Add TaskDeletedError class for explicit error discrimination - Catch 404 in waitForTaskActive polling loop, throw TaskDeletedError - Wrap existing-task path in action.ts run() with try-catch to handle TaskDeletedError and fall through to task creation Closes #12
cc40f97 to
1ce13ac
Compare
mafredri
left a comment
There was a problem hiding this comment.
Clean fix for the concurrent-deletion race. The error discrimination pattern (dedicated error class, instanceof check, fallthrough) is solid and the tests cover the primary scenario well.
A few things to consider: 2 P3s, 2 nits, 1 observation across 5 inline comments.
🤖 This review was automatically generated with Coder Agents.
mafredri
left a comment
There was a problem hiding this comment.
Two additional findings from a late-arriving reviewer that weren't in the first pass.
🤖 This review was automatically generated with Coder Agents.
|
Addressed all review feedback in b7eadbb: Semantic accuracy (comments 1, 2):
Robustness (comments 6, 7):
Test coverage (comments 3, 4, 5):
|
Depends upon #14
Problem: tasks can be deleted due to github action concurrency. Action wasn't handling 404s properly.
Solution:
TaskDeletedErrorclass for explicit error discriminationwaitForTaskActivepolling loop, throwTaskDeletedErrorrun()with try-catch; onTaskDeletedError, fall through to create a new taskCloses #12