Skip to content

fix(main): close offline mode gaps across restore, updater, telemetry, and fetches - #1317

Merged
khaira777 merged 5 commits into
mainfrom
fm/ship-pr-1306-offline-mode-fixes
Oct 23, 2026
Merged

khaira777 merged 5 commits into
mainfrom
fm/ship-pr-1306-offline-mode-fixes

Conversation

@khaira777

@khaira777 khaira777 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1309

Intent

Resolve all 6 Greptile second-review findings from PR #1306 (Issue #1309) and PR #1317 follow-up review threads

What Changed

  • Preserve offline_mode across database restores and non-overwrite JSON imports, and add getOfflineModeAbortSignal() to abort in-flight product image imports, tax pack catalog and artifact downloads, telemetry and diagnostic requests, and PostHog network requests when Offline mode is enabled.
  • Clear the daily telemetry timer and shut down the PostHog client without flushing queued events when Offline mode turns on, resume daily telemetry checks without resending app_launch when Offline mode turns off, and block CloudSync auto-registration retries and failure-state writes while offline.
  • Transition in-flight auto-updater checks and downloads to the offline state when Offline mode is enabled, track and suppress stale invalidated update check results and errors across offline transitions, and update docs/architecture/cloud-integrations.md and tests/offline-mode.test.ts.

Risk Assessment

✅ Low: The changes cleanly and durably close the Offline mode gaps across backup restore/import, PostHog flush suppression, in-flight request cancellation, telemetry timer resumption, cloud auto-registration retries, and updater check invalidation with comprehensive behavioral tests.

Testing

Ran the focused offline-mode, update-state, telemetry, tax-pack-catalog, and product-images test suites and drove all six Offline mode scenarios live against a disposable Express API, SQLite database, and local HTTP/TCP servers, recording structured evidence to ~/.no-mistakes/evidence/01M5JTP8ZYKKVH14K90HVKXJ8K/offline-mode-live-validation.json (no screenshot artifact was captured because this change touches only backend services, API routes, and documentation with no UI surface changes); all scenarios and suites passed.

  • Live validation: ✅ go - 6 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Owner enables Offline mode and restores an online backup (same-schema direct and older-schema data-only) or imports a database payload with offline_mode=false (overwrite and merge), and offline_mode r… ✅ pass live ~/.no-mistakes/evidence/01M5JTP8ZYKKVH14K90HVKXJ8K/offline-mode-live-validation.json (scenarios.restore_and_import) and npm run test:offline-mode
Enabling Offline mode while a PostHog batch request is in-flight aborts the active HTTP connection immediately and shuts down PostHog without flushing or retrying queued events ✅ pass live ~/.no-mistakes/evidence/01M5JTP8ZYKKVH14K90HVKXJ8K/offline-mode-live-validation.json (scenarios.posthog_abort_and_no_flush) and npm run test:offline-mode
Enabling Offline mode mid-request aborts in-flight product image fetches, tax-pack catalog/artifact downloads, and anonymous telemetry/diagnostic sends with offline_mode errors while caller-aborted on… ✅ pass live ~/.no-mistakes/evidence/01M5JTP8ZYKKVH14K90HVKXJ8K/offline-mode-live-validation.json (scenarios.in_flight_aborts_and_telemetry_timer) and npm run test:offline-mode
Toggling Offline mode off via PUT /api/settings/offline-mode resumes the daily telemetry and PostHog check timer without resending app_launch, and toggling Offline mode back on clears the daily timer ✅ pass live ~/.no-mistakes/evidence/01M5JTP8ZYKKVH14K90HVKXJ8K/offline-mode-live-validation.json (scenarios.in_flight_aborts_and_telemetry_timer) and npm run test:offline-mode
Enabling Offline mode during an in-flight CloudSync auto-registration attempt cancels retry scheduling and leaves cloud_registration_status unset instead of recording registration_failed ✅ pass live ~/.no-mistakes/evidence/01M5JTP8ZYKKVH14K90HVKXJ8K/offline-mode-live-validation.json (scenarios.cloud_auto_register_offline) and npm run test:offline-mode
Enabling Offline mode during an in-flight update check transitions status to offline, suppresses late check results or errors, and defers any new check after reconnect until the invalidated check sett… ✅ pass live ~/.no-mistakes/evidence/01M5JTP8ZYKKVH14K90HVKXJ8K/offline-mode-live-validation.json (scenarios.updater_offline_and_reconnect) and npm run test:offline-mode
Evidence: Live Offline-Mode Validation Evidence JSON
{
  "timestamp": "2026-10-22T23:04:46.792Z",
  "scenarios": {
    "restore_and_import": {
      "initialGet": {
        "status": 200,
        "data": {
          "offline_mode": false
        }
      },
      "managerPutStatus": 403,
      "enableRes": {
        "status": 200,
        "data": {
          "offline_mode": true
        }
      },
      "directRestoreMode": "direct",
      "afterDirectRestore": {
        "offline_mode": true
      },
      "dataOnlyRestoreMode": "data_only",
      "afterDataOnlyRestore": {
        "offline_mode": true
      },
      "importOverwriteStatus": 200,
      "afterImportOverwrite": {
        "offline_mode": true
      },
      "importMergeStatus": 200,
      "afterImportMerge": {
        "offline_mode": true
      }
    },
    "posthog_abort_and_no_flush": {
      "requestsBeforeOffline": 1,
      "posthogAbortedOnServer": true,
      "requestsAfterOffline": 1
    },
    "in_flight_aborts_and_telemetry_timer": {
      "pendingImgResult": {
        "ok": false,
        "code": "offline_mode",
        "name": "OfflineModeError"
      },
      "callerAbortImgResult": {
        "ok": false,
        "name": "AbortError"
      },
      "blockedFetchUrlStatus": 503,
      "blockedFetchUrlBody": {
        "error": "offline_mode"
      },
      "catalogAbortResult": {
        "ok": false,
        "code": "offline_mode"
      },
      "taxAbortedOnServer": true,
      "taxServerHits": 1,
      "timerWhenStartedOffline": false,
      "timerAfterGoingOnline": true,
      "appLaunchEventsAfterResume": 0,
      "timerAfterGoingOfflineAgain": false
    },
    "cloud_auto_register_offline": {
      "cloudRegHits": 1,
      "cloudRegAborted": true,
      "autoRegisterTimerIsNull": true,
      "cloudRegistrationStatus": ""
    },
    "updater_offline_and_reconnect": {
      "firstId": 1,
      "statusWhenSuspended": {
        "status": "offline",
        "reason": "unknown",
        "error": "Offline mode is on"
      },
      "acceptWhileOffline": false,
      "statusAfterOfflineError": {
        "status": "offline",
        "reason": "unknown",
        "error": "Offline mode is on"
      },
      "secondIdWhileFirstPending": null,
      "acceptBeforeFirstSettles": false,
      "statusAfterStaleError": {
        "status": "checking"
      },
      "secondRanAfterSettle": true,
      "acceptAfterFirstSettles": true
    }
  }
}
Evidence: Offline Mode Integration Suite Output

Source: Offline Mode Integration Suite Output

Offline mode: 62/62 passed (restore & import protection, PostHog abort without flush, in-flight image/tax-pack/telemetry aborts, telemetry daily timer resume without duplicate app_launch, CloudSync auto-registration retry suppression, and updater check suspension/stale-result suppression across reconnects).

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 6 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Owner enables Offline mode and restores a pre-offline backup (both direct same-schema and older-schema data-only) or imports JSON with offline_mode=false (both overwrite=true and overwrite=false); Off… ✅ pass live ~/.no-mistakes/evidence/01M5JTP8ZYKKVH14K90HVKXJ8K/offline-mode-live-validation.json
Owner enables Offline mode while a PostHog analytics request is in flight; the active HTTP connection is immediately aborted and subsequent events are not flushed or retried ✅ pass live ~/.no-mistakes/evidence/01M5JTP8ZYKKVH14K90HVKXJ8K/offline-mode-live-validation.json
Owner enables Offline mode while web image import (fetchPinnedHttps / POST /api/products/fetch-url), tax-pack catalog/artifact download, or anonymous telemetry/diagnostic delivery is in flight; in-fli… ✅ pass live ~/.no-mistakes/evidence/01M5JTP8ZYKKVH14K90HVKXJ8K/offline-mode-live-validation.json
Owner toggles Offline mode off after launching in Offline mode, then toggles it back on; the daily telemetry check timer arms on resume without sending duplicate app_launch events and stops immediatel… ✅ pass live ~/.no-mistakes/evidence/01M5JTP8ZYKKVH14K90HVKXJ8K/offline-mode-live-validation.json
Owner enables Offline mode while FloAdmin cloud auto-registration is in flight; the registration request is aborted, no retry timer is scheduled, and cloud_registration_status does not record registra… ✅ pass live ~/.no-mistakes/evidence/01M5JTP8ZYKKVH14K90HVKXJ8K/offline-mode-live-validation.json
Owner enables Offline mode during an in-flight auto-updater check and then reconnects and triggers a new check before the first check settles; the updater enters the offline state, suppresses late eve… ✅ pass live ~/.no-mistakes/evidence/01M5JTP8ZYKKVH14K90HVKXJ8K/offline-mode-live-validation.json
  • npm run test:offline-mode
  • npm run test:update-state
  • npm run test:telemetry
  • npm run test:tax-pack-catalog
  • npm run test:tax-pack-management
  • npm run test:shutdown-lifecycle
  • node -e "<live validation harness against compiled dist/main server, SQLite DB, and local HTTP/TCP endpoints>"

✅ No issues found.

  • Live validation: ✅ go - 6 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Owner enables Offline mode and restores an online backup (same-schema direct and older-schema data-only) or imports a database payload with offline_mode=false (overwrite and merge), and offline_mode r… ✅ pass live ~/.no-mistakes/evidence/01M5JTP8ZYKKVH14K90HVKXJ8K/offline-mode-live-validation.json (scenarios.restore_and_import) and npm run test:offline-mode
Enabling Offline mode while a PostHog batch request is in-flight aborts the active HTTP connection immediately and shuts down PostHog without flushing or retrying queued events ✅ pass live ~/.no-mistakes/evidence/01M5JTP8ZYKKVH14K90HVKXJ8K/offline-mode-live-validation.json (scenarios.posthog_abort_and_no_flush) and npm run test:offline-mode
Enabling Offline mode mid-request aborts in-flight product image fetches, tax-pack catalog/artifact downloads, and anonymous telemetry/diagnostic sends with offline_mode errors while caller-aborted on… ✅ pass live ~/.no-mistakes/evidence/01M5JTP8ZYKKVH14K90HVKXJ8K/offline-mode-live-validation.json (scenarios.in_flight_aborts_and_telemetry_timer) and npm run test:offline-mode
Toggling Offline mode off via PUT /api/settings/offline-mode resumes the daily telemetry and PostHog check timer without resending app_launch, and toggling Offline mode back on clears the daily timer ✅ pass live ~/.no-mistakes/evidence/01M5JTP8ZYKKVH14K90HVKXJ8K/offline-mode-live-validation.json (scenarios.in_flight_aborts_and_telemetry_timer) and npm run test:offline-mode
Enabling Offline mode during an in-flight CloudSync auto-registration attempt cancels retry scheduling and leaves cloud_registration_status unset instead of recording registration_failed ✅ pass live ~/.no-mistakes/evidence/01M5JTP8ZYKKVH14K90HVKXJ8K/offline-mode-live-validation.json (scenarios.cloud_auto_register_offline) and npm run test:offline-mode
Enabling Offline mode during an in-flight update check transitions status to offline, suppresses late check results or errors, and defers any new check after reconnect until the invalidated check sett… ✅ pass live ~/.no-mistakes/evidence/01M5JTP8ZYKKVH14K90HVKXJ8K/offline-mode-live-validation.json (scenarios.updater_offline_and_reconnect) and npm run test:offline-mode
  • npm run test:offline-mode
  • npm run test:update-state
  • npm run test:telemetry
  • npm run test:tax-pack-catalog
  • npm run test:product-images
  • Live disposable Express/SQLite/HTTP/TCP validation script writing ~/.no-mistakes/evidence/01M5JTP8ZYKKVH14K90HVKXJ8K/offline-mode-live-validation.json
✅ **Document** - passed

✅ No issues found.

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

✅ No issues found.

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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 thread tests/offline-mode.test.ts Fixed
@khaira777

Copy link
Copy Markdown
Contributor Author

@greptileai review this at apex

@greptile-apps

greptile-apps Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5 Tier: apex

[Medium impact] Offline mode now affects several outbound workflows across the app.

Fix the updater’s acceptance of old results before merging; the other findings concern launch counts and image-request hardening.

Findings

  1. P1 Old checks become active again ▶
  2. P2 Reconnects count as launches ▶
  3. P2 Pre-aborted requests escape rejection ▶

Summary

This PR preserves the device’s offline_mode across restore/import, aborts optional requests, resumes telemetry, and filters late updater results.

  • Restores and imports keep the device’s Offline mode choice.
  • Image imports and tax-pack downloads stop when Offline mode turns on.
  • Telemetry and PostHog stop sending offline and restart when the owner reconnects.
  • Cloud auto-registration waits while Offline mode is on.
  • Updater checks and downloads settle into an offline state when Offline mode turns on.

khaira777 explicitly intends to preserve the device’s Offline mode choice and discard queued PostHog events without flushing. Neither behavior is reported as a defect.

Validation: git diff --check passed. An isolated native HTTPS probe confirmed the pre-aborted request error ordering. Lint, build, documentation checks, and focused suites were not run because dependencies are not installed.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["Owner saves offline_mode"] --> B{"Offline mode on?"}
  B -->|Yes| C["Abort shared request signal"]
  C --> D["Stop image, tax-pack, telemetry and PostHog requests"]
  B -->|Yes| E["Suspend cloud, Drive and WhatsApp"]
  B -->|Yes| F["Invalidate updater check or cancel download"]
  B -->|No| G["Resume cloud, WhatsApp and telemetry"]
Loading

Reviews (1) · Last reviewed commit: "no-mistakes(document): Update Offline mo..." · Reviewed by Greptile

Comment thread main/index.ts Resolved
Comment thread main/routes/settings.ts Resolved
Comment thread main/routes/products.ts Resolved
@khaira777
khaira777 force-pushed the fm/ship-pr-1306-offline-mode-fixes branch from b9fa78f to 6dcf9e7 Compare October 22, 2026 22:27
@khaira777

Copy link
Copy Markdown
Contributor Author

@greptileai review this at apex

@khaira777 khaira777 changed the title fix(main): close remaining offline-mode gaps across restore, analytics, fetches, and updater fix(main): close offline-mode gaps across restore, updater, telemetry, and fetches Oct 22, 2026
…zation` alert in `tests/offline-mode.test.ts` (and its sibling URL-matching test interceptors in the same file): - Replaced `String(input).includes('telemetry.flopos.com')` at line 655 with an exact comparison against the exported `TELEMETRY_URL` constant (`String(input) === TELEMETRY_URL`). - Replaced `url.includes('posthog.example')` at line 291 with `new URL(String(input)).hostname === 'posthog.example'`. - Replaced `String(url).includes('/releases?')` at line 461 with `new URL(String(url)).pathname.endsWith('/releases')`. Verified with `npm run test:offline-mode` (54/54 passed), `node scripts/ci/check-changed-format.cjs --base 8a0c272`, `npm run lint`, `npm run build`, and `git diff --check`
@khaira777
khaira777 force-pushed the fm/ship-pr-1306-offline-mode-fixes branch from 6dcf9e7 to 118b9a4 Compare October 22, 2026 23:09
@khaira777 khaira777 changed the title fix(main): close offline-mode gaps across restore, updater, telemetry, and fetches fix(main): close offline mode gaps across restore, updater, telemetry, and fetches Oct 22, 2026
@khaira777

Copy link
Copy Markdown
Contributor Author

@greptileai review this at apex

@khaira777
khaira777 merged commit a19caf9 into main Oct 23, 2026
23 checks passed
@khaira777
khaira777 deleted the fm/ship-pr-1306-offline-mode-fixes branch October 23, 2026 01:41
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.

fix(offline-mode): harden restore preservation, in-flight request abort, PostHog/telemetry lifecycle, cloud retry, and updater check phase

2 participants