feat(codegen): persistent component state + inter-thread connections (REQ-CODEGEN-WIT-STATE-001)#325
Merged
Conversation
… inter-thread) Word to the mechanism, not an authoring story: persistent state = the binding REUSES the component instance across dispatches (thread_local RefCell), so state survives. Inter-thread = thread_local buffer with LATEST-VALUE/SAMPLING semantics (last-writer-wins), explicitly NOT AADL immediate/delayed timing. Oracle on ONE live instance: accumulator (5,7 -> 12 discriminates persistence) + producer-> consumer across separate dispatches, both sabotaged for non-vacuity. Stated limitation: user state lives in the DO-NOT-EDIT skeleton (regen-safe authoring is a successor). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…(REQ-CODEGEN-WIT-STATE-001)
Generated Guest now:
- reuses ONE component instance per thread across dispatches via a thread_local
RefCell (borrowed per compute) instead of constructing {Struct}Default fresh, so
component state persists. Skeleton struct gains #[derive(Default)] for the
one-time init. Single-threaded, non-reentrant wasip2 => borrow_mut cannot alias.
- routes inter-thread connections (both ends Some, previously skipped by
resolve_port_routes) through a thread_local buffer with latest-value/sampling
semantics: source Out writes the buffer after compute, dest In reads it before.
New resolve_interthread_routes + InterThreadRoute::buffer_ident (UPPER_SNAKE).
Oracles: resolver + shape fast tests (interthread_resolver_is_exact,
state_bindings_emit_threadlocal_and_interthread_buffer), STATE golden-lock +
cargo-check (green under -D warnings), and the load-bearing wasmtime state-oracle
bin proving on ONE live instance: accumulator acc(5,7)->12 (persistence) and
pr.po->buffer->cn.ci->sink-out delivers 42 (inter-thread). Persistence sabotage
(fresh-construct) drops to 7 as predicted.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…oracle job REQ-CODEGEN-WIT-STATE-001: the codegen-oracle job now also runs the state-oracle bin (persistence acc(5,7)->12 + inter-thread delivery 42), alongside the data-plane exec oracle. Both proofs sabotage-verified non-vacuous locally. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…solved Clean-room review caught the generated lib.rs header + generate_process_bindings rustdoc still disclaiming "constructed fresh per dispatch, state does NOT persist, inter-thread not yet plumbed" and "initialize/finalize keep the plain construct- and-call body" — all falsified by REQ-CODEGEN-WIT-STATE-001 (the wrapper borrows the persistent instance in every method; inter-thread is plumbed). The header shipped in every generated component, contradicting the persistent-state comment later in the same file. Now both state the reused-instance + latest-value buffers. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Rivet verification gate✅ 20/20 passed
Filter: Failed artifacts(none) Updated automatically by |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Removes the two v0.25 data-plane limitations. The generated component
Guestnow:thread_local! { RefCell<{Struct}Default> }, borrowed percompute, instead of constructing{Struct}Defaultfresh each dispatch. Component state now survives across dispatches. The skeleton struct gains#[derive(Default)]for the one-time init. A wasip2 component is single-threaded and non-reentrant, soborrow_mutcannot alias.ConnectionInstancewith BOTH endsSome(...)(thread A out → thread B in, previously skipped) now routes through athread_local!buffer with latest-value / sampling semantics: the source's Out field writes the buffer aftercompute, the destination's In field reads the latest value beforecompute. (resolve_interthread_routes+InterThreadRoute.) This is sampling, not AADL immediate/delayed connection timing — out of scope, stated in the requirement.Oracles
interthread_resolver_is_exact,state_bindings_emit_threadlocal_and_interthread_buffer.cargo checkof the emitted STATE crate (green under-D warnings).state-oracle(out-of-workspace, the load-bearing gate) — on ONE live instance:pr.po → buffer → cn.ci → sink-outdelivers 42 across two separate dispatches.Falsification (both sabotage-verified non-vacuous)
thread_localto a per-callDefaultdrops persistence to 7.Both wired into the
codegen-oracleCI job. The v0.25 DATAPLANE exec oracle still passes (its generated code now carries the state/inter-thread wiring).Stated limitation
User state lives in the generated
{thread}.rsskeleton, which carriesDO NOT EDIT — regenerate; adding real state means editing a file regen overwrites. The mechanism (instance reuse) ships here; a regen-safe authoring split is a separate successor.🤖 Generated with Claude Code