Skip to content

fix(content): read how an agent run ended when its answer is lost, and say why a run left nothing - #1518

Merged
gkhngyk merged 14 commits into
ansvisor:mainfrom
cihan-gyk:fix/agent-run-outcome
Oct 26, 2026
Merged

gkhngyk merged 14 commits into
ansvisor:mainfrom
cihan-gyk:fix/agent-run-outcome

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Stacked on #1517. The PR's own changes are its last two commits.

In the live editor test (2026-10-25), Fix open rules once ended in "Content Agent couldn't run. Try again." (compare #1350's false failure).

The cause. When the API call's answer is lost (a gateway timeout), the editor waited up to 90 seconds for an open suggestion batch, and for nothing else. A run that finished with nothing to review never makes a batch, so it always ended in the failure toast. That happens, for example, when every change it had was in a passage AI answers quote, which it keeps word for word.

How a run ended, read from its row (_draft-editor.tsx, agentOutcome).

  • While it waits, the editor reads the run's own row (content_agent_runs): Fix's kinds only, and not the run there was before it was asked. It no longer compares clocks.
  • What it says:
    • done with nothing left: "found nothing it could change", with why;
    • stopped: "Stopped · nothing was changed";
    • failed: the failure, as soon as the row says so;
    • the batch landed: shown, as before.

Why a run left nothing (content-agent.js, emptyWhy).

  • The API answers why with a count of 0:
    • none: the model proposed nothing;
    • locked: every change it proposed was in a quoted passage;
    • dropped: the checks dropped the rest.
  • It also keeps why on the run's writing step (steps is jsonb), so an editor whose answer was lost reads it too.
  • For locked, the editor says: "Content Agent's changes were all in passages AI answers quote, which it keeps. Unlock the ones you're fine to change (Edit anyway), or change them yourself."

The card's last run.

  • After a failed run, the card says "Content Agent couldn't finish · Nothing it wrote was kept. Try again; if it fails again, fix what's left yourself." It no longer shows an earlier batch's review line.
  • That clears as soon as another run starts.

The route doc comments name why.

Related issue

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

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. On a page whose open rules sit in quoted (green) passages, run Fix open rules. It says the changes were all in passages AI answers quote, and what to do, not "couldn't run".
  2. Simulate a lost answer: block the request in the browser's dev tools after it reaches the API, or let the gateway time out on a long page.
    • A run that ends with nothing says so within seconds of its row finishing.
    • A stopped run says it stopped.
    • A failed run says it failed.
  3. After a failed run over an earlier batch, the card says the last run couldn't finish. Rebuilding the brief, or running again, clears it.

Server tests cover emptyWhy and the why answer. Web tests cover:

  • done with nothing (and why);
  • stopped or failed, read from the row;
  • the run there was before not being read as this one;
  • the card's failed line.

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

Server: format, lint, npm test. Web: yarn test and yarn build. A pre-push review ran; its findings are the last commit.

🤖 Generated with Claude Code

cihan-gyk and others added 13 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]>
@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 its two commits on #1517 (20958e4, 4a0664d), with no merge commit. With the stack, it merges cleanly on main. No migration: why goes in content_agent_runs.steps, which is jsonb (00249).
  • Why a run left nothing (API).
    • emptyWhy reads what the model proposed against the same passages and locked keys that keepSuggestions used.
      • It returns locked only when every proposal is a replace on a locked passage, which keepSuggestions drops before any other check.
      • Anything else is dropped, and an empty answer is none.
    • It runs only when no row was kept.
    • why is written on step 2, the writing step (write_changes for both fix and handoff), before finishRun, and finishRun keeps it when it adds the count.
    • Both /suggestions and /handoff answer it, since the hand-off goes through fixDraftRules.
  • The lost answer (web).
    • The previous run is read once, after the save and before the call, from Fix's kinds only. The poll then takes only a row with another id that has finished.
    • Stopped and failed come from the row at once.
    • A done row with a count of 0 is "nothing", with why.
    • A done row with a count waits for its batch, which the API inserts before it finishes the row.
    • The row is read through RLS (members of the draft's organization, 00249), on content_agent_runs_draft_started.
  • Who is told.
    • The automatic hand-off stays quiet on "nothing" and on failures, as before.
    • The card's failed line is set only when a run failed, never on a refusal (running, open suggestions, budget).
    • It clears when the card follows a new run: Fix, a hand-off or the brief.
  • API and web out of step. The web takes why only as one of its three values (fixEmptyWhy, agentRunFrom); anything else reads as the plain "nothing". An older web ignores why.
  • Before the API with this PR is deployed. Nothing breaks.
    • The prod API already writes the run's row with its outcome and the writing step's count. So a run whose answer is lost and that left nothing now says "Content Agent found nothing it could change without new facts." instead of "couldn't run".
    • A stopped run says it stopped, and a failed one says so as soon as its row does.
    • The card's failed line works at once.
    • Only the "all in passages AI answers quote" line waits for the deploy.

Low, follow-up (please fix before Quality phase 3 goes on):

  1. _draft-editor.tsx:2383: Hand off sends the customer cases' paragraphs as locked, so emptyWhy (content-agent.js:486) also reads a change on a customer case as locked.
    • The person then reads "…all in passages AI answers quote… Unlock the ones you're fine to change (Edit anyway)". But a customer case isn't quoted by AI answers and has no Edit anyway.
    • When a hand-off sent cases, say it more broadly for locked, e.g. "…all in passages the page keeps as they are (quoted by AI answers, or your customer cases)…".
    • Or send the cases apart from locked, so the API can tell them from cited passages.

@gkhngyk
gkhngyk merged commit f59ab40 into ansvisor:main Oct 26, 2026
4 of 5 checks passed
@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 26, 2026
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