Skip to content

fix(content): restore once, and let the agent's batch go with the page before - #1522

Merged
gkhngyk merged 37 commits into
ansvisor:mainfrom
cihan-gyk:fix/restore-clears-agent
Oct 26, 2026
Merged

gkhngyk merged 37 commits into
ansvisor:mainfrom
cihan-gyk:fix/restore-clears-agent

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Stacked on #1521. The PR's own changes are its commits after #1521's branch.

In the live editor test (2026-10-25), Restore brought back the right page (7,098 → 15,824 characters), but:

  • History showed two "Before a restore" versions in the same minute. Restore had been clicked a few times while the first one ran.
  • The agent card stayed afterwards, with the old "Last run … 5 accepted" and an Undo all over changes the restored page didn't have.

Restore once. A ref is set on the first click, before the next render (restoringNow), so a second click while it runs does nothing. History's menu was already disabled by state, but only from the next render on.

The agent's batch goes with the page before.

  • After a restore, the agent's open suggestions are rejected on the server (decideDraftSuggestions(…, 'rejected')). They were for the page before. Left open, they would hold the next Fix run (open_suggestions).
  • If that call fails, they stay open, on the card, for the person to decide. They are never shown as set aside while the server still has them open.
  • The card closes as if its X was pressed (barClosed), with its Last run and Undo all. A new batch opens it again, as it does today.

History waits while the agent works (Fix) or a decision on its changes saves. A restore at that moment would reject the same suggestions under the decision. The button's tip says why:

  • "Content Agent is working on the page. History opens once it's done."
  • "Saving your decision on the agent's changes…"

Related issue

Editor test findings 2026-10-25 (group H).

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. Open a draft with a few versions in History. Click a version's Restore two or three times quickly. History then lists one new "Before a restore".
  2. Run Fix open rules with Agent and leave its suggestions open. Restore an earlier version. The card goes. The next Fix runs (no "open suggestions" error).
  3. Run Fix again and Accept all. Restore the version from before the agent. The card's "Last run … accepted" and Undo all are gone.
  4. While Fix runs, or right after Accept all while it saves, hover History. It is disabled and says why.

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 are in files this PR doesn't touch
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Web: yarn test and yarn build. A pre-push review ran; its findings are the last commit. A browser check at 1024 px in both themes is batched with #1513–#1521.

🤖 Generated with Claude Code

cihan-gyk and others added 24 commits October 25, 2026 21:35
…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]>
…er to rewrite the cited passages too when they hold the Length out of reach

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e back, release an unused hold, keep a cited-too miss as evidence, and offer it only when cited passages hold the Length (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…he agent and Next step move on, and count open rules as the Rules tab does

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…es read the page, keep the Length's own words, and wait for the passages before dropping skips (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ion, not the next step, and say how many placeholders it leaves to fill

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…aphs, and read a rewrite's once, not on every key (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y why a run left nothing, and show a failed last run on the card

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… id and kind, not by clocks, and clear a failed last run once another starts (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e rules before they're accepted, and say which rule met now one would break

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…age as it is now, and count a rewrite's Length as its own line reads it (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…wasn't given or drops a name a passage has

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…give claims only to sources the page or its input names, and put a rewrite's as a placeholder (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…editor shows them, and hold the rules chip until its count stands

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…aracters as the toolbar counts them, and the run's rule count

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…for the brief and catalog before the rules' count, hold the panel's counts with it, and read the shown rewrite's Length by the editor's count (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s open suggestions for the page before, and drop a batch's card once the page no longer has it

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e left open never holds the next run out of sight

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…estions when they can't be set aside, and hold History while the agent works or a decision saves (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 25, 2026

@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.

What I checked:

  • Stack. The PR's own change is three commits on #1521's head (697f9e7): cf0adfa, fcae3b5 and 3f50c86. There are no merge commits, and the chain sits on main, so it merges cleanly with its stack. It's web only, with no migration of its own. The needs-migration label comes from #1514 (00285) further down the stack.
  • Restore once. restoringNow is set before the first await, so a second click returns at once. It's cleared in finally, so a restore that failed can be tried again. The test clicks twice and gets one restore.
  • Setting aside the open suggestions.
    • Only the batch's open suggestions go, and only after the page is restored. They go through content_draft_decide_suggestions (00217, already on prod), which checks the caller is a member of the draft's organization.
    • The cards change only once that call succeeds. When it fails, they stay open on the card, which matches what the server still has.
    • An open page rewrite is set aside by its status only, as decidePage's Reject does.
    • The server never feeds rejected suggestions into a later run, so setting them aside teaches the agent nothing.
  • The card. It closes the way its X closes it. If open suggestions are left because the set-aside failed, they keep it showing (barClosed && openSuggestions === 0). A new batch opens it again (setBarClosed(false) in runAgentFix).
  • History waits while fixing is set and while deciding is set:
    • fixing covers Fix open rules and both kinds of hand-off, since they all go through runAgentFix.
    • deciding covers both decide and decidePage.
    • The two new tips are in en.json.
  • Before the API deploy. Nothing here calls the API: the restore and the decisions are Supabase RPCs that are already on prod. Nothing changes with an older API.

Low, follow-up:

  1. The other way round (_draft-editor.tsx:3740, and the agent's starts). History now waits while a decision saves, but nothing waits while a restore runs (autosave.settle and the RPC). During a restore, the card's Accept all, Reject all, Undo all and Fix still work (busy={deciding || htmlSource !== null}).
    • Accept all in that window. It's saved as accepted and then made again on the restored page, wherever it fits there. Meanwhile the restore sets the same ids aside, from a suggestionsNow read taken before the decision lands. Which status sticks depends on which call lands last.
    • Fix in that window. It can read the page from before the restore and leave a batch for that page.
    • Fix: pass busy={deciding || restoring || htmlSource !== null}, and return early from fixRules, handOff, startAgent and rewritePage while restoringNow.current is set.
  2. The set-aside is silent (_draft-editor.tsx:3271-3290). The batch disappears with the card, and the toast only says the version was restored. That batch counted toward AI usage, and a restore often keeps most of the page, so many of its changes may still apply. When any were set aside, say so in the toast, e.g. "Restored “{version}”. The agent's 4 open changes were for the page before, so they were set aside." Use a plural variant of history.restored.
  3. After a reload the card is back (_draft-editor.tsx:1706-1712 and :429). barClosed lives only in this tab. After a reload, or in another tab, the editor reads the latest batch again and shows its card, with the old "Last run … accepted" and Undo all over the restored page. That's the case the editor test reported. On a page from before the agent, Undo all then finds nothing to undo and returns without a word (changed.length === 0). Fix it in one of two ways:
    • open the card closed when the latest batch is older than the draft's latest restore version;
    • or have getDraftSuggestions return nothing for such a batch.

cihan-gyk and others added 3 commits October 26, 2026 10:11
…ead "per" only as an attribution, "claims" and "states" only before "that", and "göre" not as a comparison; keep a change that keeps every name worded or cased another way, or as bullets; know a source by its possessive, never its last word alone; let the prompts name Your input as a source (review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Thanks. All three follow-ups go into one follow-up PR on top of the chain:

  • the card's buttons and the agent's starts wait while a restore runs;
  • the toast says how many open changes were set aside (a plural history.restored);
  • the card opens closed when the latest batch is older than the latest restore.

This branch now also has #1520's review fixes merged in.

@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Merged the PR below it forward (f8ecc22), which brings in main now that #1514–#1519 are in. No conflicts; its diff against main is its own files again.

Checks after the merge:

@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 26, 2026

@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 new head, f8ecc22, only merges #1521's new head (6d3db71), and through it main. Re-merging its parents (48d77e7 and 6d3db71) is clean and gives the commit's tree (d45716a9), so the merge hides nothing. Its own change against #1521 is the same as in round 31, line for line. With its stack, it merges cleanly on main. Round 30's low follow-ups are done in #1536. The verdict stands.

@gkhngyk
gkhngyk merged commit b25e60f into ansvisor:main Oct 26, 2026
4 of 5 checks passed
gkhngyk added a commit that referenced this pull request Oct 26, 2026
…restore set aside, and open a pre-restore batch's card closed (#1522 follow-ups) (#1536)

* fix(content): read a Length's reach from what a rewrite keeps, the headings' answers and what the last rewrite came to, and offer a Length it can reach

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): count the last rewrite only for the Length it was asked 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]>

* fix(content): name kept blocks only when they alone miss the Length, 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]>

* feat(content): cut a page rewrite that came well past its Length with one more pass

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* feat(content): say when a shortening rewrite came out longer, and offer to rewrite the cited passages too when they hold the Length out of reach

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): take a cut only when restoreKept can put every kept line back, release an unused hold, keep a cited-too miss as evidence, and offer it only when cited passages hold the Length (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): leave rules held by quoted passages to the person, so the agent and Next step move on, and count open rules as the Rules tab does

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): read a sentence rule held by quoted passages as the rules read the page, keep the Length's own words, and wait for the passages before dropping skips (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): head the agent card with the result waiting for a decision, not the next step, and say how many placeholders it leaves to fill

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): count placeholders in list items written without paragraphs, and read a rewrite's once, not on every key (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): read how an agent run ended when its answer is lost, say why a run left nothing, and show a failed last run on the card

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): keep why a run left nothing on its row, read its row by id and kind, not by clocks, and clear a failed last run once another starts (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): check the agent's changes and a page rewrite against the rules before they're accepted, and say which rule met now one would break

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): check Accept all as it takes the changes, against the page as it is now, and count a rewrite's Length as its own line reads it (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): keep no agent change that gives a claim to a source it wasn't given or drops a name a passage has

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): read a dropped name only in a list, check inserts too, give claims only to sources the page or its input names, and put a rewrite's as a placeholder (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): count the rules and a rewrite's characters the way the editor shows them, and hold the rules chip until its count stands

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(content): cover the rules chip holding its count, a rewrite's characters as the toolbar counts them, and the run's rule count

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): show the rewrite's toolbar counts in Compare too, wait for the brief and catalog before the rules' count, hold the panel's counts with it, and read the shown rewrite's Length by the editor's count (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): restore once for two quick clicks, set aside the agent's open suggestions for the page before, and drop a batch's card once the page no longer has it

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): keep the agent's card while a suggestion is open, so one left open never holds the next run out of sight

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): close the agent's card on a restore, keep its open suggestions when they can't be set aside, and hold History while the agent works or a decision saves (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): move the agent's waiting page while it works: its tile, a sweep on the step under way, a line on what it does, and the page drawn in

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): keep the waiting page's lines short enough for one line, true without an outline, and silent on rules or sources read none of; even step spacing; steadier tests (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): show a live page's Start on the agent's waiting page, which runs as a Fix, with its steps and Stop

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): test that a new page's rewrite still shows its run and a Start's write doesn't stand in for it; the rewrite prop says what it reads (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): read what the last rewrite came to by the editor's count once it's decided too, not only while it's shown

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): the last rewrite's action tests read its page too; comments say when it's read and who counts it (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): end a source's or a list item's name at its sentence; read "per" only as an attribution, "claims" and "states" only before "that", and "göre" not as a comparison; keep a change that keeps every name worded or cased another way, or as bullets; know a source by its possessive, never its last word alone; let the prompts name Your input as a source (review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): hold the agent card and the agent's runs while a restore runs, say how many open changes the restore set aside, and open the card closed for a batch from before the last restore (#1522 review follow-ups)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): know a source named after a role or an adverb ("CEO Jane Doe", "Recently Gartner"), keep a sentence's first word out of a placeholder, read "per" on English pages only, read "U.S." as one name, and start a name only at a word's start (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(content): time the long run of capitals with Date.now, as lint knows it

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): hold the cards on the page and the agent's starts while a restore runs, set nothing aside for a restore of the page as it is, and read the last restore from content_drafts.restored_at (00289), which every restore that changes the page sets (review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(content): have the restore say whether it changed the page, keep restored_at the server's (guard_content_draft_server_columns), and say "nothing changed" for the page as it is (review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[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