Skip to content

Feat/commit loss epoch gap backfill#892

Merged
jgmontoya merged 3 commits into
masterfrom
feat/commit-loss-epoch-gap-backfill
Jul 17, 2026
Merged

Feat/commit loss epoch gap backfill#892
jgmontoya merged 3 commits into
masterfrom
feat/commit-loss-epoch-gap-backfill

Conversation

@jgmontoya

@jgmontoya jgmontoya commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Open in Stage

Summary by CodeRabbit

  • New Features

    • Added automatic epoch-gap detection and backfill recovery when undecryptable messages indicate stalled progress.
    • Backfill now runs during initial and ongoing synchronization, including when a pending epoch-stall is detected.
    • Recovery supports previously skipped messages below the synchronization floor once armed, with built-in safeguards to avoid repeated replays.
  • Bug Fixes

    • Fixed stored events arriving during subscription activation being incorrectly dropped instead of delivered.
    • Improved error reporting when epoch-gap backfill fails.
  • Tests

    • Added/extended integration and regression coverage for replay routing, stalled-epoch backfill, and below-floor recovery behavior.

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

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: 62f94419-30da-4f94-916d-3ba98920087f

📥 Commits

Reviewing files that changed from the base of the PR and between 90da57c and 865d5b2.

📒 Files selected for processing (2)
  • crates/marmot-app/src/client/sync.rs
  • crates/marmot-app/tests/next_event_backfill.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/marmot-app/src/client/sync.rs

Walkthrough

Epoch-gap backfill detection tracks undecryptable messages by group and epoch, triggers full-history transport reactivation, and suppresses repeated signals after replay. Runtime integration drains pending backfills, while activation ordering ensures stored replay events are routed and tested.

Changes

Epoch-gap backfill

Layer / File(s) Summary
Stall detection state
crates/marmot-app/src/client/epoch_stall.rs, crates/marmot-app/src/client/mod.rs, crates/marmot-app/src/lib.rs
Adds per-group epoch-stall tracking, threshold detection, replay suppression, client state, and initialization.
Ingest-triggered backfill flow
crates/marmot-app/src/client/sync.rs, crates/marmot-app/src/runtime/account_worker.rs, crates/marmot-app/tests/since_floor.rs
Arms full-history backfill after qualifying stale ingest failures, drains it during runtime processing, and tests recovery and debounce behavior.
Backfill liveness signaling
crates/marmot-app/src/client/sync.rs, crates/marmot-app/tests/next_event_backfill.rs
Prevents next_event from skipping an armed backfill and verifies that empty ingest results still return promptly.
Activation replay routing
crates/transport-nostr-adapter/src/lib.rs, crates/transport-nostr-adapter/tests/inbound_routing.rs
Activates routing state before subscriptions and verifies stored replay delivery during activation.

Estimated code review effort: 4 (Complex) | ~60 minutes

🚥 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 matches the main change: adding epoch-gap backfill handling for commit-loss recovery.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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/commit-loss-epoch-gap-backfill

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

@stage-review

stage-review Bot commented Jul 16, 2026

Copy link
Copy Markdown

Ready to review this PR? Stage has broken it down into 5 individual chapters for you:

Title
1 Fix race condition in subscription activation
2 Implement epoch stall detection logic
3 Integrate stall detector into AppClient
4 Wire backfill recovery into sync process
5 Add tests for epoch-gap recovery
Open in Stage

Chapters generated by Stage for commit 865d5b2 on Jul 16, 2026 5:30pm UTC.

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/marmot-app/src/client/sync.rs`:
- Around line 339-344: Update next_event around
epoch_stall.observe_undecryptable so arming epoch_backfill_pending causes the
method to return through its empty-result path immediately, allowing
run_pending_epoch_backfill to execute without waiting for another visible event.
Extend the existing sync tests with steady-state coverage alongside the
cold-boot case, verifying a peel-failed delivery arms backfill and reaches the
pending-backfill flow.
- Around line 351-356: Update run_pending_epoch_backfill so it checks
epoch_backfill_pending without clearing it, attempts activate_transport(None),
and only clears the pending intent after activation succeeds; preserve the early
return when no backfill is pending and do not call epoch_stall.mark_replayed
until successful activation.

In `@crates/transport-nostr-adapter/src/lib.rs`:
- Around line 534-550: Update the activation flow around state.activate and
subscribe_all so failures in subscription issuance compensate all
already-applied changes: tear down any partial subscriptions, revert the
account’s local routing state to inactive, and remove the newly recorded
telemetry before propagating the error. Ensure both zero-subscription and
partial-subscription failures leave state consistent and avoid exposing the
committed activation until subscribe_all succeeds.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f6945f79-e53c-469f-9554-0e92d73e744e

📥 Commits

Reviewing files that changed from the base of the PR and between 363b1fe and 90da57c.

📒 Files selected for processing (8)
  • crates/marmot-app/src/client/epoch_stall.rs
  • crates/marmot-app/src/client/mod.rs
  • crates/marmot-app/src/client/sync.rs
  • crates/marmot-app/src/lib.rs
  • crates/marmot-app/src/runtime/account_worker.rs
  • crates/marmot-app/tests/since_floor.rs
  • crates/transport-nostr-adapter/src/lib.rs
  • crates/transport-nostr-adapter/tests/inbound_routing.rs

Comment thread crates/marmot-app/src/client/sync.rs
Comment thread crates/marmot-app/src/client/sync.rs
Comment thread crates/transport-nostr-adapter/src/lib.rs
@jgmontoya
jgmontoya merged commit e6654ec into master Jul 17, 2026
20 checks passed
@jgmontoya
jgmontoya deleted the feat/commit-loss-epoch-gap-backfill branch July 17, 2026 02:26
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