Skip to content

fix(rivetkit-native): expose full hibernation metadata to JS#4657

Draft
NathanFlurry wants to merge 1 commit intobreak-up/persist-hibernating-requestsfrom
break-up/expose-hibernation-metadata
Draft

fix(rivetkit-native): expose full hibernation metadata to JS#4657
NathanFlurry wants to merge 1 commit intobreak-up/persist-hibernating-requestsfrom
break-up/expose-hibernation-metadata

Conversation

@NathanFlurry
Copy link
Copy Markdown
Member

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copy link
Copy Markdown
Member Author

NathanFlurry commented Apr 14, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@claude
Copy link
Copy Markdown

claude bot commented Apr 14, 2026

PR Review

This PR fixes two genuine correctness bugs in the native envoy hibernation path.

  1. can_hibernate was always returning false (stub), making WebSocket hibernation non-functional.
  2. restore_hibernating_requests was restoring sessions with zeroed-out message indices, empty path, and empty headers.

Both are real bugs and the general approach is correct.


Medium: ThreadsafeFunctionCallMode::Blocking should be NonBlocking in can_hibernate. Using Blocking mode can deadlock if the JS thread is already processing another TSFN call. Every other event_cb.call() in the file uses NonBlocking, and NonBlocking is sufficient since the response arrives via rx.blocking_recv().


Low: Response map entry is leaked on error in can_hibernate. If rx.blocking_recv() returns Err, the entry for response_id is never removed from response_map. The async paths clean up correctly but the synchronous path does not.


Low: The dual canHibernate call pattern is undocumented. wrapper.js calls canHibernate in two distinct places. A comment explaining when each is called would help maintainers.


Nit: r.headers.unwrap_or_else(HashMap::new) is more idiomatic as r.headers.unwrap_or_default().


Positive: Switching ResponseMap to std::sync::Mutex is correct given that can_hibernate is a synchronous fn using block_in_place. Keeping WsSenderMap as tokio::sync::Mutex is also correct.


No tests added. The can_hibernate round-trip and hibernation restore with real metadata are non-trivial. An integration test covering the hibernation/wake-up cycle through the native bridge would help prevent regressions.

@NathanFlurry NathanFlurry force-pushed the break-up/expose-hibernation-metadata branch from 26f98bc to fde1e0b Compare April 15, 2026 02:40
@NathanFlurry NathanFlurry force-pushed the break-up/persist-hibernating-requests branch from 88f4613 to ae4fe54 Compare April 15, 2026 02:50
@NathanFlurry NathanFlurry force-pushed the break-up/expose-hibernation-metadata branch from fde1e0b to 789b9cd Compare April 15, 2026 02:50
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