docs: document breakableFitAdvances cache invariant#139
Open
shaun0927 wants to merge 1 commit intochenglou:mainfrom
Open
docs: document breakableFitAdvances cache invariant#139shaun0927 wants to merge 1 commit intochenglou:mainfrom
shaun0927 wants to merge 1 commit intochenglou:mainfrom
Conversation
The cache check in getSegmentBreakableFitAdvances returns the stored result without consulting the mode parameter. This is safe because the current call sites guarantee mode is determined by isNumericRunSegment (text-deterministic) and the session-invariant engine profile, so the same segment text always arrives with the same mode. Add a comment explaining this invariant so future callers know the constraint. No behavior change.
aculich
added a commit
to aculich/pretext
that referenced
this pull request
Apr 21, 2026
Log pretext-upstream-rhythm session in WORKFLOW (merge f201433, checks, triage wave chenglou#139/chenglou#132, fork scan). Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #137
Problem
getSegmentBreakableFitAdvances()accepts amode: BreakableFitModeparameter but the cache at line 203 returns the stored result without checking whether the mode matches. If a future caller requested the same segment text with a different mode, the cache would silently return the wrong advances.Why the cache is safe today
The mode is fully determined by two things that are constant for a given segment text within a session:
isNumericRunSegment(text)— pure text predicate, always returns the same result for the same string → forcespair-contextengineProfile.preferPrefixWidthsForBreakableRuns— detected once fromnavigator.userAgent, invariant for the session → forcessegment-prefixessum-graphemesSo the same segment text always arrives with the same mode, and the mode-agnostic cache never returns a mismatched result.
Change
Added a 5-line comment above the cache check explaining the invariant and the consequence of breaking it. No behavior change, no public API change. All 84 tests pass.
Test plan
bun test src/layout.test.ts— 84 pass, 0 fail