Skip to content

fix: save snapshot on mismatch in forest-dev state compute#7123

Merged
hanabi1224 merged 1 commit into
mainfrom
hm/export-state-compute-snap-on-mismatch
Jun 1, 2026
Merged

fix: save snapshot on mismatch in forest-dev state compute#7123
hanabi1224 merged 1 commit into
mainfrom
hm/export-state-compute-snap-on-mismatch

Conversation

@hanabi1224

@hanabi1224 hanabi1224 commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Summary of changes

Changes introduced in this pull request:

Reference issue to close (if applicable)

Closes

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

Outside contributions

  • I have read and agree to the CONTRIBUTING document.
  • I have read and agree to the AI Policy document. I understand that failure to comply with the guidelines will lead to rejection of the pull request.

Summary by CodeRabbit

  • Bug Fixes
    • Database snapshot export now only occurs when the export option is explicitly specified, preventing unnecessary file write operations and improving efficiency.

@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

ComputeCommand::run in the state subcommand is refactored to write the exported DB snapshot CAR file immediately after generation when export_db_to is provided, relocating the conditional write block from the end of the function to wrap the snapshot output directly.

Changes

Snapshot export write relocation

Layer / File(s) Summary
Relocate snapshot export write after generation
src/dev/subcommands/state_cmd.rs
The conditional DB snapshot export write is moved from the end of ComputeCommand::run to execute immediately after db_snapshot is generated, consolidating the export logic closer to its source.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Possibly related PRs

  • ChainSafe/forest#6167: Directly related to state compute functionality and ComputeCommand::run export behavior with export_db_to.

Suggested reviewers

  • elmattic
  • akaladarshi
  • LesnyRumcajs
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: save snapshot on mismatch in forest-dev state compute' directly and specifically summarizes the main change: conditional snapshot saving based on mismatch detection in the state compute command.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 hm/export-state-compute-snap-on-mismatch
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch hm/export-state-compute-snap-on-mismatch

Comment @coderabbitai help to get the list of available commands and usage tips.

@hanabi1224 hanabi1224 marked this pull request as ready for review June 1, 2026 10:05
@hanabi1224 hanabi1224 requested a review from a team as a code owner June 1, 2026 10:05
@hanabi1224 hanabi1224 requested review from LesnyRumcajs and sudo-shashank and removed request for a team June 1, 2026 10:05

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

🧹 Nitpick comments (1)
src/dev/subcommands/state_cmd.rs (1)

122-124: ⚡ Quick win

Add error context to snapshot file writes.

On Line 123, std::fs::write(...) should include .with_context(...) so failures include the output path.

Suggested change
 if let Some(export_db_to) = export_db_to {
-    std::fs::write(export_db_to, db_snapshot)?;
+    std::fs::write(&export_db_to, db_snapshot).with_context(|| {
+        format!("failed to write db snapshot CAR to {}", export_db_to.display())
+    })?;
 }

As per coding guidelines: “Use anyhow::Result<T> for most operations and add context with .context() when errors occur”.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/dev/subcommands/state_cmd.rs` around lines 122 - 124, The file writes DB
snapshots using std::fs::write(export_db_to, db_snapshot)? without context;
change this to propagate errors with context by calling .with_context(||
format!("Failed to write DB snapshot to {}", export_db_to)) (from
anyhow::Context) on the write Result before the ? so failures include the output
path; ensure the module imports anyhow::Context if not already and reference the
export_db_to and db_snapshot variables and the std::fs::write call when making
the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/dev/subcommands/state_cmd.rs`:
- Around line 122-124: The file writes DB snapshots using
std::fs::write(export_db_to, db_snapshot)? without context; change this to
propagate errors with context by calling .with_context(|| format!("Failed to
write DB snapshot to {}", export_db_to)) (from anyhow::Context) on the write
Result before the ? so failures include the output path; ensure the module
imports anyhow::Context if not already and reference the export_db_to and
db_snapshot variables and the std::fs::write call when making the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: bb04e694-8845-4c43-9dd2-0d0e78b1ea94

📥 Commits

Reviewing files that changed from the base of the PR and between 86d7eaf and a9a1015.

📒 Files selected for processing (1)
  • src/dev/subcommands/state_cmd.rs

@codecov

codecov Bot commented Jun 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.42%. Comparing base (86d7eaf) to head (a9a1015).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/dev/subcommands/state_cmd.rs 0.00% 3 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/dev/subcommands/state_cmd.rs 0.00% <0.00%> (ø)

... and 13 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 86d7eaf...a9a1015. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hanabi1224 hanabi1224 enabled auto-merge June 1, 2026 12:51
@hanabi1224 hanabi1224 added this pull request to the merge queue Jun 1, 2026
Merged via the queue into main with commit 8bbf737 Jun 1, 2026
39 of 42 checks passed
@hanabi1224 hanabi1224 deleted the hm/export-state-compute-snap-on-mismatch branch June 1, 2026 13:24
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