Skip to content

fix(repair): pick_freshest compares commit_ts; add latest-commit-wins example#152

Open
mason-sharp wants to merge 2 commits into
mainfrom
feature/ACE-206/timestamp-repair
Open

fix(repair): pick_freshest compares commit_ts; add latest-commit-wins example#152
mason-sharp wants to merge 2 commits into
mainfrom
feature/ACE-206/timestamp-repair

Conversation

@mason-sharp

Copy link
Copy Markdown
Member

pick_freshest with key: commit_ts never actually compared commit timestamps — it read the key from the stripped diff row (where commit_ts has been moved into spock_metadata), found nil on both sides, and fell back to tie every time. This fixes it and documents a one-pass "latest commit wins" repair pattern.

Changes

  • Fix: freshestSide now resolves the key via lookupValue, which falls back to n1Meta/n2Meta. So key: commit_ts compares commit timestamps, while ordinary data columns (e.g. updated_at) keep working.
  • Unit tests: commit_ts from metadata (both directions), one-side-NULL (side with a timestamp wins), both-NULL (tie), and app-column-from-row.
  • Integration tests: one-pass latest-commit-wins end-to-end (newer commit_ts side wins) and pick_freshest by an app-level column (subscription_date).
  • Docs: new examples/repair-plan-latest-wins.yaml (multi-table via YAML anchor, with caveats and opt-in alternatives) and a "5g" section in advanced-repair-examples.md.

Notes

  • n1/n2 in plans are positional (alphabetical per pair), not node names — documented in the example and doc section.
  • A NULL commit_ts is rare: PostgreSQL preserves a tuple's raw xmin across freezing, so commit_ts survives until pg_commit_ts is truncated (~50M–200M txns) or track_commit_timestamp was off at write time. That branch is unit-covered (can't be reproduced live in the harness).

pick_freshest resolved its `key` only from the stripped diff row, but
commit_ts (and other spock metadata) are moved into n1Meta/n2Meta during
diff loading. So `pick_freshest: {key: commit_ts}` found nil on both sides
and fell back to `tie` every time, never actually comparing timestamps.

Resolve the key via lookupValue, which falls back to the metadata map, so
`key: commit_ts` compares commit timestamps while ordinary data columns
(e.g. updated_at) keep working.

Tests:
- unit: commit_ts-from-meta (both directions), one-side-null (the side with
  a timestamp wins), both-null (tie), and app-column-from-row.
- integration: one-pass latest-commit-wins end-to-end (newer commit_ts side
  wins) and pick_freshest by an app-level column (subscription_date).
Add examples/repair-plan-latest-wins.yaml (fully commented, one-pass
pick_freshest by commit_ts, shared across tables via a YAML anchor, with
opt-in alternatives and a per-table override) and a "5g" section to
advanced-repair-examples.md documenting the pattern, per-case resolution,
and the caveats: positional n1/n2, track_commit_timestamp, string
comparison, last-write-wins, and when commit_ts actually goes NULL.
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@mason-sharp, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 51 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a28021e6-94bd-4642-a352-6ac1169173e5

📥 Commits

Reviewing files that changed from the base of the PR and between 108b036 and a2b5256.

📒 Files selected for processing (5)
  • docs/commands/repair/advanced-repair-examples.md
  • docs/commands/repair/examples/repair-plan-latest-wins.yaml
  • internal/consistency/repair/executor.go
  • internal/consistency/repair/pick_freshest_test.go
  • tests/integration/advanced_repair_test.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/ACE-206/timestamp-repair

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.

@codacy-production

codacy-production Bot commented Jul 17, 2026

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 4 critical

Alerts:
⚠ 4 issues (≤ 0 issues of at least critical severity)
⚠ 4 issues (≤ 0 issues of at least minor severity)

Results:
4 new issues

Category Results
Security 4 critical (4 false positives)

View in Codacy

🟢 Metrics 8 complexity · 8 duplication

Metric Results
Complexity 8
Duplication 8

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

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