Repository navigation
test(platform-wallet): pin sync coordinator lifecycle behaviour - #6162
Conversation
Characterization tests for the five periodic sync coordinators (identity, DashPay, DPNS, platform-address, shielded), ahead of sharing their loop, admission and drain code. No production change. - All five coordinators get the same test hooks (`wedge_sync_slot_for_test`, `release_sync_slot_for_test`, `sync_admission_closed`); the existing tests go through them instead of the private `is_syncing` / `quiescing` fields, so they survive the fields moving. - DPNS had no tests; it now has the full lifecycle set. - Every coordinator now pins: interval clamp, quiesce waiting on the slot, the timeout latch, refusal behind a busy slot (which stays with its owner) and behind a shut gate, held / overlapping / sealed drains, start behind a latch, the drained latch reopening, stop then quick start, the first pass running at start, and a second start being a no-op. - Completion events: fired once per pass and before the slot is released (platform-address, DPNS, shielded). - `sync_wallet`: platform-address keeps two distinct refusal messages; shielded reports `None`, reads the coordinator before admission, and a pass cancelled before it produced anything is neither stamped nor reported. - The manager shutdown test also starts and joins DPNS and shielded. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
|
✅ Final review complete — no blockers (commit 1a6365b) · triage: normal |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
This test-only PR expands lifecycle coverage for all five wallet sync coordinators, adds DPNS’s first coordinator tests, and extends the manager shutdown test to join the DPNS and shielded workers. Linux Rust wallet tests passed; Kotlin SDK CI failed on an unchanged generated parity summary, Swift SDK CI failed on a SQLite write lock in an unchanged migration test, and PR Hygiene is pending.
🟡 7 suggestion(s) | 💬 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: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.2-sol (agent: phase2-reviewer, role: rust-quality); reviewer 6: gpt-6.2-sol (agent: phase2-reviewer, role: security-auditor); reviewer 7: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 8: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 9: gpt-6.2-sol (agent: phase2-reviewer, role: rust-quality); reviewer 10: gpt-6.2-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
normalbygpt-6.2-sol(effort low) — The diff adds substantial concurrency-sensitive lifecycle coverage across five coordinators, but changes only tests and test-only hooks, not production behavior. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity below 15% reserve: models 0% left),glm-5.3-flash(not used above high effort; tier asks max) - 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; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-sol— general (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— security-auditor (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— general (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— security-auditor (completed, effort high); agentphase2-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/rs-platform-wallet/src/manager/dpns_sync.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/manager/dpns_sync.rs:548-578: The DPNS drain test can hang if it misses the slot’s 200 ms hold
Impact: On a loaded runner, the wallet test job can stall or report a false failure even when `quiesce()` works correctly.
The test can hang before reaching its two-second timeout. The spawned task releases the slot after 200 ms whether or not the test has observed it, so the unbounded readiness loop can miss the entire hold. Observing only the tail end can also let a correct drain finish during the 50 ms check. Claim the slot in the test, poll `quiesce()` once to verify that it is pending with admission closed, then explicitly release the slot and await the same future under a timeout. The inherited identity, DashPay, and platform-address tests use the same timer pattern.
- [SUGGESTION] packages/rs-platform-wallet/src/manager/dpns_sync.rs:722-742: The latch-retry test can pass without retrying or fail on an unchanged loop
Impact: Depending on when the worker is scheduled, maintainers can miss a full-interval retry regression or see a false failure on the current code.
The fixed 100 ms wait does not establish that the worker attempted a pass or chose its next interval: `is_running()` only checks for a registered cancellation token. A worker first scheduled after release can succeed on its first pass even if short retries are removed. If it loses the slot CAS but is paused until after release, its post-pass `reopen_if_drained()` can clear the latch and select the normal 60-second interval, exceeding the test’s five-second deadline. Use a bounded handshake after a refused pass and after the worker has selected its delay, then release the wedge before letting it continue. The identity, DashPay, platform-address, and shielded retry tests make the same scheduling assumption.
In `packages/rs-platform-wallet/src/manager/shielded_sync.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/manager/shielded_sync.rs:1147-1159: The shielded cancellation test hangs if the coordinator read moves before slot acquisition
Impact: A maintainer who changes shielded admission order gets a stalled test instead of an assertion identifying the change.
The five-second timeout cannot catch this ordering regression. The test holds the coordinator write lock while waiting for `is_syncing()`, so a pass that reads the coordinator before claiming the slot would wait for the very lock that the test releases only after seeing the flag. Poll the pinned pass directly while holding the write lock and assert that it is pending and already owns the sync slot before calling `stop()`.
- [SUGGESTION] packages/rs-platform-wallet/src/manager/shielded_sync.rs:1201-1215: The shielded refusal tests can pass even when `sync_wallet` enters the coordinator
Impact: A refactor could admit a manual shielded sync during a drain or another pass without these tests detecting it.
The closed-gate test stays green if `sync_wallet` skips its gate check. With no bound accounts, `coordinator.sync()` yields no wallet outcome, normal slot cleanup leaves `is_syncing()` false, and the live drain guard keeps admission closed. Those are the same observations the test makes on refusal. The busy-slot sibling likewise cannot detect coordinator work that bypasses admission without touching the owner’s flag. Add an offline coordinator-entry probe and verify that an admitted control reaches it but neither refused call does.
- [SUGGESTION] packages/rs-platform-wallet/src/manager/shielded_sync.rs:957-970: The shielded timestamp test passes when the manager overwrites the coordinator’s stamp
Impact: A refactor can switch shielded completion timestamps to the manager’s clock without failing the test meant to preserve the coordinator’s timestamp.
An unconditional overwrite still satisfies the test: the returned summary and stored timestamp both come from the manager after it has processed the coordinator result, and the completion count does not depend on the timestamp source. Feed the completion path a known nonzero coordinator stamp distinct from the fallback clock and assert that exact value in both outputs. Using two real-clock readings would still let the stamps coincide at one-second resolution.
- [SUGGESTION] packages/rs-platform-wallet/src/manager/shielded_sync.rs:1107-1120: The shielded shutdown tests miss a seal that becomes temporary after a drain timeout
Impact: A refactor could let a fresh shielded pass start after a timed-out shutdown drain and still pass the lifecycle suite.
The sealed test drains an idle coordinator, and the wedged test uses a non-sealing drain. A change that calls `seal()` only after a successful drain would pass both, leaving only a temporary latch on the timeout path. Mirror the other four coordinators: hold the slot through a sealed-drain timeout, assert that it reports failure, then release the slot and verify that a direct pass cannot reopen admission, stamp, or dispatch a completion.
In `packages/rs-platform-wallet/src/manager/identity_sync.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/manager/identity_sync.rs:1428-1438: The duplicate-start tests can pass when the second call replaces the worker
Impact: A refactor can make redundant `start()` calls interrupt and restart a running sync loop without failing the tests meant to pin idempotence.
The identity and DashPay tests cannot distinguish preserving the worker from cancelling and replacing it. The new worker satisfies `is_running()`, one stop cancels it, and the registry can reap the old worker without leaving a detached thread. DPNS, platform-address, and shielded also check for an extra completion, but a replacement can miss the 150 ms observation window or lose admission while the prior pass still holds the slot. Compare the registered worker generation or identity across the two calls rather than inferring it from teardown or callback timing.
- [NITPICK] packages/rs-platform-wallet/src/manager/identity_sync.rs:1279-1280: The identity retry comment describes a 15-second default instead of 60 seconds
Impact: Readers comparing the identity test’s retry timing with the normal polling cadence are given the wrong default.
The comment understates the normal identity interval by 45 seconds. `IdentitySyncManager` initializes the interval from `DEFAULT_SYNC_INTERVAL_SECS`, which is 60; 15 seconds is the default in the DashPay and platform-address siblings. Update the comment to match the identity default.
|
Bots are done — your move: post |
|
/self-reviewed |
…let-sync-coordinator-lifecycle
…istic Review follow-up on the lifecycle characterization tests. - The four "quiesce blocks until the in-flight pass drains" tests held the slot from a background task for a fixed 200 ms and waited for it with an unbounded loop, so a loaded runner could miss the window and hang. The test now holds the slot itself, polls `quiesce()` once to see it pending with admission shut, releases the slot and awaits the drain under a timeout. - The shielded cancelled-pass test polls the pass by hand, so a pass that read the coordinator before claiming the slot fails an assertion instead of waiting on the lock the test holds. - Shielded gets the sealed-drain-that-times-out test its four siblings already had. - The shielded stamp test is renamed to what it can prove: both sides read the wall clock, so it cannot tell whose stamp was kept. - The identity retry comment named a 15 s default; it is 60 s. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
New on this head: The follow-up makes four wallet sync drain tests control slot release directly, makes shielded cancellation ordering observable, and adds a shielded test for sealing after a drain timeout. Production behavior is unchanged. The Linux Rust wallet tests and Swift and Kotlin SDK build/test checks passed on this head; PastaClaw review and PR Hygiene were pending.
🟡 5 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.
Still open from earlier rounds (3)
- 🟡 Suggestion: The latch-retry test can pass without retrying or fail on an unchanged loop —
packages/rs-platform-wallet/src/manager/dpns_sync.rs:718-738(thread) - 🟡 Suggestion: The shielded refusal tests can pass even when
sync_walletenters the coordinator —packages/rs-platform-wallet/src/manager/shielded_sync.rs:1230-1244(thread) - 🟡 Suggestion: The duplicate-start tests can pass when the second call replaces the worker —
packages/rs-platform-wallet/src/manager/identity_sync.rs:1673-1689(thread)
Review provenance
Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.2-sol (agent: phase2-reviewer, role: rust-quality); reviewer 6: gpt-6.2-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
normalbygpt-6.2-sol(effort low) — The diff adds a substantial set of concurrency tests and test-only hooks across five coordinators without changing production behavior or any critical surface. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-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; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-sol— general (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— security-auditor (completed, effort high); agentphase2-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/rs-platform-wallet/src/manager/dpns_sync.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/manager/dpns_sync.rs:558-569: The rewritten drain tests can pass when `quiesce()` waits only one poll interval
Impact: A maintainer can accidentally shorten the public drain budget to one poll interval without failing the test meant to verify that it waits for an in-flight pass.
The rewrite removes the observation period while the slot is still occupied. If the public `quiesce()` wrapper passed a 20 ms budget instead of 10 seconds, the first poll could still suspend and the next poll would see the released slot before checking the deadline, returning success. The explicit-budget tests call `quiesce_within()` directly and would not catch that wrapper regression. Keep the test-owned slot, but use a paused Tokio clock and a short timeout on the pinned drain to verify it stays pending past the first 20 ms sleep before releasing the slot. The identity, DashPay, and platform-address rewrites use the same single-poll pattern.
- [SUGGESTION] packages/rs-platform-wallet/src/manager/dpns_sync.rs:718-738: The latch-retry test can pass without retrying or fail on an unchanged loop
(carried; thread: https://github.com/dashpay/platform/pull/6162#discussion_r4671246457)
In `packages/rs-platform-wallet/src/manager/shielded_sync.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/manager/shielded_sync.rs:1132: The new shielded seal test hangs if the drain ignores its deadline
Impact: If a refactor drops the sealed drain's deadline, the wallet test job can stall instead of reporting a failed assertion.
The test owns the wedged slot and releases it only after `quiesce_sealed_within()` returns. The 50 ms argument is enforced by the code under test, so if that deadline is ignored, nothing in the test ends the wait. Add an independent outer timeout, as the neighboring non-sealed drain test does.
- [SUGGESTION] packages/rs-platform-wallet/src/manager/shielded_sync.rs:1230-1244: The shielded refusal tests can pass even when `sync_wallet` enters the coordinator
(carried; thread: https://github.com/dashpay/platform/pull/6162#discussion_r4671246463)
In `packages/rs-platform-wallet/src/manager/identity_sync.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/manager/identity_sync.rs:1673-1689: The duplicate-start tests can pass when the second call replaces the worker
(carried; thread: https://github.com/dashpay/platform/pull/6162#discussion_r4671246469)
|
Bots are done — your move: post |
|
/self-reviewed |
|
Policy satisfied — this can merge. |
romchornyi
left a comment
There was a problem hiding this comment.
✅ no blockers · no majors · 2 weak pins (agreeing with open bot threads) · 3 non-blocking recommendations — reviewed at 1a6365b779
| Level | Verdict | |
|---|---|---|
| 1 · Idea | ✅ valid | pinning the five coordinators' lifecycle before the SyncLoop refactor is the right order |
| 2 · Architecture | ✅ n/a | production code is unchanged; the only non-test lines are three #[cfg(test)] hooks per coordinator |
| 3 · Completeness | ✅ complete | all five coordinators now carry the lifecycle set, including DPNS, which had no tests |
| 4 · Code | ✅ clean | no defects; two pins are weaker than they claim, and a few test-hygiene points |
Two pins that would not catch the regression they name (both checked against the code; +1 to the open thepastaclaw threads, non-blocking)
- Duplicate
start()in DashPay and identity — and — The tests would pass if the secondstart()cancelled and replaced the worker: the new one is running, onestop()cancels it, and the old one is reaped cleanly. DPNS, platform-address and shielded do tell the cases apart by checking that no second first pass ran. Since the point of this PR is to prove the refactor changes nothing, thehold_clearingapproach the bot proposed looks worth taking here rather than relying onThreadRegistryalone. - Shielded refusal behind a shut gate —
— With no bound wallet, an admitted pass also returns
Ok(None), releases its slot and leaves the held guard's gate closed (exactly what asserts for the admitted case). Removing thequiescing.is_closed()bail fromsync_walletwould leave this test green.
3 non-blocking recommendations
- Identity refusals do not check the returned summary —
— The identity refusal tests assert only
last_sync_unix_seconds(); the other four coordinators also assert the returned summary'ssync_unix_seconds == 0. A shared bail path that stamps the summary without storing it would pass here. - Stale comment on the gate tests —
(same at
and
) — It says the gate is raised "as an in-flight
quiesce()would", butquiesce_held_withinhas already finished the drain when it returns. Either reword it or keep one test that closes the gate while the drain is still polling. - Test hygiene (not verified):
- Several loop tests (
should_run_first_pass_immediately_after_startand the resume/reopen tests) end withstop()/quiesce()but never join the registry thread, so it can outlive the test's runtime. Ending withregistry.shutdown().await+all_clean()would close that. - The stop-then-quick-start tests call
start()from inside an async test, which can spin a runtime worker for up to 1 s while the old thread is reaped. - In the shielded tests built on
empty_coordinator, theTempDiris dropped before the coordinator that holdstree.sqliteopen. - In the shielded cancellation test, the stand-in pass releases its slot manually after
cancelled().awaitinstead of through a drop guard, so a panic leaves the slot held.
- Several loop tests (
Review details
Triaged as test-only. I checked that every non-test hunk is a #[cfg(test)] hook. Levels 1–3 were done inline, and level 4 ran the general lane (/code-review high); no specialist lanes were needed. The weak-pin findings and recommendations 1–2 were checked against the code at the reviewed head.
🤖 Reviewed with Claude Code
v5.2-dev gained dashpay#6162 (sync coordinator lifecycle tests) while v5.1-dev was being merged. Two test modules conflicted with tests v5.1-dev added beside them: both sets are kept, and the shielded sync test fixture v5.1-dev built gets the two fields dashpay#6162 added to it. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Issue being fixed or feature implemented
The five periodic sync coordinators in
packages/rs-platform-wallet/src/manager/(identity, DashPay, DPNS, platform-address, shielded) each carry their own copy of the loop thread, theis_syncingslot, the admission preamble and thequiesce*family. A follow-up PR moves that shared lifecycle into oneSyncLoop. This PR goes first and pins the current behaviour with tests, so the refactor can be shown to change nothing.Coverage was uneven:
dpns_sync.rshad no tests at all, and most lifecycle cases were tested on only one or two of the five copies.What was done?
Tests only. The one change outside test modules is three
#[cfg(test)]hooks per coordinator.wedge_sync_slot_for_test,release_sync_slot_for_test,sync_admission_closed. Existing tests now go through them instead of the privateis_syncing/quiescingfields, so they keep working when those fields move.quiescewaiting for the slot; the timeout latch; refusal behind a busy slot (which stays with its owner) and behind a shut gate, with no timestamp and no event; held, overlapping and sealed drains; a start behind a latched gate resuming once the wedged pass drains;sync_nowreopening a drained latch; stop then quick start; the first pass running at start; a secondstartbeing a no-op.sync_wallet: platform-address keeps two distinct refusal messages (slot busy, gate shut); shielded reportsNonefor both, reads the coordinator before admission, and a pass cancelled before it produced anything is neither stamped nor reported.How Has This Been Tested?
On unchanged production code:
RUST_MIN_STACK=4194304 cargo test -p platform-wallet --features shielded manager::— 255 passed, 0 failed (195 before this PR), repeated four times to check the time-based tests are stable.cargo check -p platform-wallet --all-targets(withoutshielded)cargo clippy -p platform-wallet --features shielded --tests -- -D warningscargo check -p platform-wallet-ffi --features shieldedBreaking Changes
None.
Checklist:
structure.rs, regeneratedgrovedb-structure.json, and checked the structure viewer link posted on this pull requestFor repository code-owners and collaborators only
🤖 Generated with Claude Code
PR Hygiene ·
1a6365bWhen every merge requirement is met, the
PR Hygienecheck passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.