Skip to content

fix(import): calibrate the cost estimate so it stays an upper bound - #33

Merged
PastaPastaPasta merged 1 commit into
masterfrom
fix/import-estimate-calibration
Sep 26, 2026
Merged

PastaPastaPasta merged 1 commit into
masterfrom
fix/import-estimate-calibration

Conversation

@PastaPastaPasta

Copy link
Copy Markdown
Owner

Summary

This PR recalibrates forge-import's cost estimate so it is an upper bound again. --max-spend and the confirmation prompt both rely on that.

The Mirror Action's first live run (#31, run 36272329428) paid 0.0781 DASH against a 0.0649 estimate, so the estimate was 20% under.

Cause. I traced every write's estimate against its measured balance drop, using RUST_LOG=forge_import::cost=debug (added here) and an identity nothing else was using:

Kind Old overhead charged Measured overhead beyond bytes Old est/paid
issue / PR 45M credits 58–92M (mean 70–81M) 0.63–0.79 (under)
git documents (chunks, manifests, refs) 55M × a guessed count ~62M × the helper's count 0.93–0.97 (under)
comment 45M 40–55M (mean 43–53M) 0.94–1.07
event 45M 34–50M 0.91 (over)
review 45M 18–113M (mean 21–45M) 0.75–1.0 (over)
label 45M 27–68M (mean 28–36M) 0.67–0.83 (over)

On a clean run the old figures balanced out to roughly 1.0 over the whole import, so they were not an upper bound. The CI run's larger gap also included another writer on the shared OWNER identity: its log shows nonce collisions ("another write by this identity took the nonce"), so its balance drop was not only the import's.

Fix.

  • CollabDoc gives each document kind its own index overhead: issue/PR and release 90M, comment 52M, review and event 45M, label 35M.
  • Git documents are priced at 68M times the document count the helper reports (its platform event: chunks, manifests and ref updates, including the browse index's chunks). Before, the count was guessed from pack bytes and missed the index chunks.
  • forge_import::cost debug logs each write's estimate and measured cost, so this can be recalibrated.

Regression test. budget::tests::estimates_cover_a_recorded_run holds the 35 recorded writes of a clean dash-faucet import: each collab write's kind, bytes and measured cost, and each push's helper price, document count and measured cost. It requires the estimate to be 0–10% over what was paid, for the whole run and for the collab and git parts separately.

Verification

  • A fresh traced import of PastaPastaPasta/dash-faucet on moutai with the calibrated build estimated 0.068004 DASH and measured a 0.062419 DASH balance drop: 9.4% over (git part 1.5% over, after the final 66M → 68M bump).
  • Earlier runs with the old figures: dash-faucet clean runs came out 0.99–1.00 (not an upper bound), backports-validation-script 1.09.
  • cargo fmt --check, cargo clippy --workspace --all-targets -D warnings and cargo test --workspace pass.

Gaps

  • Releases: they weren't in the recorded repos, so they are priced as the largest kind (90M).
  • Devnet dependence: the figures come from devnet moutai (protocol 14). Mainnet fees follow the same formula, but should be re-checked with the debug trace once mainnet is live.

🤖 Generated with Claude Code

The Mirror Action's first run paid 0.0781 DASH against a 0.0649 estimate. Per-write traces from clean imports (an identity nothing else was using) show the underestimate was in the index overhead of issues and PRs (measured 58-92M credits, charged 45M) and of git documents (55M charged for about 60-65M). Labels and reviews were over-charged. The CI run's extra gap came from another writer on the shared OWNER identity, visible as nonce collisions in its log.

Collab documents now carry a per-kind overhead (issue/PR and release 90M, comment 52M, review and event 45M, label 35M). Git documents use 68M times the document count the helper reports (chunks, manifests and ref updates, including the browse index's chunks). A fresh traced import estimates 9.4% over its balance drop, the git part 1.5% over.

RUST_LOG=forge_import::cost=debug logs each write's estimate against its measured balance drop, for recalibration. A regression test checks the estimate against the recorded run: 0-10% over in total, and for the collab and git parts separately.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 26, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 50 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

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

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 46c614e9-11ba-49d3-b9d6-a3b9ebab1435

📥 Commits

Reviewing files that changed from the base of the PR and between a82b91d and 71ed725.

📒 Files selected for processing (4)
  • crates/forge-import/src/budget.rs
  • crates/forge-import/src/gitsync.rs
  • crates/forge-import/src/importer.rs
  • crates/forge-import/src/sink.rs

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.

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.

1 participant