Skip to content

fix(swift-sdk): admit shielded spend wrappers as native operations - #6179

Merged
QuantumExplorer merged 3 commits into
v5.1-devfrom
fix/swift-sdk-shielded-spend-admission
Nov 24, 2026
Merged

QuantumExplorer merged 3 commits into
v5.1-devfrom
fix/swift-sdk-shielded-spend-admission

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Basic explanation

What this does. When the iOS SDK starts a shielded payment, it now counts that payment as "in progress" on the wallet manager until the payment's result is back. Ten calls that did not do this now do: transfer, shield (three variants), unshield, withdraw, identity top-up and identity create from the pool, token purchase from the pool, and abandoning an identity debit.

Value. A shielded payment takes tens of seconds to prove. Before this, the app could delete the wallet or shut the manager down in that window: deleteWallet passed its "nothing is running" check, and shutdown() destroyed the native manager under the payment. Now deleteWallet is refused while a payment runs, and shutdown() waits for it.

Risks.

  • shutdown() now waits for one of these payments in flight. For five of them (transfer, unshield, withdraw, identity create, token purchase) that is a proof, a broadcast and its result wait.
  • The other five (shieldedShield, shieldedShieldToRecipient, shieldedShieldFromIdentity, shieldedIdentityTopUpFromPool, abandonShieldedIdentityDebit) share a Rust lock with Core asset-lock funding, so one started while a funding is pending on the same wallet queues behind it. That funding can wait for a ChainLock with no deadline. If the host has stopped SPV by then, the ChainLock never comes, and shutdown() does not return and deleteWallet stays refused until the app restarts. No funds are lost and the asset lock stays resumable. It takes a stuck funding, a second shield-class payment on the same wallet and a host that stops SPV before shutting down; in SwiftExampleApp that needs two windows. The base already has the direct form of this through shieldedResumeFundFromAssetLock and the wallet-drain funding. Let shutdown cancel long-running shielded wallet operations #6003 tracks the fix (shutdown cancels the funding wait); the five wrappers and shutdown() now document it.
  • The synchronous calls that refuse to run beside an admitted operation (deleteWallet, the synchronous createWallet / createWalletFromSeed / loadFromPersistor) now throw invalidHandle while one of these payments runs.
  • Three funding calls are deliberately left as they were, so the gap stays open for them (see "Not covered here").

Issue being fixed or feature implemented

Closes #6060 for the payments; its funding calls are tracked in #6003 and its recovery read in #6177. The Swift half of #5868; the Rust half (the wallet's lifecycle gate and Clear's admission held across the credit pool payments) is #6178.

Confirmed on v5.1-dev: each wrapper below called its FFI export from Task.detached with no admitNativeOp / finishNativeOp. Already admitted, and unchanged: shieldedTokenTransfer, shieldedTokenUnshield, shieldedTokenSpendPreview, shieldedResumeFundFromAssetLock, the wallet-drain calls, createPrivateDocumentEntry, privateDocumentCreateFee, privateDocumentRecipientKeys and the three private contact request writes.

Prior work: #5863 on v5.2-dev (commit aba2e7bb4a) admits one wrapper, shieldedShieldFromIdentityToRecipient, which does not exist on v5.1-dev. This follows the same shape (admit on the main actor before the detached task, an injectable native call for tests) and stays out of the lines that commit touches, so the forward merge should be clean. No open pull request covered the rest.

What was done?

Each wrapper now runs its native call through the existing withAdmittedNativeOperation helper, after its parameter checks, the way shieldedTokenTransfer does. The helper admits on the main actor, runs the call on a detached task and releases the admission once the result is back. Cancelling the awaiting task does not release it: the detached call is not cancelled, and the helper keeps waiting for it.

File Wrappers admitted
PlatformWalletManagerShieldedSync.swift shieldedTransfer, shieldedShield, shieldedShieldFromIdentity, shieldedShieldToRecipient, shieldedUnshield, shieldedIdentityTopUpFromPool, shieldedTokenPurchaseFromPool, shieldedWithdraw, shieldedIdentityCreateFromPool
PlatformWalletManagerShieldedRecovery.swift abandonShieldedIdentityDebit

The native exports behind them are called through a new function table, PlatformWalletNativeShieldedSpendCalls (.live in production), so a test can pause a real wrapper inside its native call without a fake handle ever reaching Rust.

clearShielded() is deliberately not changed and not gated in Swift. Whether a Clear may run during a payment is decided in Rust: #6182 makes the native Clear return a typed, retryable refusal while a shielded operation runs, and #6178 makes the credit pool payments hold the admission that refusal reads. With all three merged, tapping Clear during one of those payments gives that refusal. Nothing here can deadlock with it: none of the wrappers runs main-actor work between admission and the return of the native call, deleteWallet is refused before any native call, and the callbacks a spend makes (mnemonic resolver, Keychain signer, persister) do not hop synchronously to the main thread. The persister callback bodies were not audited line by line.

Before / after

let payment = Task { try await manager.shieldedTransfer(walletId: id, resolver: resolver, recipientRaw43: to, amount: 5) }
// ... the proof is being built ...
try manager.deleteWallet(walletId: id)
await manager.shutdown()
  • Before: deleteWallet ran beside the payment, and shutdown() returned after destroying the native manager while the payment was still in its native call.
  • After: deleteWallet throws PlatformWalletError.invalidHandle("an async native operation is in flight; synchronous deleteWallet rejected"), and shutdown() returns only after the payment has returned its result.

Public interface changes

No public signature, type or error case changes. Behaviour changes on PlatformWalletManager:

  • The ten wrappers in the table are admitted native operations. While one runs, deleteWallet(walletId:) and the synchronous createWallet, createWalletFromSeed and loadFromPersistor throw invalidHandle, as they already did beside a token pool transfer or a wallet create.
  • shutdown() waits for them before it destroys the native handle.
  • A wrapper called once shutdown has begun throws invalidHandle before any native work. It already did, through its isConfigured check; the admission is now a second check behind it.
  • Their doc comments say so. shieldedFundFromAssetLock, shieldedFundFromCoinJoinDrain and seedShieldedPoolNotes gained a doc note saying they are deliberately not admitted, and are otherwise unchanged.

Internal additions (not visible to SDK users):

  • struct PlatformWalletNativeShieldedSpendCalls, in the new PlatformWalletNativeShieldedSpendCalls.swift: one field per native export, typed as the export is imported into Swift.
  • PlatformWalletManager.nativeShieldedSpendCalls, the test seam, next to the existing nativeTeardownCalls / nativeCreateCalls / nativeLoadCalls.

Not covered here

How Has This Been Tested?

New ShieldedSpendAdmissionTests, every case through the real public wrappers with only the native exports replaced, and every wait bounded so a leaked admission fails by wrapper name instead of hanging:

  • testShouldRefuseDeleteWalletWhileShieldedTransferIsInFlight
  • testShouldHoldShutdownUntilEveryPausedSpendReturns (all ten wrappers: deleteWallet refused, the injected destroy not run and shutdown() not finished while paused; result returned and destroy run once after release; each wrapper reaches its own export with the right handle and wallet id)
  • testShouldRejectSpendsStartedAfterShutdownBeganWithoutNativeWork (all ten)
  • testShouldHoldAdmissionAfterTheAwaitingTaskIsCancelled

What ran: xcodebuild test -scheme SwiftDashSDK -only-testing:SwiftDashSDKTests/ShieldedSpendAdmissionTests -only-testing:SwiftDashSDKTests/PlatformWalletShutdownTests -parallel-testing-enabled NO on an iPhone 17e simulator, in a scratch copy of the package: 19 tests, 0 failures (the 4 new ones and the 15 existing shutdown tests). Swift compiled with no warnings in the touched files.

A deliberate leak (an unbalanced admission in shieldedWithdraw) made testShouldHoldShutdownUntilEveryPausedSpendReturns fail in 7.7 s with "shieldedWithdraw: shutdown did not finish within 5.0 s"; the run went on through the other wrappers and the other three tests passed. The leak was then removed and the clean run repeated.

The scratch copy linked a simulator xcframework built from a sibling checkout, with headers regenerated from this branch's base. That library predates six exports older code calls (none of them among the ten here), so the link needed scratch-only stubs for those six; no test calls them. The spend exports are replaced by the test table in every case, so the only native code these tests ran was MnemonicResolver and KeychainSigner setup.

Not yet verified

  • Not run against this branch's own native build. swift test needs a macOS slice of DashSDKFFI.xcframework, which no prebuilt copy on this machine has, and I did not start a native build. The "Swift SDK build + tests (warnings as errors)" job on this pull request runs packages/swift-sdk/run_tests.sh (build_ios.sh --target tests, then swift test), which does.
  • No build_ios.sh, no SwiftExampleApp build, no simulator run of a real payment with a delete or shutdown in flight.

Breaking Changes

None.

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

🤖 Generated with Claude Code

PR Hygiene · 6adcc91

  • Bots — thepastaclaw requested changes — dismiss the review or push a fix
  • Self-review — post /self-reviewed
  • Reviewer requests paused — your 5 review slots are occupied; this PR is excluded from reviewers' queues. Required approvals still count without a slot.
  • Build running
  • Approvals
    • swift-sdk (packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManager.swift, packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedFunding.swift, packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedRecovery.swift and 3 more) — llbartekll or romchornyi

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.

The shielded spend wrappers on PlatformWalletManager ran their FFI call
from a detached task without admitNativeOp / finishNativeOp, so
deleteWallet passed its in-flight check and shutdown() destroyed the
native manager while a payment was still proving or broadcasting.

Admit the thirteen that were not: transfer, shield, shield to recipient,
shield from identity, unshield, withdraw, identity top-up and identity
create from the pool, token purchase from the pool, fund from asset
lock, fund from CoinJoin drain, pool seeding and identity debit
abandonment. Their native calls go through an injectable table so tests
pause each wrapper in flight without reaching Rust.

Refs #6060, #5868

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

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 11 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 3b4117c and 6adcc91.

Files selected for processing: 6

  • packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManager.swift
  • packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedFunding.swift
  • packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedRecovery.swift
  • packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedSync.swift
  • packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletNativeShieldedSpendCalls.swift
  • packages/swift-sdk/SwiftTests/SwiftDashSDKTests/ShieldedSpendAdmissionTests.swift
  • 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

@github-actions github-actions Bot added this to the v5.1.0 milestone Nov 23, 2026
@thepastaclaw

thepastaclaw commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

⛔ Final review complete — 1 blocking finding(s) (commit 6adcc91) · triage: normal

@github-actions

github-actions Bot commented Nov 23, 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 23, 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.

Final validation — Phase 2 only (queue backlog)

Changes requested: 1 blocker

  • Wallet shutdown can hang if SPV stops before shielded funding gets its ChainLock — packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedFunding.swift:153-159 (new)
    Impact: An iOS host that stops SPV and replaces the wallet manager while a broadcast asset lock still needs finality can be left with an unusable old manager and no active replacement.

This PR holds Swift native-operation admission through the result of thirteen shielded wallet calls and adds XCTest coverage using injected native exports. The Swift frozen-schema check passed; the Swift build-and-test and Kotlin SDK checks were still pending.

🔴 1 blocking | 🟡 3 suggestion(s)

Review provenance

Source: reviewer 1: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 4: gpt-6.2-sol (agent: phase2-reviewer, role: security-auditor); reviewer 5: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 6: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 7: gpt-6.2-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 8: gpt-6.2-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.2-sol (effort low) — The change applies native-operation tracking across thirteen Swift wrappers, requiring review of cancellation and shutdown behavior without changing how funds are moved.
  • Phase 1 reviewers: not run (skipped for throughput: 11 PRs queued, above the 10 limit)
  • Second Phase-2 pass: on this first full review every Phase-2 reviewer also ran a second, independent time, and the verifier weighed both sets
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — ffi-engineer (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — security-auditor (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — ffi-engineer (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — security-auditor (completed, effort high); 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/PlatformWallet/PlatformWalletManagerShieldedFunding.swift`:
- [BLOCKING] packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedFunding.swift:153-159: Wallet shutdown can hang if SPV stops before shielded funding gets its ChainLock
  Impact: An iOS host that stops SPV and replaces the wallet manager while a broadcast asset lock still needs finality can be left with an unusable old manager and no active replacement.
  A same-network SDK rebuild can now strand the active wallet manager, not just the payment. The Send screen calls this wrapper directly (`SendViewModel.swift:1051`), so the funding check in `OptionsView.swift:692–696` misses it and the rebuild stops SPV before awaiting the old manager's shutdown (`WalletManagerStore.swift:317`). The fresh funding and CoinJoin drain exports pass no ChainLock deadline (`shielded_send.rs:2325–2327, 2483–2485`); without a locally usable proof, the Rust loop only retries and never checks for shutdown (`asset_lock/sync/proof.rs:769–774`). The new admission makes shutdown wait for that call after revoking the handle needed to restart SPV (`PlatformWalletManager.swift:1021–1025, 1058–1062`). Keep the handle fence, but signal the Rust funding flow before draining so it can return a pending result with the tracked outpoint intact. Have seeding stop at a safe batch boundary as well. Cover shutdown after SPV stops without delivering a covering ChainLock; releasing a mocked export does not exercise this path.
- [SUGGESTION] packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedFunding.swift:248-254: Asset-lock funding remains outside the PR's stated Clear protection
  Impact: A host that clears shielded state during asset-lock funding, a CoinJoin drain, or a seed batch can see Clear succeed and then receive an activity write from that same call.
  The PR description says Clear will refuse these payments once the companion changes land, but that guarantee does not cover the asset-lock paths. Swift `clearShielded()` does not read the new admission count, and #6178 does not add coordinator admission to these paths. Native funding takes `shield_guard`, which coordinator Clear does not take, then records the landed shield through the wallet's persister (`fund_from_asset_lock.rs:211, 615–616, 798–807`). Changing Clear to a retryable refusal in #6182 therefore does not fence that write. Narrow the description to Swift deletion and shutdown, and keep the asset-lock Clear gap tracked on v5.1. The Clear epoch check proposed in #5934 shows how to reject the stale write without making Clear wait for finality.

In `packages/swift-sdk/SwiftTests/SwiftDashSDKTests/ShieldedSpendAdmissionTests.swift`:
- [SUGGESTION] packages/swift-sdk/SwiftTests/SwiftDashSDKTests/ShieldedSpendAdmissionTests.swift:326-331: The shutdown test hangs if a wrapper leaks its admission
  Impact: A regression that leaves the admission count above zero can make Swift CI hit its job timeout instead of identifying the wrapper that prevented shutdown.
  After the fake native call is released, `call.value` can return even if the wrapper forgot to release admission. The next `await shutdown.value` then waits indefinitely on the manager's drain continuation; the recorder's semaphore timeout no longer applies. Have the shutdown task fulfill a wrapper-specific XCTest expectation, and exit the case on timeout rather than awaiting an unfinished task. The rejection and cancellation tests have the same unbounded final await.

In `packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedSync.swift`:
- [SUGGESTION] packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedSync.swift:1063-1067: The new spend wrappers duplicate the existing admission sequence
  Impact: A future change to the admission helper can update token spends and asset-lock resume while leaving the thirteen newly guarded wrappers with different teardown behavior.
  `withAdmittedNativeOperation` already covers the same lifetime: it admits on the main actor, captures the handle, awaits a detached native call and its result conversion, and releases admission even when the call throws. Use it for wrappers that have no separate main-actor work after the native result. Capture the injected call table before entering the helper, and keep the signer or resolver alive while reading its raw pointer inside the closure, as `shieldedTokenTransfer` already does.
Out-of-scope follow-up suggestions (1)

These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.

  • Clear can still erase recovery state during a token purchase — Token purchase holds the wallet-generation guard but not the coordinator's operation guard. Clear can still remove saved recovery state while the purchase proceeds; the new Swift handle admission does not change that ordering.
    • Follow-up: Resolve #6176 in the Rust wallet and test that Clear refuses while a token purchase is paused with recovery state saved.

@github-actions

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them.
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 23, 2026
Review follow-up on the shielded spend admission:

- shieldedFundFromAssetLock, shieldedFundFromCoinJoinDrain and
  seedShieldedPoolNotes are not admitted after all. The fundings wait
  for a ChainLock with no deadline and a seeding run lasts tens of
  minutes; shutdown() cannot cancel a native call, so admitting them
  let shutdown hang once the host had stopped SPV (#6003). Ten bounded
  wrappers stay admitted;
- those ten go through withAdmittedNativeOperation instead of repeating
  its admit / detach / finish sequence;
- every wait in ShieldedSpendAdmissionTests is bounded, so a wrapper
  that leaks its admission fails the test by name instead of hanging.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@github-actions

github-actions Bot commented Nov 24, 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.

@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

Changes requested: 1 blocker

  • Wallet shutdown can hang if SPV stops before shielded funding gets its ChainLock — packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedSync.swift:1236-1237 (carried)
    Impact: An iOS host that stops SPV to reconfigure a manager while a Platform-credit shield is queued behind Core funding on the same wallet can be left with a revoked manager and no active replacement.

New on this head: This revision routes ten shielded-payment and recovery wrappers through the shared native-operation admission helper, leaves fresh asset-lock funding and pool seeding unadmitted, and bounds the tests’ completion waits. The Tests workflow was pending and the Kotlin build and tests were queued; no code check had failed, and there was no Swift build or test result against this head’s native library.

🔴 1 blocking

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 4: gpt-6.2-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 5: gpt-6.2-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.2-sol (effort low) — The ten wrappers change when Swift admits native calls and releases the wallet manager, so cancellation and shutdown ordering warrant review, but the diff does not change how funds are selected or moved.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (lane failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — ffi-engineer (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — security-auditor (completed, effort high); 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/PlatformWallet/PlatformWalletManagerShieldedSync.swift`:
- [BLOCKING] packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedSync.swift:1236-1237: Wallet shutdown can hang if SPV stops before shielded funding gets its ChainLock
  Impact: An iOS host that stops SPV to reconfigure a manager while a Platform-credit shield is queued behind Core funding on the same wallet can be left with a revoked manager and no active replacement.
  Removing admission from fresh funding fixes the funding-only case, but a second call can still make manager replacement wait indefinitely. A host can call `shieldedFundFromAssetLock` with spendable Core funds, then call `shieldedShield` using existing Platform credits on the same wallet while the asset lock is pending. Neither public wrapper refuses the overlap. Both native exports resolve the same wallet, and funding holds its `shield_guard` across the ChainLock fallback (`fund_from_asset_lock.rs:211–236, 417–420`). The new Swift admission counts the Platform-credit shield before its synchronous export blocks on that same mutex, before input selection (`shielded_send.rs:1221–1237`; `platform_wallet.rs:3094–3115`). An identity top-up from existing shielded notes can queue on the same guard (`platform_wallet.rs:2024–2035`). If the host stops SPV before the wallet applies a covering ChainLock, the funding fallback has neither a deadline nor a teardown signal (`shielded_send.rs:2325–2327`; `asset_lock/sync/proof.rs:751–775`). `shutdown()` has already revoked the public handle and waits for the counted caller before destroying the manager (`PlatformWalletManager.swift:1022–1026, 1059–1063`). The example app demonstrates this teardown order: rebuild stops SPV first, its funding check misses the direct Send funding path, and the replacement is not activated until the old manager shuts down. Neither call in the Platform-credit shield sequence entered the Swift drain on `v5.1-dev`; the new admission makes shutdown inherit the existing finality wait. Keep the handle fence, but make the Rust funding wait respond to teardown while preserving the pending outpoint, or return a retryable busy result before a queued shield builds or broadcasts. Add a regression test that exercises the shared native guard without delivering a covering ChainLock; releasing a mocked export only tests the Swift fence.
Out-of-scope follow-up suggestions (1)

These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.

  • Fresh asset-lock funding and pool seeding still lack teardown protection — The excluded wrappers retain their base behavior: wallet removal can overlap asset-lock funding, and Clear can finish before an in-flight funding call records its activity. That is separate from shutdown now waiting on an admitted caller queued behind funding.
    • Follow-up: Continue the cancellation work in #6003 and address the native removal and Clear gaps documented in #5516 and #6176.

@github-actions

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them.
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 24, 2026
Five admitted wrappers share a Rust lock with Core asset-lock funding,
so one started while a funding is pending on the same wallet queues
behind it, and shutdown() then waits as long. A funding can wait for a
ChainLock with no deadline. Say so on the five wrappers, on shutdown()
and on the two funding calls, whose notes read as if leaving them
unadmitted avoided the wait altogether (#6003).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@github-actions

github-actions Bot commented Nov 24, 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 24, 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

Changes requested: 1 blocker

  • Wallet shutdown can hang if SPV stops before shielded funding gets its ChainLock — packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedSync.swift:1241 (thread, carried)
    Impact: An iOS host that stops SPV to replace its wallet manager can be left with a revoked manager and no active replacement when a Platform-credit shield is queued behind Core funding on the same wallet.

New on this head: This revision updates the Swift SDK documentation for shielded-operation admission and shutdown; runtime and test code are unchanged from the previous review. The Swift SDK build and tests and the Kotlin SDK emulator job are pending, with no failed code checks reported.

🔴 1 blocking

Still open from earlier rounds (1)

  • 🔴 Blocking: Wallet shutdown can hang if SPV stops before shielded funding gets its ChainLock — packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedSync.swift:1241 (thread)
Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 4: gpt-6.2-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 5: gpt-6.2-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.2-sol (effort low) — The diff changes admission, cancellation, and shutdown behavior across ten Swift wrappers without changing how shielded payments are constructed, proved, or executed.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (lane failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — ffi-engineer (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — security-auditor (completed, effort high); 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/PlatformWallet/PlatformWalletManagerShieldedSync.swift`:
- [BLOCKING] packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedSync.swift:1241: Wallet shutdown can hang if SPV stops before shielded funding gets its ChainLock
  (carried; thread: https://github.com/dashpay/platform/pull/6179#discussion_r4673828940)

@github-actions

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix.
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 24, 2026
@QuantumExplorer
QuantumExplorer merged commit fe0da20 into v5.1-dev Nov 24, 2026
25 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-self-review Waiting for the author to post /self-reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

swift-sdk: shielded spend wrappers on v5.1-dev run without native-operation admission, so Clear, wallet deletion or shutdown can overlap a payment

2 participants