Skip to content

fix: re-materialize views during procedure commit (re-entrant)#4299

Closed
clockwork-labs-bot wants to merge 2 commits intomasterfrom
fix/4296-procedure-view-reentrant
Closed

fix: re-materialize views during procedure commit (re-entrant)#4299
clockwork-labs-bot wants to merge 2 commits intomasterfrom
fix/4296-procedure-view-reentrant

Conversation

@clockwork-labs-bot
Copy link
Collaborator

@clockwork-labs-bot clockwork-labs-bot commented Feb 15, 2026

Problem

Procedures that modify tables don't trigger view re-materialization (fixes #4296).

Root Cause

Procedures commit transactions via procedure_commit_mut_tx syscall while executing inside the wasm/V8 instance. The reducer path calls call_views_with_tx() to re-materialize views before committing, but the procedure path skipped this entirely — views were never updated.

Fix: Re-entrant View Evaluation

Both backends (wasmtime and V8) now evaluate dirty views re-entrantly during procedure_commit_mut_tx, within the same transaction:

  1. Check tx.view_for_update() for views whose read sets overlap with the transaction's writes
  2. For each dirty view, call the view function re-entrantly (wasmtime: TypedFunc::call_async + now_or_never, V8: call_call_view/call_call_view_anon through the scope)
  3. Process view results (Rows or RawSql paths) and materialize backing tables via update_view_table
  4. Commit the transaction — data writes and view updates together atomically

Changes

wasm_instance_env.rs (wasmtime):

  • Added call_view, call_view_anon, module_def fields to WasmInstanceEnv
  • Rewrote procedure_commit_mut_tx with re-entrant view evaluation
  • Added process_view_result_and_materialize helper

v8/syscall/common.rs (V8):

  • Rewrote procedure_commit_mut_tx with re-entrant view evaluation via hooks
  • Added process_v8_view_result helper

v8/mod.rs:

  • Added module_def to JsInstanceEnv, implemented set_module_def

wasmtime_module.rs:

  • Store view func handles in WasmInstanceEnv during instantiation

module_host_actor.rs:

  • Extracted evaluate_view_sql as standalone pub(crate) function
  • Added set_module_def to WasmInstance trait
  • Made deserialize_view_rows pub(crate)

instance_env.rs:

  • Made finish_anon_tx() and procedure_last_tx_offset pub(crate)

Closes #4296

When a procedure commits a transaction via procedure_commit_mut_tx,
we now check for dirty views (views whose read sets overlap with
the transaction's write set) and re-evaluate them re-entrantly
before committing. This ensures that views are kept up-to-date
when procedures modify data they depend on.

Implementation details:
- Store call_view/call_view_anon TypedFunc handles and module_def
  on WasmInstanceEnv for re-entrant access during procedure commits
- Factor out evaluate_view_sql as a standalone pub(crate) function
  from InstanceCommon::run_query_for_view
- In procedure_commit_mut_tx, iterate dirty views, put tx back in
  TxSlot for each view call, call view function re-entrantly via
  TypedFunc::call_async/now_or_never, process results (BSATN rows
  or RawSql), and materialize before final commit
- Add set_module_def to WasmInstance trait for post-instantiation
  module definition injection
- V8 backend: added TODO for equivalent implementation

Fixes #4296
Mirrors the wasmtime re-entrant view evaluation in the V8 backend.

During procedure_commit_mut_tx in V8:
- Check tx.view_for_update() for dirty views
- Get hooks via get_registered_hooks(scope)
- For each dirty view, call call_call_view/call_call_view_anon
  re-entrantly through the V8 scope
- Process results (Rows or RawSql) and materialize backing tables
- Commit the transaction with view updates included

Also adds module_def to JsInstanceEnv (set via set_module_def on
the WasmInstance trait) so view definitions are available during
the syscall.

Part of #4296
@joshua-spacetime
Copy link
Collaborator

Closing in favor of #4301

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.

Procedures don't trigger view changes

2 participants