Skip to content

[claude] Add an endpoint to request a CRDT snapshot rebuild - #2630

Open
myieye wants to merge 9 commits into
developfrom
claude/force-crdt-snapshot-rebuild
Open

[claude] Add an endpoint to request a CRDT snapshot rebuild#2630
myieye wants to merge 9 commits into
developfrom
claude/force-crdt-snapshot-rebuild

Conversation

@myieye

@myieye myieye commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

[Claude, autonomous]

POST /api/fw-lite/sync/request-crdt-snapshot-rebuild/{projectId} adds an empty commit dated before every other commit in the project. A client that receives a commit predating its history rolls its snapshots all the way back and replays everything, so each one rebuilds its snapshots the next time it syncs. Nothing is rebuilt server-side, and a client that never syncs never rebuilds. Admin only. An optional note goes into the commit metadata, and the response says how many commits clients will replay.

Tests cover what it promises: no commit sorts before the marker and it carries no changes, and a client with nothing left to sync is still sent it (which is what the fresh client id buys).

The mechanism was also checked outside the tests, by replaying a captured sync payload plus such a commit against a copy of a wedged production project's database: the resulting projected state came out byte-identical to a from-scratch rebuild.

myieye and others added 9 commits September 3, 2026 16:17
The interceptor threw 'Sequence contains no elements', which says nothing about which entry is missing. It fires when a sense is saved whose entry is no longer in the projected table.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Adds an empty commit dated before the project's oldest, so every client rolls its snapshots back past the start of history and replays the whole thing in one batch. Recovers a project whose sync fails repeatedly with a foreign key violation from AddSnapshots (sillsdev/harmony#105).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The search table error message is unrelated to this endpoint. The rebuild is a general mechanism, so its comments no longer describe one specific failure.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
It belongs next to the other sync maintenance endpoints rather than in a controller of its own.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
It adds a commit; the rebuild happens on each client's next sync, so calling it rebuilds nothing by itself.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Covers the three things the endpoint claims: the commit predates every other commit in the project, it carries no changes, and a client with nothing left to sync is still sent it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Deriving the date from the oldest commit could race with an older commit arriving, and threw if the project started within a day of DateTimeOffset.MinValue; the floor can't be beaten and needs no query. The SignalR notify meant a broadcast failure returned an error for a commit that was already saved, and a retry would make every client replay twice; clients pick the commit up on their next sync anyway.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Now that the commit is dated at the floor, asserting it is strictly older than everything else fails whenever another test in the class has already added one, and xUnit does not fix method order. What matters is that no commit sorts before it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions github-actions Bot added the 📦 Lexbox issues related to any server side code, fw-headless included label Sep 4, 2026
@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 1fd8b446-5dfb-4c11-9416-573b602f3db3

📥 Commits

Reviewing files that changed from the base of the PR and between afcea01 and 063506b.

📒 Files selected for processing (3)
  • backend/LexBoxApi/Controllers/SyncController.cs
  • backend/LexBoxApi/Services/CrdtCommitService.cs
  • backend/Testing/LexCore/Services/CrdtCommitServiceTests.cs

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The service now creates empty CRDT snapshot-rebuild commits with replay metadata. An admin-only controller endpoint requests these commits. Tests cover commit ordering, replay counts, empty changes, and delivery to synchronized clients.

Changes

CRDT snapshot rebuild

Layer / File(s) Summary
Snapshot-rebuild commit creation and validation
backend/LexBoxApi/Services/CrdtCommitService.cs, backend/Testing/LexCore/Services/CrdtCommitServiceTests.cs
CrdtCommitService creates snapshot-rebuild commits and returns replay metadata. Tests validate commit ordering, empty changes, replay counts, and delivery to up-to-date clients.
Administrative rebuild endpoint
backend/LexBoxApi/Controllers/SyncController.cs
SyncController injects CrdtCommitService and adds an admin-protected POST endpoint. The endpoint returns the created commit or 404 when the project has no CRDT commits.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 06350

This adds an admin-only request that causes syncing clients to replay project history from an empty marker commit. The marker behavior and delivery path are covered, with no remaining concrete merge-blocking risk.

Suggested reviewers: hahn-kev

Poem

A rabbit taps a rebuild bell
Empty commits march through the shell
Old histories wake and play
Admin paws now lead the way
Snapshots bloom before the day

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding an endpoint that requests a CRDT snapshot rebuild.
Description check ✅ Passed The description accurately explains the new admin-only endpoint, marker commit behavior, optional note, replay count, client effects, and test coverage.
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/force-crdt-snapshot-rebuild

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📦 Lexbox issues related to any server side code, fw-headless included

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant