Skip to content

fix(content): drop an out-of-range Length hint instead of refusing the run, and test the editor's Fix and hand-off calls (#1552 follow-ups) - #1553

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/over-length-hint-safe
Oct 26, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/over-length-hint-safe

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Follow-ups from the review of #1552 (merged). These should go in before the API deploy that carries #1552.

1. A Length of 0 no longer makes the API refuse the run.

  • The problem:
    • The Rules tab can save a Length of 0. lengthBand(0) is 0–0, so every page reads as long with max: 0.
    • Fix open rules sends such a Length as a rule, but a hand-off (the automatic one too) and Remove AI traces' own Fix sent overLength: { count, max: 0 }.
    • The schema refuses max: 0, so once the API was deployed those runs would answer 400 invalid.
  • Server (content-agent.js):
    • overLength is .optional().catch(undefined): a value out of range is dropped and the run goes on. This also covers handOffInput, which extends the same schema.
    • The prompt line isn't said when a length rule is among the rules, since the line says the Length isn't.
  • Web (rules.ts): overLengthFor returns undefined when the band's top is under 1.

2. The editor's calls are tested (page.test.tsx):

  • Hand off, on a page with a Length of 100:
    • it sends overLength: { count, max: 120 };
    • with the Length set to the page's own count (within its band), it sends none;
    • with a Length of 0, it sends none.
  • Fix open rules, from the Rules tab's Run Agent:
    • a page past a Length of 20 sends the hint when the Length isn't among the rules sent;
    • with no Length set, it sends none.

Related issue

Follow-up to #1552 (no issue).

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

  1. Run the tests:
    cd server && npx vitest run src/lib/content-agent.test.js src/lib/content-handoff.test.js
    cd web && npx vitest run src/lib/content/rules.test.ts "src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx" -t "past its Length|over its Length"
  2. On a draft, set Length to 0 in the Rules tab and Hand off from Quality. The run starts as before; the request has no overLength.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/): 0 errors; the 6 warnings were already on main
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Also run:

  • server: format, lint and tests (225 files, 2,890 passed, 3 skipped);
  • web yarn test (427 files, 4,068 tests);
  • web yarn build, before the last edits, which were comments and tests only.

Server tests:

  • max: 0, a negative count and a string parse to no overLength, and the rest of the input is kept;
  • the line isn't said with a length rule sent;
  • a hand-off drops a Length of 0 and runs.

Web tests: overLengthFor gives nothing for a Length of 0.

Pre-push review

A review agent read the change. It checked zod 4.3.6 against the real fixBody and handOffBody:

  • absent stays absent;
  • invalid values drop;
  • another invalid field still refuses the request.

Fixed from it:

  • the editor test checks a Length within its band, not only a short page, and a Length of 0;
  • a Fix-call test and a server hand-off test were added;
  • comments merged.

🤖 Generated with Claude Code

…e run, and test the editor's Fix and hand-off calls (ansvisor#1552 review)

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 a follow-up.

The #1552 review's two items:

  1. A Length of 0 makes the API refuse the run: Done.
  2. The editor's two calls aren't tested: Done. One test has a small gap (follow-up 1).

What I checked:

  • Why it goes before the API deploy. I confirmed it.
    • Main's routes refuse overLength: { count, max: 0 }. I parsed main's real fixBody and handOffBody (zod 4.3.6), and both fail on overLength.max. So they answer 400 invalid.
    • The web on main sends that body whenever a draft's Length is 0 and its page isn't empty. That covers every hand-off (Hand off and the automatic one) and Remove AI traces' own Fix.
    • So if the API is deployed from main without this, those runs fail.
    • The web half alone stops the requests once Vercel deploys it. The server half covers pages opened before the merge.
  • The server (server/src/lib/content-agent.js:135-141).
    • .optional().catch(undefined) sits on the field. The same parse with this PR's schemas:
      • max: 0, count: -1, count: 1.5, 'long' and null all parse, with no overLength;
      • a valid hint is kept as it was;
      • with no field, there's still no key.
    • Nothing else is hidden. With max: 0 plus another bad field, the request is still refused, and the issue names only that field. I tried empty rules, a bad brandId, an empty text rule, bad sources and bad locked. For the hand-off I tried empty items, an unknown origin and a key outside HANDOFF_KEYS.
    • The hand-off gets the same. handOffInput is fixRulesInput.omit({ rules }).extend(…), so it keeps the field as it is, and the route's .extend({ brandId }) does too. A dropped hint leaves the key as undefined. handOffDraft passes it on only when set (content-handoff.js:85), and overLengthLine(undefined) is ''.
    • A Length rule sent (:994) gives no line. Without one the line is said as before. Main's and this PR's prompts are the same byte for byte when no Length is sent, with or without the hint, and when a Length is sent with no hint. Hand-off keys can't be length, so the skip only matters for Fix.
  • The web (web/src/lib/content/rules.ts:832-835).
    • status.max >= 1 drops the hint only for a Length of 0. lengthBand(1) already gives a top of 1, and the Rules tab takes whole numbers only.
    • Fix open rules was already safe: a Length of 0 isn't held (lengthOutOfReach needs a target above 0), so it's sent as a rule.
  • Tests.
    • The new cases for the change fail without it:
      • the server's three dropped values and the Length-rule prompt check (checked against main's modules);
      • the hand-off parse of max: 0;
      • overLengthFor with a Length of 0;
      • the page test's Length-0 hand-off, which sends max: 0 on main.
    • The page tests' other cases cover #1552's two calls, and they fail if a call stops sending the field.
      • Hand off: 100 sends max: 120, and a Length equal to the page's own count sends none.
      • Fix: in that fixture the Length is held. A rewrite's floor (the H1's 20 characters plus a 100-character summary) is past 24, so the hint goes, with max: 24.
    • I read the web tests but didn't run them.
  • Speed and AI budget. No new regex, no loop on the page's text, and no new model call.
  • Merge.
    • One commit on main (307670b), and git merge-tree with main gives the PR's own tree. No migration.
    • It merges cleanly with every open PR, including #1544 (content-agent.js) and #1556 (the editor and page.test.tsx). #1556 keeps the Fix call's overLength as it is.
  • Before the API deploy. Users see no change. The prod API strips overLength, so the web stops sending a hint the API ignores today.

Follow-up:

  1. The Fix test passes on either branch (page.test.tsx:6701-6705).
    • The if accepts both outcomes: the Length sent with no hint, or the Length held with the hint. In this fixture the Length is held, so only the else runs.
    • If the fixture changes so the Length isn't held, the test still passes but stops checking the call.
    • Fix: state the branch:
      expect(sent.rules.map((r: { key: string }) => r.key)).not.toContain('length');
      expect(sent.overLength).toEqual({ count: expect.any(Number), max: 24 });

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