Skip to content

fix(disputes): sweep every dispute key of a finished order - #900

Merged
grunch merged 2 commits into
mainfrom
fix/dispute-key-sweep
Oct 29, 2026
Merged

grunch merged 2 commits into
mainfrom
fix/dispute-key-sweep

Conversation

@grunch

@grunch grunch commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Linked issue

Refs #439. This fixes one of the flaky tests it covers: api::disputes::tests::the_chat_key_share_survives_a_restart_for_its_solver, which failed the Rust job of #899 (run 40377813795). The other tests #439 lists are untouched, so it stays open. This is a fix by a maintainer and is exempt from the accepted-issue rule (CONTRIBUTING.md § Contribution quality bar).

Type

fix

What changes and why

clear_dispute_keys deletes five settings keys for an order: solver, assignment time, node, origin marker and chat key share, in that order. Rehydration decides whether a finished order still has any of them, and it read only two, the solver and the origin marker. A clear that stopped after the solver key left the other three behind for good. The clear can stop there because of a failed delete, which is only logged, or because the process was killed between two deletes. Yet clear_dispute_keys promised that "the stale key is seen again — and cleared again — on the next pass". Rehydration now reads the same five keys. Both functions build them from one list, settings_keys::dispute_keys, so a key added there is both cleared and swept.

This is the likeliest cause of the CI failure. Six tests run rehydrate_disputes_from_storage over the same global store, and each pass walks every test's rows. Another test's pass deleted the finished order's solver key but had not yet deleted its share. At that moment the failing test's own pass read the solver key, found nothing and skipped the order. The test then found the share still there. With this change the test's own pass still sees the share and deletes it, whatever the other pass is doing.

Affected flow

No screen or user action. The change runs during dispute rehydration from storage: when the relay pool comes online (resubscribe_active_dispute_chats) and when an identity session is restored. It touches finished orders only: SettledByAdmin, CanceledByAdmin, CompletedByAdmin, Success, Canceled and the others in is_order_finished.

  • Rust core: rust/src/api/disputes.rs (has_dispute_keys, clear_dispute_keys) and rust/src/db/mod.rs (settings_keys::dispute_keys).

Blast radius

  • Persisted data: the only rows that can now be deleted are the dispute_admin_at:, dispute_node: and dispute_key_shared: keys of an order whose trade is already finished. These are the rows clear_dispute_keys deletes on every resolution anyway. On an existing install, keys left by an earlier partial clear are swept once, at the next rehydration.
  • Cost: a finished trade's check reads up to five keys instead of two, and still writes nothing unless one is found.
  • Generated bindings: unchanged. No item was added to or removed from crate::api; the new helper lives in crate::db. scripts/check-generated.sh passes (Flutter 3.41.9).
  • Web: this is the same code over the Storage trait, so IndexedDB behaves like SQLite.
  • Wire, daemon, v1: nothing is sent or read differently.
  • Identity wipe: unaffected. All five prefixes were already in IDENTITY_SCOPED_PREFIXES.

Platforms tested

Linux (Rust tests only; no app flow).

Manual testing

Setup

This branch, and main with only its test: commit (89f4cc5) applied. Run from rust/.

Steps

  1. (fails on main) At 89f4cc5: cargo test --lib api::disputes::tests::a_finished_order_s_keys_left_by_a_partial_clear_are_swept
    Expected: FAILED, with dispute_admin_at:partial-… stayed.
  2. On this branch, run the same command.
    Expected: ok.
  3. On this branch: cargo test --lib
    Expected: test result: ok. 1478 passed; 0 failed; 30 ignored.
  4. On this branch: cargo clippy --locked -- -D warnings
    Expected: no warnings.

Not covered

The race itself was not reproduced locally: 40 runs of cargo test --lib api::disputes::tests -- --test-threads=16 on main all passed. The red test reproduces the state that race leaves behind deterministically, instead of the interleaving that produces it. A second path to the same CI failure stays open: the test's own list_trades failing while another test's pass skips the order. There is no evidence that it happened. Serialising the tests that rehydrate over the global store, which is what #439 suggests, would close it.

Screenshots

No visible change.

Automated tests

  • a_finished_order_s_keys_left_by_a_partial_clear_are_swept (rust/src/api/disputes.rs). It leaves on a finished order the three keys a clear that stopped after the solver key leaves, runs rehydration and asserts all three are gone. It fails on main and passes here.
  • the_chat_key_share_survives_a_restart_for_its_solver, the test that flaked, is unchanged. It now gets a pass of its own that deletes the share, even when another test's pass has already deleted the solver key.

cargo test --lib: test result: ok. 1478 passed; 0 failed; 30 ignored; 0 measured; 0 filtered out

Checklist

  • cd rust && cargo fmt --check && cargo clippy -- -D warnings && cargo test pass locally. cargo clippy --locked -- -D warnings and cargo test pass. cargo fmt --check already fails on main with the local rustfmt 1.10.0, on lines this PR does not touch; none of its complaints are on a changed line.
  • dart format --set-exit-if-changed ., flutter analyze and flutter test pass locally (n/a: no Dart change)
  • Changed rust/src/api/: regeneration produces no diff (scripts/check-generated.sh)
  • New or changed user-facing text (n/a)
  • Changed an automation identifier (n/a)
  • Protocol or transport change (n/a)
  • Behaviour or contract change (n/a: no spec describes which keys rehydration reads)
  • Commits are signed
  • I ran the Manual testing steps myself and can explain every line of this diff. Claude Code ran steps 1–4; they are pending a maintainer.

AI assistance

Claude Code diagnosed the CI failure from the job log and the code, then wrote the test, the fix and this description.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Myq8f28gDqfJ4rUxarqYqn

Summary by CodeRabbit

  • Bug Fixes
    • Finished trades now clear all associated dispute settings when rehydrated, preventing stale dispute information from persisting.

grunch and others added 2 commits October 26, 2026 15:54
…wept

clear_dispute_keys deletes five keys, solver first, chat key share last.
Rehydration decides whether a finished order still has any by reading
two of them (solver, origin marker), so a clear that stopped after the
solver leaves the solver's assignment time, the dispute's node and the
chat key share where no later pass looks again.

It is the likeliest cause of the CI failure of
the_chat_key_share_survives_a_restart_for_its_solver on PR #899 (not
reproduced locally: 40 runs of the dispute tests passed): another test's
rehydration, walking the same global store, deleted the finished order's
solver key but not yet its share when this test's own pass read the
solver key and skipped the order.

Refs #439

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Myq8f28gDqfJ4rUxarqYqn
Rehydration now looks for the same five keys clear_dispute_keys
deletes, built from one list in settings_keys::dispute_keys, so a key
added there is both cleared and swept. Until now it read only the
solver and the origin marker: a clear that stopped after the solver (a
failed delete, which is only logged, or a process killed between two)
left the assignment time, the node and the chat key share for good,
although clear_dispute_keys promised the next pass would clear them.

Refs #439

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Myq8f28gDqfJ4rUxarqYqn
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 44eec08 and 884c4b2.

Files selected for processing: 2
  • rust/src/api/disputes.rs
  • rust/src/db/mod.rs

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

Walkthrough

The change adds a shared list of persisted dispute-setting keys. Dispute cleanup and presence checks now use that list. A rehydration test checks that selected settings are absent after a finished trade is rehydrated.

Changes

Dispute key cleanup

Layer / File(s) Summary
Shared dispute keys and cleanup validation
rust/src/db/mod.rs, rust/src/api/disputes.rs
settings_keys::dispute_keys returns five persisted keys for each order. clear_dispute_keys deletes keys from this collection, and has_dispute_keys checks the same collection. A rehydration test checks that assignment-time, node, and chat-key-share settings are removed from a finished trade.

Priority: Normal

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

Change: Bug fix

Possibly related issues

  • MostroP2P/mostro#1086 — The change clears persisted dispute settings during finished-trade rehydration, but does not repair the dispute row or skipped resolution messages described by the issue.

Suggested reviewers: catrya, forte11cuba

Merge Risk: Minimal · up to 884c4

No actionable merge-blocking issue is identified; the change is mergeable after normal checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title "fix(disputes): sweep every dispute key of a finished order" matches the main change. Rehydration now checks and clears the same five dispute settings keys that clear_dispute_keys deletes, t…
Description check Passed The description follows the repository template and fills in every required section. It names the linked issue (Refs #439, with an explanation of why it is a partial reference), sets the type to fix, …
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. Analyzed 8 functions across 2 files.
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: Title check

Explanation

The title "fix(disputes): sweep every dispute key of a finished order" matches the main change. Rehydration now checks and clears the same five dispute settings keys that clear_dispute_keys deletes, through the shared settings_keys::dispute_keys helper. The title is specific, uses the conventional fix(scope) form, and states the behaviour change without file lists or vague terms.

Full details: Description check

Explanation

The description follows the repository template and fills in every required section. It names the linked issue (Refs #439, with an explanation of why it is a partial reference), sets the type to fix, and explains what changes and why in detail. It describes the affected flow, lists the blast radius (persisted data, cost, generated bindings, web, wire, identity wipe), and gives platforms tested. It also provides numbered manual testing steps with expected results, including a step that fails on main, and it lists the automated tests and a checklist. The Screenshots section states 'No visible change'. Some checklist items remain unchecked with explanations, and the manual testing steps are pending maintainer confirmation, which the author discloses. These gaps are non-critical, so the description is mostly complete.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 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

A rabbit checks each key in sight
Five settings vanish from the slate
Rehydration clears the finished trade
The shared key list keeps its place
Then hops away beneath the moon

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T20:45:55.647211Z 884c4b2 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@MostroP2P MostroP2P deleted a comment from coderabbitai Bot Oct 26, 2026
@MostroP2P MostroP2P deleted a comment from coderabbitai Bot Oct 26, 2026
@grunch

grunch commented Oct 26, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@grunch

grunch commented Oct 26, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 884c4b2bbf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@grunch
grunch merged commit a633267 into main Oct 29, 2026
6 checks passed
@grunch
grunch deleted the fix/dispute-key-sweep branch October 29, 2026 12:40
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.

1 participant