Skip to content

fix(store): repair truncated CAS entries#357

Merged
jdx merged 1 commit intomainfrom
codex/repair-truncated-cas
Apr 28, 2026
Merged

fix(store): repair truncated CAS entries#357
jdx merged 1 commit intomainfrom
codex/repair-truncated-cas

Conversation

@jdx
Copy link
Copy Markdown
Contributor

@jdx jdx commented Apr 28, 2026

Summary

  • Verify an existing content-addressed file has the expected byte length when importing bytes into the store.
  • Remove and rewrite stale truncated CAS files before returning store metadata.
  • Add a regression test that seeds an empty CAS file for a package manifest-shaped payload and confirms import repairs it.

Why

A discussion report showed a valid npm tarball failing package validation with an empty package.json parse error. The upstream tarball and integrity for @babel/helper-string-parser@7.27.1 are valid, which points to reuse of a stale zero-byte or truncated CAS file during import.

Validation

  • cargo fmt --check
  • cargo test -p aube-store test_import_bytes_repairs_truncated_existing_cas_entry
  • cargo test -p aube-store
  • cargo clippy -p aube-store --all-targets -- -D warnings

Note

Medium Risk
Touches CAS import and cache-staleness detection paths; incorrect size checks or rewrite logic could cause unnecessary rewrites or new I/O errors during installs, but changes are localized and covered by a regression test.

Overview
Prevents reuse of truncated/zero-byte CAS files by verifying on-disk byte length against the expected StoredFile.size and treating mismatches as stale.

import_bytes now rechecks the stored file length after creation, and if it’s wrong it deletes and rewrites the CAS entry (failing with a detailed I/O error if the second attempt is still wrong). A new regression test seeds an empty CAS file and asserts that a subsequent import repairs it.

Reviewed by Cursor Bugbot for commit 206edfc. Bugbot is set up for automated code reviews on this repo. Configure here.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 28, 2026

Greptile Summary

This PR fixes CAS corruption reuse by validating on-disk file length against StoredFile.size after write, removing and retrying once if there's a mismatch, and returning a descriptive error if the retry also fails. The stored_file_matches_metadata refactor into cas_file_matches_len is a clean extraction with equivalent semantics, and the regression test covers the motivating bug directly.

Confidence Score: 5/5

Safe to merge — small, targeted fix with a regression test and no logic issues found.

No P0 or P1 issues found. The length-check-after-write, remove-and-retry, and fallback error path are all correct. The stored_file_matches_metadata refactor is semantically equivalent to the original. The regression test directly exercises the truncated-entry repair path.

No files require special attention.

Important Files Changed

Filename Overview
crates/aube-store/src/lib.rs Adds CAS length validation after write, remove-and-retry for truncated entries, refactors stored_file_matches_metadata, and adds a regression test — logic is correct and well-contained.

Reviews (2): Last reviewed commit: "fix(store): repair truncated CAS entries" | Re-trigger Greptile

Comment thread crates/aube-store/src/lib.rs
@jdx jdx force-pushed the codex/repair-truncated-cas branch from 9f29a96 to 206edfc Compare April 28, 2026 12:46
@jdx jdx merged commit 1ac4869 into main Apr 28, 2026
17 checks passed
@jdx jdx deleted the codex/repair-truncated-cas branch April 28, 2026 13:23
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