Skip to content

Fix pagination gap-skipping bug in list_tasks - #63

Open
zinodict121 wants to merge 1 commit into
ecotask-network:mainfrom
zinodict121:fix-pagination-bug
Open

Fix pagination gap-skipping bug in list_tasks#63
zinodict121 wants to merge 1 commit into
ecotask-network:mainfrom
zinodict121:fix-pagination-bug

Conversation

@zinodict121

Copy link
Copy Markdown

Description

Fix pagination gap-skipping bug in list_tasks.

Previously, a gap in the ID space (from any missing records) would silently consume a tick of the limit counter. This bug returned artificially shortened pages, causing front-end or indexer paginators that use page.len() < limit as a stop signal to drop indexing operations and miss remaining items.

This PR fixes this issue by moving remaining -= 1; inside the if let Some(task) = storage::read_task(...) condition in list_tasks. This ensures the requested page limit is fulfilled by actual returned tasks rather than consuming the page allocation on missing or deleted IDs (gaps).

Fixes #40

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Added test_list_tasks_with_gaps to simulate scenarios where gaps exist in the index. The test strictly validates that the function correctly fetches the requested quota of tasks despite gaps, safely stopping only at the end-of-registry. Existing pagination and full_scan tests remain unbroken.

  • cargo test - Verified cargo test -p task-registry handles base index scans, pagination constraints, and accurately fetches tasks dynamically when spanning deleted/missing item chunks.
  • Integration tests in tests/
  • Manual verification via Soroban CLI

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

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

The CI checks are failing please kindly fix them

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.

list_tasks in the registry does a sequential ID scan; deleted/non-existent IDs silently shrink pages without warning

2 participants