From 4dae9255e0166e2f4c09236db405b7d254951fcf Mon Sep 17 00:00:00 2001 From: Joshua Horton Date: Fri, 24 Apr 2026 20:40:15 +0700 Subject: [PATCH 1/2] change(web): Apply EB suggestions from code review Co-authored-by: Eberhard Beilharz --- .../worker-thread/src/main/correction/legacy-quotient-spur.ts | 2 +- .../predictive-text/worker-thread/src/main/predict-helpers.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/web/src/engine/predictive-text/worker-thread/src/main/correction/legacy-quotient-spur.ts b/web/src/engine/predictive-text/worker-thread/src/main/correction/legacy-quotient-spur.ts index dadf5bc239..147efc3e52 100644 --- a/web/src/engine/predictive-text/worker-thread/src/main/correction/legacy-quotient-spur.ts +++ b/web/src/engine/predictive-text/worker-thread/src/main/correction/legacy-quotient-spur.ts @@ -51,7 +51,7 @@ export class LegacyQuotientSpur extends SearchQuotientSpur { return new LegacyQuotientSpur(parentNode, inputs, inputSource) as this; } - protected buildEdgesFromResults(priorResults: ReadonlyArray) { + protected buildEdgesFromResults(priorResults: ReadonlyArray): SearchNode[] { // With a newly-available input, we can extend new input-dependent paths from // our previously-reached 'extractedResults' nodes. let outboundNodes = priorResults.map((result) => { diff --git a/web/src/engine/predictive-text/worker-thread/src/main/predict-helpers.ts b/web/src/engine/predictive-text/worker-thread/src/main/predict-helpers.ts index 4b7bde5bae..4a915b74b9 100644 --- a/web/src/engine/predictive-text/worker-thread/src/main/predict-helpers.ts +++ b/web/src/engine/predictive-text/worker-thread/src/main/predict-helpers.ts @@ -534,7 +534,7 @@ export async function correctAndEnumerate( let rawPredictions: CorrectionPredictionTuple[] = []; let bestCorrectionCost: number; const correctionPredictionMap: Record> = {}; - for await(const match of getBestMatches(searchModules, timer, initTokenResultFilterer())) { + for await(const match of getBestTokenMatches(searchModules, timer)) { // Corrections obtained: now to predict from them! const tokenization = tokenizations.find(t => t.spaceId == match.spaceId); From f0c7084dc228da710ce67b3ba85a744f0513ed91 Mon Sep 17 00:00:00 2001 From: Joshua Horton Date: Fri, 24 Apr 2026 08:52:47 -0500 Subject: [PATCH 2/2] change(web): re-filter previously returned results --- .../src/main/correction/distance-modeler.ts | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/web/src/engine/predictive-text/worker-thread/src/main/correction/distance-modeler.ts b/web/src/engine/predictive-text/worker-thread/src/main/correction/distance-modeler.ts index 5408a79bb6..fdbd8f92f0 100644 --- a/web/src/engine/predictive-text/worker-thread/src/main/correction/distance-modeler.ts +++ b/web/src/engine/predictive-text/worker-thread/src/main/correction/distance-modeler.ts @@ -621,9 +621,25 @@ export async function *getBestMatches( if((priorResultsQueue.peek()?.totalCost ?? Number.POSITIVE_INFINITY) <= spaceQueue.peek().currentCost) { const result = priorResultsQueue.dequeue(); - // Just pass it through the filter, even if it _was_ already filtered once before. - filter(result); - return result; + // There's no guarantee that the filter closure is the same instance as + // before. + // + // As a filter function may contain caching and/or deduplication + // components, we pass pre-existing results through the filter so that + // it may reconstruct related state and thus cache/deduplicate new + // results based upon old results. + // + // See `initTokenResultFilterer()`, which maintains a map used for + // deduplication. + // + // As these _are_ pre-existing results, we know that they previously + // passed through the filter with a `true` response. However, as #14366 + // isn't implemented, it IS technically possible that a lower-cost + // result was found after a higher-cost result in some cases; therefore + // there is a chance such a duplicate may exist. On that basis, + // re-filtering even for prior results is reasonably motivated at this + // time. + return filter(result) ? result : null; } let lowestCostSource = spaceQueue.dequeue();