From b1ffa83c8bdde7ff03be7d7d21fff539f8e73676 Mon Sep 17 00:00:00 2001 From: Joshua Horton Date: Wed, 29 Oct 2025 13:57:55 -0500 Subject: [PATCH] fix(web): add safeguard for split-distribution merging --- .../main/correction/search-quotient-spur.ts | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/web/src/engine/predictive-text/worker-thread/src/main/correction/search-quotient-spur.ts b/web/src/engine/predictive-text/worker-thread/src/main/correction/search-quotient-spur.ts index d3b5cd01e5..13108769cc 100644 --- a/web/src/engine/predictive-text/worker-thread/src/main/correction/search-quotient-spur.ts +++ b/web/src/engine/predictive-text/worker-thread/src/main/correction/search-quotient-spur.ts @@ -199,23 +199,28 @@ export abstract class SearchQuotientSpur implements SearchQuotientNode { // per-codepoint. if(localInputId != spaceInputId || localInputId === undefined) { return space.construct(parentMerge, space.inputs, space.inputSource); - } else { - // Get the twin halves that were split. - // Assumption: the two halves are in their original order, etc. - const localInputs = this.inputs; - const spaceInputs = space.inputs; - - // Merge them! - const mergedInputs = localInputs?.map((entry, index) => { - return { - sample: buildMergedTransform(entry.sample, spaceInputs[index].sample), - p: entry.p - } - }); - - // Now to re-merge the two halves. - return space.construct(this.parentNode, mergedInputs, this.inputSource); } + // Get the twin halves that were split. + // Assumption: the two halves are in their original order, etc. + const localInputs = this.inputs; + const spaceInputs = space.inputs; + + // Sanity check - ensure that the input distributions have the same length; + // if not, this shouldn't represent a SearchPath split! + if(localInputs.length != spaceInputs.length) { + return space.construct(parentMerge, space.inputs, space.inputSource); + } + + // Merge them! + const mergedInputs = localInputs?.map((entry, index) => { + return { + sample: buildMergedTransform(entry.sample, spaceInputs[index].sample), + p: entry.p + } + }); + + // Now to re-merge the two halves. + return space.construct(this.parentNode, mergedInputs, this.inputSource); } else { // If the parent was a cluster, the cluster itself is the merge. return parentMerge;