Skip to content

fix(sync): a device signed in again after its removal takes over its state file instead of failing with wrong_identity - #4708

Merged
datlechin merged 4 commits into
mainfrom
fix/sync-removed-device-stale-identity
Nov 28, 2026
Merged

datlechin merged 4 commits into
mainfrom
fix/sync-removed-device-stale-identity

Conversation

@datlechin

@datlechin datlechin commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Summary

  • A TablePro Sync state file is named by sign-in and account but bound to the device row. After the server removed a row (E2E F36, also a reset by another device or a row dropped while signed out), the next sign-in got a new row and every call answered sync.state.wrong_identity for good: Sync Now, the key screens, Team Library, and Sign Out's key erase and Team Library delete.
  • The service engine's start now takes such a file over (keys::open_service_state, ADR 0081):
    • opens it under the row it is bound to, so the MAC and anchor checks run;
    • erases that row's keys as Sign Out does (device keys, account and reset keys, key tables, scope cursors), with no revoke;
    • binds it to the new row in one sealed commit, refused while key rows remain (StateStore::move_to_row);
    • reopens it under the new row. Each step runs again after a crash.
  • A file of another account or server at that place stays refused. A server's device_removed alone still erases nothing: the erase runs at the person's next sign-in on a new row.
  • Unsent edits: the sync tables (bases, held, outbox, approvals, conflicts) move with the file, so the removed device's unsent Team Library edits go up from the new row once it syncs, and personal ones once it is approved. Nothing is dropped. A Team Library delete left pending by an earlier Sign Out Anyway finishes at the start, as before.
  • StateFiles::other_row reads which row of the account the file is bound to; a refused open now closes its connection before it lets the lock go, so the next open never waits on it.
  • KeyService::erase_replaced_row shares Sign Out's record and erase steps, split out of finish_signing_out.
  • Both erase the account keys of every av from 1 to the device's own pin, not only the pin's and the certificates the key tables hold: a file repaired from its checkpoint keeps the pin but no older certificate (Codex review finding).
  • FFI ServiceEngine::start uses it, so macOS, iOS and Windows heal at their next start while signed in. The exported FFI is unchanged, so no binding changes.
  • macOS Sign Out: listing Team Library edits that fail with sync.state.wrong_identity or sync.state.integrity is a new stateUnreadable failure. The question then offers no Upload and says the sync data couldn't be read, instead of "The upload did not finish. The team library refused the change". Publish and status texts get the same words.
  • ADR 0081 records the rule; 0054 and 0056 status lines and the index point to it.
  • Tests changed on purpose: TeamLibraryTests.uploadListsWhatIsLeft and signOutListsHiddenEdits read unsentChanges() and upload() through their new Result.

Test plan

  • Fails on main, passes here: ffi sync::tests::a_sign_in_on_a_new_row_after_a_removal_starts_as_a_new_device (approve on one row, server removes it, open on a new row of the same account: syncs, needs approval, old row's keys gone). On main it fails on key_state with sync.state.wrong_identity.
  • sync account_keys::replaced_row: take-over as a new device keeping bases; a take-over cut off partway finishing at the next sign-in; the erase sends no revoke; account keys of every av up to the pin go; a file holding key rows keeps its row; other_row names only another row of the same account and makes no file.
  • macOS AccountSettingsModelTests.unreadableSyncDataOffersNoUpload.
  • cargo test --locked -p tablepro-sync -p tablepro-sync-testing: all suites pass (account_keys 91, engine 178, state_integrity 165, team_library 53, ...).
  • cargo test --locked -p tablepro-ffi --lib sync::: 70 passed.
  • cargo clippy --locked -p tablepro-sync -p tablepro-sync-testing -p tablepro-ffi --all-targets -- -D warnings: clean. cargo fmt --check: clean.
  • verify.sh --jobs 4 test AccountSettingsModelTests TeamLibraryTests TeamLibraryHeaderTests: PASS, 58 passed. verify.sh lint on the changed Swift files: PASS.
  • iOS and Windows: the exported FFI is unchanged, so no binding regeneration; both get the fix through the same ServiceEngine::start.
  • Codex review (code and security, one round): one finding, fixed in this PR (account keys of an av a repaired file no longer names). The reset keys of a pending reset on a file put back from an older copy stay in the device store, as after Sign Out on such a file; ADR 0081 records it, since the device store lists no items by account.

@datlechin
datlechin merged commit 5a7de60 into main Nov 28, 2026
8 of 35 checks passed
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