Skip to main content

Module maybe

Module maybe 

Source
Expand description

Thread-safety bounds that relax on browser wasm.

The host-facing seams (ToolExecutor, ApprovalHandler, EventSink, SessionStore) must be Send + Sync on native targets, where a turn can hop between runtime threads. In a browser the agent lives on one JS thread and its implementations hold JsValues, which are !Send. These aliases resolve to exactly Send / Sync everywhere except wasm32-unknown-unknown, so native signatures are unchanged. Other wasm targets (wasm32-wasip1-threads, Emscripten with pthreads) can run threads, so they keep the real bounds. It is the same pattern wgpu uses (WasmNotSend).

Soundness rests on the single-thread guarantee: nothing holding a JsValue may be handed to another thread. Do not paper over a !Send type with unsafe impl Send.

Traitsยง

MaybeSend
MaybeSync