Skip to content

fix(swift-sdk): run identityGet and dpnsGetUsername off the main actor - #5862

Merged
romchornyi merged 3 commits into
v5.1-devfrom
feat/swift-sdk-nonisolated-identity-reads
Nov 12, 2026
Merged

romchornyi merged 3 commits into
v5.1-devfrom
feat/swift-sdk-nonisolated-identity-reads

Conversation

@romchornyi

@romchornyi romchornyi commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Issue being fixed or feature implemented

SDK.identityGet(identityId:) and SDK.dpnsGetUsername(identityId:limit:) are @MainActor and call synchronous FFI exports (dash_sdk_identity_fetch, the DPNS username query) that block on the network fetch. An app that awaits them from its UI freezes the main thread for the whole round trip, including slow-network timeouts. Dash Wallet iOS hits this when it checks an Identity ID typed into its Send flow (dashpay/dashwallet-ios#1358).

What was done?

  • identityGet and dpnsGetUsername are now nonisolated and run the blocking FFI call through performBlockingQuery, the pattern documentList already uses in the same file; their results are returned as sending values. Signatures stay async throws, so callers compile unchanged.
  • The debug print lines in identityGet are removed.
  • Not changed in this PR: the other reads in PlatformQueryExtensions.swift with the same blocking shape (identityGetKeys, identityGetNonce, identityGetContractNonce, identityGetBalance, identityGetBalanceAndRevision, identityGetByPublicKeyHash, identityGetByNonUniquePublicKeyHash, dataContractGet, dataContractGetHistory, documentGet, dpnsResolve, dpnsSearch). They can follow the same pattern separately.

How Has This Been Tested?

  • New PlatformQueryOffMainTests.testIdentityReadsDoNotNeedTheMainActor: runs on no actor, holds the main thread, calls both reads against the FFI mock and asserts they return while the main thread is still held. A variant that runs the FFI on the main actor fails it (≈5.8 s wait).
  • xcodebuild test -scheme SwiftDashSDK -only-testing:SwiftDashSDKTests (iPhone 17 simulator): 937 tests, 1 skipped, 2 failures — both in KeychainSignerAdditionalSigningKeysTests (XCTUnwrap on a keychain write), which fail the same way without this change.
  • SwiftExampleApp build-for-testing succeeds.

Breaking Changes

None. Isolation is relaxed; the public signatures are unchanged.

Checklist:

  • I have performed a self-review of my own code
  • My Rust, FFI, WASM, Swift or Kotlin changes follow the coding conventions
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed
  • If I added or changed GroveDB structure, I described it in the area's structure.rs, regenerated grovedb-structure.json, and checked the structure viewer link posted on this pull request
  • If I added or changed a system contract's document schemas, I checked the contract viewer link posted on this pull request

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

PR Hygiene · da4773c

  • Bots — thepastaclaw ✓
  • Self-review — posted; again after any push
  • Build green
  • Approvals — you own every area touched; none needed

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

Summary by CodeRabbit

  • Bug Fixes
    • Identity and username lookups can now complete without waiting for the main queue, helping keep apps responsive when it is busy.
    • Username lookups return an empty result when no data or error is provided.

Both were @mainactor and called synchronous FFI exports that block on the
network fetch, so an app awaiting them froze its UI for the whole round trip,
timeouts included. They are now nonisolated and run the blocking call through
performBlockingQuery, as documentList does; their signatures stay async throws.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added this to the v5.1.0 milestone Nov 11, 2026
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 34 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 2df354f and da4773c.

Files selected for processing: 1

  • packages/swift-sdk/SwiftTests/SwiftDashSDKTests/PlatformQueryOffMainTests.swift

No actionable comments were generated in the recent review.

Walkthrough

identityGet and dpnsGetUsername now run FFI queries through the shared Platform query queue. Both parse copied JSON results. A test checks that the calls return while the main queue is held.

Changes: Platform query isolation

Layer / File(s) Summary
Query execution and validation
packages/swift-sdk/Sources/SwiftDashSDK/FFI/PlatformQueryExtensions.swift, packages/swift-sdk/SwiftTests/SwiftDashSDKTests/PlatformQueryOffMainTests.swift
identityGet and dpnsGetUsername are now nonisolated and use performBlockingQuery. The methods parse copied JSON results; dpnsGetUsername returns an empty array when the FFI result has neither data nor an error. The test checks that both calls return while the main queue is held.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related issues

Possibly related PRs

  • dashpay/platform#5715: Adds another Platform query through the shared query queue, using the same off-main-actor approach.

Suggested reviewers: jeanpierreroma

Merge Risk: Minimal · previous review 2df35

Both identity reads now run off the main actor, which reduces the risk of UI freezes during network fetches. The supplied evidence shows no remaining merge-blocking risk.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: moving identityGet and dpnsGetUsername off the main actor in the Swift SDK.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 2 files.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between d4a42a0 and 2df354f.

Files selected for processing: 2

  • packages/swift-sdk/Sources/SwiftDashSDK/FFI/PlatformQueryExtensions.swift
  • packages/swift-sdk/SwiftTests/SwiftDashSDKTests/PlatformQueryOffMainTests.swift

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Nov 11, 2026
@thepastaclaw

thepastaclaw commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit da4773c) · triage: low

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

Final validation — Phase 1 + Phase 2

At head 2df354f, both queries correctly reuse the off-main executor while preserving FFI ownership, error handling, and absence semantics. Static verification confirms two non-blocking suggestions: track the remaining instances of the same blocking-query pattern and strengthen the new test's error assertions. The Swift CI log reports 937 SDK tests with one skipped and no failures; the overall Swift check failed later because the simulator could not launch the SwiftExampleApp test runner, not because of an identified defect in this diff.

🟡 2 suggestion(s)

Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.

1 finding(s) not shown inline (the lines are not part of this PR's diff)

🟡 Suggestion: Track the remaining main-actor blocking query wrappers
packages/swift-sdk/Sources/SwiftDashSDK/FFI/PlatformQueryExtensions.swift:232-239

The same blocking pattern remains in sibling methods: identityGetKeys, identityGetNonce, identityGetBalance, dpnsResolve, and dpnsSearch, among others, inherit main-actor isolation from this extension and directly invoke Rust exports that synchronously call runtime.block_on. Awaiting those methods from UI code therefore still freezes the main thread during the network round trip. Limiting this fix to the two reported reads is reasonable, but the missed instances need a linked tracking issue before being deferred. Issue #5303 covers error assertions, error mapping, and executor consolidation rather than these migrations; closed issue #5145 targets the previously converted document and contest queries. Link a dedicated follow-up covering the remaining wrappers, or migrate them here.

source: glm-5.3-flash (phase1-reviewer: general)

Review provenance

Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.1-sol (effort low) — This is a small, contained change that moves two blocking reads onto an existing off-main execution helper and adds a focused regression test without changing critical protocol or financial logic.
  • Phase 1 reviewers: glm-5.3-flash — general (completed, effort high); agent phase1-reviewer
  • Phase 1 model: glm-5.3-flash — zai quota: 5h 92% left, weekly 79% left; passed over gemini-3.8-flash-high (antigravity quota lookup failed)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — ffi-engineer (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort medium); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.

In `packages/swift-sdk/Sources/SwiftDashSDK/FFI/PlatformQueryExtensions.swift`:
- [SUGGESTION] packages/swift-sdk/Sources/SwiftDashSDK/FFI/PlatformQueryExtensions.swift:232-239: Track the remaining main-actor blocking query wrappers
  The same blocking pattern remains in sibling methods: `identityGetKeys`, `identityGetNonce`, `identityGetBalance`, `dpnsResolve`, and `dpnsSearch`, among others, inherit main-actor isolation from this extension and directly invoke Rust exports that synchronously call `runtime.block_on`. Awaiting those methods from UI code therefore still freezes the main thread during the network round trip. Limiting this fix to the two reported reads is reasonable, but the missed instances need a linked tracking issue before being deferred. Issue #5303 covers error assertions, error mapping, and executor consolidation rather than these migrations; closed issue #5145 targets the previously converted document and contest queries. Link a dedicated follow-up covering the remaining wrappers, or migrate them here.

In `packages/swift-sdk/SwiftTests/SwiftDashSDKTests/PlatformQueryOffMainTests.swift`:
- [SUGGESTION] packages/swift-sdk/SwiftTests/SwiftDashSDKTests/PlatformQueryOffMainTests.swift:73-82: Reject pre-FFI failures in the new regression test
  Both bare catches accept `SDKError.invalidState`, including the error thrown by `performBlockingQuery` before it invokes the FFI closure. A regression that makes handle acquisition fail would therefore let this test pass while neither query reaches Rust, despite the test's stated invariant. The main-thread timing assertion remains useful, but it should be paired with an assertion that these calls did not fail before entering the FFI. This is the same weakness documented in issue #5303; avoid adding two more instances in the new test.

@github-actions

Copy link
Copy Markdown
Contributor

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Nov 11, 2026
@romchornyi

Copy link
Copy Markdown
Contributor Author

Re the suggestion to track the remaining main-actor blocking query wrappers: deferred, tracked in #5867 (the 12 sibling reads in PlatformQueryExtensions.swift, same nonisolated + performBlockingQuery pattern). This PR keeps to the two reads the iOS Send flow awaits.

…ver reaches the FFI

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head and removed waiting-self-review Waiting for the author to post /self-reviewed labels Nov 11, 2026

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

Re-review — Final validation — Phase 1 + Phase 2

At 5d99479, both regression-test calls now reject pre-FFI invalidState failures, and the off-main query changes preserve FFI ownership and existing result semantics. One minor test-handshake robustness issue remains; no blocking defects were confirmed. Static verification and current CI show passing Swift SDK build/tests and frozen-schema checks, with review and PR Hygiene checks pending.

💬 1 nitpick(s)

Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.

Review provenance

Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.1-sol (effort low) — This is a small, contained change moving two blocking reads onto an existing query execution pattern, with focused regression coverage and no changes to critical protocol or financial logic.
  • Phase 1 reviewers: glm-5.3-flash — general (completed, effort high); agent phase1-reviewer
  • Phase 1 model: glm-5.3-flash — zai quota: 5h 84% left, weekly 77% left; passed over gemini-3.8-flash-high (antigravity quota lookup failed)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — ffi-engineer (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort medium); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.

In `packages/swift-sdk/SwiftTests/SwiftDashSDKTests/PlatformQueryOffMainTests.swift`:
- [NITPICK] packages/swift-sdk/SwiftTests/SwiftDashSDKTests/PlatformQueryOffMainTests.swift:66-71: Bound the wait for the main-thread hold to start
  The five-second timeout only starts after the main-queue block executes. The initial mainHeld.wait() has no deadline, so if the test host stops servicing the main queue before that block starts, this continuation never resumes and the test waits for an external runner timeout instead of reporting a local failure. This is test robustness rather than a defect in the query implementation. Give the handshake a bounded wait and report a test failure on timeout; use a throwing continuation if propagating that failure as an error.

@github-actions

Copy link
Copy Markdown
Contributor

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Nov 11, 2026
The wait for the main queue to start the hold had no deadline, so a host
that never serviced the main queue made the test hang instead of fail.
Wait at most 5 seconds, release the hold, and throw an error saying the
main queue never ran it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head and removed waiting-self-review Waiting for the author to post /self-reviewed labels Nov 12, 2026

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

Re-review — Final validation — Phase 1 + Phase 2

Static verification at da4773c found no new actionable defects in the off-main query wrappers or current-head test changes. The reported identity-not-found message regression does not occur because the old null-pointer branch was unreachable. Current CI reports successful Swift SDK build/tests and frozen-schema checks, with no failed code checks; PR Hygiene and PastaClaw review remain pending.

🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)

Review provenance

Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.1-sol (effort low) — This is a small, contained change moving two blocking reads onto an existing off-main execution helper, with focused regression tests and no changes to critical protocol or financial logic.
  • Phase 1 reviewers: glm-5.3-flash — general (completed, effort high); agent phase1-reviewer
  • Phase 1 model: glm-5.3-flash — zai quota: 5h 87% left, weekly 66% left; passed over gemini-3.8-flash-high (antigravity quota lookup failed)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — ffi-engineer (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort medium); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify the current code and confirm that no unresolved issues remain.

No unresolved findings remain from the prior review on this head.

@github-actions

Copy link
Copy Markdown
Contributor

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Nov 12, 2026
@romchornyi

Copy link
Copy Markdown
Contributor Author

/self-reviewed

@github-actions

Copy link
Copy Markdown
Contributor

Policy satisfied — this can merge.
Full checklist in the description.

@github-actions github-actions Bot removed the waiting-self-review Waiting for the author to post /self-reviewed label Nov 12, 2026

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

Read the diff and the surrounding helpers; no bugs found.

  • Behaviour is unchanged: identityGet still throws notFound on an empty result, dpnsGetUsername still returns [], and FFI errors keep their typed mapping.
  • FFI ownership is right: the string and error are copied and freed inside the closure on the query queue, and performBlockingQuery retains self for the duration of the call.
  • The new test holds the main thread across both calls and rejects invalidState, so a regression back to @MainActor would be caught.

I did not run the tests locally; CI is green.

@romchornyi
romchornyi merged commit 0c4fdf9 into v5.1-dev Nov 12, 2026
28 checks passed
@romchornyi
romchornyi deleted the feat/swift-sdk-nonisolated-identity-reads branch November 12, 2026 13:57
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.

3 participants