Skip to content

fix: disconnect a profile that newer paykit data keeps from loading - #1429

Open
ovitrif wants to merge 2 commits into
masterfrom
fix/disconnect-newer-paykit
Open

ovitrif wants to merge 2 commits into
masterfrom
fix/disconnect-newer-paykit

Conversation

@ovitrif

@ovitrif ovitrif commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1427

Description

  • Fixes Disconnect on a profile whose shared Paykit state a newer Bitkit saved: it showed the raw PaykitError.Storage text and left the profile in place, because sign-out first removes Paykit endpoints, which needs that state. A profile whose session never restored is now forgotten on this device only, as on Android (PubkyRepo.forgetUnrestoredIdentity()); the shared Paykit state on the homeserver stays untouched.
  • Drops a pending public endpoint cleanup with that identity, so it cannot run against the next profile.
  • Waits for a restore that is already running before deciding, so a profile restored during Disconnect is signed out, not only forgotten.
  • Shows the plain update message instead of the raw storage text when Disconnect fails with the same error on a restored profile.

Out of Scope

  • Homeserver: the endpoints and session of the forgotten identity stay; removing them needs a Bitkit that reads the newer state, as on Android.

Design

N/A — no UI changes.

Preview

N/A

QA Notes

Setup

As in #1427: connect a Paykit profile on regtest, stop Bitkit, write version 6 shared state for the same identity with a newer Paykit SDK, then relaunch this build.

Journeys

N/A — not drivable; see Manual Tests.

Manual Tests

  • 1. On Profile with the update hint above Try Again, tap Disconnect and confirm → Bitkit leaves Profile with no error toast; opening Profile again offers to connect a profile — needs Paykit state written by a newer SDK, not in Capabilities
  • 2. After case 1, connect a compatible profile → it connects and its Paykit endpoints are not removed — same capability
  • 3. Connected profile on regtest: turn off networking and relaunch so restoring waits (cached header with Try Again), then tap Disconnect and confirm → Profile offers to connect a profile
  • 4. In the same state, restore connectivity, tap Try Again and confirm Disconnect while the spinner shows → the profile is fully signed out and its public endpoints no longer resolve

Automated Checks

  • added PubkyProfileManagerTests.swift — Disconnect only forgets an identity that never restored and drops its pending endpoint cleanup; a restored one signs out as before; through the manager, a profile that needs an update is forgotten, and one restored while Disconnect waits is signed out

Evidence

xcodebuild test with the unit-tests.yml skips and swiftformat --lint pass on this change over master 325b409. Device cases not run.

Gaps

  • 1 and 2 not run: they need Paykit state written by a newer SDK.

Models used

  • Planning/scoping: Claude Opus 5.5 (reasoning: medium)
  • Implementation: Claude Opus 5.5 (reasoning: medium)
  • Review: gemini-4-neon-high (reasoning: high)

An identity that never restored is forgotten on this device, as on Android, and other sign-out errors show plain text.

Verified: xcodebuild test (unit-tests.yml skips), swiftformat --lint
@ovitrif ovitrif self-assigned this Nov 25, 2026
@ovitrif
ovitrif requested review from a team, jvsena42 and piotr-iohk and removed request for a team November 25, 2026 12:16
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T12:18:03.476634Z 2c99657 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes affect profile Disconnect and its error messages.

The PR appears safe to merge, with a non-blocking gap in testing the real Disconnect path.

Findings

  1. P2 Disconnect path remains untested ▶

Summary

Disconnect now forgets an identity locally when its session has not restored.

  • Disconnect forgets profiles that cannot restore their shared Paykit state.
  • Disconnect screens show an update hint for newer Paykit state.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Disconnect] --> B{Profile session restored?}
  B -->|No| C[Forget local session access]
  C --> D[Drop pending public cleanup]
  B -->|Yes| E[Remove endpoints and sign out]
  D --> F[Clear local app and profile state]
  E --> F
Loading

Reviews (1) · Last reviewed commit: "fix: disconnect a profile that newer pay..." · Reviewed by Greptile

@talosmachina talosmachina left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 finding (1 P1). Disconnect on a profile that never restored now forgets the identity on this device instead of failing on newer Paykit state, drops the pending public endpoint cleanup, and the sign-out toasts show the update message instead of the raw storage error. Reviewed 2c99657, full tier.

The P1: the restored/unrestored decision is taken before an in-flight session restore settles, so a Disconnect that races a successful restore takes the forget-only branch for an identity that did restore.

QA: static review. Not built: an auto-review never builds a Bitkit branch, and iOS does not build on this Linux host.

What I checked, and 3 candidates I ruled out

Read in full: PubkyProfileManager.swift (sign-out, session mutation, initializeSessionState, clearLocalAppState, endpoint removal), ProfileView.swift, EditProfileView.swift, PaykitError+NewerState.swift; PaykitSdkService.signOut, forgetSessionAccess, restorePersistedSession in PubkyService.swift.
Parity: PubkyRepo.forgetUnrestoredIdentity() and ProfileViewModel.signOut() on bitkit-android master.
Paykit: forget_session_access at the pinned paykit-rs 0b9c63d clears local session access only, takes no storage read, so it does not hit the newer-state error.
CI at review time: SwiftFormat, validate, build-local green; Run Tests, Run Integration Tests and e2e still pending.

Ruled out

  • Private contact-sharing cleanup flag left set: clearLocalAppState already clears it via clearPublicPaykitSharingState.
  • Profile deletion taking the forget-only branch: deleteProfile requires currentSession, so publicKey is set there.
  • profileErrorDescription masking a different storage error: it matches only the two newer-state contexts, other errors keep localizedDescription.
  • Cold reader: the finding stood; it rated it P2. I kept P1 because the outcome is a silent regression of Disconnect for a restorable identity, which Android guards with a dedicated test.

Merge confidence: 3/5, one P1 on the Disconnect-during-restore race.

Reviewer model: claude-opus-5-5, with xiaomi/mimo-v2.6-pro as the cold reader
Reasoning effort: Not exposed (the run metadata names the models only)

@piotr-iohk piotr-iohk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QA review

Scope: full PR diff against its merge base, at 2c99657.

No new actionable code findings.

This pass found no new actionable code findings. Disconnect on a profile that never restored now forgets the identity on this device instead of failing on newer Paykit state. The pinned paykit-rs forget_session_access at 0b9c63d clears local session access with no storage read, so this path avoids the newer-state error. It also deletes the saved session and secret key (PubkySessionAccessTeardown), so a forgotten identity does not come back through restoreSessionIfNeeded. Profile deletion still takes the restored path because it requires currentSession. clearLocalAppState already clears the private contact-sharing cleanup flag. The toast change only swaps the text for the two newer-state errors.

Existing unresolved concern (verified at this head). talosmachina's thread on the restore race holds against the pinned source. While a restore is in flight from Try Again or retrySessionRestoration, the cached header still shows Disconnect (ProfileView.swift#L327-L337). isRestored is read before anything waits for that restore (PubkyProfileManager.swift#L1633). restorePersistedSession and forgetSessionAccess both serialize on operationLock (PubkyService.swift#L559-L572, #L1696-L1702). The result: a successful restore is followed by an unrevoked local forget, the pending public cleanup is dropped, and initializeSessionState discards the restore on the revision check. The identity's endpoints and grant stay on the homeserver with no retry. At base, the same race ran private and public endpoint removal and PubkyService.signOut() after the restore. Android master checks _publicKey inside initializeMutex and has a regression test for this case. The basis is source analysis; I did not run anything. The thread is open and needs a fix or an evidence-backed rebuttal.

Greptile's test-gap thread is also accurate. testDisconnectOnlyForgetsAnIdentityThatNeverRestored supplies isRestored itself, so nothing covers how signOut() derives it from manager state, including the in-flight restore case above.

Parity: compared with bitkit-android master 791d51b (PubkyRepo.forgetUnrestoredIdentity, ProfileViewModel.signOut). Both platforms forget whenever the public key is null, which includes deferred (offline) and generic failed restores, not only the newer-state case. Both leave homeserver endpoints and the grant in place, as the PR's Out of Scope states. The only material difference is Android's lock-guarded check described above.

Validation: on PR CI, SwiftFormat, validate and build-local pass. Run Tests, Run Integration Tests and e2e were pending at review time, so unit test execution is not yet confirmed.

Recommended before device testing: resolve the restore-race thread, and wait for Run Tests to finish on this head.

Device testing: not performed in this review. Author cases 1 and 2 remain unrun. They need Paykit state written by a newer SDK.

Suggested additional test cases

  • iOS, regtest, connected profile: turn off networking and relaunch so restoration is deferred (cached header with Try Again). Tap Disconnect and confirm. Expected: Profile offers to connect a profile. On reconnecting the same identity, note whether its old endpoints still resolve; that is the accepted residue.
  • iOS, same deferred state: restore connectivity, tap Try Again, and confirm Disconnect while the spinner is showing. Expected: the profile is fully signed out and its public endpoints no longer resolve. Today the race above predicts they stay.

Reviewer model: claude-opus-5-5
Reasoning effort: high

Verified: xcodebuild test (unit-tests.yml skips), swiftformat --lint
@ovitrif
ovitrif requested a review from piotr-iohk November 25, 2026 13:08

@piotr-iohk piotr-iohk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QA review

Scope: changes since 2c99657, including affected code paths and prior findings, at e018ea9. Baseline: previous QA review. The previous head is an ancestor of the current head, and the merge base is unchanged. This pass re-read the one new commit, the Disconnect branching it changes, the profile-deletion caller and the new tests. Coverage of the error toasts, changelog, paykit-rs forget_session_access contract and the original signOutCleanup unit test carries over from the baseline.

No new actionable code findings.

No new actionable code findings in the follow-up.

Prior concern, fixed in the code. talosmachina's restore-race thread is marked resolved, and the code at this head supports that. The baseline QA review listed it as an existing concern. signOutOrForget now waits for every running initializationTask before it reads publicKey (PubkyProfileManager.swift#L1648-L1651). An identity that restores while Disconnect waits therefore takes the full sign-out path instead of the forget-only path. Nothing can start a new restore between the end of the wait and beginSessionMutation. The while loop also catches a restore that starts while Disconnect waits. The profile-deletion caller cannot wait: performProfileDeletion requires initializationTask == nil, and initialize refuses to start while a deletion is running. testDisconnectSignsOutAProfileRestoredWhileItWaits would fail without the wait, because it expects ["signOut"] and would get ["forget"].

Test-coverage thread, partly addressed. Greptile's thread is marked resolved. The new testDisconnectForgetsAProfileThatNeedsAnUpdate goes through the manager after .restorationNeedsUpdate. It checks that only the forget step runs and that the displayed key and the update flag are cleared. It still injects forgetSessionAccess, so the deletion of the saved session and secret key and the dropped pending-cleanup flag are not asserted. This is a coverage gap only, not a defect.

Android parity. Compared with bitkit-android master 791d51b. There, PubkyRepo.forgetUnrestoredIdentity() and signOut() both run under initializeMutex, so they also wait for a running restore before choosing a path. iOS now matches that behaviour.

Validation and limits. This is a source-only review. No Swift toolchain was available, so I did not compile or run anything. When I checked, the PR's unit-tests and integration-tests runs for e018ea9 were still in progress, so there is no CI result yet for the two new tests. Device testing was not performed in this review.

Suggested additional test cases

  • iOS, restore-race Disconnect: start with a saved profile whose restore was deferred (for example, open Profile while offline). Tap Try Again, or bring connectivity back, and confirm Disconnect while the restore is still running. Expected: the button stays disabled until the restore finishes. The identity is then signed out (its session ends and its endpoints are removed). Profile then offers a fresh connection, and the old identity does not come back after the app restarts.

Reviewer model: claude-opus-5-5
Reasoning effort: high

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.

[Bug]: Disconnect leaves an incompatible Paykit profile in place and shows a raw storage error

3 participants