Repository navigation
fix: serialize task claims and completions under one lock - #93
Conversation
Only claimTask took a lock (an O_EXCL `.claim.lock`), so a completion could run while a claim was between its read and its write; the claim then wrote "claimed" over the completion. Found 2026-11-09 with real processes: 5 of 30 tasks claimed and completed at once ended claimed with no result_path, next to a done result and its trusted receipt, and the claimer could not complete them. The stale-lock reap (stat, rm, recreate) also let two claimers both win when a crashed claimer had left its lock: 6 of 15 rounds of four concurrent claims. claimTask and completeTask now run under withTaskUpdateLock, a withCrossProcessFileLock per task (`.<task>.update.lock`, 10 s wait). Its holder is identified by pid, so a crashed holder's lock is taken over atomically instead of by age. A `.claim.lock` left by an older version is ignored. Verified: tests/task-update-lock.test.ts (claim paused mid-write while a completion runs) fails against main and passes here; tests/store.test.ts passes, including the old stale-lock case; the hunt's real-process scripts went from 5/30 inconsistent and 6/15 double-claimed against main to 0/30 and 0/15; npx tsc --noEmit; full suite 1870 passed, 3 skipped. Claude-Session: https://claude.ai/code/session_01EMqNwnnhHXznd2P2PDsaDV
What this touches
3 file(s), 137 line(s) changed. Tests changed. Worth a look
This is an automated first pass, not a review. CI is the gate; a person decides. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4fc888fb33
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| private async withTaskUpdateLock<T>(taskId: string, fn: () => Promise<T>): Promise<T> { | ||
| return withCrossProcessFileLock( | ||
| path.join(this.dir("tasks"), `.${taskId}.update.lock`), |
There was a problem hiding this comment.
Validate task IDs before constructing and acquiring the lock
When a caller supplies a traversal-containing task ID, this acquires the lock before getTask() reaches the existing assertBridgeRecordId() validation. Unlike the previous completion path, withCrossProcessFileLock() recursively creates the lock's parent directory first, so an MCP bridge_complete_task request with task_id: "x/../../../../escaped/nested/task" creates directories outside the repository even though the request ultimately fails validation. The MCP input checks permit this string. Validate the task ID before invoking the lock helper so rejected IDs cannot cause filesystem changes outside task storage.
Useful? React with 👍 / 👎.
# Conflicts: # CHANGELOG.md
…e lock) to the container image Same change as main PR #93 (merge 555d9c5), released in 0.40.51, applied to src, tests and docs without changes. The CHANGELOG lines are main's with the PR noted. Claude-Session: https://claude.ai/code/session_01EMqNwnnhHXznd2P2PDsaDV
Problem
Found 2026-11-09 by running real processes against one ledger.
A claim can overwrite a completion. Only
claimTasktook a lock, an O_EXCL.claim.lock. A completion (prodex tasks complete, or MCPbridge_complete_task) could run between a claim's read and its write, and the claim then wrote "claimed" over the completion.tasks claimandtasks completerunning at the same moment, 5 of 30 tasks ended claimed with noresult_path. Each sat next to a done result and its trusted receipt.tasks list --status claimed.A stale claim lock lets two claimers win. When a crashed claimer left its lock behind, each new claimer checked the lock's age, deleted it and created its own. Two claimers that both found it stale both won: 6 of 15 rounds of four concurrent claims.
Change
claimTaskandcompleteTasknow run underwithTaskUpdateLock. It is the existingwithCrossProcessFileLockapplied per task, on.<task>.update.lock, with a 10 s wait..claim.lockleft by an older version is ignored.Verification
tests/task-update-lock.test.tspauses a claim mid-write while a completion runs. It fails against main (claimedinstead ofdone) and passes here.tests/store.test.tspasses, including the existing cases for a stale lock and concurrent claims.npx tsc --noEmitpasses. Full suite: 1870 passed, 3 skipped.