Repository navigation
feat(content): read and keep the brief's version 2 through Edit brief (brief rules PR 3) - #1539
Merged
Merged
Conversation
…d facts per section; TL;DR, angle, proof, fan-outs left out, freshness, names and links per page), and keep them through Edit brief (brief rules PR 3) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…kind and ref, keep http(s) links only, refuse a brief past 64 KB, and never let Edit write over a brief it can't read (pre-push review) Co-Authored-By: Claude Opus 5.5 <[email protected]>
4 of 12 tasks
gkhngyk
approved these changes
Oct 26, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Looks good, with follow-ups to fix before PR 4 writes version 2.
What I checked:
- Today's briefs.
- Version 1's rules are unchanged; the diff only adds fields.
- Every version 2 field is optional both ways: absent when read, absent when saved. In zod 4.4,
preprocessandcatchcount as optional for an absent key, and an absent optional key stays out of the result. - So a version 1 brief reads as the same object, and Edit brief writes the same JSON as before. The tests check
versionandfactsstay undefined. - Only two things write
content_drafts.briefon main: the server's rebuild and Edit brief. The rebuild cuts to the version 1 limits (BRIEF_LIMITS,mapOutline).citedLengthstays within its range (at most 500,000 characters and 5 pages). - So no stored brief should start failing to read under the new
getDraftBrief.
- Edit brief.
({ points, ...s })keeps a section'sanswer,formatandfacts, and leaves out the editor's ownpoints.headingandkeyPointsare replaced as before....briefkeeps the page-level fields. New sections are as before.- These fields stay with their section when its heading is rewritten, as
fanoutandplatformdo. Nothing shows them until PR 9, so keepCONTENT_BRIEF_RULESoff until then.
- Not trusted.
saveDraftBriefparses what the browser sends again, with the same kinds and limits, so a changed request gets no further than the editor's own read.- Keys the schema doesn't know are still dropped on read and on save. A later
versionsaves as none. That's fine while the web ships first: it goes out on merge, and the API is deployed by hand later.
- Nothing rendered unsafely.
- Nothing new renders in this PR. Links are http(s) only (
z.url({ protocol })), andjavascript:andftp:are dropped, with tests. - A fact's source
refisn't checked as an address. Today the suggestion chips never use a ref as a link. PR 9 should keep it that way, or check http(s) first. getDraftBrieflogs zod's issues, which leave the input out, so no brief text goes to the logs.
- Nothing new renders in this PR. Links are http(s) only (
- Size.
too_longis checked withjsonbBytes, which measures text the way Postgres writes jsonb. That's what 00212'soctet_length(brief::text) <= 65536checks. It runs before the write, and the test checks nothing is written. - A brief of the draft's own that can't be read is now a failed read. It no longer falls back to the opportunity's brief, so Edit brief can't write over it.
- Merge state. Built on 4085418, no migration. It merges cleanly on main as it is now (38ca76b, with #1514–#1519). None of those touches the brief. CI passes; its web job runs format, lint and typecheck only.
- Before the API is deployed:
- Nothing writes version 2 yet.
- A version 1 brief reads, shows and saves as today.
- A brief past 64 KB is refused before the write, with the same toast as today (item 1).
- Nothing that works today stops working.
Low, follow-up (please fix before PR 4 writes version 2):
_brief-tab.tsx:389andcontent-drafts.ts:2155:- In a production build, an error thrown from a server action reaches the browser with React's generic message and a digest, not
too_long. - So on prod the person still sees "Couldn't save the brief. Try again.", and trying again can't help. The test passes only because it mocks the action.
- Fix: check the size in Edit brief before calling, as
_use-draft-rules.ts:237does withdraftRulesFit(jsonbBytesruns in the browser too), and keep the server's check as the guard. Or return{ error: 'too_long' }from the action, asrebuildDraftBriefdoes.
- In a production build, an error thrown from a server action reaches the browser with React's generic message and a digest, not
brief.ts:196-197:- A fact's source label is held to 300 characters, through
claim's limit, andBRIEF_V2_LIMITShas no key of its own for it. The PR says a fact keeps its source as a suggestion does. - A suggestion's label is a prompt's text (up to 500 characters) or a cited page's address (up to 2,048) (
server/src/lib/content-sources.js:67,:74). - Such a fact fails as a whole, so it's left out on read, and the next Edit brief saves the brief without it.
- The same holds inside every list item: a long claim, proof, left-out query, name, anchor or link section drops its item, while top-level text is cut.
- Fix: give the source its own limits in
BRIEF_V2_LIMITS(sourceRef,sourceLabel), so PR 4's test reads them. Cut text inside items asv2textdoes, so length never drops an item.
- A fact's source label is held to 300 characters, through
brief.ts:149-163:- These still fail the whole brief:
facts: null,proof: nullorleftOut: null, or ananswer,tldroranglethat isn't a string. - With this PR's
getDraftBrief, that's a failed read with only Retry (_brief-tab.tsx:98): no Edit brief and no Rebuild, so the person can't get past it. - Fix: read null as none, and add
.catch(undefined)tov2textandv2list, so only version 1's fields can fail the read. A test with{ ...v2, proof: null }and a section withfacts: nullwould hold it.
- These still fail the whole brief:
- For PR 4, the limits add up to far more than the column holds:
- Version 1 at its limits is about 60 KB of ASCII.
- Version 2's per-field limits allow roughly 180 KB more. Four facts per section with 2,048-character refs come to about 130 KB on their own.
- Edit brief is guarded now; the rebuild's write isn't. A brief past 64 KB fails 00212's check after the model call has been charged.
- Fix: trim the brief to fit (
jsonbBytes≤ 65,536, for example dropping facts and links from the end) before the write.
7 of 12 tasks
This was referenced Oct 26, 2026
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.
Summary
Brief rules 2026, PR 3 of 10: the editor reads and keeps the brief's version 2. Web only, cut from
main, no migration.The server's brief gains the 2026 rules in PR 4–6, behind
CONTENT_BRIEF_RULES. That brief must still read in the editor, and Edit brief must not drop what it doesn't show. Two things stand in the way today:draftBriefSchemais a plainz.object, which drops any field it doesn't know;So this PR ships first, and only reads and keeps the new fields. The Brief tab shows them in PR 9.
web/src/lib/content/brief.ts: version 2's fields, each optional, so a brief from before them reads as it was.answer: a note on what the section's first, direct answer must say;format:paragraphs,list,steps,tableorfaq(a "faq" section's key points are its questions);facts: up to 4, each a claim, the kind of source it needs (statistic,study,quote,example,official) and the source it was given. The source is kept by kind and ref, with its name, as a suggestion keeps its own (00248), never by its number in one run (S1…), which changes as Sources change.version: 2,tldr,angle;proof: the brand's own proof to gather, as Your input takes it (experience, data, a case, a test, a quote). Whether Your input has it is read from Your input when shown, not stored: it changes after a rebuild;leftOut: fan-outs kept for another page;freshness: a dated point, an "Updated" line, the year in the title;entities: the brand, its products and the competitors, as written;links: internal up to 8, outbound up to 5, http(s) addresses only.BRIEF_V2_LIMITSholds the limits.getDraftBrief: a brief of the draft's own that can't be read is said as a failed read. It no longer falls back to the opportunity's brief or none, so Edit brief, which shows on a read brief only, can't write over it.saveDraftBrief: a brief past the column's 64 KB (00212) is refused astoo_longbefore writing, and Edit brief says so.__fixtures__/brief-v2.json: a sample version 2 brief. PR 4's server test reads this same file, and the limits and kinds frombrief.ts, ascontent-page-types.test.jsreads the web's files. There's no copy to drift._brief-tab.tsx: Edit brief keeps each section's other fields (...section), and with...briefthe page's too, as before.The contract is written into the plan for PR 4–6.
Related issue
Roadmap CE-EVAL-001 / brief rules 2026 (no GitHub issue).
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 web && yarn vitest run src/lib/content/brief.test.ts "src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_brief-tab.test.tsx".content_drafts.briefon a dev database, opens in the Brief tab, and Edit brief → Save brief keeps them.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/): 0 errors; the 6 warnings are in files this PR doesn't touchyarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Web:
yarn test(3,964 passed) andyarn build.Tests:
getDraftBriefreads version 2 and says an unreadable brief of the draft's own as a failed read;saveDraftBriefkeeps version 2 as the person's, and refuses past 64 KB;too_long.A pre-push review ran; its findings are in the second commit (tolerant reading, kept sources, http(s) links, the 64 KB check,
proofwithouthave, nullish text).🤖 Generated with Claude Code