Repository navigation
fix(import): restore large gzip backups within available storage - #1032
devnoname120 wants to merge 3 commits into
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Reviewer's GuideAPIExpose path-specific free-space queries and storage-aware gzip failures so callers can distinguish exhausted capacity from invalid backup data.
Uses of the APIApply the shared storage-operation gate to imports, exports, backups, and compaction so capacity checks remain valid through the disk-heavy work and cleanup.
Implement storage-budgeted gzip extraction, preserve storage errors during backup detection and cleanup, and report per-file storage failures without falling through to CSV routing.
TestsCover storage-budget calculations, error propagation and cleanup, queue ordering and deferral, backup serialization, and large-gzip restore behavior.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Ok I found a workaround: extract the |
Linked issuesChecked at commit 0291f35 #1031 Nothing was imported – Unpacks to more than 2 GB, which is not something we can import. · 1 of 2 met · 1 to check by hand
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="lib/import/import_container.dart" line_range="409" />
<code_context>
final destPath = p.join(dir.path, base);
+ final freeBytes = await freeDiskBytes(path: dir.path);
+ final maxBytes = gzipInflateByteLimit(freeBytes);
+ if (maxBytes == 0) throw _gzipNeedsSpace(path);
final sink = File(destPath).openWrite();
var written = 0;
</code_context>
<issue_to_address>
**Storage errors become CSV errors**
When a gzipped OpenStrap backup is refused or fails because of its extraction budget and is processed through NOOP resolution or import routing, `resolveNoopDatabase` catches the storage exception and returns `null`, so backup detection or `NoopImporter` treats the file as unrecognized and routes it to CSV import; that hides the storage guidance and can decompress the file a second time before failing.
Preserve and propagate storage-related import exceptions through `resolveNoopDatabase` and the import-routing paths.
Also at `lib/import/import_container.dart:432`.
</issue_to_address>
### Comment 2
<location path="lib/import/import_container.dart" line_range="319" />
<code_context>
- final v = await _channel.invokeMethod<Object?>(
- 'freeBytes',
- {'path': await getDatabasesPath()},
- );
+ final v = await _channel.invokeMethod<Object?>('freeBytes', {
+ 'path': path ?? await getDatabasesPath(),
</code_context>
<issue_to_address>
**Concurrent jobs overcommit storage**
When two large gzip restores, or a gzip restore and VACUUM, run concurrently after checking available space, each `inflateGzip` call computes its limit from the same unreserved free-space snapshot, so concurrent restores can each consume half of that space; together they exhaust the headroom and a restore or concurrent compaction fails for lack of storage.
Coordinate disk-space reservations across extraction and compaction jobs, or serialize those operations so their individual budgets cannot consume the same free space.
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: lib/import/import_container.dart:409, lib/import/import_container.dart:319
|
@coderabbitai Updated the PR description to address the inconclusive Out of Scope Changes check. The new Why storage serialization is part of this fix section links the concurrent-budget review finding and explains why each storage-operation call site belongs to the gzip fix: overlapping restores or VACUUM could consume the same measured free space and the headroom reserved for merge/journaling. It also explains the full-job lifetime and derive-lock ordering. The verification section now records the 335 passing targeted tests and the separate real 5.5 GiB probe. The actual reporter-backup/iPhone validation limitation remains explicit. Please re-evaluate the scope check against the updated description; the code head is unchanged at c57664a. |
|
Tip For best results, initiate chat on the files or code changes. Analysis chain
My assessment: the Out of Scope Changes check passes. The description now explains why the queue and its call sites support the gzip storage budget: overlapping storage jobs could consume the same measured free space and the headroom reserved for the merge. It also explains the job lifetime and derive-lock ordering. The queue is not an OS-level reservation, so ENOSPC handling remains necessary. The description reports 335 passing targeted tests and a separate 5.5 GiB extraction probe. I did not rerun them. The storage bridge was mocked, and the probe did not test a multi-gigabyte SQLite merge. As stated in the description, confirm the reporter’s backup on an iPhone with sufficient free storage before merge. This is a reassessment in this reply; it does not update the saved check result.
You are interacting with an AI system. |
|
The current-head Actions runs have not executed any jobs: test and PR Agent both report Could a maintainer review and approve those workflow runs so the actual CI results can be evaluated? The author account has no upstream write access. Local verification (335 targeted tests, a separate real 5.5 GiB extraction probe, and clean analysis) is recorded in the PR description; it is not a substitute for the pending upstream CI. |
Problem
Fixes #1031.
inflateGziprejects every stream once its output exceeds 2 GiB, before the database merge can begin. That fixed storage-safety guard also rejects the roughly 5.5 GB backup reported in the issue, even when the device has enough free space. The error does not establish that the backup is corrupt.Change
openstrap/storagebridge.freeDiskBytesnow accepts an optional path; database compaction keeps its existing default.max(0, min(freeBytes ~/ 2, freeBytes - 512 MiB)). This leaves at least half the initial available space for the subsequent merge/journal and at least 512 MiB of headroom. It is a conservative extraction budget, not a guarantee that the later merge will fit.The backpressured streaming pipeline and CRC32/ISIZE checks are unchanged. In particular, gzip ISIZE remains checked modulo 2^32, so valid output above 4 GiB is accepted. No dependency, database schema, or analytics-version changes. The separate ZIP extraction limits are intentionally unchanged.
Why storage serialization is part of this fix
This addresses the concurrent-budget review finding, not an unrelated storage refactor. The extraction limit is calculated from a free-space snapshot. Two gzip restores, or a restore and VACUUM, could otherwise budget the same space and spend the headroom that this fix leaves for the merge and journal.
lib/data/storage_operation.dartprovides a shared main-isolate queue instead of estimating and tracking reservations.LocalDb.importFromDbFile,NoopImporter.importFile, andWhoopImporter.importFileshold it through extraction, consumption/merge, and temporary-file cleanup; releasing it immediately after inflation would expose the merge's headroom again. Own-backup inspection uses it too because detecting a renamed gzip can require extraction.LocalDb.exportCopy,vacuumAndCheckpoint,vacuumIfBloated, andDerivationEngine.compactStorageparticipate because their database rewrites can compete for the same space. Manual compaction queries capacity inside the queue and takes the storage gate before the derive latch. Automatic VACUUM, which already holds the derive latch, defers with the existing-1retry sentinel rather than deadlocking with an import waiting to derive.This coordinates these operations within the main isolate; it is not an OS-level reservation against external writers. Runtime ENOSPC handling remains necessary. Regression tests cover concurrent capacity queries, both extraction/compaction orderings, a real SQLite restore held after merge until cleanup, failed-job release, and automatic-VACUUM deferral.
Verification
Tested with the repository's CI toolchain: Flutter 3.41.6 / Dart 3.11.4, with the committed dependency lock enforced.
flutter test --no-pub --concurrency=1 --reporter expanded \ test/storage_operation_test.dart test/storage_operation_integration_test.dart \ test/gzip_storage_budget_test.dart test/import_container_test.dart \ test/import_routing_test.dart test/import_data_safety_test.dart \ test/import_partial_failure_test.dart test/import_bulk_restore_test.dart \ test/db_paged_import_export_test.dart test/auto_backup_test.dart \ test/noop_backup_import_test.dart test/compact_database_test.dart \ test/whoop_reimport_edits_test.dart test/whoop_import_timezone_test.dart \ test/welcome_import_report_hold_test.dart test/welcome_import_report_headline_test.dart \ test/backup_cleanup_preferences_test.dart test/backup_crypto_test.dart test/backup335 passed, with the optional large probe skipped. Coverage includes budget enforcement, storage-error propagation without CSV retries, mixed-selection/decrypted-file cleanup, queue ordering/reentrancy/error release, and real SQLite restore/compaction integration.
The separate large probe passed. It actually generates and extracts a 5.5 GiB (5,905,580,032-byte) synthetic gzip payload, validates wrapped ISIZE and endpoint contents, and exercises checksum verification. The same payload is refused and cleaned up under the unknown-capacity 2 GiB fallback. It is opt-in to avoid writing several GiB on every CI run.
Analysis clean; whitespace check clean. The sibling-pin guard passes with an existing warning that protocol's upstream main has advanced; neither pin nor the lockfile was changed.
Remaining validation
No physical iPhone or copy of the reporter's backup was available. The storage bridge is mocked in the automated tests; the existing iOS implementation and its registration were inspected. The multi-gigabyte probe tests extraction, not a multi-gigabyte SQLite row merge. Confirm the actual backup on iOS with sufficient free storage before merge.
Summary by Sourcery
Restore large gzip backups when device storage permits, and coordinate disk-intensive operations to preserve space for the database merge.
Bug Fixes:
Enhancements:
Tests:
Summary by CodeRabbit