diff --git a/.changeset/fix-redos.md b/.changeset/fix-redos.md deleted file mode 100644 index 6c518dc..0000000 --- a/.changeset/fix-redos.md +++ /dev/null @@ -1,29 +0,0 @@ ---- -"@intentface/chat": patch ---- - -Fix two quadratic-backtracking regexes that could hang the browser. - -`parseChipSegments` is the serious one, because message text is untrusted — it -arrives from the model. The chip token pattern had two independent blowups. A long -run of `[` with no closing bracket made the label group consume to end-of-string, -fail, backtrack over every position, advance one character and repeat: 355ms at -32k characters. Worse, `[a](chip:x:` repeated with no `)` anywhere did the same -through the value group from many start positions at once: 264ms at 88k -characters. Both grow quadratically, so a large message could hang a tab for -seconds. - -Every character class now excludes `[`, so no group can consume past the next -one and the work per start position is bounded by the gap to it. Safe for -anything `encodeChipMarkdown` produces — values are `encodeURIComponent`-escaped, -queries come from `URLSearchParams`, prefixes are short identifiers — and labels -containing raw brackets never parsed under the previous pattern either. - -`detectActivePrefix` had the same shape via `/\S*$/`, which retries from every -position when the text ends in whitespace. It runs on every keystroke, so pasting -a large single-token blob froze the editor — 16 seconds for a 200k-character run. -Replaced with a backwards index scan, which is linear, allocation-free, and -returns identical results. - -Both are covered by regression tests asserting a time budget that the previous -implementations exceeded by two orders of magnitude. diff --git a/packages/chat/CHANGELOG.md b/packages/chat/CHANGELOG.md index 3864c5d..3ea6d43 100644 --- a/packages/chat/CHANGELOG.md +++ b/packages/chat/CHANGELOG.md @@ -1,5 +1,35 @@ # @intentface/chat +## 0.1.1 + +### Patch Changes + +- [#58](https://github.com/Intentface/intentface-chat/pull/58) [`9f74772`](https://github.com/Intentface/intentface-chat/commit/9f747721d26299de9a15f7983e875ec9c8df3ad3) Thanks [@rpvilo](https://github.com/rpvilo)! - Fix two quadratic-backtracking regexes that could hang the browser. + + `parseChipSegments` is the serious one, because message text is untrusted — it + arrives from the model. The chip token pattern had two independent blowups. A long + run of `[` with no closing bracket made the label group consume to end-of-string, + fail, backtrack over every position, advance one character and repeat: 355ms at + 32k characters. Worse, `[a](chip:x:` repeated with no `)` anywhere did the same + through the value group from many start positions at once: 264ms at 88k + characters. Both grow quadratically, so a large message could hang a tab for + seconds. + + Every character class now excludes `[`, so no group can consume past the next + one and the work per start position is bounded by the gap to it. Safe for + anything `encodeChipMarkdown` produces — values are `encodeURIComponent`-escaped, + queries come from `URLSearchParams`, prefixes are short identifiers — and labels + containing raw brackets never parsed under the previous pattern either. + + `detectActivePrefix` had the same shape via `/\S*$/`, which retries from every + position when the text ends in whitespace. It runs on every keystroke, so pasting + a large single-token blob froze the editor — 16 seconds for a 200k-character run. + Replaced with a backwards index scan, which is linear, allocation-free, and + returns identical results. + + Both are covered by regression tests asserting a time budget that the previous + implementations exceeded by two orders of magnitude. + ## 0.1.0 ### Minor Changes diff --git a/packages/chat/package.json b/packages/chat/package.json index 2559e7b..3006a0e 100644 --- a/packages/chat/package.json +++ b/packages/chat/package.json @@ -1,6 +1,6 @@ { "name": "@intentface/chat", - "version": "0.1.0", + "version": "0.1.1", "description": "Headless chat UI primitives — unstyled compound components, hooks, and wire formats for building AI chat interfaces.", "license": "MIT", "type": "module",