Skip to content

Upgrade rune from 0.13 to 0.14#159

Open
vponomaryov wants to merge 2 commits intomainfrom
rune-0.14
Open

Upgrade rune from 0.13 to 0.14#159
vponomaryov wants to merge 2 commits intomainfrom
rune-0.14

Conversation

@vponomaryov
Copy link
Copy Markdown
Collaborator

@vponomaryov vponomaryov commented May 1, 2026

Adapt to rune 0.14 API changes:

  • AnyObj::from_ref/from_mut became pub(crate), so Context can no longer be passed to the VM as a borrowed reference. Instead, each VM call receives an owned shallow clone via Value::new(context).

  • Update Value/VmResult/VmError APIs to match 0.14 signatures (VmResult<T> → Result<T, RuntimeError>, Shared removal, etc).

  • Remove unused ThreadRng field from Context which was causing data corruption on high load.

Closes: #QATOOLS-10

@vponomaryov vponomaryov marked this pull request as draft May 1, 2026 18:16
ThreadRng contains Rc<UnsafeCell<...>> pointing to thread-local storage,
making it !Send. While the field was never read or written by any code,
its construction (rand::rng()) and destruction involved Rc refcount
operations on thread-local data. When tokio migrated tasks between
worker threads, the Rc drop could race with Rc operations on the
originating thread, causing data corruption and segfaults.

This was the root cause of intermittent crashes observed after
switching to rune 0.14, where Context became VM-owned (created and
dropped per call) rather than borrowed via AnyObj::from_ref as in
rune 0.13.
@vponomaryov vponomaryov marked this pull request as ready for review May 5, 2026 16:58
@vponomaryov vponomaryov marked this pull request as draft May 5, 2026 17:32
@vponomaryov vponomaryov changed the title Bump Rune from 0.13 to 0.14 Upgrade rune from 0.13 to 0.14 May 5, 2026
@vponomaryov vponomaryov marked this pull request as ready for review May 5, 2026 17:38
@vponomaryov vponomaryov marked this pull request as draft May 5, 2026 17:44
Adapt to rune 0.14 API changes:

- AnyObj::from_ref/from_mut became pub(crate), so Context is now passed
  to the VM as an owned shallow clone via Value::new(context) instead
  of a borrowed reference.

- Update Value/VmResult/VmError APIs to match 0.14 signatures
  (Value::Result → downcast, Shared removal, VmResult → Result, etc).

- Retain unsafe impl Send/Sync for Context. This is sound because the
  only !Send field is `data: Value` (non-atomic Cell<usize> refcount),
  and within latte's architecture each Context instance is confined to
  sequential polling within a single tokio task — no concurrent access
  to the same Cell can occur. The previously-unsound ThreadRng field
  was removed in the prior commit.
@vponomaryov vponomaryov marked this pull request as ready for review May 5, 2026 19:26
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