Skip to content

fix(bench): stabilize tied recent-post ordering - #258

Merged
benvinegar merged 1 commit into
mainfrom
fix/benchmark-recent-post-determinism
Aug 18, 2026
Merged

fix(bench): stabilize tied recent-post ordering#258
benvinegar merged 1 commit into
mainfrom
fix/benchmark-recent-post-determinism

Conversation

@benvinegar

Copy link
Copy Markdown
Member

What

Make recent-post result membership deterministic when multiple writes share the same millisecond timestamp.

PR #255 exposed the issue: the deterministic response-byte benchmark measured 137,029 bytes on its first CI run, then the committed 132,989-byte baseline on rerun with no code change.

Cause

SqlStore.listRecentPosts() ordered only by millisecond-resolution updatedAt before applying LIMIT. Large fixture batches create timestamp ties across the limit boundary, leaving SQLite free to select different posts depending on version/query plan. The JSON store also relied implicitly on stable sort behavior.

Fix

  • use rowid DESC as the explicit SQLite tie-breaker
  • use newest Map insertion order as the equivalent JSON-store tie-breaker
  • document the store contract
  • freeze time in a shared 25-post contract test and assert exact 20-post membership for both backends
  • retain the existing timestamp index for the hot query

No benchmark baseline update is needed: repeated Node 22 and Node 24 runs now both produce exactly 132,989 typical bytes and 196,269 heavy bytes.

Validation

  • npm test
  • npm run coverage
  • npm run test:worker
  • npm run typecheck
  • npm run lint
  • npm run format:check
  • npm run security:audit
  • npm run bench:check -- --gate deterministic
  • independent review: no blocker, high, or medium findings

This PR description was generated by Pi using gpt-5.6-sol

@benvinegar
benvinegar merged commit feac177 into main Aug 18, 2026
10 checks passed
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.

1 participant