Repository navigation
fix(content): move Next on to the fourth step once the agent has taken the third, with rules still open or the Length off - #1550
Merged
Conversation
…n the third, with rules still open or the Length off 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:
- When the step counts as taken (
thirdStepTried,web/src/lib/content/next-step.ts:180).- A run still going. Fix sets
fixingin the same handler that notes the attempt, sobusyholds it. A rewrite is noted only once its start is accepted, and then the editor unmounts until the run ends. - Changes not yet decided.
open > 0holds it. The batch the run began on doesn't count, so the batch from before the run never passes it. - Failed, stopped or never run. For a Fix, every exit puts the attempt from before it back:
failed(),stopped, a lost answer that reads stopped or failed, andopen_suggestions. A rewrite that fails or is stopped doesn't; see item 3. - Not stuck. A run that found nothing passes it, whether it answered
count: 0or its answer was lost and its row says so. A batch whose changes were all rejected passes it too. - Reload. The attempt is read from
localStoragewhen the editor mounts. Until the batch is read, the batch isnull, so nothing passes early. The editor only renders in the browser (page.tsxreads the draft in an effect), so there's no hydration mismatch. - Restore. A restore to another page clears the attempt in the same batch of updates as setting aside the open changes, so those set-aside changes never count as decided.
- Quality's hand-off. It calls
runAgentFixwithout an attempt, so with no attempt left over it never takes the step. Run Agent on step 4 is ignored, becausebeginThirdTryreturns null once the step is passed.
- A run still going. Fix sets
- Where its state comes from. Only from this browser's
localStorage, the latest batch's id and the editor's own busy flags. It doesn't read the run row. Skip's state works the same way. - What the person sees (only with Quality phase 1 or later, because the basket only shows then).
- Once the run's changes are decided, Next and the agent card head with Add proof and author (or Check and mark ready).
- The Rules tab still lists the open rules, and the card's Run Agent still runs Fix.
- The "If you see…" lines still offer Fix open rules ("1 to 3 rules open") or Rewrite page ("Page far longer than Length").
- "The rules are met." (
reasons.checkRules) never shows. It needsqualityto be null, and then the basket isn't rendered. With Quality on, Check's reason is the links, schema and Trust line. - The path shows step 3 checked and struck through as done; see item 5.
- The deploy gap. None. The change reads the batch's
batchId(CE-018), the Fix answer'scount, and the run row'soutcomeand writing-step count (00249). The API on prod already writes all of them.whyis optional, and the toast handles it missing. Next behaves the same before and after the API deploy. - The work. No regex, and nothing loops over the page's text.
- Tests.
- The unit tests fail without the change, because
thirdStepTriedandthirdTriedare new. - In
page.test.tsx, "moves on once decided" and "moves on when it found nothing" fail without it. The three "stays" tests pass either way, as guards should. - Not covered: the rewrite path, the Length step in the editor (the fixture turns Length off), the restore clearing the attempt, and a lost answer read as nothing; see item 6.
- The unit tests fail without the change, because
- Merge. One commit on c58edb8 (main).
git merge-treewith main gives the head's tree (804b06c0). Web only, no migration.
Follow-ups:
- A Fix on some of the rules, or on the Length step, passes the whole third step (
_draft-editor.tsx:456-462,:2369-2374;_rules-tab.tsx:683;next-step.ts:287).beginThirdTryignoresonly. Say Next is on Fix open rules with three rules open, and the person clicks Fix on "Remove AI traces" in the Rules tab (agentFix.run(['aiTraces'])). Once those changes are decided, Next moves on to step 4, though the other two rules never went to the agent.- On the Length step, a Fix (the step's own alternative, or the card's Run Agent) passes Length too, because
tried()covers both ids. Fix doesn't take the Length when it's far off (rulesForNext). Since #1514, the Length step only shows when a rewrite can reach it. So Next calls "Shorten to your Length" done without ever trying a rewrite. - Fix:
- Pass
onlytobeginThirdTry. Count the run only whenonlyis unset or coversrulesForNext(...)as it is now. - Note the step the run was for in
ThirdTry(step: 'length' | 'fixRules'), and havetried(id)pass that step only. A rewrite passes Length, and a Fix passes Fix open rules. On the Length step, Next then stays on Rewrite page after a Fix, as on main. - Add an editor test with each case.
- Pass
- Once passed, the step never comes back (
next-step.ts:184;_draft-editor.tsx:3159-3170).passedholds until a restore. None of these bring Fix open rules or Length back in this browser, and the path keeps step 3 checked:- a rule that opens later (a rule turned on, the page type changed, the person's own edits, changes accepted on step 4);
- a Length that drifts far off;
- a whole new page from Brief › Rewrite from brief (
_brief-tab.tsx:369, a Start that writes the page again).
- Skip handles this already: a skipped step comes back once its
stepStatechanges. - Fix:
- Keep the open rules and the Length state when the step passes (
at: rulesForNext(...),length: stepState('length', s)). - Hold the pass only while every open rule is among those and the Length reads the same. Then a rule the agent never saw brings the step back, and one it couldn't close doesn't.
- Clear the attempt when Start writes the page again, as a restore does.
- Keep the open rules and the Length state when the step passes (
- A rewrite that fails or is stopped leaves its attempt behind (
_draft-editor.tsx:2996).- The attempt is noted once the rewrite starts, and the editor unmounts. Nothing puts it back when the run fails or is stopped. The same happens to a Fix whose tab closes mid-run and whose run then fails.
- The next batch from anything else then passes the step once it's decided: Quality's Hand off, Suggest changes from brief, or another tab's run. The PR says the hand-off never counts, and this is the one way it does.
- Fix:
- Note the run's kind in the attempt.
- When the editor opens with an attempt that hasn't passed, read the latest run of that kind (
readAgentRun(draft.id, [kind])). If it endedfailedorstopped, drop the attempt.draft.agentState === 'failed'already covers the failed rewrite.
- The pass is kept per browser. A teammate, another device or a private window sees Next back on Fix open rules for the same page. Running it again uses AI usage. A restore made elsewhere doesn't clear it here.
- Fix (later): read it from the run row: the latest fix or rewrite run after the last restore, ended
done, with its batch decided. Or keep the pass on the draft.
- Fix (later): read it from the run row: the latest fix or rewrite run after the last restore, ended
- The path calls step 3 done while rules are still open (
_next-step.tsx:349,next-step.ts:317).- It's checked and struck through. The "If you see…" line below it still says rules are open.
- Fix: show it as passed rather than done, the way a skipped step shows. For example "Fix open rules · yours in the Rules tab", with a key in
en.json.
- Tests to add (
page.test.tsx):- a rewrite started from Next, whose page is then decided;
- a restore after the pass that brings Fix open rules back;
- the AI traces Fix not passing the step (item 1);
- a lost answer whose row says the run found nothing;
- a fixture with Length on, so the Length step is covered in the editor.
7 of 12 tasks
7 of 12 tasks
4 of 12 tasks
gkhngyk
pushed a commit
that referenced
this pull request
Oct 26, 2026
…e page reads as it did, drop a failed or stopped run's attempt, and show the step as passed (#1550 review) (#1556) Co-authored-by: Cihan <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
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
The problem (live test, 2026-10-26). A live test on an Optimize draft got stuck at step 3 of the Next step basket:
The change. Once the agent has taken the third step, Next moves on to the fourth, whatever the rules read after. The third step is Length (Rewrite page) or Fix open rules. Rules still open stay in the Rules tab for the person, and Run Agent is still there.
When the step counts as taken (
thirdStepTried,web/src/lib/content/next-step.ts):These don't count, and the step stays:
In each of these cases, the attempt from before it is put back.
How the editor notes it (
_draft-editor.tsx):aeo:next-step-third-try:{id}), as Skip's state is kept.Once taken:
passed. A later run, such as a hand-off on step 4, doesn't bring the step back while it works or while its changes wait.A History restore to another page clears it: the restored page's third step is open again. Skip this step works as before.
Related issue
Live editor test, 2026-10-26 (no issue). It follows the Next step basket work: #1428, #1516.
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=1, open a draft whose Next step is Fix open rules, and whose open rules the agent can't all close (e.g. a fan-out H2 it isn't given room for).Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/): 0 errors; the 6 warnings were already on mainyarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Also run:
yarn test(427 files, 4,060 tests) andyarn build.Tests:
next-step.test.ts:thirdStepTriedcovers:passedholding through a later run;page.test.tsx, each ending on the exact step Next shows:Pre-push review
A review agent read the change before the push. Fixed from it:
failedalso covers runs that never ran;🤖 Generated with Claude Code