Skip to content

fix(rivetkit-core): return None for empty inspector state to avoid frontend CBOR decode error#4732

Draft
NathanFlurry wants to merge 1 commit into04-23-fix_rivetkit-core_don_t_install_tokio_signal_ctrl_c_handler_inside_serve_with_configfrom
04-23-fix_rivetkit-core_return_none_for_empty_inspector_state_to_avoid_frontend_cbor_decode_error
Draft

fix(rivetkit-core): return None for empty inspector state to avoid frontend CBOR decode error#4732
NathanFlurry wants to merge 1 commit into04-23-fix_rivetkit-core_don_t_install_tokio_signal_ctrl_c_handler_inside_serve_with_configfrom
04-23-fix_rivetkit-core_return_none_for_empty_inspector_state_to_avoid_frontend_cbor_decode_error

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 24, 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.

@NathanFlurry NathanFlurry force-pushed the 04-23-fix_rivetkit-core_return_none_for_empty_inspector_state_to_avoid_frontend_cbor_decode_error branch from 1250cce to b819d4e Compare April 24, 2026 09:52
@NathanFlurry NathanFlurry mentioned this pull request Apr 24, 2026
11 tasks
@claude
Copy link
Copy Markdown

claude Bot commented Apr 24, 2026

Code Review

Verdict: Approve with minor notes. This is a focused, correct fix. The root cause is clear — ActorContext::state() returns Vec::new() before any state is persisted, and the previous code wrapped that in Some(vec![]), causing the frontend CBOR decoder to fail on zero bytes. Returning None matches the optional<State> declared in the v4.bare protocol schema for both Init and StateResponse.


What works well

Correctness. The inspector_state_payload helper correctly maps both "state disabled" (!is_state_enabled) and "no state yet" (state.is_empty()) to None. This aligns with the wire schema and eliminates the decode error.

Lock reduction. The previous code called instance.ctx.has_state() and instance.ctx.state() as separate expressions, which reads the connection_config RwLock twice per site. Caching is_state_enabled before passing it to the helper removes one acquisition per message.

Helper extraction. Extracting inspector_state_payload deduplicates the logic between inspector_init_message and inspector_state_response, and the doc comment explains the why (CBOR failure on empty bytes) rather than the what.


Issues / suggestions

StateUpdated path is unguarded. inspector_push_message_for_signal still passes instance.ctx.state() directly to StateUpdated { state: ... }. The StateUpdated wire type declares state: State (non-optional), so there is no protocol slot for None here. But an actor that calls save_state with an empty delta would still produce empty bytes on this path. This is lower risk since StateUpdated is only fired after an explicit save, but for consistency consider adding an is_empty() guard and skipping the push (or logging a warning) in that case.

No regression test. The fix is deterministic enough to test: an actor that has never called save_state should produce state: None in the Init message. Adding a test in the existing inspector test module (tests/modules/registry.rs) would prevent this from regressing silently.

PR description is empty. The body is an unfilled template. A one-line description of the bug and how to reproduce it would help reviewers and make the git history more useful.


Summary

The core fix is correct and the refactor is a net improvement. The StateUpdated gap and missing test are worth addressing before merge, but neither is a blocker if the stacked PR context makes a quick fix impractical.

@NathanFlurry NathanFlurry force-pushed the 04-23-fix_rivetkit-core_don_t_install_tokio_signal_ctrl_c_handler_inside_serve_with_config branch from 026a6ce to 836ab72 Compare April 24, 2026 10:32
@NathanFlurry NathanFlurry force-pushed the 04-23-fix_rivetkit-core_return_none_for_empty_inspector_state_to_avoid_frontend_cbor_decode_error branch from c674f60 to 60c167f Compare April 24, 2026 10:32
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