Repository navigation
fix(core): close TOCTOU in bulk_update via SQL COALESCE, document bulk_create_hierarchy contract - #1262
Conversation
…k_create_hierarchy contract Fixes B8 from architectural audit (#1228). bulk_update: replace the get_node() pool read inside the transaction with a single COALESCE UPDATE statement — no read escapes the tx, closing the read-modify-write race window entirely (Option B). Detects not-found via affected-rows check; any error rolls back the whole batch. Added doc comment explicitly stating the intentional last-write-wins / non-OCC contract. bulk_create_hierarchy: add doc comment confirming validate_node_type is pure in-memory (no DB reads, no uncommitted-state dependency) and that any early ?-return drops tx without commit(), rolling back the entire batch. Tests added: - test_bulk_update_partial_fields_preserves_unspecified: COALESCE keeps content when only node_type is updated, and vice versa - test_bulk_update_bad_id_rolls_back: bad id mid-batch causes full rollback Closes #1258. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Code Review SummaryThis PR closes the TOCTOU race in One critical issue blocks merge: the FindingsCritical Issues
UPDATE node SET content = COALESCE(?1, content), node_type = COALESCE(?2, node_type), version = version + 1, modified_at = ?3 WHERE id = ?4
Impact surface: The single-node Required fix: Extend the COALESCE statement (or add additional per-row SQL) to cover the three missing fields: UPDATE node SET
content = COALESCE(?1, content),
node_type = COALESCE(?2, node_type),
properties = COALESCE(?3, properties),
title = COALESCE(?4, title),
lifecycle_status = COALESCE(?5, lifecycle_status),
version = version + 1,
modified_at = ?6
WHERE id = ?7Note that
The doc comment states: "no read-then-write; the read-modify-write is a single atomic SQL statement inside the transaction with no pool reads escaping the tx." This is accurate for Suggested Improvements
The service layer still calls
If a caller passes a Nitpicks
Acceptance Criteria Checklist (from issue #1258)
VerdictRequest changes. The TOCTOU fix is correct and well-implemented for what it covers, and the doc comments and rollback semantics are sound. The blocker is that three of five |
Addresses review feedback on PR #1262. - Extend the bulk_update SQL to cover properties, lifecycle_status, and title alongside the existing content/node_type COALESCE handling. properties uses COALESCE (replace semantics, documented as diverging from single-node update_node which merges). lifecycle_status uses COALESCE. title uses a separate conditional UPDATE within the same tx to correctly express the Option<Option<String>> clearing semantic (Some(None) must write NULL, which COALESCE cannot distinguish from absent). - Update doc comment to document properties replace-vs-merge and title clearing semantics explicitly. - Add service-layer comment clarifying that the pre-validation snapshot is intentionally outside the transaction (last-write-wins contract). - Extend test_bulk_update_partial_fields_preserves_unspecified to cover properties round-trip; rename shadowed `after` bindings to distinct names for clearer CI failure messages. - Fix clippy: redundant closure in props_json serialization. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Review AddressedAll critical and important findings resolved in commit 90547fc. Changes made🔴 Critical — extended
🟡 Important — service-layer validation comment
🟢 Nits addressed
Skipped
Test results
|
Re-Review: Code Review Summary (commit 90547fc)This re-review covers only the second commit ( FindingsCritical IssuesNone. Suggested Improvements
The main COALESCE statement increments More practically: a
The original code used Suggested fix: restore NodeUpdate::new().with_node_type("task".to_string()),
// ...
assert_eq!(after_type_update.node_type, "task");Nitpicks
Acceptance Criteria Checklist (from issue #1258)
VerdictApprove. The critical blocker from the first review is fully and correctly resolved. All five |
…k_create_hierarchy contract (#1262) * fix(core): close TOCTOU in bulk_update via SQL COALESCE, document bulk_create_hierarchy contract Fixes B8 from architectural audit (#1228). bulk_update: replace the get_node() pool read inside the transaction with a single COALESCE UPDATE statement — no read escapes the tx, closing the read-modify-write race window entirely (Option B). Detects not-found via affected-rows check; any error rolls back the whole batch. Added doc comment explicitly stating the intentional last-write-wins / non-OCC contract. bulk_create_hierarchy: add doc comment confirming validate_node_type is pure in-memory (no DB reads, no uncommitted-state dependency) and that any early ?-return drops tx without commit(), rolling back the entire batch. Tests added: - test_bulk_update_partial_fields_preserves_unspecified: COALESCE keeps content when only node_type is updated, and vice versa - test_bulk_update_bad_id_rolls_back: bad id mid-batch causes full rollback Closes #1258. Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * fix(core): extend bulk_update COALESCE to all five NodeUpdate fields Addresses review feedback on PR #1262. - Extend the bulk_update SQL to cover properties, lifecycle_status, and title alongside the existing content/node_type COALESCE handling. properties uses COALESCE (replace semantics, documented as diverging from single-node update_node which merges). lifecycle_status uses COALESCE. title uses a separate conditional UPDATE within the same tx to correctly express the Option<Option<String>> clearing semantic (Some(None) must write NULL, which COALESCE cannot distinguish from absent). - Update doc comment to document properties replace-vs-merge and title clearing semantics explicitly. - Add service-layer comment clarifying that the pre-validation snapshot is intentionally outside the transaction (last-write-wins contract). - Extend test_bulk_update_partial_fields_preserves_unspecified to cover properties round-trip; rename shadowed `after` bindings to distinct names for clearer CI failure messages. - Fix clippy: redundant closure in props_json serialization. Co-Authored-By: Claude Sonnet 4.6 <[email protected]> --------- Co-authored-by: Michael Libio <[email protected]> Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Fixes #1258 (B8 from architectural audit #1228).
Summary
bulk_update: Replaceget_node()pool read inside the transaction with a singleCOALESCEUPDATE, closing the read-modify-write race window entirely (Option B from the issue). Addedaffected == 0check for not-found detection. Added doc comment stating the intentional last-write-wins / non-OCC contract.bulk_create_hierarchy: Added doc comment confirmingvalidate_node_typeis pure in-memory and documenting the partial-failure rollback contract.Tests added
test_bulk_update_partial_fields_preserves_unspecified: COALESCE keeps content when only node_type is updated, and vice versatest_bulk_update_bad_id_rolls_back: bad id mid-batch causes full rollback🤖 Generated with Claude Code