Skip to content

fix(content): hold the agent card while a restore runs, say what the restore set aside, and open a pre-restore batch's card closed (#1522 follow-ups) - #1536

Merged
gkhngyk merged 61 commits into
ansvisor:mainfrom
cihan-gyk:fix/restore-followups
Oct 26, 2026
Merged

gkhngyk merged 61 commits into
ansvisor:mainfrom
cihan-gyk:fix/restore-followups

Conversation

@cihan-gyk

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

Copy link
Copy Markdown
Collaborator

Summary

Follow-ups from the review of #1522 (restore guard). Stacked on #1526, the tip of the #1514–#1526 chain. This PR's own change is its commits after #1526's branch.

gkhngyk listed three low follow-ups on #1522. All three are here, web only:

  1. Nothing else runs during a restore. History already waited while a decision saved; now the reverse holds too:

    • while a restore runs, the agent card's buttons are busy (busy={deciding || restoring || htmlSource !== null});
    • Fix open rules, Hand off, Start and Rewrite page return at once while restoringNow is set.

    Without this, an Accept all landing during a restore could be saved as accepted, then set aside by the restore, whichever call landed last. A Fix could also read the page from before the restore.

  2. The toast says what was set aside. The open changes are set aside first, and the toast then reads, for example: "Restored “Live page”. The agent’s 4 open changes were for the page before, so they were set aside." With none set aside it reads as before: "…The page before it is in History." history.restored is now an ICU plural on count.
    After a review of this PR (second commit):

  • The cards on the page wait during a restore too: decide and decidePage return while it runs, and the Fix, Hand off, rewrite and Next step reasons say "Restoring…", so their buttons read as held. Try again is held too.

  • Restoring the version the page already is sets nothing aside, leaves the card open, and says "“…” is the page as it is: nothing changed." The server says so: content_draft_restore now returns restored: false. A database before 00289 doesn't, and then the editor compares the page itself.

  • Migration 00289:

    • adds content_drafts.restored_at;
    • re-creates content_draft_restore (00215's) to set it each time the page changes, and to return whether it did;
    • re-creates guard_content_draft_server_columns (00262's) so a member can't write it, as with the other server columns.

    getLastRestoreAt reads restored_at. A "restore" version can't say when a restore happened: one is kept only when the page differs from the latest version, so a restore right after Mark ready or an Undo all left none.

    There's no backfill: an update to content_drafts moves its updated_at (the Library's order, an open editor's save base), and fix(content): restore once, and let the agent's batch go with the page before #1522 hasn't shipped. 00289 is applied on the dev database, and schema.sql and types/supabase.ts are updated. Labelling it needs-migration is for you, @gkhngyk.

  1. The card stays closed after a reload.
    • New action: getLastRestoreAt(draftId) reads the draft's restored_at (00289), one row through RLS.
    • On open: when the latest batch is older than that restore, the editor opens its card closed. That's the same state the tab that restored it left, so the old "Last run … accepted" and Undo all no longer show over the restored page.
    • What still shows: open changes a failed set-aside left are still on the card to decide. A batch run after the restore shows as before. A restore that can't be read leaves the card as it was.
    • What it doesn't change: getDraftSuggestions is unchanged, so the side panel's "Last used by Content Agent" and the agent's own polling read the batch as before.

Related issue

Follow-ups to #1522 (review 2026-10-26). Editor test 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 an agent batch that has open changes, and restore a version from History. While it restores, the card's Accept all is disabled. Then the toast says how many open changes were set aside, and the card closes.
  2. Reload the editor. The card stays closed.
  3. Run Fix open rules again. The new batch's card opens as usual.

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/)
  • Migration added as a new file (00289); bash supabase/build-schema.sh run and supabase/schema.sql included
  • Changes are focused — one concern per PR

Web: yarn test (3,984 passed) and yarn build. 00289 is applied on the dev database.

Tests:

  • the card's Accept all is disabled while a restore runs, and the restore alone sets the open change aside;
  • the toast says what was set aside;
  • after a reload, the card is closed for a batch from before the last restore;
  • the card still shows with open changes, for a batch after the restore, and when the restore can't be read;
  • getLastRestoreAt reads the latest restore version.

Two reviews ran after opening. Their findings are fixed in the later commits (above).

🤖 Generated with Claude Code

cihan-gyk and others added 30 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]>
… 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]>
…, 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]>
…hich runs as a Fix, with its steps and Stop

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…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]>
…t once it's decided too, not only while it's shown

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ents say when it's read and who counts it (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 26, 2026
cihan-gyk and others added 2 commits October 26, 2026 10:57
… 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]>
…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]>

@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 #1526's branch: 0981c74, 2214640 and 8ad3c70. Its two merges (6cce798 and a119152) only bring #1526's branch in: re-merging their parents gives the same trees. With its stack it merges cleanly on main as it was before #1514's squash. #1514's squash on main is exactly #1514's head merged there, so it follows the rest of the chain.
  • #1522's three follow-ups:
    1. Nothing else runs during a restore. Done.
      • The card's buttons are busy while it runs (_draft-editor.tsx:3777), and Try again is disabled (:3730).
      • decide, decidePage, fixRules, handOff, startAgent and rewritePage return while restoringNow is set. That covers the buttons on the page too.
      • Fix, Hand off, Start, Rewrite page and Next step give "Restoring…" as the reason.
      • History already waits while fixing or deciding is set, so a decision and a restore can't overlap from either side.
    2. The toast says what was set aside. Done. history.restored is an ICU plural on count, and this is its only use. The count is what was actually set aside. It's 0 when the set-aside failed and the changes stay on the card, so the toast never claims something that didn't happen.
    3. The card after a reload. Done. It uses a better signal than the one I suggested: restored_at, written by the restore itself. A restore version isn't kept when the page repeats the latest version.
      • The card opens closed only when the latest batch is older than restored_at (:1712-1717).
      • Open changes still show.
      • A batch run after the restore shows as before.
      • If the read fails, the card shows as before.
  • Restoring the page it already is. content_draft_restore already left such a draft alone. It now says so (restored: false), so nothing is set aside, the card stays, restored_at doesn't move, and the toast says nothing changed (:3300-3325).
  • 00289:
    • restored_at is nullable, with no default. Adding it only changes the catalog and doesn't rewrite content_drafts. There's no backfill, so no draft's updated_at moves.
    • content_draft_restore matches 00215's version line for line, plus restored_at and restored. It keeps the same member check (content_draft_member), search_path and grants: authenticated and service_role, never anon.
    • guard_content_draft_server_columns is 00262's version plus restored_at, on insert and on update. 00262's is the latest; no later migration or open PR redefines it. A member can't set the column through the table. The restore writes it as the function's owner, which the guard lets through, as it does for migrations.
    • It can run twice safely (if not exists, create or replace). No other open PR uses 00289. schema.sql and types/supabase.ts match it.
  • The read. getLastRestoreAt (content-drafts.ts:1719) reads one column of one row by id, through content_drafts' member policy. It runs in parallel with the batch read when the editor opens.
  • Before 00289 is applied. The read fails, and the card shows as it does today. The restore returns no restored, so the editor compares the page itself. Merging before the migration breaks nothing that works today. Applying the migration first is safe too, since the current editor ignores the new field.
  • Before the API deploy. This is web and a migration only, and it calls no API route. Nothing waits on the deploy.
  • Tests:
    • Accept all is disabled, and Accept on the page does nothing, while a restore runs;
    • Try again is held;
    • the toast for one change and for two;
    • nothing is set aside when the version is the page as it is;
    • the card is closed after a reload for a batch from before the restore;
    • the card shows with open changes, for a batch after the restore, and when the read fails;
    • the toast when the set-aside fails;
    • getLastRestoreAt, and restored passed through.

No findings.

@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Merged #1526 forward (9af7e25), which brings in main now that #1514–#1519 are in. No conflicts. schema.sql matches build-schema.sh (00289 is still this PR's own migration).

Checks after the merge:

@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, 9af7e25, only merges #1526's new head (c149612), and through it main. Re-merging its parents (8ad3c70 and c149612) is clean and gives the commit's tree (2b652fb2), so the merge hides nothing. Its own change against #1526 is the same as in round 31, line for line.

00289 is unchanged since 8ad3c70, and so are schema.sql and types/supabase.ts. None of the other open migrations (00286–00288 and 00290) redefines content_draft_restore or guard_content_draft_server_columns, so the order they're applied in doesn't matter. With its stack, it merges cleanly on main. Round 31's verdict stands.

@gkhngyk
gkhngyk merged commit a443462 into ansvisor:main Oct 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants