Repository navigation
fix(content): don't say the Content Agent couldn't run while it is still at work - #1350
Conversation
…ill at work Fix open rules waits on the agent's model call (up to 60 s), and an answer lost on the way, a platform timeout, read as "Content Agent couldn't run" while the API went on and left its suggestions. The editor's segment now allows 300 s, as the API proxy's long routes do. When the answer doesn't come back (the call threw, or a gateway answered without the API's code), the editor looks for the agent's batch every 5 s for 90 s and shows it, saying it couldn't run only if none lands. The API's own errors are shown at once. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@gkhngyk this is item 8 from the editor feedback. I worked out the cause from the code, since I can't see the logs: if Vercel's logs show the editor's server action timing out around Fix open rules, that confirms it. The fix is maxDuration 300 on the editor segment, plus a 90 s look for the agent's batch when the answer doesn't come back. The API's own errors are unchanged. |
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good. Three small follow-ups.
web/src/lib/actions/content-drafts.ts:1563: any failed answer without acodebecomesunconfirmed. That includes the API's own 401: the auth middleware answers{ message }, for example on an expired session. The editor then waits 90 s before saying "couldn't run", for a run that never started. Keepunconfirmedfor the cases where the run may have gone on: 502, 503 and 504, and a thrown fetch (:1570). Any other uncoded answer should stayfailed._draft-editor.tsx:123and:595: the wait doesn't stop when the editor unmounts. If the person leaves the page or opens another draft, it keeps reading suggestions every 5 s. Up to 90 s later it toasts "suggested N changes" or "couldn't run" on whatever page they are on. Stop it on unmount: check a mounted ref in the loop and before the toasts, or pass anAbortSignal.web/src/lib/actions/content-drafts.test.ts:624: the action's new mapping has no test. Cover these cases:- a 504 with an HTML body, and a thrown
fetch, both givingunconfirmed; - a 401 with
{ message }, givingfailedonce item 1 is done; - a coded 402, still giving its code.
- a 504 with an HTML body, and a thrown
The maxDuration = 300 in the segment's layout.tsx matches api/aeo/[...path] and api/agent/chat. The page is a client component, so the layout is the right place for it. The editor tests cover a batch that lands late and one that never lands.
Merge notes
- Merges cleanly on main and with #1346, #1347, #1348, #1349, #1351 and #1353. No migration.
- With #1346: the two new tests click
'Fix open rules with agent'(page.test.tsx:1670and:1697). After #1346 that label is'Apply rules with Agent'. There's no textual conflict, but the tests fail until the label is renamed. It's easiest to merge this before #1346 and rename them there.
Tested on top of main together with #1353, #1347, #1348, #1350 and #1351: web and server tests, tsc, lint and Prettier pass.
Summary
Content Editor feedback item 8: Fix open rules with agent said "Content Agent couldn't run. Try again." while the agent was still working, and its suggestions showed up later.
Cause (from the code; I couldn't see the production logs): Fix open rules is synchronous. The server action calls
POST /api/content-drafts/:id/suggestionsand waits for the model call, whichcontent-agent.jscuts at 60 s. When the answer is lost on the way (the page's function hitting the platform's time limit, or a gateway timeout), the editor's catch shows "couldn't run". Meanwhile the API finishes and inserts its batch.Fix:
content/editor/[draftId]/layout.tsxexportsmaxDuration = 300, asapi/aeo/[...path]andapi/agent/chatdo. That covers the page's server actions.fixDraftRulesnow returns a newunconfirmederror in two cases: the fetch threw, or the response wasn't the API's JSON with acode(a gateway's page). The editor treats a thrown action the same way.unconfirmed,fixRulesreadsgetDraftSuggestionsevery 5 s (AGENT_POLL_MS) for up to 90 s from the click (FIX_WAIT_MS, past the 60 s call and the batch's save).ai_budget,no_subscription,empty,open_suggestions,published, andfailedwith its code.Related issue
Content Editor feedback round (no issue).
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
yarn test src/app/[locale]/(dashboard)/dashboard/content/editorcovers two new cases:unconfirmedcomes back and nothing lands, so "couldn't run" appears only after 90 s.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Also run:
yarn test(2632 tests pass) andyarn build.🤖 Generated with Claude Code