Skip to content

Add a web engine for wasm32-unknown-unknown - #50

Merged
setoelkahfi merged 2 commits into
developmentfrom
feature/web-engine
Nov 18, 2026
Merged

setoelkahfi merged 2 commits into
developmentfrom
feature/web-engine

Conversation

@setoelkahfi

Copy link
Copy Markdown
Collaborator

On wasm32-unknown-unknown, ChatEngine is now a real engine instead of the stub. It runs GGUF Qwen2.5 and Qwen3 models on the CPU through candle, single threaded, with the tokenizer loaded from tok_model_id. The public signatures match the native engine, so ed-agent compiles against it unchanged. Tool calling reports Unsupported. Other wasm and unknown targets keep the stub.

Model files come from Hugging Face and are kept in Cache Storage (onde-models-v1), which works from a window and from a worker. web_store::download_model mirrors hf_cache::download_model with a progress callback, and is_cached and delete_model manage the cache.

Generation builds a ChatML prompt, samples from SamplingConfig, and yields to the event loop between tokens, so a cancel or a dropped stream is seen. build.rs gains the onde_web cfg, and the qwen25 and qwen3 presets set tok_model_id on web as they do on Android.

This has no version bump. The release is separate.

Testing

tests/web_smoke.rs downloads Qwen 2.5 0.5B in headless Chrome and checks a streamed reply. It only runs with ONDE_WEB_SMOKE set, so CI compiles it and does not run it, because of the 380 MB download.

I also ran the engine through the Ed web example in ondeinference/ed#62: the model downloads with progress, two turns stream with the second using the first as context, and a reload loads from the cache without downloading again. It runs at roughly 1 to 2.5 tokens/s on an Apple Silicon Mac.

On wasm32-unknown-unknown, ChatEngine is now a real engine instead of the
stub. It runs GGUF Qwen2.5 and Qwen3 models on the CPU through candle,
single-threaded, with the tokenizer loaded from tok_model_id. The public
signatures match the native engine, so ed-agent compiles unchanged.
Tool calling reports Unsupported. Other wasm and unknown targets keep
the stub.

Model files come from Hugging Face and are kept in Cache Storage
(onde-models-v1), which works from a window and from a worker.
web_store::download_model mirrors hf_cache::download_model with a
progress callback, and is_cached and delete_model manage the cache.

Generation builds a ChatML prompt, samples from SamplingConfig, and
yields to the event loop between tokens, so cancels and dropped streams
are seen. build.rs gains the onde_web cfg. The qwen25 and qwen3 presets
set tok_model_id on web as they do on Android.

tests/web_smoke.rs downloads Qwen 2.5 0.5B in headless Chrome and checks
a streamed reply. It runs only with ONDE_WEB_SMOKE set, so CI compiles
it and does not run it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: siGit Code v1.7.10 <noreply@sigit.si>
Co-Authored-By: OndeCode v1.1.2 <noreply@ondeinference.com>

@sigit-code-review sigit-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR turns the wasm32-unknown-unknown target from the stub into a real browser engine. build.rs adds the onde_web cfg (wasm32 + unknown OS only), Cargo.toml adds candle/tokenizers/web-sys under that target, and engine.rs re-exports super::web::ChatEngine in its place, with the qwen25/qwen3 presets now setting tok_model_id on web as they already did on Android. New text.rs holds the host-testable ChatML prompt builder and logit penalties; new web/mod.rs implements the full ChatEngine surface (prefill chunked with event-loop yields, token streaming with cancel-on-drop via a tokio channel, <think> splitting for history, tool calling reporting Unsupported); new web_store.rs mirrors hf_cache over Cache Storage with streamed download progress. CI compiles (but does not run) the gated web_smoke browser test.

Reviewers should look first at web/mod.rs's generation loop and web_store.rs's download path. Two things worth knowing: the whole GGUF is buffered into wasm memory at load time (see finding), and the smoke test only exercises the Qwen2.5 path — the Qwen3 weights, the <think> handling, and the penalties are untested in a browser.


Automated review by siGit Code Review · commit 731c53a · see the review dashboard

Comment thread src/inference/web/mod.rs Resolved
Comment thread src/web_store.rs Resolved
Comment thread src/inference/web/mod.rs Resolved
send_message returned the model's raw text while history and complete()
both split off Qwen3's <think> block, so a thinking model gave callers the
reasoning mixed into the reply. It now returns the reply alone, trimmed
like the native engine.

load_file now documents its peak memory (about three times the file size),
and the prepare_turn comment says the busy guard runs first.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: siGit Code v1.7.10 <noreply@sigit.si>
Co-Authored-By: OndeCode v1.1.2 <noreply@ondeinference.com>
setoelkahfi added a commit to ondeinference/ed that referenced this pull request Nov 16, 2026
…eplies

build.sh now appends +simd128 to an exported RUSTFLAGS instead of dropping
it. The worker answers a message that arrives before Ed has started with an
error instead of ignoring it. A reply that fails after some tokens streamed
keeps its text and gets the error appended. The onde comment in Cargo.toml
now says the dependency waits on ondeinference/onde#50 rather than on a
version number.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: siGit Code v1.7.10 <noreply@sigit.si>
Co-Authored-By: OndeCode v1.1.2 <noreply@ondeinference.com>

@sigit-code-review sigit-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of the follow-up commit 731c53a. Both earlier findings on src/inference/web/mod.rs are addressed: send_message now returns split_think(&out.text).0 so callers get the same text that commit_turn stores in history, and the prepare_turn doc comment now correctly says it runs after the busy guard. The web_store.rs memory finding was resolved by documenting the ~3x peak-wasm-memory behaviour on load_file rather than changing the code, which is a reasonable call given the constraints; the thread stays settled. No new issues in the diff.


Automated review by siGit Code Review · commit dfe2641 · changes since 731c53a · see the review dashboard

@setoelkahfi
setoelkahfi added this pull request to stack #53 November 17, 2026 21:48
@setoelkahfi
setoelkahfi merged commit cdab839 into development Nov 18, 2026
21 checks passed
@setoelkahfi
setoelkahfi deleted the feature/web-engine branch November 18, 2026 07:32
@setoelkahfi setoelkahfi mentioned this pull request Nov 18, 2026
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.

3 participants