Skip to content

feat(restore): unify post-restore hydrate orchestrator (step 4) - #159

Merged
arkanoider merged 4 commits into
mainfrom
feat/restore-orchestrator-step4
Sep 2, 2026
Merged

feat(restore): unify post-restore hydrate orchestrator (step 4)#159
arkanoider merged 4 commits into
mainfrom
feat/restore-orchestrator-step4

Conversation

@arkanoider

@arkanoider arkanoider commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add RestoreHydrateReport, hydrate_after_session_restore, and spawn_post_restore_hydrate to run trade-DM replay and peer-chat rebuild in parallel behind one background task.
  • Replace PostRestoreTradeDmReplayCompleted / PostRestorePeerChatReplayCompleted with a single PostRestoreHydrateCompleted { report }.
  • Always emit completion after restore so track_startup_chats re-seeds live subscriptions even when there are no peer orders to rebuild (fixes the prior early-return on empty order_ids).

Test plan

  • cargo test --all-features restore_hydrate
  • cargo clippy --all-targets --all-features -- -D warnings
  • Manual: session restore with active peer chats — Messages + My Trades chat hydrate without restart
  • Manual: session restore with no peer-chat-eligible orders — live chat subscriptions still re-track

Made with Cursor

Summary by CodeRabbit

  • New Features

    • Restore Session now refreshes trade conversations and My Trades peer chats in the background without requiring an application restart.
    • Restored chats are rebuilt from available data, including the user’s own peer-chat messages where applicable.
    • Session restoration now provides a unified completion status after chat hydration finishes.
  • Documentation

    • Updated recovery, startup, messaging, DM listener, key management, and interface documentation to describe the revised restore-session behavior and verification steps.

Replace separate trade-DM and peer-chat background spawns with
hydrate_after_session_restore and RestoreHydrateReport. Always emit
PostRestoreHydrateCompleted so track_startup_chats runs even when there
are no peer orders to rebuild.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

Next included review available in 50 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 8a6c4ec6-ea20-47ef-ba86-f07ac7835720

📥 Commits

Reviewing files that changed from the base of the PR and between 2706b81 and e3ce6dc.

📒 Files selected for processing (5)
  • docs/DM_LISTENER_FLOW.md
  • docs/README.md
  • docs/RESTORE_SESSION_ACCEPTANCE.md
  • docs/STARTUP_AND_CONFIG.md
  • src/ui/helpers/startup.rs

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 9f35abfd-e29e-4653-815a-64594b727238

📥 Commits

Reviewing files that changed from the base of the PR and between fb95502 and 2706b81.

📒 Files selected for processing (12)
  • docs/DATABASE.md
  • docs/DM_LISTENER_FLOW.md
  • docs/KEY_MANAGEMENT.md
  • docs/MESSAGE_FLOW_AND_PROTOCOL.md
  • docs/README.md
  • docs/STARTUP_AND_CONFIG.md
  • docs/TUI_INTERFACE.md
  • src/main.rs
  • src/ui/helpers/mod.rs
  • src/ui/helpers/startup.rs
  • src/ui/operation_result.rs
  • src/ui/orders.rs

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


Walkthrough

The session restore flow now uses one background hydration task. The task replays trade DMs and rebuilds peer chats in parallel, then reports results through one OperationResult variant. Documentation describes the updated recovery and chat behavior.

Changes

Session Restore Hydration

Layer / File(s) Summary
Hydration orchestrator
src/ui/helpers/startup.rs
The helper runs trade-DM replay and peer-chat rebuilding in parallel. It returns RestoreHydrateReport and includes orchestration tests.
Operation result integration
src/main.rs, src/ui/helpers/mod.rs, src/ui/operation_result.rs, src/ui/orders.rs
The application starts and handles one PostRestoreHydrateCompleted result. The result carries the combined hydrate report.
Recovery flow documentation
docs/*.md
The documentation describes session restore hydration, relay replay, peer-channel handling, recovery behavior, attachments, and verification steps.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: 🔵 Low · up to 2706b

This PR unifies post-restore chat hydration and fixes the empty-order path so live subscriptions are re-seeded, but an overlapping restore or terminal order transition could briefly restore stale chat state in the client. The change is mergeable with explicit owner awareness or follow-up to add freshness or cancellation guards.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant SessionRestore
  participant spawn_post_restore_hydrate
  participant TradeDMReplay
  participant PeerChatRebuild
  participant MainLoop
  User->>SessionRestore: select Restore Session
  SessionRestore->>spawn_post_restore_hydrate: start background hydration
  spawn_post_restore_hydrate->>TradeDMReplay: replay active trade DMs
  spawn_post_restore_hydrate->>PeerChatRebuild: rebuild peer transcripts
  TradeDMReplay-->>spawn_post_restore_hydrate: return trade-DM summary
  PeerChatRebuild-->>spawn_post_restore_hydrate: return peer summary and order IDs
  spawn_post_restore_hydrate-->>MainLoop: send PostRestoreHydrateCompleted
  MainLoop->>MainLoop: apply transcripts and re-track startup chats
Loading

Poem

A rabbit packed the chats in rows
Then replayed trades where history flows
Peer notes bloomed beside the stream
One report gathered every gleam
Restore ran on without a restart

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: consolidating the post-restore hydration flow into one orchestrator. The step reference is additional context and does not make the title vag…
Docstring Coverage ✅ Passed Docstring coverage is 92.86% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 5 files. (7 skipped: 7 …
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 clearly and concisely describes the main change: consolidating the post-restore hydration flow into one orchestrator. The step reference is additional context and does not make the title vague or misleading.

Full details: Docstring Coverage

Explanation

Docstring coverage is 92.86% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 5 files. (7 skipped: 7 unsupported.)

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/restore-orchestrator-step4

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.

Cover session restore orchestrator, trade-DM replay filters, peer chat
rebuild, clear_session_chat_projection, and updated peer-channel echo rules.

Co-authored-by: Cursor <cursoragent@cursor.com>

@ermeme ermeme Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed current head 4bb78fdd99c65b413c8d4adbee76b0d072f4293e.

Blocking issue: the PR still does not pass the repository formatting gate. I reproduced it locally with rustup run 1.97.0 cargo fmt --all -- --check, and GitHub's current fmt check is failing too. The required changes are only rustfmt output in:

  • src/main.rs
  • src/ui/helpers/startup.rs

I also reviewed the new docs added on top of the orchestrator change. The focused restore-hydrate tests pass locally with rustup run 1.97.0 cargo test --all-features restore_hydrate, and I did not find another correctness blocker in the hydrate orchestration flow. Please run cargo fmt --all (or rustup run 1.97.0 cargo fmt --all) and push the formatted result so CI can go green.

arkanoider and others added 2 commits September 2, 2026 13:34
Formal RESTORE_SESSION_ACCEPTANCE.md with criteria matrix, manual smoke
scenarios, and sign-off table. Add spawn completion test for empty peer orders.

Co-authored-by: Cursor <cursoragent@cursor.com>
@arkanoider
arkanoider merged commit 2c3270e into main Sep 2, 2026
15 checks passed
@arkanoider
arkanoider deleted the feat/restore-orchestrator-step4 branch September 2, 2026 11:54
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