Skip to content

hotfix: _ANR detector and Sentry reporting Minidump files#8859

Open
NickKhalow wants to merge 1 commit into
mainfrom
feat/anr-detection-hotfix
Open

hotfix: _ANR detector and Sentry reporting Minidump files#8859
NickKhalow wants to merge 1 commit into
mainfrom
feat/anr-detection-hotfix

Conversation

@NickKhalow
Copy link
Copy Markdown
Contributor

Pull Request Description

What does this PR change?

Features

Key components

  • DclAnrIntegration — Sentry ISdkIntegration that creates and registers the watchdog
  • DclAnrWatchDog (abstract) — Base watchdog with pause/resume awareness, configurable timeout, and minidump collection on report
  • DclAnrWatchDogMultiThreaded — Desktop implementation: a background thread monitors main-thread heartbeats via a coroutine tick counter
  • DclAnrWatchDogSingleThreaded — WebGL fallback: coroutine-based elapsed-time check (single-threaded environment)
  • DclApplicationNotRespondingException — Custom exception type with Sentry mechanism metadata; on Windows, carries the dump file path for attachment
  • ThreadsDumpUtility — Windows-only utility that:
    • Calls the native MiniDumpWriteDump Win32 API (via MiniDumpNative) to generate a .dmp file — no external binaries required
    • Opens a process handle with PROCESS_QUERY_INFORMATION | PROCESS_VM_READ via ProcessInfoNative, with proper IDisposable handle cleanup
    • Polls for file readiness with a 5s timeout to handle async write completion
    • Compresses the dump into a ZIP archive for smaller Sentry attachment payloads
    • Caches Application.persistentDataPath and Application.streamingAssetsPath on the main thread ([RuntimeInitializeOnLoadMethod]) since Unity APIs are unavailable from background threads
    • Provides a Unity Editor menu item (Tools/ProcDump/Dump Current) for quick testing during development
  • MiniDumpNative — Static class wrapping the Dbghelp.dll MiniDumpWriteDump P/Invoke with thread-info, handle-data, and unloaded-modules dump flags
  • ProcessInfoNative / ProcessHandle — Win32 process handle management with IDisposable for safe cleanup
  • DclProcesses.ExecuteBlocking / dcl_start_process_blocking — New native C function for blocking process execution (waits for child exit and returns exit code), available on both Windows (_spawnvp _P_WAIT) and macOS (posix_spawnp + waitpid)

Debug chat commands (registered in DynamicWorldContainer)

  • /anr-simulate [ms] — Freezes the main thread for the specified duration (default 10s) to trigger ANR detection
  • /anr-dump — Manually collects and archives a process dump to the app directory (Windows only); runs on a background thread via ExecuteOnThreadPoolScope

Sentry diagnostics & CI

  • Sentry status loggingDiagnosticInfoUtils now logs whether Sentry is enabled, plus its environment, release, and DSN status at startup
  • enable-sentry PR label — The build-unitycloud.yml workflow now checks for an enable-sentry label on PR builds, allowing Sentry to be activated for specific PRs without requiring a manual workflow input
  • script-debugging PR label / script_debugging workflow input — Enables AllowDebugging build option (forces a Development build). Can be toggled via the script-debugging label on PR builds or the script_debugging input for workflow_dispatch / workflow_call triggers
  • Application arguments formatting — Log output for app args now uses separator lines for better readability
  • S3 upload URL reporting — New CI step prints the artifact upload URL to the job summary for easy access
  • Command error logging — Chat command execution errors are now reported via ReportHub.LogError in addition to the user-facing error message

Native code changes

  • dcl_processes.c / .h — Added dcl_start_process_blocking() for synchronous child process execution; also fixed a CloseHandle leak in get_process_name on Windows (handle was closed after the buffer was freed)
  • DCLProcesses.dll / .exp / .lib — Rebuilt native binaries with the new blocking export
  • DclProcessesNativeMethods.cs — Added managed P/Invoke binding for dcl_start_process_blocking

The built-in Sentry ANR integration is explicitly disabled (DisableAnrIntegration()) to avoid duplicate detection.


Test Instructions

Steps (standard run):

metaforge explorer run 8811

Expected result:

  • Explorer launches and runs normally without false-positive ANR reports

Steps (fresh account):

metaforge account create --clear
metaforge explorer run 8811

Expected result:

  • Same as above — no spurious ANR reports during normal operation

Prerequisites

  • Windows build for minidump verification (macOS dump collection not yet supported)
  • Sentry dashboard access to verify ANR event format and dump attachment

Test Steps

  1. Launch the explorer and navigate normally — no ANR events should fire
  2. Use the /anr-simulate chat command (or /anr-simulate 8000 for 8s) to freeze the main thread and trigger ANR detection
  3. Verify Sentry receives a DclApplicationNotRespondingException event with a .dmp file attachment (ZIP-compressed)
  4. Use the /anr-dump chat command to manually collect a dump and confirm the file paths are printed
  5. In Unity Editor (Windows), use Tools > ProcDump > Dump Current to verify the editor integration works
  6. Confirm the built-in Sentry ANR integration does not fire duplicate events
  7. Add the enable-sentry label to a test PR and verify Sentry is enabled in the resulting build
  8. Add the script-debugging label to a test PR and verify the build includes AllowDebugging and Development flags
  9. Check startup logs for the new Sentry status section (Enabled, Environment, Release, DSN)

Additional Testing Notes

  • macOS does not yet support dump collection — ANR events will report "Dump is not available on macOS yet"
  • WebGL uses a single-threaded fallback (coroutine-based timing) — verify no false positives on that platform
  • The watchdog pauses during app background/focus-loss to avoid false reports
  • Dump file readiness is polled with a 5s timeout — if MiniDumpWriteDump takes longer, the dump will fail gracefully
  • Minidump uses MiniDumpNormal | WithThreadInfo | WithHandleData | WithUnloadedModules flags (equivalent to procdump -mt)

Quality Checklist

  • Changes have been tested locally
  • Documentation has been updated (if required)
  • Performance impact has been considered
  • For SDK features: Test scene is included

Code Review Reference

Please review our Branch & PR Standards before submitting. It explains the automated review flow, QA/DEV approval requirements, and what each label does — especially useful for first-time contributors.

@NickKhalow NickKhalow self-assigned this May 22, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 22, 2026

@NickKhalow NickKhalow marked this pull request as ready for review May 22, 2026 12:48
@NickKhalow NickKhalow requested review from a team as code owners May 22, 2026 12:48
@github-actions github-actions Bot requested review from DafGreco, dalkia and popuz May 22, 2026 12:48
@NickKhalow NickKhalow force-pushed the feat/anr-detection-hotfix branch from 7463d03 to 6969a53 Compare May 22, 2026 13:09
@mikhail-dcl mikhail-dcl self-requested a review May 22, 2026 13:22
@m3taphysics
Copy link
Copy Markdown
Collaborator

PR #8859, run #26292798681

Builds: Windows change, Windows baseline, macOS change, macOS baseline

Framework 13 i7

Metric Change Baseline Delta Improvement
Samples 2700 2700
CPU average 33.3 ms 33.3 ms -0.0 ms 0.0%
CPU 1% worst 33.6 ms 33.6 ms -0.0 ms 0.1%
CPU 0.1% worst 34.8 ms 35.3 ms -0.5 ms 1.5%
GPU average 7.9 ms 8.3 ms -0.5 ms 5.5% 🟢
GPU 1% worst 20.4 ms 19.8 ms 0.5 ms -2.8%
GPU 0.1% worst 26.6 ms 25.3 ms 1.3 ms -5.2% 🔴

Integrate custom ANR detector with Sentry reporting, native Windows
minidump collection, background archival/upload, debug chat commands,
and CI flags for opt-in builds.
@NickKhalow NickKhalow force-pushed the feat/anr-detection-hotfix branch from 6969a53 to aca6f8b Compare May 22, 2026 14:39
@m3taphysics
Copy link
Copy Markdown
Collaborator

PR #8859, run #26296225401

Builds: Windows change, Windows baseline, macOS change, macOS baseline

Framework 13 i7

Metric Change Baseline Delta Improvement
Samples 2700 2700
CPU average 33.3 ms 33.3 ms -0.0 ms 0.0%
CPU 1% worst 33.6 ms 33.6 ms -0.0 ms 0.0%
CPU 0.1% worst 35.1 ms 35.6 ms -0.5 ms 1.5%
GPU average 7.8 ms 7.9 ms -0.1 ms 1.8%
GPU 1% worst 20.0 ms 19.5 ms 0.5 ms -2.5%
GPU 0.1% worst 26.9 ms 24.5 ms 2.4 ms -9.7% 🔴

@NickKhalow NickKhalow added enable-sentry Enables Sentry integration clean-build Used to trigger clean build on PR labels May 25, 2026
@m3taphysics
Copy link
Copy Markdown
Collaborator

PR #8859, run #26397329283

Builds: Windows change, Windows baseline, macOS change, macOS baseline

Framework 13 i7

Metric Change Baseline Delta Improvement
Samples 2700 2700
CPU average 33.3 ms 33.3 ms -0.0 ms 0.0%
CPU 1% worst 33.4 ms 33.5 ms -0.1 ms 0.3%
CPU 0.1% worst 34.0 ms 35.2 ms -1.2 ms 3.3% 🟢
GPU average 8.9 ms 8.6 ms 0.3 ms -3.7% 🔴
GPU 1% worst 16.6 ms 17.4 ms -0.8 ms 4.5% 🟢
GPU 0.1% worst 20.8 ms 23.5 ms -2.7 ms 11.6% 🟢

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

Labels

clean-build Used to trigger clean build on PR enable-sentry Enables Sentry integration new-dependency

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants