Skip to content

fix(app): soft-retry leave/background offline upload aborts (#4587) - #11166

Merged
kodjima33 merged 2 commits into
BasedHardware:mainfrom
aryanorastar:fix/4587-sync-leave-soft-retry
Aug 6, 2026
Merged

kodjima33 merged 2 commits into
BasedHardware:mainfrom
aryanorastar:fix/4587-sync-leave-soft-retry

Conversation

@aryanorastar

@aryanorastar aryanorastar commented Aug 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Leaving the Offline Sync page (or backgrounding the app) mid-upload no longer paints a hard Processing Failed / ClientSoftware caused connection abort red error (Offline sync errors if I leave offline sync page  #4587).
  • Root cause: UI promises leave-safe sync (syncProcessingBackgroundHint), but architecture is foreground-only. OS aborts in-flight multipart; batches increment localUploadFailures and correctly leave WALs as miss, then SyncProvider._performSync fail-closed with toError.
  • Shrink-only: on localUploadFailures > 0 → toIdle + cooldown wake (matches schema: retryable, re-arm recovery — not completed, not terminal error). Transient network catch (incl. connection abort / ClientSoftware) same soft path. No FGS/Workmanager.
  • Orthogonal to #11127 (bug: Background sync stalls on iOS when screen is off — 1000+ files queue #7221 screen-lock grace).

Test plan

  • flutter test test/providers/sync_provider_sync_wal_wake_test.dart test/unit/transient_network_error_test.dart → 7 passed
  • CI Dart Analyze / hermetic green
  • Not verified on-device: Android leave sync page mid-upload with pendant backlog (needs device). Hermetic tests cover the fail-closed → soft-retry contract.

Failure-Class: none

Fixes #4587

Review in cubic

…dware#4587)

Leaving the sync page or backgrounding mid-upload aborts multipart sockets
(ClientSoftware connection abort). Those batches already leave WALs as miss;
stop painting SyncStatus.error and re-arm coordinator recovery instead.

Co-authored-by: Cursor <[email protected]>
@aryanorastar
aryanorastar requested a review from mdmohsin7 as a code owner August 6, 2026 04:07
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 4 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread app/lib/providers/sync_provider.dart Resolved
Comment thread app/lib/backend/http/shared.dart Resolved
Comment thread app/lib/providers/sync_provider.dart Resolved
Distinguish permanent local upload refusals from transient leave/background
aborts so 400/413 still surface SyncStatus.error. Match only the full
"software caused connection abort" phrase. Do not double-wake cooldown on
coordinator drains (rethrowOnError) or after soft-retry syncWal.

Co-authored-by: Cursor <[email protected]>
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Addressed all four cubic findings on the new tip:

P1 — no double cooldown wake: local-failure / transient soft paths wake only when !rethrowOnError (direct/manual). Coordinator drains keep rethrowOnError: true and rely on _runPass → _scheduleRetry. syncWal post-success wake now requires zero failures so soft-retry does not emit a second wake.

P2 — ClientSoftware token: isTransientNetworkError matches only the full phrase software caused connection abort (case-insensitive). Bare ClientSoftware no longer counts as transient.

P2 — permanent refusals: batch catch now tracks localUploadPermanentFailures / localUploadPermanentError. Soft toIdle only when failures are transient; permanent 400/413 still toError.

P3 — wake assertion: regression test expects exactly [cooldownElapsed] and WalStatus.miss; added permanent-failure case expecting error + zero wakes.

flutter test on the touched suites → 9 passed.

@Git-on-my-level Git-on-my-level added positive-signal Automation verified a genuine fix/quality contribution flutter flutter work labels Aug 6, 2026
@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @aryanorastar — solid fix for #4587. The approach is well-scoped and the reasoning is sound:

  • Correctly distinguishes transient leave/background multipart aborts from permanent server refusals (400/413) via the new localUploadPermanentFailures/localUploadPermanentError fields. Soft-retry (toIdle + cooldown wake) applies only to transient failures; permanent refusals still surface SyncStatus.error.
  • The software caused connection abort matching (case-insensitive, full-phrase only) avoids over-classifying bare ClientSoftware tokens, which was the right tightening after cubic's review.
  • No-double-wake guard (!rethrowOnError) correctly prevents the coordinator drain path from double-poking cooldown.
  • Tests cover both the transient soft-retry contract (miss + exactly one cooldown wake, no error) and the permanent-failure error path, plus a dedicated unit suite for the network-error classifier.

A couple of things worth a human maintainer's eye before merge:

  1. The lower variable in isTransientNetworkError is computed but only the abort-phrase branch uses it; the classic connectivity phrases still match against the original-cased text. That's intentional for the existing token list but worth confirming that none of those substrings depend on case (e.g. http.ClientException messages from the http package are typically already mixed-case). Not blocking.
  2. This shifts localUploadFailures from fail-closed (toError) to fail-open-soft-retry. That's the intended fix, but it's a behavior change in the user-visible sync status surface — worth a quick on-device sanity check that a genuine persistent network failure still eventually surfaces (the PR notes on-device verification is still pending).

No security, privacy, or dependency concerns. Checks are green. Leaving a positive signal — requesting a maintainer's final product/UX judgment before merge since the on-device confirmation is still outstanding.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@mdmohsin7 all required checks are green on the current head (fa7750c), and @Git-on-my-level left a positive signal after the cubic follow-up hardening.\n\nThis is now only waiting on code-owner approval.\n\nCould you please take a quick review pass and approve if it looks good?

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Leave/background mid-upload now soft-retries instead of painting a terminal Processing Failed; 7 passing tests.

@kodjima33
kodjima33 merged commit bea099d into BasedHardware:main Aug 6, 2026
33 of 34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flutter flutter work positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Offline sync errors if I leave offline sync page

3 participants