Skip to content

fix(runtime): ignore a stale error-report marker - #2124

Draft
edusperoni wants to merge 1 commit into
mainfrom
fix/stale-error-marker
Draft

edusperoni wants to merge 1 commit into
mainfrom
fix/stale-error-marker

Conversation

@edusperoni

Copy link
Copy Markdown
Collaborator

Description

Symptom. In a debug build, after a crash whose error screen never appeared, the next normal launch of the app crashes before any JavaScript runs:

  • with an SBG-generated launcher activity: Cannot initialize an instance of com.tns.NativeScriptActivity: no NativeScript runtime is bound to thread "main";
  • with a launcher activity generated at runtime: ClassNotFoundException: com.tns.NativeScriptActivity (no JavaScript ran, so nothing registered it).

The launch after that one works.

Root cause.

  • On an uncaught error, ErrorReport.startActivity writes files/hasError (test-app/app/src/debug/java/com/tns/ErrorReport.java:144), sends the pending intent for ErrorReportActivity (:147) and kills the process (:152).
  • The next process start reads that marker in RuntimeHelper.hasErrorIntent (test-app/app/src/main/java/com/tns/RuntimeHelper.java:30-58), deletes it, and initRuntime then skips runtime initialization (:79-80). That way the error activity can show without re-running the failing code.
  • Android can block the error activity's start. On API 35 a crash inside Application.onCreate counts as a background activity launch, and logcat shows Background activity launch blocked! … ErrorReportActivity … (BAL_BLOCK).
  • When that happens, no process starts for the error activity, and the marker survives. The next launch of any other activity (the user's, or the CLI's after a rebuild) consumes it and skips runtime init.

Fix. The marker still gets deleted on every start. It now counts only when one of the app's tasks has com.tns.ErrorReportActivity on top (ActivityManager.getAppTasks(), with topActivity on API 23+ and baseIntent's component before that). At Application.onCreate time, the activity the process is starting for is already the top of its task. If the tasks can't be read, the old behaviour stays.

Does your commit message include the wording below to reference a specific issue in this repo?

No issue. It was found while bringing up the @nativescript/vite dev boot on Android.

Related Pull Requests

None.

Does your pull request have unit tests?

No. The decision depends on ActivityManager state at process start, and the app module has no JVM test harness. Verified manually on an API 35 emulator (Pixel 9 Pro image) with @nativescript/android 9.1.2-next.2026-11-18 (this branch's base commit, a12106397). The test app had this RuntimeHelper.java patched into its generated platforms/android project and was rebuilt through the CLI.

Stale marker:

  • Stock RuntimeHelper: run-as <app> touch files/hasError, then a normal am start crashed with ClassNotFoundException: com.tns.NativeScriptActivity.
  • Patched: the same steps gave a normal launch, the app connected to its dev server, and the marker was gone.

Blocked error activity:

  • A throw at the top of the app's bundle.mjs crashed Application.onCreate, and the system logged BAL_BLOCK for ErrorReportActivity.
  • With the patch, the next am start launched the app normally.

Error activity still shows: with the app visible, a delayed Thread.getDefaultUncaughtExceptionHandler().uncaughtException(…) started ErrorReportActivity (BAL_ALLOW_VISIBLE_WINDOW). Its new process honored the marker, the error screen showed the exception, and the marker was consumed.

@coderabbitai

coderabbitai Bot commented Nov 20, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

ErrorReport writes files/hasError before it starts ErrorReportActivity, and
the next process start consumes it to skip runtime init so the error screen
can show. When Android blocks the error activity's start (a crash during
Application.onCreate on API 35 is a background activity launch), the marker
survives, and the next normal launch skips runtime init and crashes.

The marker now counts only when one of the app's tasks has
ErrorReportActivity on top, i.e. the process is starting for it.
@edusperoni
edusperoni force-pushed the fix/stale-error-marker branch from 5256901 to 165aff2 Compare November 20, 2026 13:15

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant