Skip to content

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

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/attribution-followups-2
Oct 27, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/attribution-followups-2

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

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).

  • English.
    • The comma form is split in two. "According to …" and "Per …" read as before.
    • A sentence's "In … report from X," is skipped when the reader is spoken to after the comma ("you", "your"), or told what to do in a tool: a verb such as "filter", "open" or "see", followed by a small word ("filter by", "open the"). So these aren't read:
      • "In the report from Google Search Console, you can see…";
      • "In a report from Google Analytics, filter by channel".
    • A verb's word used as a noun is no instruction, so these are still read: "In a 2025 report by Gartner, most teams…", "…, open rates fell 8%", "…, use cases tripled", "…, add-on sales grew".
    • "X's report/study … shows" counts only before "that" or a figure, as the "report from X" pattern does. "The Search Console report shows clicks" and "GA4's Acquisition report shows where…" aren't read.
  • Turkish.
    • A kind of report's acronym (SEO, PDF, KPI, CRM, ERP) isn't a source, at a sentence's start or in it: "SEO raporuna göre", "Aylık SEO raporuna göre".
    • A list's number doesn't make a sentence's first noun read mid-sentence: ) is out of the lookbehind's class, so "1) Ürün açıklamasına göre" isn't read.
  • German.
    • "laut" skips "Angaben" ("Laut Angaben des Herstellers"), and the skipped nouns inside a compound: "Produktdatenblatt", "Packungsbeilage", "Kundenbewertungen". "Laut Bewertungsportal Trustpilot" is still read.
    • The giver of the figures is read through the "nach Angaben von" pattern, which now also takes "laut" and "des/der": "Laut Angaben von Statista", "Laut Angaben des Statistischen Bundesamtes".
    • "zufolge" skips a noun after an article with an adjective in between: "Einer neuen Studie zufolge", "Einer repräsentativen Umfrage zufolge". A verb's ending isn't read as an adjective's, so "Die Ausgaben sollen Gartner zufolge steigen" is still read.

4. The two side effects.

  • A name that is itself possessive goes whole: "According to McDonald's, sales rose" becomes "According to [source], sales rose". "According to Gartner's latest survey" and "…Gartner's 2025 survey" still keep "[source]'s".
  • "In most of the US states that…" isn't read: the count words take "of the".

5. The send's brand read (content-delivery.js).

  • brandFor selects the site type, industry and Shopping mode too, and gives the brand's kind of site. myRuleSets takes it, so the brand is read once.
  • An unread brand now gives no My rules set, never the B2B one.
  • New test: a brand with Shopping mode on gets the e-commerce set's language.

6. Long input (the guards that run on a Fix's or Start's changes, a page rewrite and the brief).

  • Letters joined by apostrophes (content-people.js): your two fixes. NAME never starts inside a word, an apostrophe's either ((?<!\p{L}|\p{L}['’])), and WORD's lookahead reads only what the word can hold.
  • An opening bracket with no closing one: /\[[^[\]]*\]/g in content-people.js and content-sources.js.
  • Thousands of edits on a line:
    • New edit-spans.js keeps the edits in order and checks a new one against its neighbours, found by a binary search. peopleEdits and attributionEdits use it.
      • An empty edit sorts before a non-empty one at the same start, so the span checked before a place is the one that can run past it.
      • Its test compares it with the old check against every edit, on 2,000 random edits. Separately, 200,000 more random edits over 20 seeds gave no mismatch.
    • editLines builds each text node once from its pieces.
    • placeholderNumbers builds 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:

  • "says/said";
  • "reports/notes/finds/estimates that";
  • "claims/states that";
  • "report/study … shows/finds/says";
  • "zufolge";
  • "göre" for the Turkish forms.

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:

Input main this branch
20,000 names, text 1,269 ms 25 ms
20,000 names, HTML 2,883 ms 45 ms
20,000 numbers 1,472 ms 8 ms
20,000 sources, HTML 3,220 ms 65 ms
a 400 KB line of capitalised words 161 ms 4 ms

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's attributedNames, placeholderAttributions, guardPeople and placeholderNumbers. 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 feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How 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

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/): no web change
  • yarn typecheck passes (run from web/): no web change
  • yarn format:check passes (run from web/): no web change
  • Changes are focused — one concern per PR

Server: npm run format, npm run lint, npm test (226 files, 2,914 tests) pass.

🤖 Generated with Claude Code

… 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 gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) and attributableSources;
    • guardPeople (text, heading, HTML);
    • addedNumbers and placeholderNumbers(InHtml).

    The strings:

    • every string and line in the content-* and edit-spans test 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 == start is 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.

    • free against 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: attributionEdits skips start >= 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) and htmlLines all 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 when turned 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, dropsName and htmlLines;
    • keepSuggestions, with an insert, a replace and a long after;
    • guardPeople (text, heading, HTML, a blockquote);
    • the number guard and the sources reader: numbersIn, knownNumbers, addedNumbers, placeholderNumbers(InHtml), stripSourceIds and sourceSuggestion.

    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).

    • brandFor now selects site_type and shopping_mode_enabled with the rest, and returns siteType. That is brandSiteType(brand), or null when the read gave no row.
    • myRuleSets takes siteType instead of reading the brand again, and returns no sets without it. A failed brand read now gives the brand's language, else en, 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:
      • contentPackage still 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.
  1. 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.
  2. 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. /\[[^[\]]*\]/g is in both files.
  • Dense edits. editSpans is used in peopleEdits and attributionEdits. editLines builds each text node once, and placeholderNumbers builds the text once.
  • Each has a speed test with a character past Latin-1.
  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):

  1. 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*(?:[,.;:!?]|$)/u on 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.
  2. editSpans.add inserts with splice (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 free checks that list's last edit and the kept spans' neighbours.
      • Then merge the two sorted lists once per pattern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants