Skip to content

fix(runtime): share hot TLS state across provider images - #9805

Closed
proggeramlug wants to merge 4 commits into
PerryTS:mainfrom
proggeramlug:fix/9791-provider-stream-symbols
Closed

fix(runtime): share hot TLS state across provider images#9805
proggeramlug wants to merge 4 commits into
PerryTS:mainfrom
proggeramlug:fix/9791-provider-stream-symbols

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

The native-root provider gate could not load its streamed Response app because the standalone stdlib omitted two required helpers. Retaining/exporting those helpers exposed a second failure: separately built runtime copies assigned unrelated thread-local declarations to the same shared HotTls slot. LLDB showed CURRENT_IMAGE and STATE_PTR both claiming slot 0, corrupting class-image state during module initialization.

Retain/export the strategy-aware ReadableStream constructor and Response body-init reset helper. Give hot TLS declarations stable identities through a shared, non-inlined C registry entry point, and reuse already-published storage before initializing a second provider copy. The cache layout and hot read path remain unchanged. As with the existing provider ABI, the images must come from compatible source builds.

Closes #9791.

Validation on macOS arm64:

  • Rebuilt both providers, both app dylibs, and both hosts with the canonical provider gate's commands and assertions, adapted only to reuse the retained scratch checkout/build cache. The compiler and static linking inputs were frozen from the unchanged base compiler source.
  • Native-root host: 32,768 calls, 11 full collections, and bounded retained live bytes.
  • Response host: normal and forced/verified moving-GC output both match the committed Node oracle. The liveness gate confirms 35 copying minors and 18,190 copied objects.
  • All 16 focused TLS tests pass, including concurrent duplicate-provider first touch, one initializer/destructor per thread, distinct local declarations, and teardown invalidation.
  • Runtime root-holder inventory, thread-local policy, Rust file-size, and Node-version consistency checks pass.

Linux provider validation remains for CI. The previous targeted CI run was canceled while queued during release-runner prioritization; it did not execute. No version bump.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed streamed responses under moving garbage collection by preserving thread-local state and shared provider storage.
    • Restored missing ReadableStream and Response functionality in native-root environments.
    • Improved consistency when multiple runtime providers access shared TLS state.
  • Tests

    • Added regression coverage for shared provider storage, declaration identity, and streamed-response behavior.

@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 5341fca6-4c78-48d8-86a5-8342e6ab3e9b

📥 Commits

Reviewing files that changed from the base of the PR and between c7361c8 and bf3427b.

📒 Files selected for processing (5)
  • changelog.d/9791-provider-stream-constructor.md
  • crates/perry-runtime/src/tls_hot.rs
  • crates/perry-runtime/src/tls_hot/provider_tests.rs
  • tests/fixtures/issue_8075_provider_gc/stdlib-linker.sh
  • tests/fixtures/issue_8075_provider_gc/stdlib-provider/src/lib.rs

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

The runtime now shares thread-local provider storage by named declaration identity. Provider tests cover storage reuse and local declaration separation. The provider fixture retains additional stream and response symbols, and the changelog records the fixes.

Changes

Provider runtime compatibility

Layer / File(s) Summary
Shared TLS slot identity and cache reuse
crates/perry-runtime/src/tls_hot.rs
SlotId uses stable declaration names. A process-wide registry assigns shared slots across provider images. resolve_and_cache reuses values already published in the shared cache.
Provider storage regression coverage
crates/perry-runtime/src/tls_hot.rs, crates/perry-runtime/src/tls_hot/provider_tests.rs
Tests verify shared storage addresses, one initializer and destructor per thread, valid slot indices, and distinct function-local declarations.
Stream and response symbol retention
tests/fixtures/issue_8075_provider_gc/stdlib-linker.sh, tests/fixtures/issue_8075_provider_gc/stdlib-provider/src/lib.rs, changelog.d/9791-provider-stream-constructor.md
The provider export list and linker-pinning function retain the readable-stream constructor and response-body reset symbols. The changelog documents the provider fixes.

Estimated code review effort: 4 (Complex) | ~45 minutes

Merge Risk: ⚪ Minimal · up to bf342

Provider loading symbols and shared TLS storage behavior are covered by the updated implementation and focused tests, with no unresolved merge-blocking risk identified.

Sequence Diagram(s)

sequenceDiagram
  participant ProviderCopyA
  participant js_tls_hot_claim_slot
  participant SharedCache
  participant ProviderCopyB
  ProviderCopyA->>js_tls_hot_claim_slot: claim named declaration slot
  js_tls_hot_claim_slot->>SharedCache: publish slot identity
  ProviderCopyA->>SharedCache: initialize and publish value
  ProviderCopyB->>js_tls_hot_claim_slot: claim the same named declaration
  js_tls_hot_claim_slot-->>ProviderCopyB: return shared slot
  ProviderCopyB->>SharedCache: read published value
  SharedCache-->>ProviderCopyB: reuse cached value
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 52.94% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 4 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary runtime change: sharing hot TLS state across provider images.
Description check ✅ Passed The description provides a clear summary, concrete changes, linked issue, detailed validation results, compatibility constraints, and version-bump information. The optional screenshots section is not …
Linked Issues check ✅ Passed The changes address issue #9791 by retaining and exporting the missing ReadableStream constructor and Response reset helper required for provider dylib loading. The provider-image hot TLS fixes also a…
Out of Scope Changes check ✅ Passed The TLS registry, storage-reuse logic, regression tests, symbol exports, and linker pinning all support provider-image loading and state consistency. No unrelated code changes are evident.
Full details: Docstring Coverage

Explanation

Docstring coverage is 52.94% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 4 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@proggeramlug proggeramlug changed the title fix(test): export the strategy-aware provider stream constructor fix(test): retain and export the provider Response helpers Sep 5, 2026
@proggeramlug proggeramlug changed the title fix(test): retain and export the provider Response helpers fix(runtime): share hot TLS state across provider images Sep 5, 2026
@proggeramlug
proggeramlug marked this pull request as ready for review September 5, 2026 13:21
@proggeramlug

Copy link
Copy Markdown
Contributor Author

Landed on main via merge train #9817 (rebase-merged, so your commits keep their authorship). Thanks!

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.

gc-native-roots: provider dylib fails to dlopen — symbol not found in flat namespace '_js_readable_stream_new_with_strategy_and_source_type'

1 participant