Skip to content

feat(anr): [Non-Fatal ANR 1] Add HangRecorder - #6722

Open
markushi wants to merge 1 commit into
markushi/feat/non-fatal-anr-collectionfrom
markushi/feat/non-fatal-anr-1-hang-recorder
Open

markushi wants to merge 1 commit into
markushi/feat/non-fatal-anr-collectionfrom
markushi/feat/non-fatal-anr-1-hang-recorder

Conversation

@markushi

Copy link
Copy Markdown
Member

Adds HangRecorder: it opens a hang interval when a signal reports SUSPICIOUS, lets the collectors sample on its own 66 ms tick thread, and gives a HangRecord to the subscribers when the interval ends. Not wired yet.

Design: Non-Fatal ANR Architecture (JAVA-777)

⚠️ Merge this PR using a merge commit (not squash). Only the collection branch is squash-merged into main.

🤖 Generated with Claude Code

#skip-changelog

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR risk: medium

For commit b6952c6.

Main concerns: public contract, host performance, data sent to Sentry.

Rules that block low also fired:

  • R4: a public API record changed: sentry-android-core/api/sentry-android-core.api

This label is a hint for reviewers, not an approval.

@github-actions

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

Generated by 🚫 dangerJS against b6952c6

@sentry

sentry Bot commented Nov 20, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.65.0 (1) release

⚙️ sentry-android Build Distribution Settings

@markushi
markushi marked this pull request as ready for review November 20, 2026 18:01
@markushi
markushi requested review from a team and adinauer as code owners November 20, 2026 18:01
@markushi
markushi requested review from 0xadam-brown and romtsn and removed request for a team November 20, 2026 18:01
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 20, 2026

@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 and found 3 potential issues.

Fix All in Cursor

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

Reviewed by Cursor Bugbot for commit b6952c6. Configure here.

// scheduleWithFixedDelay stops all later ticks after an exception.
ExceptionUtils.rethrowIfFatal(t);
options.getLogger().log(SentryLevel.ERROR, "HangRecorder tick failed", t);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tick errors skip hang time cap

Medium Severity

The max-recording-time stop lives in a finally that only wraps collector onSample calls. TickListener.onMetronomeTick runs before that block, so a listener that throws is caught by the outer catch (Throwable) and skips the cap. During a true hang, IDLE never arrives, so the interval can stay open and keep recording past maxRecordingTimeMs.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bugbot

Reviewed by Cursor Bugbot for commit b6952c6. Configure here.

}
tickFuture =
self.scheduleWithFixedDelay(this::tick, 0, pollingIntervalMs, TimeUnit.MILLISECONDS);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Failed start leaves detection stuck

Medium Severity

startSignals sets signalsStarted = true before starting signals or scheduling ticks. If signal.start() throws, remaining signals never start, tickFuture is never scheduled, and later onForeground calls return immediately because signalsStarted is already true. The failed task is an execute() runnable, so the exception is swallowed by the executor. Hang detection then stays off until the next background/foreground cycle.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bugbot

Reviewed by Cursor Bugbot for commit b6952c6. Configure here.

.setEndedAtMaxRecordingTime(endedAtMaxRecordingTime);
for (final @NotNull HangDataCollector collector : collectors) {
collector.onRecordingStopped(interval, builder);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stop failure reopens capped hangs

Medium Severity

endInterval clears openInterval and then calls onRecordingStopped with no isolation. If a collector throws, the HangRecord is never delivered and remaining collectors are not stopped. When this happens on the max-recording-time path, waitingForIdleAfterMaxRecordingTime is also never set, so a later SUSPICIOUS can open a new interval while the original hang is still in progress.

Additional Locations (1)
Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bugbot

Reviewed by Cursor Bugbot for commit b6952c6. Configure here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant