Skip to content

test(runtime): leak probe flake fixes; run Catalyst without XCUITest - #603

Merged
edusperoni merged 4 commits into
mainfrom
fix/leak-probe-planted-flake
Nov 23, 2026
Merged

edusperoni merged 4 commits into
mainfrom
fix/leak-probe-planted-flake

Conversation

@edusperoni

@edusperoni edusperoni commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes an intermittent failure in the leak probe's "planted shapes" specs, and adds a way to run the Mac Catalyst suite without XCUITest.

Flake

On the Mac Catalyst lane (V8 with JIT, default resurrecting mode), "reports TNSLeakBlockCycle / TNSLeakSelfHandler by default only when it leaks under this mode" failed intermittently while the other shapes passed. Example: run 44962227647 on #595.

  • Cause: the first nine planted shapes were built in one function scope, so all their closures shared one V8 context.
    • If any root reached any of those closures, the whole context became reachable, and BlockCycle and SelfHandler then correctly read as non-leaks.
    • Forcing a root through a neighbouring shape (another shape's operation kept alive by an owner the probe can't see) flips exactly that pair, both on main and on the failing CI tree.
    • On the CI tree, which predates fix(runtime): leak probe review fixes #591, a wrapper first dying in the snapshot's own collection also flips exactly that pair. fix(runtime): leak probe review fixes #591's settle closes that path on main.
    • The heap dump shows the pair reached via (Global handles) → callback → shared context.
  • Fix: each shape is planted in its own scope, as the file's comment already required. The later shapes already followed that rule.
  • Ruled out:
    • an undrained autorelease pool (that would also break the WeakMap shapes, which passed);
    • KeepDuringJob;
    • conservative stack scanning;
    • deferred releases (none in the planted window across instrumented runs).
  • Caveat: the failure never reproduced on its own locally (about 26 full Catalyst runs and 60+ focused loops on Catalyst and the simulator). This removes the coupling between shapes. What held the objects in that one CI run wasn't identified.

run_tests.sh --catalyst --no-xctest

  • What it does: builds the Catalyst TestRunner and launches the app binary directly, like running it from Xcode. It mirrors the runtime's os_log to stderr (OS_ACTIVITY_DT_MODE=1) into <test folder>/console.log, waits for the junit report or the end marker, then terminates the app, which never quits on its own.
  • Why: XCUITest on macOS needs Automation Mode, which asks for an admin password and so can't run unattended on a dev machine.
  • When it fails: on failing specs, a summary other than SUCCESS, a crash before the report, or a 15-minute hang.
  • Other options:
    • It combines with --wrapper-lifetime <mode>[:<scope>]: the mode's build setting is passed to the build, and the mode check runs on the report.
    • --asan is rejected.
  • Limit: there's no host HTTP server, so the specs that need it are skipped (37 vs 11 on CI).

Releases waiting for the runtime's thread

The probe's settle step drained the wrapper-lifetime release queue but not ObjectManager's deferred releases: native releases (and Block_releases) a finalizer queued because they must run on the runtime's thread. An object waiting there is alive but has no wrapper. The probe never walked it, so anything it owned, such as a JS block whose callback is strong, read as a JS root and could hide a cycle.

  • ObjectManager::RunDeferredReleases(isolate) runs the existing DrainDeferredReleases when called on the runtime's thread, and does nothing elsewhere.
  • The host's drainReleases (used by every settle round) now calls it first. There is no SPI change (kVersion stays 3).
  • New spec, "finds a cycle that an object waiting for its release on the runtime's thread shared": a block cycle whose operation is also held by an array that a background-queue release puts in the deferred queue right before the probe runs. It fails without the drain, in resurrecting and canary.

Testing

  • Focused planted-shapes loops, 20 iterations each, 0 failures: Catalyst and simulator, in resurrecting, rooted/all and canary/all.
  • Full suite on the simulator, 2169 specs, 0 failures: resurrecting/extended, rooted/all, canary/all, canary/extended.
  • With the drain: 2170 specs, 0 failures in resurrecting/extended, rooted/all, canary/all, canary/extended and ASan canary/all; --catalyst --no-xctest 2171 specs, 0 failures.
  • --catalyst --no-xctest, 2170 specs, 0 failures: resurrecting/extended, and --wrapper-lifetime canary:all (mode check passed).

The first planted shapes shared one function scope, so their closures
shared one context. Anything that kept one of those closures reachable
(an object meant to die that a collection had not finalized yet, or a
transient retain on one shape's objects) made the whole context, and
every shape closing over a variable in it, reachable from a root, and
the probe then correctly reported none of those cycles.
TNSLeakBlockCycle and TNSLeakSelfHandler failed together that way on
the Mac Catalyst lane. Keeping TNSLeakWeakHandler, whose handler shares
the context, alive at the snapshot reproduces exactly that pair.

Give every shape its own scope, as the later shapes already had.
`./run_tests.sh --catalyst --no-xctest` builds TestRunner for Mac
Catalyst and launches the app itself instead of through XCUITest, so it
needs no Automation Mode. The runtime's console goes to console.log in
the test folder (OS_ACTIVITY_DT_MODE mirrors os_log to stderr), the app
is quit once its junit report appears in the test folder's home
(CFFIXED_USER_HOME), and the run fails on failing specs, a final summary
other than SUCCESS, a crash before the report, or no report within 15
minutes. Without the XCTest host's HTTP server, the specs that need one
are skipped.
@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 57 minutes.

Check out review usage here.

View limit details

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

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1d777b4d-a77a-44d5-8ffa-1a4658d8f402
Commits

Reviewing files that changed from the base of the PR and between db5c9e3 and 0c852c9.

Files selected for processing: 8

  • NativeScript/runtime/LeakProbe.mm
  • NativeScript/runtime/LeakProbeSPI.h
  • NativeScript/runtime/ObjectManager.h
  • NativeScript/runtime/ObjectManager.mm
  • NativeScriptLeakProbe/NativeScriptLeakProbe.mm
  • TestRunner/app/tests/NativeCallbackSelfTests.js
  • TestRunner/app/tests/WrapperLifetimeLeaksTests.js
  • run_tests.sh
  • 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

…a leak probe

An explicit release or a collection on another thread hands the native
release of an object first wrapped on the runtime's thread to an event
loop task. Until that task runs the object is alive with no wrapper, so
the probe never walks it, and anything it owns (a JS block whose callback
handle is strong) reads as owned from outside, hiding cycles through it.

The probe's settle drain now also makes those deferred releases, on the
runtime's thread only. The host SPI is unchanged: drainReleases covers
them.
@edusperoni edusperoni changed the title test(runtime): plant each leak shape in its own scope; run Catalyst without XCUITest test(runtime): leak probe flake fixes; run Catalyst without XCUITest Nov 23, 2026
The specs in NativeCallbackSelfTests.js (and its beforeEach) settle with
several rounds of two full collections each. Under ASan, on the large heap
late in the suite, that can outlast Jasmine's default 5 s async timeout,
as it did on CI for the owned C function primitive results spec.
@edusperoni
edusperoni marked this pull request as ready for review November 23, 2026 03:31
@edusperoni
edusperoni merged commit 8d0a4f1 into main Nov 23, 2026
14 checks passed
@edusperoni
edusperoni deleted the fix/leak-probe-planted-flake branch November 23, 2026 03:33
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