Skip to content

[code-review] Task record CAS: close the race between the status pre-check and companion artifact/document writes - #9785

Merged
orbit-agent-01 merged 1 commit into
agent-mainfrom
orbit/ORB-25209-497b8b21
Nov 16, 2026
Merged

orbit-agent-01 merged 1 commit into
agent-mainfrom
orbit/ORB-25209-497b8b21

Conversation

@orbit-agent-01

Copy link
Copy Markdown
Contributor

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 checks expected_status against 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 returns Err with companion edits persisted.

End state

A multi-part task record write with expected_status is 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

  • A write carrying expected_status plus artifact or document changes, whose status changes concurrently between the pre-check and the history commit, persists none of its artifact, document or history changes and returns the CAS error.
  • A regression test reproduces the interleaving deterministically (for example with an injected hook between the commit steps) and fails on ab0d106.
  • No existing caller of update_returning_row deadlocks or changes lock order in a way the runtime suites catch.

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

  • Not reported

Branch Freshness

  • Base ref: refs/remotes/origin/agent-main
  • Head ref: orbit/ORB-25209-497b8b21
  • Behind base: 0
  • Ahead of base: 1

[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
@orbit-agent-01 orbit-agent-01 added the orbit orbit related label Nov 16, 2026
@orbit-agent-01
orbit-agent-01 merged commit 66205e3 into agent-main Nov 16, 2026
19 checks passed
@orbit-agent-01
orbit-agent-01 deleted the orbit/ORB-25209-497b8b21 branch November 16, 2026 04:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

orbit orbit related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant