Skip to content

create project snapshot from crdt project when missing#1753

Closed
hahn-kev wants to merge 2 commits into
developfrom
cleanup-after-failed-import
Closed

create project snapshot from crdt project when missing#1753
hahn-kev wants to merge 2 commits into
developfrom
cleanup-after-failed-import

Conversation

@hahn-kev

Copy link
Copy Markdown
Collaborator

closes #1735

Changes FW Headless so that if the previous sync failed to create a snapshot (OOM, restart, or bug) then we will create a snapshot based on what's in the CRDT db. Then when the sync executes it will be able to resume where it left off, instead of trying to import again.

hahn-kev added 2 commits June 16, 2025 10:29
…roject to restart the sync from scratch, rather than trying to resume where we left off
…apshot, create one from what's currently in the database, this means even a partial import will resume more or less where it left off.
@coderabbitai

coderabbitai Bot commented Jun 16, 2025

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The changes refactor project setup and snapshot handling logic in the synchronization process. Methods are reorganized for clarity, with new helpers for CRDT project opening and snapshot checks. The code now leverages injected services, reduces parameter passing, and introduces snapshot availability checks to improve robustness during sync operations.

Changes

File(s) Change Summary
backend/FwHeadless/Services/SyncHostedService.cs Refactored project setup logic; updated method signatures; added helper for CRDT project open; integrated snapshot checks and saving.
backend/FwLite/FwLiteProjectSync/CrdtFwdataProjectSyncService.cs Added SaveProjectSnapshot(FwDataProject, IMiniLcmApi) and IsSnapshotAvailable(FwDataProject) methods; refactored snapshot saving logic in sync process.

Assessment against linked issues

Objective Addressed Explanation
Prevent pushing changes after failed import by checking for snapshot file (#1735)
Add/Refactor logic to check snapshot availability and save snapshots as part of sync process (#1735)
Improve handling of partial import failures and ensure correct sync recovery (#1735)

Poem

A bunny hopped through code today,
Tidying sync in every way.
Snapshots checked, imports neat,
Crashes dodged with nimble feet.
Now syncs recover, projects thrive—
Harmony’s hop keeps bugs alive...
Only to chase them out, not let them survive! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions

Copy link
Copy Markdown
Contributor

C# Unit Tests

116 tests  ±0   116 ✅ ±0   10s ⏱️ ±0s
 17 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 405075b. ± Comparison against base commit c064fae.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
backend/FwHeadless/Services/SyncHostedService.cs (1)

196-210: Snapshot write happens without cancellation / atomicity

SetupCrdtProject writes a new snapshot when missing, but:

  • No CancellationToken is passed down – an aborted host shutdown will leave a partial file.
  • SaveProjectSnapshot uses File.Create, meaning readers can open a half-written file.

Use a temp-file + File.Replace (atomic move) and plumb the existing stoppingToken through to allow graceful cancellation.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c064fae and 405075b.

📒 Files selected for processing (2)
  • backend/FwHeadless/Services/SyncHostedService.cs (4 hunks)
  • backend/FwLite/FwLiteProjectSync/CrdtFwdataProjectSyncService.cs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Build API / publish-api
  • GitHub Check: Build FwHeadless / publish-fw-headless
  • GitHub Check: Analyze (csharp)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Build FW Lite and run tests
  • GitHub Check: frontend

Comment thread backend/FwLite/FwLiteProjectSync/CrdtFwdataProjectSyncService.cs
Comment thread backend/FwLite/FwLiteProjectSync/CrdtFwdataProjectSyncService.cs
Comment thread backend/FwHeadless/Services/SyncHostedService.cs
@argos-ci

argos-ci Bot commented Jun 16, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) ✅ No changes detected - Jun 16, 2025, 4:03 AM

@hahn-kev hahn-kev changed the title recreate crdt project if there's no snapshot create project snapshot from crdt project when missing Jun 16, 2025
{
return new CrdtProject("crdt", crdtFile);
logger.LogWarning("No snapshot available for project {ProjectId}, creating a new one, maybe the last sync didn't finish?", projectId);
await syncService.SaveProjectSnapshot(fwDataProject, api);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should throw (or something) if projectLookupService.IsCrdtProject(projectId).
I don't know how that would happen, but it wouldn't be good 🤷.

Would it maybe make sense to query and assert that sort of stuff all at once higher up? Something like IsInValidSyncableState()

@hahn-kev

Copy link
Copy Markdown
Collaborator Author

per a discussion in a team meeting, this will be changed to just make the import resumable, rather than messing around with snapshots.

@hahn-kev

Copy link
Copy Markdown
Collaborator Author

replaced by #1760

@hahn-kev hahn-kev closed this Jun 18, 2025
@hahn-kev
hahn-kev deleted the cleanup-after-failed-import branch August 15, 2025 08:37
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.

Sync FW <-> Fw lite crash when an import fails part way through

2 participants