fix(db): return the newest events, not an arbitrary slice - #476
fix(db): return the newest events, not an arbitrary slice#476avionicharshit-byte wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughThe event service now exposes a reusable query builder. Event results are ordered by ChangesEvent query ordering
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The change makes limited event queries return the newest records as expected by callers, with no identified user-impacting or production merge-blocking risk remaining beyond normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Linked Issues checkExplanation The change satisfies issue
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
fixes #475.
queryEventsCoreended with.limit(input.limit ?? 20).execute()and noORDER BY, so clickhouse returned whatever it read first. events sort on(project_id, toDate(created_at), created_at, name)partitioned by month, so a bare limit hands back an arbitrary slice of the window. every caller labels those rows as recent: the mcp tool passessortedBy: 'created_at desc',zLimittells the model results are ranked, and the agent tools call them recent events.sorting before the limit. clickhouse can read the sort key in reverse for this, so it is not a full sort of the window.
measured on a local clickhouse with the same sort key and partitioning, 90 days of one profile's events, one per day, limit 5. before:
2026-09-01, then2026-07-01through2026-07-04. after:2026-09-01back to2026-08-28.the query builder is split out so the shape can be tested, same as
buildProfileMetricsSql. the ordering test fails on main.Summary by CodeRabbit
Improvements
Tests