Skip to content

Fix crash when a native task throws a jsi::JSError of another runtime - #60440

Open
tjzel wants to merge 6 commits into
react:mainfrom
tjzel:fix/runtime-scheduler-foreign-jserror
Open

tjzel wants to merge 6 commits into
react:mainfrom
tjzel:fix/runtime-scheduler-foreign-jserror

Conversation

@tjzel

@tjzel tjzel commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Note

This pull request was authored by AI on behalf of @tjzel.

Summary:

Human track

Why

Fixes #60439. Earlier report of the same root cause: #55913.

Libraries that run a second Hermes runtime, such as react-native-worklets, can let a jsi::JSError of that runtime escape from a native callback that the RuntimeScheduler runs on the JS thread, for example a CallInvoker::invokeAsync callback. React Native then reports the error with its value, which belongs to the other runtime, and Hermes crashes when the React Native runtime reads it. The reproducer in the issue crashes with SIGSEGV on 0.88.1.

What

When a native task of the RuntimeScheduler throws a jsi::JSError, React Native now checks whether the error belongs to its own runtime. An error of another runtime is reported as an Error that React Native creates on its own runtime, with the message and stack of the original error. An error of its own runtime is reported unchanged, with its type, properties and identity. The check needs the JS engine to implement the new JSI interface jsi::IValueOwnership (meta/hermes#2361). On engines without it, every error from a native task is rebuilt, which keeps only its message and stack. Tasks that are JS functions are not changed.

The JSI header change mirrors meta/hermes#2361 byte for byte and should come with the next JSI sync from Hermes; this PR includes it so that it builds on its own.

How

A jsi::JSError keeps its message and stack as C++ strings, read when it is created, so they can be read on any runtime. Its value cannot. meta/hermes#2361 adds jsi::IValueOwnership, which a runtime can implement to tell whether a value belongs to it; Hermes implements it.

The change is in the one place that both RuntimeScheduler implementations run native tasks. A jsi::JSError thrown from a native task is caught there. If the runtime implements IValueOwnership and says the error is its own, the error is thrown again unchanged. Otherwise, it is thrown again as a new error, created on the React Native runtime from the strings of the original. The error handlers then always get a value that belongs to the runtime they use.

native task ──throws JSError──► Task::execute
                                  │ runtime implements IValueOwnership and owns the value?
                                  ├─ yes ─► rethrow unchanged
                                  └─ no / no interface ─► rethrow JSError(RN runtime, message, stack)
                                  ▼
          RuntimeScheduler catch ──► JsErrorHandler ──► ErrorUtils.reportFatalError

This PR does not cover a foreign jsi::JSError that a synchronous host function lets escape into JS. Hermes rethrows such an error into JS at the host function boundary, before React Native sees it. meta/hermes#2360 fixes that path in Hermes. The reproducer shows both cases.

Changelog:

[GENERAL] [FIXED] - Fix a crash when a native task on the JS thread throws a jsi::JSError of another JS runtime

Test Plan:

Testing

Two new RuntimeScheduler unit tests run for both the legacy and the modern scheduler:

  1. A native task makes a second Hermes runtime throw, and the reported error must be an Error with the original message.
  2. A native task throws an error of the React Native runtime, which must still be reported with its message.

Four more RuntimeScheduler tests run a native task on a wrapper runtime that implements IValueOwnership with a fixed answer, because the Hermes binary that the test build links does not have the interface yet:

  1. With the answer "own", an own TypeError with a custom property is reported as the same object, with its name and property.
  2. With the answer "foreign", the same error is rebuilt as an Error with the original message.
  3. With the answer "foreign", an error of a second Hermes runtime is reported with its message.
  4. With the interface hidden, an own error is rebuilt, as on engines without the interface.

Without the Task::execute change, the first test fails and the others pass. The scheduler and React instance tests also pass against a Hermes build with meta/hermes#2360 and meta/hermes#2361, where the existing test with an error of a second runtime goes through the real Hermes implementation. Two death tests fail there because they expect a crash that meta/hermes#2360 prevents. The device reproduction was not repeated with this version.

### Alternatives, replace item 1 and 2:

  1. Rebuild every caught jsi::JSError in the scheduler, as in the first version of this PR and in Fix LogBox parsing for cross-runtime jsi::JSErrors #55994 (open, marked stale) and Fixes LogBox displaying "Unknown" when an exception is thrown from an… #56000 (closed as a duplicate of Fix LogBox parsing for cross-runtime jsi::JSErrors #55994). Errors of the React Native runtime thrown by a native task then lose their type and extra properties such as componentStack and cause. This PR still does that, but only on engines without IValueOwnership.
  2. Add a method to jsi::Runtime that reports which runtime a value belongs to. That needs a default implementation in every JSI runtime and changes the Runtime ABI; an optional interface found with castInterface does not.

Agent track, add under ### Files:

  • packages/react-native/ReactCommon/jsi/jsi/jsi.h: IValueOwnership (UUID f92f55b7-3d5c-441e-8b2d-7e88f267cd40), identical to API/jsi/jsi/jsi.h of Add jsi::IValueOwnership to tell whether a value belongs to a runtime meta/hermes#2361 (the RN copy was byte-identical to Hermes static_h before).
  • Task.cpp: isOwnValue(runtime, value) = castInterface<IValueOwnership>(&runtime) != nullptr && ->isOwnValue(value); own → throw;, else throw recreateJSErrorInRuntime(runtime, error);.
  • tests/RuntimeSchedulerTest.cpp: ValueOwnershipRuntime (RuntimeDecorator<jsi::Runtime> + IValueOwnership, modes Own/Foreign/Unavailable), fixture executor passes it when set; tests handlingOwnErrorInRawCallbackKeepsTheError, handlingErrorReportedAsForeignInRawCallbackRebuildsTheError, handlingErrorOfAnotherRuntimeReportedAsForeignInRawCallback, handlingOwnErrorInRawCallbackWithoutValueOwnershipRebuildsTheError.
  • tests/StubErrorUtils.h: reportFatalError stores the reported value as global.lastReportedError.

Results at the new head: react_renderer_runtimescheduler_tests 110/110, react_runtime_tests 45 passed / 9 skipped (prebuilt Hermes). Against Hermes 9d0c4fcaf (#2360 on #2361, no JSI_UNSTABLE): scheduler -*/0 60/60 (*/0 aborts on MicrotaskQueue must be enabled, Hermes static_h vs RN main), react_runtime_tests 44 passed / 8 skipped / F3, H3 death tests fail (no crash any more).

Changelog line: unchanged.

The whole RuntimeScheduler test suite passes locally with this change. Without the change, the first test fails on the legacy scheduler and crashes the test process with SIGSEGV on the modern scheduler.

On a device, the reproducer from #60439 crashes on 0.88.1 (POCO X3 Pro, Android 11), and the same callback does not crash when it converts the error itself, which is what this change does inside React Native. With this change built into the reproducer app (ReactAndroid from source on 0.88.1 with this patch), variant A no longer crashes and shows a RedBox with the original message.

Startup cases (reproducer variants F, G, H on a device, with and without this change, 3 cold starts each): a foreign jsi::JSError thrown by a synchronous TurboModule method (F) or by a host function on global (H) at module scope of index.js, and one thrown by an app BindingsInstaller in the initializeRuntime task (G). None crashes before or after this change, and the output does not change. This change does not cover F and H: Hermes moves the foreign value into the runtime at the host function boundary, before Task::execute sees it, and they crash as soon as a GC runs while the error is reported (variants F3/H3), with or without this change. G reaches the error handler as an Error of the React Native runtime with this change. After startup, a host function on global called from a setTimeout callback (I) crashes without this change. With it, it shows a RedBox with an empty message instead of crashing, because the foreign value already entered the runtime at the host function boundary.

Every way a jsi::JSError of another runtime can reach React Native

Device results are from React Native 0.88.1 Debug on an Android 11 phone (arm64), 3 cold starts per variant for F to I2. The C++ tests run on the macOS host build.

Variant Where the error escapes Without this change With this change Test
A a native task scheduled with invokeAsync crash RedBox with the original message normal; crashes without this change
B a sync TurboModule method, after startup crash not run on device skipped
C like A, the other runtime is destroyed while the error unwinds crash crash skipped
D like A, the error is rebuilt on the React Native runtime first RedBox RedBox normal
E like B, the error is rebuilt on the React Native runtime first JS catches it JS catches it normal
F a sync TurboModule method, while the bundle evaluates RedBox, message lost same skipped
F2 like F, the other runtime is destroyed while the error unwinds crash crash skipped
F3 like F, a garbage collection runs while React Native reports the error crash in the GC crash in the GC death test
G a bindings installer, before the bundle evaluates RedBox with the original message same on screen; the error handler gets an Error of the React Native runtime normal; crashes without this change on the host build
H a host function on global, while the bundle evaluates RedBox, message lost same skipped
H2 like H, the other runtime is destroyed while the error unwinds crash crash skipped
H3 like H, plus the garbage collection of F3 crash in the GC crash in the GC death test
I a host function on global, in a setTimeout callback crash RedBox, message lost skipped
I2 like I, the other runtime is destroyed while the error unwinds crash crash skipped

This change cannot fix the variants where the error passes through a host function (B, F to F3, H to I2): Hermes stores the error of the other runtime in the React Native runtime at the host function boundary, before React Native code sees it, so the value is already corrupted. In C, F2, H2 and I2 the error itself points into a runtime that no longer exists, and React Native crashes as soon as it releases it. The skipped tests crash on the macOS host build but not on the Android phone, so their outcome depends on how Hermes lays out its heap; the death tests force a garbage collection, which crashed on both. The tests with a destroyed runtime (C, F2, H2, I2) are skipped too: they rely on reading freed memory, which crashed on macOS and on the phone, but not on the Linux CI runner.

The variants that this change cannot fix (an error that leaves a host function) are addressed in Hermes by meta/hermes#2360, which rebuilds a jsi::JSError of another runtime as an Error of the calling runtime at the host function boundary.

Performance

No measurement. The change adds a try/catch around native tasks, which costs nothing unless the task throws.

Alternatives

  1. Rebuild every caught jsi::JSError in the scheduler, as in Fix LogBox parsing for cross-runtime jsi::JSErrors #55994 (open, marked stale) and Fixes LogBox displaying "Unknown" when an exception is thrown from an… #56000 (closed as a duplicate of Fix LogBox parsing for cross-runtime jsi::JSErrors #55994). That also rebuilds errors thrown by JS functions, which always belong to the React Native runtime, and drops their extra properties such as componentStack and cause.
  2. Let JSI report which runtime a value or a jsi::JSError belongs to. That is a JSI and Hermes API change, much larger than this fix. The Hermes maintainers consider passing a value to another runtime a bug in the caller (JSError outliving its host runtime leads to crashes on deconstructor invocation meta/hermes#1927).
  3. Fix it in every library that runs a second runtime. Libraries already try, but any native callback that a user can reach with a raw runtime is enough to crash the app, and React Native cannot show the error then.

Agent track

Details

Files

  • packages/react-native/ReactCommon/react/renderer/runtimescheduler/Task.cpp: Task::execute wraps the RawCallback call in try { ... } catch (const jsi::JSError& error) { throw recreateJSErrorInRuntime(runtime, error); }. recreateJSErrorInRuntime creates jsi::JSError(runtime, error.getMessage()) (which uses IRuntime::createError, so the value is a real Error with the right prototype), sets its stack property to error.getStack(), and returns jsi::JSError(jsi::Value(errorObject), error.getMessage(), error.getStack()). The last constructor does not call setValue, so getMessage()/getStack() stay equal to the original strings, which JsErrorHandler::handleErrorWithCppPipeline uses for rawStack and originalMessage.
  • tests/RuntimeSchedulerTest.cpp: handlingErrorOfAnotherRuntimeInRawCallback, handlingErrorInRawCallback.
  • tests/StubErrorUtils.h: reportFatalError stub records the message of the reported value when it is instanceof Error (getLastReportedErrorMessage()), so the tests also check that the reported value is a real Error and not the plain object that jsi::JSError(rt, message, stack) creates (the problem described in Poor handling of exceptions from extra Hermes Runtimes #55913).

Why Task::execute

  • Both RuntimeScheduler_Legacy::executeTask (task->execute) and RuntimeScheduler_Modern::executeTask (task.execute) go through it, so one change covers both schedulers and all their catch sites (callExpiredTasks, startWorkLoop, executeTask).
  • The jsi::Function branch is left alone. jsi::Function::call throws a jsi::JSError that Hermes builds from the thrown value of its own heap (HermesRuntimeImpl::throwPendingError ends with throw jsi::JSError(std::move(jsiVal), msg, stack), https://github.com/facebook/hermes/blob/7a9359527cb174f438395cb105c03473f1a6409c/API/hermes/hermes.cpp#L3186-L3252, the Hermes revision RN main builds), so its value belongs to runtime and keeps all its properties (componentStack, cause, RN$ErrorExtraDataKey).
  • jsi::JSError stores message_ and stack_ as std::string, filled in the constructor on the throwing runtime (JSError::setValue in ReactCommon/jsi/jsi/jsi.cpp). value() returns a jsi::Value whose PointerValue belongs to the throwing runtime. JSI has no API that maps a value to its runtime.

What stays broken (not in scope)

  • A foreign jsi::JSError thrown from a synchronous host function (TurboModule method called from JS): Hermes catches it at the host function boundary with catch (const jsi::JSError &error) { return rt_.runtime_.setThrownValue(hvFromValue(error.value())); } (https://github.com/facebook/hermes/blob/7a9359527cb174f438395cb105c03473f1a6409c/API/hermes/hermes.cpp#L881-L882), so the React Native runtime holds a value of the other heap before React Native sees it. Reproducer variant B, crashes with the same stack as A. Fix belongs to the library.
  • The other runtime destroyed while its jsi::JSError is still alive: the destructor of the exception object releases a PointerValue of a freed runtime (reproducer variant C, JSError outliving its host runtime leads to crashes on deconstructor invocation meta/hermes#1927). Task::execute cannot help, the exception object outlives the runtime.
  • ReactInstance runs runtimeExecutor callbacks outside the scheduler with its own catch (jsi::JSError&) (ReactCommon/react/runtime/ReactInstance.cpp, the jsThread->runOnQueue lambda). Not changed here; the reproducer path goes through RuntimeSchedulerCallInvoker.

Commands and results

yarn install --frozen-lockfile
yarn --cwd packages/react-native-codegen build
./gradlew :private:react-native-fantom:configureFantomTester -x :packages:react-native:ReactAndroid:buildCodegenCLI
cmake --build private/react-native-fantom/build/tester --target react_renderer_runtimescheduler_tests
private/react-native-fantom/build/tester/react-common-tests/react_renderer_runtimescheduler_tests
  • With the change: [ PASSED ] 102 tests. (/0 = legacy, /1 = modern scheduler).
  • Without the Task.cpp change: handlingErrorOfAnotherRuntimeInRawCallback/0 fails (getLastReportedErrorMessage() is "", expected "Error of another runtime"), handlingErrorOfAnotherRuntimeInRawCallback/1 crashes the process (exit code 139, SIGSEGV).
  • buildCodegenCLI was skipped only because its build.sh runs yarn install in a temporary directory and picked a global Yarn 4 on the test machine; the codegen lib/ was built with the repository's Yarn 1 instead.
  • Formatting: dotslash scripts/clang-format -i (clang-format 21.1.2) on the three files.

Device reproduction (0.88.1, POCO X3 Pro, Android 11, Debug build with embedded bundle)

  • Variant A (invokeAsync callback throws on the second runtime): Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR) on mqt_v_js; frames handleJSError -> JsErrorHandler::handleError -> RuntimeScheduler_Modern::handleTaskError -> RuntimeScheduler_Modern::executeTask.
  • Variant D (same callback, throw jsi::JSError(rnRuntime, error.getMessage())): no crash, RedBox "Error: thrown on the second runtime".

Related

Tests per variant

Tests (all in packages/react-native/ReactCommon/react/runtime/tests/cxx/ReactInstanceTest.cpp unless noted):

Variant Test Kind macOS host, with fix macOS host, without fix
A ReactInstanceTest.testNativeTaskThrowsErrorOfAnotherRuntime normal OK SIGSEGV
A RuntimeSchedulerTest.handlingErrorOfAnotherRuntimeInRawCallback/{0,1} (renderer/runtimescheduler/tests/RuntimeSchedulerTest.cpp) normal OK /0 FAILED (message ""), /1 SIGSEGV
B ReactInstanceTest.testNativeModuleMethodThrowsErrorOfAnotherRuntime GTEST_SKIP skipped (SIGSEGV 3/3 when unskipped) skipped (SIGSEGV 3/3 when unskipped)
C ReactInstanceDeathTest.testNativeTaskThrowsErrorOfDestroyedRuntime GTEST_SKIP skipped (died on macOS and Android; failed to die on Linux CI) skipped
D ReactInstanceTest.testNativeTaskThrowsErrorConvertedFromAnotherRuntime normal OK OK
E ReactInstanceTest.testNativeModuleMethodThrowsErrorConvertedFromAnotherRuntime normal OK OK
F ReactInstanceTest.testNativeModuleMethodThrowsErrorOfAnotherRuntimeDuringBundleEvaluation GTEST_SKIP skipped (SIGSEGV 3/3 when unskipped) skipped (SIGSEGV 3/3 when unskipped)
F2 ReactInstanceDeathTest.testNativeModuleMethodThrowsErrorOfDestroyedRuntimeDuringBundleEvaluation GTEST_SKIP skipped (died on macOS and Android; failed to die on Linux CI) skipped
F3 ReactInstanceDeathTest.testNativeModuleMethodThrowsErrorOfAnotherRuntimeDuringBundleEvaluationAndGarbageCollection death dies dies
G ReactInstanceTest.testBindingsInstallerThrowsErrorOfAnotherRuntime normal OK SIGSEGV
H ReactInstanceTest.testGlobalHostFunctionThrowsErrorOfAnotherRuntimeDuringBundleEvaluation GTEST_SKIP skipped (SIGSEGV 3/3 when unskipped) skipped (SIGSEGV 3/3 when unskipped)
H2 ReactInstanceDeathTest.testGlobalHostFunctionThrowsErrorOfDestroyedRuntimeDuringBundleEvaluation GTEST_SKIP skipped (died on macOS and Android; failed to die on Linux CI) skipped
H3 ReactInstanceDeathTest.testGlobalHostFunctionThrowsErrorOfAnotherRuntimeDuringBundleEvaluationAndGarbageCollection death dies dies
I ReactInstanceTest.testGlobalHostFunctionThrowsErrorOfAnotherRuntimeInTimer GTEST_SKIP skipped (SIGSEGV 3/3 when unskipped) skipped (SIGSEGV 3/3 when unskipped)
I2 ReactInstanceDeathTest.testGlobalHostFunctionThrowsErrorOfDestroyedRuntimeInTimer GTEST_SKIP skipped (died on macOS and Android; failed to die on Linux CI) skipped
  • Build: cmake --build private/react-native-fantom/build/tester --target react_runtime_tests react_renderer_runtimescheduler_tests. With the fix, 3 full runs: react_runtime_tests 49 passed / 5 skipped (one pre-existing skip), react_renderer_runtimescheduler_tests 102 passed.
  • The F3/H3 garbage collection is forced from global.__getBundleMetadata, which JsErrorHandler::handleErrorWithCppPipeline calls while it reports the error (ReactCommon/jserrorhandler/JsErrorHandler.cpp:98).
  • The death tests use death_test_style = "threadsafe" because Hermes starts threads before the fork.
  • Host-function root cause: Hermes HFContext::func (API/hermes/hermes.cpp) does setThrownValue(hvFromValue(error.value())), which moves the pointer of the other runtime's object into the React Native heap. On the macOS host (non-contiguous heap) the crash comes earlier, in throwPendingError → getNamedWithReceiver while Hermes reads the error message.
  • Inference, not verified: the CI job runs on Linux x86_64, where Hermes uses a contiguous heap like Android, so the skipped variants would not crash there. C relies on a use-after-free of the destroyed runtime; it crashed every time on macOS and on Android, but a use-after-free is not guaranteed to crash (see the note in react/renderer/scheduler/tests/SchedulerDelegateInvalidationTest.cpp about flaky death tests).

A native callback that the RuntimeScheduler runs on the JS thread can let a
jsi::JSError of another jsi::Runtime escape. The error handlers then pass its
value, which belongs to that other runtime, to ErrorUtils on the React Native
runtime, and Hermes crashes.

Task::execute now rethrows a jsi::JSError that escapes a raw callback as a new
Error created on the React Native runtime, with the message and stack of the
original error. jsi::JSError keeps both as std::string, so reading them does
not touch the other runtime.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 1, 2026
@facebook-github-tools facebook-github-tools Bot added p: Software Mansion Partner: Software Mansion Partner labels Dec 1, 2026
@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Dec 1, 2026
…eact Native

ReactInstanceTest covers each way a native callback can let a jsi::JSError
of a second Hermes runtime escape into React Native: a raw task scheduled
with invokeAsync, a bindings installer, a native module method and a global
host function, during bundle evaluation and after startup.

The raw task and bindings installer cases now report an Error of the React
Native runtime. The cases where the second runtime is destroyed, or where
the React Native runtime collects garbage while it holds the foreign error,
still crash and run as death tests. The host function cases without such a
trigger are skipped: Hermes stores the foreign error in the React Native
runtime at the host function boundary, so their outcome depends on the
Hermes heap layout.
@tjzel
tjzel marked this pull request as ready for review December 1, 2026 22:21
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Dec 1, 2026

@javache javache left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Letting errors from one runtime leak into another seems like a library error. The proposed PR will drop all metadata from an error just to bypass the crash, which is not desirable.

@tjzel

tjzel commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

I agree that it is a library error but it falsely suggests that React Native failed as its error handlers are crashing.

What kind of metadata do you mean? I thought that re-creating the error with the message and stack would be sufficient here.

@BruceBotterson

Copy link
Copy Markdown

Hi, Bruce here.
Model: Claude Opus 5.5 (claude-opus-5-5) · Session: owner session Anna @lazy-chunks

On the metadata question, checked against the code: the loss is real, but it hits errors of the React Native runtime, not the foreign ones.

Task::execute cannot tell whose error it caught, so this PR rebuilds every jsi::JSError that leaves a native task. That includes errors of the React Native runtime itself, for example a JS function that a native task calls and that throws. For those, the rebuilt Error drops what JsErrorHandler::handleErrorWithCppPipeline reads from the original object (packages/react-native/ReactCommon/jserrorhandler/JsErrorHandler.cpp:266-312):

  1. name: a TypeError becomes Error;
  2. componentStack;
  3. the RN$ErrorExtraDataKey extra data and jsEngine;
  4. cause, and the stackSymbols, stackReturnAddresses and stackElements read from it;
  5. any other custom property, and the identity of the object.

For a foreign error, message and stack are all that can be read safely, so rebuilding them is enough there.

So the change is only safe if it rebuilds foreign errors and leaves own errors untouched. JSI has no way to ask which runtime a value belongs to, so React Native cannot do that on its own. Hermes can: meta/hermes#2360 checks whether the error's PointerValue was created by the calling runtime (an address comparison against its hermesValues_ list, which never reads the foreign memory). It keeps own errors exactly as they are, and rebuilds only foreign ones at the host function boundary. That is the path that this PR cannot cover anyway.

Two ways forward:

  1. Close this PR in favor of Rebuild a JSError of another runtime when it escapes a host function meta/hermes#2360, and keep the native-task case (variant A) as a library rule. Libraries must not let a jsi::JSError of their own runtime leave a task that React Native runs.
  2. Narrow this PR to foreign errors only, once the runtime exposes an ownership check (for example the Hermes check from Rebuild a JSError of another runtime when it escapes a host function meta/hermes#2360 through a JSI interface). Own errors then keep all their properties.

@tjzel

tjzel commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

That's a bummer then

Add jsi::IValueOwnership to the JSI header, mirroring the Hermes change.
When a raw callback of a task throws a jsi::JSError, Task::execute
rethrows it unchanged if the runtime implements IValueOwnership and
reports the error value as its own, so that the error keeps its identity,
name and custom properties. Errors of another runtime, and every error of
a runtime without the interface, are still rebuilt in the runtime.
@BruceBotterson

Copy link
Copy Markdown

Hi, Bruce here.
Model: Claude Opus 5.5 (claude-opus-5-5) · Session: owner session Anna @lazy-chunks

Updated to address the metadata concern (f0a6c10). Task::execute now rebuilds an error only when it belongs to another runtime. An error of React Native's own runtime is rethrown unchanged, with its type, componentStack, extra data, cause and identity.

To tell the two apart, the runtime has to implement a new JSI interface, jsi::IValueOwnership (bool isOwnValue(const Value&)), proposed in meta/hermes#2361 and implemented there for Hermes. On engines without the interface, the PR keeps the previous behavior and rebuilds every error from a native task. The jsi.h change here mirrors meta/hermes#2361 so that the PR builds on its own.

meta/hermes#2360, stacked on #2361, uses the same check at Hermes' host function boundary, which covers the case that React Native cannot see.

tjzel added 2 commits December 2, 2026 22:33
…/runtime-scheduler-foreign-jserror

# Conflicts:
#	packages/react-native/ReactCommon/react/renderer/runtimescheduler/tests/RuntimeSchedulerTest.cpp

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

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. p: Software Mansion Partner: Software Mansion Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash when a jsi::JSError of another Hermes runtime escapes a native task on the JS thread

3 participants