Repository navigation
feat(content): read the kind of a source's site the rules can't place with AI (CE-046, part b) - #1451
Conversation
…he weak ones (CE-046, part a) Quality phase 2 (NEXT_PUBLIC_CONTENT_QUALITY_PHASE=2), by rules only: - sourceClass(): primary (official, research, standards), secondary (news, reviews, Wikipedia), weak (forums, social posts, uploaded papers), a competitor's page (primary on a comparison) or the brand's own; an address the rules can't place is left out (an AI read comes in part b) - Trust's primarySources (15) and noWeakSources (10); two placed sources score Trust on their own - Quality suggests replacing weak sources (Show, Keep) and adding a primary one, once Trust is scored; the editor underlines weak sources in amber (a decoration: never exported) - 00263: content_drafts.kept_sources (≤ 50) and content_draft_keep_source() - byUrl keeps a link's first place, so Show goes there Co-Authored-By: Claude Opus 5.5 <[email protected]>
… with AI (CE-046, part b) Quality phase 2 (web NEXT_PUBLIC_CONTENT_QUALITY_PHASE and server CONTENT_QUALITY_PHASE at 2): - POST /api/content-pages/source-classes reads the sites a draft links (as saved) that the editor's rules can't place: the model sees each site's address alone and answers primary, secondary or weak; each read is kept for every workspace 90 days (00264 content_source_classes); 20 sites a read, 30 reads a draft a day, its own rate limit - the reads draw on the AI budget as their own feature, "quality" (00264 widens prompt_improve_usage.feature): a small hold (holdUsd), left out of the median that sizes other calls' holds and the Improve tab's estimate; a read cut off by its timeout keeps its hold; Billing lists it - the editor asks 3 s after a save (useSourceClasses), Trust takes the reads for sites the rules can't place, the weak-sources suggestion is tagged "AI check", and a spent budget pauses the reads with a note Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
left a comment
There was a problem hiding this comment.
A few fixes before merge:
-
Accept only plain public DNS names as sites, before they're asked about or kept (medium).
- Today
siteOf(server/src/lib/content-source-class.js:38) accepts any URL hostname.keptSite(:52), the route's schema (server/src/routes/content-pages.js:137) and the table's check (00264_content_source_classes.sql:26) only limit length, case and a leadingwww.. - A URL hostname can still contain punctuation (
,;("'…). IP literals and single-label names (localhost, an intranet name) pass too, and are then asked about and kept like any other site. - Fix: keep both to LDH names: letters, digits and hyphens per label, at least one dot, a letter TLD, no IP literal. For example:
/^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z][a-z0-9-]{0,61}[a-z0-9]$/
Punycode labels pass this. - Where to apply it:
- in
siteOf/keptSite, solinkedSitesdrops the rest; - in
unplacedSites(web/src/lib/content/quality-checks.ts:410), so the editor doesn't ask about them; - in the table's check, as the same regex in Postgres.
- in
- A host with a quote or parentheses also breaks the
.in('host', …)filter today. - It would also be worth making a site's read not depend on which other sites were asked with it, e.g. one site per call, or caching only reads from calls that asked about that one site.
- Today
-
A site the model doesn't know is still put in one of the three kinds, and that guess is kept for every workspace (low).
- The prompt says "A site you don't know, judge by its address" (
content-source-class.js:68). The guess is then kept for every workspace for 90 days. - Part a leaves an address it can't place out of Trust, so a guess here goes against that.
- Suggestion: add an
unknownanswer that Trust leaves out, kept for a day or not at all. - This also fixes a cost leak. Today a site the model leaves out or names differently is skipped (
:147), so it stays unread. It is then asked again after every save, as a charged call, up to 30 a day per draft.
- The prompt says "A site you don't know, judge by its address" (
-
Kept sources are still asked about (low). The description says the sites a person kept aren't asked about, but nothing on this path reads
kept_sources: notunplacedSites, not the route. Either skip a site once every link to it is kept, or drop that line from the description. -
A failed server action call leaves its sites stuck (low). In
_use-source-classes.ts:64, if theclassifyDraftSourcescall itself rejects (a network error, or a deploy in between), the.thennever runs. The sites stay inaskingfor the rest of the session, so they're never asked again, and the rejection is unhandled. Add a.catch, and clearaskingin a.finally. -
server/.env.example:72(low): say that phase 2 also turns on these AI source reads, and that they draw on the AI budget. It currently mentions only the site type.
What I checked and found fine:
content_source_classesis server-only: RLS is on with no policy, and anon and authenticated have no grants. In a dry run, a member's select was refused.- The route reads only the sites the caller's saved draft links, after the brand check.
- The cache keeps no workspace or draft id.
- Only the hosts go to the model.
- The reads are held and charged on the workspace's AI budget as
quality.reserve_ai_usageaccepted that feature in the dry run, and these rows stay out of the hold median for the other features. - An answer that misses the schema is charged and fails the request.
- The limits are 20 sites a read, 30 reads a draft a day, and a per-user limiter.
00264 dry-runs cleanly on prod after 00262 and 00263. Apply it before the server runs with CONTENT_QUALITY_PHASE=2.
…rce-classes-ai # Conflicts: # supabase/schema.sql # web/messages/en.json # web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx # web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_quality-tab.test.tsx # web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_quality-tab.tsx # web/src/lib/actions/content-drafts.test.ts # web/src/lib/content/quality-checks.test.ts # web/src/lib/content/quality-checks.ts # web/src/lib/content/source-class.ts # web/src/types/supabase.ts
…a day, and skip kept sources (CE-046, part b review) - SITE_NAME (LDH, a dot, a letter TLD; no IP, no single label) in keptSite/linkedSites, the editor's unplacedSites and 00264's check; a label that reads as words isn't asked about either - the model may answer unknown, which Trust leaves out; it, and a site the model left out, is kept a day, so it isn't asked again (and charged) after every save - a site whose every link the person kept isn't asked about (route and editor); a kept link counts in Trust with or without a read - a failed classifyDraftSources call lets its sites go (.catch/.finally) - .env.example: phase 2 turns the AI source reads on, from the AI budget Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rce-classes-ai # Conflicts: # supabase/schema.sql # web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx
…fter ansvisor#1435 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks. All five are done (a65598a). main is merged in: with #1450, using its head as the base, so only this PR's changes remain; then #1435 and #1452. The getImproveQuotaStatus test now sizes against Starter's $5 (#1435).
Checks: server |
gkhngyk
left a comment
There was a problem hiding this comment.
All five items are done, and neither merge of main changes anything else.
One fix before merge:
- Read each site in its own call, in this PR (medium).
server/src/lib/content-source-class.js:169still sends up to 20 sites in one call, and every workspace gets those reads.- The label check (
:72, andaskableSiteinweb/src/lib/content/source-class.ts:35) limits what one site's name can do to the reads of the sites asked with it. It doesn't rule that out, so the follow-up you offered should land here:- one
generateObjectper missing site, run in parallel (Promise.allSettled, so one failed site keeps the others' reads); - one hold per site, with a smaller
SOURCE_CLASS_HOLD_USD, since one site is about 200 tokens in; - the day's cap then counts sites. Size
SOURCE_READS_PER_DAYfor that, and keep it in step with #1457's sharedQUALITY_CALLS_PER_DAY.
- one
- The label check can stay as a cheap first filter.
00264 dry-runs cleanly on prod after 00262, 00263 and 00265. Apply it before the server runs with CONTENT_QUALITY_PHASE=2.
… per site (CE-046, part b review) One generateObject per site the rules can't place, run together with Promise.allSettled: no site's name reaches another's read, and a failed site keeps the others' reads. Each read holds $0.0005; the day's cap counts sites (SOURCE_READS_PER_DAY = 40). An answer off the schema is charged and kept as unknown for a day. The route logs an error's name and message only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d log no whole error (CE-046, part b review) When no site is read, the error thrown is a spent budget's if any (429, the editor pauses) rather than the first site's. An ask reads its sites five at a time, so 20 holds and their queries don't go out at once. A site's hold is $0.001 (the model's thinking is billed as output). The route's error log keeps the stack, not the provider's request. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks. Each site now has its own call (68490db + e70a269):
Server: |
gkhngyk
left a comment
There was a problem hiding this comment.
All items done.
- One call per site: each site the rules can't place gets its own
generateObjectcall, with the promptSite: x(server/src/lib/content-source-class.js:128-155). Five run at once. - One hold per site: each call holds $0.001.
- The day's cap counts sites: each read is one
qualityrow, androomlimits how many sites are read (:202-206).limitedis set when the cap leaves some out. - Failures: a failed site is left out, and the other sites' reads are kept. When no site is read, a spent budget's 429 is thrown before any other error (
:234). - Logs: the route (
server/src/routes/content-pages.js:186-190) and the module log only the error's name, message and stack.
Looks good.
00264 hasn't changed, and it dry-runs cleanly on prod after 00267 and 00268. Apply it before the server runs with CONTENT_QUALITY_PHASE=2.
Summary
Quality Phase 2, CE-046 "Source classification", part b: an AI read for the sites the rules can't place. Stacked on #1450 (part a); review that first. The server's phase flag
CONTENT_QUALITY_PHASEcomes from #1449, and the file is identical here. Everything sits behind phase 2 (webNEXT_PUBLIC_CONTENT_QUALITY_PHASE=2, serverCONTENT_QUALITY_PHASE=2). At phase 1, nothing changes.Server
POST /api/content-pages/source-classesreads the sites a draft links (as saved) that part a's rules leave asnull.primary,secondaryorweak.kept_sources) aren't asked about.qualityCheckLimiter).content_source_classes: each read is kept for 90 days and shared by every workspace. A public website's kind isn't any workspace's own data, and one read serves them all. The table is server-only (noanon/authenticatedgrants).quality. 00264 widensprompt_improve_usage.featureto allow it.reserveAiBudgettakes a fixed small hold (holdUsd, 0.002) instead of the median.holdCostUsdandimproveSpendThisPeriodleavequalityrows out of their median, so these tiny calls don't shrink the hold for the Content Agent's larger calls or the Improve estimate.QUALITY_CHECK_MODEL(documented in.env.example), falling back toDEFAULT_SUGGESTION_MODEL, thengoogle/gemini-3-flash-preview.Web
useSourceClassesasks 3 s after a save, only for sites not yet read and not already being asked about.Related issue
Quality spec (Drive), Phase 2, CE-046 (part b). Stacked on #1450 (part a), which follows #1449 (CE-056).
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
NEXT_PUBLIC_CONTENT_QUALITY_PHASE=2inweb/.env.localandCONTENT_QUALITY_PHASE=2inserver/.env. Restart both servers.select * from content_source_classesshows the host (no path) and its kind. Saving again doesn't ask about it again.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)00264 is applied on the dev DB and
schema.sqlis rebuilt.npm run lintand Prettier pass. The fullnpm testrun had one failure (content-runs.test.js: its Supabase mock lacked.or()for the new median filter); with the mock fixed, that file and the new ones pass.I haven't checked it in the browser in both themes yet; it goes into the next local test session, with screenshots.
🤖 Generated with Claude Code