Skip to content

Conversation

@LesnyRumcajs
Copy link
Member

@LesnyRumcajs LesnyRumcajs commented Nov 3, 2025

Summary of changes

Changes introduced in this pull request:

  • fixed an issue where export status would show unix time genesis on forest-cli snapshot export-status --format json on a rebooted node (where no prior export has taken place)
  • progress 0.31231231353452 is weird; let's keep only to two decimal places
  • v2 job seems to be constantly failing; I increased the number of retries.

on a fresh node it's now:

❯ forest-cli snapshot export-status --format json
{
  "progress": 0.0,
  "exporting": false,
  "cancelled": false,
  "start_time": null
}

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.

Summary by CodeRabbit

  • Bug Fixes
    • Improved snapshot export status handling by gracefully managing cases where start time is unavailable.
    • Progress bar values now display with consistent two decimal place precision.
    • Increased retry limit for snapshot export polling to reduce premature timeout occurrences.

@LesnyRumcajs LesnyRumcajs requested a review from a team as a code owner November 3, 2025 11:27
@LesnyRumcajs LesnyRumcajs requested review from elmattic and hanabi1224 and removed request for a team November 3, 2025 11:27
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 3, 2025

Walkthrough

The PR makes the start_time field optional across export status types, updates initialization and usage logic to handle the optional value, increases polling retry limits from 10 to 30, and rounds progress calculations to two decimal places.

Changes

Cohort / File(s) Summary
Type definition updates
src/ipld/util.rs, src/rpc/types/mod.rs
Changed start_time field from DateTime<Utc> to Option<DateTime<Utc>> in both ExportStatus and ApiExportStatus structs. Updated initialization in start_export() to wrap timestamp in Some().
Export status handling
src/cli/subcommands/snapshot_cmd.rs
Modified elapsed time calculation in the export status wait-path to use unwrap_or_default() when accessing the now-optional start_time, affecting progress bar timing.
Progress calculation
src/rpc/methods/chain.rs
Added rounding logic to progress value in ForestChainExportStatus::handle(), rounding to exactly two decimal places.
Test script
scripts/tests/calibnet_export_check.sh
Increased retry limit from 10 to 30 for snapshot export-status polling loops.

Sequence Diagram

sequenceDiagram
    participant Start as Snapshot Export
    participant Util as ExportStatus<br/>(ipld/util)
    participant RPC as ForestChainExportStatus<br/>(rpc/methods)
    participant API as ApiExportStatus<br/>(rpc/types)
    participant CLI as snapshot_cmd<br/>(cli/subcommands)

    Start->>Util: start_export()
    Util->>Util: start_time = Some(Utc::now())
    
    Note over Util,API: Export progresses...
    
    RPC->>Util: Query ExportStatus
    Util-->>RPC: start_time: Option<DateTime>
    
    RPC->>RPC: Calculate progress<br/>Round to 2 decimals
    RPC->>API: Convert to ApiExportStatus
    API-->>API: start_time remains Option
    
    CLI->>API: Poll export-status
    API-->>CLI: ApiExportStatus
    CLI->>CLI: elapsed = start_time<br/>.unwrap_or_default()
    CLI->>CLI: Update progress bar
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review the optional type changes across struct definitions and their impact on serialization/deserialization behavior
  • Verify that all call sites handle the optional start_time correctly (particularly the unwrap_or_default() usage in elapsed time calculation)
  • Confirm progress rounding logic produces expected output format
  • Ensure increased retry limit (10→30) aligns with expected timeout behavior

Possibly related PRs

Suggested labels

RPC

Suggested reviewers

  • elmattic
  • hanabi1224
  • akaladarshi

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'fix: improve export status output and CI' accurately reflects the main changes in the changeset. The modifications address three specific improvements: fixing an export status issue on rebooted nodes, rounding progress values to two decimal places, and increasing CI retry limits. The title is concise, clear, and captures the essence of the primary changes without being overly vague.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch export-status-fixes

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/cli/subcommands/snapshot_cmd.rs (1)

220-224: Consider defaulting to current time for better UX.

The code correctly handles the optional start_time, but using unwrap_or_default() would compute elapsed time from Unix epoch (1970-01-01) if start_time is None, resulting in a very large duration (~50+ years). While this scenario is unlikely in practice (the wait block is only entered when exporting is true, and start_time is set atomically with it), consider using unwrap_or_else(|| Utc::now()) for more sensible fallback behavior:

                let elapsed = chrono::Utc::now()
-                       .signed_duration_since(result.start_time.unwrap_or_default())
+                       .signed_duration_since(result.start_time.unwrap_or_else(|| chrono::Utc::now()))
                        .to_std()
                        .unwrap_or(Duration::ZERO);

This would show ~0 elapsed time rather than 50+ years if the field is unexpectedly None.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f0718b5 and d94196e.

📒 Files selected for processing (5)
  • scripts/tests/calibnet_export_check.sh (1 hunks)
  • src/cli/subcommands/snapshot_cmd.rs (1 hunks)
  • src/ipld/util.rs (2 hunks)
  • src/rpc/methods/chain.rs (1 hunks)
  • src/rpc/types/mod.rs (1 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: LesnyRumcajs
Repo: ChainSafe/forest PR: 5907
File: src/rpc/methods/state.rs:523-570
Timestamp: 2025-08-06T15:44:33.467Z
Learning: LesnyRumcajs prefers to rely on BufWriter's Drop implementation for automatic flushing rather than explicit flush() calls in Forest codebase.
📚 Learning: 2025-08-25T13:35:24.230Z
Learnt from: hanabi1224
Repo: ChainSafe/forest PR: 5969
File: src/tool/subcommands/snapshot_cmd.rs:412-412
Timestamp: 2025-08-25T13:35:24.230Z
Learning: In src/tool/subcommands/snapshot_cmd.rs, the +1 in `last_epoch = ts.epoch() - epochs as i64 + 1` fixes an off-by-1 bug where specifying --check-stateroots=N would validate N+1 epochs instead of N epochs, causing out-of-bounds errors when the snapshot contains only N recent state roots.

Applied to files:

  • src/cli/subcommands/snapshot_cmd.rs
📚 Learning: 2025-10-17T14:24:47.046Z
Learnt from: hanabi1224
Repo: ChainSafe/forest PR: 6167
File: src/tool/subcommands/state_compute_cmd.rs:89-91
Timestamp: 2025-10-17T14:24:47.046Z
Learning: In `src/tool/subcommands/state_compute_cmd.rs`, when using `ReadOpsTrackingStore` to generate minimal snapshots, `HEAD_KEY` should be written to `db.tracker` (not `db` itself) before calling `export_forest_car()`, because the export reads from the tracker MemoryDB which accumulates only the accessed data during computation.

Applied to files:

  • src/cli/subcommands/snapshot_cmd.rs
📚 Learning: 2025-08-08T12:10:45.218Z
Learnt from: hanabi1224
Repo: ChainSafe/forest PR: 5867
File: src/ipld/util.rs:553-558
Timestamp: 2025-08-08T12:10:45.218Z
Learning: Forest project targets Rust stable >=1.89; features stabilized in 1.88 like let-chains are acceptable in this codebase.

Applied to files:

  • src/rpc/methods/chain.rs
📚 Learning: 2025-08-28T12:52:46.927Z
Learnt from: LesnyRumcajs
Repo: ChainSafe/forest PR: 6011
File: src/cli/main.rs:18-25
Timestamp: 2025-08-28T12:52:46.927Z
Learning: In Forest CLI (src/cli/main.rs), the early RPC network check before Cli::parse_from() does not block help/version commands because clap processes these internally before reaching the RPC call. LesnyRumcajs confirmed this implementation works correctly and that RPC call failures are acceptable in this context.

Applied to files:

  • src/rpc/methods/chain.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: tests
  • GitHub Check: Build Ubuntu
  • GitHub Check: Build forest binaries on Linux AMD64
  • GitHub Check: tests-release
  • GitHub Check: Build MacOS
  • GitHub Check: cargo-publish-dry-run
  • GitHub Check: All lint checks
🔇 Additional comments (5)
scripts/tests/calibnet_export_check.sh (1)

14-14: LGTM: Increased retry tolerance for CI stability.

Tripling the retry limit from 10 to 30 provides better tolerance for slower CI environments or startup delays, improving test reliability.

src/rpc/types/mod.rs (1)

571-571: LGTM: Necessary API change to fix Unix epoch display issue.

Making start_time optional correctly addresses the issue where a rebooted node with no prior export would show Unix epoch (genesis) time. Consumers should handle None appropriately.

src/ipld/util.rs (2)

29-29: LGTM: Consistent with API change.

Making the field optional allows Default initialization to set it to None, preventing display of Unix epoch time before the first export.


49-49: LGTM: Correct initialization.

Setting start_time to Some(Utc::now()) when export starts ensures the field is populated for active exports.

src/rpc/methods/chain.rs (1)

526-527: LGTM: Clean progress rounding to two decimal places.

The rounding formula correctly limits progress values to two decimal places (e.g., 0.31 instead of 0.31231231353452), improving output readability as per PR objectives.

@LesnyRumcajs LesnyRumcajs added this pull request to the merge queue Nov 3, 2025
Merged via the queue into main with commit efc9068 Nov 3, 2025
40 checks passed
@LesnyRumcajs LesnyRumcajs deleted the export-status-fixes branch November 3, 2025 12:17
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.

3 participants