Repository navigation
Description
Summary
Two remaining pkgs/id state-file writers use write-to-temp + rename but do not sync the temp file before the rename or the parent directory afterward. id-core::durable_write::write_durable now provides that discipline for three sibling writers (merged PR #12153), but these two sites were outside #12152's explicitly listed scope. A sudden power/kernel loss can therefore leave the newly published bytes or rename non-durable even though the save returned success.
Evidence
Verified on origin/main aca6c869f28a33645c08093bc9f316bd8060c9b8:
pkgs/id/crates/id-worlds/src/world_records.rs:61-72,write_atomic: writescontentswithtokio::fs::write(&tmp, ...), then renames, with no file or directory sync.RecordsStore::openuses it at :132 to persist the iroh-docs namespace ID. The file is a cache and can be recreated, but losing/replacing its durable namespace identity can break continuity with the existing records document and its replica tickets. The comment says this followstags::save_registry; that sibling now uses the durable helper, so the comparison is stale.pkgs/id/crates/id-cli/src/publications.rs:342-359,Registry::save: writes JSON withstd::fs::write, then renames, with no file or directory sync. This is the persisted publication set loaded byid serve; its module contract says restart restores the set, and its save comment says a crash mid-save keeps the previous set intact.- Correct sibling pattern:
pkgs/id/crates/id-core/src/durable_write.rs:8-23writes all bytes, syncs the temp file, renames, and attempts to sync the parent directory. Its existing callers are the three sites covered by fix(id): fsync temp files before rename in SequenceFile, registry and list-store saves #12152 / PR fix(id): fsync temp files before rename in SequenceFile, registry and list-store saves #12153.
Why it matters
Atomic rename prevents readers from seeing a partially written destination during ordinary operation, but without syncing the temp data and directory entry it does not provide the same power-loss durability as the new shared helper. The publication registry can fail to restore the last successfully saved set; the namespace cache can lose continuity with its document. This is a durability gap, not a claim about ordinary process termination.
Dedupe
- CLOSED fix(id): fsync temp files before rename in SequenceFile, registry and list-store saves #12152 and MERGED fix(id): fsync temp files before rename in SequenceFile, registry and list-store saves #12153 cover exactly
SequenceFile::next_sequence,id-store::tags::save_registry, andListVersionStore::save; neither candidate file is in the PR diff or the issue acceptance criteria. - CLOSED id(world): a crash-torn or empty records.namespace bricks the world forever — RecordsStore::open makes a torn cache file fatal, and writes it non-atomically #1544 concerned the non-atomic
records.namespacewrite; it predates this temp-and-rename helper and does not cover fsync/directory durability. - Fresh all-state searches for
world_records,publications,write_atomic, andfsync power loss atomic renamefound no open issue for these sites. Open PR search forworld_records,publications, ordurable_writefound no matching PR.
Acceptance criteria
- Both writers use
id_core::durable_write::write_durable(or an equivalent shared helper) so the temp file is synced before rename and the parent directory is synced afterward. - Temp paths remain sibling paths on the same filesystem and are chosen consistently with the helper's callers; errors retain useful path context.
- Persistence tests for namespace-file recovery/reuse and publication-registry save/load still pass, with focused coverage for replacement and cleanup behavior as appropriate.
- Update the
write_atomiccomment and the publication persistence docs to describe the actual durability guarantees without overstating them.
Suggested fix
Reuse id_core::durable_write::write_durable; select stable sibling temp paths and preserve the existing async/sync API shape as practical. No fix was made in this audit.
Activity
developing-today commentedon Nov 21, 2026
CODE-4461
dezren39 commentedon Nov 21, 2026
agent-note:v1
state: picked_up
task: 20925
issue: #12254
lane: oc-code-07
worker: repo-worker-code
origin: openchamber-scheduled-lane
stage: claimed -> fresh verification
Claimed and checkpointed task 20925. I am revalidating the two state-file writers against current main and checking for a superseding issue or PR. Triage only; no product code changes.
dezren39 commentedon Nov 21, 2026
agent-note:v1
state: done
task: 20925
issue: #12254
lane: oc-code-07
worker: repo-worker-code
origin: openchamber-scheduled-lane
stage: verified -> triaged
Triage confirmed the durability gap on current main:
RecordsStore::write_atomic(pkgs/id/crates/id-worlds/src/world_records.rs:61-72) andRegistry::save(pkgs/id/crates/id-cli/src/publications.rs:342-359) write and rename without syncing file data or the parent directory. The existingid_core::durable_write::write_durablehelper (pkgs/id/crates/id-core/src/durable_write.rs:8-23) is the bounded reuse path. Fresh open-PR search found no matching PR; adjacent #12152/#12153 and #1544 do not cover these writers. No product code changed. Enqueued implementation task 20926 in repo-health-code-pilot for the bounded fix.dezren39 commentedon Nov 21, 2026
Claimed implementation task 20926 and checkpointed. Fresh verification confirms #12254 is OPEN and carries no hold labels. I am creating a dedicated task worktree from current main and will implement the two durable state-file writes with focused coverage.
dezren39 commentedon Nov 21, 2026
Implementation PR opened: #12255. Both persistence paths now reuse the shared durable writer, preserving sibling temp paths and adding context for target and temp paths. Focused tests passed for id-worlds namespace recovery, id-cli registry save/load, and id-core durable replacement/temp cleanup. Edited-file rustfmt and
git diff --checkpass; workspace formatting still reports unrelated drift. CI and CodeRabbit review are in progress.