Skip to content

Fix WASM RuntimeError causing persistent display failures in mesh worker#1694

Draft
Copilot wants to merge 6 commits into
mainfrom
copilot/fix-index-out-of-bounds-error
Draft

Fix WASM RuntimeError causing persistent display failures in mesh worker#1694
Copilot wants to merge 6 commits into
mainfrom
copilot/fix-index-out-of-bounds-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 6, 2026

Intermittent RuntimeError: index out of bounds from replicad's WASM module would corrupt the mesh worker's WASM heap, causing all subsequent geometry renders to silently fall back to "No output to display" — only recoverable via page refresh.

Root cause

geometryProvider.get() speculatively calls deserializeDrawing() on all cached shapes. When called on Shape3D data, the WASM runtime can trap (RuntimeError: index out of bounds), leaving the module in an unrecoverable state. Every deserialization after that also fails.

Changes

geometryProvider.ts

  • Add WasmDeserializationError (exported) — thrown when both deserializeDrawing and deserializeShape fail, giving callers a precise signal to act on
  • On double-deserializer failure, delete the corrupt IndexedDB entry via deleteShape() so geometry is recomputed on next request rather than failing indefinitely

meshWorker.ts

  • Import WasmDeserializationError; detect WASM failures via instanceof WasmDeserializationError || e instanceof WebAssembly.RuntimeError
  • Schedule self.close() in a finally block (after fallback attempt) using named constant WORKER_RESTART_DELAY_MS = 100ms — workerpool then spins up a fresh worker with a clean WASM heap
  • Wrap fallback mesh generation in its own try/catch so uncached default-mesh edge cases propagate correctly
// geometryProvider.ts — thrown instead of generic Error
throw new WasmDeserializationError("Failed to deserialize geometry: " + e2);

// meshWorker.ts — triggers worker restart via finally
const isWasmError =
  e instanceof WasmDeserializationError ||
  e instanceof WebAssembly.RuntimeError;
try {
  return { id, mesh: await generateDefaultMesh(context) };
} catch (fallbackError) { ... throw e; }
finally {
  if (isWasmError) setTimeout(() => self.close(), WORKER_RESTART_DELAY_MS);
}

Effect: one render cycle shows the fallback; the next user action triggers a fresh worker that deserializes and renders correctly — no page refresh required.

Copilot AI linked an issue May 6, 2026 that may be closed by this pull request
Copilot AI and others added 5 commits May 6, 2026 17:53
… IndexedDB entries

Agent-Logs-Url: https://github.com/BarbourSmith/Abundance/sessions/c063747f-e615-4ab5-99b6-d770a9ce12a9

Co-authored-by: BarbourSmith <9359447+BarbourSmith@users.noreply.github.com>
…T_DELAY_MS constant

Agent-Logs-Url: https://github.com/BarbourSmith/Abundance/sessions/c063747f-e615-4ab5-99b6-d770a9ce12a9

Co-authored-by: BarbourSmith <9359447+BarbourSmith@users.noreply.github.com>
…view issues

Agent-Logs-Url: https://github.com/BarbourSmith/Abundance/sessions/c063747f-e615-4ab5-99b6-d770a9ce12a9

Co-authored-by: BarbourSmith <9359447+BarbourSmith@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix index out of bounds display error Fix WASM RuntimeError causing persistent display failures in mesh worker May 6, 2026
Copilot AI requested a review from BarbourSmith May 6, 2026 18:04
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.

Index out of bounds display error

2 participants