Skip to content

feat(wasm): add bounded opaque blobs and exact-output file capability #17

Closed

Description

@zackees

Context

Third dependency-ordered foundation for #13 and #14. It depends on #15 and #16 and establishes the first real bulk-data/authority boundary: quota-accounted opaque blobs and one exact native output-file capability. #14 needs this to persist a screenshot without passing PNG bytes or a filesystem path through Wasm.

Depends on

Extend that one ABI and resource registry only. Do not add a direct helper, side channel, second serialization mechanism, or native copy of sketch logic.

Proposal

Implement facade-owned generated-ABI semantics equivalent to:

async fn blob_write_chunk(blob: WritableBlob, bytes: &[u8]) -> Result<WriteProgress, BlobError>;
async fn blob_read_chunk(blob: ReadableBlob, max_bytes: u32) -> Result<ReadChunk, BlobError>;
async fn blob_close(blob: BlobHandle) -> Result<(), BlobError>;
async fn write_blob_to_output(blob: ReadableBlob, output: OutputFile) -> Result<(), OutputWriteError>;

Final generated names may differ, but the model is fixed: blobs are opaque host resources rather than Vec<u8> ABI values; transfers are bounded chunks; output is an exact native capability rather than a guest path; final output is atomically committed only after success.

The embedding CLI/host canonicalizes and authorizes one exact output destination before guest instantiation. The guest receives only a scoped OutputFile handle. write_blob_to_output writes a sibling temporary file, flushes/closes it, then atomically replaces the authorized final path. Failure/cancellation/trap/teardown removes the temporary file and leaves no partial final output. If atomic replacement is unavailable, return a typed failure instead of silently degrading.

Backpressure and quota contract

kernal-api owns backpressure. Enforce configurable maximum chunk size, live blobs, per-blob bytes, per-sketch blob bytes, pending reads/writes, and in-flight transfer bytes.

  • Reads are pull-based: no additional bytes until a bounded request.
  • Writes await downstream capacity, not an unbounded queue.
  • Fast production stops at capacity and resumes after capacity release.
  • Pending I/O is cancellable.
  • Close, cancellation, trap, guest-thread exit, and teardown release permits/buffers exactly once.
  • Blob/output handles remain generation-safe and cross-instance use fails deterministically.

Future native image capture may internally materialize a platform result, but must create a bounded quota-accounted blob. PNG/image bytes never cross the Wasm ABI as one serialized value.

Invariants

  • Types/errors are facade-owned semantic types; no Tokio, Wasmtime, fp-bindgen/WIT, descriptor, native file, Tauri, WebKitGTK, WebView2, WKImage, or platform image types are public.
  • default = [] must not resolve or compile engine, generator, GUI, capture, or image-encoder dependencies.
  • Existing private atomic-replace support may be used internally but raw paths/implementation types are not guest API.
  • Do not add a speculative generic storage trait or separate public data crate.
  • Future non-Tauri producers/consumers use this same opaque-resource protocol.

Non-goals

  • Tauri/window navigation/page-load/screenshot capture.
  • Arbitrary file read/write, directory authority, filesystem sandbox, or ambient WASI filesystem support.
  • read_to_end, full-image serialization, JavaScript bridge, WebDriver, OS-desktop capture, compression, or archive APIs.

Acceptance criteria

  • RED: checked-in tests prove current guest/host code has no opaque blob or exact output-file capability and would require raw bytes or a raw path.
  • RED: regression tests reject whole-value payload exchange, ambient filesystem imports, raw guest paths, and cross-instance output handles.
  • GREEN: a guest transfers at least 64 MiB through the real generated ABI in bounded chunks without total-length guest or ABI allocation.
  • GREEN: instrumentation proves peak outstanding bytes stay within configured per-transfer/per-sketch budgets independent of total length.
  • GREEN: fast-producer/slow-consumer testing proves capacity-awaited writes stop at the configured limit and resume after consumption.
  • GREEN: pull reads produce nothing until the consumer asks for a bounded chunk.
  • GREEN: cancellation while reads/writes are pending wakes both sides, releases capacity, and returns typed errors.
  • GREEN: stale, double-closed, forged, and cross-instance blob/output handles fail deterministically.
  • GREEN: close, cancellation, trap, thread exit, timeout, and teardown return blob/buffer/permit/pending-operation counters to zero.
  • GREEN: host grants one exact output destination; guest writes only through OutputFile and has no raw path or directory authority.
  • GREEN: successful bounded blob output is byte-identical at the authorized path through sibling-temp-file flush/close/atomic replacement.
  • GREEN: injected write/flush/rename/cancellation/teardown failures leave no partial final file and remove the temporary file.
  • GREEN: default-feature checks remain free of sketch, GUI, capture, and image-encoder dependency resolution.
  • GREEN: focused format/lint/build/test commands are documented through Soldr.

Platform matrix and deliverables

Compile on Linux, macOS, and Windows x86-64/ARM64. Run output atomicity/cleanup tests natively on each operating-system family and report target, quotas, total transfer, peak accounted bytes, commit result, and temporary-file cleanup result. Platform replacement differences require facade-owned tests and typed errors, not best effort.

Deliver opaque blob/output ABI support, quota/backpressure instrumentation, native output grant/atomic commit implementation, large-transfer/slow-consumer/cancellation/handle/cleanup tests, focused Soldr documentation, and a short future-producer/consumer contract.

Decisions

Related issues

Activity

  1. added
    enhancement
    on Aug 27, 2026
  2. zackees commented on Sep 14, 2026

    @zackees
    CollaboratorAuthor

    Completed by PR #153 (merge fddd176). Bounded opaque blobs, exact-output authority, 64 MiB real guest transfer, quota/backpressure/cancellation/cleanup coverage, and native artifact proof lanes landed. Run 34801708129 passed every archive and screenshot artifact lane across Linux/macOS/Windows x86-64 and ARM64.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions