Skip to content

fix: Infinite loop#464

Merged
shahnami merged 1 commit into
mainfrom
fix/stellar-pagination-bug
Mar 24, 2026
Merged

fix: Infinite loop#464
shahnami merged 1 commit into
mainfrom
fix/stellar-pagination-bug

Conversation

@shahnami

@shahnami shahnami commented Mar 18, 2026

Copy link
Copy Markdown
Member

Summary

Testing Process

Checklist

  • Add a reference to related issues in the PR description.
  • Add unit tests if applicable.
  • Add integration tests if applicable.
  • Add property-based tests if applicable.
  • Update documentation if applicable.

Note

If you are using Monitor in your stack, consider adding your team or organization to our list of Monitor Users in the Wild!

Summary by CodeRabbit

  • Bug Fixes

    • Stellar blockchain pagination now includes enhanced cursor state tracking with improved stall detection mechanisms, providing more stable pagination operations.
  • Tests

    • Added regression test validating proper pagination behavior and data continuity across various cursor advancement and state scenarios.

@shahnami shahnami requested a review from a team as a code owner March 18, 2026 10:16
@shahnami shahnami requested a review from Copilot March 18, 2026 10:16
@coderabbitai

coderabbitai Bot commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

The Stellar client's block pagination logic was modified to detect cursor stalls by tracking the previous cursor value instead of comparing against the start_block. An accompanying regression test verifies pagination completes correctly when the initial cursor matches the start_block.

Changes

Cohort / File(s) Summary
Stellar Pagination Stall Detection
src/services/blockchain/clients/stellar/client.rs
Added previous_cursor tracking to detect pagination stalls. Loop now breaks when cursor fails to advance (cursor == previous_cursor) rather than when cursor equals start_block, preventing infinite loops while maintaining correct pagination behavior.
Pagination Regression Test
tests/integration/blockchain/clients/stellar/client.rs
Added test test_get_blocks_cursor_equal_start_block_still_paginates to verify pagination continues when initial cursor matches start_block, ensuring the new stall-detection logic correctly handles this edge case.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A cursor that stalls shall trouble us so,
But tracking its progress helps pagination flow!
No more endless loops on the blockchain we roam,
When the cursor stands still, it's time to go home. ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description matches the template structure but all content sections are empty; Summary and Testing Process are blank, and checklist items are unchecked despite integration tests being added. Fill in the Summary section describing the pagination bug and fix, complete the Testing Process section documenting how the fix was tested, and check the relevant checklist items that apply to this change.
Title check ❓ Inconclusive The title 'fix: Infinite loop' is vague and does not clearly identify the specific component or nature of the fix; it lacks sufficient context about what was changed. Provide a more specific title that identifies the affected component and the specific issue, such as 'fix: Stellar pagination cursor stall detection' or 'fix: Prevent infinite loop in Stellar block retrieval when cursor does not advance'.
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ 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 fix/stellar-pagination-bug
📝 Coding Plan
  • Generate coding plan for human review comments

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 OpenGrep (1.16.4)
src/services/blockchain/clients/stellar/client.rs

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

�[1m Loading rules from local config...�[0m

tests/integration/blockchain/clients/stellar/client.rs

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

�[1m Loading rules from local config...�[0m


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

Tip

You can generate walkthrough in a markdown collapsible section to save space.

Enable the reviews.collapse_walkthrough setting to generate walkthrough in a markdown collapsible section.

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

🧹 Nitpick comments (1)
src/services/blockchain/clients/stellar/client.rs (1)

293-298: Consider adding stall detection to get_transactions and get_events for consistency.

While these methods didn't have the cursor == start_block bug, they could still loop indefinitely if a server misbehaves and returns the same cursor repeatedly with non-empty results. Adding the same previous_cursor pattern would provide defensive consistency across all pagination methods.

This is optional and can be deferred if you'd prefer to keep this PR focused on the specific bug.

Also applies to: 434-439

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/services/blockchain/clients/stellar/client.rs` around lines 293 - 298,
Add stall-detection in get_transactions and get_events by tracking a
previous_cursor variable alongside cursor and breaking the pagination loop if
response_body["result"]["cursor"] equals previous_cursor (i.e., cursor did not
advance) to avoid infinite loops when the server returns the same cursor with
non-empty results; update the loop in both functions to set previous_cursor =
cursor before assigning cursor = response_body["result"]["cursor"] and check
equality after assignment to break out defensively.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/services/blockchain/clients/stellar/client.rs`:
- Around line 293-298: Add stall-detection in get_transactions and get_events by
tracking a previous_cursor variable alongside cursor and breaking the pagination
loop if response_body["result"]["cursor"] equals previous_cursor (i.e., cursor
did not advance) to avoid infinite loops when the server returns the same cursor
with non-empty results; update the loop in both functions to set previous_cursor
= cursor before assigning cursor = response_body["result"]["cursor"] and check
equality after assignment to break out defensively.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f7eab22d-9938-42f1-8272-ae9f65b03019

📥 Commits

Reviewing files that changed from the base of the PR and between afa2612 and f76a9af.

📒 Files selected for processing (2)
  • src/services/blockchain/clients/stellar/client.rs
  • tests/integration/blockchain/clients/stellar/client.rs

Copilot AI 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.

Pull request overview

This PR adjusts Stellar get_blocks pagination termination logic to avoid incorrect early termination/infinite-loop behavior and adds a regression integration test around cursor handling.

Changes:

  • Track the previous pagination cursor in StellarClient::get_blocks and stop when the cursor stops advancing.
  • Remove the prior termination condition that treated cursor == start_block as end-of-range.
  • Add an integration regression test ensuring pagination continues even when the first page cursor equals start_block.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/services/blockchain/clients/stellar/client.rs Updates get_blocks pagination break conditions by tracking previous_cursor.
tests/integration/blockchain/clients/stellar/client.rs Adds a regression integration test covering the cursor == start_block pagination case.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/services/blockchain/clients/stellar/client.rs
Comment thread tests/integration/blockchain/clients/stellar/client.rs
@codecov

codecov Bot commented Mar 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.5%. Comparing base (5507296) to head (f76a9af).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main    #464   +/-   ##
=====================================
  Coverage   95.5%   95.5%           
=====================================
  Files         97      97           
  Lines      31586   31586           
=====================================
  Hits       30186   30186           
  Misses      1400    1400           
Flag Coverage Δ
integration 58.8% <ø> (ø)
properties 25.5% <ø> (ø)
unittests 88.2% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

LGTM

@tirumerla tirumerla left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm

@shahnami shahnami merged commit fb1be50 into main Mar 24, 2026
29 checks passed
@shahnami shahnami deleted the fix/stellar-pagination-bug branch March 24, 2026 17:13
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants