Skip to content

fix: forward subscription updates that resolve pending fetches - #1508

Merged
GabrielePicco merged 2 commits into
masterfrom
fix/forward-consumed-subscription-updates
Jul 30, 2026
Merged

fix: forward subscription updates that resolve pending fetches#1508
GabrielePicco merged 2 commits into
masterfrom
fix/forward-consumed-subscription-updates

Conversation

@GabrielePicco

@GabrielePicco GabrielePicco commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Problem

A subscription update arriving for an account with a fetch in flight is consumed to resolve that fetch and never forwarded to the update pipeline — while submux dedup has already dropped every other copy. Correctness silently depends on the fetch caller cloning the result. Non-cloning callers (delegation-status reads via fetch_remote_accounts) and multi-stage resolutions that fail mid-churn discard it, permanently losing the freshest chain state. With a stale copy in the bank suppressing refetches, the account stays wedged until the next on-chain write — reproducible by delegating/undelegating in quick succession while anything polls the account.

#1507 fixed one consumer of this class (the slot-matching companion path); this fixes the class at its source.

Solution

Consumption is non-exclusive: the update resolves the fetch waiters and is forwarded like any other notification (one NoneSome(update) at the arbitration site). Double-processing is benign via the existing non-advancing-slot gate.

Tests

  • test_update_resolving_pending_fetch_is_also_forwarded — non-cloning fetch in flight, update consumed; red before, green after.
  • Two existing tests updated from the old exclusive-consumption contract; exact global-metric asserts relaxed to lower bounds (concurrent tests share label sets).

Summary by CodeRabbit

  • Bug Fixes

    • Subscription updates that resolve in-flight account fetches are now also forwarded to downstream consumers.
    • Redelegation updates are preserved and correctly applied when finalizing account state.
    • Consumed subscription updates are reliably replayed through the update pipeline.
  • Tests

    • Expanded coverage for forwarded subscription updates and replay behavior.
    • Improved metric assertions to remain reliable during concurrent test execution.

An update consumed to resolve a pending fetch was not forwarded to the
update pipeline, and submux dedup has already dropped every other copy.
Correctness then depended on the fetch caller cloning the result, which
non-cloning callers (delegation-status reads) and failing multi-stage
resolutions do not: the freshest state was lost and, with a stale copy in
the bank suppressing refetches, the account stayed wedged until the next
on-chain write.

Consumption is now non-exclusive: the update resolves the waiters and is
forwarded like any other notification. Double-processing is benign via
the existing non-advancing-slot gate.
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@GabrielePicco, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 53 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 66b91032-7609-4533-9571-fecc0e583438

📥 Commits

Reviewing files that changed from the base of the PR and between b8bd5ca and a8c3101.

📒 Files selected for processing (1)
  • magicblock-chainlink/src/remote_account_provider/tests.rs
📝 Walkthrough

Walkthrough

Subscription updates that resolve in-flight account fetches are now forwarded into the main update pipeline while also resolving fetch waiters. Tests now verify forwarded redelegation and consumed updates, validate subscription-derived fetch results and forwarding, and use lower-bound assertions for shared companion-fetch attempt metrics.

Suggested reviewers: thlorenz, dodecahedr0x

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/forward-consumed-subscription-updates

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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b8bd5ca3a9

ℹ️ 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".

Comment thread magicblock-chainlink/src/remote_account_provider/mod.rs

@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: 1

🤖 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 `@magicblock-chainlink/src/remote_account_provider/tests.rs`:
- Around line 1663-1669: Update the paired histogram-sum assertion following
chainlink_companion_fetch_attempts_sample_count to require at least
attempts_sum_before + 1.0 instead of exactly that value, preserving
concurrency-safe behavior when same-label observations increase the sum.
🪄 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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 2200d86a-924e-448a-88a9-9fa1c2c104eb

📥 Commits

Reviewing files that changed from the base of the PR and between 1d9aa3e and b8bd5ca.

📒 Files selected for processing (3)
  • magicblock-chainlink/src/chainlink/fetch_cloner/tests.rs
  • magicblock-chainlink/src/remote_account_provider/mod.rs
  • magicblock-chainlink/src/remote_account_provider/tests.rs

Comment thread magicblock-chainlink/src/remote_account_provider/tests.rs
@GabrielePicco
GabrielePicco merged commit 55e4533 into master Jul 30, 2026
36 checks passed
@GabrielePicco
GabrielePicco deleted the fix/forward-consumed-subscription-updates branch July 30, 2026 16:18
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