Repository navigation
fix(content): stop recommending a page rewrite for a Length it can't reach, and offer one it can - #1514
Merged
Conversation
…adings' answers and what the last rewrite came to, and offer a Length it can reach Co-Authored-By: Claude Opus 5.5 <[email protected]>
… for, keep its numbers on the row (00285), and read the floor's sections closer (pre-push review) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…and count the last rewrite only within its Length's band and the same kept text (pre-push review) Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 25, 2026
fix(content): one count for the rules and for a rewrite's characters, as the editor shows them
#1521
Merged
This was referenced Oct 26, 2026
This was referenced Oct 26, 2026
gkhngyk
approved these changes
Oct 26, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Looks good.
What I checked:
-
00285.
- It adds three nullable integer columns to
content_draft_suggestions, with no default and a check on each. Nothing is rewritten. The checks take one pass over the table while it's locked.add column if not existsmakes it safe to run again. - Members read the columns through the table's existing select policy, which covers drafts of their own organization.
authenticatedhas select only, so only the API writes them. schema.sqlhas the migration as the build script writes it.supabase.tshas the three columns in Row, Insert and Update.getLastPageRewritefilters ondraft_idandkind, takes the newest row and reads one.content_draft_suggestions_draft_idx (draft_id, created_at desc)covers that.
- It adds three nullable integer columns to
-
What the API writes (
content-writer.js:599-603).length_targetis the Length the rewrite was sent, or null with Length off.rebuildSourceskeeps it between 100 and 50,000, so the> 0check always holds.kept_charsiskeepBlocks' own count.after_charsis counted on the final page, after the kept blocks go back and unsourced numbers become placeholders.- The server test checks all three, and the null with Length off.
-
The floor (
rewriteFloor). It walks the top-level blocks the same waykeptCharactersdoes. It counts:- what a rewrite keeps;
- each heading;
- 100 characters under each heading that has no kept quoted passage under it;
- 100 under the H1, only when Summary is on.
A heading that only groups deeper ones adds no answer. The tests cover a quoted passage that answers a heading (in a quote too), a heading that groups, and an unlocked passage.
-
The last rewrite (
lastRewriteSays).- It's ignored with Length off, and when the kept count has moved by more than the slack.
- For a Length shorter than the one it was written to, it counts only when it missed its own and the new Length is inside that one's band.
- A rewrite that got within the band wins over the estimate.
suggestedis the larger of the two numbers, rounded up to 500. It never goes past the page orRULE_LENGTH_MAX, so one Raise is enough.- Each case has a test.
-
Where it shows.
- The Rules tab note has three wordings, and each gets all of its placeholders.
- Raise Length sits inside the fieldset that stays disabled until the rules are ready.
- Next step and Run Agent's recommendation stop offering the Length rewrite. Rewrite page itself is still under ▾.
- The agent card names the kept blocks only when they alone put the Length out of reach.
-
The read. It runs on opening, and again when a new page suggestion shows. It goes through RLS. If it fails, it's logged and the estimate stands.
-
Before the API is deployed. This assumes 00285 is applied first.
- The web reads the new columns. They're null for every rewrite until the API writes them, so only the estimate counts.
- The new note wordings and Raise Length show.
- On a page where the floor still fits the band, as on the test page, a rewrite is still recommended after one misses. That stays until the API goes out.
- Nothing that works today breaks.
- The API with this change needs 00285 on the database first, because its page-rewrite insert names the new columns.
-
Merge. It's based on current main and merges cleanly.
Low, follow-up:
_cited-passages.ts:173: only its own tests usekeptCharactersnow, andrewriteFloorrepeats its walk. Drop it and its tests, or haverewriteFloortake its kept test from one shared helper.
This was referenced Oct 26, 2026
7 of 12 tasks
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
In the live editor test (2026-10-25), an Optimize "best of" page with a Length of 4,000 kept 14 cited passages and 4 tables, about 3,125 characters (78% of the Length). The Rules tab and Next step kept recommending Rewrite page. Three rewrites came to 5,468, 6,843 and 7,335 characters, and the third made the page longer.
Two things caused it:
lengthOutOfReachonly fired once kept blocks reached 85% of the Length.rewriteAdviceignored that the last rewrite had already missed.This PR reads a Length's reach from two things, either one enough (
web/src/lib/content/rules.ts,RewriteReach).1. The least a rewrite comes to (
rewriteFloor,_cited-passages.ts). It's the sum of:Notes:
LEAST_SUMMARYand a newLEAST_ANSWER(100). It stays low on purpose, so "out of reach" means it.2. What the page's last rewrite came to.
Migration 00285 adds three nullable columns to
content_draft_suggestions, written bycontent-writer.json a page rewrite:length_target: the Length it was written to, null with Length off;kept_chars: what it kept word for word;after_chars: what it came to.The editor reads these numbers only (
getLastPageRewrite), on opening and once a new rewrite shows. The rewritten page itself isn't read.The last rewrite counts only when all of these hold:
So a rewrite for a Length of 10,000 says nothing of 3,000, met or missed, and one written with Length off says nothing at all.
A last rewrite that got within the band means the Length is in reach, whatever the estimate says.
If either one is past the top of the Length's band (+20%), the page is out of reach:
keptOutOfReach); the rewrite's own result is no reason. The old 85% gate is gone (KEPT_LENGTH_SHARE).Page rewrites made before 00285 have no numbers, so for them only the estimate counts.
The other parts of this round go in separate PRs from main:
Related issue
Editor test findings 2026-10-25 (group B).
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 testsDeploy order
00285 goes first: the API writes the new columns. Before it's applied, the API's insert of a page rewrite would fail. The web reads the columns and logs a failed read, falling back to the estimate. Applied on the dev database.
How to test
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/)Server: format, lint,
npm test. Web:yarn testandyarn build.bash supabase/build-schema.shwas run, andschema.sqlis in this PR. Two pre-push reviews; their findings are the second and third commits. The browser check of the Rules tab note is in the next batched local test session.🤖 Generated with Claude Code