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).

@coderabbitai

coderabbitai Bot commented Jul 17, 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: CHILL

Plan: Pro

Run ID: c1a7b9a0-ce23-41c2-ac7d-2bfba74de693

📥 Commits

Reviewing files that changed from the base of the PR and between 5f23d5a and 4aa7174.

📒 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

📝 Walkthrough

Walkthrough

Changes

The repair executor now reads freshness keys from row data or Spock metadata. Unit and integration tests cover commit timestamps and application columns, while documentation adds a reusable multi-table latest-wins plan.

Freshest-side repair behavior

Layer / File(s) Summary
Metadata-aware freshness selection
internal/consistency/repair/executor.go, internal/consistency/repair/pick_freshest_test.go
freshestSide resolves keys through lookupValue, with tests for metadata timestamps, NULL handling, and application columns.
End-to-end freshness repair validation
tests/integration/advanced_repair_test.go
Integration tests verify commit-timestamp and application-column plans, convergence, and expected row winners.
Reusable latest-wins repair plan
docs/commands/repair/examples/repair-plan-latest-wins.yaml, docs/commands/repair/advanced-repair-examples.md
Adds a shared YAML-anchored commit_ts rule, multi-table examples, outcome details, caveats, and dry-run guidance.

Poem

I’m a rabbit with rows in my hat,
Picking the freshest—imagine that!
Commit times hop, metadata gleams,
Old rows yield to newer dreams.
One plan, many tables,
Carrots at the repair tables!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the core fix and the new latest-commit-wins example.
Description check ✅ Passed The description clearly matches the implemented fix, tests, docs, and examples in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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 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

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

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.

@mason-sharp
mason-sharp requested a review from rasifr July 20, 2026 15:03
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.
@mason-sharp
mason-sharp force-pushed the feature/ACE-206/timestamp-repair branch from a2b5256 to 4aa7174 Compare July 20, 2026 16:48
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.

2 participants