Repository navigation
fix(content): tell a Fix run or hand-off how far past its Length the page is when it isn't asked to shorten it - #1552
Merged
Conversation
…page is when it isn't asked to shorten it, so what it adds stays short Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
approved these changes
Oct 26, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Looks good, with follow-ups.
What I checked:
-
Before the API deploy.
- The fix and hand-off routes parse with
fixRulesInput.extend({ brandId })andhandOffInput.extend({ brandId })(server/src/routes/content-drafts.js:208,:246, the same on main). - Both are plain
z.objects (zod 4.3), which strip unknown keys. None of the three files has had.strict()orstrictObjectsince the routes came in (#1304, #1481). - So an older API drops
overLengthand runs as it does today: no 400, and the same prompt. I parsed both bodies with the field using zod 4.3.6, and each passed without it. - What users see between merge and the API deploy: no change, and no error. Until then, Fix on a held Length keeps adding full sections, as in your live test.
- A new API with an older web gets no field and adds no line.
- The fix and hand-off routes parse with
-
overLengthFor(web/src/lib/content/rules.ts:825-835).- The count is the Length status's
page.characters.useDraftRulesreads it from the toolbar'scharacterCount.characters(), so it's #1521's one count. - The max is
lengthBand(n).max, the band's top as the rules read it: 1,000 gives 1,200, and 13,998 gives 16,798. - When it's undefined: with Length off (
rule.on), within its band or short (code !== 'long'), and when Length is among the rules sent. - Units and types. Length has one unit, characters; words are only shown beside it. Every page type has a Length (
lengthTarget, 3,000 by default), so no type goes without one. - What each run sends.
- Fix open rules passes
open, what's left afterheldandNOT_FOR_AGENT. So the field goes with a held Length, and with Remove AI traces' own Fix, the only caller withonly. - A hand-off passes
[], so the field goes whenever the page is past its Length.
- Fix open rules passes
- A locked passage counts in the page, as the toolbar counts it. That's right, since the line asks the agent to add little, not to cut.
- One edge is item 1.
- The count is the Length status's
-
The server.
overLengthis validated as two integers: a count of 0–10,000,000 and a max of 1–10,000,000. They reach the prompt only astoLocaleString('en-US')of those integers, so no text from the sender gets in.- The line is said only when
count > max. With no field (an older web),overLengthLinereturns''and the prompt is main's, byte for byte. - The hand-off takes it through
handOffInput(fixRulesInputwithoutrules), with the same bounds.handOffDraftpasses it on to the samebuildFixPrompt. - Prompt only. There's no new check, so nothing is dropped for length.
- "no section, list, table or example a rule doesn't ask for" leaves out what a rule asks for: an FAQ, a fan-out H2, a specs table, a summary.
- "unless the rule needs words added" covers keywords, figures and names, and also a disclosure or a balance paragraph.
- The worst case is shorter answers, which the person reviews. One or two sentences still clears the 40-character least answer under a heading.
-
AI budget. No new call. The line adds about 100 tokens to the one prompt, held and charged by the run's one
reserveAiBudget. -
Speed. No new regex, and no loop on the page's text.
overLengthForreads the rules list once (about 25 rules), and the server formats two numbers. -
Tests. Each new test fails without the change:
overLengthForis new;- the prompt line, the parse and the two refusals need the schema and
overLengthLine; - the hand-off test needs both the schema and
handOffDraft's pass-through; - the two action tests need the field in the body.
The editor's two calls aren't covered (item 2).
-
Merge.
- One commit on main (c58edb8).
git merge-treewith main gives the PR's own tree. No migration. - It conflicts with #1550 in
fixRules(_draft-editor.tsx:2343-2347), where #1550 adds arguments to the samerunAgentFixcall. Whichever merges second keeps both:The hand-off's change merges on its own. It merges clean with #1544, #1549 and #1551.const overLength = overLengthFor(rules.rules, open); await runAgentFix( () => fixDraftRules(draft.id, draft.brandId, overLength ? { ...request, overLength } : request), undefined, false, beginThirdTry(), );
- One commit on main (c58edb8).
Follow-ups:
- A Length of 0 makes the API refuse the run (
web/src/lib/content/rules.ts:832-834;server/src/lib/content-agent.js:136).- The Rules tab saves "0" (
_rules-tab.tsx:721takes^\d{1,6}$).lengthBand(0)is 0–0, so every page reads as long, withmax: 0. - Such a Length isn't held, because
lengthOutOfReachneeds a target above 0 (rules.ts:959). So Fix open rules sends it as a rule, as today. - But a hand-off, the automatic one included, and Remove AI traces' own Fix send
overLength: { count, max: 0 }. The schema refusesmax: 0(min(1)), so once the API is deployed those runs answer 400invalidand the editor says the run failed. - Fix: the hint shouldn't cost a run.
- On the server, make the field
.optional().catch(undefined), so a value out of range is dropped and the run goes on. I checked this with zod 4.3.6. - Also skip the line when a
lengthrule is among the rules, since it says the Length isn't. - On the web, return undefined when
status.max < 1. - In the server test, the two
toThrowchecks become "parses withoutoverLength".
- On the server, make the field
- It's small, and it can go in with this PR, before the API deploy.
- The Rules tab saves "0" (
- The editor's two calls aren't tested (
_draft-editor.tsx:2344,:2528).- The PR says a page test would need a held Length. That's true for Fix open rules, but a hand-off sends the field on any page past its Length.
- Fix: in
page.test.tsx, use a draft with Length set to 100 (overrides: { length: { value: '100' } }) and a longer page:- Hand off sends
overLength: { count: expect.any(Number), max: 120 }; - with the Length within its band, Hand off sends no
overLength.
- Hand off sends
7 of 12 tasks
gkhngyk
pushed a commit
that referenced
this pull request
Oct 26, 2026
…e run, and test the editor's Fix and hand-off calls (#1552 review) (#1553) Co-authored-by: Cihan <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
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
The problem (live test, 2026-10-26). On a live Optimize draft, the page was 17,683 characters against a Length of 13,998:
The change. When the page is over its Length and a run doesn't send the Length rule, the run says so, and the agent keeps what it adds short. That covers:
overLengthFor(web/src/lib/content/rules.ts) gives the page's characters and the most its Length allows (the band's top, +20%). It's undefined when Length is off, within its band, or sent.overLength(fixDraftRules,handOffDraft).fixRulesInputtakes an optionaloverLength: { count, max }, andhandOffDraftpasses it on.buildFixPromptadds one line under the rules: "The page is already 17,683 characters, past the most its Length allows (16,798). The Length isn't among the rules here, so don't cut the page for it. Fix each rule with as few words as it needs: an answer in one or two sentences, no section, list, table or example a rule doesn't ask for, and a replace no longer than the words it replaces unless the rule needs words added (a keyword, a figure, a name)."There's no change when the Length rule is among the rules sent, since it already says how far off the page is. Rewrite page already sends the Length with its reading.
Deploy order:
Related issue
Live editor test, 2026-10-26 (no issue). It goes with the PR that moves Next past the third step once the agent has taken it.
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
overLength. Its suggestions add short answers, with no new sections beyond what a rule asks.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Also run: server format, lint and tests (225 files, 2,890 passed, 3 skipped); web
yarn test(427 files, 4,057 tests) andyarn build.Tests:
overLengthForgives{ count, max }when the Length is held, when only other rules are asked for, and for a hand-off (none sent);fixDraftRulesandhandOffDraftsend it in the body.fixRules) passes the open rules it sends. A page test would need a held Length, which depends on a stored last rewrite, so it's covered at the helper.Pre-push review
A review agent read the change before the push. It confirmed the condition, the
onlypath, the numbers and that an older API ignores the field (Zod strips it). Fixed from it:Left for a separate PR: Start on an existing page gives its writer only the Length target, not the page's current count. Its prompt invites a missing section or an FAQ.
🤖 Generated with Claude Code