Repository navigation
fix(content): read no tool's report, report acronym or maker's German as a source, and read long input in linear time (#1544 review follow-ups) - #1563
Conversation
… as a source, read the brand once for a send, and read long input in linear time (ansvisor#1544 review follow-ups) Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good, with follow-ups. #1544's items 3–7 are all done. The three slow paths now read in linear time on everything I tried up to 200 KB, and so do the new patterns. The sentences that read differently are the ones you meant, plus a few small misses listed in item 8. Those, and item 9, can go in a follow-up.
What I checked:
-
Scope and merge.
- It's one commit on 3b650fb, which is also the merge-base, so it's a fast-forward there.
- Main has since moved to 6f0c49f (#1551, #1557–#1560, #1566). It still merges clean, and the merged tree differs from main by exactly this PR's 10 server files.
- There's no migration and no web change. Nothing changes on Vercel at merge; the guards and the send change with the next API deploy.
- CI is green.
-
Behaviour. I read about 6,000 strings with main and with this head, in English, Turkish and German, through:
attributedNames,placeholderAttributions(InHtml)andattributableSources;guardPeople(text, heading, HTML);addedNumbersandplaceholderNumbers(InHtml).
The strings:
- every string and line in the
content-*andedit-spanstest files, main's and this head's; - round 33's and 35's sentences;
- about 180 of mine on this PR's forms:
- the tool-report gate, "shows", the possessive name, "of the";
- the Turkish acronyms and list numbers;
- the German "laut", "Angaben" and adjectives;
- apostrophe names, brackets, and numbers next to each other.
What changed is listed under items 3, 4 and 8. Everything else reads as on main, apart from text inside nested brackets: "[a 40 [b]" now reads the 40, as you said.
-
The edit machinery.
-
edit-spans.js, by reading. These all give the same answers as the old check against every edit:- the order (by start, then end);
- empty edits at one start;
- an overlap at either neighbour;
- adjacent spans:
end == startis free either way.
Only the previous neighbour can cover
start: kept spans are apart, and an empty span sorts before the one that shares its start. -
freeagainst main's check. I ran 5 shapes × 20 seeds × 10,000 random edits, 1,000,000 checks: no mismatch. The shapes were dense short spans, your test's, wide, many empty and long.- The kept edits come out in main's order, except that an empty edit now sorts before a non-empty one at its start.
- No guard makes an empty edit:
attributionEditsskipsstart >= end, and a quote or a name is never empty. So no output changes.
-
Random texts. I built 6,000 random texts from tokens the regex changes don't touch: names, quotes, cues, sources, numbers, units, placeholders, spaces, non-breaking spaces and a letter past Latin-1. Each also went in as HTML, with inline tags cut in at random places, mid-name too.
guardPeople,guardPeopleInHtml,placeholderAttributions(InHtml),placeholderNumbers(InHtml)andhtmlLinesall give main's output.
-
placeholderNumbers. On 300,000 random strings of digits, signs, units and spaces, with and without known numbers, it gives main's output, "40 %50" included. -
Trigger words (item 7). With
whenturned off, the 6,000 strings read the same. Each trigger is a word its pattern must match.
-
-
Speed. I timed every public reader on 100 KB and 200 KB inputs, as Latin-1 text and with a character past Latin-1.
The readers:
attributedNames,addsAttribution,placeholderAttributions(InHtml),attributableSources,dropsNameandhtmlLines;keepSuggestions, with an insert, a replace and a longafter;guardPeople(text, heading, HTML, a blockquote);- the number guard and the sources reader:
numbersIn,knownNumbers,addedNumbers,placeholderNumbers(InHtml),stripSourceIdsandsourceSuggestion.
The inputs were round 33's and 35's, about 220, and about 110 more:
- each apostrophe shape, alone and after each people cue ("Dr.", "CEO", "our customer", ", says", a quote, "Sarah, our…", the Turkish role);
- unclosed and nested brackets, alone and with numbers, names or sources inside;
- dense names, quotes, sources, possessive names, numbers, percents (written before and after), currencies and units;
- the tool-report gate, with runs of spaces, non-breaking spaces and verbs;
- the Turkish acronyms and list numbers;
- the German compounds, "Angaben" and adjectives, and "of the";
- runs of capitals before each trigger word, and with every trigger word in the line.
The results:
- Every case grows linearly: 200 KB takes about twice as long as 100 KB. The slowest case of each reader does the same on Node 20.
- Main's slow cases are gone: the apostrophe runs, an unclosed bracket, and thousands of edits on one line.
- The slowest input is still a line of capitalised words that holds every trigger word. It's linear, and it reads as on main.
-
The send's brand read (item 5).
brandFornow selectssite_typeandshopping_mode_enabledwith the rest, and returnssiteType. That isbrandSiteType(brand), or null when the read gave no row.myRuleSetstakessiteTypeinstead of reading the brand again, and returns no sets without it. A failed brand read now gives the brand's language, elseen, never the B2B set.- The send reads the brand, then My rules. Before, it ran them side by side, with a second brand read inside My rules, so the number of round trips is the same.
- The rest of the send is unchanged:
contentPackagestill sends only the brand's id, name, domain and industry, so the webhook body is the same.- The Webflow send doesn't read the brand.
- Each page's language is read as before, through
rulesLanguage(rules, brand.language).
- The new test covers Shopping mode and an unread brand, and counts one brand read.
Round 33 (#1544's first review):
3. Product and tool sentences. Done.
- English.
- "In the report from Google Search Console, you can see…", "In a report from Google Analytics, filter by channel" and "…, open the Acquisition tab" aren't read.
- "…, open rates fell 8%", "…, use cases tripled", "…, add-on sales grew" and "…, set-up costs rose" still are.
- "According to …" and "Per …" are read whatever follows. "The Search Console report shows clicks" and "GA4's Acquisition report shows where…" aren't read.
- One side effect, as you'd expect: "Gartner's research shows teams forecast." isn't read now either, only "…shows that…" or a figure is.
- Turkish. "SEO/PDF/KPI raporuna göre", "CRM/ERP verilerine göre", "Aylık SEO raporuna göre" and "1) Ürün açıklamasına göre" aren't read. "TÜİK raporuna göre" and "Bu yıl Gartner raporuna göre" still are.
- German.
- "Laut Angaben des Herstellers", "Laut Produktdatenblatt", "Laut Packungsbeilage" and "Laut Kundenbewertungen" aren't read.
- "Laut Angaben von Statista", "Laut/Nach Angaben des Statistischen Bundesamtes" and "Nach Angaben der Bundesbank" read the giver. Main read "Angaben" after "Laut", and nothing after "Nach".
- "Einer neuen Studie zufolge", "Dem neuen Bericht zufolge" and "Einem internen Papier zufolge" aren't read, and "Die Ausgaben sollen Gartner zufolge" still is.
- The two side effects. Done.
- "According to McDonald's, sales rose" becomes "According to [source], sales rose", and "…Gartner's latest/2025 survey" keeps "[source]'s".
- "(In) most/many of the US states that…" isn't read.
- The tests and the send's brand read. Done, as above.
Round 35 (#1544's approval):
6. Bound the work on three more kinds of long input. Done.
- Apostrophes. Both fixes are in, as written. "'Jane Doe said…" and "Bob O'Neil said…" are still read.
- Brackets.
/\[[^[\]]*\]/gis in both files. - Dense edits.
editSpansis used inpeopleEditsandattributionEdits.editLinesbuilds each text node once, andplaceholderNumbersbuilds the text once. - Each has a speed test with a character past Latin-1.
- Name-first patterns only with their trigger word. Done. A line of capitalised words with none of them skips those patterns.
Follow-ups (low):
-
A few sentences the new gates now miss. None of these hurts much, so a follow-up is fine.
-
The reader spoken to (
content-agent.js:394,:495). "you"/"your" after the comma also skips a real claim:- "In a 2025 survey by Gartner, your peers said budgets grew 40%."
- "In a 2025 survey by Gartner, you will find that 40% of teams plan."
A verb that starts a clause skips it too: "…, set in 2024, costs rose 30%", "…, go to market spend rose 30%".
Fix: keep the gate only when no figure follows in the sentence, e.g.
(?!\s*${TO_READER}(?![^.!?]*\p{N})).- Then "you can see which queries bring clicks" and "filter by channel" still aren't read, and both sentences above are.
- The cost is that "…, you can see 1,200 clicks" is read again.
-
The possessive look-ahead (
:676). It reads only 3 characters and wants a letter or digit, so "'s" goes when anything else follows it:- "According to Gartner's (2025) survey" becomes "According to [source] (2025) survey", and "Gartner's “latest” survey" becomes "[source] “latest” survey";
- three spaces before the next word do the same.
Fix: read the name as one that is itself possessive only when punctuation or the end follows:
/^\s*(?:[,.;:!?]|$)/uon a short slice. -
Turkish
)(:523). A parenthesis mid-sentence counts as a list number now: "Pazar (bu yıl) Gartner raporuna göre büyüyor" and "Bu (2025) Gartner raporuna göre…" aren't read.Fix: let
)through after a word, e.g.(?<=[^\s.!?:)]\s+|\p{L}{2,}\)\s+). "(bu yıl) Gartner…" is then read, and "1)", "12)" and "a)" still aren't. -
German.
- A modal verb after a pronoun reads as an adjective (
:461): "Das werden Gartner zufolge mehr" and "Die dürften IDC zufolge steigen" aren't read. - The compound match skips a named platform's reviews: "Laut Trustpilot-Bewertungen". It's rare; I'd leave it.
- A modal verb after a pronoun reads as an adjective (
-
-
editSpans.addinserts withsplice(edit-spans.js:50). This one is optional.- Each insert moves the spans after it. So when a later pattern's edits fall between an earlier one's, the time grows with the square of their count. In
peopleEdits, that's a quote, then its speaker ("“…,” said Jane Doe."). - It's far from today's input sizes:
- a 200 KB line holds about 7,000 such pairs, and adds them in a few milliseconds;
- it starts to show at about 14,000 pairs in one line, about 420 KB.
- Fix, if you want it bounded:
- Keep each pattern's new edits in a list of their own. A pattern's matches come in order, so
freechecks that list's last edit and the kept spans' neighbours. - Then merge the two sorted lists once per pattern.
- Keep each pattern's new edits in a list of their own. A pattern's matches come in order, so
- Each insert moves the spans after it. So when a later pattern's edits fall between an earlier one's, the time grows with the square of their count. In
Summary
The follow-ups from #1544's reviews: round 33's items 3–5 and the approval's items 6–7. Server only.
3. Product and tool sentences (
content-agent.js).)is out of the lookbehind's class, so "1) Ürün açıklamasına göre" isn't read.4. The two side effects.
5. The send's brand read (
content-delivery.js).brandForselects the site type, industry and Shopping mode too, and gives the brand's kind of site.myRuleSetstakes it, so the brand is read once.6. Long input (the guards that run on a Fix's or Start's changes, a page rewrite and the brief).
content-people.js): your two fixes.NAMEnever starts inside a word, an apostrophe's either ((?<!\p{L}|\p{L}['’])), andWORD's lookahead reads only what the word can hold./\[[^[\]]*\]/gincontent-people.jsandcontent-sources.js.edit-spans.jskeeps the edits in order and checks a new one against its neighbours, found by a binary search.peopleEditsandattributionEditsuse it.editLinesbuilds each text node once from its pieces.placeholderNumbersbuilds the text once, left to right, reading the unit with a sticky regex instead of slicing. A unit that would run into the next number's sign is left to that number, as the old right-to-left code did, so "40 %50" keeps its space.7. Name-first patterns run only with their trigger word in the text:
A line with none of these skips them.
Speed tests. Each new kind of input has one, with a character past Latin-1 and a budget. Measured on this Mac, main → this branch:
Each test fails with its fix undone. I checked every item 3–7 change that way; the edit-list check needed the budgets tightened to 150 / 300 ms before it failed.
Same reading otherwise. I read the 1,146 string literals in the 20
content-*test files through main's and this branch'sattributedNames,placeholderAttributions,guardPeopleandplaceholderNumbers. The only differences are the new test sentences above, and nested brackets: a[inside an open[…is now its own start, as you expected.Related issue
Follow-ups to #1544 (round 33 items 3–5, approval items 6–7).
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
cd server && npx vitest run src/lib/content-agent.test.js src/lib/content-people.test.js src/lib/content-sources.test.js src/lib/content-delivery.test.js. The new cases are under "attributions as the review of #1544 read them" and "long input read quickly (#1544 review)".Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/): no web changeyarn typecheckpasses (run fromweb/): no web changeyarn format:checkpasses (run fromweb/): no web changeServer:
npm run format,npm run lint,npm test(226 files, 2,914 tests) pass.🤖 Generated with Claude Code