Skip to content

fix(sdk/python): order Stats.Recent by insertion order, not last_confirmed#474

Merged
peteski22 merged 1 commit into
mainfrom
fix/sqlite-stats-recent-order
Jun 25, 2026
Merged

fix(sdk/python): order Stats.Recent by insertion order, not last_confirmed#474
peteski22 merged 1 commit into
mainfrom
fix/sqlite-stats-recent-order

Conversation

@peteski22

@peteski22 peteski22 commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Replace in-memory last_confirmed sort with ORDER BY rowid DESC LIMIT ? SQL query in the Python SQLite store's stats() method, matching all other store implementations
  • Update StoreStats.Recent docstring in Go (sdk/go/types.go) and field comment in Python (sdk/python/src/cq/store.py) to say "most recently added"
  • Update test to verify insertion order instead of confirmation-date order

Test plan

  • Python SDK tests pass (453 passed)
  • Go SDK tests pass
  • Python lint clean
  • Go lint clean (0 issues)

Fixes #473

Summary by CodeRabbit

  • Bug Fixes

    • Updated “recent items” store statistics to represent the most recently added units, using insertion order rather than last confirmation time.
    • Existing totals and other breakdowns remain calculated from the full set of stored units.
  • Tests

    • Updated test expectations and renamed the relevant assertion to verify “recent items” follow insertion order (most recently inserted first).

@peteski22 peteski22 added sdk sdk-python For issues or PRs related to the Python SDK labels Jun 25, 2026
@coderabbitai

coderabbitai Bot commented Jun 25, 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: ASSERTIVE

Plan: Pro

Run ID: 7677d153-1676-4ed7-86e7-219ba06c16be

📥 Commits

Reviewing files that changed from the base of the PR and between b7bb9c9 and 582748c.

📒 Files selected for processing (3)
  • sdk/go/types.go
  • sdk/python/src/cq/store.py
  • sdk/python/tests/test_store.py

Walkthrough

StoreStats comments now describe recent as most recently added units. Python SQLite stats now builds recent from the latest inserted rows by rowid DESC, while totals and counts still use all rows. The Python test now checks insertion order.

Changes

StoreStats recent ordering

Layer / File(s) Summary
StoreStats wording
sdk/go/types.go, sdk/python/src/cq/store.py
StoreStats comments now describe recent as the most recently added local-store units.
SQLite recent query
sdk/python/src/cq/store.py
SqliteStore.stats now fetches recent from a rowid-ordered limited query and still computes the remaining aggregates from all rows.
Recent-order test
sdk/python/tests/test_store.py
The stats test removes unused imports and asserts stats().recent returns the latest inserted unit first.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly states the Python SQLite stats ordering fix and the change from last_confirmed to insertion order.
Linked Issues check ✅ Passed The PR matches #473 by switching Python SQLite Recent to insertion order and updating the Go and Python docs comments.
Out of Scope Changes check ✅ Passed The changes stay within the stated scope: behaviour fix, matching documentation, and a targeted test update.

✏️ 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/sqlite-stats-recent-order

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.

…irmed

The Python SQLite store sorted Recent units by evidence.last_confirmed
descending, diverging from all other store implementations (Go SQLite,
Go in-memory, Go PostgreSQL, Python PostgreSQL) which use rowid DESC
(insertion order). Replace the in-memory sort with a SQL ORDER BY
rowid DESC query to match.

Also update the StoreStats.Recent docstring in Go and Python to say
"most recently added" instead of "most recently confirmed".

Fixes #473

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

Pull request overview

Updates the Python SQLite store’s stats() implementation so StoreStats.recent reflects insertion order (most recently added), matching the semantics used by other store backends and SDKs.

Changes:

  • Switch Python SQLite stats() “recent” selection from in-memory last_confirmed sorting to ORDER BY rowid DESC LIMIT ?.
  • Update Go and Python StoreStats.Recent/recent documentation/comments to say “most recently added”.
  • Adjust Python test to assert insertion-order behavior.

Reviewed changes

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

File Description
sdk/python/tests/test_store.py Updates the recent ordering test to validate reverse insertion order.
sdk/python/src/cq/store.py Changes SQLite stats() to fetch recent via ORDER BY rowid DESC LIMIT ? and updates the field comment.
sdk/go/types.go Updates StoreStats.Recent comment to align with “most recently added” semantics.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sdk sdk-python For issues or PRs related to the Python SDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(sdk/python): SQLite store Stats orders Recent by last_confirmed instead of insertion order

2 participants