Skip to content

fix(db): getLatestPublishedAiReview has no tiebreaker on its ORDER BY published_at DESC LIMIT 1 #8894

Description

@JSONbored

⚠️ Definition of Done: this issue must be completed in full, in a single PR. Do not split this
work across multiple PRs, and do not defer any Deliverable below to a follow-up issue. A PR that
satisfies only some of the Deliverables, stubs a required test, or leaves a checkbox
partially-done does NOT resolve this issue and will be closed.

Context

src/db/repositories.ts:5089-5110's query at line 5097 has no tiebreaker. Every other "pick the most recent row" query in repositories.ts explicitly breaks ties on rowid/id (e.g. getLatestAdvisoryForPullRequest at line 5025: ORDER BY updated_at DESC, rowid DESC, with a comment explaining a rapid synchronize burst can tie on the millisecond-precision text timestamp; listSignalSnapshots at line 5463 has the identical fix with an even more detailed comment citing an adversarial-id regression). getLatestPublishedAiReview selects the most-recently-published ai_review_cache row across all of a PR's historical head SHAs, but is missing the same tiebreak -- two head SHAs published within the same millisecond return a nondeterministic result.

Requirements

Change line 5097 to ORDER BY published_at DESC, rowid DESC LIMIT 1, matching the sibling functions' tiebreak pattern exactly.

Deliverables

  • getLatestPublishedAiReview's query includes rowid DESC as a tiebreaker
  • A test in test/unit/ai-review-cache.test.ts with two rows sharing an identical published_at, asserting a stable, deterministic result

All of the above Deliverables are required in the same PR unless the deliverable text itself states otherwise.

Test Coverage Requirements

src/** -- 99%+ patch coverage, branch-counted, including the new tiebreak test.

Expected Outcome

getLatestPublishedAiReview returns a deterministic result even when two head SHAs were published within the same millisecond.

Links & Resources

  • src/db/repositories.ts:5025,5089-5110,5463
  • test/unit/ai-review-cache.test.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    gittensor:bugGittensor-scored bug fix — scores a 0.05x multiplier.help wantedExtra attention is needed

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions