Skip to content

fix(droid): resolve DataCloneError in ws-worker Comlink callback#9893

Merged
h0lybyte merged 3 commits intodevfrom
trunk/irc-dataclone-1775767815
Apr 9, 2026
Merged

fix(droid): resolve DataCloneError in ws-worker Comlink callback#9893
h0lybyte merged 3 commits intodevfrom
trunk/irc-dataclone-1775767815

Conversation

@h0lybyte
Copy link
Copy Markdown
Member

@h0lybyte h0lybyte commented Apr 9, 2026

Summary

Replaced the main-thread bridgeWsToDb pattern with direct worker-to-worker communication via BroadcastChannel.

Before (main thread in the data path):

ws-worker → Comlink → main thread → Comlink → db-worker → IndexedDB

After (main thread only handles UI events):

ws-worker → BroadcastChannel → db-worker → IndexedDB

Changes

  • ws-worker: broadcasts classified messages (text/binary + timestamp) to kbve_ws_data BroadcastChannel — main thread callback still fires for UI rendering
  • db-worker: listens on kbve_ws_data channel, stores raw bytes as Uint8Array (format-agnostic — IRC text, FlatBuffers, Protobuf all stored the same way, consumers decode on read)
  • main.ts: removed bridgeWsToDb function and unused proxy import — main thread no longer participates in the storage pipeline
  • DataCloneError fix: removed FlexBuffers toReference decode from db-worker write path — was producing objects with typed array views that Dexie's BroadcastChannel sync couldn't clone

Test plan

  • Open IRC Gateway (chat.kbve.com) — verify no DataCloneError
  • Send/receive messages — verify WebSocket messages display correctly
  • Open multiple tabs — verify Dexie multi-tab sync works without errors
  • Verify droid + astro-irc build clean

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 9, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Snapshot Warnings

⚠️: No snapshots were found for the head SHA 82a09f8.
Ensure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice.

Scanned Files

None

storeWsMessage stored FlexBuffers-decoded objects directly into Dexie.
toReference().toObject() returns objects containing Uint8Array typed
array views referencing the original ArrayBuffer. Dexie's multi-tab
sync broadcasts changes via BroadcastChannel.postMessage(), which
throws DataCloneError on these typed array views. JSON round-trip
the decoded object before storing to produce a plain cloneable value.
@h0lybyte h0lybyte force-pushed the trunk/irc-dataclone-1775767815 branch from c56bd84 to e808324 Compare April 9, 2026 22:07
h0lybyte added 2 commits April 9, 2026 18:23
storeWsMessage assumed all WebSocket data was FlexBuffers-encoded and
called toReference().toObject(), which returns objects with typed array
views. Dexie's BroadcastChannel multi-tab sync then threw DataCloneError
when trying to postMessage those views.

The ws-worker is protocol-agnostic (IRC text, FlatBuffers, Protobuf)
so the storage layer should be too. Now stores raw bytes as Uint8Array
(natively supported by IndexedDB and BroadcastChannel) and removes the
FlexBuffers decode from the write path. Consumers decode on read using
the appropriate deserializer for their protocol.
Replaced the main-thread bridgeWsToDb pattern with direct worker-to-
worker communication via BroadcastChannel ('kbve_ws_data').

Before: ws-worker → Comlink → main thread → Comlink → db-worker → IDB
After:  ws-worker → BroadcastChannel → db-worker → IDB

- ws-worker broadcasts classified messages (text/binary + timestamp)
  directly to db-worker, main thread never touches raw data
- db-worker stores raw bytes as Uint8Array (format-agnostic, no
  FlexBuffers assumption — supports IRC text, FlatBuffers, Protobuf)
- Removed bridgeWsToDb and unused proxy import from main.ts
- Removed FlexBuffers toReference import from db-worker (was
  causing DataCloneError via Dexie BroadcastChannel sync)
@h0lybyte h0lybyte merged commit 067e1c5 into dev Apr 9, 2026
2 checks passed
@h0lybyte h0lybyte deleted the trunk/irc-dataclone-1775767815 branch April 9, 2026 22:39
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.

1 participant