Skip to content

Feat/improve space validations#406

Open
egalvis27 wants to merge 3 commits into
mainfrom
feat/improve-space-validations
Open

Feat/improve space validations#406
egalvis27 wants to merge 3 commits into
mainfrom
feat/improve-space-validations

Conversation

@egalvis27

Copy link
Copy Markdown

What is Changed / Added


  • Unified drive space validation so backups and regular drive uploads rely on the same check before uploading data.
  • Updated backup space validation to reserve the actual number of bytes that must be uploaded, instead of using the net size delta between local and remote files.
  • Added upload preflight validation for temporal file uploads to fail early when the account does not have enough available drive space.
  • Updated the virtual drive release flow to preserve the temporal file when the upload is rejected due to insufficient space, instead of deleting the local content.
  • Hardened the shared space validator to reject invalid values such as negative or non-finite requested sizes.
  • Added focused test coverage for:
    • shared space validation edge cases
    • insufficient-space preflight during temporal file uploads
    • release behavior when uploads are rejected for lack of space

Why

  • Backups and normal uploads consume the same remote storage quota, so they should be validated with the same rule and produce consistent behavior.
  • The previous backup validation could allow false positives by checking only the net storage delta. In practice, the flow uploads full file contents first, so the real peak space requirement is the amount being uploaded, not the final net result.
  • Failing before opening streams and starting uploads avoids unnecessary work, retries, and late quota errors.
  • Preserving the temporal file on insufficient-space errors prevents local data loss and makes retry behavior safer for the user.
  • Centralizing this logic reduces drift between upload paths and makes future storage validation changes easier to maintain.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Warning

Review limit reached

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

Next review available in: 1 minute

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1c58e89d-f068-4738-9423-6741a3e2b1ba

📥 Commits

Reviewing files that changed from the base of the PR and between e6b1171 and 7b8a956.

📒 Files selected for processing (8)
  • src/apps/backups/BackupService.ts
  • src/backend/features/usage/validate-space.test.ts
  • src/backend/features/usage/validate-space.ts
  • src/backend/features/virtual-drive/services/operations/release.service.test.ts
  • src/backend/features/virtual-drive/services/operations/release.service.ts
  • src/context/storage/TemporalFiles/application/upload/TemporalFileUploader.test.ts
  • src/context/storage/TemporalFiles/application/upload/TemporalFileUploader.ts
  • vitest.setup.main.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/improve-space-validations

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.

Comment on lines -144 to +152
const bytesToUpdate = Array.from(filesDiff.modified.entries()).reduce((acc, [local, remote]) => {
acc += local.size - remote.size;
const bytesToUpdate = Array.from(filesDiff.modified.entries()).reduce((acc, [local]) => {
acc += local.size;

return acc;
}, 0);

const total = bytesToUpdate + bytesToUpload;
const bytesToReserve = bytesToUpdate + bytesToUpload;

const validateSpaceResult = await UsageModule.validateSpace(total);
const validateSpaceResult = await UsageModule.validateSpace(bytesToReserve);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

We changed this check to be simpler and safer:

Before, backup could pass the space check but still fail later during upload.
Now, we validate space using the real bytes we are going to upload (added + modified).

try {
if (!Number.isFinite(desiredSpaceToUse) || desiredSpaceToUse < 0) {
return { error: new Error('Desired space to use must be a finite non-negative number') };
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This guard rejects invalid space requests early.
desiredSpaceToUse must be a finite, non-negative number; otherwise the check could return misleading results (for example with NaN, Infinity, or negative values).
Failing fast here makes space validation safer and easier to reason about.

@sonarqubecloud

sonarqubecloud Bot commented Jul 8, 2026

Copy link
Copy Markdown

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