Repository navigation
[code-review] Task record CAS: close the race between the status pre-check and companion artifact/document writes - #9785
Merged
Conversation
[code-review] Task record CAS: close the race between the status pre-check and companion artifact/document writes Fix: TaskRecordService::update_returning_row (crates/orbit-core/src/application/task/records.rs) now runs a write that carries expected_status and any change under the task's write lock (TaskStoreBackend::with_task_write_lock) across the status pre-check, footprint pre-flight, and the artifact, document and history commits (split into a private commit_parts helper). The bundle write lock is thread-re-entrant (HeldFileLock reentry; the boundary nests via BoundaryDepth), so each inner commit re-enters it; lock order stays boundary-then-bundle, as for the existing callers that already wrap task_records().update in with_task_write_lock. A concurrent status change now serializes before the pre-check (CAS error, nothing written) or after the whole write; it can no longer land between companion commits and the history commit. Writes without expected_status, and comment-only operator writes (which never carry expected_status), keep their previous lock path. Search indexing stays outside the lock. No behaviour change for successful writes. Orbit-Task: ORB-25209
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.
Task
ORB-25209 — [code-review] Task record CAS: close the race between the status pre-check and companion artifact/document writes
Description
Follow-up split from ORB-25178 (PR #9770, merged as ab0d106) on Daniel's choice, 2026-11-16: land the sequential fix and track the concurrent race separately (decision dr-40f47c8149b42043, option 1).
Observed
TaskRecordService::update_returning_row(crates/orbit-core/src/application/task/records.rs) now checksexpected_statusagainst the current row before any artifact, document or history write, and the history commit re-checks it under its lock. A one-at-a-time CAS failure leaves no companion edits. Two writers can still race: a status change that lands after the pre-check and before the history commit makes the history commit refuse, while the artifact and document commits already landed. The write returnsErrwith companion edits persisted.End state
A multi-part task record write with
expected_statusis all-or-nothing against a concurrent status change: when the CAS fails, no artifact, document or history change from that write persists. Whether this is one store transaction, a task-wide lock across the three commits, or compensation is the implementer's choice; callers that take no lock today must not deadlock, and the store's in-lock guards stay authoritative.Behaviour change: none for writes that succeed.
Acceptance Criteria
Execution Summary
Click to expand
Fix: TaskRecordService::update_returning_row (crates/orbit-core/src/application/task/records.rs) now runs a write that carries expected_status and any change under the task's write lock (TaskStoreBackend::with_task_write_lock) across the status pre-check, footprint pre-flight, and the artifact, document and history commits (split into a private commit_parts helper). The bundle write lock is thread-re-entrant (HeldFileLock reentry; the boundary nests via BoundaryDepth), so each inner commit re-enters it; lock order stays boundary-then-bundle, as for the existing callers that already wrap task_records().update in with_task_write_lock. A concurrent status change now serializes before the pre-check (CAS error, nothing written) or after the whole write; it can no longer land between companion commits and the history commit. Writes without expected_status, and comment-only operator writes (which never carry expected_status), keep their previous lock path. Search indexing stays outside the lock. No behaviour change for successful writes.
Criteria: (1) met - a status change racing a CAS-guarded write cannot land between the pre-check and history commit; if the CAS fails no artifact/document/history change persists. (2) met - regression concurrent_status_change_cannot_split_a_cas_guarded_write (crates/orbit-core/src/application/task/tests/records.rs) uses a cfg(test) BEFORE_HISTORY_COMMIT hook between the document and history commits to start a racing status change on another thread and wait up to 2 s for it; it failed with the fix disabled (base behaviour: records.rs:161 'CAS failure left a document edit') and passes with it. (3) met - no deadlock: full orbit-core lib (252 passed) and runtime suite (778 passed, 9 ignored) passed.
Validation: PASSED cargo test -p orbit-cli -p orbit-core --lib --test runtime; PASSED make ci-guards; PASSED cargo fmt --all -- --check; PASSED rustfmt --check --edition 2024 on the changed test file; PASSED clippy -p orbit-core --lib --bins and --all-targets -D warnings -A clippy::disallowed_methods; PASSED RUSTDOCFLAGS=-D warnings cargo doc --no-deps -p orbit-core. NOT RUN: task.final_validation_commands (pipeline final validation). No manual QA: internal store-coordination change with no user-visible surface, covered by the regression test.
Reconciliation: delivery paths crates/orbit-core/src/application/task/records.rs, crates/orbit-core/src/application/task/tests/records.rs (sibling regression test next to the existing ORB-25178 one; outside the declared selectors, needed for the test), scripts/unit-test-baseline.json (admits the new unit test; outside selectors). Scratch logs only under .orbit/tmp/. Deviation: test lives in the existing sibling unit-test file rather than tests/runtime/task_update.rs because the injected hook is cfg(test)-only. Risk: the racer test spends up to 2 s waiting on the fixed path by design.
Validation
Branch Freshness
refs/remotes/origin/agent-mainorbit/ORB-25209-497b8b21