Skip to content

fix: avoid waits after profile saving - #1711

Merged
ovitrif merged 2 commits into
masterfrom
fix/profile-save-latency
Oct 27, 2026
Merged

ovitrif merged 2 commits into
masterfrom
fix/profile-save-latency

Conversation

@ben-kaufman

@ben-kaufman ben-kaufman commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Companion: synonymdev/bitkit-e2e-tests#287 (merged) — shared widget Delete helper used by Android E2E.
Companion: synonymdev/bitkit-ios#1147 — matching profile-save regression journey.
Companion: pubky/paykit-rs#236 — removes the shared mobile DHT wait; the Android post-save fix is independent.

This PR stops profile saving from waiting for redundant reads after the profile has already been published and saved locally.

Description

  • Completes creation after the required signup, profile publication and local cache write succeed, keeping those failures visible.
  • Loads contacts in the repository scope with the existing identity guard and avoids immediately fetching the profile that was just saved.
  • Adds a journey that records Saving duration and verifies profile persistence after restart, waiting for the loaded profile instead of treating cached metadata as a completed load.

Out of Scope

None.

Design

N/A — no UI changes.

Preview

N/A — no visual layout changes; this changes when successful saving completes.

QA Notes

Setup

Use a dedicated unfunded dev wallet with Paykit enabled, no existing Pubky identity, PIN disabled, English selected and working access to the configured signup service. Do not reset an existing wallet or enable contact payments during this check. The source dependency remains paykit-android:0.1.1-rc1; the separate shared SDK candidate was tested through a local AAR only.

Journeys

  • J1: new create-profile.xml — saves a name-only profile, records Saving duration and checks the saved name after app relaunch.

Manual Tests

N/A — the journey covers the requested interaction; failure and identity-race cases are automated.

Automated Checks

  • updated PubkyRepoTest.kt — proves saving completes while contacts are held, cache-write failure remains visible, the published profile is retained without readback, and a wipe during contact loading cannot restore the old identity.

Evidence

The focused repository suite passed 218 tests. Final just compile, just test and just lint passed for the published runtime change (409b100): 4,613 unit tests, no failures or skipped tests, zero detekt SARIF findings and zero Android Lint XML findings. Complete structured diagnostics were inspected.

J1 was exercised on an API 36 arm64 Pixel 8 emulator with app base aa8607f0d2a8cb631c480bac6184bc03e226acd1, this Android change and the locally built relay-only SDK candidate. Creation succeeded and the exact name and identity survived app restart. The completion log was 25.655 seconds after Save; stale accessibility snapshots prevented an exact UI-duration measurement. This is one observation, not a controlled before/after benchmark.

The branch is based on 7ce91e86ef7123ffdc420d193d393b5b1d12dd97. Its USDT cache changes do not change the reviewed profile save path. XML and all seven UI identifiers were verified on that base. Independent source review and the base-interaction delta review found no actionable issues.

The journey follow-up in 17e0512fe37e1660d14a7313d15e75e061dd10b6 waits for ProfileViewName after relaunch, checks the exact saved value and confirms ProfileCachedHeader is gone. An unfinished load is reported separately from a loaded profile with a missing name. Saving-time steps are unchanged. XML parsing, all 13 action steps against the matching iOS journey, source identifier/state checks, git diff --check and independent review passed. This documentation-only follow-up changes no Kotlin, SDK pin or CI configuration; no fresh application build or device execution is claimed. Both commits in the entire PR range were cryptographically verified locally against live master 25e1aa49337703d8890e69bbee5e49f2653dbe9d and reported verified/valid by GitHub.

Gaps

The field 30–90 second delay was not reproduced end to end. The shared SDK direct-DHT fix is in pubky/paykit-rs#236 and requires a reviewed SDK release plus approved mobile adoption. This PR independently removes Android's post-save read/contact wait and changes no SDK pin. The device observation predates the SDK's additional app-publication batching optimization and does not execute the revised restart-wait journey.

Models used

  • Planning/scoping: gpt-6-astra (reasoning: xhigh)
  • Implementation: gpt-6-astra (reasoning: xhigh)
  • Review: gpt-6-astra (reasoning: xhigh)
  • CI monitoring: gpt-6.1-sol (reasoning: xhigh)

CI follow-up (27 October)

The shared widget Delete target was obscured by the fixed Home header. E2E #287 (7824c8e) fixes that hit target without changing app code. Run 40516074936 was rerun once from the branch resolver so its dependent tests use the corrected E2E branch.

Backup now gets past widget deletion and saves the price widget, then fails because PriceWidget never appears. All three attempt logs report price-feed Bad Gateway errors; read-only requests at 16:03 UTC confirmed HTTP 502 from both the price-history and news endpoints on feeds.synonym.to. The later WidgetSave timeout is the test's retry after returning Home. Widget/feed source is identical between this PR's base and head. CI remains blocked on feed recovery; no test was disabled and no further unchanged run was requested. The widget shard has now finished: seven cases passed, including the complete content-widget add/remove case. Its two remaining price-widget cases failed on all three attempts after deletion, with PriceService Bad Gateway and no price data in every attempt's logcat. Run 40516074936 is complete with five successful shards and two blocked by the feed outage.

A bounded read-only recheck at 17:20 UTC still returned HTTP 502 from both feed endpoints. The documentation follow-up does not clear this runtime E2E acceptance gap, even if its own change-filtered CI skips E2E. Recheck feed recovery before one bounded affected-job rerun; no unchanged outage rerun was requested.

Current-head CI result (27 October)

At 17e0512fe, build/unit workflow 40550316259 passed all 4,613 tests with zero failures or skips. The downloaded report totals agree with the complete job log. Lint workflow 40550316028 passed; the complete artifact contains zero Detekt SARIF findings and zero Android Lint SARIF/XML issues.

E2E run 40550316994 has finished with five successful shards and two failed groups. Both complete failure logs resolve the corrected E2E suite 7824c8e209ada0b001508a28aba8d6f6722131e6. The widget group passed seven cases and failed the same two price-widget cases; the backup group passed six and failed its widget-dependent backup case. All three attempts in each group report price-feed Bad Gateway in logcat. A read-only recheck at 18:13 UTC still returned HTTP 502 from both price and news endpoints. Full logs and hash-verified artifacts are retained. Required E2E acceptance remains blocked on feed recovery; no manual rerun was issued for this unchanged outage.

@greptile-apps

greptile-apps Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Profile creation now finishes after publication and the local cache write succeed.

  • Profile saving ends before the contacts refresh finishes.

ben-kaufman explicitly defers shared SDK direct-DHT waits to separate work; this PR leaves the SDK pin unchanged.

Diagram

sequenceDiagram
    participant UI as Create profile screen
    participant Repo as PubkyRepo
    participant Service as Pubky service
    participant Cache as Local cache
    UI->>Repo: createIdentity
    Repo->>Service: Sign up or sign in if needed
    Repo->>Service: Publish profile
    Service-->>Repo: Published
    Repo->>Repo: Set created profile
    Repo->>Cache: Save metadata
    Cache-->>Repo: Saved
    Repo-->>UI: Success
    Repo->>Service: Load contacts in background
Loading

Reviews (1) · Last reviewed commit: "fix: avoid waiting for reads after profi..." · Reviewed by Greptile

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Regtest APK

Built from 17e0512 (run).

Download bitkit-dev-debug universal APK (expires in 30 days).

@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.

No findings. createIdentity now returns once the profile is published and cached locally, and moves the contact reload to the repository scope behind the sign-in guard instead of re-reading the just-saved profile and waiting on contacts. Reviewed 409b100, full tier, static: per this repo's track rules the branch was not built here, so this rests on the code and on CI.

What I checked, and 5 candidates I ruled out

Read in full: PubkyRepo.createIdentity, finishIdentityCreation, loadProfile, loadContacts/loadContactRecords, currentSignIn/isCurrent, startSignIn, setProfile, the four changed tests in PubkyRepoTest.kt, create-profile.xml and its README paragraph
Call sites traced: CreateProfileViewModel.save (the only caller), CreateProfileEffect.CreateSuccess to onNavigateToPayContacts, the contactsLoadVersion consumers in AppViewModel and ContactsViewModel
Journey: identical byte for byte to create-profile.xml in synonymdev/bitkit-ios#1147; every identifier it names resolves at this head (ProfileButton, ProfileIntro-button, PubkyChoiceCreate, CreateProfileUsername, CreateProfileSave, PayContactsContinue, ProfileViewName)
CI: detect-changes, e2e-branch / determine and Greptile green; build, build-local and lint still pending at review time

Ruled out

  • Dropping loadProfile() leaves the profile or its cache unset: finishIdentityCreation already calls setProfile(createdProfile) and cacheMetadata(createdProfile), and startSignIn already invalidates the read-only profile, which were the only side effects the readback added on success.
  • Errors used to surface through the old runSuspendCatching: loadProfile and loadContactRecords both catch and log internally, so that wrapper only ever carried cancellation; the required failures (signup, writeProfile, pubkyStore.update) still return from inside the mutex block, and the cache-failure test now asserts it on the first write.
  • The background contact load writes into a later identity after a wipe or sign-out: isCurrent(signIn) is checked before the launch body runs and again inside loadContactRecords before _contacts is updated, and clearAuthenticatedState bumps signInGeneration first.
  • Something downstream needs contacts loaded before Pay Contacts opens: PayContactsViewModel reads no contact state, and AppViewModel gates its Paykit sync on contactsLoadVersion > 0, a flow that fires whenever the load lands.
  • An exception in the launched job is lost or crashes: scope is appScope, a SupervisorJob with loggingExceptionHandler, the same scope the repository already uses for background work.

Merge confidence: 4/5, no findings, but the branch was not built here and build and lint were still pending.

Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed (the runner does not report an effort level)

@ovitrif ovitrif added this to the 3.1.0 milestone Oct 27, 2026
@ovitrif

ovitrif commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Triage: 3.1.0. It's a small fix for the slow profile saving every Lugano attendee hit (30–90 s after naming a new pubky), and 3.1.0 is cut on 28 Oct. An iOS twin, if one is needed, should join it.

@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: Reviewed the full PR diff against its merge base, at 409b100c.

No new actionable code findings.

Profile creation returns after signup, profile publication, and the local cache write. Contact loading then continues on the repository scope for that sign-in, and a wipe or newer sign-in drops the result before it is published. A failed publication or cache write still returns to the create screen and shows the error toast. The saved name is the name just written, which session restore can show again after relaunch.

iOS createProfile at 99241b77 already completes from the local profile, with contact loading following authentication. bitkit-ios#1147 adds the same journeys/profile/create-profile.xml. paykit-rs#236 at 9c0c2430 removes the shared mobile direct-DHT publication wait. Android remains on paykit-android:0.1.1-rc1, so homeserver publication can still wait until that SDK is adopted.

The CI build job, which runs testDevDebugUnitTest, and lint succeeded for this revision. This review inspected the changed tests and did not re-run them. J1 covers the name-only save and relaunch. The profile journey README's rejected-write and relay-only checks remain manual and were not run here.

Device testing: not performed in this review.

Ready for device testing.

Reviewer model: grok-4.7
Reasoning effort: high

jvsena42
jvsena42 previously approved these changes Oct 27, 2026

@jvsena42 jvsena42 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approving. The code scan found nothing, and the device gate passed.

Code: the post-mutex loadProfile() readback and the blocking loadContacts() are gone from createIdentity. Signup, publishPaykitProfile and cacheMetadata still run inside the mutex and still fail creation, and createdProfile is field for field what was written, so nothing required is skipped. The contact load now runs in appScope behind isCurrent(signIn), and clearAuthenticatedState bumps the generation first, so a wipe during the load can't write stale contacts.

Device gate: 409b100 (CI APK), create-profile.xml on the dev emulator, fresh unfunded wallet, staging signup. Pass.

  • Save → PayContactsContinue took 22.3 s.
  • No profile error. Home shows "Profile Save Test", and ProfileViewName shows it before and after a force-stop relaunch.
  • Base for comparison: master ea89ed1, same journey and network: 25.5 s. One run each, so the difference is within noise here. Signup dominates on this network, and a fresh identity has no contacts to load. The saving grows with homeserver latency and contact count, which this setup doesn't stress.
  • An earlier master attempt failed signup with identity_error (sign up Pubky identity) and passed on retry, so that failure came from staging, not the app.

The iOS run of the same journey is on synonymdev/bitkit-ios#1147.

@ovi-reviewer ovi-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: ✅ Approve

Findings: None.

QA for 17e0512:

Test 1: J1 — save and restore a new profile ✅ A new profile saved and its name appeared after a force-stop and relaunch.

On an API 36 Android emulator with a fresh unfunded dev wallet and Paykit enabled, I entered Profile Save Test, reached Pay Contacts, returned home without enabling contact payments, and reopened the profile before and after relaunch. The UI hierarchy showed ProfileViewName with the expected name and no ProfileCachedHeader after relaunch. The recording is choppy; a repeat also passed but had more stutter. This is not a controlled latency benchmark.

Profile creation and relaunch (2× speed).

I reviewed the full diff from 7ce91e8 to 17e0512, including creation, cancellation, identity guards, contact loading and the profile journey. Controlled write rejection and the held-contact race were not driven on device; the changed unit tests cover those paths. The earlier device report covers the runtime commit and a base comparison. The current-head E2E run still has widget and backup failures attributed in the PR to the price-feed outage.

The matching journey in bitkit-ios#1147 has the same actions; iOS already completes profile creation from the local profile.

Reviewer model: Unknown
Reasoning effort: Unknown

Model and effort were not exposed in the accessible session metadata.


Reviewed by gpt-6.1-terra-high via gh-pr-review-loop skill
Commands: @ovi-reviewer review · test · retest

@ovitrif ovitrif 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.

utAck

@ovitrif
ovitrif merged commit b392d6a into master Oct 27, 2026
30 of 33 checks passed
@ovitrif

ovitrif commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

@ben-kaufman Merged, as it was approved and green.

@ovitrif
ovitrif deleted the fix/profile-save-latency branch October 27, 2026 19:42
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.

5 participants