Skip to content

fix(content): pass Next's third step only by its own run and while the page reads as it did, and show it as passed (#1550 follow-ups) - #1556

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/next-step-third-try-followups
Oct 26, 2026
Merged

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

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Follow-ups from the review of #1550 (merged). #1550 moves the Next step basket past its third step (Length → Rewrite page, or Fix open rules) once the Content Agent has taken it. This narrows when that happens and lets the step come back when the page moves on.

1. Each run passes its own step only, as you put it: a rewrite passes the Length, a Fix passes Fix open rules.

  • An attempt notes the step it takes (step: 'length' | 'fixRules', from the run's kind), and is noted only while Next's step is the third. A rewrite's step is read when it's asked for, before its waits.
  • A Fix counts only when it was asked for every rule the step counts (only unset, or covering rulesForNext). A Fix of Remove AI traces alone, from the Rules tab, isn't the step.
  • On the Length step, a Fix (its alternative, or the card's Run Agent) passes Fix open rules, not the Length: Next stays on Rewrite page, as on main.

2. A passed step holds only while the page reads as it did (thirdStepPasses).

  • A pass keeps the open rules and the Length's state when it's taken.
  • Fix open rules holds while every rule open now was open then. A rule the agent never saw brings it back: one turned on, a page type change, edits, changes accepted on step 4. A rule it couldn't close doesn't.
  • Length holds while the Length reads the same.
  • Timing: the pass is written once the rules have read the page after the last decision (PAGE_READ_DELAY_MS, then their deferred read), so it keeps the page as it reads after, not before.
  • Stale passes: a pass that no longer holds is dropped, as a stale skip is (once the reads are in), so a page that later reads as before doesn't bring it back to life.
  • Cleared entirely: when Start writes the page again (Try again, Rewrite from brief), and on a restore to another page.

3. A run that failed or was stopped while the editor was closed leaves no attempt.

  • An attempt notes its run's kind and when it began. When the editor opens with an attempt not yet taken, it reads the latest run of that kind.
  • If that run began with the attempt and ended failed or stopped, or has a stopped_at and no outcome yet (a Stop writes it first), the attempt is dropped.
  • A failed rewrite (failedRewrite: agentState failed on a rewrite run) is dropped at once.
  • No step passes on a kept attempt until this read is done, so a hand-off batch can't win the race.
  • A run still under way when the editor opens is left to finish: its batch passes the step. If it then fails, the attempt stays until a later batch. That gap is narrow, and it closes with item 4.

4. The path says the step was passed, not done. It shows muted, not struck through, with "· yours in the Rules tab". The screen-reader state reads "taken by Content Agent, what's left is yours in the Rules tab". Both are in en.json.

Storage:

Left for later (review item 4): the pass is kept per browser. Reading it from the run row, or keeping it on the draft, would carry it across devices and teammates.

Related issue

Follow-up to #1550 (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

With NEXT_PUBLIC_CONTENT_QUALITY_PHASE=1, on a draft whose Next step is Fix open rules:

  1. Rules tab › Remove AI traces › Fix, then decide its changes: Next stays on Fix open rules.
  2. Next › Fix open rules, decide its changes: Next moves on. The path shows "Fix open rules · yours in the Rules tab".
  3. Turn on a rule the page doesn't meet: Next is back on Fix open rules.
  4. On a page far off its Length (Next: Shorten to your Length), run Fix: Next stays on Rewrite page.

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,077 tests) and yarn build.

Tests:

  • next-step.test.ts:
    • a pass shown as passed;
    • a Fix never passing the Length step;
    • the Length then Fix open rules, each by its own run;
    • a pass holding with the rule it couldn't close, and with fewer rules;
    • a new rule bringing Fix open rules back;
    • a Length drift bringing the Length step back;
    • thirdStepTried's cases.
  • page.test.tsx (a fixture with Length on, at 400, for the Length step):
    • On Fix open rules:
      • a Fix's change rejected passes the step after the page's read, and the path reads "Fix open rules· yours in the Rules tab";
      • the Remove AI traces Fix doesn't pass it (fails without the only check);
      • a lost answer whose run row says it found nothing passes it;
      • a run that found nothing passes it, and the pass holds after a reopen.
    • On the Length step: a Fix doesn't pass it, and a rewrite begun on it, its page decided, passes it after the page reopens.
    • An attempt dropped on open, so another decided batch doesn't pass the step: a rewrite run stopped, failed, or stopped with no outcome yet; and a failed rewrite (agentState).
    • Coming back: a rule opened since the pass brings the step back, and the stale pass is dropped. A restore clears the passes and brings Fix open rules back.
    • The 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 cases.

Pre-push review

A review agent read the change. Fixed from it:

  • the pass was written before the rules re-read the page after the last decision;
  • stale passes weren't dropped and could come back;
  • the open-time read raced the pass, and missed a stopped run with no outcome yet;
  • the step mapping now follows your rule (rewrite → Length, Fix → Fix open rules);
  • a rewrite's step was read after its waits;
  • the screen-reader text now names the Rules tab;
  • readThirdStep / writeThirdStep were renamed;
  • the tests listed above were added.

🤖 Generated with Claude Code

…e page reads as it did, drop a failed or stopped run's attempt, and show the step as passed (ansvisor#1550 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 follow-ups.

The #1550 review's six items:

  1. A Fix on some of the rules, or on the Length step, passes the whole step: Done.
    • beginThirdTry(kind, { only, at }) (_draft-editor.tsx:474-494) notes nothing unless Next's step was Length or Fix open rules when the run was asked for.
    • A Fix with only counts only when only covers rulesForNext (:479-486). Only Remove AI traces' own Fix passes only (_rules-tab.tsx:683), so it counts only when AI traces is the last rule left. Run Agent (the Rules tab's and the card's) and Next's button send no only, so they count.
    • The attempt notes its step by kind: a rewrite takes length, a Fix takes fixRules (:488). nextStep passes each step by its own pass (next-step.ts:323-324). On the Length step, a Fix passes Fix open rules, and Next stays on Rewrite page.
    • A rewrite reads Next's step before its waits (stepAsked, :2996, :3039).
  2. Once passed, the step never comes back: Done.
    • thirdPassOf keeps rulesForNext and the Length's state (next-step.ts:204). thirdStepPasses holds a pass while the Length reads the same and, for Fix open rules, every rule open now was open then (:214-223).
    • The pass is written once the page has been read after the last decision (_draft-editor.tsx:3274-3287). A pass that no longer holds is dropped (:3290-3303).
    • Start clears the passes (:2950): Write with Agent, Rewrite from brief, and Try again after a failed write. So does a restore to another page (:3550).
  3. A rewrite that fails or is stopped leaves its attempt behind: Mostly done.
    • A failed rewrite (failedRewrite) drops its attempt as the page opens (:3312).
    • Otherwise the page reads the latest run of the attempt's kind, begun no earlier than a minute before the attempt (:3318-3333). A run that failed, stopped, or has stopped_at drops it. attemptChecked keeps any step from passing until that read is in, so a hand-off batch can't pass it first.
    • Two gaps are left. A run still under way when the page opens, which then fails, keeps its attempt; the PR says so. Follow-up 3 has the other.
  4. The pass is kept per browser: Not done. The PR leaves it for later.
  5. The path calls step 3 done while rules are open: Done.
    • There's a new path state, passed (next-step.ts:114, :353-357).
    • The step shows muted with its number, not a check, and isn't struck through (_next-step.tsx:215, :375, :390-392).
    • Both strings are in en.json.
  6. Tests to add: Done.
    • The fixture has Length on (400).
    • The other cases: the Remove AI traces Fix, a rewrite's page decided after the page reopens, a lost answer whose row says it found nothing, and a restore.
    • The rewrite is begun from storage, not by a click, so stepAsked isn't exercised.
    • One test doesn't guard what it names (follow-up 4).

What I checked:

  • Whether it gets stuck the other way.
    • What a pass compares.
      • Fix open rules compares the keys of rulesForNext: rules that are on, open, and that a Fix can close. That leaves out Length, Who it's for unset, One H1, the feed, and rules held by quoted passages. It compares keys, not counts.
      • Both passes also compare the Length's state, stepState('length'). That's long or short when the page is more than 30% off and a rewrite can reach it, else ''. It compares the state, not the count.
    • A typo fix changes neither, so the pass holds. It brings the step back only if it tips a rule over its edge (a sentence one word past the limit, a keyword out of a heading) or crosses the 30% line.
      • That's by design: the agent never saw that rule.
      • The pass is then dropped for good, as a stale skip is, so undoing the edit doesn't bring it back.
      • There's no loop. Each decided run writes a new pass with what's open then, and the step can still be skipped.
    • A rejected batch. The pass is written after the page is read again, with the rules from before the run, and it holds.
    • A run that found nothing. The same, and it still holds after the page reopens (tested).
    • Accepted changes that open a rule (a Fix's added sentence): the page read restarts the wait (pageHtml in the deps). So the pass keeps the rule as open, and it doesn't bring the step back.
    • One case does misfire; see follow-up 1.
  • Stored state.
    • The key is unchanged: aeo:next-step-third-try:{draftId}. It now holds { attempt: { step, kind, at, batch, ended? } | null, passes: { length?: { rules, length }, fixRules?: { rules, length } } }, and it's removed when both are empty.
    • #1550's { batch, ended?, passed? } has no passes, so it reads as nothing taken. Bad JSON, a plain value, or an attempt without step read the same way. Nothing throws.
    • So a page #1550 passed today shows Fix open rules once more (the PR says so), and one decided run passes it again.
    • A tab still on #1550's build reads the new shape as nothing taken too.
  • What the person sees (only with Quality phase 1 or later, where the basket shows).
    • The path line reads "Fix open rules · yours in the Rules tab", "Shorten to your Length · yours in the Rules tab" or "Bring it up to your Length · yours in the Rules tab".
    • Screen readers hear "… · taken by Content Agent, what's left is yours in the Rules tab".
    • The Next button's bars show the step light, as they do a skipped one.
    • After the last decision, Next moves on after about 0.65 s on a reject and about 1 s on an accept, not at once. It takes longer while Quality is still reading the page (links being checked, for example).
  • The deploy gap. None.
    • The one new read is the latest run of a kind, from the browser: content_agent_runs, its started_at, stopped_at and outcome (00249, readable by members, on prod).
    • The editor already read draft.agentState and agentRun.
    • The API on prod already writes fix and rewrite runs with these columns, so Next behaves the same before and after the API deploy.
  • Speed. No regex. The loops run over at most two passes and the open rules' keys.
  • Tests.
    • The unit tests fail without the change: thirdPassOf and thirdPasses are new.
    • These page tests fail without it:
      • "moves on once decided": the stored shape and the path's wording;
      • the Length step: main passes the Length on a Fix;
      • the three dropped attempts and the failed rewrite: main has no read when the page opens, and their stored attempt stays;
      • a rule opened since: main's passed holds for good.
    • The Remove AI traces test fails on main, but not without this PR's only check (follow-up 4).
    • The lost answer and the restore pass on main as well. They're the cover round 34 asked for.
    • I read the tests but didn't run them.
  • Merge.
    • One commit (c9c2ee2) on 307670b, which is main (merge-base confirms it). git merge-tree with main gives the head's tree (b6c15317). Web only, no migration.
    • It merges cleanly with #1553 (tree 68fd0307), which adds tests to other blocks of page.test.tsx.
      • #1553's new Fix test clicks Run Agent in the Rules tab. With this PR that notes an attempt, but the test checks only the request, and localStorage is cleared before each test.

Follow-ups:

  1. The Fix open rules pass also drops when the Length's state changes (next-step.ts:218).
    • pass.length !== length applies to both passes. That can catch the person while they do the part the path just called theirs.
    • For example, a page far under its Length:
      1. "Bring it up to your Length": the rewrite is decided, and the page is still short.
      2. Fix open rules: its changes are decided.
      3. The person writes two paragraphs, and the page comes within 30%.
      4. Next goes back to Fix open rules, for the same rules the agent couldn't close.
    • The same happens when someone trims a long page by hand. It costs one more run, or a Skip.
    • The unit test names the other direction, a Length that drifts far off ("the Length step, and Fix open rules with it"). There the page has changed a lot, and bringing the step back is right.
    • Fix:
      • Drop the Fix open rules pass on a Length change only when the Length is far off now (length !== '').
      • Clear the pass when a rewrite's page is accepted, as Start does: that's a page written again.
  2. The pass waits for every Quality read, not just the ones it compares (_draft-editor.tsx:3238-3250, :3275, :3290).
    • nextRead waits for the authors, the site's trust, the links, the facts and the page's read.
      • If the authors read fails, eeatScore stays null (:1101, :1532), and nextRead never turns true in that visit.
      • Then a decided run never passes the step: Next stays on Fix open rules, and a second run ends the same way.
      • On main the step passed at once, and only dropping stale skips waited for these reads.
    • nextRead doesn't wait for the page's last rewrite (getLastPageRewrite, :2014). That read moves the Length's state through reach.last.
      • Say it fails, or lands after the others, on a page whose last rewrite missed its Length.
      • Meanwhile a page far over its Length can read long, and its passes are dropped for good.
    • Fix: wait for what thirdPassOf reads, for both the pass and the stale drop:
      • rulesSettled;
      • citedRead;
      • a flag set once the last rewrite's read is in (in its finally).
  3. When the page opens (_draft-editor.tsx:3309-3339).
    • A newer attempt can be dropped. The read drops whatever attempt is current when it lands. Say the person runs Fix in the moment after the page opens, and the earlier run had failed or stopped: the new Fix loses its attempt.
      • Fix: drop only the attempt it read: if (thirdStepNow.current.attempt === attempt) saveThirdTry(null).
    • A Fix that found nothing while the tab was closed is kept, but never marked ended. It left no batch, so Next stays on Fix open rules until another batch is decided.
      • Fix: read it as agentOutcome does. When kind === 'fix', outcome === 'done' and !run.steps[2]?.count, save { ...attempt, ended: true }.
  4. The Remove AI traces test passes without the only check (page.test.tsx:6569-6574).
    • The pass is written 650 ms after the run, and the test checks Next right after the run.
    • Fix: add expect(stored()).toBeNull(). Without the check, the attempt is stored with ended: true. Or await settle() before the last check.
    • Also, the dropped-attempt cases pair kind: 'rewrite' with step: 'fixRules' (:6629-6630), which the editor never writes. Add a kind: 'fix' case (a tab closed mid-run), and give the rewrite step: 'length'.
  5. The pass is kept per browser (round 34's item 4). It's still open, as the PR says.

@gkhngyk
gkhngyk merged commit c00e0f0 into ansvisor:main Oct 26, 2026
6 checks passed
gkhngyk pushed a commit that referenced this pull request Oct 27, 2026
…within its Length, wait only for what a pass reads, and read a kept attempt's run by that attempt alone (#1556 review) (#1560)

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