Skip to content

fix(data): return flagged estimate for partially-stored files#115

Merged
jacderida merged 1 commit into
rc-2026.6.2from
nic/fix-estimate-partial-stored
Jun 12, 2026
Merged

fix(data): return flagged estimate for partially-stored files#115
jacderida merged 1 commit into
rc-2026.6.2from
nic/fix-estimate-partial-stored

Conversation

@Nic-dorman

Copy link
Copy Markdown
Contributor

Summary

Client::estimate_upload_cost returned Err(CostEstimationInconclusive) for a benign, common case — a file whose leading chunks are already stored but whose tail is new — leaving display consumers (the desktop GUI) with no estimate to show. This fixes that in two parts, following the discussion on #114.

Changes

1. Distributed sampling. Sample chunk addresses spread evenly across the whole file (distributed_sample_indices) instead of the first ESTIMATE_SAMPLE_CAP. A shared leading prefix (compressed archives, similar headers) no longer biases the probe toward already-stored chunks. When the file has ≤ cap chunks every chunk is sampled, preserving the exact "whole file sampled" detection. Covered by unit tests.

2. Flagged estimate instead of an error. The residual case — every sampled chunk already stored, but the tail unsampled — now returns Ok with storage_cost_atto: "0" rather than erroring. A new CostEstimateConfidence enum tells the three outcomes apart:

Variant Meaning storage_cost_atto
PricedSample Live quote extrapolated (normal) real estimate
VerifiedAllAlreadyStored Whole file sampled, all stored "0" (exactly free)
AllSamplesAlreadyStoredIncomplete All samples stored, tail unsampled "0" (best-effort; payment reconciles)

The CLI renders the confidence ("likely already stored — free (confirmed at payment)") instead of catching the error.

API compatibility

  • UploadCostEstimate is now #[non_exhaustive] (matching FileUploadResult) so future field additions aren't breaking. This addition is the one-time break: downstream code that constructs or exhaustively destructures the struct must update.
  • The new confidence field is #[serde(default)], so existing JSON deserializes unchanged (defaults to PricedSample).
  • Error::CostEstimationInconclusive is retained (no longer produced) to avoid removing a public variant.

Tests

  • Unit: distributed_sample_indices spread / coverage / range invariants.
  • E2E (e2e_cost_estimate.rs): a fully-stored >5-chunk file re-estimates to Ok + AllSamplesAlreadyStoredIncomplete (the regression); a fully-stored small file re-estimates to VerifiedAllAlreadyStored.

cargo clippy --all-targets --all-features -- -D warnings and cargo fmt are clean; unit tests pass. (E2E tests require a testnet to run.)

Closes #114

🤖 Generated with Claude Code

estimate_upload_cost sampled only the first ESTIMATE_SAMPLE_CAP chunk
addresses, so a file whose leading chunks were already stored but whose
tail was new returned CostEstimationInconclusive even though a real
estimate was obtainable. Display consumers (the GUI) were left with no
value to show.

- Distributed sampling: sample addresses spread evenly across the whole
  chunk list instead of the first N (distributed_sample_indices, unit-
  tested). Files with <= cap chunks still sample every chunk, preserving
  exact "whole file sampled" detection.
- The residual all-stored-but-incomplete case returns Ok with
  storage_cost_atto "0" instead of erroring, tagged with a new
  CostEstimateConfidence enum (PricedSample / VerifiedAllAlreadyStored /
  AllSamplesAlreadyStoredIncomplete). The CLI renders the confidence.

UploadCostEstimate is now #[non_exhaustive] with a #[serde(default)]
confidence field. Error::CostEstimationInconclusive is retained (no
longer produced) to avoid removing a public variant.

BREAKING CHANGE: UploadCostEstimate is #[non_exhaustive] and gained a
`confidence` field; downstream code constructing or exhaustively
destructuring it must update.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jacderida jacderida changed the base branch from main to rc-2026.6.2 June 12, 2026 16:04
@jacderida jacderida merged commit 8ba3688 into rc-2026.6.2 Jun 12, 2026
12 checks passed
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.

estimate_upload_cost errors (CostEstimationInconclusive) for partially-stored files instead of returning an estimate

2 participants