Skip to content

rebuild only when needed, demote noisy log - #1197

Open
rkuhn wants to merge 2 commits into
mainfrom
rk/fix-newtip
Open

rebuild only when needed, demote noisy log#1197
rkuhn wants to merge 2 commits into
mainfrom
rk/fix-newtip

Conversation

@rkuhn

@rkuhn rkuhn commented Aug 12, 2026

Copy link
Copy Markdown
Contributor
  • ledger DB directories were triggering rebuilds of amaru, which I don’t think is useful -- please correct me if wrong
  • peer snapshot download metadata was triggering rebuilds of amaru-node, which was incorrect (moved that file to $out_dir)
  • printing span close for every single gov prop at INFO level seems inappropriate to me, the aggregate count is still there and I’ve seen INFO log when a gov prop is opened

Skip-changelog


Stack created with GitHub Stacks CLIGive Feedback 💬

Summary by CodeRabbit

  • Developer Experience

    • Added automatic setup for sharing snapshot data across Git worktrees.
    • Improved hook installation for standard repositories and linked worktrees.
    • Snapshot downloads and cached data are reused more reliably, reducing unnecessary fetches and rebuilds.
    • Build processes now avoid rewriting unchanged generated files.
  • Tests

    • Stake-distribution and ledger tests now handle missing snapshots with warnings instead of build-time filtering or failures.
  • Documentation

    • Clarified peer snapshot setup, offline usage, caching, and rebuild behavior.
    • Updated guidance for refreshing generated stake-distribution test data.
  • Observability

    • Reduced verbosity for proposal-ratification logging while preserving important enactment information.

Signed-off-by: Roland Kuhn <rk@rkuhn.info>
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@rkuhn, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 31 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2d0286d7-096e-4d07-b4ad-ff11e1a51a24

📥 Commits

Reviewing files that changed from the base of the PR and between 9adcf67 and 924e526.

📒 Files selected for processing (1)
  • crates/amaru/tests/summary.rs

Walkthrough

Peer snapshot artifacts now use OUT_DIR, with staged-file fallbacks and content-aware writes. Worktree hooks link shared snapshots. Stake-distribution tests use fixture-driven generation and runtime snapshot checks. Proposal-ratification spans use debug level.

Changes

Peer snapshot build flow

Layer / File(s) Summary
OUT_DIR snapshot storage
crates/amaru-node/build/..., crates/amaru/build/build.rs
Snapshot downloads, commit metadata, cache checks, staged fallbacks, and build-output documentation now use OUT_DIR and content-aware writes.
Snapshot input contract
crates/amaru-node/config/peer-snapshots/README.md
Documentation describes staged inputs, cache reuse, failure conditions, and rebuild triggers.

Worktree snapshot tooling

Layer / File(s) Summary
Worktree snapshot linking
scripts/hooks/post-checkout, scripts/setup-worktree-snapshots.sh, .gitignore
The post-checkout hook links secondary worktree snapshots to the primary worktree and handles existing paths safely.
Linked-worktree hook installation
scripts/setup-hooks.sh
Hook installation now supports Git-linked worktrees and creates the resolved hooks directory.

Stake-distribution conformance tests

Layer / File(s) Summary
Fixture-driven test generation
crates/amaru/build/stake_distribution.rs, CHANGELOG.md
Build generation now watches fixture directories and creates active tests for all fixture epochs.
Runtime ledger snapshot handling
crates/amaru/tests/summary.rs, crates/amaru/tests/conformance/stake-distributions/README.md
Tests resolve ledger paths through a shared helper and soft-skip missing snapshots with warnings.

Build and observability hygiene

Layer / File(s) Summary
Ratification span levels
crates/amaru-ledger/src/governance/ratification.rs
Proposal-ratification spans use debug_span!; enactment spans remain at info level.

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

Sequence Diagram(s)

sequenceDiagram
  participant Cargo
  participant build_script
  participant OUT_DIR
  participant GitHub_API
  Cargo->>build_script: watch staged inputs
  build_script->>OUT_DIR: read cached snapshots
  build_script->>GitHub_API: fetch missing snapshots
  GitHub_API-->>build_script: return snapshot bytes and commit metadata
  build_script->>OUT_DIR: write resolved artifacts
  build_script-->>Cargo: provide generated build inputs
Loading

Possibly related PRs

Suggested reviewers: ktorz

Poem

Snapshots rest in OUT_DIR,
Worktree hooks link paths sure.
Fixtures drive each test anew,
Missing ledgers warn, then through.
Ratification whispers low.

🚥 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 summarizes the pull request's two main changes: reducing unnecessary rebuilds and lowering noisy log verbosity.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch rk/fix-newtip

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
crates/amaru-node/build/peer_snapshot.rs (1)

170-196: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Discard stale output bytes when the resolved SHA changes.

If sha_changed is true and download_snapshot fails, the previous file at dest remains. prepare_peer_snapshots then treats that file as present and emits the new CONFIGS_COMMIT, even though the embedded bytes came from the previous SHA.

Remove the previous output before the download attempt when the SHA changes. This lets the staged-file fallback replace a failed download. Otherwise, fail the build instead of embedding stale bytes.

Proposed fix
     for network in peer_snapshot_network_names() {
         let dest = out_dir_snapshot_path(out_dir, network);
+        if sha_changed && dest.is_file() {
+            fs::remove_file(&dest)
+                .with_context(|| format!("remove stale snapshot {}", dest.display()))?;
+        }
         if !sha_changed && dest.is_file() {
             continue;
         }
🤖 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 `@crates/amaru-node/build/peer_snapshot.rs` around lines 170 - 196, In
prepare_peer_snapshots, remove each existing dest output before attempting
download_snapshot whenever sha_changed is true. Preserve existing files when the
SHA is unchanged, and ensure a failed download cannot leave stale bytes to be
embedded; allow the existing staged-file fallback to replace the removed output
or propagate a build failure when no replacement is available.
🧹 Nitpick comments (1)
crates/amaru/build/stake_distribution.rs (1)

90-96: 🗄️ Data Integrity & Integration | 🔵 Trivial | 🏗️ Heavy lift

Make snapshot refreshes machine-checkable.

available_ledger_snapshot_epochs(&ledger_dir) still contributes to stake_distribution_test_cases_source, which writes OUT_DIR/stake_distribution_{network}_test_cases.rs. After the ledger rerun trigger is removed, importing a new snapshot does not refresh this file by itself. A missed fixture-touch or cargo clean -p amaru step can silently omit an epoch from conformance tests. If the snapshot import workflow does not enforce that step, add a watched snapshot manifest or a CI freshness check.

🤖 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 `@crates/amaru/build/stake_distribution.rs` around lines 90 - 96, Make snapshot
refreshes machine-checkable for stake_distribution_test_cases_source and its
generated OUT_DIR/stake_distribution_{network}_test_cases.rs: either watch a
snapshot manifest that changes on every import or add a CI freshness check that
regenerates the test-case list and fails when it differs. Ensure newly imported
ledger epochs cannot be silently omitted without detecting the stale generated
file.
🤖 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 `@scripts/setup-worktree-snapshots.sh`:
- Around line 21-22: Update the primary worktree extraction assigned to
main_root in the setup script to remove only the “worktree ” prefix from the
complete porcelain line, preserving spaces in the path; keep selecting the first
worktree entry and leave the subsequent path checks and linking behavior
unchanged.

---

Outside diff comments:
In `@crates/amaru-node/build/peer_snapshot.rs`:
- Around line 170-196: In prepare_peer_snapshots, remove each existing dest
output before attempting download_snapshot whenever sha_changed is true.
Preserve existing files when the SHA is unchanged, and ensure a failed download
cannot leave stale bytes to be embedded; allow the existing staged-file fallback
to replace the removed output or propagate a build failure when no replacement
is available.

---

Nitpick comments:
In `@crates/amaru/build/stake_distribution.rs`:
- Around line 90-96: Make snapshot refreshes machine-checkable for
stake_distribution_test_cases_source and its generated
OUT_DIR/stake_distribution_{network}_test_cases.rs: either watch a snapshot
manifest that changes on every import or add a CI freshness check that
regenerates the test-case list and fails when it differs. Ensure newly imported
ledger epochs cannot be silently omitted without detecting the stale generated
file.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5d78ac8f-ea54-4b78-a80e-83a3559d0c49

📥 Commits

Reviewing files that changed from the base of the PR and between 7e278ef and f6067f9.

📒 Files selected for processing (10)
  • .gitignore
  • crates/amaru-ledger/src/governance/ratification.rs
  • crates/amaru-node/build/build.rs
  • crates/amaru-node/build/peer_snapshot.rs
  • crates/amaru-node/config/peer-snapshots/README.md
  • crates/amaru/build/build.rs
  • crates/amaru/build/stake_distribution.rs
  • scripts/hooks/post-checkout
  • scripts/setup-hooks.sh
  • scripts/setup-worktree-snapshots.sh

Comment on lines +21 to +22
# First entry of `git worktree list` is always the primary worktree.
main_root="$(git worktree list --porcelain | awk '/^worktree / { print $2; exit }')"

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Preserve spaces in the primary worktree path.

Line 22 uses awk field $2, which truncates a worktree path that contains spaces. The script then tests and links the wrong src path. Remove only the worktree prefix from the complete line.

Proposed fix
- main_root="$(git worktree list --porcelain | awk '/^worktree / { print $2; exit }')"
+ main_root="$(git worktree list --porcelain | awk '/^worktree / { sub(/^worktree /, ""); print; exit }')"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# First entry of `git worktree list` is always the primary worktree.
main_root="$(git worktree list --porcelain | awk '/^worktree / { print $2; exit }')"
# First entry of `git worktree list` is always the primary worktree.
main_root="$(git worktree list --porcelain | awk '/^worktree / { sub(/^worktree /, ""); print; exit }')"
🤖 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 `@scripts/setup-worktree-snapshots.sh` around lines 21 - 22, Update the primary
worktree extraction assigned to main_root in the setup script to remove only the
“worktree ” prefix from the complete porcelain line, preserving spaces in the
path; keep selecting the first worktree entry and leave the subsequent path
checks and linking behavior unchanged.

@KtorZ

KtorZ commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

ledger DB directories were triggering rebuilds of amaru, which I don’t think is useful -- please correct me if wrong

It is useful; this is how we trigger the epoch boundary tests. In principle this only happens once: if the folders don't exists, they are created and then, the build is skipped.

Of course, it also happens if the content of the ledger.db changes, because that means new/different e2e snapshot tests are available.

@rkuhn rkuhn self-assigned this Aug 12, 2026
@rkuhn

rkuhn commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

@KtorZ thanks for the explanation! Could you be more specific about what exactly is required to make this useful? I’d like to avoid that amaru is always rebuilt even if nothing changed.

@rkuhn

rkuhn commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

Discussion notes:

  • need to generate test scenarios, should happen automatically
  • perhaps we can monitor the snapshots instead of the ledger DB, then have the test routines dynamically decide whether to test or just pass

@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)
crates/amaru/tests/summary.rs (1)

89-100: 🗄️ Data Integrity & Integration | 🔵 Trivial

Verify that CI exposes successful soft-skips.

When the snapshot is missing, this function returns Ok(()), so libtest reports the comparison as passed. For a successful test, libtest captures the eprintln! warning unless the run uses --nocapture. If CI uses the default command, the suite can pass without comparing any snapshot. Ensure CI enables --nocapture or records and checks the soft-skip count.

This follows from the Ok(()) branch in crates/amaru/tests/summary.rs and the documented test command in crates/amaru/tests/conformance/stake-distributions/README.md.

🤖 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 `@crates/amaru/tests/summary.rs` around lines 89 - 100, Update the CI test
invocation for the stake-distribution comparison to use --nocapture, or
otherwise record and validate the soft-skip count, so the missing-snapshot
warning from the Ok(()) branch in the summary test is visible and actionable.
Use the documented command in the stake-distributions README as the reference
and preserve normal successful comparisons.
🤖 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 `@crates/amaru/tests/conformance/stake-distributions/README.md`:
- Around line 37-41: Update the command heading in the stake-distributions
README to remove the claim that the commands target a given network. State that
cargo test lists or runs all generated comparison tests, unless the commands are
extended with a supported network filter.

---

Nitpick comments:
In `@crates/amaru/tests/summary.rs`:
- Around line 89-100: Update the CI test invocation for the stake-distribution
comparison to use --nocapture, or otherwise record and validate the soft-skip
count, so the missing-snapshot warning from the Ok(()) branch in the summary
test is visible and actionable. Use the documented command in the
stake-distributions README as the reference and preserve normal successful
comparisons.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cf8531ec-76c0-4b23-9841-0d1d055527af

📥 Commits

Reviewing files that changed from the base of the PR and between f6067f9 and 9adcf67.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • crates/amaru/build/stake_distribution.rs
  • crates/amaru/tests/conformance/stake-distributions/README.md
  • crates/amaru/tests/summary.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/amaru/build/stake_distribution.rs

Comment on lines 37 to +41
To list or run the generated comparison tests for a given network:

```console
AMARU_NETWORK=preview cargo test -p amaru --test summary -- --list
AMARU_NETWORK=preview cargo test -p amaru --test summary
cargo test -p amaru --test summary -- --list
cargo test -p amaru --test summary --nocapture

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Correct the network scope in the command heading.

The commands are network-independent, but the heading says “for a given network”. Both commands run the summary test binary without a network selector. State that they list or run all generated comparison tests, or document a supported network filter.

Suggested wording
- To list or run the generated comparison tests for a given network:
+ To list or run all generated comparison tests:

This follows from the fixture scan over tests/conformance/stake-distributions/<network>/ and the commands shown in this section.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
To list or run the generated comparison tests for a given network:
```console
AMARU_NETWORK=preview cargo test -p amaru --test summary -- --list
AMARU_NETWORK=preview cargo test -p amaru --test summary
cargo test -p amaru --test summary -- --list
cargo test -p amaru --test summary --nocapture
To list or run all generated comparison tests:
🤖 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 `@crates/amaru/tests/conformance/stake-distributions/README.md` around lines 37
- 41, Update the command heading in the stake-distributions README to remove the
claim that the commands target a given network. State that cargo test lists or
runs all generated comparison tests, unless the commands are extended with a
supported network filter.

amaru

Signed-off-by: Roland Kuhn <rk@rkuhn.info>
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