Skip to content

fix(forest-cli): sync wait -w no longer leaves a stale Status: line - #7453

Open
EclesioMeloJunior wants to merge 8 commits into
mainfrom
eclesio/sync-wait
Open

fix(forest-cli): sync wait -w no longer leaves a stale Status: line#7453
EclesioMeloJunior wants to merge 8 commits into
mainfrom
eclesio/sync-wait

Conversation

@EclesioMeloJunior

@EclesioMeloJunior EclesioMeloJunior commented Aug 5, 2026

Copy link
Copy Markdown
Member

Summary of changes

print_sync_report_details was counting each println! as lines written and use it after to clear the terminal (by moving the cursor) and happens that a line wider than the terminal wraps onto two of them which causes the cursor to land one row too low and the clear started below the first line, leaving one Status: line on screen per refresh.

Changes introduced in this pull request:

  • src/cli/subcommands/sync_cmd.rs: count the terminal rows each line occupies instead of counting lines, so the cursor arithmetic matches what is on screen, fetch terminal width from dialoguer::console::Term (already a dependency).
  • Write the frame through a BufWriter so the cursor moves, the clear and the whole report reach the terminal in a single write.

Reference issue to close (if applicable)

Closes #7366

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

  • This pull request is based on an issue that a maintainer has accepted (see Before Opening a Pull Request).
  • 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

    • Fixed forest-cli sync wait -w leaving stale Status: lines when reports wrap across multiple terminal rows.
    • Improved terminal output clearing for wrapped sync reports, keeping watch-mode updates clean and accurate.
  • Documentation

    • Added a changelog entry describing the sync status display fix.

@EclesioMeloJunior
EclesioMeloJunior requested a review from a team as a code owner August 5, 2026 22:27
@EclesioMeloJunior
EclesioMeloJunior requested review from akaladarshi and hanabi1224 and removed request for a team August 5, 2026 22:27
@coderabbitai

coderabbitai Bot commented Aug 5, 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: Pro Plus

Run ID: d75c97f8-e073-4a0e-b898-0c7ed54cee96

📥 Commits

Reviewing files that changed from the base of the PR and between c8d9f39 and dfb1d4e.

📒 Files selected for processing (1)
  • src/cli/subcommands/sync_cmd.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • filecoin-project/lotus (manual)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/cli/subcommands/sync_cmd.rs

Walkthrough

The sync command now buffers terminal output, counts wrapped rows, and clears prior output by row count. Watch, one-time status, and initialization paths use explicit terminal writes and flushes. A changelog entry records the fix.

Changes

Sync terminal rendering

Layer / File(s) Summary
Terminal-row rendering
src/cli/subcommands/sync_cmd.rs
The report renderer writes through generic writers, measures terminal width, counts wrapped rows, formats fork details inline, and clears previous output by rendered row count.
Sync command integration
src/cli/subcommands/sync_cmd.rs, CHANGELOG.md
Watch, one-time status, and initialization paths use buffered terminal output, explicit flushes, and terminal line clearing. The changelog records the stale-status-line fix.

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

Suggested reviewers: akaladarshi, hanabi1224

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the CLI command and the stale Status line issue addressed by the changes.
Linked Issues check ✅ Passed The implementation directly addresses issue #7366 by preventing stale Status lines during sync wait refreshes, including wrapped and resized terminals.
Out of Scope Changes check ✅ Passed The code and changelog changes are directly related to fixing stale sync wait output described in issue #7366.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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 eclesio/sync-wait
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch eclesio/sync-wait

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.

@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: 1

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

63-63: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add context to direct output failures.

The new clear, completion write, and flush operations propagate bare I/O errors. Add operation-specific .context(...) calls so a terminal write failure identifies the failed sync-status action.

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

Also applies to: 69-74, 99-99

🤖 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/cli/subcommands/sync_cmd.rs` at line 63, Add operation-specific anyhow
context to the direct terminal I/O operations in the sync command:
clear_previous_lines, the completion write, and stdout.flush. Update the
surrounding operations at the referenced locations to call .context(...) before
propagating errors, with messages identifying the failed sync-status action.

Source: Coding guidelines

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

Inline comments:
In `@src/cli/subcommands/sync_cmd.rs`:
- Around line 63-67: Update the sync refresh flow around clear_previous_lines
and print_sync_report_details to recalculate the previous report’s row count
using the current terminal width before clearing it, rather than reusing
rows_printed_last_iteration from the old width. Preserve correct cursor movement
across terminal resizes and add a regression test covering a width change
between refreshes.

---

Nitpick comments:
In `@src/cli/subcommands/sync_cmd.rs`:
- Line 63: Add operation-specific anyhow context to the direct terminal I/O
operations in the sync command: clear_previous_lines, the completion write, and
stdout.flush. Update the surrounding operations at the referenced locations to
call .context(...) before propagating errors, with messages identifying the
failed sync-status action.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 27b34606-5d35-4e44-826f-7b8437199b0f

📥 Commits

Reviewing files that changed from the base of the PR and between a188092 and 9053a98.

📒 Files selected for processing (2)
  • CHANGELOG.md
  • src/cli/subcommands/sync_cmd.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • filecoin-project/lotus (manual)

Comment thread src/cli/subcommands/sync_cmd.rs Outdated
@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 50 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.13%. Comparing base (c80db66) to head (98a10f2).
✅ All tests successful. No failed tests found.

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

... and 5 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c80db66...98a10f2. 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.

/// [`clear_previous_lines`] moves the cursor by rows. Counting `writeln!` calls
/// instead leaves the topmost row of each frame behind on narrow terminals.
/// See <https://github.com/ChainSafe/forest/issues/7366>.
fn print_sync_report_details(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

High level question, do we need to do this line arithmetic dance ourselves? Do we have some crates in the tree that'd already do it for us?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

the one we have on the tree is dialoguer however it does not have methods that perform the line calcs and move the cursor/clean up to a new block print.

There is one called ratatui that is a whole TUI crate but IMO it will be too much to only display the status report, having that calc by done by ourselves seems ok (get the printed string and divide by the terminal width to get the amount of terminal rows used)

One thing that we could improve is the clean part, we were using a very verbose cursor move approach:

 write!(
            out,
            "\r{}{}",
            anes::MoveCursorUp(rows as u16),
            anes::ClearBuffer::Below,
        )?;

that can be written just as:

term.clear_last_lines(rows)?;

@LesnyRumcajs LesnyRumcajs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@LesnyRumcajs LesnyRumcajs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🐰 comment might be valid, I did some resizing while the sync wait -w was running and ended up with

❯ forest-cli sync wait -w
Status: Syncing (3861 epochs behind)
Node Head: Epoch 3954812 ([bafy2bzacebmet6slu6aoznsmvqdxqnxbbvt32vmiykg
Status: Syncing (3846 epochs behind)
Node Head: Epoch 3954827 ([bafy2bzaceasstg4lg6rfa7s3iwjrq7gbg57wmmomv4i5xpvb3dm22qqv63vb4, ...])
Network Head: Epoch 3958673
Last Update: 2026-08-07T07:09:48.671036974+00:00
Active Sync Tasks:
  - Fork Target: 3958673 ([bafy2bzacedzursoxvdbugyvcsdw42yxsrhvdfdcl7j4emd46pkmgkl3un3te4, ...]), Stage: Validating Tipsets, Syncing Range: [3954828..3958673] (3845 epochs)

This gets properly cleared when I resize back to the original width.

@EclesioMeloJunior

Copy link
Copy Markdown
Member Author

@LesnyRumcajs tested and confirmed that it was buggy when resizing, applied what 🐰 suggested

Store the previous report line widths or content. Recalculate its row count with the current width before clearing. Add a resize regression test.

and after the fix it is pretty solid against terminal resizes

Screen.Recording.2026-08-07.at.09.29.09.mov

@LesnyRumcajs

Copy link
Copy Markdown
Member

and after the fix it is pretty solid against terminal resizes

@EclesioMeloJunior It's not fixed.

❯ forest-cli sync wait -w
Status: Syncing (2654 epochs behind)
Status: Syncing (2650 epochs behind)
Status: Syncing (2631 epochs behind)
Status: Syncing (2616 epochs behind)
Status: Syncing (2597 epochs behind)
Status: Syncing (2587 epochs behind)
Status: Syncing (2564 epochs behind)
Node Head: Epoch 3957065 ([bafy2bzacea63eha42apg7isczdctbce6fwolsxu24d6apwyshnlpyvamarjag, ...])
Network Head: Epoch 3959629
Last Update: 2026-08-07T15:07:34.259477872+00:00
Active Sync Tasks:
  - Fork Target: 3959629 ([bafy2bzacedjfefn7pur7ugpra42tnftshglxmvpmyudyqaze2r3dnmgriwetc, ...]), Stage: Validating Tipsets, Syncing Range: [3957066..3959629] (2563 epochs)

I reproduce it by going from my terminal full screen to floating window (alt down/up on GNOME, alacritty, Fedora Linux 44 (Workstation Edition).

❯ forest-cli --version
forest-filecoin 0.35.0+git.dfb1d4e8a

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stale tasks in sync wait -w

2 participants