This commit is contained in:
2026-08-16 19:32:44 +01:00
parent 05cfa36e5b
commit ca1a73e0bb
5 changed files with 30 additions and 20 deletions
+4 -3
View File
@@ -829,10 +829,11 @@ export function makeReader(opts = {}) {
let acc = null, frames = 0, anchor = null, pending = null;
const similar = (a, b) => { let s = 0, na = 0, nb = 0; for (let i = 0; i < a.length; i++) { s += a[i] * b[i]; na += a[i] * a[i]; nb += b[i] * b[i]; } return s / Math.sqrt(na * nb || 1); };
// slots only move forward, about 2 per second: a token far from the last one is noise or a replay
const gate = (token, now) => {
// a first token that needed the full rs correction waits for a second one to agree
const gate = (token, now, sure) => {
const slot = +token.slice(1).split(".")[0];
const near = (ref) => { const d = ((slot - ref.slot + 98304) % 65536) - 32768; return d >= -8 && d <= 8 + (now - ref.at) / 100; };
if (!anchor || near(anchor)) { anchor = { slot, at: now }; pending = null; return true; }
if (anchor ? near(anchor) : sure) { anchor = { slot, at: now }; pending = null; return true; }
if (pending && near(pending)) { anchor = { slot, at: now }; pending = null; return true; }
pending = { slot, at: now };
return false;
@@ -850,7 +851,7 @@ export function makeReader(opts = {}) {
if (t && t.fixes <= 2) { token = t.token; via = "sum"; }
}
} else if (token) { acc = Float32Array.from(d.soft, (v) => (v > 0 ? 1.5 : -1.5)); frames = 1; }
if (token && opts.gate !== false && !gate(token, now)) token = null;
if (token && opts.gate !== false && !gate(token, now, via === "sum" || d.fixes <= 2)) token = null;
return { ...d, token, via };
},
};