Skip to content

Bind backup work to the view lifecycle - #148

Merged
hawkff merged 1 commit into
mainfrom
fix/010-backup-lifecycle
Jul 13, 2026
Merged

Bind backup work to the view lifecycle#148
hawkff merged 1 commit into
mainfrom
fix/010-backup-lifecycle

Conversation

@hawkff

@hawkff hawkff commented Jul 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • run export, share, and remote backup work in lifecycle-owned jobs
  • cancel in-flight HTTP calls with coroutine cancellation
  • keep pending document exports single-admission and format archives explicitly

Validation

  • Namespace CI run 29212528450 passed
  • local read-only review found no remaining lifecycle or cancellation issues
  • lifecycle interaction validation remains pending until a compatible device is available

Greptile Summary

This PR binds backup work to the fragment view lifecycle. The main changes are:

  • Lifecycle-owned jobs for export, share, and WebDAV backup.
  • Cancellable OkHttp calls for remote backup.
  • Explicit JSON and ZIP archive encoding.
  • Unit tests for archive encoding.

Confidence Score: 4/5

The local document export flow needs a fix before merging.

  • Export bytes are cleared when the view is destroyed.
  • The system document picker can return after that lifecycle event.
  • A valid picked URI can then fail to receive the generated backup data.

app/src/main/java/io/nekohasekai/sagernet/ui/BackupFragment.kt

Important Files Changed

Filename Overview
app/src/main/java/io/nekohasekai/sagernet/ui/BackupArchiveEncoding.kt Adds explicit JSON and ZIP backup archive encoding.
app/src/main/java/io/nekohasekai/sagernet/ui/BackupFragment.kt Moves backup actions into lifecycle-owned jobs, but the document export result can lose its pending bytes after view recreation.
app/src/test/java/io/nekohasekai/sagernet/ui/BackupArchiveEncodingTest.kt Adds focused tests for JSON, ZIP, UTF-8, empty content, and concurrent archive encoding.

Reviews (1): Last reviewed commit: "fix(backup): bind export work to lifecyc..." | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 41 seconds

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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2a8efc9f-ad4a-40d4-82a6-9b7f6ab8101e

📥 Commits

Reviewing files that changed from the base of the PR and between ff4269f and 8407bac.

📒 Files selected for processing (3)
  • app/src/main/java/io/nekohasekai/sagernet/ui/BackupArchiveEncoding.kt
  • app/src/main/java/io/nekohasekai/sagernet/ui/BackupFragment.kt
  • app/src/test/java/io/nekohasekai/sagernet/ui/BackupArchiveEncodingTest.kt

Comment @coderabbitai help to get the list of available commands.

isBackupInProgress = false
snackbar?.dismiss()
snackbar = null
pendingExportData = null

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Pending Export Lost On Recreate

When the user starts Export and the system document picker is open, a rotation or view recreation runs onDestroyView() and clears pendingExportData. The fragment-level ActivityResult callback can still receive the picked URI afterward, but it now sees no bytes to write and reports an export error instead of saving the backup.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

No change. View teardown intentionally cancels the export and clears its payload so archive data does not outlive the view lifecycle. A later picker result is handled as a normal failed export rather than written from stale state. Retaining bytes across recreation would require the saved-state design excluded from this change.

@hawkff

hawkff commented Jul 13, 2026

Copy link
Copy Markdown
Owner Author

Verified on Android: local export and share flows opened the expected system surfaces, cancellation completed without a crash, and existing app data remained intact.

@hawkff
hawkff merged commit c2a58c0 into main Jul 13, 2026
9 checks passed
@hawkff
hawkff deleted the fix/010-backup-lifecycle branch July 13, 2026 01:29
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