Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(mobile): Persist crash diagnostics before runtime fatals #4033

Openjuliusmarmingewants to merge 9 commits intomain fromrefs/pull/4033/headopened View on GitHub

juliusmarmingecommented

Fatal JavaScript errors delivered through React Native’s ErrorUtils handler can disappear before React Native terminates the runtime. The original logger used Expo’s asynchronous File.write() and only printed recovered records to the console.

Persist fatal records with writeSync() before calling the existing global handler, preserve that handler’s behavior if persistence fails, and keep at most 20 records on a best-effort basis. Settings → Diagnostics now combines saved JavaScript errors with Expo startup records and includes both in copied reports. Local records remain available when Expo updates is disabled or its log read fails. Matching local and Expo startup records are shown as one event while retaining both sets of details. Failed writes attempt to remove the partial file. Recovery is lazy; startup no longer scans or prints private crash records.

This rebuild preserves the original commits in #4033, crediting @juliusmarminge. It does not add breadcrumbs or outbox instrumentation claimed by the older description.

Validation on headless Linux, Node 24:

  • Existing test file: 5 → 8 tests. The three added cases cover persistence before previous-handler termination, recovery after a fresh module graph into the combined report, and nonfatal/storage-failure delegation.
  • Against the original implementation: 6 passed, 2 failed. Rebuilt head: all 8 passed. The same tests were extended for duplicate records, failed-write cleanup, and empty-report text; before those fixes, 5 passed and 3 failed, then all 8 passed again.
  • Mobile tsc --noEmit, scoped lint, formatting, and git diff --check: passed.
  • Installed Expo 58.0.9 JavaScript types and iOS/Android native method registrations confirm that write is asynchronous and writeSync is synchronous. The filesystem mock preserves that distinction.

Native EAS verification uses fresh iOS and Android development-client builds from this branch after merging c274a25151. Baseline and head receive the same temporary Diagnostics action invoking ErrorUtils.reportFatalError(new Error("mobile-02 runtime fatal 4033")); that action is verification-only and is removed from the shipping tree. The iOS baseline shows no recovered runtime fatal after a forced process relaunch. Head recovers the named error and stack from native disk in Diagnostics after a forced process relaunch; Copy changes to Copied. Both captures use the same native binary and production-mode Metro JS.

Before — iOS baseline after fatal/relaunch:

Before: iOS Diagnostics has no recovered runtime fatal

After — iOS PR head after fatal/relaunch:

After: iOS Diagnostics recovers the fatal message and stack

Android baseline and head both forward the fatal to the same React Native error screen. After closing/relaunching the native process, head recovers the named fatal and stack through Settings → About T3 Code → Diagnostics. Copy changes to Copied, and Android’s system clipboard preview shows the report text and stack. Direct clipboard reads are unsupported by this emulator; the clipboard preview is the observed proof.

After — Android PR head after fatal/relaunch:

After: Android Diagnostics recovers the fatal message and stack

Limits: these are Debug native clients, so they do not establish store/Release process-termination behavior. On iOS, baseline returned to Springboard while head stayed open before the forced relaunch; the fresh source investigation found no supported logger fix, and the session did not expose native crash-report APIs to establish the cause. Release fatal termination still needs a signed native verification. Pre-existing storage warnings occurred during both baseline/head navigation and were dismissed before capturing Diagnostics. macOS, Windows, and Electron desktop were not exercised. This hook captures fatal errors routed through ErrorUtils after installation. React Native 0.88 sends some uncaught React render failures directly to ExceptionsManager, bypassing this hook; Expo startup records remain the existing coverage for those failures. Native crashes and process kills are outside this hook. A rare multiline error can still appear in both local and Expo records; all raw details remain available.

Implemented with Codex GPT-6.1-Sol; test phase with Codex GPT-6-Astra. Two parallel full-diff review rounds used Claude Opus 5.5 and Codex GPT-6-Sol. Round 1 led to duplicate-record merging, failed-write cleanup, empty-report text, and stored-field normalization fixes. Round 2 found no code blocker within the ErrorUtils scope and identified the render-error and multiline-record limits above; broader React renderer interception was left outside this PR. Harness: Codex in T3 Code.

    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: Path: .coderabbit.config.ts
      • Review profile: CHILL
      • Plan: Team
      • Run ID: d10b04a4-a67b-4a65-9045-01724df43daf
      📥 Commits

      Reviewing files that changed from the base of the PR and between 65fbd78700ac4369b4333cf55548dc35ee42d479 and 4d520ba87589bbec7f8909db0fafd50eb0ee4324.

      📒 Files selected for processing: 6
      • apps/mobile/index.ts
      • apps/mobile/src/features/diagnostics/SettingsDiagnosticsRouteScreen.tsx
      • apps/mobile/src/features/diagnostics/crash-log-model.test.ts
      • apps/mobile/src/features/diagnostics/crash-log-model.ts
      • apps/mobile/src/lib/crashLog.ts
      • docs/user/install.md

      Limit details: You’ve used all 10 included reviews currently available.

      📝 Walkthrough

      The mobile app now saves fatal JavaScript errors and combines them with startup crash records in Settings → Diagnostics. The diagnostics screen remains available when startup-log reading fails. The install guide describes the saved records and report contents.

      Changes: Mobile crash logging and diagnostics

      Layer / File(s)Summary
      Persist fatal crash records
      apps/mobile/src/lib/crashLog.ts, apps/mobile/src/lib/installCrashLog.ts, apps/mobile/index.ts
      Installs a global error handler, saves fatal error records, retains up to 20 crash files, and delegates errors to the previous handler. The app entry point imports the installer.
      Combine and display crash records
      apps/mobile/src/features/diagnostics/crash-log-model.ts, apps/mobile/src/features/diagnostics/SettingsDiagnosticsRouteScreen.tsx, apps/mobile/src/features/diagnostics/crash-log-model.test.ts
      Combines persisted records with matching startup records and displays them in Diagnostics. The screen still displays saved records if startup-log reading fails. Tests cover persistence, recovery, and delegation when persistence fails.
      Document diagnostics
      docs/user/install.md
      Describes the saved fatal errors, startup crashes, report retention, and available stack traces.

      Priority: ⬇️ Low

      Estimated code review effort: 3 (Moderate) | ~25 minutes

      Change: Bug fix

      Sequence Diagram(s)

      sequenceDiagram
        participant GlobalErrorHandler as React Native error handler
        participant CrashLogger as installCrashLogger
        participant FileSystem as crash-logs directory
        participant DiagnosticsScreen as SettingsDiagnosticsRouteScreen
        participant CrashRecordModel as readCrashRecords
        GlobalErrorHandler->>CrashLogger: deliver fatal error
        CrashLogger->>FileSystem: persist crash record
        DiagnosticsScreen->>CrashRecordModel: request records with startup entries
        CrashRecordModel->>FileSystem: read persisted records
        CrashRecordModel->>DiagnosticsScreen: return combined records

      Possibly related PRs

      Suggested labels: 📱 Native Change, size:L

      Suggested reviewers: maria-rcks

      Merge Risk: ⚪ Minimal · up to 4d520

      No actionable issue remains from this review. Native end-to-end validation is still outstanding, but it does not establish a merge-blocking defect.

      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely summarizes the main change: persisting mobile crash diagnostics before fatal runtime handling.
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Description checkPassedThe description is detailed and covers the problem, implementation, verification results, UI evidence, limitations, scope, and agent attribution. It does not use the template headings, and it does not…
      Full details: Description check

      Explanation

      The description is detailed and covers the problem, implementation, verification results, UI evidence, limitations, scope, and agent attribution. It does not use the template headings, and it does not clearly identify an approval comment or explain an approval exemption, but the required information is mostly present.

      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs Human Approval

      Macroscope's review found this PR requires human approval — This PR adds always-on mobile crash capture, persistent local storage of error details, and a broader Diagnostics/reporting workflow. Because these change default product behavior and introduce production-side effects, the change warrants human review.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

      Fix All in Cursor Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start. Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 959a39bf2526e5334b060f1b80f621ca82a874d1. Configure [here](https://www.cursor.com/dashboard/bugbot).
      apps/mobile/src/lib/crashLog.ts line 47OutdatedResolvedby juliusmarminge
      apps/mobile/src/lib/crashLog.ts line 70OutdatedResolvedby juliusmarminge
    5. apps/mobile/src/lib/crashLog.ts lines 40 to 40OutdatedResolvedby juliusmarminge
    6. juliusmarminge added labelsmacroscope-review

    7. juliusmarminge assignedjuliusmarminge

    8. Taking over this one for batch mobile-02. I’ll rebuild it against current main, connect recovered fatal records to diagnostics, and verify synchronous persistence and handler delegation. The existing commits will be preserved; no merge is planned.

Sign in to join this conversation.