Skip to content

feat(rust): cloneable Runtime, 'static Program, and Runtime::offload(false) - #174

Merged
kommander merged 5 commits into
devfrom
local-run
Dec 2, 2026
Merged

kommander merged 5 commits into
devfrom
local-run

Conversation

@simonklee

Copy link
Copy Markdown
Member

What

  • Make Runtime cheap to Clone and Send + Sync + 'static. Clones share an Arc<Setup>, and the builder methods use Arc::make_mut.
  • Program owns a Runtime clone instead of borrowing &'a Runtime, so Program and its futures are 'static. Program<'a> becomes Program: code that names the lifetime drops it.
  • Add Runtime::offload(bool), true by default. With offload(false), a run driven as a future (execute_async, run_async, run_resumable_async) never spawns or moves to a worker thread: every compute stretch runs on the polling thread.
  • Document it in rust/README.md under "Only Rust has" and "Design -> Threading".

Why

A single-threaded UI embedder such as the OpenCode Rust client keeps each plugin's running future in a struct. A borrowed Program<'a> makes that struct self-referential. The client also needs plugin compute to stay on the UI thread, so that its thread-CPU monitoring counts the plugin's time there, with no hop to a worker and no scheduler of its own.

Upstream

Rebased onto origin/dev (dec90d1; tip e24937e). Resolved a 1-line adjacency conflict in rust/README.md with #153's locale bullet; nothing was superseded by merged upstream work.

Compared with open PRs #157 (880f23f) and #139 (74c0392), which add a persistent Session (Runtime::session / session_with) and zero-copy HostCtx / HostFunction::direct:

Tests

  • Added rust/crates/psychoscript/tests/offload.rs:
    • runtime_clones_and_program_is_static
    • offload_false_keeps_compute_on_the_calling_thread: a fixed compute loop finishes in one poll and advances the calling thread's ThreadClock.
  • cargo fmt --all --check, cargo clippy --locked -p psychoscript -p psychoscript-bench --all-targets -- -D warnings, cargo clippy --locked -p psychoscript-mobile --no-default-features --features locale --all-targets -- -D warnings, and cargo test --locked -p psychoscript --lib --test offload --test snapshot --test streaming --test value_depth --test hostile --test host --test host_recording --test globals --test boundary --test program_lines --test gc --test map_compaction --test number_locale (146 passed, 0 failed) pass.

@simonklee
simonklee requested a review from kommander December 2, 2026 12:37
# Conflicts:
#	rust/README.md
#	rust/crates/psychoscript/src/runtime.rs
#	rust/crates/psychoscript/tests/value_depth.rs
# Conflicts:
#	rust/crates/psychoscript/src/runtime.rs
@kommander
kommander merged commit b39f44e into dev Dec 2, 2026
2 checks passed
@kommander
kommander deleted the local-run branch December 2, 2026 19:55
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.

2 participants