Skip to content

feat(cojson): signature mismatch recovery with session conflict preservation#3522

Draft
gdorsi wants to merge 8 commits into
mainfrom
feat/session-log-conflict-recovery
Draft

feat(cojson): signature mismatch recovery with session conflict preservation#3522
gdorsi wants to merge 8 commits into
mainfrom
feat/session-log-conflict-recovery

Conversation

@gdorsi
Copy link
Copy Markdown
Collaborator

@gdorsi gdorsi commented Apr 10, 2026

Summary

  • Adds signature mismatch recovery: when a client's local session diverges from the server (e.g., after a crash where transactions reached the server but not local storage), the client detects the mismatch, replaces the divergent session with authoritative server content, and preserves any divergent local edits via a conflict session
  • Implements replaceSessionContent on CoValueCore and replaceSessionHistory on both sync and async storage layers
  • Adds layered test coverage: 9 end-to-end integration stories, 5 core invariant tests, 4 async storage queue ordering tests
  • Documents 2 known design gaps as test.fails cases: deleted-value tombstone propagation and crash-during-queue-replacement

Test plan

  • All 18 new/refactored recovery tests pass
  • Full cojson test suite passes (1384 tests, 0 failures)
  • test.fails cases correctly document known design gaps
  • Verify CI passes

gdorsi added 8 commits April 8, 2026 11:21
Introduce ConflictSessionID type and isConflictSessionID/toConflictSessionID
helpers, following the existing pattern of ActiveSessionID/DeleteSessionID.
Conflict sessions are derived from active sessions by appending "!" and will
be used to store divergent transactions during crash recovery.
Introduces recoveryTestHelpers.ts with five shared helpers for
signature mismatch recovery test layers: setupRecoveryActors,
createSharedTaskMap, crashAfterServerAckBeforeLocalPersist,
expectTaskFields, and waitForRecovery.
Replace anonymous key/value pairs (a, b, c, d; server1, server2; only-on-server)
in the three recovery integration tests with realistic task map fields
(title, priority, status, assignee, archived, owner, due) and add ASCII
topology docblocks explaining the crash scenario and expected state.

Introduce shared helpers from recoveryTestHelpers.ts for actor setup,
crash simulation, field assertions, and condition polling. Keep the first
two protocol-level tests (SignatureMismatch detection and dedup) unchanged.

Also fix crashAfterServerAckBeforeLocalPersist to wait for peer sync only
(not storage sync) when storage writes are intentionally blocked, preventing
a hang when the storage waitForSync promise never resolves.

Note: the "jazzCloud ahead by more transactions" test requires the client
session to be longer than the server's to trigger the SignatureMismatch
error path; the test makes three post-crash edits to satisfy this constraint.
…ion recovery stories

Adds three integration tests to the signature mismatch recovery suite:
- bob convergence after observing stale state pre-recovery
- fresh charlie load after recovery sees only repaired history
- recovery preserves unrelated sessions from a second agent session
Add two tests to the replaceSessionContent core invariants suite:
- verify isDeleted remains true and delete session is preserved after replaceSessionContent on a deleted coValue
- verify newContentSince(undefined) emits tombstone content after deleted recovery
Add recovery module that detects signature mismatches from the server,
replaces the divergent session with authoritative content, and preserves
divergent local edits via conflict sessions.

Implementation:
- recovery/index.ts: orchestrates mismatch recovery flow
- replaceSessionContent on CoValueCore: rebuilds VerifiedState
- replaceSessionHistory on storage: durable session replacement
- SignatureMismatch error handling in sync layer

Test coverage across three layers:
- Integration (L1): 9 end-to-end recovery stories
- Core invariants (L2): 5 focused replaceSessionContent tests
- Storage queue (L3): 4 async queue ordering tests

Includes test.fails cases documenting known design gaps:
deleted-value tombstone propagation and crash-during-queue-replacement.
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
clerk-demo Error Error Apr 10, 2026 5:07pm
file-upload-demo Error Error Apr 10, 2026 5:07pm
form-demo Error Error Apr 10, 2026 5:07pm
gcmp-homepage Error Error Apr 10, 2026 5:07pm
image-upload-demo Error Error Apr 10, 2026 5:07pm
jazz-chat Error Error Apr 10, 2026 5:07pm
jazz-chat-1 Error Error Apr 10, 2026 5:07pm
jazz-chat-2 Error Error Apr 10, 2026 5:07pm
jazz-filestream Error Error Apr 10, 2026 5:07pm
jazz-image-upload Error Error Apr 10, 2026 5:07pm
jazz-inspector Error Error Apr 10, 2026 5:07pm
jazz-multi-cursors Error Error Apr 10, 2026 5:07pm
jazz-nextjs Error Error Apr 10, 2026 5:07pm
jazz-organization Error Error Apr 10, 2026 5:07pm
jazz-paper-scissors Error Error Apr 10, 2026 5:07pm
jazz-richtext Error Error Apr 10, 2026 5:07pm
jazz-todo Error Error Apr 10, 2026 5:07pm
jazz-vector-search Error Error Apr 10, 2026 5:07pm
jazz-version-history Error Error Apr 10, 2026 5:07pm
music-demo Error Error Apr 10, 2026 5:07pm
passkey-demo Error Error Apr 10, 2026 5:07pm
passphrase-auth-demo Error Error Apr 10, 2026 5:07pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
jazz-homepage Ignored Ignored Preview Apr 10, 2026 5:07pm

Request Review

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant