@blockcast/fec-worker 0.1.0-main.c71423b8a4e4 → 0.1.0-main.cde7600fad6a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,7 +25,8 @@ export declare class FecWorkerClient {
25
25
  configure(config: FecTrackConfig, wasmModule: WebAssembly.Module, altaPublicKey?: ArrayBuffer, altaWasmModule?: WebAssembly.Module): void;
26
26
  /**
27
27
  * Feed a source symbol to the Worker. data ArrayBuffer is transferred (zero-copy).
28
- * Caller must not access data after this call — it is detached.
28
+ * Caller must not access data after this call — it is transferred with the
29
+ * task's symbol batch, before any later command of this client.
29
30
  *
30
31
  * Optional `alta` carries the detached ALTA authenticator bytes and the
31
32
  * byte offset in `data` where the signed payload ends. The auth buffer is
@@ -1 +1 @@
1
- {"version":3,"file":"fec-worker-client.d.ts","sourceRoot":"","sources":["../src/fec-worker-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAGX,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,SAAS,EACT,kBAAkB,EAClB,MAAM,uBAAuB,CAAC;AAE/B,qBAAa,eAAe;;IAc3B;;;OAGG;gBACS,WAAW,EAAE,MAAM,GAAG,GAAG;IAgBrC;;;;;;OAMG;IACH,SAAS,CACR,MAAM,EAAE,cAAc,EACtB,UAAU,EAAE,WAAW,CAAC,MAAM,EAC9B,aAAa,CAAC,EAAE,WAAW,EAC3B,cAAc,CAAC,EAAE,WAAW,CAAC,MAAM,GACjC,IAAI;IAkBP;;;;;;;;OAQG;IACH,UAAU,CACT,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,WAAW,EACjB,EAAE,EAAE,MAAM,EACV,IAAI,CAAC,EAAE;QAAE,IAAI,EAAE,WAAW,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,GAC9C,IAAI;IAgBP;;;;;;;;OAQG;IACH,UAAU,CACT,OAAO,EAAE,MAAM,EACf,SAAS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E,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,KAAK,IAAI,GAAG,IAAI;IAI/D,0FAA0F;IAC1F,iBAAiB,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAIlD,2CAA2C;IAC3C,OAAO,CAAC,EAAE,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,kBAAkB,KAAK,IAAI,GAAG,IAAI;IAIvE;;;;;OAKG;IACH,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED;;;OAGG;IACH,OAAO,IAAI,IAAI;CA4Df"}
@@ -20,6 +20,15 @@ export class FecWorkerClient {
20
20
  #pendingResets = 0;
21
21
  #resetFailed = false;
22
22
  #disposed = false;
23
+ // Symbols fed during the current task, sent as one feedSymbols message
24
+ // when the task's microtasks run (BLO-36599). A packet stream delivers many
25
+ // symbols per task, and each postMessage is a structured-clone round trip
26
+ // on the page thread; the batch boundary is the task, not a size or timer.
27
+ #pendingSymbols = [];
28
+ #pendingTransfer = [];
29
+ #flushQueued = false;
30
+ // Batching starts only once the Worker announced it accepts feedSymbols.
31
+ #batchSymbols = false;
23
32
  /**
24
33
  * Create a FecWorkerClient.
25
34
  * @param workerOrUrl - Either a Worker instance (for testing) or a URL to create one
@@ -49,6 +58,7 @@ export class FecWorkerClient {
49
58
  configure(config, wasmModule, altaPublicKey, altaWasmModule) {
50
59
  if (this.#disposed)
51
60
  throw new Error("[FecWorkerClient] disposed");
61
+ this.#flushSymbols();
52
62
  const cmd = {
53
63
  type: "configure",
54
64
  config,
@@ -67,7 +77,8 @@ export class FecWorkerClient {
67
77
  }
68
78
  /**
69
79
  * Feed a source symbol to the Worker. data ArrayBuffer is transferred (zero-copy).
70
- * Caller must not access data after this call — it is detached.
80
+ * Caller must not access data after this call — it is transferred with the
81
+ * task's symbol batch, before any later command of this client.
71
82
  *
72
83
  * Optional `alta` carries the detached ALTA authenticator bytes and the
73
84
  * byte offset in `data` where the signed payload ends. The auth buffer is
@@ -77,18 +88,19 @@ export class FecWorkerClient {
77
88
  feedSource(ssId, data, ts, alta) {
78
89
  if (this.#disposed)
79
90
  throw new Error("[FecWorkerClient] feedSource on a disposed client");
80
- const cmd = alta
81
- ? {
91
+ if (alta) {
92
+ this.#queueSymbol({
82
93
  type: "feedSource",
83
94
  ssId,
84
95
  data,
85
96
  ts,
86
97
  altaAuth: alta.auth,
87
98
  altaPayloadEnd: alta.payloadEnd,
88
- }
89
- : { type: "feedSource", ssId, data, ts };
90
- const transfer = alta ? [data, alta.auth] : [data];
91
- this.#worker.postMessage(cmd, transfer);
99
+ }, data, alta.auth);
100
+ }
101
+ else {
102
+ this.#queueSymbol({ type: "feedSource", ssId, data, ts }, data);
103
+ }
92
104
  }
93
105
  /**
94
106
  * Feed a repair symbol to the Worker. data ArrayBuffer is transferred (zero-copy).
@@ -102,14 +114,37 @@ export class FecWorkerClient {
102
114
  feedRepair(ssStart, ssbLength, rsId, data, ts) {
103
115
  if (this.#disposed)
104
116
  throw new Error("[FecWorkerClient] feedRepair on a disposed client");
105
- this.#worker.postMessage({
106
- type: "feedRepair",
107
- ssStart,
108
- ssbLength,
109
- rsId,
110
- data,
111
- ts,
112
- }, [data]);
117
+ this.#queueSymbol({ type: "feedRepair", ssStart, ssbLength, rsId, data, ts }, data);
118
+ }
119
+ #queueSymbol(symbol, data, auth) {
120
+ if (!this.#batchSymbols) {
121
+ this.#worker.postMessage(symbol, auth ? [data, auth] : [data]);
122
+ return;
123
+ }
124
+ this.#pendingSymbols.push(symbol);
125
+ this.#pendingTransfer.push(data);
126
+ if (auth)
127
+ this.#pendingTransfer.push(auth);
128
+ if (this.#flushQueued)
129
+ return;
130
+ this.#flushQueued = true;
131
+ queueMicrotask(() => {
132
+ this.#flushQueued = false;
133
+ this.#flushSymbols();
134
+ });
135
+ }
136
+ /**
137
+ * Send the symbols fed so far. Every other command calls this first, so a
138
+ * cleanup barrier, reset or signature still follows all earlier symbols.
139
+ */
140
+ #flushSymbols() {
141
+ if (this.#pendingSymbols.length === 0 || this.#disposed)
142
+ return;
143
+ const symbols = this.#pendingSymbols;
144
+ const transfer = this.#pendingTransfer;
145
+ this.#pendingSymbols = [];
146
+ this.#pendingTransfer = [];
147
+ this.#worker.postMessage({ type: "feedSymbols", symbols }, transfer);
113
148
  }
114
149
  /**
115
150
  * Submit relay block signature for verification. sig and hash are transferred.
@@ -117,6 +152,7 @@ export class FecWorkerClient {
117
152
  relayBlockSig(sbn, sig, hash) {
118
153
  if (this.#disposed)
119
154
  throw new Error("[FecWorkerClient] relayBlockSig on a disposed client");
155
+ this.#flushSymbols();
120
156
  this.#worker.postMessage({ type: "relayBlockSig", sbn, sig, hash }, [sig, hash]);
121
157
  }
122
158
  /**
@@ -143,12 +179,16 @@ export class FecWorkerClient {
143
179
  reset() {
144
180
  if (this.#disposed)
145
181
  throw new Error("[FecWorkerClient] reset on a disposed client");
182
+ this.#flushSymbols();
146
183
  this.#pendingResets++;
147
184
  this.#cleanupInFlight = null;
148
185
  this.#queuedCleanupSbns.clear();
149
186
  this.#worker.postMessage({ type: "reset" });
150
187
  }
151
188
  #postCleanup(sbns) {
189
+ // The cleanup is a queue-drain barrier: every symbol fed before it is
190
+ // posted must reach the Worker first.
191
+ this.#flushSymbols();
152
192
  this.#cleanupInFlight = sbns;
153
193
  const orderedSbns = [...sbns].sort((a, b) => a - b);
154
194
  this.#worker.postMessage({ type: "cleanup", sbns: orderedSbns });
@@ -194,12 +234,21 @@ export class FecWorkerClient {
194
234
  if (this.#disposed)
195
235
  return;
196
236
  this.#disposed = true;
237
+ // A terminated Worker decodes nothing; symbols still batched are dropped.
238
+ this.#pendingSymbols = [];
239
+ this.#pendingTransfer = [];
197
240
  this.#cleanupInFlight = null;
198
241
  this.#queuedCleanupSbns.clear();
199
242
  this.#worker.postMessage({ type: "dispose" });
200
243
  this.#worker.terminate();
201
244
  }
202
245
  #handleEvent(event) {
246
+ if (event.type === "capabilities") {
247
+ if (Array.isArray(event.commands) && event.commands.includes("feedSymbols")) {
248
+ this.#batchSymbols = true;
249
+ }
250
+ return;
251
+ }
203
252
  if (event.type === "resetComplete") {
204
253
  this.#pendingResets = Math.max(0, this.#pendingResets - 1);
205
254
  this.#resetFailed = false;
@@ -1 +1 @@
1
- {"version":3,"file":"fec-worker-client.js","sourceRoot":"","sources":["../src/fec-worker-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAYH,MAAM,OAAO,eAAe;IAClB,OAAO,CAAS;IACzB,QAAQ,GAA0D,IAAI,CAAC;IACvE,WAAW,GAA4C,IAAI,CAAC;IAC5D,cAAc,GAA+C,IAAI,CAAC;IAClE,YAAY,GAAsD,IAAI,CAAC;IACvE,kBAAkB,GAAmC,IAAI,CAAC;IAC1D,QAAQ,GAAkE,IAAI,CAAC;IAC/E,gBAAgB,GAAuB,IAAI,CAAC;IAC5C,kBAAkB,GAAG,IAAI,GAAG,EAAU,CAAC;IACvC,cAAc,GAAG,CAAC,CAAC;IACnB,YAAY,GAAG,KAAK,CAAC;IACrB,SAAS,GAAG,KAAK,CAAC;IAElB;;;OAGG;IACH,YAAY,WAAyB;QACpC,IAAI,WAAW,YAAY,GAAG,EAAE,CAAC;YAChC,IAAI,CAAC,OAAO,GAAG,IAAI,MAAM,CAAC,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC5D,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,OAAO,GAAG,WAAW,CAAC;QAC5B,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,CAAC,CAA+B,EAAE,EAAE,CAC5D,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,CAAC,OAAO,CAAC,OAAO,GAAG,CAAC,CAAC,EAAE,EAAE;YAC5B,IAAI,CAAC,QAAQ,EAAE,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC;QAC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OAAO,CAAC,CAAC;QACjC,CAAC;QACD,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK;YAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACtD,CAAC;SAAM,IAAI,KAAK,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC;QAChC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC;AAED,SAAS,wBAAwB,CAAC,KAAmB;IACpD,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;IACxB,MAAM,MAAM,GACX,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAClB,IAAI,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;YAC5C,KAAK,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IAC/C,OAAO,4DAA4D,MAAM,EAAE,CAAC;AAC7E,CAAC"}
@@ -57,8 +57,10 @@ export interface FecBlockSnapshot {
57
57
  sourceReceived: number;
58
58
  /** Number of repair symbols received */
59
59
  repairReceived: number;
60
- /** Expected source symbols (K) */
60
+ /** Configured source-block geometry (K) */
61
61
  k: number;
62
+ /** Authored source symbols (SSB_length) once a repair symbol declared it */
63
+ ssbLength?: number;
62
64
  /** Expected repair symbols (P) */
63
65
  repairCount: number;
64
66
  /** Timestamp of first symbol arrival (ms) */
@@ -152,7 +154,7 @@ export interface FecTrackStats {
152
154
  };
153
155
  }
154
156
  /** Stable identities for Worker failures whose message text contains live values. */
155
- export type FecWorkerErrorCode = "recovered-symbol-size-unconfigured" | "recovered-block-too-short" | "repair-symbol-size-mismatch" | "reset-failed" | "unknown-command" | "command-failed" | "worker-runtime" | "worker-message";
157
+ export type FecWorkerErrorCode = "recovered-symbol-size-unconfigured" | "recovered-block-too-short" | "recovered-symbol-ssb-length-invalid" | "repair-symbol-size-mismatch" | "repair-ssb-length-conflict" | "reset-failed" | "unknown-command" | "command-failed" | "worker-runtime" | "worker-message";
156
158
  /** Per-frame metadata emitted with frame events from Worker. */
157
159
  export interface FrameMeta {
158
160
  /** ALTA verification result: true/false after check, null when ALTA not configured (AUTH-04) */
@@ -161,8 +163,14 @@ export interface FrameMeta {
161
163
  recovered: boolean;
162
164
  /** Source block number this frame belongs to */
163
165
  sbn: number;
164
- /** Encoding Symbol ID within the recovered source block (0..K-1). */
166
+ /** Encoding Symbol ID within the recovered source block (0..ssbLength-1). */
165
167
  esi?: number;
168
+ /**
169
+ * Authored source-symbol count of the recovered block (the repair
170
+ * symbols' SSB_length, 1..K). Recovered frames are ESI 0..ssbLength-1;
171
+ * ESIs ssbLength..K-1 are encoder zero padding and are never emitted.
172
+ */
173
+ ssbLength?: number;
166
174
  }
167
175
  /** Discriminated union of all commands sent from main thread to Worker. */
168
176
  export type FecWorkerCommand = {
@@ -210,6 +218,16 @@ export type FecWorkerCommand = {
210
218
  rsId: number;
211
219
  data: ArrayBuffer;
212
220
  ts: number;
221
+ } | {
222
+ /**
223
+ * Every source and repair symbol the page fed in one task, in feed
224
+ * order, sharing one transfer list. The client sends symbols this
225
+ * way instead of one message per symbol (BLO-36599); the Worker
226
+ * handles each record exactly like the single-symbol command of the
227
+ * same `type`, and a record that fails does not stop the others.
228
+ */
229
+ type: "feedSymbols";
230
+ symbols: FecSymbolCommand[];
213
231
  } | {
214
232
  type: "relayBlockSig";
215
233
  sbn: number;
@@ -224,6 +242,12 @@ export type FecWorkerCommand = {
224
242
  } | {
225
243
  type: "dispose";
226
244
  };
245
+ /** One symbol record of a `feedSymbols` batch. */
246
+ export type FecSymbolCommand = Extract<FecWorkerCommand, {
247
+ type: "feedSource";
248
+ } | {
249
+ type: "feedRepair";
250
+ }>;
227
251
  /** Discriminated union of all events emitted from Worker to main thread. */
228
252
  export type FecWorkerEvent = {
229
253
  type: "frame";
@@ -244,9 +268,21 @@ export type FecWorkerEvent = {
244
268
  sbns: number[];
245
269
  } | {
246
270
  type: "resetComplete";
271
+ }
272
+ /**
273
+ * Optional commands this Worker accepts, posted once it is configured.
274
+ * The client uses `feedSymbols` only after the Worker names it, so a page
275
+ * that meets an older cached Worker bundle keeps sending one command per
276
+ * symbol instead of a batch that Worker would reject (BLO-36599).
277
+ */
278
+ | {
279
+ type: "capabilities";
280
+ commands: FecWorkerOptionalCommand[];
247
281
  } | {
248
282
  type: "error";
249
283
  message: string;
250
284
  code?: FecWorkerErrorCode;
251
285
  };
286
+ /** Commands a client may send only after the Worker announced them. */
287
+ export type FecWorkerOptionalCommand = "feedSymbols";
252
288
  //# sourceMappingURL=fec-worker-types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fec-worker-types.d.ts","sourceRoot":"","sources":["../src/fec-worker-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,mFAAmF;AACnF,MAAM,WAAW,cAAc;IAC9B,oDAAoD;IACpD,KAAK,EAAE,MAAM,CAAC;IACd,8BAA8B;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,uBAAuB;IACvB,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC;IAC7B,2CAA2C;IAC3C,UAAU,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACtC,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4CAA4C;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,iEAAiE;IACjE,SAAS,EAAE,MAAM,CAAC;IAClB,mCAAmC;IACnC,CAAC,EAAE,MAAM,CAAC;IACV,qDAAqD;IACrD,WAAW,EAAE,MAAM,CAAC;IACpB,uBAAuB;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,qCAAqC;IAC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C5E,MAAM,MAAM,cAAc,GACvB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,SAAS,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,aAAa,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,KAAK,EAAE,gBAAgB,CAAA;CAAE,GAChD;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,WAAW,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,GAC3C;IAAE,IAAI,EAAE,eAAe,CAAA;CAAE;AAC3B;;;;;GAKG;GACD;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,QAAQ,EAAE,wBAAwB,EAAE,CAAA;CAAE,GAC9D;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAEjE,uEAAuE;AACvE,MAAM,MAAM,wBAAwB,GAAG,aAAa,CAAC"}
@@ -189,15 +189,16 @@ function emitRecoveredSymbols(sbn, recoveredBlock, block) {
189
189
  });
190
190
  return;
191
191
  }
192
- if (recoveredBlock.byteLength < symbolSize * config.k) {
192
+ const ssbLength = block.ssbLength ?? config.k;
193
+ if (recoveredBlock.byteLength !== symbolSize * ssbLength) {
193
194
  emit({
194
195
  type: "error",
195
196
  code: "recovered-block-too-short",
196
- message: `[FecWorker] recovered block too short: got ${recoveredBlock.byteLength}B, expected at least ${symbolSize * config.k}B`
197
+ message: `[FecWorker] recovered block has the wrong length: got ${recoveredBlock.byteLength}B, expected ${symbolSize * ssbLength}B (SSB_length=${ssbLength})`
197
198
  });
198
199
  return;
199
200
  }
200
- for (let i = 0; i < config.k; i++) {
201
+ for (let i = 0; i < ssbLength; i++) {
201
202
  const symbol = recoveredBlock.subarray(i * symbolSize, (i + 1) * symbolSize);
202
203
  const recoveredAltaVerified = null;
203
204
  if (altaEnabled) altaPending++;
@@ -206,7 +207,8 @@ function emitRecoveredSymbols(sbn, recoveredBlock, block) {
206
207
  altaVerified: recoveredAltaVerified,
207
208
  recovered: true,
208
209
  sbn,
209
- esi: i
210
+ esi: i,
211
+ ssbLength
210
212
  };
211
213
  emit({ type: "frame", data: buf, meta }, [buf]);
212
214
  }
@@ -289,6 +291,7 @@ async function handleConfigure(cmd) {
289
291
  }
290
292
  }
291
293
  wasmDecoder.configure_params(config.k, config.symbolSize);
294
+ emit({ type: "capabilities", commands: ["feedSymbols"] });
292
295
  startSnapshotTimer();
293
296
  emitSnapshot();
294
297
  }
@@ -322,12 +325,13 @@ function handleFeedSource(cmd) {
322
325
  block.lastSymbolTs = performance.now();
323
326
  sourceSymbols++;
324
327
  if (altaEnabled) altaPending++;
325
- if (block.sourceReceived >= block.k && block.state === "collecting") {
328
+ const authoredLength = block.ssbLength ?? block.k;
329
+ if (block.sourceReceived >= authoredLength && block.state === "collecting") {
326
330
  markBlockTerminal(block, "complete");
327
331
  blocksComplete++;
328
332
  emitBlockUpdate(block);
329
333
  }
330
- if (result && result.byteLength > 0 && block.sourceReceived < block.k) {
334
+ if (result && result.byteLength > 0 && block.sourceReceived < authoredLength) {
331
335
  const recovered = new Uint8Array(toOwnedArrayBuffer(result));
332
336
  const recoveryMs = performance.now() - block.firstSymbolTs;
333
337
  recoveryTimes.push(recoveryMs);
@@ -369,6 +373,14 @@ function handleFeedRepair(cmd) {
369
373
  const existingBlock = blocks.get(sbn);
370
374
  if (existingBlock && isTerminalBlock(existingBlock)) return;
371
375
  if (acceptedRepairEsis.get(sbn)?.has(repairEsi)) return;
376
+ if (existingBlock?.ssbLength !== void 0 && existingBlock.ssbLength !== cmd.ssbLength) {
377
+ emit({
378
+ type: "error",
379
+ code: "repair-ssb-length-conflict",
380
+ message: `[FecWorker] Dropping repair symbol whose SSB_length ${cmd.ssbLength} conflicts with ${existingBlock.ssbLength} (sbn=${sbn})`
381
+ });
382
+ return;
383
+ }
372
384
  const result = wasmDecoder.add_repair(
373
385
  cmd.ssStart,
374
386
  cmd.ssbLength,
@@ -384,10 +396,15 @@ function handleFeedRepair(cmd) {
384
396
  }
385
397
  repairEsis.add(repairEsi);
386
398
  const block = getOrCreateBlock(sbn);
399
+ block.ssbLength = cmd.ssbLength;
387
400
  block.repairReceived++;
388
401
  block.lastSymbolTs = performance.now();
389
402
  repairSymbols++;
390
- if (result && result.byteLength > 0) {
403
+ if (block.sourceReceived >= cmd.ssbLength && block.state === "collecting") {
404
+ markBlockTerminal(block, "complete");
405
+ blocksComplete++;
406
+ emitBlockUpdate(block);
407
+ } else if (result && result.byteLength > 0) {
391
408
  const recovered = new Uint8Array(toOwnedArrayBuffer(result));
392
409
  const recoveryMs = performance.now() - block.firstSymbolTs;
393
410
  recoveryTimes.push(recoveryMs);
@@ -425,7 +442,7 @@ function handleCleanup(cmd) {
425
442
  retireAcceptedIds(sbn);
426
443
  continue;
427
444
  }
428
- currentBlock ?? (currentBlock = getOrCreateBlock(sbn));
445
+ currentBlock ??= getOrCreateBlock(sbn);
429
446
  if (currentBlock.sourceReceived >= currentBlock.k) {
430
447
  markBlockTerminal(currentBlock, "complete");
431
448
  blocksComplete++;
@@ -518,6 +535,28 @@ function handleReset() {
518
535
  emit({ type: "resetComplete" });
519
536
  if (config) emitSnapshot();
520
537
  }
538
+ function handleFeedSymbols(cmd) {
539
+ if (!Array.isArray(cmd.symbols)) {
540
+ throw new Error("[FecWorker] feedSymbols: symbols must be an array");
541
+ }
542
+ for (const symbol of cmd.symbols) {
543
+ try {
544
+ if (symbol?.type === "feedSource") handleFeedSource(symbol);
545
+ else if (symbol?.type === "feedRepair") handleFeedRepair(symbol);
546
+ else {
547
+ throw new Error(
548
+ `[FecWorker] feedSymbols: unknown symbol type ${String(symbol?.type)}`
549
+ );
550
+ }
551
+ } catch (err) {
552
+ emit({
553
+ type: "error",
554
+ code: "command-failed",
555
+ message: err instanceof Error ? err.message : `[FecWorker] ${String(err)}`
556
+ });
557
+ }
558
+ }
559
+ }
521
560
  async function dispatchCommand(cmd) {
522
561
  try {
523
562
  switch (cmd.type) {
@@ -530,6 +569,9 @@ async function dispatchCommand(cmd) {
530
569
  case "feedRepair":
531
570
  handleFeedRepair(cmd);
532
571
  break;
572
+ case "feedSymbols":
573
+ handleFeedSymbols(cmd);
574
+ break;
533
575
  case "relayBlockSig":
534
576
  handleRelayBlockSig(cmd);
535
577
  break;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/transfer.ts", "../src/fec-worker.ts"],
4
- "sourcesContent": ["/**\n * Return a fresh ArrayBuffer containing exactly the bytes in `view`.\n *\n * Worker outputs must not transfer buffers that might be owned by a WASM\n * binding or by a larger shared packet. A fresh JS-owned buffer gives\n * postMessage() exclusive ownership without detaching unrelated memory.\n */\nexport function toOwnedArrayBuffer(view: Uint8Array): ArrayBuffer {\n\tconst copy = new Uint8Array(view.byteLength);\n\tcopy.set(view);\n\treturn copy.buffer;\n}\n", "/**\n * @blockcast/fec-worker \u2014 Worker Entry Point\n *\n * Runs inside DedicatedWorkerGlobalScope. Receives FecWorkerCommand messages,\n * drives the MmtFecDecoder WASM module, emits FecWorkerEvent messages back.\n *\n * WASM bindings are resolved via:\n * 1. (self as any).__MMT_WASM_BINDINGS__ \u2014 set by consumer's loader/importmap\n * 2. Falls back to error if not available (no defaults)\n *\n * This file must NOT import DOM globals incompatible with Worker scope.\n */\n\nimport type {\n\tFecWorkerCommand,\n\tFecWorkerEvent,\n\tFecTrackConfig,\n\tFecTrackStats,\n\tFecBlockSnapshot,\n\tFrameMeta,\n} from \"./fec-worker-types.js\";\nimport { toOwnedArrayBuffer } from \"./transfer.js\";\n\n// --- WASM binding types (from mmt-wasm) ---\n// Signatures MUST match a freshly generated external mmt_wasm.d.ts exactly.\n// The decoder derives SBN/ESI internally \u2014 do not pre-compute.\ninterface WasmFecDecoder {\n\t/** ISO 23008-1 \u00A7C.5.2: ss_id is the flat 32-bit Source Symbol ID. */\n\tadd_source(\n\t\tss_id: number,\n\t\tdata: Uint8Array,\n\t\ttimestamp: number,\n\t): Uint8Array | undefined;\n\t/** ISO 23008-1 \u00A7C.5.3: repair ESI = configured K + rs_id, SBN = ss_start / configured K. */\n\tadd_repair(\n\t\tss_start: number,\n\t\tssb_length: number,\n\t\trs_id: number,\n\t\tdata: Uint8Array,\n\t\ttimestamp: number,\n\t): Uint8Array | undefined;\n\tconfigure_params(k: number, symbolSize: number): void;\n\t/** Block-scoped counterpart driven by the manager's exact deadlines. */\n\tcleanup_blocks_detailed(sbns: Uint32Array): Uint8Array;\n\t/** Remove decoder blocks below its configured live-SBN interleave horizon. */\n\tcleanup_by_sbn(current_sbn: number): Uint32Array;\n\tflush(): void;\n\tpending_blocks(): number;\n\treset_stats(): void;\n\tget_stats(): {\n\t\tsource_packets: bigint;\n\t\trepair_packets: bigint;\n\t\tblocks_complete: bigint;\n\t\tblocks_recovered: bigint;\n\t\tblocks_failed: bigint;\n\t\tbytes_recovered: bigint;\n\t\trecovery_rate(): number;\n\t};\n\tfree(): void;\n}\n\ninterface WasmBindings {\n\tinitSync(module: { module: WebAssembly.Module }): unknown;\n\tMmtFecDecoder: new (\n\t\tinterleaveDepth: number,\n\t\tgreenFillEnabled: boolean,\n\t) => WasmFecDecoder;\n}\n\n// --- Worker state (local to this Worker instance) ---\n\nlet wasmDecoder: WasmFecDecoder | null = null;\nlet config: FecTrackConfig | null = null;\nlet altaEnabled = false;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nlet altaVerifier: any = null; // JsAltaVerifier instance (loaded from ALTA WASM)\nlet snapshotTimer: ReturnType<typeof setInterval> | null = null;\n\n// Block tracking\nconst blocks = new Map<number, FecBlockSnapshot>();\nconst acceptedSourceEsis = new Map<number, Set<number>>();\nconst acceptedRepairEsis = new Map<number, Set<number>>();\nconst UINT32_MAX = 0xffff_ffff;\nconst UINT24_MAX = 0xff_ffff;\n// ISO/IEC 23008-1 AL-FEC signaling carries interleave_depth in one byte.\nconst MAX_INTERLEAVE_DEPTH = 0xff;\n// Rust stores T as u16 and this decoder profile fixes RFC 6330 Al=8.\nconst MAX_SYMBOL_SIZE = 0xfff8;\n// RFC 6330 systematic table limit, enforced by the vendored raptorq decoder.\nconst MAX_RAPTORQ_SOURCE_SYMBOLS_PER_BLOCK = 56_403;\n\n// Aggregate counters\nlet sourceSymbols = 0;\nlet repairSymbols = 0;\nlet blocksComplete = 0;\nlet blocksRecovered = 0;\nlet blocksFailed = 0;\nlet greenFillFrames = 0;\nlet altaVerified = 0;\nlet altaFailed = 0; // Crypto-confirmed tamper (MAC / sig / hash chain mismatch)\nconst altaFailedDetails: Array<{\n\tseq: number;\n\terror: string;\n\tauthLen: number;\n\tpayloadLen: number;\n\tpath: string; // \"direct\" | \"recovered\" | \"pending-retry\"\n}> = [];\nlet altaPending = 0; // Unverifiable but not tamper (no trailer, verifier not ready, anchor missing)\nlet altaPendingEvictedCap = 0; // Incoming \"pending\" packets rejected because the queue was at cap after stale-sweep (flood indicator)\nlet altaPendingEvictedTtl = 0; // Deferred-queue entries dropped by TTL (retry window expired)\nlet altaError = 0; // verifyDetached threw \u2014 infrastructure flake, not tamper\nlet altaInitFailed = false; // ALTA configured but WASM init failed; altaEnabled was forced off\nlet relayBlocksVerified = 0;\nlet relayBlocksFailed = 0;\nlet liveSbn = 0;\n// Highest SBN that has fallen strictly below the decoder's retained\n// interleave window. Numeric ordering is per decoder epoch; reset/configure\n// starts a new epoch before the 32-bit source-symbol counter can wrap.\nlet retiredSbnFrontier = -1;\nlet repairSymbolSizeMismatch = 0;\n\n// Recovery timing\nconst recoveryTimes: number[] = [];\n\n// \u2500\u2500 Deferred ALTA verification queue (08-07 Path 3) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n//\n// When an ALTA packet arrives whose MAC references point at sequences not yet\n// in the verifier's ring buffer, we can't anchor trust \u2014 verify returns \"No\n// trust anchor\". Typical cause: a predecessor packet was lost and hasn't been\n// FEC-recovered yet. Rather than drop these, hold them in a bounded FIFO and\n// retry verification after every successful verify (direct or FEC-recovered)\n// that seeds the ring buffer with new raw bytes.\n//\n// Zero-copy (1B-B): the queue entry stores a Uint8Array view into the\n// original `data` ArrayBuffer. JS GC keeps the buffer alive via the view\n// reference; no bytes are copied on queue.\n//\n// Timeout entries (TTL exceeded) and cap-rejections count as `altaPending`\n// (2C-B): they're not tamper indicators, they're just packets that couldn't\n// be authenticated within the receive window \u2014 either loss or, in the cap\n// case, a flood of unanchorable arrivals (real or attacker-driven) that\n// exceeded the queue budget. See enqueuePendingVerify for the rate-limit\n// protocol.\ninterface PendingVerify {\n\tseq: number;\n\tauth: Uint8Array;\n\tpayload: Uint8Array;\n\tarrivalTs: number;\n}\nconst pendingVerify = new Map<number, PendingVerify>();\nlet pendingVerifyCap = 0;\nlet pendingVerifyTtlMs = 0;\n\n// --- Helpers ---\n\nfunction emit(event: FecWorkerEvent, transfer?: Transferable[]): void {\n\tself.postMessage(event, transfer ?? []);\n}\n\nfunction isUint32(value: number): boolean {\n\treturn Number.isInteger(value) && value >= 0 && value <= UINT32_MAX;\n}\n\nfunction isTerminalBlock(block: FecBlockSnapshot): boolean {\n\treturn block.state !== \"collecting\";\n}\n\nfunction retireAcceptedIds(sbn: number): void {\n\tacceptedSourceEsis.delete(sbn);\n\tacceptedRepairEsis.delete(sbn);\n}\n\nfunction clearBlockTracking(): void {\n\tblocks.clear();\n\tacceptedSourceEsis.clear();\n\tacceptedRepairEsis.clear();\n\tpendingVerify.clear();\n\trecoveryTimes.length = 0;\n\tliveSbn = 0;\n\tretiredSbnFrontier = -1;\n}\n\n/**\n * Retire terminal diagnostics only after the decoder's monotonic interleave\n * horizon proves that the SBN can no longer be valid out-of-order media.\n * Admission keeps the compact frontier as the durable tombstone, so deletion\n * never reopens a finalized block.\n */\nfunction trimBlockRetention(): void {\n\tfor (const [sbn, block] of blocks) {\n\t\tif (!isTerminalBlock(block) || sbn > retiredSbnFrontier) continue;\n\t\tblocks.delete(sbn);\n\t\tretireAcceptedIds(sbn);\n\t}\n}\n\nfunction advanceMediaHorizon(sbn: number): void {\n\tif (!config || sbn <= liveSbn) return;\n\tliveSbn = sbn;\n\tconst firstRetainedSbn = Math.max(0, liveSbn - config.interleaveDepth);\n\tretiredSbnFrontier = Math.max(retiredSbnFrontier, firstRetainedSbn - 1);\n\ttrimBlockRetention();\n}\n\nfunction markBlockTerminal(\n\tblock: FecBlockSnapshot,\n\tstate: \"complete\" | \"recovered\" | \"failed\",\n): void {\n\tblock.state = state;\n\tblock.completedTs = performance.now();\n\tretireAcceptedIds(block.sbn);\n\ttrimBlockRetention();\n}\n\nfunction synchronizeDecoderHorizon(): void {\n\tif (!wasmDecoder) return;\n\tconst expired = wasmDecoder.cleanup_by_sbn(liveSbn);\n\tfor (const sbn of expired) {\n\t\tconst block = blocks.get(sbn);\n\t\tif (!block || isTerminalBlock(block)) {\n\t\t\tretireAcceptedIds(sbn);\n\t\t\tcontinue;\n\t\t}\n\t\tmarkBlockTerminal(block, \"failed\");\n\t\tblocksFailed++;\n\t\temitBlockUpdate(block);\n\t}\n\ttrimBlockRetention();\n}\n\n/**\n * Run detached ALTA verify against the current verifier. Four-state result:\n * - \"valid\": crypto passed, packet authentic. Caller increments altaVerified.\n * - \"failed\": crypto confirmed tamper (MAC/sig mismatch, hash chain mismatch).\n * Caller increments altaFailed. Not retryable.\n * - \"pending\": anchor missing (MAC refs not in buffer, no signature, not\n * early-warmup). Caller may enqueue for retry after the next\n * successful verify seeds the ring buffer.\n * - \"error\": verifier threw \u2014 WASM trap, unmarshal panic, OOM. Caller\n * increments altaError (infrastructure flake, not tamper).\n * The distinction matters for ops alerting: a spike in\n * altaError indicates a runtime problem, not an attack.\n */\nlet _lastVerifyError = \"\";\nfunction runDetachedVerify(\n\tauth: Uint8Array,\n\tpayload: Uint8Array,\n): \"valid\" | \"failed\" | \"pending\" | \"error\" {\n\tif (!altaVerifier) return \"pending\";\n\ttry {\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tconst r: any = altaVerifier.verifyDetached(auth, payload);\n\t\tif (r.valid) {\n\t\t\t_lastVerifyError = \"\";\n\t\t\treturn \"valid\";\n\t\t}\n\t\tconst err = (r.error as string | undefined) ?? \"\";\n\t\t_lastVerifyError = err;\n\t\t// The bootstrap-friendly verifier returns this specific error string when\n\t\t// the only obstacle to verification is a missing anchor (see alta-rs\n\t\t// verifier.rs verify()). Distinguishing this from tamper cases keeps us\n\t\t// from queuing packets that are definitively invalid.\n\t\tif (err.startsWith(\"No trust anchor\")) return \"pending\";\n\t\treturn \"failed\";\n\t} catch (e) {\n\t\t// Ratelimit: first ~N occurrences get logged. A sustained exception\n\t\t// stream indicates a real problem \u2014 the altaError counter is the\n\t\t// durable signal.\n\t\tif (altaError < 5) {\n\t\t\tconsole.warn(\"[FecWorker] verifyDetached threw:\", e);\n\t\t}\n\t\treturn \"error\";\n\t}\n}\n\n/** Extract u32 BE sequence number from the ALTA authenticator header (offset 0..3). */\nfunction seqFromAuth(auth: Uint8Array): number {\n\treturn (\n\t\t((auth[0]! << 24) | (auth[1]! << 16) | (auth[2]! << 8) | auth[3]!) >>> 0\n\t);\n}\n\n/**\n * Enqueue a packet whose ALTA verification returned \"pending\" (anchor\n * missing). Dedupes by sequence number.\n *\n * Flood resistance (08-08 review): when the queue is at cap we do NOT\n * evict the oldest entry. The oldest entry is typically the most\n * load-bearing one \u2014 it's the packet whose anchor everything else in the\n * queue is waiting on. Evict-oldest-on-insert let an attacker emitting a\n * stream of \"No trust anchor\" packets flood out legitimate entries and\n * prevent them from ever anchoring. Instead:\n * 1. First try to free stale TTL'd entries (they'd be evicted on next\n * drain anyway \u2014 pulling that forward is free).\n * 2. If still full, reject the NEW entry. altaPendingEvictedCap counts\n * these rejections (rate-limit trigger).\n *\n * Stores Uint8Array views into the original data + auth buffers \u2014 no copy.\n * The views keep their underlying ArrayBuffers alive via GC references.\n */\nfunction enqueuePendingVerify(\n\tauth: Uint8Array,\n\tpayload: Uint8Array,\n): void {\n\tconst seq = seqFromAuth(auth);\n\tif (pendingVerify.has(seq)) return;\n\n\tif (pendingVerify.size >= pendingVerifyCap) {\n\t\t// Step 1: sweep stale entries so legitimate traffic isn't penalized\n\t\t// by TTL'd junk that happens to still occupy slots.\n\t\tconst now = performance.now();\n\t\tfor (const [staleSeq, entry] of pendingVerify) {\n\t\t\tif (now - entry.arrivalTs > pendingVerifyTtlMs) {\n\t\t\t\tpendingVerify.delete(staleSeq);\n\t\t\t\taltaPendingEvictedTtl++;\n\t\t\t}\n\t\t}\n\t\t// Step 2: if the queue is still at cap it's a genuine flood \u2014\n\t\t// reject the new entry rather than evict an existing one. The\n\t\t// rejected packet counts as altaPendingEvictedCap (which is\n\t\t// surfaced up through stats for rate-limit alerting).\n\t\tif (pendingVerify.size >= pendingVerifyCap) {\n\t\t\taltaPendingEvictedCap++;\n\t\t\treturn;\n\t\t}\n\t}\n\n\tpendingVerify.set(seq, {\n\t\tseq,\n\t\tauth,\n\t\tpayload,\n\t\tarrivalTs: performance.now(),\n\t});\n}\n\n/**\n * Retry every queued entry. Called after every successful verify (direct\n * source or FEC-recovered) \u2014 new raw bytes in the verifier's ring buffer may\n * unblock previously-pending MAC references.\n *\n * Three outcomes per entry:\n * - \"valid\" \u2192 remove from queue, altaVerified++\n * - \"failed\" \u2192 remove from queue, altaFailed++ (tamper on retry)\n * - \"pending\" \u2192 keep in queue, unless TTL expired (then evict as altaPending)\n *\n * Iteration order: Map preserves insertion order, so we drain oldest-first.\n * No-op when the queue is empty or the verifier isn't ready.\n */\nfunction drainPendingVerify(): void {\n\tif (pendingVerify.size === 0 || !altaVerifier) return;\n\tconst now = performance.now();\n\t// Collect keys to avoid mutating Map during iteration\n\tconst keys = Array.from(pendingVerify.keys());\n\tfor (const seq of keys) {\n\t\tconst entry = pendingVerify.get(seq);\n\t\tif (!entry) continue;\n\t\tif (now - entry.arrivalTs > pendingVerifyTtlMs) {\n\t\t\tpendingVerify.delete(seq);\n\t\t\taltaPendingEvictedTtl++;\n\t\t\tcontinue;\n\t\t}\n\t\tconst result = runDetachedVerify(entry.auth, entry.payload);\n\t\tif (result === \"valid\") {\n\t\t\tpendingVerify.delete(seq);\n\t\t\taltaVerified++;\n\t\t} else if (result === \"failed\") {\n\t\t\tpendingVerify.delete(seq);\n\t\t\taltaFailed++;\n\t\t\tif (altaFailedDetails.length < 16) {\n\t\t\t\taltaFailedDetails.push({\n\t\t\t\t\tseq: entry.seq,\n\t\t\t\t\terror: _lastVerifyError,\n\t\t\t\t\tauthLen: entry.auth.length,\n\t\t\t\t\tpayloadLen: entry.payload.length,\n\t\t\t\t\tpath: \"pending-retry\",\n\t\t\t\t});\n\t\t\t}\n\t\t} else if (result === \"error\") {\n\t\t\t// Infrastructure failure \u2014 remove from queue, count as altaError.\n\t\t\t// Keeping it around would just re-throw on every subsequent drain.\n\t\t\tpendingVerify.delete(seq);\n\t\t\taltaError++;\n\t\t}\n\t\t// \"pending\" \u2192 leave in queue for next drain\n\t}\n}\n\nfunction getOrCreateBlock(sbn: number): FecBlockSnapshot {\n\tlet block = blocks.get(sbn);\n\tif (!block) {\n\t\tif (!config) throw new Error(\"[FecWorker] not configured\");\n\t\tconst now = performance.now();\n\t\tblock = {\n\t\t\tsbn,\n\t\t\tstate: \"collecting\",\n\t\t\tsourceReceived: 0,\n\t\t\trepairReceived: 0,\n\t\t\tk: config.k,\n\t\t\trepairCount: config.repairCount,\n\t\t\tfirstSymbolTs: now,\n\t\t\tlastSymbolTs: now,\n\t\t\tdeadlineTs: now + config.deliveryWindowMs,\n\t\t\taltaVerified: 0,\n\t\t\trelayBlockSigValid: null,\n\t\t};\n\t\tblocks.set(sbn, block);\n\t\ttrimBlockRetention();\n\t}\n\treturn block;\n}\n\nfunction buildStatsSnapshot(): FecTrackStats {\n\tif (!config) throw new Error(\"[FecWorker] not configured\");\n\tconst decoderStats = wasmDecoder?.get_stats();\n\tconst decoder = decoderStats\n\t\t? {\n\t\t\tsourcePackets: Number(decoderStats.source_packets),\n\t\t\trepairPackets: Number(decoderStats.repair_packets),\n\t\t\tblocksComplete: Number(decoderStats.blocks_complete),\n\t\t\tblocksRecovered: Number(decoderStats.blocks_recovered),\n\t\t\tblocksFailed: Number(decoderStats.blocks_failed),\n\t\t\tbytesRecovered: Number(decoderStats.bytes_recovered),\n\t\t\tpendingBlocks: wasmDecoder?.pending_blocks() ?? 0,\n\t\t}\n\t\t: undefined;\n\n\tconst avgRecoveryMs =\n\t\trecoveryTimes.length > 0\n\t\t\t? recoveryTimes.reduce((a, b) => a + b, 0) / recoveryTimes.length\n\t\t\t: 0;\n\tconst maxRecoveryMs =\n\t\trecoveryTimes.length > 0 ? Math.max(...recoveryTimes) : 0;\n\n\t// Cap block array to interleave window\n\tconst maxBlocks = Math.max(config.interleaveDepth * 3, 24);\n\tconst blockArray = Array.from(blocks.values())\n\t\t.sort((a, b) => b.sbn - a.sbn)\n\t\t.slice(0, maxBlocks);\n\n\treturn {\n\t\tconfig,\n\t\tsourceSymbols,\n\t\trepairSymbols,\n\t\tblocksComplete,\n\t\tblocksRecovered,\n\t\tblocksFailed,\n\t\tgreenFillFrames,\n\t\trecoveryRate:\n\t\t\tblocksComplete + blocksRecovered > 0\n\t\t\t\t? Math.round(\n\t\t\t\t\t\t(blocksRecovered / (blocksRecovered + blocksFailed)) * 100,\n\t\t\t\t\t) || 0\n\t\t\t\t: 0,\n\t\taltaVerified,\n\t\taltaFailed,\n\t\taltaPending,\n\t\taltaPendingEvictedCap,\n\t\taltaPendingEvictedTtl,\n\t\taltaError,\n\t\taltaInitFailed,\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\taltaFailedDetails: altaFailedDetails.slice() as any,\n\t\trelayBlocksVerified,\n\t\trelayBlocksFailed,\n\t\tliveSbn,\n\t\tblocks: blockArray,\n\t\tinterleaveWindowBlocks: config.interleaveDepth,\n\t\tavgRecoveryMs: Math.round(avgRecoveryMs * 100) / 100,\n\t\tmaxRecoveryMs: Math.round(maxRecoveryMs * 100) / 100,\n\t\trepairSymbolSizeMismatch,\n\t\tdecoder,\n\t};\n}\n\nfunction emitSnapshot(): void {\n\tif (!config) return;\n\temit({ type: \"snapshot\", stats: buildStatsSnapshot() });\n}\n\nfunction emitBlockUpdate(block: FecBlockSnapshot): void {\n\temit({ type: \"blockUpdate\", block: { ...block } });\n}\n\nfunction emitRecoveredSymbols(\n\tsbn: number,\n\trecoveredBlock: Uint8Array,\n\tblock: FecBlockSnapshot,\n): void {\n\tif (!config) return;\n\tconst symbolSize = config.symbolSize;\n\tif (symbolSize <= 0) {\n\t\temit({\n\t\t\ttype: \"error\",\n\t\t\tcode: \"recovered-symbol-size-unconfigured\",\n\t\t\tmessage: \"[FecWorker] recovered block has no configured symbolSize\",\n\t\t});\n\t\treturn;\n\t}\n\tif (recoveredBlock.byteLength < symbolSize * config.k) {\n\t\temit({\n\t\t\ttype: \"error\",\n\t\t\tcode: \"recovered-block-too-short\",\n\t\t\tmessage: `[FecWorker] recovered block too short: got ${recoveredBlock.byteLength}B, expected at least ${symbolSize * config.k}B`,\n\t\t});\n\t\treturn;\n\t}\n\n\tfor (let i = 0; i < config.k; i++) {\n\t\tconst symbol = recoveredBlock.subarray(i * symbolSize, (i + 1) * symbolSize);\n\n\t\t// Source authentication now runs once at router admission in\n\t\t// @blockcast/mmt-manifest-verify. The worker only records that this\n\t\t// legacy ALTA-enabled symbol bypassed hot-path verification.\n\t\tconst recoveredAltaVerified: boolean | null = null;\n\t\tif (altaEnabled) altaPending++;\n\n\t\tconst buf = toOwnedArrayBuffer(symbol);\n\t\tconst meta: FrameMeta = {\n\t\t\taltaVerified: recoveredAltaVerified,\n\t\t\trecovered: true,\n\t\t\tsbn,\n\t\t\tesi: i,\n\t\t};\n\t\temit({ type: \"frame\", data: buf, meta }, [buf]);\n\t}\n}\n\nfunction startSnapshotTimer(): void {\n\tif (snapshotTimer !== null) clearInterval(snapshotTimer);\n\tsnapshotTimer = setInterval(() => emitSnapshot(), 200);\n}\n\nfunction resolveWasmBindings(): WasmBindings {\n\tconst bindings = (self as unknown as Record<string, unknown>)\n\t\t.__MMT_WASM_BINDINGS__ as WasmBindings | undefined;\n\tif (!bindings) {\n\t\tthrow new Error(\n\t\t\t\"[FecWorker] WASM bindings not available. Set self.__MMT_WASM_BINDINGS__ = { initSync, MmtFecDecoder } before configure.\",\n\t\t);\n\t}\n\treturn bindings;\n}\n\n// --- Command handlers ---\n\nasync function handleConfigure(\n\tcmd: Extract<FecWorkerCommand, { type: \"configure\" }>,\n): Promise<void> {\n\tif (!cmd.wasmModule) {\n\t\tthrow new Error(\"[FecWorker] configure: wasmModule required\");\n\t}\n\tif (!cmd.config) {\n\t\tthrow new Error(\"[FecWorker] configure: config required\");\n\t}\n\tif (\n\t\t!Number.isFinite(cmd.config.interleaveDepth) ||\n\t\t!Number.isInteger(cmd.config.interleaveDepth) ||\n\t\tcmd.config.interleaveDepth <= 0 ||\n\t\tcmd.config.interleaveDepth > MAX_INTERLEAVE_DEPTH\n\t) {\n\t\tthrow new Error(\n\t\t\t`[FecWorker] configure: interleaveDepth must be an integer in 1..${MAX_INTERLEAVE_DEPTH} (got ${cmd.config.interleaveDepth})`,\n\t\t);\n\t}\n\tif (\n\t\t!Number.isFinite(cmd.config.interleaveMs) ||\n\t\tcmd.config.interleaveMs <= 0\n\t) {\n\t\tthrow new Error(\n\t\t\t`[FecWorker] configure: interleaveMs must be finite and > 0 (got ${cmd.config.interleaveMs})`,\n\t\t);\n\t}\n\tif (\n\t\t!Number.isFinite(cmd.config.deliveryWindowMs) ||\n\t\tcmd.config.deliveryWindowMs <= 0\n\t) {\n\t\tthrow new Error(\n\t\t\t`[FecWorker] configure: deliveryWindowMs must be > 0 (got ${cmd.config.deliveryWindowMs})`,\n\t\t);\n\t}\n\tif (\n\t\t!Number.isInteger(cmd.config.k) ||\n\t\tcmd.config.k <= 0 ||\n\t\tcmd.config.k > MAX_RAPTORQ_SOURCE_SYMBOLS_PER_BLOCK\n\t) {\n\t\tthrow new Error(\n\t\t\t`[FecWorker] configure: k must be an integer in 1..${MAX_RAPTORQ_SOURCE_SYMBOLS_PER_BLOCK} (got ${cmd.config.k})`,\n\t\t);\n\t}\n\tif (\n\t\t!Number.isInteger(cmd.config.symbolSize) ||\n\t\tcmd.config.symbolSize <= 0 ||\n\t\tcmd.config.symbolSize > MAX_SYMBOL_SIZE ||\n\t\tcmd.config.symbolSize % 8 !== 0\n\t) {\n\t\tthrow new Error(\n\t\t\t`[FecWorker] configure: symbolSize must be an 8-byte-aligned integer in 8..${MAX_SYMBOL_SIZE} (got ${cmd.config.symbolSize})`,\n\t\t);\n\t}\n\n\tconst wasm = resolveWasmBindings();\n\n\t// Initialize WASM from pre-compiled Module (no fetch, no re-compile)\n\twasm.initSync({ module: cmd.wasmModule });\n\n\t// A configure command starts a new decoder epoch. No terminal tombstone,\n\t// accepted-symbol ID, or active block from the previous decoder may affect it.\n\twasmDecoder?.free();\n\twasmDecoder = null;\n\tclearBlockTracking();\n\n\t// Decoder policy and geometry are explicit at the epoch boundary. The WASM\n\t// module has no guessed K/T/interleave slow path.\n\twasmDecoder = new wasm.MmtFecDecoder(\n\t\tcmd.config.interleaveDepth,\n\t\tcmd.config.trackType === \"video\",\n\t);\n\tconfig = cmd.config;\n\taltaEnabled = !!cmd.altaPublicKey;\n\n\t// Size the deferred-verify queue strictly from catalog-derived FEC\n\t// parameters. CLAUDE.md bans Math.max(x, floor) magic \u2014 if catalog\n\t// values are zero/missing, throw at init rather than silently applying\n\t// a hardcoded floor. Consumers of an undersized queue cap would see\n\t// altaPendingEvictedCap spike with no actionable signal.\n\t// Cap: 1.5\u00D7 interleave depth \u2014 wide enough to hold one full FEC recovery\n\t// window plus jitter, narrow enough to bound memory.\n\tpendingVerifyCap = Math.ceil(config.interleaveDepth * 1.5);\n\t// TTL: 1.5\u00D7 block duration (K symbols at one per interleave tick) \u2014\n\t// after this many ms, any unresolved entry has missed its FEC window.\n\tpendingVerifyTtlMs = Math.ceil(config.interleaveMs * config.k * 1.5);\n\n\t// Initialize ALTA WASM verifier if public key and WASM module provided (D-05, D-09)\n\taltaVerifier = null;\n\taltaInitFailed = false;\n\tif (cmd.altaPublicKey && cmd.altaWasmModule) {\n\t\ttry {\n\t\t\t// Load ALTA JS glue (wasm-bindgen output from wasm-pack build).\n\t\t\t// Mirrors the RaptorQ WASM pattern: initSync({ module }) then construct.\n\t\t\t// Dynamic import path matches the IWA static asset layout.\n\t\t\t// Cast via string to prevent TypeScript from attempting static resolution\n\t\t\t// of a runtime-only URL (same pattern as fec-worker-entry.js loading).\n\t\t\tconst altaGlueUrl = '/wasm/alta/alta_rs.js' as string;\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\tconst altaGlue: any = await import(/* webpackIgnore: true */ altaGlueUrl);\n\t\t\taltaGlue.initSync({ module: cmd.altaWasmModule });\n\t\t\tconst keyBytes = new Uint8Array(cmd.altaPublicKey);\n\t\t\taltaVerifier = new altaGlue.JsAltaVerifier(keyBytes);\n\t\t} catch (e) {\n\t\t\t// T-08-15: WASM init failure must NOT silently look like \"not-ready-yet\".\n\t\t\t// Force altaEnabled = false so handleFeedSource takes the disabled\n\t\t\t// branch instead of continuously bumping altaPending under the\n\t\t\t// misleading \"verifier not yet ready\" comment. altaInitFailed\n\t\t\t// flag in the snapshot tells consumers this is an error state, not\n\t\t\t// an opt-out.\n\t\t\tconsole.warn('[FecWorker] ALTA WASM init failed, verification disabled:', e);\n\t\t\taltaVerifier = null;\n\t\t\taltaEnabled = false;\n\t\t\taltaInitFailed = true;\n\t\t}\n\t}\n\n\twasmDecoder.configure_params(config.k, config.symbolSize);\n\n\t// Start periodic snapshot emission (200ms floor)\n\tstartSnapshotTimer();\n\n\t// Emit initial snapshot\n\temitSnapshot();\n}\n\nfunction handleFeedSource(\n\tcmd: Extract<FecWorkerCommand, { type: \"feedSource\" }>,\n): void {\n\tif (!wasmDecoder) {\n\t\tthrow new Error(\"[FecWorker] feedSource: not configured\");\n\t}\n\tif (!config) {\n\t\tthrow new Error(\"[FecWorker] feedSource: config missing\");\n\t}\n\tif (\n\t\t!isUint32(cmd.ssId) ||\n\t\t!(cmd.data instanceof ArrayBuffer)\n\t) {\n\t\tthrow new Error(\"[FecWorker] feedSource: invalid source symbol\");\n\t}\n\n\tconst view = new Uint8Array(cmd.data);\n\n\t// Derive SBN locally for block-level accounting. WASM derives the same\n\t// value internally (ISO 23008-1 \u00A7C.5.2: SBN = floor(SS_ID / K)).\n\tconst sbn = config.k > 0 ? Math.floor(cmd.ssId / config.k) : cmd.ssId;\n\tconst esi = cmd.ssId % config.k;\n\tif (sbn <= retiredSbnFrontier) return;\n\tconst existingBlock = blocks.get(sbn);\n\tif (existingBlock && isTerminalBlock(existingBlock)) return;\n\tif (acceptedSourceEsis.get(sbn)?.has(esi)) return;\n\n\tconst result = wasmDecoder.add_source(cmd.ssId, view, cmd.ts);\n\tadvanceMediaHorizon(sbn);\n\tlet sourceEsis = acceptedSourceEsis.get(sbn);\n\tif (!sourceEsis) {\n\t\tsourceEsis = new Set<number>();\n\t\tacceptedSourceEsis.set(sbn, sourceEsis);\n\t}\n\tsourceEsis.add(esi);\n\n\t// Update block state\n\tconst block = getOrCreateBlock(sbn);\n\tblock.sourceReceived++;\n\tblock.lastSymbolTs = performance.now();\n\tsourceSymbols++;\n\n\t// The FEC worker must remain decode-only on the per-symbol hot path. ALTA\n\t// WASM is retained temporarily for low-rate signaling users, but media is\n\t// authenticated by the canonical manifest verifier at router admission.\n\tif (altaEnabled) altaPending++;\n\n\t// Check if block is complete (all K source symbols received)\n\tif (\n\t\tblock.sourceReceived >= block.k &&\n\t\tblock.state === \"collecting\"\n\t) {\n\t\tmarkBlockTerminal(block, \"complete\");\n\t\tblocksComplete++;\n\t\temitBlockUpdate(block);\n\t}\n\n\t\t// A source-triggered return can be either clean block completion or recovery\n\t\t// of earlier missing symbols after repair arrived. Clean completion is\n\t\t// already routed by the source path, so only emit when the block did not\n\t\t// reach K source arrivals.\n\t\tif (result && result.byteLength > 0 && block.sourceReceived < block.k) {\n\t\t\tconst recovered = new Uint8Array(toOwnedArrayBuffer(result));\n\t\t\tconst recoveryMs = performance.now() - block.firstSymbolTs;\n\t\t\trecoveryTimes.push(recoveryMs);\n\t\t\tif (recoveryTimes.length > 1000) recoveryTimes.shift();\n\n\t\t\tif (block.state === \"collecting\") {\n\t\t\t\tmarkBlockTerminal(block, \"recovered\");\n\t\t\t\tblocksRecovered++;\n\t\t\t\temitBlockUpdate(block);\n\t\t\t}\n\t\t\temitRecoveredSymbols(sbn, recovered, block);\n\t\t}\n\t\tsynchronizeDecoderHorizon();\n\t}\n\nfunction handleFeedRepair(\n\tcmd: Extract<FecWorkerCommand, { type: \"feedRepair\" }>,\n): void {\n\tif (!wasmDecoder) {\n\t\tthrow new Error(\"[FecWorker] feedRepair: not configured\");\n\t}\n\tif (!config) {\n\t\tthrow new Error(\"[FecWorker] feedRepair: config missing\");\n\t}\n\tif (\n\t\t!isUint32(cmd.ssStart) ||\n\t\t!isUint32(cmd.ssbLength) ||\n\t\tcmd.ssbLength <= 0 ||\n\t\tcmd.ssbLength > config.k ||\n\t\tcmd.ssStart % config.k !== 0 ||\n\t\t!isUint32(cmd.rsId) ||\n\t\tconfig.k + cmd.rsId > UINT24_MAX ||\n\t\t!(cmd.data instanceof ArrayBuffer)\n\t) {\n\t\tthrow new Error(\"[FecWorker] feedRepair: invalid repair symbol\");\n\t}\n\n\tconst view = new Uint8Array(cmd.data);\n\tif (config.symbolSize > 0 && view.byteLength !== config.symbolSize) {\n\t\trepairSymbolSizeMismatch++;\n\t\tif (repairSymbolSizeMismatch <= 5 || repairSymbolSizeMismatch % 100 === 0) {\n\t\t\temit({\n\t\t\t\ttype: \"error\",\n\t\t\t\tcode: \"repair-symbol-size-mismatch\",\n\t\t\t\tmessage: `[FecWorker] Dropping repair symbol with invalid size: got ${view.byteLength}B, expected ${config.symbolSize}B (ssStart=${cmd.ssStart}, ssbLength=${cmd.ssbLength}, rsId=${cmd.rsId})`,\n\t\t\t});\n\t\t}\n\t\treturn;\n\t}\n\tconst sbn = Math.floor(cmd.ssStart / config.k);\n\tconst repairEsi = config.k + cmd.rsId;\n\tif (sbn <= retiredSbnFrontier) return;\n\tconst existingBlock = blocks.get(sbn);\n\tif (existingBlock && isTerminalBlock(existingBlock)) return;\n\tif (acceptedRepairEsis.get(sbn)?.has(repairEsi)) return;\n\n\tconst result = wasmDecoder.add_repair(\n\t\tcmd.ssStart,\n\t\tcmd.ssbLength,\n\t\tcmd.rsId,\n\t\tview,\n\t\tcmd.ts,\n\t);\n\tadvanceMediaHorizon(sbn);\n\tlet repairEsis = acceptedRepairEsis.get(sbn);\n\tif (!repairEsis) {\n\t\trepairEsis = new Set<number>();\n\t\tacceptedRepairEsis.set(sbn, repairEsis);\n\t}\n\trepairEsis.add(repairEsi);\n\tconst block = getOrCreateBlock(sbn);\n\tblock.repairReceived++;\n\tblock.lastSymbolTs = performance.now();\n\trepairSymbols++;\n\t\t// If WASM returned data, it is the recovered source block: K fixed-width\n\t\t// source symbols concatenated. Split it before emitting so MmtpRouter gets\n\t\t// the same one-symbol shape as a direct source packet.\n\t\tif (result && result.byteLength > 0) {\n\t\t\tconst recovered = new Uint8Array(toOwnedArrayBuffer(result));\n\t\t\tconst recoveryMs = performance.now() - block.firstSymbolTs;\n\t\t\trecoveryTimes.push(recoveryMs);\n\t\t// Cap recovery times array at 1000 entries\n\t\tif (recoveryTimes.length > 1000) recoveryTimes.shift();\n\n\t\tif (block.state === \"collecting\") {\n\t\t\tmarkBlockTerminal(block, \"recovered\");\n\t\t\tblocksRecovered++;\n\t\t\t\temitBlockUpdate(block);\n\t\t\t}\n\t\t\temitRecoveredSymbols(sbn, recovered, block);\n\t\t}\n\t\tsynchronizeDecoderHorizon();\n\t}\n\nfunction handleRelayBlockSig(\n\tcmd: Extract<FecWorkerCommand, { type: \"relayBlockSig\" }>,\n): void {\n\t// No-op AUTH stub: store sig on block, mark as not-yet-verified\n\tconst block = blocks.get(cmd.sbn);\n\tif (block) {\n\t\t// Real verification deferred to ALTA milestone\n\t\t// For now, mark as null (not verified) \u2014 will be wired when ALTA is implemented\n\t\tblock.relayBlockSigValid = null;\n\t\temitBlockUpdate(block);\n\t}\n}\n\nfunction handleCleanup(\n\tcmd: Extract<FecWorkerCommand, { type: \"cleanup\" }>,\n): void {\n\tif (\n\t\t!Array.isArray(cmd.sbns) ||\n\t\tcmd.sbns.length === 0 ||\n\t\t!cmd.sbns.every(isUint32)\n\t) {\n\t\tthrow new Error(\"[FecWorker] cleanup: invalid SBNs\");\n\t}\n\tconst sbns = [...new Set(cmd.sbns)].sort((a, b) => a - b);\n\tconst pendingSbns = sbns.filter((sbn) => sbn > retiredSbnFrontier);\n\ttry {\n\t\tif (!wasmDecoder) {\n\t\t\tthrow new Error(\"[FecWorker] cleanup: not configured\");\n\t\t}\n\n\t\t// Call WASM cleanup only after all earlier symbol commands have drained.\n\t\t// The detailed API carries the true owner of every fill emitted by a\n\t\t// single cleanup pass; command coalescing must not infer ownership from\n\t\t// the largest timed-out SBN.\n\t\tconst cleanupRecords = pendingSbns.length > 0\n\t\t\t? wasmDecoder.cleanup_blocks_detailed(Uint32Array.from(pendingSbns))\n\t\t\t: new Uint8Array();\n\t\t// Manager deadlines are block-scoped and may expire a newer SBN while an\n\t\t// older interleaved block is still live. Only accepted media progression\n\t\t// advances the shared JS/Rust horizon; cleanup creates exact tombstones.\n\n\t\t// Rust already finalized every SBN behind the media frontier. For each\n\t\t// remaining exact request, mirror the block-scoped WASM boundary immediately\n\t\t// so JS never retains state for a decoder block that is gone, even if decoding\n\t\t// the trusted cleanup framing were to fail.\n\t\tfor (const sbn of pendingSbns) {\n\t\t\tlet currentBlock = blocks.get(sbn);\n\t\t\tif (currentBlock && isTerminalBlock(currentBlock)) {\n\t\t\t\tretireAcceptedIds(sbn);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tcurrentBlock ??= getOrCreateBlock(sbn);\n\t\t\tif (currentBlock.sourceReceived >= currentBlock.k) {\n\t\t\t\tmarkBlockTerminal(currentBlock, \"complete\");\n\t\t\t\tblocksComplete++;\n\t\t\t} else {\n\t\t\t\tmarkBlockTerminal(currentBlock, \"failed\");\n\t\t\t\tblocksFailed++;\n\t\t\t}\n\t\t\temitBlockUpdate(currentBlock);\n\t\t}\n\n\t\tconst greenFills = decodeCleanupRecords(cleanupRecords);\n\t\tfor (const { sbn, data } of greenFills) {\n\t\t\tgreenFillFrames++;\n\t\t\temit({ type: \"greenFill\", sbn, data }, [data]);\n\t\t}\n\t} finally {\n\t\t// Message ordering makes this an acknowledgement that every source/repair\n\t\t// command posted before cleanup has completed. The main thread must not\n\t\t// commit failure accounting until it observes this event.\n\t\temit({ type: \"cleanupComplete\", sbns });\n\t}\n}\n\nfunction decodeCleanupRecords(\n\tframed: Uint8Array,\n): Array<{ sbn: number; data: ArrayBuffer }> {\n\tconst records: Array<{ sbn: number; data: ArrayBuffer }> = [];\n\tconst view = new DataView(framed.buffer, framed.byteOffset, framed.byteLength);\n\tlet offset = 0;\n\twhile (offset < framed.byteLength) {\n\t\tif (framed.byteLength - offset < 8) {\n\t\t\tthrow new Error(\"[FecWorker] cleanup_blocks_detailed: truncated record header\");\n\t\t}\n\t\tconst sbn = view.getUint32(offset, false);\n\t\tconst length = view.getUint32(offset + 4, false);\n\t\toffset += 8;\n\t\tif (length > framed.byteLength - offset) {\n\t\t\tthrow new Error(\"[FecWorker] cleanup_blocks_detailed: truncated record payload\");\n\t\t}\n\t\tconst data = toOwnedArrayBuffer(framed.subarray(offset, offset + length));\n\t\trecords.push({ sbn, data });\n\t\toffset += length;\n\t}\n\treturn records;\n}\n\nfunction handleDispose(): void {\n\t// Clear snapshot timer (MUST clear to prevent leaks)\n\tif (snapshotTimer !== null) {\n\t\tclearInterval(snapshotTimer);\n\t\tsnapshotTimer = null;\n\t}\n\n\t// Free ALTA verifier WASM object (MUST call to release WASM memory \u2014\n\t// Worker.terminate() fires immediately after dispose, so the FinalizationRegistry\n\t// callback has no chance to run and this memory would leak without explicit free)\n\tif (altaVerifier) {\n\t\ttry {\n\t\t\taltaVerifier.free();\n\t\t} catch (_e) {\n\t\t\t// Best-effort \u2014 verifier may already be freed\n\t\t}\n\t\taltaVerifier = null;\n\t}\n\n\t// Free WASM decoder (MUST call to release WASM memory)\n\tif (wasmDecoder) {\n\t\twasmDecoder.free();\n\t\twasmDecoder = null;\n\t}\n\n\t// Clear deferred-verify queue so pinned ArrayBuffers drop.\n\tpendingVerify.clear();\n\tpendingVerifyCap = 0;\n\tpendingVerifyTtlMs = 0;\n\n\tconfig = null;\n\tclearBlockTracking();\n}\n\nfunction handleReset(): void {\n\ttry {\n\t\twasmDecoder?.flush();\n\t\twasmDecoder?.reset_stats();\n\t} catch (err) {\n\t\temit({\n\t\t\ttype: \"error\",\n\t\t\tcode: \"reset-failed\",\n\t\t\tmessage:\n\t\t\t\terr instanceof Error\n\t\t\t\t\t? `[FecWorker] reset failed: ${err.message}`\n\t\t\t\t\t: `[FecWorker] reset failed: ${String(err)}`,\n\t\t});\n\t\treturn;\n\t}\n\n\tclearBlockTracking();\n\tsourceSymbols = 0;\n\trepairSymbols = 0;\n\tblocksComplete = 0;\n\tblocksRecovered = 0;\n\tblocksFailed = 0;\n\tgreenFillFrames = 0;\n\taltaVerified = 0;\n\taltaFailed = 0;\n\taltaFailedDetails.length = 0;\n\taltaPending = 0;\n\taltaPendingEvictedCap = 0;\n\taltaPendingEvictedTtl = 0;\n\taltaError = 0;\n\trelayBlocksVerified = 0;\n\trelayBlocksFailed = 0;\n\trepairSymbolSizeMismatch = 0;\n\temit({ type: \"resetComplete\" });\n\tif (config) emitSnapshot();\n}\n\n// --- Main message handler ---\n\nasync function dispatchCommand(cmd: FecWorkerCommand): Promise<void> {\n\ttry {\n\t\tswitch (cmd.type) {\n\t\t\tcase \"configure\":\n\t\t\t\t// handleConfigure is async (ALTA WASM init uses dynamic import).\n\t\t\t\t// Await it so feed/cleanup messages cannot run against a partially\n\t\t\t\t// configured decoder.\n\t\t\t\tawait handleConfigure(cmd);\n\t\t\t\tbreak;\n\t\t\tcase \"feedSource\":\n\t\t\t\thandleFeedSource(cmd);\n\t\t\t\tbreak;\n\t\t\tcase \"feedRepair\":\n\t\t\t\thandleFeedRepair(cmd);\n\t\t\t\tbreak;\n\t\t\tcase \"relayBlockSig\":\n\t\t\t\thandleRelayBlockSig(cmd);\n\t\t\t\tbreak;\n\t\t\tcase \"cleanup\":\n\t\t\t\thandleCleanup(cmd);\n\t\t\t\tbreak;\n\t\t\tcase \"reset\":\n\t\t\t\thandleReset();\n\t\t\t\tbreak;\n\t\t\tcase \"dispose\":\n\t\t\t\thandleDispose();\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\temit({\n\t\t\t\t\ttype: \"error\",\n\t\t\t\t\tcode: \"unknown-command\",\n\t\t\t\t\tmessage: `Unknown command type: ${(cmd as Record<string, unknown>).type}`,\n\t\t\t\t});\n\t\t}\n\t} catch (err) {\n\t\temit({\n\t\t\ttype: \"error\",\n\t\t\tcode: \"command-failed\",\n\t\t\tmessage:\n\t\t\t\terr instanceof Error ? err.message : `[FecWorker] ${String(err)}`,\n\t\t});\n\t}\n}\n\nlet commandQueue: Promise<void> = Promise.resolve();\n\nself.onmessage = (e: MessageEvent<FecWorkerCommand>) => {\n\tconst cmd = e.data;\n\tcommandQueue = commandQueue.then(() => dispatchCommand(cmd));\n};\n"],
5
- "mappings": ";;;AAOO,SAAS,mBAAmB,MAA+B;AACjE,QAAM,OAAO,IAAI,WAAW,KAAK,UAAU;AAC3C,OAAK,IAAI,IAAI;AACb,SAAO,KAAK;AACb;;;AC4DA,IAAI,cAAqC;AACzC,IAAI,SAAgC;AACpC,IAA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,IACjE,CAAC;AAAA,EACF;AACD;AAEA,IAAI,eAA8B,QAAQ,QAAQ;AAElD,KAAK,YAAY,CAAC,MAAsC;AACvD,QAAM,MAAM,EAAE;AACd,iBAAe,aAAa,KAAK,MAAM,gBAAgB,GAAG,CAAC;AAC5D;",
4
+ "sourcesContent": ["/**\n * Return a fresh ArrayBuffer containing exactly the bytes in `view`.\n *\n * Worker outputs must not transfer buffers that might be owned by a WASM\n * binding or by a larger shared packet. A fresh JS-owned buffer gives\n * postMessage() exclusive ownership without detaching unrelated memory.\n */\nexport function toOwnedArrayBuffer(view: Uint8Array): ArrayBuffer {\n\tconst copy = new Uint8Array(view.byteLength);\n\tcopy.set(view);\n\treturn copy.buffer;\n}\n", "/**\n * @blockcast/fec-worker \u2014 Worker Entry Point\n *\n * Runs inside DedicatedWorkerGlobalScope. Receives FecWorkerCommand messages,\n * drives the MmtFecDecoder WASM module, emits FecWorkerEvent messages back.\n *\n * WASM bindings are resolved via:\n * 1. (self as any).__MMT_WASM_BINDINGS__ \u2014 set by consumer's loader/importmap\n * 2. Falls back to error if not available (no defaults)\n *\n * This file must NOT import DOM globals incompatible with Worker scope.\n */\n\nimport type {\n\tFecWorkerCommand,\n\tFecWorkerEvent,\n\tFecTrackConfig,\n\tFecTrackStats,\n\tFecBlockSnapshot,\n\tFrameMeta,\n} from \"./fec-worker-types.js\";\nimport { toOwnedArrayBuffer } from \"./transfer.js\";\n\n// --- WASM binding types (from mmt-wasm) ---\n// Signatures MUST match a freshly generated external mmt_wasm.d.ts exactly.\n// The decoder derives SBN/ESI internally \u2014 do not pre-compute.\ninterface WasmFecDecoder {\n\t/** ISO 23008-1 \u00A7C.5.2: ss_id is the flat 32-bit Source Symbol ID. */\n\tadd_source(\n\t\tss_id: number,\n\t\tdata: Uint8Array,\n\t\ttimestamp: number,\n\t): Uint8Array | undefined;\n\t/** ISO 23008-1 \u00A7C.5.3: repair ESI = configured K + rs_id, SBN = ss_start / configured K. */\n\tadd_repair(\n\t\tss_start: number,\n\t\tssb_length: number,\n\t\trs_id: number,\n\t\tdata: Uint8Array,\n\t\ttimestamp: number,\n\t): Uint8Array | undefined;\n\tconfigure_params(k: number, symbolSize: number): void;\n\t/** Block-scoped counterpart driven by the manager's exact deadlines. */\n\tcleanup_blocks_detailed(sbns: Uint32Array): Uint8Array;\n\t/** Remove decoder blocks below its configured live-SBN interleave horizon. */\n\tcleanup_by_sbn(current_sbn: number): Uint32Array;\n\tflush(): void;\n\tpending_blocks(): number;\n\treset_stats(): void;\n\tget_stats(): {\n\t\tsource_packets: bigint;\n\t\trepair_packets: bigint;\n\t\tblocks_complete: bigint;\n\t\tblocks_recovered: bigint;\n\t\tblocks_failed: bigint;\n\t\tbytes_recovered: bigint;\n\t\trecovery_rate(): number;\n\t};\n\tfree(): void;\n}\n\ninterface WasmBindings {\n\tinitSync(module: { module: WebAssembly.Module }): unknown;\n\tMmtFecDecoder: new (\n\t\tinterleaveDepth: number,\n\t\tgreenFillEnabled: boolean,\n\t) => WasmFecDecoder;\n}\n\n// --- Worker state (local to this Worker instance) ---\n\nlet wasmDecoder: WasmFecDecoder | null = null;\nlet config: FecTrackConfig | null = null;\nlet altaEnabled = false;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nlet altaVerifier: any = null; // JsAltaVerifier instance (loaded from ALTA WASM)\nlet snapshotTimer: ReturnType<typeof setInterval> | null = null;\n\n// Block tracking\nconst blocks = new Map<number, FecBlockSnapshot>();\nconst acceptedSourceEsis = new Map<number, Set<number>>();\nconst acceptedRepairEsis = new Map<number, Set<number>>();\nconst UINT32_MAX = 0xffff_ffff;\nconst UINT24_MAX = 0xff_ffff;\n// ISO/IEC 23008-1 AL-FEC signaling carries interleave_depth in one byte.\nconst MAX_INTERLEAVE_DEPTH = 0xff;\n// Rust stores T as u16 and this decoder profile fixes RFC 6330 Al=8.\nconst MAX_SYMBOL_SIZE = 0xfff8;\n// RFC 6330 systematic table limit, enforced by the vendored raptorq decoder.\nconst MAX_RAPTORQ_SOURCE_SYMBOLS_PER_BLOCK = 56_403;\n\n// Aggregate counters\nlet sourceSymbols = 0;\nlet repairSymbols = 0;\nlet blocksComplete = 0;\nlet blocksRecovered = 0;\nlet blocksFailed = 0;\nlet greenFillFrames = 0;\nlet altaVerified = 0;\nlet altaFailed = 0; // Crypto-confirmed tamper (MAC / sig / hash chain mismatch)\nconst altaFailedDetails: Array<{\n\tseq: number;\n\terror: string;\n\tauthLen: number;\n\tpayloadLen: number;\n\tpath: string; // \"direct\" | \"recovered\" | \"pending-retry\"\n}> = [];\nlet altaPending = 0; // Unverifiable but not tamper (no trailer, verifier not ready, anchor missing)\nlet altaPendingEvictedCap = 0; // Incoming \"pending\" packets rejected because the queue was at cap after stale-sweep (flood indicator)\nlet altaPendingEvictedTtl = 0; // Deferred-queue entries dropped by TTL (retry window expired)\nlet altaError = 0; // verifyDetached threw \u2014 infrastructure flake, not tamper\nlet altaInitFailed = false; // ALTA configured but WASM init failed; altaEnabled was forced off\nlet relayBlocksVerified = 0;\nlet relayBlocksFailed = 0;\nlet liveSbn = 0;\n// Highest SBN that has fallen strictly below the decoder's retained\n// interleave window. Numeric ordering is per decoder epoch; reset/configure\n// starts a new epoch before the 32-bit source-symbol counter can wrap.\nlet retiredSbnFrontier = -1;\nlet repairSymbolSizeMismatch = 0;\n\n// Recovery timing\nconst recoveryTimes: number[] = [];\n\n// \u2500\u2500 Deferred ALTA verification queue (08-07 Path 3) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n//\n// When an ALTA packet arrives whose MAC references point at sequences not yet\n// in the verifier's ring buffer, we can't anchor trust \u2014 verify returns \"No\n// trust anchor\". Typical cause: a predecessor packet was lost and hasn't been\n// FEC-recovered yet. Rather than drop these, hold them in a bounded FIFO and\n// retry verification after every successful verify (direct or FEC-recovered)\n// that seeds the ring buffer with new raw bytes.\n//\n// Zero-copy (1B-B): the queue entry stores a Uint8Array view into the\n// original `data` ArrayBuffer. JS GC keeps the buffer alive via the view\n// reference; no bytes are copied on queue.\n//\n// Timeout entries (TTL exceeded) and cap-rejections count as `altaPending`\n// (2C-B): they're not tamper indicators, they're just packets that couldn't\n// be authenticated within the receive window \u2014 either loss or, in the cap\n// case, a flood of unanchorable arrivals (real or attacker-driven) that\n// exceeded the queue budget. See enqueuePendingVerify for the rate-limit\n// protocol.\ninterface PendingVerify {\n\tseq: number;\n\tauth: Uint8Array;\n\tpayload: Uint8Array;\n\tarrivalTs: number;\n}\nconst pendingVerify = new Map<number, PendingVerify>();\nlet pendingVerifyCap = 0;\nlet pendingVerifyTtlMs = 0;\n\n// --- Helpers ---\n\nfunction emit(event: FecWorkerEvent, transfer?: Transferable[]): void {\n\tself.postMessage(event, transfer ?? []);\n}\n\nfunction isUint32(value: number): boolean {\n\treturn Number.isInteger(value) && value >= 0 && value <= UINT32_MAX;\n}\n\nfunction isTerminalBlock(block: FecBlockSnapshot): boolean {\n\treturn block.state !== \"collecting\";\n}\n\nfunction retireAcceptedIds(sbn: number): void {\n\tacceptedSourceEsis.delete(sbn);\n\tacceptedRepairEsis.delete(sbn);\n}\n\nfunction clearBlockTracking(): void {\n\tblocks.clear();\n\tacceptedSourceEsis.clear();\n\tacceptedRepairEsis.clear();\n\tpendingVerify.clear();\n\trecoveryTimes.length = 0;\n\tliveSbn = 0;\n\tretiredSbnFrontier = -1;\n}\n\n/**\n * Retire terminal diagnostics only after the decoder's monotonic interleave\n * horizon proves that the SBN can no longer be valid out-of-order media.\n * Admission keeps the compact frontier as the durable tombstone, so deletion\n * never reopens a finalized block.\n */\nfunction trimBlockRetention(): void {\n\tfor (const [sbn, block] of blocks) {\n\t\tif (!isTerminalBlock(block) || sbn > retiredSbnFrontier) continue;\n\t\tblocks.delete(sbn);\n\t\tretireAcceptedIds(sbn);\n\t}\n}\n\nfunction advanceMediaHorizon(sbn: number): void {\n\tif (!config || sbn <= liveSbn) return;\n\tliveSbn = sbn;\n\tconst firstRetainedSbn = Math.max(0, liveSbn - config.interleaveDepth);\n\tretiredSbnFrontier = Math.max(retiredSbnFrontier, firstRetainedSbn - 1);\n\ttrimBlockRetention();\n}\n\nfunction markBlockTerminal(\n\tblock: FecBlockSnapshot,\n\tstate: \"complete\" | \"recovered\" | \"failed\",\n): void {\n\tblock.state = state;\n\tblock.completedTs = performance.now();\n\tretireAcceptedIds(block.sbn);\n\ttrimBlockRetention();\n}\n\nfunction synchronizeDecoderHorizon(): void {\n\tif (!wasmDecoder) return;\n\tconst expired = wasmDecoder.cleanup_by_sbn(liveSbn);\n\tfor (const sbn of expired) {\n\t\tconst block = blocks.get(sbn);\n\t\tif (!block || isTerminalBlock(block)) {\n\t\t\tretireAcceptedIds(sbn);\n\t\t\tcontinue;\n\t\t}\n\t\tmarkBlockTerminal(block, \"failed\");\n\t\tblocksFailed++;\n\t\temitBlockUpdate(block);\n\t}\n\ttrimBlockRetention();\n}\n\n/**\n * Run detached ALTA verify against the current verifier. Four-state result:\n * - \"valid\": crypto passed, packet authentic. Caller increments altaVerified.\n * - \"failed\": crypto confirmed tamper (MAC/sig mismatch, hash chain mismatch).\n * Caller increments altaFailed. Not retryable.\n * - \"pending\": anchor missing (MAC refs not in buffer, no signature, not\n * early-warmup). Caller may enqueue for retry after the next\n * successful verify seeds the ring buffer.\n * - \"error\": verifier threw \u2014 WASM trap, unmarshal panic, OOM. Caller\n * increments altaError (infrastructure flake, not tamper).\n * The distinction matters for ops alerting: a spike in\n * altaError indicates a runtime problem, not an attack.\n */\nlet _lastVerifyError = \"\";\nfunction runDetachedVerify(\n\tauth: Uint8Array,\n\tpayload: Uint8Array,\n): \"valid\" | \"failed\" | \"pending\" | \"error\" {\n\tif (!altaVerifier) return \"pending\";\n\ttry {\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tconst r: any = altaVerifier.verifyDetached(auth, payload);\n\t\tif (r.valid) {\n\t\t\t_lastVerifyError = \"\";\n\t\t\treturn \"valid\";\n\t\t}\n\t\tconst err = (r.error as string | undefined) ?? \"\";\n\t\t_lastVerifyError = err;\n\t\t// The bootstrap-friendly verifier returns this specific error string when\n\t\t// the only obstacle to verification is a missing anchor (see alta-rs\n\t\t// verifier.rs verify()). Distinguishing this from tamper cases keeps us\n\t\t// from queuing packets that are definitively invalid.\n\t\tif (err.startsWith(\"No trust anchor\")) return \"pending\";\n\t\treturn \"failed\";\n\t} catch (e) {\n\t\t// Ratelimit: first ~N occurrences get logged. A sustained exception\n\t\t// stream indicates a real problem \u2014 the altaError counter is the\n\t\t// durable signal.\n\t\tif (altaError < 5) {\n\t\t\tconsole.warn(\"[FecWorker] verifyDetached threw:\", e);\n\t\t}\n\t\treturn \"error\";\n\t}\n}\n\n/** Extract u32 BE sequence number from the ALTA authenticator header (offset 0..3). */\nfunction seqFromAuth(auth: Uint8Array): number {\n\treturn (\n\t\t((auth[0]! << 24) | (auth[1]! << 16) | (auth[2]! << 8) | auth[3]!) >>> 0\n\t);\n}\n\n/**\n * Enqueue a packet whose ALTA verification returned \"pending\" (anchor\n * missing). Dedupes by sequence number.\n *\n * Flood resistance (08-08 review): when the queue is at cap we do NOT\n * evict the oldest entry. The oldest entry is typically the most\n * load-bearing one \u2014 it's the packet whose anchor everything else in the\n * queue is waiting on. Evict-oldest-on-insert let an attacker emitting a\n * stream of \"No trust anchor\" packets flood out legitimate entries and\n * prevent them from ever anchoring. Instead:\n * 1. First try to free stale TTL'd entries (they'd be evicted on next\n * drain anyway \u2014 pulling that forward is free).\n * 2. If still full, reject the NEW entry. altaPendingEvictedCap counts\n * these rejections (rate-limit trigger).\n *\n * Stores Uint8Array views into the original data + auth buffers \u2014 no copy.\n * The views keep their underlying ArrayBuffers alive via GC references.\n */\nfunction enqueuePendingVerify(\n\tauth: Uint8Array,\n\tpayload: Uint8Array,\n): void {\n\tconst seq = seqFromAuth(auth);\n\tif (pendingVerify.has(seq)) return;\n\n\tif (pendingVerify.size >= pendingVerifyCap) {\n\t\t// Step 1: sweep stale entries so legitimate traffic isn't penalized\n\t\t// by TTL'd junk that happens to still occupy slots.\n\t\tconst now = performance.now();\n\t\tfor (const [staleSeq, entry] of pendingVerify) {\n\t\t\tif (now - entry.arrivalTs > pendingVerifyTtlMs) {\n\t\t\t\tpendingVerify.delete(staleSeq);\n\t\t\t\taltaPendingEvictedTtl++;\n\t\t\t}\n\t\t}\n\t\t// Step 2: if the queue is still at cap it's a genuine flood \u2014\n\t\t// reject the new entry rather than evict an existing one. The\n\t\t// rejected packet counts as altaPendingEvictedCap (which is\n\t\t// surfaced up through stats for rate-limit alerting).\n\t\tif (pendingVerify.size >= pendingVerifyCap) {\n\t\t\taltaPendingEvictedCap++;\n\t\t\treturn;\n\t\t}\n\t}\n\n\tpendingVerify.set(seq, {\n\t\tseq,\n\t\tauth,\n\t\tpayload,\n\t\tarrivalTs: performance.now(),\n\t});\n}\n\n/**\n * Retry every queued entry. Called after every successful verify (direct\n * source or FEC-recovered) \u2014 new raw bytes in the verifier's ring buffer may\n * unblock previously-pending MAC references.\n *\n * Three outcomes per entry:\n * - \"valid\" \u2192 remove from queue, altaVerified++\n * - \"failed\" \u2192 remove from queue, altaFailed++ (tamper on retry)\n * - \"pending\" \u2192 keep in queue, unless TTL expired (then evict as altaPending)\n *\n * Iteration order: Map preserves insertion order, so we drain oldest-first.\n * No-op when the queue is empty or the verifier isn't ready.\n */\nfunction drainPendingVerify(): void {\n\tif (pendingVerify.size === 0 || !altaVerifier) return;\n\tconst now = performance.now();\n\t// Collect keys to avoid mutating Map during iteration\n\tconst keys = Array.from(pendingVerify.keys());\n\tfor (const seq of keys) {\n\t\tconst entry = pendingVerify.get(seq);\n\t\tif (!entry) continue;\n\t\tif (now - entry.arrivalTs > pendingVerifyTtlMs) {\n\t\t\tpendingVerify.delete(seq);\n\t\t\taltaPendingEvictedTtl++;\n\t\t\tcontinue;\n\t\t}\n\t\tconst result = runDetachedVerify(entry.auth, entry.payload);\n\t\tif (result === \"valid\") {\n\t\t\tpendingVerify.delete(seq);\n\t\t\taltaVerified++;\n\t\t} else if (result === \"failed\") {\n\t\t\tpendingVerify.delete(seq);\n\t\t\taltaFailed++;\n\t\t\tif (altaFailedDetails.length < 16) {\n\t\t\t\taltaFailedDetails.push({\n\t\t\t\t\tseq: entry.seq,\n\t\t\t\t\terror: _lastVerifyError,\n\t\t\t\t\tauthLen: entry.auth.length,\n\t\t\t\t\tpayloadLen: entry.payload.length,\n\t\t\t\t\tpath: \"pending-retry\",\n\t\t\t\t});\n\t\t\t}\n\t\t} else if (result === \"error\") {\n\t\t\t// Infrastructure failure \u2014 remove from queue, count as altaError.\n\t\t\t// Keeping it around would just re-throw on every subsequent drain.\n\t\t\tpendingVerify.delete(seq);\n\t\t\taltaError++;\n\t\t}\n\t\t// \"pending\" \u2192 leave in queue for next drain\n\t}\n}\n\nfunction getOrCreateBlock(sbn: number): FecBlockSnapshot {\n\tlet block = blocks.get(sbn);\n\tif (!block) {\n\t\tif (!config) throw new Error(\"[FecWorker] not configured\");\n\t\tconst now = performance.now();\n\t\tblock = {\n\t\t\tsbn,\n\t\t\tstate: \"collecting\",\n\t\t\tsourceReceived: 0,\n\t\t\trepairReceived: 0,\n\t\t\tk: config.k,\n\t\t\trepairCount: config.repairCount,\n\t\t\tfirstSymbolTs: now,\n\t\t\tlastSymbolTs: now,\n\t\t\tdeadlineTs: now + config.deliveryWindowMs,\n\t\t\taltaVerified: 0,\n\t\t\trelayBlockSigValid: null,\n\t\t};\n\t\tblocks.set(sbn, block);\n\t\ttrimBlockRetention();\n\t}\n\treturn block;\n}\n\nfunction buildStatsSnapshot(): FecTrackStats {\n\tif (!config) throw new Error(\"[FecWorker] not configured\");\n\tconst decoderStats = wasmDecoder?.get_stats();\n\tconst decoder = decoderStats\n\t\t? {\n\t\t\tsourcePackets: Number(decoderStats.source_packets),\n\t\t\trepairPackets: Number(decoderStats.repair_packets),\n\t\t\tblocksComplete: Number(decoderStats.blocks_complete),\n\t\t\tblocksRecovered: Number(decoderStats.blocks_recovered),\n\t\t\tblocksFailed: Number(decoderStats.blocks_failed),\n\t\t\tbytesRecovered: Number(decoderStats.bytes_recovered),\n\t\t\tpendingBlocks: wasmDecoder?.pending_blocks() ?? 0,\n\t\t}\n\t\t: undefined;\n\n\tconst avgRecoveryMs =\n\t\trecoveryTimes.length > 0\n\t\t\t? recoveryTimes.reduce((a, b) => a + b, 0) / recoveryTimes.length\n\t\t\t: 0;\n\tconst maxRecoveryMs =\n\t\trecoveryTimes.length > 0 ? Math.max(...recoveryTimes) : 0;\n\n\t// Cap block array to interleave window\n\tconst maxBlocks = Math.max(config.interleaveDepth * 3, 24);\n\tconst blockArray = Array.from(blocks.values())\n\t\t.sort((a, b) => b.sbn - a.sbn)\n\t\t.slice(0, maxBlocks);\n\n\treturn {\n\t\tconfig,\n\t\tsourceSymbols,\n\t\trepairSymbols,\n\t\tblocksComplete,\n\t\tblocksRecovered,\n\t\tblocksFailed,\n\t\tgreenFillFrames,\n\t\trecoveryRate:\n\t\t\tblocksComplete + blocksRecovered > 0\n\t\t\t\t? Math.round(\n\t\t\t\t\t\t(blocksRecovered / (blocksRecovered + blocksFailed)) * 100,\n\t\t\t\t\t) || 0\n\t\t\t\t: 0,\n\t\taltaVerified,\n\t\taltaFailed,\n\t\taltaPending,\n\t\taltaPendingEvictedCap,\n\t\taltaPendingEvictedTtl,\n\t\taltaError,\n\t\taltaInitFailed,\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\taltaFailedDetails: altaFailedDetails.slice() as any,\n\t\trelayBlocksVerified,\n\t\trelayBlocksFailed,\n\t\tliveSbn,\n\t\tblocks: blockArray,\n\t\tinterleaveWindowBlocks: config.interleaveDepth,\n\t\tavgRecoveryMs: Math.round(avgRecoveryMs * 100) / 100,\n\t\tmaxRecoveryMs: Math.round(maxRecoveryMs * 100) / 100,\n\t\trepairSymbolSizeMismatch,\n\t\tdecoder,\n\t};\n}\n\nfunction emitSnapshot(): void {\n\tif (!config) return;\n\temit({ type: \"snapshot\", stats: buildStatsSnapshot() });\n}\n\nfunction emitBlockUpdate(block: FecBlockSnapshot): void {\n\temit({ type: \"blockUpdate\", block: { ...block } });\n}\n\nfunction emitRecoveredSymbols(\n\tsbn: number,\n\trecoveredBlock: Uint8Array,\n\tblock: FecBlockSnapshot,\n): void {\n\tif (!config) return;\n\tconst symbolSize = config.symbolSize;\n\tif (symbolSize <= 0) {\n\t\temit({\n\t\t\ttype: \"error\",\n\t\t\tcode: \"recovered-symbol-size-unconfigured\",\n\t\t\tmessage: \"[FecWorker] recovered block has no configured symbolSize\",\n\t\t});\n\t\treturn;\n\t}\n\t// The decoder returns only the block's authored source symbols\n\t// (SSB_length x T); the encoder's zero padding is not media.\n\tconst ssbLength = block.ssbLength ?? config.k;\n\tif (recoveredBlock.byteLength !== symbolSize * ssbLength) {\n\t\temit({\n\t\t\ttype: \"error\",\n\t\t\tcode: \"recovered-block-too-short\",\n\t\t\tmessage: `[FecWorker] recovered block has the wrong length: got ${recoveredBlock.byteLength}B, expected ${symbolSize * ssbLength}B (SSB_length=${ssbLength})`,\n\t\t});\n\t\treturn;\n\t}\n\n\tfor (let i = 0; i < ssbLength; i++) {\n\t\tconst symbol = recoveredBlock.subarray(i * symbolSize, (i + 1) * symbolSize);\n\n\t\t// Source authentication now runs once at router admission in\n\t\t// @blockcast/mmt-manifest-verify. The worker only records that this\n\t\t// legacy ALTA-enabled symbol bypassed hot-path verification.\n\t\tconst recoveredAltaVerified: boolean | null = null;\n\t\tif (altaEnabled) altaPending++;\n\n\t\tconst buf = toOwnedArrayBuffer(symbol);\n\t\tconst meta: FrameMeta = {\n\t\t\taltaVerified: recoveredAltaVerified,\n\t\t\trecovered: true,\n\t\t\tsbn,\n\t\t\tesi: i,\n\t\t\tssbLength,\n\t\t};\n\t\temit({ type: \"frame\", data: buf, meta }, [buf]);\n\t}\n}\n\nfunction startSnapshotTimer(): void {\n\tif (snapshotTimer !== null) clearInterval(snapshotTimer);\n\tsnapshotTimer = setInterval(() => emitSnapshot(), 200);\n}\n\nfunction resolveWasmBindings(): WasmBindings {\n\tconst bindings = (self as unknown as Record<string, unknown>)\n\t\t.__MMT_WASM_BINDINGS__ as WasmBindings | undefined;\n\tif (!bindings) {\n\t\tthrow new Error(\n\t\t\t\"[FecWorker] WASM bindings not available. Set self.__MMT_WASM_BINDINGS__ = { initSync, MmtFecDecoder } before configure.\",\n\t\t);\n\t}\n\treturn bindings;\n}\n\n// --- Command handlers ---\n\nasync function handleConfigure(\n\tcmd: Extract<FecWorkerCommand, { type: \"configure\" }>,\n): Promise<void> {\n\tif (!cmd.wasmModule) {\n\t\tthrow new Error(\"[FecWorker] configure: wasmModule required\");\n\t}\n\tif (!cmd.config) {\n\t\tthrow new Error(\"[FecWorker] configure: config required\");\n\t}\n\tif (\n\t\t!Number.isFinite(cmd.config.interleaveDepth) ||\n\t\t!Number.isInteger(cmd.config.interleaveDepth) ||\n\t\tcmd.config.interleaveDepth <= 0 ||\n\t\tcmd.config.interleaveDepth > MAX_INTERLEAVE_DEPTH\n\t) {\n\t\tthrow new Error(\n\t\t\t`[FecWorker] configure: interleaveDepth must be an integer in 1..${MAX_INTERLEAVE_DEPTH} (got ${cmd.config.interleaveDepth})`,\n\t\t);\n\t}\n\tif (\n\t\t!Number.isFinite(cmd.config.interleaveMs) ||\n\t\tcmd.config.interleaveMs <= 0\n\t) {\n\t\tthrow new Error(\n\t\t\t`[FecWorker] configure: interleaveMs must be finite and > 0 (got ${cmd.config.interleaveMs})`,\n\t\t);\n\t}\n\tif (\n\t\t!Number.isFinite(cmd.config.deliveryWindowMs) ||\n\t\tcmd.config.deliveryWindowMs <= 0\n\t) {\n\t\tthrow new Error(\n\t\t\t`[FecWorker] configure: deliveryWindowMs must be > 0 (got ${cmd.config.deliveryWindowMs})`,\n\t\t);\n\t}\n\tif (\n\t\t!Number.isInteger(cmd.config.k) ||\n\t\tcmd.config.k <= 0 ||\n\t\tcmd.config.k > MAX_RAPTORQ_SOURCE_SYMBOLS_PER_BLOCK\n\t) {\n\t\tthrow new Error(\n\t\t\t`[FecWorker] configure: k must be an integer in 1..${MAX_RAPTORQ_SOURCE_SYMBOLS_PER_BLOCK} (got ${cmd.config.k})`,\n\t\t);\n\t}\n\tif (\n\t\t!Number.isInteger(cmd.config.symbolSize) ||\n\t\tcmd.config.symbolSize <= 0 ||\n\t\tcmd.config.symbolSize > MAX_SYMBOL_SIZE ||\n\t\tcmd.config.symbolSize % 8 !== 0\n\t) {\n\t\tthrow new Error(\n\t\t\t`[FecWorker] configure: symbolSize must be an 8-byte-aligned integer in 8..${MAX_SYMBOL_SIZE} (got ${cmd.config.symbolSize})`,\n\t\t);\n\t}\n\n\tconst wasm = resolveWasmBindings();\n\n\t// Initialize WASM from pre-compiled Module (no fetch, no re-compile)\n\twasm.initSync({ module: cmd.wasmModule });\n\n\t// A configure command starts a new decoder epoch. No terminal tombstone,\n\t// accepted-symbol ID, or active block from the previous decoder may affect it.\n\twasmDecoder?.free();\n\twasmDecoder = null;\n\tclearBlockTracking();\n\n\t// Decoder policy and geometry are explicit at the epoch boundary. The WASM\n\t// module has no guessed K/T/interleave slow path.\n\twasmDecoder = new wasm.MmtFecDecoder(\n\t\tcmd.config.interleaveDepth,\n\t\tcmd.config.trackType === \"video\",\n\t);\n\tconfig = cmd.config;\n\taltaEnabled = !!cmd.altaPublicKey;\n\n\t// Size the deferred-verify queue strictly from catalog-derived FEC\n\t// parameters. CLAUDE.md bans Math.max(x, floor) magic \u2014 if catalog\n\t// values are zero/missing, throw at init rather than silently applying\n\t// a hardcoded floor. Consumers of an undersized queue cap would see\n\t// altaPendingEvictedCap spike with no actionable signal.\n\t// Cap: 1.5\u00D7 interleave depth \u2014 wide enough to hold one full FEC recovery\n\t// window plus jitter, narrow enough to bound memory.\n\tpendingVerifyCap = Math.ceil(config.interleaveDepth * 1.5);\n\t// TTL: 1.5\u00D7 block duration (K symbols at one per interleave tick) \u2014\n\t// after this many ms, any unresolved entry has missed its FEC window.\n\tpendingVerifyTtlMs = Math.ceil(config.interleaveMs * config.k * 1.5);\n\n\t// Initialize ALTA WASM verifier if public key and WASM module provided (D-05, D-09)\n\taltaVerifier = null;\n\taltaInitFailed = false;\n\tif (cmd.altaPublicKey && cmd.altaWasmModule) {\n\t\ttry {\n\t\t\t// Load ALTA JS glue (wasm-bindgen output from wasm-pack build).\n\t\t\t// Mirrors the RaptorQ WASM pattern: initSync({ module }) then construct.\n\t\t\t// Dynamic import path matches the IWA static asset layout.\n\t\t\t// Cast via string to prevent TypeScript from attempting static resolution\n\t\t\t// of a runtime-only URL (same pattern as fec-worker-entry.js loading).\n\t\t\tconst altaGlueUrl = '/wasm/alta/alta_rs.js' as string;\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\tconst altaGlue: any = await import(/* webpackIgnore: true */ altaGlueUrl);\n\t\t\taltaGlue.initSync({ module: cmd.altaWasmModule });\n\t\t\tconst keyBytes = new Uint8Array(cmd.altaPublicKey);\n\t\t\taltaVerifier = new altaGlue.JsAltaVerifier(keyBytes);\n\t\t} catch (e) {\n\t\t\t// T-08-15: WASM init failure must NOT silently look like \"not-ready-yet\".\n\t\t\t// Force altaEnabled = false so handleFeedSource takes the disabled\n\t\t\t// branch instead of continuously bumping altaPending under the\n\t\t\t// misleading \"verifier not yet ready\" comment. altaInitFailed\n\t\t\t// flag in the snapshot tells consumers this is an error state, not\n\t\t\t// an opt-out.\n\t\t\tconsole.warn('[FecWorker] ALTA WASM init failed, verification disabled:', e);\n\t\t\taltaVerifier = null;\n\t\t\taltaEnabled = false;\n\t\t\taltaInitFailed = true;\n\t\t}\n\t}\n\n\twasmDecoder.configure_params(config.k, config.symbolSize);\n\n\t// Tell the client which optional commands this Worker accepts, so it can\n\t// batch symbols without risking a Worker that predates the batch command.\n\temit({ type: \"capabilities\", commands: [\"feedSymbols\"] });\n\n\t// Start periodic snapshot emission (200ms floor)\n\tstartSnapshotTimer();\n\n\t// Emit initial snapshot\n\temitSnapshot();\n}\n\nfunction handleFeedSource(\n\tcmd: Extract<FecWorkerCommand, { type: \"feedSource\" }>,\n): void {\n\tif (!wasmDecoder) {\n\t\tthrow new Error(\"[FecWorker] feedSource: not configured\");\n\t}\n\tif (!config) {\n\t\tthrow new Error(\"[FecWorker] feedSource: config missing\");\n\t}\n\tif (\n\t\t!isUint32(cmd.ssId) ||\n\t\t!(cmd.data instanceof ArrayBuffer)\n\t) {\n\t\tthrow new Error(\"[FecWorker] feedSource: invalid source symbol\");\n\t}\n\n\tconst view = new Uint8Array(cmd.data);\n\n\t// Derive SBN locally for block-level accounting. WASM derives the same\n\t// value internally (ISO 23008-1 \u00A7C.5.2: SBN = floor(SS_ID / K)).\n\tconst sbn = config.k > 0 ? Math.floor(cmd.ssId / config.k) : cmd.ssId;\n\tconst esi = cmd.ssId % config.k;\n\tif (sbn <= retiredSbnFrontier) return;\n\tconst existingBlock = blocks.get(sbn);\n\tif (existingBlock && isTerminalBlock(existingBlock)) return;\n\tif (acceptedSourceEsis.get(sbn)?.has(esi)) return;\n\n\tconst result = wasmDecoder.add_source(cmd.ssId, view, cmd.ts);\n\tadvanceMediaHorizon(sbn);\n\tlet sourceEsis = acceptedSourceEsis.get(sbn);\n\tif (!sourceEsis) {\n\t\tsourceEsis = new Set<number>();\n\t\tacceptedSourceEsis.set(sbn, sourceEsis);\n\t}\n\tsourceEsis.add(esi);\n\n\t// Update block state\n\tconst block = getOrCreateBlock(sbn);\n\tblock.sourceReceived++;\n\tblock.lastSymbolTs = performance.now();\n\tsourceSymbols++;\n\n\t// The FEC worker must remain decode-only on the per-symbol hot path. ALTA\n\t// WASM is retained temporarily for low-rate signaling users, but media is\n\t// authenticated by the canonical manifest verifier at router admission.\n\tif (altaEnabled) altaPending++;\n\n\t// Check if block is complete (all authored source symbols received:\n\t// SSB_length once a repair symbol declared it, otherwise K)\n\tconst authoredLength = block.ssbLength ?? block.k;\n\tif (\n\t\tblock.sourceReceived >= authoredLength &&\n\t\tblock.state === \"collecting\"\n\t) {\n\t\tmarkBlockTerminal(block, \"complete\");\n\t\tblocksComplete++;\n\t\temitBlockUpdate(block);\n\t}\n\n\t\t// A source-triggered return can be either clean block completion or recovery\n\t\t// of earlier missing symbols after repair arrived. Clean completion is\n\t\t// already routed by the source path, so only emit when the block did not\n\t\t// reach K source arrivals.\n\t\tif (result && result.byteLength > 0 && block.sourceReceived < authoredLength) {\n\t\t\tconst recovered = new Uint8Array(toOwnedArrayBuffer(result));\n\t\t\tconst recoveryMs = performance.now() - block.firstSymbolTs;\n\t\t\trecoveryTimes.push(recoveryMs);\n\t\t\tif (recoveryTimes.length > 1000) recoveryTimes.shift();\n\n\t\t\tif (block.state === \"collecting\") {\n\t\t\t\tmarkBlockTerminal(block, \"recovered\");\n\t\t\t\tblocksRecovered++;\n\t\t\t\temitBlockUpdate(block);\n\t\t\t}\n\t\t\temitRecoveredSymbols(sbn, recovered, block);\n\t\t}\n\t\tsynchronizeDecoderHorizon();\n\t}\n\nfunction handleFeedRepair(\n\tcmd: Extract<FecWorkerCommand, { type: \"feedRepair\" }>,\n): void {\n\tif (!wasmDecoder) {\n\t\tthrow new Error(\"[FecWorker] feedRepair: not configured\");\n\t}\n\tif (!config) {\n\t\tthrow new Error(\"[FecWorker] feedRepair: config missing\");\n\t}\n\tif (\n\t\t!isUint32(cmd.ssStart) ||\n\t\t!isUint32(cmd.ssbLength) ||\n\t\tcmd.ssbLength <= 0 ||\n\t\tcmd.ssbLength > config.k ||\n\t\tcmd.ssStart % config.k !== 0 ||\n\t\t!isUint32(cmd.rsId) ||\n\t\tconfig.k + cmd.rsId > UINT24_MAX ||\n\t\t!(cmd.data instanceof ArrayBuffer)\n\t) {\n\t\tthrow new Error(\"[FecWorker] feedRepair: invalid repair symbol\");\n\t}\n\n\tconst view = new Uint8Array(cmd.data);\n\tif (config.symbolSize > 0 && view.byteLength !== config.symbolSize) {\n\t\trepairSymbolSizeMismatch++;\n\t\tif (repairSymbolSizeMismatch <= 5 || repairSymbolSizeMismatch % 100 === 0) {\n\t\t\temit({\n\t\t\t\ttype: \"error\",\n\t\t\t\tcode: \"repair-symbol-size-mismatch\",\n\t\t\t\tmessage: `[FecWorker] Dropping repair symbol with invalid size: got ${view.byteLength}B, expected ${config.symbolSize}B (ssStart=${cmd.ssStart}, ssbLength=${cmd.ssbLength}, rsId=${cmd.rsId})`,\n\t\t\t});\n\t\t}\n\t\treturn;\n\t}\n\tconst sbn = Math.floor(cmd.ssStart / config.k);\n\tconst repairEsi = config.k + cmd.rsId;\n\tif (sbn <= retiredSbnFrontier) return;\n\tconst existingBlock = blocks.get(sbn);\n\tif (existingBlock && isTerminalBlock(existingBlock)) return;\n\tif (acceptedRepairEsis.get(sbn)?.has(repairEsi)) return;\n\t// One block has one authored SSB_length; a repair symbol naming another\n\t// is dropped before it reaches the decoder (which rejects it too).\n\tif (existingBlock?.ssbLength !== undefined && existingBlock.ssbLength !== cmd.ssbLength) {\n\t\temit({\n\t\t\ttype: \"error\",\n\t\t\tcode: \"repair-ssb-length-conflict\",\n\t\t\tmessage: `[FecWorker] Dropping repair symbol whose SSB_length ${cmd.ssbLength} conflicts with ${existingBlock.ssbLength} (sbn=${sbn})`,\n\t\t});\n\t\treturn;\n\t}\n\n\tconst result = wasmDecoder.add_repair(\n\t\tcmd.ssStart,\n\t\tcmd.ssbLength,\n\t\tcmd.rsId,\n\t\tview,\n\t\tcmd.ts,\n\t);\n\tadvanceMediaHorizon(sbn);\n\tlet repairEsis = acceptedRepairEsis.get(sbn);\n\tif (!repairEsis) {\n\t\trepairEsis = new Set<number>();\n\t\tacceptedRepairEsis.set(sbn, repairEsis);\n\t}\n\trepairEsis.add(repairEsi);\n\tconst block = getOrCreateBlock(sbn);\n\tblock.ssbLength = cmd.ssbLength;\n\tblock.repairReceived++;\n\tblock.lastSymbolTs = performance.now();\n\trepairSymbols++;\n\t\t// Every authored source symbol already arrived: knowing SSB_length makes\n\t\t// the block clean. The decoder's return is the source already routed.\n\t\t// Otherwise, returned data is the recovered source block: its SSB_length\n\t\t// fixed-width authored symbols concatenated. Split it before emitting so\n\t\t// MmtpRouter gets the same one-symbol shape as a direct source packet.\n\t\tif (block.sourceReceived >= cmd.ssbLength && block.state === \"collecting\") {\n\t\t\tmarkBlockTerminal(block, \"complete\");\n\t\t\tblocksComplete++;\n\t\t\temitBlockUpdate(block);\n\t\t} else if (result && result.byteLength > 0) {\n\t\t\tconst recovered = new Uint8Array(toOwnedArrayBuffer(result));\n\t\t\tconst recoveryMs = performance.now() - block.firstSymbolTs;\n\t\t\trecoveryTimes.push(recoveryMs);\n\t\t// Cap recovery times array at 1000 entries\n\t\tif (recoveryTimes.length > 1000) recoveryTimes.shift();\n\n\t\tif (block.state === \"collecting\") {\n\t\t\tmarkBlockTerminal(block, \"recovered\");\n\t\t\tblocksRecovered++;\n\t\t\t\temitBlockUpdate(block);\n\t\t\t}\n\t\t\temitRecoveredSymbols(sbn, recovered, block);\n\t\t}\n\t\tsynchronizeDecoderHorizon();\n\t}\n\nfunction handleRelayBlockSig(\n\tcmd: Extract<FecWorkerCommand, { type: \"relayBlockSig\" }>,\n): void {\n\t// No-op AUTH stub: store sig on block, mark as not-yet-verified\n\tconst block = blocks.get(cmd.sbn);\n\tif (block) {\n\t\t// Real verification deferred to ALTA milestone\n\t\t// For now, mark as null (not verified) \u2014 will be wired when ALTA is implemented\n\t\tblock.relayBlockSigValid = null;\n\t\temitBlockUpdate(block);\n\t}\n}\n\nfunction handleCleanup(\n\tcmd: Extract<FecWorkerCommand, { type: \"cleanup\" }>,\n): void {\n\tif (\n\t\t!Array.isArray(cmd.sbns) ||\n\t\tcmd.sbns.length === 0 ||\n\t\t!cmd.sbns.every(isUint32)\n\t) {\n\t\tthrow new Error(\"[FecWorker] cleanup: invalid SBNs\");\n\t}\n\tconst sbns = [...new Set(cmd.sbns)].sort((a, b) => a - b);\n\tconst pendingSbns = sbns.filter((sbn) => sbn > retiredSbnFrontier);\n\ttry {\n\t\tif (!wasmDecoder) {\n\t\t\tthrow new Error(\"[FecWorker] cleanup: not configured\");\n\t\t}\n\n\t\t// Call WASM cleanup only after all earlier symbol commands have drained.\n\t\t// The detailed API carries the true owner of every fill emitted by a\n\t\t// single cleanup pass; command coalescing must not infer ownership from\n\t\t// the largest timed-out SBN.\n\t\tconst cleanupRecords = pendingSbns.length > 0\n\t\t\t? wasmDecoder.cleanup_blocks_detailed(Uint32Array.from(pendingSbns))\n\t\t\t: new Uint8Array();\n\t\t// Manager deadlines are block-scoped and may expire a newer SBN while an\n\t\t// older interleaved block is still live. Only accepted media progression\n\t\t// advances the shared JS/Rust horizon; cleanup creates exact tombstones.\n\n\t\t// Rust already finalized every SBN behind the media frontier. For each\n\t\t// remaining exact request, mirror the block-scoped WASM boundary immediately\n\t\t// so JS never retains state for a decoder block that is gone, even if decoding\n\t\t// the trusted cleanup framing were to fail.\n\t\tfor (const sbn of pendingSbns) {\n\t\t\tlet currentBlock = blocks.get(sbn);\n\t\t\tif (currentBlock && isTerminalBlock(currentBlock)) {\n\t\t\t\tretireAcceptedIds(sbn);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tcurrentBlock ??= getOrCreateBlock(sbn);\n\t\t\tif (currentBlock.sourceReceived >= currentBlock.k) {\n\t\t\t\tmarkBlockTerminal(currentBlock, \"complete\");\n\t\t\t\tblocksComplete++;\n\t\t\t} else {\n\t\t\t\tmarkBlockTerminal(currentBlock, \"failed\");\n\t\t\t\tblocksFailed++;\n\t\t\t}\n\t\t\temitBlockUpdate(currentBlock);\n\t\t}\n\n\t\tconst greenFills = decodeCleanupRecords(cleanupRecords);\n\t\tfor (const { sbn, data } of greenFills) {\n\t\t\tgreenFillFrames++;\n\t\t\temit({ type: \"greenFill\", sbn, data }, [data]);\n\t\t}\n\t} finally {\n\t\t// Message ordering makes this an acknowledgement that every source/repair\n\t\t// command posted before cleanup has completed. The main thread must not\n\t\t// commit failure accounting until it observes this event.\n\t\temit({ type: \"cleanupComplete\", sbns });\n\t}\n}\n\nfunction decodeCleanupRecords(\n\tframed: Uint8Array,\n): Array<{ sbn: number; data: ArrayBuffer }> {\n\tconst records: Array<{ sbn: number; data: ArrayBuffer }> = [];\n\tconst view = new DataView(framed.buffer, framed.byteOffset, framed.byteLength);\n\tlet offset = 0;\n\twhile (offset < framed.byteLength) {\n\t\tif (framed.byteLength - offset < 8) {\n\t\t\tthrow new Error(\"[FecWorker] cleanup_blocks_detailed: truncated record header\");\n\t\t}\n\t\tconst sbn = view.getUint32(offset, false);\n\t\tconst length = view.getUint32(offset + 4, false);\n\t\toffset += 8;\n\t\tif (length > framed.byteLength - offset) {\n\t\t\tthrow new Error(\"[FecWorker] cleanup_blocks_detailed: truncated record payload\");\n\t\t}\n\t\tconst data = toOwnedArrayBuffer(framed.subarray(offset, offset + length));\n\t\trecords.push({ sbn, data });\n\t\toffset += length;\n\t}\n\treturn records;\n}\n\nfunction handleDispose(): void {\n\t// Clear snapshot timer (MUST clear to prevent leaks)\n\tif (snapshotTimer !== null) {\n\t\tclearInterval(snapshotTimer);\n\t\tsnapshotTimer = null;\n\t}\n\n\t// Free ALTA verifier WASM object (MUST call to release WASM memory \u2014\n\t// Worker.terminate() fires immediately after dispose, so the FinalizationRegistry\n\t// callback has no chance to run and this memory would leak without explicit free)\n\tif (altaVerifier) {\n\t\ttry {\n\t\t\taltaVerifier.free();\n\t\t} catch (_e) {\n\t\t\t// Best-effort \u2014 verifier may already be freed\n\t\t}\n\t\taltaVerifier = null;\n\t}\n\n\t// Free WASM decoder (MUST call to release WASM memory)\n\tif (wasmDecoder) {\n\t\twasmDecoder.free();\n\t\twasmDecoder = null;\n\t}\n\n\t// Clear deferred-verify queue so pinned ArrayBuffers drop.\n\tpendingVerify.clear();\n\tpendingVerifyCap = 0;\n\tpendingVerifyTtlMs = 0;\n\n\tconfig = null;\n\tclearBlockTracking();\n}\n\nfunction handleReset(): void {\n\ttry {\n\t\twasmDecoder?.flush();\n\t\twasmDecoder?.reset_stats();\n\t} catch (err) {\n\t\temit({\n\t\t\ttype: \"error\",\n\t\t\tcode: \"reset-failed\",\n\t\t\tmessage:\n\t\t\t\terr instanceof Error\n\t\t\t\t\t? `[FecWorker] reset failed: ${err.message}`\n\t\t\t\t\t: `[FecWorker] reset failed: ${String(err)}`,\n\t\t});\n\t\treturn;\n\t}\n\n\tclearBlockTracking();\n\tsourceSymbols = 0;\n\trepairSymbols = 0;\n\tblocksComplete = 0;\n\tblocksRecovered = 0;\n\tblocksFailed = 0;\n\tgreenFillFrames = 0;\n\taltaVerified = 0;\n\taltaFailed = 0;\n\taltaFailedDetails.length = 0;\n\taltaPending = 0;\n\taltaPendingEvictedCap = 0;\n\taltaPendingEvictedTtl = 0;\n\taltaError = 0;\n\trelayBlocksVerified = 0;\n\trelayBlocksFailed = 0;\n\trepairSymbolSizeMismatch = 0;\n\temit({ type: \"resetComplete\" });\n\tif (config) emitSnapshot();\n}\n\n/**\n * A batch of symbols fed in one page task (BLO-36599). Each record is\n * handled exactly as its single-symbol command would be, in order, and a\n * failing record reports the same `command-failed` error that command would\n * without stopping the records after it.\n */\nfunction handleFeedSymbols(\n\tcmd: Extract<FecWorkerCommand, { type: \"feedSymbols\" }>,\n): void {\n\tif (!Array.isArray(cmd.symbols)) {\n\t\tthrow new Error(\"[FecWorker] feedSymbols: symbols must be an array\");\n\t}\n\tfor (const symbol of cmd.symbols) {\n\t\ttry {\n\t\t\tif (symbol?.type === \"feedSource\") handleFeedSource(symbol);\n\t\t\telse if (symbol?.type === \"feedRepair\") handleFeedRepair(symbol);\n\t\t\telse {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`[FecWorker] feedSymbols: unknown symbol type ${String((symbol as { type?: unknown } | null)?.type)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (err) {\n\t\t\temit({\n\t\t\t\ttype: \"error\",\n\t\t\t\tcode: \"command-failed\",\n\t\t\t\tmessage:\n\t\t\t\t\terr instanceof Error ? err.message : `[FecWorker] ${String(err)}`,\n\t\t\t});\n\t\t}\n\t}\n}\n\n// --- Main message handler ---\n\nasync function dispatchCommand(cmd: FecWorkerCommand): Promise<void> {\n\ttry {\n\t\tswitch (cmd.type) {\n\t\t\tcase \"configure\":\n\t\t\t\t// handleConfigure is async (ALTA WASM init uses dynamic import).\n\t\t\t\t// Await it so feed/cleanup messages cannot run against a partially\n\t\t\t\t// configured decoder.\n\t\t\t\tawait handleConfigure(cmd);\n\t\t\t\tbreak;\n\t\t\tcase \"feedSource\":\n\t\t\t\thandleFeedSource(cmd);\n\t\t\t\tbreak;\n\t\t\tcase \"feedRepair\":\n\t\t\t\thandleFeedRepair(cmd);\n\t\t\t\tbreak;\n\t\t\tcase \"feedSymbols\":\n\t\t\t\thandleFeedSymbols(cmd);\n\t\t\t\tbreak;\n\t\t\tcase \"relayBlockSig\":\n\t\t\t\thandleRelayBlockSig(cmd);\n\t\t\t\tbreak;\n\t\t\tcase \"cleanup\":\n\t\t\t\thandleCleanup(cmd);\n\t\t\t\tbreak;\n\t\t\tcase \"reset\":\n\t\t\t\thandleReset();\n\t\t\t\tbreak;\n\t\t\tcase \"dispose\":\n\t\t\t\thandleDispose();\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\temit({\n\t\t\t\t\ttype: \"error\",\n\t\t\t\t\tcode: \"unknown-command\",\n\t\t\t\t\tmessage: `Unknown command type: ${(cmd as Record<string, unknown>).type}`,\n\t\t\t\t});\n\t\t}\n\t} catch (err) {\n\t\temit({\n\t\t\ttype: \"error\",\n\t\t\tcode: \"command-failed\",\n\t\t\tmessage:\n\t\t\t\terr instanceof Error ? err.message : `[FecWorker] ${String(err)}`,\n\t\t});\n\t}\n}\n\nlet commandQueue: Promise<void> = Promise.resolve();\n\nself.onmessage = (e: MessageEvent<FecWorkerCommand>) => {\n\tconst cmd = e.data;\n\tcommandQueue = commandQueue.then(() => dispatchCommand(cmd));\n};\n"],
5
+ "mappings": ";;;AAOO,SAAS,mBAAmB,MAA+B;AACjE,QAAM,OAAO,IAAI,WAAW,KAAK,UAAU;AAC3C,OAAK,IA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,QAAM,MAAM,EAAE;AACd,iBAAe,aAAa,KAAK,MAAM,gBAAgB,GAAG,CAAC;AAC5D;",
6
6
  "names": []
7
7
  }
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Re-exports shared types and main-thread client.
5
5
  */
6
- export type { FecWorkerCommand, FecWorkerEvent, FecWorkerErrorCode, FecTrackConfig, FecTrackStats, FecBlockSnapshot, FrameMeta, } from "./fec-worker-types.js";
6
+ export type { FecWorkerCommand, FecSymbolCommand, FecWorkerOptionalCommand, FecWorkerEvent, FecWorkerErrorCode, FecTrackConfig, FecTrackStats, FecBlockSnapshot, FrameMeta, } from "./fec-worker-types.js";
7
7
  export { FecWorkerClient } from "./fec-worker-client.js";
8
8
  export type { ShredWorkerCommand, ShredWorkerEvent, ShredWorkerConfig, ShredWorkerStats, ShredWorkerErrorCode, RecoveredMeta, SlotSample, } from "./shred-worker-types.js";
9
9
  export { ShredWorkerClient } from "./shred-worker-client.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EACX,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,SAAS,GACT,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAKzD,YAAY,EACX,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,EACb,UAAU,GACV,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EACX,gBAAgB,EAChB,gBAAgB,EAChB,wBAAwB,EACxB,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,SAAS,GACT,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAKzD,YAAY,EACX,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,EACb,UAAU,GACV,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAYH,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAezD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAcH,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAezD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockcast/fec-worker",
3
- "version": "0.1.0-main.c71423b8a4e4",
3
+ "version": "0.1.0-main.cde7600fad6a",
4
4
  "description": "Worker-per-track FEC decode with zero-copy ArrayBuffer transfer and ALTA auth plumbing",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -35,7 +35,7 @@
35
35
  "test:watch": "vitest"
36
36
  },
37
37
  "dependencies": {
38
- "@blockcast/mmt-alta-parse": "0.1.0-main.c71423b8a4e4"
38
+ "@blockcast/mmt-alta-parse": "0.1.0-main.cde7600fad6a"
39
39
  },
40
40
  "devDependencies": {
41
41
  "esbuild": "^0.28.0",
@@ -10,6 +10,7 @@
10
10
 
11
11
  import type {
12
12
  FecWorkerCommand,
13
+ FecSymbolCommand,
13
14
  FecWorkerEvent,
14
15
  FecTrackConfig,
15
16
  FecTrackStats,
@@ -31,6 +32,15 @@ export class FecWorkerClient {
31
32
  #pendingResets = 0;
32
33
  #resetFailed = false;
33
34
  #disposed = false;
35
+ // Symbols fed during the current task, sent as one feedSymbols message
36
+ // when the task's microtasks run (BLO-36599). A packet stream delivers many
37
+ // symbols per task, and each postMessage is a structured-clone round trip
38
+ // on the page thread; the batch boundary is the task, not a size or timer.
39
+ #pendingSymbols: FecSymbolCommand[] = [];
40
+ #pendingTransfer: Transferable[] = [];
41
+ #flushQueued = false;
42
+ // Batching starts only once the Worker announced it accepts feedSymbols.
43
+ #batchSymbols = false;
34
44
 
35
45
  /**
36
46
  * Create a FecWorkerClient.
@@ -66,6 +76,7 @@ export class FecWorkerClient {
66
76
  altaWasmModule?: WebAssembly.Module,
67
77
  ): void {
68
78
  if (this.#disposed) throw new Error("[FecWorkerClient] disposed");
79
+ this.#flushSymbols();
69
80
  const cmd: FecWorkerCommand = {
70
81
  type: "configure",
71
82
  config,
@@ -84,7 +95,8 @@ export class FecWorkerClient {
84
95
 
85
96
  /**
86
97
  * Feed a source symbol to the Worker. data ArrayBuffer is transferred (zero-copy).
87
- * Caller must not access data after this call — it is detached.
98
+ * Caller must not access data after this call — it is transferred with the
99
+ * task's symbol batch, before any later command of this client.
88
100
  *
89
101
  * Optional `alta` carries the detached ALTA authenticator bytes and the
90
102
  * byte offset in `data` where the signed payload ends. The auth buffer is
@@ -98,18 +110,22 @@ export class FecWorkerClient {
98
110
  alta?: { auth: ArrayBuffer; payloadEnd: number },
99
111
  ): void {
100
112
  if (this.#disposed) throw new Error("[FecWorkerClient] feedSource on a disposed client");
101
- const cmd: FecWorkerCommand = alta
102
- ? {
113
+ if (alta) {
114
+ this.#queueSymbol(
115
+ {
103
116
  type: "feedSource",
104
117
  ssId,
105
118
  data,
106
119
  ts,
107
120
  altaAuth: alta.auth,
108
121
  altaPayloadEnd: alta.payloadEnd,
109
- }
110
- : { type: "feedSource", ssId, data, ts };
111
- const transfer: Transferable[] = alta ? [data, alta.auth] : [data];
112
- this.#worker.postMessage(cmd, transfer);
122
+ },
123
+ data,
124
+ alta.auth,
125
+ );
126
+ } else {
127
+ this.#queueSymbol({ type: "feedSource", ssId, data, ts }, data);
128
+ }
113
129
  }
114
130
 
115
131
  /**
@@ -129,16 +145,38 @@ export class FecWorkerClient {
129
145
  ts: number,
130
146
  ): void {
131
147
  if (this.#disposed) throw new Error("[FecWorkerClient] feedRepair on a disposed client");
148
+ this.#queueSymbol({ type: "feedRepair", ssStart, ssbLength, rsId, data, ts }, data);
149
+ }
150
+
151
+ #queueSymbol(symbol: FecSymbolCommand, data: ArrayBuffer, auth?: ArrayBuffer): void {
152
+ if (!this.#batchSymbols) {
153
+ this.#worker.postMessage(symbol, auth ? [data, auth] : [data]);
154
+ return;
155
+ }
156
+ this.#pendingSymbols.push(symbol);
157
+ this.#pendingTransfer.push(data);
158
+ if (auth) this.#pendingTransfer.push(auth);
159
+ if (this.#flushQueued) return;
160
+ this.#flushQueued = true;
161
+ queueMicrotask(() => {
162
+ this.#flushQueued = false;
163
+ this.#flushSymbols();
164
+ });
165
+ }
166
+
167
+ /**
168
+ * Send the symbols fed so far. Every other command calls this first, so a
169
+ * cleanup barrier, reset or signature still follows all earlier symbols.
170
+ */
171
+ #flushSymbols(): void {
172
+ if (this.#pendingSymbols.length === 0 || this.#disposed) return;
173
+ const symbols = this.#pendingSymbols;
174
+ const transfer = this.#pendingTransfer;
175
+ this.#pendingSymbols = [];
176
+ this.#pendingTransfer = [];
132
177
  this.#worker.postMessage(
133
- {
134
- type: "feedRepair",
135
- ssStart,
136
- ssbLength,
137
- rsId,
138
- data,
139
- ts,
140
- } satisfies FecWorkerCommand,
141
- [data],
178
+ { type: "feedSymbols", symbols } satisfies FecWorkerCommand,
179
+ transfer,
142
180
  );
143
181
  }
144
182
 
@@ -147,6 +185,7 @@ export class FecWorkerClient {
147
185
  */
148
186
  relayBlockSig(sbn: number, sig: ArrayBuffer, hash: ArrayBuffer): void {
149
187
  if (this.#disposed) throw new Error("[FecWorkerClient] relayBlockSig on a disposed client");
188
+ this.#flushSymbols();
150
189
  this.#worker.postMessage(
151
190
  { type: "relayBlockSig", sbn, sig, hash } satisfies FecWorkerCommand,
152
191
  [sig, hash],
@@ -178,6 +217,7 @@ export class FecWorkerClient {
178
217
  /** Reset this track's decoder epoch while preserving Worker configuration. */
179
218
  reset(): void {
180
219
  if (this.#disposed) throw new Error("[FecWorkerClient] reset on a disposed client");
220
+ this.#flushSymbols();
181
221
  this.#pendingResets++;
182
222
  this.#cleanupInFlight = null;
183
223
  this.#queuedCleanupSbns.clear();
@@ -185,6 +225,9 @@ export class FecWorkerClient {
185
225
  }
186
226
 
187
227
  #postCleanup(sbns: Set<number>): void {
228
+ // The cleanup is a queue-drain barrier: every symbol fed before it is
229
+ // posted must reach the Worker first.
230
+ this.#flushSymbols();
188
231
  this.#cleanupInFlight = sbns;
189
232
  const orderedSbns = [...sbns].sort((a, b) => a - b);
190
233
  this.#worker.postMessage(
@@ -239,6 +282,9 @@ export class FecWorkerClient {
239
282
  dispose(): void {
240
283
  if (this.#disposed) return;
241
284
  this.#disposed = true;
285
+ // A terminated Worker decodes nothing; symbols still batched are dropped.
286
+ this.#pendingSymbols = [];
287
+ this.#pendingTransfer = [];
242
288
  this.#cleanupInFlight = null;
243
289
  this.#queuedCleanupSbns.clear();
244
290
  this.#worker.postMessage({ type: "dispose" } satisfies FecWorkerCommand);
@@ -246,6 +292,12 @@ export class FecWorkerClient {
246
292
  }
247
293
 
248
294
  #handleEvent(event: FecWorkerEvent): void {
295
+ if (event.type === "capabilities") {
296
+ if (Array.isArray(event.commands) && event.commands.includes("feedSymbols")) {
297
+ this.#batchSymbols = true;
298
+ }
299
+ return;
300
+ }
249
301
  if (event.type === "resetComplete") {
250
302
  this.#pendingResets = Math.max(0, this.#pendingResets - 1);
251
303
  this.#resetFailed = false;
@@ -62,8 +62,10 @@ export interface FecBlockSnapshot {
62
62
  sourceReceived: number;
63
63
  /** Number of repair symbols received */
64
64
  repairReceived: number;
65
- /** Expected source symbols (K) */
65
+ /** Configured source-block geometry (K) */
66
66
  k: number;
67
+ /** Authored source symbols (SSB_length) once a repair symbol declared it */
68
+ ssbLength?: number;
67
69
  /** Expected repair symbols (P) */
68
70
  repairCount: number;
69
71
  /** Timestamp of first symbol arrival (ms) */
@@ -168,7 +170,9 @@ export interface FecTrackStats {
168
170
  export type FecWorkerErrorCode =
169
171
  | "recovered-symbol-size-unconfigured"
170
172
  | "recovered-block-too-short"
173
+ | "recovered-symbol-ssb-length-invalid"
171
174
  | "repair-symbol-size-mismatch"
175
+ | "repair-ssb-length-conflict"
172
176
  | "reset-failed"
173
177
  | "unknown-command"
174
178
  | "command-failed"
@@ -185,8 +189,14 @@ export interface FrameMeta {
185
189
  recovered: boolean;
186
190
  /** Source block number this frame belongs to */
187
191
  sbn: number;
188
- /** Encoding Symbol ID within the recovered source block (0..K-1). */
192
+ /** Encoding Symbol ID within the recovered source block (0..ssbLength-1). */
189
193
  esi?: number;
194
+ /**
195
+ * Authored source-symbol count of the recovered block (the repair
196
+ * symbols' SSB_length, 1..K). Recovered frames are ESI 0..ssbLength-1;
197
+ * ESIs ssbLength..K-1 are encoder zero padding and are never emitted.
198
+ */
199
+ ssbLength?: number;
190
200
  }
191
201
 
192
202
  // --- Worker commands (main -> worker) ---
@@ -241,6 +251,17 @@ export type FecWorkerCommand =
241
251
  data: ArrayBuffer;
242
252
  ts: number;
243
253
  }
254
+ | {
255
+ /**
256
+ * Every source and repair symbol the page fed in one task, in feed
257
+ * order, sharing one transfer list. The client sends symbols this
258
+ * way instead of one message per symbol (BLO-36599); the Worker
259
+ * handles each record exactly like the single-symbol command of the
260
+ * same `type`, and a record that fails does not stop the others.
261
+ */
262
+ type: "feedSymbols";
263
+ symbols: FecSymbolCommand[];
264
+ }
244
265
  | {
245
266
  type: "relayBlockSig";
246
267
  sbn: number;
@@ -255,6 +276,12 @@ export type FecWorkerCommand =
255
276
  | { type: "reset" }
256
277
  | { type: "dispose" };
257
278
 
279
+ /** One symbol record of a `feedSymbols` batch. */
280
+ export type FecSymbolCommand = Extract<
281
+ FecWorkerCommand,
282
+ { type: "feedSource" } | { type: "feedRepair" }
283
+ >;
284
+
258
285
  // --- Worker events (worker -> main) ---
259
286
 
260
287
  /** Discriminated union of all events emitted from Worker to main thread. */
@@ -265,4 +292,14 @@ export type FecWorkerEvent =
265
292
  | { type: "greenFill"; sbn: number; data: ArrayBuffer }
266
293
  | { type: "cleanupComplete"; sbns: number[] }
267
294
  | { type: "resetComplete" }
295
+ /**
296
+ * Optional commands this Worker accepts, posted once it is configured.
297
+ * The client uses `feedSymbols` only after the Worker names it, so a page
298
+ * that meets an older cached Worker bundle keeps sending one command per
299
+ * symbol instead of a batch that Worker would reject (BLO-36599).
300
+ */
301
+ | { type: "capabilities"; commands: FecWorkerOptionalCommand[] }
268
302
  | { type: "error"; message: string; code?: FecWorkerErrorCode };
303
+
304
+ /** Commands a client may send only after the Worker announced them. */
305
+ export type FecWorkerOptionalCommand = "feedSymbols";
package/src/fec-worker.ts CHANGED
@@ -496,16 +496,19 @@ function emitRecoveredSymbols(
496
496
  });
497
497
  return;
498
498
  }
499
- if (recoveredBlock.byteLength < symbolSize * config.k) {
499
+ // The decoder returns only the block's authored source symbols
500
+ // (SSB_length x T); the encoder's zero padding is not media.
501
+ const ssbLength = block.ssbLength ?? config.k;
502
+ if (recoveredBlock.byteLength !== symbolSize * ssbLength) {
500
503
  emit({
501
504
  type: "error",
502
505
  code: "recovered-block-too-short",
503
- message: `[FecWorker] recovered block too short: got ${recoveredBlock.byteLength}B, expected at least ${symbolSize * config.k}B`,
506
+ message: `[FecWorker] recovered block has the wrong length: got ${recoveredBlock.byteLength}B, expected ${symbolSize * ssbLength}B (SSB_length=${ssbLength})`,
504
507
  });
505
508
  return;
506
509
  }
507
510
 
508
- for (let i = 0; i < config.k; i++) {
511
+ for (let i = 0; i < ssbLength; i++) {
509
512
  const symbol = recoveredBlock.subarray(i * symbolSize, (i + 1) * symbolSize);
510
513
 
511
514
  // Source authentication now runs once at router admission in
@@ -520,6 +523,7 @@ function emitRecoveredSymbols(
520
523
  recovered: true,
521
524
  sbn,
522
525
  esi: i,
526
+ ssbLength,
523
527
  };
524
528
  emit({ type: "frame", data: buf, meta }, [buf]);
525
529
  }
@@ -662,6 +666,10 @@ async function handleConfigure(
662
666
 
663
667
  wasmDecoder.configure_params(config.k, config.symbolSize);
664
668
 
669
+ // Tell the client which optional commands this Worker accepts, so it can
670
+ // batch symbols without risking a Worker that predates the batch command.
671
+ emit({ type: "capabilities", commands: ["feedSymbols"] });
672
+
665
673
  // Start periodic snapshot emission (200ms floor)
666
674
  startSnapshotTimer();
667
675
 
@@ -716,9 +724,11 @@ function handleFeedSource(
716
724
  // authenticated by the canonical manifest verifier at router admission.
717
725
  if (altaEnabled) altaPending++;
718
726
 
719
- // Check if block is complete (all K source symbols received)
727
+ // Check if block is complete (all authored source symbols received:
728
+ // SSB_length once a repair symbol declared it, otherwise K)
729
+ const authoredLength = block.ssbLength ?? block.k;
720
730
  if (
721
- block.sourceReceived >= block.k &&
731
+ block.sourceReceived >= authoredLength &&
722
732
  block.state === "collecting"
723
733
  ) {
724
734
  markBlockTerminal(block, "complete");
@@ -730,7 +740,7 @@ function handleFeedSource(
730
740
  // of earlier missing symbols after repair arrived. Clean completion is
731
741
  // already routed by the source path, so only emit when the block did not
732
742
  // reach K source arrivals.
733
- if (result && result.byteLength > 0 && block.sourceReceived < block.k) {
743
+ if (result && result.byteLength > 0 && block.sourceReceived < authoredLength) {
734
744
  const recovered = new Uint8Array(toOwnedArrayBuffer(result));
735
745
  const recoveryMs = performance.now() - block.firstSymbolTs;
736
746
  recoveryTimes.push(recoveryMs);
@@ -786,6 +796,16 @@ function handleFeedRepair(
786
796
  const existingBlock = blocks.get(sbn);
787
797
  if (existingBlock && isTerminalBlock(existingBlock)) return;
788
798
  if (acceptedRepairEsis.get(sbn)?.has(repairEsi)) return;
799
+ // One block has one authored SSB_length; a repair symbol naming another
800
+ // is dropped before it reaches the decoder (which rejects it too).
801
+ if (existingBlock?.ssbLength !== undefined && existingBlock.ssbLength !== cmd.ssbLength) {
802
+ emit({
803
+ type: "error",
804
+ code: "repair-ssb-length-conflict",
805
+ message: `[FecWorker] Dropping repair symbol whose SSB_length ${cmd.ssbLength} conflicts with ${existingBlock.ssbLength} (sbn=${sbn})`,
806
+ });
807
+ return;
808
+ }
789
809
 
790
810
  const result = wasmDecoder.add_repair(
791
811
  cmd.ssStart,
@@ -802,13 +822,20 @@ function handleFeedRepair(
802
822
  }
803
823
  repairEsis.add(repairEsi);
804
824
  const block = getOrCreateBlock(sbn);
825
+ block.ssbLength = cmd.ssbLength;
805
826
  block.repairReceived++;
806
827
  block.lastSymbolTs = performance.now();
807
828
  repairSymbols++;
808
- // If WASM returned data, it is the recovered source block: K fixed-width
809
- // source symbols concatenated. Split it before emitting so MmtpRouter gets
810
- // the same one-symbol shape as a direct source packet.
811
- if (result && result.byteLength > 0) {
829
+ // Every authored source symbol already arrived: knowing SSB_length makes
830
+ // the block clean. The decoder's return is the source already routed.
831
+ // Otherwise, returned data is the recovered source block: its SSB_length
832
+ // fixed-width authored symbols concatenated. Split it before emitting so
833
+ // MmtpRouter gets the same one-symbol shape as a direct source packet.
834
+ if (block.sourceReceived >= cmd.ssbLength && block.state === "collecting") {
835
+ markBlockTerminal(block, "complete");
836
+ blocksComplete++;
837
+ emitBlockUpdate(block);
838
+ } else if (result && result.byteLength > 0) {
812
839
  const recovered = new Uint8Array(toOwnedArrayBuffer(result));
813
840
  const recoveryMs = performance.now() - block.firstSymbolTs;
814
841
  recoveryTimes.push(recoveryMs);
@@ -994,6 +1021,38 @@ function handleReset(): void {
994
1021
  if (config) emitSnapshot();
995
1022
  }
996
1023
 
1024
+ /**
1025
+ * A batch of symbols fed in one page task (BLO-36599). Each record is
1026
+ * handled exactly as its single-symbol command would be, in order, and a
1027
+ * failing record reports the same `command-failed` error that command would
1028
+ * without stopping the records after it.
1029
+ */
1030
+ function handleFeedSymbols(
1031
+ cmd: Extract<FecWorkerCommand, { type: "feedSymbols" }>,
1032
+ ): void {
1033
+ if (!Array.isArray(cmd.symbols)) {
1034
+ throw new Error("[FecWorker] feedSymbols: symbols must be an array");
1035
+ }
1036
+ for (const symbol of cmd.symbols) {
1037
+ try {
1038
+ if (symbol?.type === "feedSource") handleFeedSource(symbol);
1039
+ else if (symbol?.type === "feedRepair") handleFeedRepair(symbol);
1040
+ else {
1041
+ throw new Error(
1042
+ `[FecWorker] feedSymbols: unknown symbol type ${String((symbol as { type?: unknown } | null)?.type)}`,
1043
+ );
1044
+ }
1045
+ } catch (err) {
1046
+ emit({
1047
+ type: "error",
1048
+ code: "command-failed",
1049
+ message:
1050
+ err instanceof Error ? err.message : `[FecWorker] ${String(err)}`,
1051
+ });
1052
+ }
1053
+ }
1054
+ }
1055
+
997
1056
  // --- Main message handler ---
998
1057
 
999
1058
  async function dispatchCommand(cmd: FecWorkerCommand): Promise<void> {
@@ -1011,6 +1070,9 @@ async function dispatchCommand(cmd: FecWorkerCommand): Promise<void> {
1011
1070
  case "feedRepair":
1012
1071
  handleFeedRepair(cmd);
1013
1072
  break;
1073
+ case "feedSymbols":
1074
+ handleFeedSymbols(cmd);
1075
+ break;
1014
1076
  case "relayBlockSig":
1015
1077
  handleRelayBlockSig(cmd);
1016
1078
  break;
package/src/index.ts CHANGED
@@ -6,6 +6,8 @@
6
6
 
7
7
  export type {
8
8
  FecWorkerCommand,
9
+ FecSymbolCommand,
10
+ FecWorkerOptionalCommand,
9
11
  FecWorkerEvent,
10
12
  FecWorkerErrorCode,
11
13
  FecTrackConfig,