Skip to content

docs: fix order state transitions and improve documentation accuracy - #18

Merged
grunch merged 11 commits into
mainfrom
improve-logic
Mar 24, 2026
Merged

docs: fix order state transitions and improve documentation accuracy#18
grunch merged 11 commits into
mainfrom
improve-logic

Conversation

@Catrya

@Catrya Catrya commented Mar 23, 2026

Copy link
Copy Markdown
Member
  • Fix cancel transitions: taker cancel returns order to pending, creator cancel is permanent
  • Add timeout behavior referencing expiration_seconds from instance event 38385
  • Replace incorrect unilateral cancel with cooperative cancel flow in ACTIVE and FIAT_SENT
  • Add missing cancel transitions to FIAT_SENT table
  • Add payment failure flow to SETTLED_HOLD_INVOICE (buyer may need to provide new invoice)
  • Seller can rate buyer in SETTLED_HOLD_INVOICE without waiting for payment to complete
  • Remove non-existent admin-complete action from DISPUTE and IN_PROGRESS tables
  • Mark COMPLETED_BY_ADMIN as reserved/unused status in mostro-core
  • Clarify EXPIRED only applies to pending orders with no direct notification to creator
  • Clarify IN_PROGRESS is a dispute status (kind 38386), not an order status
  • Add release and cooperative cancel as available actions during dispute
  • Add Contact button for P2P chat in ACTIVE, FIAT_SENT and DISPUTE states
  • Update State Transitions summary table to reflect all changes
  • Replace vague "Re-sync user data" with specific restore-session protocol action in ACCOUNT_SCREEN.md

Summary by CodeRabbit

  • Documentation
    • Updated refresh flow: clarified confirmation text, added an explicit three-step refresh procedure, and show a success snackbar when data is restored; refresh now retrieves non-finalized orders and active disputes.
    • Clarified order-state behavior: role-dependent cancel outcomes, cooperative-cancel semantics, dispute release/auto-close rules, timeout/expiration handling, persistence of certain hold states after payment failures, and added a universal Contact action.

Catrya added 9 commits March 23, 2026 14:34
- Replace vague Re-sync user data from relays, with specific protocol action details and add confirmation dialog text explaining when to use it
  - Taker cancel returns order to pending (republished), not canceled.
  -Add timeout behavior note referencing expiration_seconds from event 38385.
  - Replace incorrect unilateral cancel with cooperative cancel flow
  - Add cancel transitions to FIAT_SENT table (were missing entirely)
  - Clarify that order status does not change until both parties cancel
  - Buyer may need to provide new invoice if payment fails after retries
  - Separate available actions by role (seller: none, buyer: add-invoice)
  - Reference PAYMENT_FAILED section for full details
  - No handler in mostrod, no spec in protocol docs
  - Mark COMPLETED_BY_ADMIN as reserved/unused status in mostro-core
  - Clean up DISPUTE and IN_PROGRESS transition tables
  - Only applies to pending orders not taken before expires_at
  - No direct notification; client detects via updated replaceable event
  - Add release and cooperative cancel as available actions during dispute
  - Clarify IN_PROGRESS is a dispute status (kind 38386), not an order status
  - Users can resolve disputes themselves while admin review is pending
@coderabbitai

coderabbitai Bot commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a7bbbf7b-fa6f-419c-af36-4a01982e4212

📥 Commits

Reviewing files that changed from the base of the PR and between e541a7b and 93db4c0.

📒 Files selected for processing (1)
  • .specify/v1-reference/ORDER_STATES.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • .specify/v1-reference/ORDER_STATES.md

Walkthrough

Updated ACCOUNT_SCREEN.md to replace a generic re-sync with a restore-session command that retrieves non-finalized orders and active disputes (with trade_index) and added an explicit three-step refresh procedure and confirmation copy. ORDER_STATES.md was revised to make cancel behavior role-dependent, introduce cooperative-cancel semantics, add timeout event handling (Mostro kind 38385), refine settled-hold-invoice flows, adjust dispute/release transitions, and clarify admin/in-progress usage and UI actions.

Changes

Cohort / File(s) Summary
Account Refresh Flow
.specify/v1-reference/ACCOUNT_SCREEN.md
Replaced generic "Re-sync user data" with a restore-session command to Mostro; updated confirmation dialog language; added explicit "On Refresh" steps: send restore-session, merge returned non-finalized orders & disputes (annotated with trade_index), and show success snackbar.
Order State Machine
.specify/v1-reference/ORDER_STATES.md
Made cancel role-dependent in pre-escrow states and cooperative-cancel aware in escrow/dispute; added Mostro event kind 38385 for timeout/expiration semantics; extended settled-hold-invoice and dispute transitions (release, cooperative cancel, auto-close) and updated action/button mappings and state transition table.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant Mostro as Mostro Server
    participant LocalState as Local State Manager
    participant UI as UI

    Client->>Mostro: send `restore-session` command
    activate Mostro
    Mostro->>Mostro: fetch non-finalized orders & disputes (annotate `trade_index`)
    Mostro-->>Client: return orders & disputes
    deactivate Mostro

    Client->>LocalState: update/merge returned orders & disputes
    activate LocalState
    LocalState-->>Client: merged state confirmed
    deactivate LocalState

    Client->>UI: show success snackbar
    activate UI
    UI-->>Client: snackbar displayed
    deactivate UI
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • grunch

Poem

🐰 I hopped to Mostro, nose aglow,
Pulled lost trades where they used to go,
I stitched the states with patient care,
Sent a restore, then showed a flare —
Snackbar cheered: the books now flow! 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'docs: fix order state transitions and improve documentation accuracy' directly and comprehensively addresses the main changes in the PR, which focus on correcting order-state transition behavior and clarifying documentation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch improve-logic

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

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

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.specify/v1-reference/ACCOUNT_SCREEN.md:
- Around line 152-153: Update ACCOUNT_SCREEN.md to match the protocol: replace
the incorrect action name "restore-session" with "restore" wherever referenced
and rename the payload field "trade_index" to "last-trade-index" so the action
and payload names match the documented protocol ("restore" /
"last-trade-index"); ensure both occurrences in ACCOUNT_SCREEN.md that mention
the action and payload are updated and any example payloads or descriptive text
reflect the corrected names.

In @.specify/v1-reference/ORDER_STATES.md:
- Around line 64-67: The MD028 failures are caused by blank lines inside
consecutive blockquote sections around the "Cancel behavior depends on role in
the order" and "Timeout behavior" blocks; remove the empty lines so each
blockquote paragraph is a continuous series of lines that each start with ">"
(no blank line between them) and apply the same change to the similar blockquote
at the later occurrence (the block containing the timeout/cancel explanation
referenced in the comment).
- Around line 318-322: The spec marks the ORDER_STATE `completed-by-admin` as
reserved/unused but later appendices still document
`admin-completed`/`admin-complete` restore/action/display entries, causing a
contradiction; update the appendices to match the reserved status by removing or
marking as unavailable any restore/action/display references to
`admin-completed`/`admin-complete` and replace them with a note that
`completed-by-admin` is a terminal/reserved state with no actions, or conversely
re-enable the state consistently if intended—search for the tokens
`completed-by-admin`, `admin-completed`, and `admin-complete` and edit the
restore/display sections so the protocol documentation and enum comment are
consistent.
- Around line 122-127: The Appendix A terminal-action mapping still lists a
generic "cancel → canceled" which contradicts the cooperative-cancel semantics
introduced (where a single-party "cancel" leaves the order in `active` until the
counterparty also sends `cancel`); update the Appendix A mapping and any other
terminal-action tables that show "cancel → canceled" (including the other
occurrences noted) to reflect that a single-party `cancel` is non-terminal (maps
to `active`/no terminal transition) and only a mutual/both-party `cancel` should
map to `canceled`, and adjust any explanatory note/footnote to reference the
cooperative-cancel behavior for `cancel`, `active`, and `canceled`.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ba7cc379-1f12-4c10-8b72-c280a932a8b7

📥 Commits

Reviewing files that changed from the base of the PR and between 9b57316 and cd12b78.

📒 Files selected for processing (2)
  • .specify/v1-reference/ACCOUNT_SCREEN.md
  • .specify/v1-reference/ORDER_STATES.md

Comment thread .specify/v1-reference/ACCOUNT_SCREEN.md
Comment thread .specify/v1-reference/ORDER_STATES.md
Comment thread .specify/v1-reference/ORDER_STATES.md
Comment thread .specify/v1-reference/ORDER_STATES.md

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.specify/v1-reference/ORDER_STATES.md:
- Around line 572-573: The table rows for the `fiat-sent` -> `release`
transition leave the buyer outcome as `-`, causing ambiguity; update the
`fiat-sent | release` entries (and the similar rows around the `581-582` area)
to explicitly state both buyer and seller next-states (e.g., buyer -> `settled`
or `settled-hold-invoice` and seller -> `settled` as appropriate to the release
flow) so the role-specific FSM mappings match the release flow description;
locate the entries referencing `fiat-sent`, `release`, and
`settled-hold-invoice` and replace the `-` with the correct buyer/seller
outcomes consistent with the documented release behavior.
- Line 794: Table rows containing the extra cell with the note "(reserved — not
generated by current protocol)" (e.g., the row with `completed-by-admin` /
`admin-completed`) are malformed and break the Markdown table; remove the extra
pipe-delimited cell and move the reserved note into an existing cell (for
example append it to the same cell as `admin-completed` using a <br> or
parentheses), and apply the same fix to the other rows that add that extra cell
with the reserved note so each row has the correct number of columns.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f7a343e4-8197-49d4-b274-b11264db1bad

📥 Commits

Reviewing files that changed from the base of the PR and between cd12b78 and e541a7b.

📒 Files selected for processing (1)
  • .specify/v1-reference/ORDER_STATES.md

Comment thread .specify/v1-reference/ORDER_STATES.md Outdated
Comment thread .specify/v1-reference/ORDER_STATES.md Outdated
@Catrya
Catrya requested a review from grunch March 24, 2026 02:58

@grunch grunch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@grunch
grunch merged commit 1e9d1e5 into main Mar 24, 2026
1 check passed
@grunch
grunch deleted the improve-logic branch March 24, 2026 12:20
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.

2 participants