Skip to content

fix(id): make world namespace and publication registry writes durable #12254

Closed

Description

@dezren39

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:

  1. pkgs/id/crates/id-worlds/src/world_records.rs:61-72, write_atomic: writes contents with tokio::fs::write(&tmp, ...), then renames, with no file or directory sync. RecordsStore::open uses 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 follows tags::save_registry; that sibling now uses the durable helper, so the comparison is stale.
  2. pkgs/id/crates/id-cli/src/publications.rs:342-359, Registry::save: writes JSON with std::fs::write, then renames, with no file or directory sync. This is the persisted publication set loaded by id serve; its module contract says restart restores the set, and its save comment says a crash mid-save keeps the previous set intact.
  3. Correct sibling pattern: pkgs/id/crates/id-core/src/durable_write.rs:8-23 writes 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

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_atomic comment 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

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    effort/sSmall: expected under 2 hours of work
    on Nov 21, 2026
  2. developing-today commented on Nov 21, 2026

    @developing-today
    Contributor
  3. dezren39 commented on Nov 21, 2026

    @dezren39
    MemberAuthor

    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.

  4. dezren39 commented on Nov 21, 2026

    @dezren39
    MemberAuthor

    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) and Registry::save (pkgs/id/crates/id-cli/src/publications.rs:342-359) write and rename without syncing file data or the parent directory. The existing id_core::durable_write::write_durable helper (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.

  5. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    on Nov 21, 2026
  6. dezren39 commented on Nov 21, 2026

    @dezren39
    MemberAuthor

    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.

  7. dezren39 commented on Nov 21, 2026

    @dezren39
    MemberAuthor

    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 --check pass; workspace formatting still reports unrelated drift. CI and CodeRabbit review are in progress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)queue/claimedQueue worker lifecycle statesource/creatorFiled by the new-issue-creator jobstatus/in-progressQueue worker lifecycle statestatus:donetask/triageQueue packet kind: verify, reproduce, and route this itemwork/assignedQueue worker lifecycle state

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions