Skip to content

fix(content): keep Next's Fix open rules passed while the page comes within its Length, wait only for what a pass reads (#1556 review) - #1560

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/next-step-pass-reads
Oct 27, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/next-step-pass-reads

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Follow-ups to #1556's review: how the Next step basket's third step (Fix open rules, or the Length) stays passed once the agent took it.

1. Fix open rules holds while the person brings the page within its Length (next-step.ts, thirdStepPasses).

  • Before, any change in the Length's state dropped both passes. Say the rewrite and Fix were decided on a page far under its Length, and the person then wrote two paragraphs and came within 30%. Next went back to Fix open rules, for the same rules the agent couldn't close.
  • Now the Fix open rules pass drops on a Length change only when the Length is far off now and reads differently from when it passed. A Length that drifts far off still brings the step back. The Length's own pass still drops on any change.
  • Accepting a rewrite's page clears the passes, as Start does: that's a page written again (decidePage). The rewrite's own attempt stays, so it still passes its step.

2. The pass waits only for what it compares (_draft-editor.tsx).

  • The pass and the stale-pass drop waited for nextRead: the authors, the site's trust, the links, the facts and the page's read. If one of these failed (the authors, say), E-E-A-T never read, nextRead never turned true, and a decided run never passed the step.
  • Now they wait for thirdRead: the rules settled, the quoted passages (which hold some rules), and the page's last rewrite. The last rewrite moves the Length's state through its reach, and nextRead didn't wait for it.
  • The last rewrite's read is kept per rewrite shown (lastRewriteReadFor, set in its read's finally). When a new rewrite shows, the pass waits for its re-read, not the one before.

3. When the page opens.

  • The read of a kept attempt's run changes only that attempt. A Fix begun while the read was out is the newer run's, and is no longer dropped when the earlier run turns out failed or stopped.
  • If that newer Fix then doesn't run, it puts back the earlier attempt as the read found it (attemptRead), not as it was. An attempt found failed stays gone.
  • A Fix that found nothing while the tab was closed (outcome: 'done', nothing written) is read as agentOutcome reads it, and marked ended. Before, it left no batch and was never marked, so Next stayed on Fix open rules.

4. Tests.

  • The Remove AI traces case asserts nothing is stored, and settles before its last check. It now fails without the only check.
  • The dropped-attempt cases give a rewrite step: 'length' and add kind: 'fix' (a tab closed mid-run).
  • New cases, one per fix above. Each fails with its fix undone; I checked all eight, and the unit test.

Still open, as in #1556: the pass is kept per browser (round 34's item 4).

Related issue

Follow-ups to #1556 (review items 1–4).

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. cd web && yarn vitest run src/lib/content/next-step.test.ts 'src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx' -t "Next step basket|third step"
  2. In the editor, on a page with open rules and a Length far under it:
    • run Rewrite, accept it, then Fix open rules, and decide its changes. Next moves to proof;
    • add text by hand until the page is within its Length. Next stays on proof (before, it went back to 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/)
  • 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,088 tests) and yarn build, both pass.

🤖 Generated with Claude Code

…within its Length, wait only for what a pass reads, and read a kept attempt's run by that attempt alone (ansvisor#1556 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.

The #1556 review's four follow-ups:

  1. The Fix open rules pass dropped when the Length's state changed: Done.
    • thirdStepPasses now skips a pass on a Length change only for the Length's own pass, or when the Length is far off now (next-step.ts:221). So a Fix open rules pass taken at short or long holds once the page comes within 30% (''), and still drops when the page goes far off the other way, or far off from a pass taken within.
    • The rule check is unchanged (:222): a rule opened since still brings the step back.
    • Accepting a rewrite's page clears the passes and keeps the rewrite's attempt (_draft-editor.tsx:2346-2350). The attempt then passes the Length step on the new page. For a rewrite, the card offers only its own Accept, Reject and Undo and the compare dialog, not Accept all (_agent-card.tsx:622-657, :701-709). So decidePage is the only place a rewrite is accepted.
  2. The pass waited on every Quality read, but not the last rewrite's read: Done.
    • The pass and the stale drop wait for thirdRead = rulesSettled && citedRead && lastRewriteRead (:3291, :3297, :3313). That covers everything thirdPassOf reads:
      • the rules: My rules, the sources, the brief and the catalog;
      • the quoted passages, which hold the Sentence rule;
      • reach, which moves the Length's state.
    • The rules read only the brief and the sources (_use-draft-rules.ts), so leaving Quality's reads out doesn't let a pass be written before a rule can change.
    • The last rewrite's read is tracked per rewrite shown (lastRewriteReadFor, set in finally unless cancelled, :2018-2029). A failed read still counts as read. A catalog read that fails sets null, not undefined, so rulesSettled can't hang on it.
    • staleSkips still waits for nextRead, as it should: a proof skip reads Trust.
  3. When the page opens: Done.
    • The read changes only the attempt it read (:3356). A Fix begun meanwhile keeps its own.
    • Beyond what the review asked, attemptRead (:456, :3355) lets that newer Fix's untried put back the earlier attempt as the read found it (:2465-2469). An attempt found failed stays gone, and one found ended comes back ended. The identity check holds: the effect, beginThirdTry's prev and untried all pass the same object.
    • A Fix found done with nothing written is marked ended (:3352), as agentOutcome reads it (:349).
  4. Tests: Done.
    • The Remove AI traces case checks stored() is null before and after settle() (page.test.tsx:6627-6631).
    • The rewrite cases take step: 'length', and two fix cases are added (:6680-6735). The stored attempt being null is what guards a rewrite case now: with the Length off in this fixture, a kept rewrite attempt wouldn't move Next anyway.

What I checked:

  • Whether a pass now holds when it shouldn't.
    • A rule the agent never saw still drops the pass, whatever the Length does.
    • A page that goes far off since the pass, in either direction, drops it. Say the pass was taken at short and the person writes far past the Length: long drops it (unit test, next-step.test.ts:311).
    • A page that comes back to the same far-off state as the pass (short, then within, then short again) keeps the Fix pass. That doesn't hide anything: the Length's own pass was already dropped for good when the page came within, so Next shows the Length step first. Its accepted rewrite then clears the Fix pass.
    • Accept, then Undo, of a rewrite leaves the earlier Fix pass cleared, so Fix open rules can come back on the page from before. That costs one Skip, and it's rare. No change needed.
    • No loop. The stale drop only removes passes, and each attempt writes its pass once (the attempt goes to null). The accept clear runs once per decision. While the rewrite's page is open, thirdTaken is false, so no older timer can write over the clear.
  • Stored state. The format is unchanged: aeo:next-step-third-try:{draftId} holds { attempt, passes }, and ThirdPass is { rules, length }.
    • A pass #1556 wrote reads the same way, and now holds in more cases. A #1556 tab that has already dropped such a pass for good doesn't bring it back.
    • A Fix attempt that #1556 stored and that found nothing while the tab was closed passes on the first open with this build.
    • attemptRead is a ref and isn't stored.
    • A tab still on #1556's build reads this build's store without trouble. It drops a Fix pass on a Length change that this build keeps. That's harmless.
  • What the person sees. This is only visible with Quality phase 1 or later, where the basket shows.
    • Brings the page within its Length by hand after the agent took Fix open rules: Next stays on the step after it.
    • Accepts a whole-page rewrite: a Fix open rules pass from the page before is gone, so Fix open rules comes back if rules are still open.
    • The authors or another Quality read fails: Next still moves on once the run is decided.
    • A Fix that found nothing while the tab was closed: Next moves on when the page opens.
  • The deploy gap. None. Web only, with no new API field.
    • The reads are on main and prod already: getLastPageRewrite (00285) and readAgentRun's steps, outcome and stopped_at (00249).
    • The API on prod already writes a Fix run's write count at steps[2], which agentOutcome reads too.
  • Speed. No regex. The loops run over at most two passes and the open rules' keys.
  • Tests.
    • The unit test fails on main: there, the Fix pass taken at short drops at ''.
    • These page tests fail without their part of the change:
      • Remove AI traces, without the only check;
      • the Fix that found nothing: on main, its attempt stays unended;
      • the Fix begun while the read was out: main drops it;
      • the attempt not put back: without attemptRead, the failed attempt comes back;
      • both waits for the last rewrite: main writes the pass first;
      • the failed authors read: nextRead never turns true on main;
      • the accept clear.
    • The two fix dropped-attempt cases pass on main too. They're the cover the review asked for.
    • I read the tests but didn't run them.
  • Merge.
    • One commit (d188b1d) on c00e0f0, #1556's squash. Main's 3b650fb adds #1544 on top, server only. git merge-tree with main is clean (7b1fd25d).
    • It merges cleanly with #1566 (_next-step.tsx, tree 438cdb18). #1566 adds a line-through span around the step's name, and the text the tests read stays the same.
    • It also merges cleanly with #1558 (page.test.tsx, tree 5411e202). #1558's hunk is in the Fix run's Length hint test, apart from these.

Still open from #1556, as the PR says: the pass is kept per browser (round 34's item 4).

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