Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,14 @@ async function quantiseAndSend(
hiddenDim: number,
dtype: EmbeddingMsg['dtype'],
): Promise<void> {
if (seqLen < 1) {
workerLog('warn', 'quantiseAndSend: seqLen < 1; skipping Q² quantisation', { seqLen });
return;
}
if (hiddenDim < 1) {
workerLog('warn', 'quantiseAndSend: hiddenDim < 1; skipping Q² quantisation', { hiddenDim });
return;
}
Comment on lines +284 to +291

Copilot AI Mar 21, 2026

Copy link

Choose a reason for hiding this comment

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

The new guards prevent the seqLen=0/hiddenDim=0 trap, but quantiseAndSend still doesn’t validate other documented kernel preconditions (e.g., n must be a power of 2 and ≤ 16,384, and the buffer must contain at least the last-token row). Without these checks it’s still possible to call into the WASM kernel with unsupported dimensions or an undersized buffer, which can lead to traps or incorrect fingerprints. Consider extending the early validation to enforce the kernel’s n constraints (and, if applicable, the expected byteLength for the given dtype) before copying/calling into WASM.

Copilot uses AI. Check for mistakes.
Comment on lines +284 to +291

Copilot AI Mar 21, 2026

Copy link

Choose a reason for hiding this comment

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

This change introduces new early-return behavior for invalid seqLen/hiddenDim, but there’s no unit test asserting that the Q² kernel is not invoked in these cases. Since the repo already has worker unit tests, consider adding a test that triggers the embedding extraction path with seqLen=0 and/or hiddenDim=0 and verifies getKernel/quantise are not called (and that the worker continues without error).

Copilot uses AI. Check for mistakes.
const n = hiddenDim;
const dtypeId = DTYPE_TO_Q2[dtype] ?? Q2_DTYPE_FP32;
try {
Expand Down
Loading