Skip to content

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
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/next-step-after-agent-try
Oct 26, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/next-step-after-agent-try

Conversation

@cihan-gyk

@cihan-gyk cihan-gyk commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

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 Content Agent's Fix open rules run left 3 changes, and all were accepted.
  • 2 rules stayed open: Length (17,683 / 13,998 characters, held for the person) and "Direct answer under each H2" (15 of 18).
  • Next stayed on Fix open rules, and the page never reached step 4 (Add proof and author).

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):

  • the agent's run left a new batch and every change in it is decided, accepted or rejected; or
  • the run found nothing to change.

These don't count, and the step stays:

  • a run that fails or is stopped;
  • one that never runs (busy, AI usage used up, another tab's open suggestions).

In each of these cases, the attempt from before it is put back.

How the editor notes it (_draft-editor.tsx):

  • When: a Fix open rules run (from Next, the card's Run Agent or the Rules tab) or a page rewrite once it has started, but only while Next's step is Length or Fix open rules.
    • Quality's hand-off, automatic or not, is never the third step's.
  • What: the batch on the page then.
  • Where: in this browser, per draft (aeo:next-step-third-try:{id}), as Skip's state is kept.

Once taken:

  • It's kept as 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.
  • The path shows the step as done. The Rules tab still shows what's open.

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 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. With 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).
  2. Click Next · Fix open rules → Fix open rules. Accept or reject what it leaves.
  3. Next moves on to Add proof and author, or to Check and mark ready with Quality's to-dos done. The Rules tab still lists the rules open.
  4. Run it again and click Stop: Next stays on Fix open rules.

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: yarn test (427 files, 4,060 tests) and yarn build.

Tests:

  • next-step.test.ts:
    • with the step taken, a page with a rule open and its Length off moves on to proof, or to Check with Quality off;
    • an empty page is still written first;
    • thirdStepTried covers:
      • a run under way, and open changes;
      • a decided batch, and the batch from before the run;
      • found nothing (also while another run works);
      • passed holding through a later run;
      • a first batch.
  • page.test.tsx, each ending on the exact step Next shows:
    • a Fix run's change rejected with the rule still open moves Next on to Add proof and author;
    • a run that found nothing moves on and holds after a reopen;
    • a stopped run, a failed run, and another tab's changes decided here all stay.
    • The first two fail without the editor change.

Pre-push review

A review agent read the change before the push. Fixed from it:

  • the Quality hand-off counted as the third step: it never does now;
  • a failure counted as taken, though failed also covers runs that never ran;
  • a later run brought the step back while it worked;
  • a History restore passed the step: it clears the attempt;
  • an attempt was noted before a rewrite had started, and a stopped or refused run left it in place: the attempt before it is put back;
  • tests now check the exact next step, and cover failure and another tab's changes.

🤖 Generated with Claude Code

…n the third, with rules still open or the Length off

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 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 fixing in the same handler that notes the attempt, so busy holds 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 > 0 holds 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, and open_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: 0 or 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 localStorage when the editor mounts. Until the batch is read, the batch is null, so nothing passes early. The editor only renders in the browser (page.tsx reads 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 runAgentFix without an attempt, so with no attempt left over it never takes the step. Run Agent on step 4 is ignored, because beginThirdTry returns null once the step is passed.
  • 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 needs quality to 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's count, and the run row's outcome and writing-step count (00249). The API on prod already writes all of them. why is 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 thirdStepTried and thirdTried are 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.
  • Merge. One commit on c58edb8 (main). git merge-tree with main gives the head's tree (804b06c0). Web only, no migration.

Follow-ups:

  1. 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).
    • beginThirdTry ignores only. 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 only to beginThirdTry. Count the run only when only is unset or covers rulesForNext(...) as it is now.
      • Note the step the run was for in ThirdTry (step: 'length' | 'fixRules'), and have tried(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.
  2. Once passed, the step never comes back (next-step.ts:184; _draft-editor.tsx:3159-3170).
    • passed holds 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 stepState changes.
    • 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.
  3. 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 ended failed or stopped, drop the attempt. draft.agentState === 'failed' already covers the failed rewrite.
  4. 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.
  5. 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.
  6. 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.

@gkhngyk
gkhngyk merged commit bb743ee into ansvisor:main Oct 26, 2026
6 checks passed
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]>
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