Honor ledger API offset pagination#867
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe PR adds offset-based pagination to the newest-first ledger list: data access accepts offset, the API validates and forwards limit+offset, docs show usage, and tests check valid pages and invalid offset inputs. ChangesLedger offset pagination
Possibly related PRs
🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 32c08e9c-f8f0-4ee8-a1a1-27e5f6d74709
📒 Files selected for processing (4)
app/ledger_views.pyapp/main.pydocs/api-examples.mdtests/test_api_mcp.py
xiefuzheng713-alt
left a comment
There was a problem hiding this comment.
I reviewed the current head for ledger offset pagination and found it aligned with the bounty scope.
I checked:
- app/ledger_views.py:
ecent_ledger_entries(session, limit, offset) now applies .offset(offset) after ordering by LedgerEntry.sequence.desc(). - app/main.py: /api/v1/ledger now accepts offset with explicit query validation: repeated param rejection, canonical-int rejection, and passes through to the data access helper.
- docs/api-examples.md: usage snippet now shows limit + offset paging.
- tests/test_api_mcp.py: added regression coverage for:
- offset=1 paging behavior (second item)
- offset=0 equivalence
- invalid offset cases: negative, overflow, non-canonical, repeated
The query contract in this PR now matches the style already used on other bounded list endpoints. I did not see functional regressions in this change set.
tudorian95
left a comment
There was a problem hiding this comment.
Reviewed current head cb6c425279fbc3d73177e8a6aedf029b34b0e251 for Bounty #838.
What I checked:
- Inspected the focused diff in
app/main.py,app/ledger_views.py,tests/test_api_mcp.py, anddocs/api-examples.md. - Confirmed the live production before-state is still reproducible with harmless GETs:
GET /api/v1/ledger?limit=1returned sequence1178,GET /api/v1/ledger?limit=1&offset=1also returned1178, whileGET /api/v1/ledger?limit=2returned1178,1177. - In Docker/uv on a fresh checkout of this PR head:
uv run --extra dev pytest tests/test_api_mcp.py::test_ledger_api_honors_canonical_offset -q-> 1 passed, 1 existing Starlette/httpx warning.uv run --extra dev pytest tests/test_api_mcp.py tests/test_ledger_views.py tests/test_docs_public_urls.py -q-> 143 passed, 1 existing warning.uv run --extra dev ruff check app/main.py app/ledger_views.py tests/test_api_mcp.py docs/api-examples.md-> passed.uv run --extra dev ruff format --check app/main.py app/ledger_views.py tests/test_api_mcp.py-> passed.uv run --extra dev mypy app/main.py app/ledger_views.py-> success.uv run --extra dev python scripts/docs_smoke.py-> docs smoke ok.git diff --check-> clean.
git merge-tree --write-tree origin/main HEADsucceeded with tree5346d2a17c095c2271e9eb4c968f620bcb09450a.- GitHub reports the current head as
MERGEABLE.
The change keeps existing newest-first ledger behavior while threading a bounded canonical offset through the read-only list endpoint and its query helper. I did not find blockers.
Summary
offsetsupport toGET /api/v1/ledger.recent_ledger_entries()after the newest-first ordering.limit+offsetpagination for the ledger API.limit=1&offset=1,offset=0, negative/oversized offsets, non-canonicaloffset=01, and repeatedoffsetvalues.Source report
Fixes the production issue reported in #798: #798 (comment)
Current production evidence before this fix:
offsetis silently ignored today. With this change,limit=1&offset=1returns the second newest ledger entry instead of the newest one again.Validation
uv run --extra dev pytest tests/test_api_mcp.py::test_ledger_api_honors_canonical_offset -quv run --extra dev pytest tests/test_api_mcp.py tests/test_ledger_views.py tests/test_docs_public_urls.py -quv run --extra dev ruff check app/main.py app/ledger_views.py tests/test_api_mcp.py docs/api-examples.mduv run --extra dev ruff format --check app/main.py app/ledger_views.py tests/test_api_mcp.pyuv run --extra dev mypy app/main.py app/ledger_views.pyuv run --extra dev python scripts/docs_smoke.pygit diff --checkgit merge-tree origin/main HEADSummary by CodeRabbit
New Features
Documentation
Tests