Skip to content

[Bug][affinity] Async startup hydration overwrites chains updated by live requests #6253

Open

Description

@Afloat16

Reproduction

At master dc041dd1ab1a014efa352ba47a6f31fc47f55284, startup calls hydrateAffinityUnified() in the background. While its KV reads await completion, requests can call prefixAffinity.note() with a deeper or newer chain. Hydration then imports the older file/KV record unconditionally, replacing that live chain.

A controlled test with the real SQLite-backed KV store pauses the first read after capturing a depth-2 snapshot, notes a live depth-6 chain, and releases hydration. The resulting live depth is 2. A second test at equal depth replaces the newer tail hash and prevents that exact replay from retaining its existing session. The one-time legacy migration can also durably write the stale chain over the newer in-memory record.

Proposed fix

Immediately before import, merge the current in-memory snapshot with the file/KV union using the existing deeper-then-fresher persistence rule. Use that reconciled union for one-time migration as well. A genuinely deeper stored chain must continue to win; no new resolution policy is needed.

Validation

  • Unchanged master: three new regressions fail; the deeper-stored control passes.
  • Fixed: 52 tests pass across unified affinity storage, legacy persistence, prefix resolution and persona restart stability, including actual SQLite and local HTTP coverage.
  • Whole-project npm run typecheck, npm run build and git diff --check pass.

Duplicate screening: all existing PR entries, open/closed issues and Afloat16's prior issues/fork branches were checked. #5757 introduced the unified overlay, #5480 concerns cross-process legacy-file journaling, #6047 validates carrier shape, and #6186 concerns write durability/debounce lifecycle. None reconciles mutations made while this startup read is pending.

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions