refactor(web): extract buildAndMapPredictions as new prediction-helper 🚂#15781
Conversation
User Test ResultsTest specification and instructions User tests are not required |
| */ | ||
| rootCost *= ModelCompositor.SINGLE_CHAR_KEY_PROB_EXPONENT; // note the `Math.exp` below. | ||
| if(match.node.editCount > 0 && !searchModules.find(s => s.correctionsEnabled)) { | ||
| continue; |
There was a problem hiding this comment.
This is all we need to enforce a "disabled corrections" state - we actually don't need an entirely separate control flow / code block.
3802382 to
0e33686
Compare
Build-bot: skip build:web Test-bot: skip
7163830 to
04e6479
Compare
| // Only set 'best correction' cost when a correction ACTUALLY YIELDS predictions. | ||
| if(predictions.length > 0 && bestCorrectionCost === undefined) { | ||
| bestCorrectionCost = rootCost; | ||
| bestCorrectionCost = predictions[0].correction.p; |
There was a problem hiding this comment.
from devin.ai:
bestCorrectionCost stores a probability instead of a cost, breaking early search termination
The old code set bestCorrectionCost = rootCost where rootCost was match.totalCost (a log-space cost value, e.g. 0–20+). The new code sets bestCorrectionCost = predictions[0].correction.p, which is Math.exp(-rootCost) — a probability in the range (0, 1]. However, shouldStopSearchingEarly at predict-helpers.ts:594 compares this against match.totalCost (a cost) plus CORRECTION_SEARCH_THRESHOLDS (8 or 4). Since bestCorrectionCost is now always ≤ 1 instead of being a cost in the same domain, the effective stop threshold becomes ~8 regardless of the first match's actual cost. For example, when the first viable correction has cost 5, the old code would stop at cost 13 (5+8), but the new code stops at ~8.007 (exp(-5)+8), terminating the search much too early and potentially missing better predictions.
| bestCorrectionCost = predictions[0].correction.p; | |
| bestCorrectionCost = match.totalCost; |
While addressing support for corrections and predictions under whitespace fat-fingering scenarios, I came to recognize a helper that would be needed... that was previously written in two separate sections within the
correctAndEnumeratehelper function. Fortunately, the two sections are actually possible to condense into just one with a little effort, simplifying the code a bit in the process.Build-bot: skip build:web
Test-bot: skip