Skip to content

fix(content): refuse a Start or a page rewrite while a Fix open rules runs on the draft - #1525

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:fix/start-waits-for-fix
Oct 26, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:fix/start-waits-for-fix

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

From main, independent of the open editor chain; no conflicts with it.

startDraftWriting (content-writer.js) is behind the editor's Start / Try again, Rewrite page, and the New content dialog's Start. It refused a run while the draft is being written, and (for a live page or a rewrite) while suggestions are open. But it didn't refuse while a person's Fix open rules is still under way on the same draft, for example from another tab. Then:

fixDraftRules already refuses the other way round: beside a Start (409 writing) and beside another fix (409 running, fixUnderWay). Found in the pre-push review of #1524.

Server

  • startDraftWriting refuses with 409 running while a Fix or Quality's hand-off is under way on the draft (fixUnderWay).
  • It does this for every method, before anything is held on the AI budget, claimed or called.
  • The checks before it are unchanged. A draft already being written still answers writing, and open suggestions still answer open_suggestions.
  • A stopped fix no longer counts as under way (fixUnderWay adds stopped_at is null). Its batch is dropped anyway (stopIfStopped).
    • Without this, a Stop on the waiting page could be followed by up to 10 minutes of false "fixing" refusals, when the run's row stayed open after a restart.
    • The same holds for Fix open rules after a stopped fix, which had that wait already.
  • Two comments said a Fix holds no claim on the draft (stopDraftRun, the stop route). They now say that a live page's Start runs as a Fix and holds its own. The 409 lists in the route and function docs name running too.

Web

  • running is a known start error (AGENT_WRITE_ERRORS), so it's said, not shown as "couldn't start".
  • The editor says: "Content Agent is fixing this page, maybe from another tab. Try again once it has finished."
  • The New content dialog, whose drafts are new, says it neutrally: "The agent is already working on this page…"

Related issue

Follow-up to the editor test findings 2026-10-25 (#1524's review).

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 in two tabs. In tab A, run Fix open rules with Agent.
  2. While it runs, press Rewrite page in tab B, or Try again / Start on a draft the agent couldn't finish. Tab B says Content Agent is fixing this page and doesn't start. Nothing is charged.
  3. Once the Fix has finished, decide its suggestions. The Rewrite or Start then runs as before.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • npm run lint passes (run from server/)
  • npm test passes (run from server/)
  • 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 too. Tests:

  • server: a Start (new page and live page) and a rewrite are refused while a Fix runs, with nothing held, claimed or called, and a Start goes once it has finished;
  • server: fixUnderWay leaves stopped runs out;
  • web: 409 running maps to the running error.

A pre-push review ran; its fixes are the last commit. After it: server format, lint and npm test in full; web lint, typecheck and the affected tests.

🤖 Generated with Claude Code

cihan-gyk and others added 2 commits October 26, 2026 01:08
…nce after Stop; neutral dialog wording; 409 codes in the docs (pre-push 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:

  • Where it refuses. startDraftWriting answers 409 running while a Fix open rules or a hand-off is under way on the draft (content-writer.js:396-401).
    • It applies to a new page's Start, a live page's Start and a rewrite.
    • It runs after not_draft, writing and open_suggestions. It runs before the AI budget hold, the claim and the run row, so a refusal costs nothing and holds nothing.
    • The new test covers all three cases, and a Start once the Fix has finished.
  • No false refusals from its own runs.
    • A live page's Start runs as fix and holds a claim. A second Start is refused as writing before this check.
    • A writing run finishes its row however it ends (done, stopped or failed). So Try again after a failed live-page Start goes at once.
    • A row left by a server that stopped counts for 10 minutes at most, the same window as a stale writing claim.
  • Stopped runs. fixUnderWay now leaves out stopped runs (content-runs.js:61).
    • A stopped run's batch is dropped before it's written (stopIfStopped comes before the suggestions insert). So a Start or a Fix may go right after Stop.
    • Fix open rules' own running refusal benefits too. Before, it waited out a stopped run.
  • Web. running is in AGENT_WRITE_ERRORS, with words in both places that show these errors:
    • the editor's agentFailed.errors, for Try again and Rewrite page;
    • the New content dialog's start.agentErrors.
    • In the editor, a Fix or hand-off in the same tab already holds Start and Rewrite (agentBusy). The server's refusal only shows for another tab's run, as the words say.
  • Merge. It merges cleanly on main, alongside #1511, and on top of the editor chain's last PR (#1526). CI passes.
  • Before the API is deployed, nobody sees a change: the live API never answers running on these routes. After the deploy, a Start or Rewrite during another tab's Fix is refused with the new words, instead of running beside it.

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