agentleFS
SentryKnown publishergetsentry/sentry-java/.cursor/rules/offline.mdc

sentry-java / rules

Cursor rule1.4k starsChanged 7 months agoMITView on GitHub

Java SDK Offline behaviour

Trending

Quiet this year.about the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 0 mentionsApr 2026: 0 mentionsMay 2026: 0 mentionsJun 2026: 0 mentionsJul 2026: 0 mentionsAug 2026: 0 mentionsSep 2026: 0 mentionsOct 2026: 0 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the getsentry/sentry-java repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about getsentry/sentry-java

The biggest 5 of 18 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 18

Talked about on GitHub (18 times).

On GitHub · 18

13 more on GitHub

The file

We split this offline.mdc into the rules it gives an agent

12 rules. About 0 are common, 4 are distinctive, and 8 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 8

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    If an envelope is dropped due to rate limit and has previously been cached (Cached hint) it will be discarded from the IEnvelopeCache.

    line 15
  2. Distinctive:

    If the envelope is not retryable and hasn't been sent to offline cache, it's recorded as lost in a client report.

    line 24
  3. Distinctive:

    If it's not retryable and hasn't been cached, it's recorded as lost in a client report.

    line 27
  4. Very specific:

    When AsyncHttpTransport successfully sends an envelope to the Sentry server, it calls envelopeCache.discard(envelope) to remove the cached …

    line 45
  5. Very specific:

    If an envelope is dropped due to rate limiting and has previously been cached (indicated by the Cached hint), it gets discarded immediately …

    line 48
  6. Very specific:

    When the SDK processes cached envelope files from disk (via EnvelopeSender), files are deleted after processing unless they are marked for …

    line 52
  7. Very specific:

    If the number of files in the cache directory has reached the configured limit (SentryOptions.maxCacheItems), the oldest file will be …

    line 58
  8. Distinctive:

    Non-retryable envelopes: If they fail to send, they're immediately recorded as lost (not cached for retry)

    line 67
  9. Very specific:

    Queue Overflow: When the transport executor queue is full - recorded as DiscardReason.QUEUE_OVERFLOW

    line 71
  10. Very specific:

    Network Errors (Non-Retryable): When an envelope isn't marked as retryable and fails due to network issues - recorded as …

    line 73
  11. Very specific:

    Rate Limiting: When envelope items are dropped due to active rate limits - recorded as DiscardReason.RATELIMIT_BACKOFF

    line 75
  12. Very specific:

    Cache Overflow: When the cache directory has reached maxCacheItems, old files are deleted - recorded as DiscardReason.CACHE_OVERFLOW

    line 77

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
offline.mdc
---
alwaysApply: false
description: Java SDK Offline behaviour
---
# Java SDK Offline behaviour

By default offline caching is enabled for Android but disabled for JVM.
It can be enabled by setting SentryOptions.cacheDirPath.

For Android, AndroidEnvelopeCache is used. For JVM, if cache path has been configured, EnvelopeCache will be used.

Any error, event, transaction, profile, replay etc. is turned into an envelope and then sent into ITransport.send.
The default implementation is AsyncHttpTransport.

If an envelope is dropped due to rate limit and has previously been cached (Cached hint) it will be discarded from the IEnvelopeCache.

AsyncHttpTransport.send will enqueue an AsyncHttpTransport.EnvelopeSender task onto an executor.

Any envelope that doesn't have the Cached hint will be stored in IEnvelopeCache by the EventSender task. Previously cached envelopes (Cached hint) will have a noop cache passed to AsyncHttpTransport.EnvelopeSender and thus not cache again. It is also possible cache is disabled in general.

An envelope being sent directly from SDK API like Sentry.captureException will not have the Retryable hint.

In case the SDK is offline, it'll mark the envelope to be retried if it has the Retryable hint.
If the envelope is not retryable and hasn't been sent to offline cache, it's recorded as lost in a client report.

In case the envelope can't be sent due to an error or network connection problems it'll be marked for retry if it has the Retryable hint.
If it's not retryable and hasn't been cached, it's recorded as lost in a client report.

In case the envelope is sent successfully, it'll be discarded from cache.

The SDK has multiple mechanisms to deal with envelopes on disk.
- OutboxSender: Sends events coming from other SDKs like NDK that wrote them to disk.
- io.sentry.EnvelopeSender: This is the offline cache.

Both of these are set up through an integration (SendCachedEnvelopeIntegration) which is configured to use SendFireAndForgetOutboxSender or SendFireAndForgetEnvelopeSender.

io.sentry.EnvelopeSender is able to pick up files in the cache directory and send them.
It will trigger sending envelopes in cache dir on init and when the connection status changes (e.g. the SDK comes back online, meaning it has Internet connection again).

## When Envelope Files Are Removed From Cache

Envelope files are removed from the cache directory in the following scenarios:

### 1. Successful Send to Sentry Server
When `AsyncHttpTransport` successfully sends an envelope to the Sentry server, it calls `envelopeCache.discard(envelope)` to remove the cached file. This happens in `AsyncHttpTransport.EnvelopeSender.flush()` when `result.isSuccess()` is true.

### 2. Rate Limited Previously Cached Envelopes
If an envelope is dropped due to rate limiting **and** has previously been cached (indicated by the `Cached` hint), it gets discarded immediately via `envelopeCache.discard(envelope)` in `AsyncHttpTransport.send()`.
In this case the discarded envelope is recorded as lost in client reports.

### 3. Offline Cache Processing (EnvelopeSender)
When the SDK processes cached envelope files from disk (via `EnvelopeSender`), files are deleted after processing **unless** they are marked for retry. In `EnvelopeSender.processFile()`, the file is deleted with `safeDelete(file)` if `!retryable.isRetry()`.

### 4. Session File Management
Session-related files (session.json, previous_session.json) are removed during session lifecycle events like session start/end and abnormal exits.

### 5. Cache rotation
If the number of files in the cache directory has reached the configured limit (SentryOptions.maxCacheItems), the oldest file will be deleted to make room.
This happens in `CacheStrategy.rotateCacheIfNeeded`. The deleted envelope will be recorded as lost in client reports.

## Retry Mechanism

**Important**: The SDK does NOT implement a traditional "max retry count" mechanism. Instead:

### Infinite Retry Approach
- **Retryable envelopes**: Stay in cache indefinitely and are retried when conditions improve (network connectivity restored, rate limits expire, etc.)
- **Non-retryable envelopes**: If they fail to send, they're immediately recorded as lost (not cached for retry)

### When Envelopes Are Permanently Lost (Not Due to Retry Limits)

1. **Queue Overflow**: When the transport executor queue is full - recorded as `DiscardReason.QUEUE_OVERFLOW`

2. **Network Errors (Non-Retryable)**: When an envelope isn't marked as retryable and fails due to network issues - recorded as `DiscardReason.NETWORK_ERROR`

3. **Rate Limiting**: When envelope items are dropped due to active rate limits - recorded as `DiscardReason.RATELIMIT_BACKOFF`

4. **Cache Overflow**: When the cache directory has reached maxCacheItems, old files are deleted - recorded as `DiscardReason.CACHE_OVERFLOW`

### Cache Processing Triggers
Cached envelopes are processed when:
- Network connectivity is restored (via connection status observer)
- SDK initialization occurs
- Rate limits expire
- Manual flush operations

### File Deletion Implementation
The actual file deletion is handled by `EnvelopeCache.discard()` which calls `envelopeFile.delete()` and logs errors if deletion fails.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.