Skip to content

feat: Add offline mode to pause uploads - #2339

Merged
Sebassmaster merged 4 commits into
v1from
feat/offline-mode-minimal
Nov 24, 2026
Merged

Sebassmaster merged 4 commits into
v1from
feat/offline-mode-minimal

Conversation

@Sebassmaster

@Sebassmaster Sebassmaster commented Nov 24, 2026 •

Copy link
Copy Markdown

Adds an offline mode that stops the SDK from uploading anything, so apps that know they have no connectivity don't stall on network timeouts, for example at shutdown. While it's enabled, envelopes are written to the cache if http_retry is on and discarded otherwise. Disabling it sends the cached envelopes immediately.

sentry_set_offline(1);
sentry_set_offline(0);   // sends cached envelopes right away
sentry_is_offline();

The setting follows the user-consent model. It's stored in <database>/offline-mode and loaded by sentry_init before envelopes from previous runs are sent, so an app that starts while still offline doesn't try to upload them. Like the consent API, the functions only take effect after sentry_init. Offline mode is a second reason for sentry__run_should_skip_upload to block uploads, next to missing consent, so every upload path follows it: events, sessions, the retry poller, the Crashpad handler (via SetUploadsEnabled/SetUploadsPaused and RequestRetry) and the native crash daemon (via a new shared-memory field). Enabling it without http_retry logs a warning, because envelopes captured offline would be lost.

Logs and metrics are discarded while offline, as they already are while consent is revoked: the batcher drops envelopes whenever uploads are blocked. This is documented on sentry_set_offline. Caching them too would be a follow-up.

Open questions:

  • Naming: "offline mode" can be confused with SENTRY_CACHE_KEEP_OFFLINE. An alternative is sentry_pause_uploads/sentry_resume_uploads, which matches Crashpad's terminology. Should this start as SENTRY_EXPERIMENTAL_API?
    • settled on sentry_set_offline(1) / sentry_set_offline(0) / sentry_is_offline() and decided on SENTRY_API
  • Cache limits are only enforced by the cleanup at sentry_init, so the cache can grow beyond them during one long offline run. This is unchanged from how consent and failed sends already behave.
    • This is OK considering that we are not caching logs, just events, crashes and sessions.
  • External crash reporter: it isn't launched for crashes that happen while offline. The crash is cached and later uploaded directly, the same as with revoked consent.
    • OK to follow user consent pattern
  • Native shared memory: the new field changes the layout of sentry_crash_context_t without increasing SENTRY_CRASH_VERSION, following feat(native): consent-aware offline caching #1649.
    • OK because we only provide source builds that apps/games build and deploy themselves
  • user_consent_changed_func now also fires on offline-mode changes. Should it be renamed?
    • We'll leave this name as is in this PR, and potentially renaming it later in a separate step
  • Switch (sentry-switch): the NX backend sizes its dying-message region from sentry__should_skip_upload() in its consent callback. Once it moves to a 1.x release that includes this change, offline mode would set the region to 0 and crashes would lose their Sentry data, even though Nintendo's crash reporting uploads them later anyway. The backend should check consent only, which may need a consent-only helper here.
  • PlayStation (sentry-playstation): its transport is built with sentry_transport_new and has no retry support, so with offline mode and http_retry, envelopes are cached but never sent, not even after sentry_set_offline(0). Either document that sending cached envelopes needs the built-in HTTP transport, or add retry support to the PS transport.

Fixes #929

🤖 Generated with Claude Code

Add sentry_offline_mode_enable/disable/is_enabled. While offline mode
is enabled, nothing is uploaded: envelopes are cached when http_retry
is enabled and discarded otherwise. Disabling it sends the cached
envelopes immediately.

Like user consent, the setting is persisted in the database directory
and loaded by sentry_init before envelopes from previous runs are sent,
so an app that starts while still offline does not try to upload them.
The Crashpad handler and the native crash daemon follow it as well.

Logs and metrics are still discarded while offline, as they are today
while consent is revoked.

Refs #929

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 4f377c4

@Sebassmaster
Sebassmaster requested a review from jpnurmi November 24, 2026 09:52
Replace sentry_offline_mode_enable/disable with sentry_set_offline(int)
and sentry_offline_mode_is_enabled with sentry_is_offline.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Sebassmaster
Sebassmaster marked this pull request as ready for review November 24, 2026 10:50

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 9168a45. Configure here.

@jpnurmi

jpnurmi commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

sentry_close() can still run into the shutdown timeout as in #929 because offline mode is only checked when an envelope is submitted, so envelopes already queued in the HTTP transport are still sent after sentry_set_offline(1).

Could http_send_task check sentry__run_should_skip_upload(state->run) before sending and treat a blocked envelope like a network failure? The transport already holds the run, so nothing new needs to be passed in, and the existing failure path caches the envelope for retry when http_retry is enabled.

Offline mode and user consent are checked when an envelope is
submitted, but envelopes already queued in the HTTP transport were
still sent afterwards. Without connectivity, each of them waited for a
network timeout, so sentry_close() could still hit the shutdown
timeout after sentry_set_offline(1).

Check the upload gate in http_send_task right before sending, and
handle a blocked envelope like a network failure, so the existing
failure path caches it for retry when http_retry is enabled.

Refs #929

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Sebassmaster

Copy link
Copy Markdown
Author

sentry_close() can still run into the shutdown timeout as in #929 because offline mode is only checked when an envelope is submitted, so envelopes already queued in the HTTP transport are still sent after sentry_set_offline(1).

Could http_send_task check sentry__run_should_skip_upload(state->run) before sending and treat a blocked envelope like a network failure? The transport already holds the run, so nothing new needs to be passed in, and the existing failure path caches the envelope for retry when http_retry is enabled.

Good point, added it in the last commit.
Also revoked consent benefits too, because envelopes queued before sentry_user_consent_revoke() are no longer sent.

The crash daemon submitted the logs, sessions and transactions dumped by
the crashing app before copying user consent and offline mode from
shared memory into its run. With offline mode enabled, those envelopes
were still uploaded (or timed out without connectivity), and with user
consent given, they were held back as if consent was missing.

Copy both values before anything is submitted.

Refs #929

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@jpnurmi jpnurmi 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.

Nice! A few last remaining CI checks are still running but the changes look good to me. 👍

@Sebassmaster
Sebassmaster merged commit 6619e27 into v1 Nov 24, 2026
71 checks passed
@Sebassmaster
Sebassmaster deleted the feat/offline-mode-minimal branch November 24, 2026 12:56
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.

2 participants