Repository navigation
fix(shared): text cuts no longer leave half an emoji - #261
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
This branch was previously deployed
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.
.slice()counts UTF-16 units, so a cut that lands inside an emoji leaves half of it behind. In October that lone surrogate made a Codexturn/startline unparsable, and the CAD follow-up was dropped after a 30 second timeout. The fix went into one localclipinCadDrivetrain.ts. Every other cut in the repo still had the bug.What changed
clip(text, max, keep = "start")now lives inpackages/shared/src/String.tsand is the one way to cut text to a length. It returns at mostmaxunits, never half of a surrogate pair, and always well formed text.keep: "end"keeps the tail instead of the head.truncatestays as a second function and now callsclip. The two have different jobs:clipis the hard limit, andtruncateis the title cut that trims and appends "...". Other display cuts keep their own ellipsis and budget aroundclip, so their output is the same as before.51 call sites in 33 files now go through
clip: the 8 existing ones, plus every cut of text for a user, an agent or a wire payload in the server, web, desktop, shared and client-runtime. 8 of them are tail cuts such asslice(-8_000)in the title prompt, which can leave the other half of a pair.Behavior
No behavior change beyond the fix. A cut that used to land mid-pair now lands one unit earlier. Text that already carries a lone surrogate now leaves a cut with U+FFFD in its place.
clipkeeps whole code points, not whole graphemes. A cut can still land inside a ZWJ sequence or a flag.Left alone
packages/featurescript, which has no dependency on@cadsense/shared.Preview.ts:662still cuts an input's default value at 80 units withslice. The two conformance report cuts carry a lint disable that says why.scripts/andapps/server/scripts/.providerInstanceInitialspicksword[0]. That needs a first code point, not a length cut.innerTextinside the page, where the helper cannot be imported. The main process now clips the result.Lint rule
cadsense/no-slice-truncationreports aslice,substringorsubstrwritten right beside an ellipsis, in a template literal or a+. On main that shape matches 22 lines: 21 text cuts and 1 hex trace id, which keeps itssliceunder a disable comment.The rule cannot see a bare
name.slice(0, 120), the shape of the original bug. Without type information that is the same syntax as an array slice.Verification
String.test.tslists 17 ways a cut can fail, written before the helper, and tests them: a pair on the boundary, a lone surrogate already in the input, a max of 0, ZWJ sequences, negative, fractional and NaN limits.CodexFollowUpRuntime.integration.test.tsruns the October repro through the real path. A part name is padded so an emoji sits on the collision title's 160 unit cut, then goes throughdraftCadComments,followUpMessageand the realCodexSessionRuntimeto the rawturn/startline the mock app-server reads. The line has no lone surrogate escape. With the oldsliceput back, the test fails on a title that ends in half an emoji.\ud83dput back where the old cut ended, it fails withunexpected end of hex escape, the error from October.cadsense-follow-up-turn-start.jsonin the OS temp directory.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.