Repository navigation
fix: leave the transient SQLite SHM out of the replica signature - #65
Merged
Merged
Conversation
…rce SHM When no connection holds the source database, every reader that opens it runs WAL recovery and rewrites the -shm, while the DB and WAL stay byte-identical. The replica signature includes the -shm, so a reader that opens during each copy attempt exhausts all three attempts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The -shm is SQLite's WAL index. The first connection to open a database rebuilds it from the DB and WAL, so it can change while the data does not. Including it in the signature rejected consistent copies and, with a reader opening during each attempt, exhausted the bounded retry. The replica now signs and copies only the main DB and WAL. It still opens read-only with query_only, and SQLite rebuilds the replica's own -shm in the private temp directory. Ported from lineage commit 410fc39. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
|
Decision: merge. Evidence:
|
This was referenced Nov 23, 2026
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.
Why
Every open PR in twoimo/alden should be resolved on its merits. The 22 stale
codex/alden-*draft PRs cannot merge as-is and will be closed, so useful fixes from that lineage get ported to main first, and only when the defect reproduces on main. This ports the SHM part of lineage commit410fc39("fix: rebuild private SQLite SHM and type bounded snapshot retries").What was broken
src/context_sync_replica.rsincluded the source-shmin the copy signature. The-shmis SQLite's transient WAL index. When no other connection holds the database, each new reader is the first connection. It runs WAL recovery and rewrites the-shm, while the main DB and the WAL stay identical. A reader that opens during each copy attempt therefore uses up all three attempts.context-sync-localthen reports a failed snapshot, and the DB watcher stays fenced and delays delivery. This is an availability problem, not a wrong send.Measured on a scratch WAL database (Python
sqlite3, macOS). A separate process that reads while another connection holds the DB left the-shmstat unchanged in 6 of 6 runs. With no holder, each read-only reader changed only the-shmmtime in 3 of 3 runs. The DB and WAL stayed the same. How often production hits the no-holder state is not measured.Fix
The signature and the copy now cover only the main DB and the WAL. The replica still opens with
SQLITE_OPEN_READ_ONLYandquery_only, and SQLite rebuilds the replica's own-shmin the private temp directory. Every other safeguard stays as it was: regular-file checks, the size check, three bounded attempts, fail-closed exhaustion, and the source identity checks inopen_fresh. The rest of410fc39(typed retry error, clonefile flags, ctime/device fields, watcher changes, docs) is not ported. Main already has its own retry plumbing, and none of those parts had a reproduced defect.Red, then green
The repro test lands first (
7a07cf3). Run against that commit in a detached worktree:The test's hook asserts that, on every attempt, the reader left the DB and WAL signatures unchanged and changed only the
-shm. With the fix (e6284ee):The existing fail-closed test still passes. A WAL write on every attempt still exhausts the retry.
CI steps run locally (macOS, Rust 1.95.0)
cargo testpassed, 1173 passed and 0 failed.cargo fmt --checkpassed.cargo clippy --all-targets -- -D warningspassed.cargo build && ./target/debug/openkakao-cli --versionprintedopenkakao-cli 1.9.1.Tests ran only against scratch databases. No KakaoTalk database, watcher, or send was touched.
🤖 Generated with Claude Code