fix: exclude hyphenated terminal order statuses - #882
Conversation
EXCLUDED_ORDER_STATUSES and TERMINAL_ORDER_STATUSES spelled the four multi-word statuses without hyphens (canceledbyadmin, completedbyadmin, settledbyadmin, cooperativelycanceled). Status' Display impl serializes them as kebab-case, and that is the form stored in the orders table: canceled-by-admin, completed-by-admin, settled-by-admin and cooperatively-canceled. The four single-word entries did match, so both NOT IN filters kept working for expired, success, canceled and dispute while silently letting every hyphenated status through. Two effects: - find_user_orders_by_master_key restored orders that were already over. On a live node 30 rows qualified, all of them months-old cooperatively-canceled or canceled-by-admin. Clients received them as restorable session state for trades they no longer track. - find_active_trade_pubkeys never dropped the trade keys of admin-closed or cooperatively-canceled orders, so the Phase 2 anti-spam gate kept fast-pathing them indefinitely. The existing terminal-exclusion test only inserted 'success' and 'canceled', the two spellings that happened to be correct, which is why the gap survived. Both affected tests now assert every hyphenated status individually and fail without this change.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan includes up to 2 reviews per rolling hour; 1 remains after this review. WalkthroughThe change updates terminal order status constants to use hyphenated serialized values. Database tests verify active trade-key and restore-session queries exclude orders with these statuses. ChangesTerminal status filtering
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This change corrects terminal-status filtering so resolved orders are excluded from restoration and active-key lookups; the reported tests and checks pass, and no actionable merge-blocking risk remains. Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
ToRyVand
left a comment
There was a problem hiding this comment.
Reviewed and verified independently against main — everything in the description holds up. Details of what I checked rather than took on faith:
The premise. Confirmed Status' Display impl in mostro-core 0.14.5 (the version this repo pins in Cargo.toml) does emit the hyphenated forms — canceled-by-admin, settled-by-admin, completed-by-admin, cooperatively-canceled — while both constants on main carry the unhyphenated spellings. Real mismatch.
That it's a typo, not an alternative encoding. ACTIVE_DISPUTE_STATUSES ('in-progress') and PRETRADE_STATUSES ('waiting-taker-bond') in the same file are hyphenated correctly, which is the detail that settles it.
Reproduced the failure. Reverted TERMINAL_ORDER_STATUSES to the pre-fix spelling on your branch and ran find_active_trade_pubkeys_covers_active_and_disputed_excludes_terminal — fails, exactly as you documented. Restored the fix — passes. Same for the new restore-session test.
Completeness. Grepped all of src/ for any remaining unhyphenated occurrences of the four statuses: none. No other call site reintroduces the bug, and both constants feed the two functions you name (find_user_orders_by_master_key at the format! in db.rs, and find_active_trade_pubkeys).
Checks. Full suite 1187 passed / 0 failed, cargo clippy --all-targets -- -D warnings clean, cargo fmt --check clean.
One thing worth calling out as reviewer rather than as a request: flagging the #784 interaction up front — that this removes an accidental mask over half of it rather than creating anything — is the right call and saved me from having to work that out. Scoping the bonds state machine fix out of here is correct.
Note I'm a contributor, not a maintainer, so treat this as a technical second opinion for @grunch rather than a merge signal.
|
Reviewed and verified locally. The fix is correct and the tests are genuine regression tests — I reverted only the two constants while keeping the new tests, and both fail with exactly the output described; restoring the constants makes them pass. Since the branch is based a few commits before 0.18.5, I re-ran everything against current The patch applies to current I also grepped One nice side effect: Follow-upsOpened separately so they do not expand this PR's scope:
Before mergingWorth linking #784 from here. As the description says, this removes an accidental mask rather than creating a problem — but the practical effect is that the admin-cancel branch of #784 starts reproducing once this lands. Without the link that will read as a fresh regression to whoever hits it. |
EXCLUDED_ORDER_STATUSESandTERMINAL_ORDER_STATUSESinsrc/db.rslist the four multi-word order statuses without hyphens, butStatus'Displayimpl serializes them as kebab-case, and that is the form actually stored in theorderstable.RestoredOrdersInfo::statuseven documents the contract the constants break — "Current status of the order, serialized as kebab-case" (message.rs:490).The four single-word entries (
expired,success,canceled,dispute) do match, so bothNOT INfilters keep working for those and fail silently for the rest. Two other constants in the same file —ACTIVE_DISPUTE_STATUSES('in-progress') andPRETRADE_STATUSES('waiting-taker-bond') — are hyphenated correctly, which is what makes this look like a typo rather than an alternative encoding.Impact
find_user_orders_by_master_key(restore session) returns orders that are already over. On a live node, 30 rows qualified — months-oldcooperatively-canceledandcanceled-by-adminorders — and they were handed back to their owners as restorable session state for trades their clients no longer track.This also has a knock-on effect:
find_user_orders_by_master_keyhas noLIMIT, while the follow-upordersaction rejects the whole request whenids.len() > max_orders_per_response(src/app/orders.rs). Users whose accumulated dead orders push the restore list past the cap get a blankettoo_many_requestsand cannot refresh at all — the server offers a list its own limit will not accept back. That is how this bug was found.find_active_trade_pubkeys(Phase 2 anti-spam gate) never drops the trade pubkeys of admin-closed or cooperatively-canceled orders, because those orders never count as terminal. Their keys stay in the fast-pathed "known keys" set indefinitely, which is precisely whatTERMINAL_ORDER_STATUSESexists to prevent.Verification against real data
Same query, same database, only the status list differs:
cooperatively-canceledcanceled-by-adminpendingwaiting-maker-bondsettled-hold-invoicewaiting-taker-bond30 terminal orders stop being restored; every genuinely active order is untouched.
Why the existing tests missed it
find_active_trade_pubkeys_covers_active_and_disputed_excludes_terminaldoes test terminal exclusion, but only inserts'success'and'canceled'— the two spellings that happen to be correct. No test used a hyphenated status on the terminal side.Both tests now cover every hyphenated status individually. Confirmed failing before the constant change and passing after:
Full suite: 1187 passed, 0 failed.
cargo fmt --checkandcargo clippy --all-targets -- -D warningsare clean.Interaction with #784
Worth flagging explicitly for reviewers. #784 ("Restore session loses pending bond payouts on terminal-status orders") describes the admin-cancel route on the assumption that
'canceledbyadmin'is already excluded. It is not — because of this bug — so that branch of #784 does not currently reproduce, while the admin-settle branch ('success', correctly spelled) does.This change makes the two routes behave the same, which means the admin-cancel branch of #784 will start reproducing once this lands. It does not create that problem and does not make it worse in substance; it removes an accidental mask over half of it. Fixing #784 needs its own change to restore the
bondsstate machine, so it is deliberately out of scope here.Summary by CodeRabbit
Bug Fixes
Tests