refactor(memory): dedupe atomic-file-replace helpers across two state stores - #2402
Open
cyberlife-coder wants to merge 1 commit into
Open
cyberlife-coder wants to merge 1 commit into
cyberlife-coder wants to merge 1 commit into
Conversation
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | -17 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
… stores mutation::controller::state and online_migration::job_state each kept an identical copy of the same five functions: a symlink-rejecting directory check, a symlink-rejecting regular-file check, an existence probe, and the platform-specific promote/sync-directory pair backing their staged-write- then-rename persistence. The logic is safety-sensitive (TOCTOU-safe symlink rejection, crash-safe atomic promote) and is now split across two files that a future fix could touch in one and silently miss in the other. Move the five functions into a new shared crate::mutation::atomic_file module and have both call sites use it. The two message-bearing checks take an `entity` argument so every existing error string is reproduced exactly; the one string that already varied three ways across this crate for an untestable, unreachable-on-CI platform branch is unified to one wording. No behavior change on any platform this project ships for.
cyberlife-coder
force-pushed
the
refactor/mutation-online-migration-atomic-file-dedup
branch
from
September 25, 2026 03:38
e9a24c6 to
2d24315
Compare
This branch has not been deployed
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.
refactor/*→ targetsdevelop. ✅Description
Routine code-quality pass, found while looking for duplication candidates.
mutation::controller::stateandonline_migration::job_stateeach carried an identical copy of the same five functions: a symlink-rejecting directory check, a symlink-rejecting regular-file check, an existence probe, and the platform-specificpromote/sync_directorypair backing their staged-write-then-rename persistence.This isn't cosmetic: it's the TOCTOU-safe symlink rejection (
symlink_metadata+ explicitis_symlink()reject) and the crash-safe atomic promote that the staged-write-then-promote scheme depends on in both stores. Two independent copies mean a future correctness fix to the symlink check, or a platform fix topromote/sync_directory, can land in one copy and silently miss the other.Moved the five functions into a new shared
crate::mutation::atomic_filemodule and updated both call sites to use it. The two message-bearing checks (validate_workspace,validate_regular_file) now take anentity: &strargument so every existing error string is reproduced byte-for-byte. The one exception: the "replacement unsupported" message on the#[cfg(not(any(unix, windows)))]branch already read three different ways across this crate (this pair plusmutation::journal::platform's own copy) for a branch that's unreachable on any platform this project ships for or runs CI on — unified to one wording rather than picking one of the three to keep arbitrarily.Fixes # (none — proactive quality pass, no tracked issue)
Type of Change
How Has This Been Tested?
cargo check -p velesdb-memory(default features, and--features persistence)cargo clippy -p velesdb-memory --all-targets -- -D warnings -D clippy::pedantic(clean)cargo test -p velesdb-memory --lib --features persistence -- --test-threads=1(817 passed, 0 failed, 9 ignored)cargo fmt --all -- --check(clean)python3 scripts/check_prod_unwraps.py/check-todo-annotations.py(clean; unaffected by this diff, re-verified anyway)Test Configuration:
rust-toolchain.toml(MSRV 1.90)Checklist
Unsafe Code Checklist
Not applicable — no
unsafecode touched.High-Risk Change Checklist
Not applicable — doesn't touch
hnsw,storage,Drop,unsafe, or SIMD dispatch paths.Additional Notes
The same five-function shape is duplicated a few more times in this crate (e.g.
mutation/journal.rs's ownvalidate_workspace/validate_regular_file, plus similar patterns inonline_migration/cleanup.rsandmcp/extraction_job_store.rs). Left untouched here to keep this PR mechanical, single-purpose and reviewable; a follow-up could migrate those call sites ontocrate::mutation::atomic_filetoo.