Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

fix(content): show a live page's Start on the agent's waiting page (#1524)

Cihanb428349ea9da
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_agent-writing.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_agent-writing.tsx
index 7af49b0b7..eced08330 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_agent-writing.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_agent-writing.tsx
@@ -8,7 +8,7 @@ import { Link } from '@/i18n/navigation';
import { Button } from '@/components/ui/button';
import { buttonVariants } from '@/components/ui/button-variants';
import { stopAgentRun } from '@/lib/content/agent-runs-client';
-import type { AgentRun } from '@/lib/content/agent-runs';
+import type { AgentRun, AgentRunKind } from '@/lib/content/agent-runs';
import { CONTENT_LIBRARY_PATH, type DraftMethod } from '@/lib/content/drafts';
import { cn } from '@/lib/utils';
import { AgentTile, RunSteps, StepSweep } from './_agent-card';
@@ -34,8 +34,16 @@ const WRITING = STEPS.indexOf('write');
*/
const SLOW_AFTER_S = 120;
-/** The runs this page waits on: a new page, or the whole page rewritten. */
-const WRITING_RUNS = ['write', 'rewrite'] as const;
+/**
+ * The run this page waits on, as the server starts it (content-writer.js
+ * startWritingRun): a Start on a new page writes it, one on a live page runs
+ * as a Fix (its suggestions), and a rewrite rewrites the whole page.
+ */
+const WRITING_RUNS = {
+ create: ['write'],
+ optimize: ['fix'],
+ rewrite: ['rewrite'],
+} as const satisfies Record<DraftMethod | 'rewrite', readonly AgentRunKind[]>;
/**
* What the agent does while it writes, as its prompt asks it
@@ -161,7 +169,7 @@ export function AgentWriting({
method: DraftMethod;
/** When the agent started (content_drafts.agent_state_at). */
since: string | null;
- /** Rewrite the page to these rules, as this tab started it. */
+ /** Rewrite the page to these rules (the draft's agent_run): its run is a rewrite. */
rewrite?: boolean;
/** The run ended (stopped, done or failed): the page reads the draft again. */
onRunEnded?: (stopped?: boolean) => void;
@@ -169,7 +177,7 @@ export function AgentWriting({
const t = useTranslations('contentEditor.editor');
const seconds = elapsedSeconds(since, useNow({ updateInterval: 1000 }));
const mode = rewrite ? 'rewrite' : method;
- const live = useAgentRun(draftId, true, WRITING_RUNS);
+ const live = useAgentRun(draftId, true, WRITING_RUNS[mode]);
const [stopping, setStopping] = useState(false);
// The last run read stays until the editor opens: the fixed list never
// comes back for a moment at its end.
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx
index d10db099e..e380ae701 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx
@@ -975,6 +975,78 @@ describe('the content editor', () => {
}
});
+ it('shows a live page’s Start, which runs as a Fix, and stops it', async () => {
+ getContentDraft.mockResolvedValue(
+ draft({ status: 'draft', agentState: 'writing', agentSince: new Date().toISOString() }),
+ );
+ readAgentRun.mockResolvedValue({
+ id: 'r2',
+ kind: 'fix',
+ steps: [
+ { key: 'read_rules', count: 7 },
+ { key: 'gather_sources', count: 3 },
+ { key: 'write_changes', count: null },
+ { key: 'check_sources', count: null },
+ ],
+ step: 2,
+ startedAt: new Date().toISOString(),
+ finishedAt: null,
+ stoppedAt: null,
+ outcome: null,
+ });
+ await renderPage();
+ await act(async () => {});
+ const status = container.querySelector('[role="status"]')!;
+ // Its real steps, not the fixed list, and its Stop.
+ expect([...status.querySelectorAll('li')].map((li) => li.textContent)).toEqual([
+ 'Reading 7 rules',
+ 'Gathering 3 sources',
+ 'Writing changes',
+ 'Checking sources',
+ ]);
+ await act(async () => button('Stop')!.click());
+ expect(stopAgentRun).toHaveBeenCalledWith('d1', 'b1', 'r2');
+ });
+
+ it('shows only the run the page waits on: a rewrite’s on a new page, never another kind’s', async () => {
+ for (const [method, agentRun, kind, shown] of [
+ // A new page's rewrite: its run is a rewrite, not the Start's write.
+ ['create', 'rewrite', 'rewrite', true],
+ ['create', 'rewrite', 'write', false],
+ ['create', 'write', 'fix', false],
+ ['optimize', 'rewrite', 'fix', false],
+ ] as const) {
+ getContentDraft.mockResolvedValue(
+ draft({
+ status: 'draft',
+ method,
+ agentState: 'writing',
+ agentRun,
+ agentSince: new Date().toISOString(),
+ }),
+ );
+ readAgentRun.mockResolvedValue({
+ id: 'r3',
+ kind,
+ steps: [{ key: 'check_sources', count: null }],
+ step: 0,
+ startedAt: new Date().toISOString(),
+ finishedAt: null,
+ stoppedAt: null,
+ outcome: null,
+ });
+ await renderPage();
+ await act(async () => {});
+ // Another run's: the fixed list stays, with no Stop for it.
+ expect(
+ container.querySelector('[role="status"]')!.textContent!.includes('Checking sources'),
+ ).toBe(shown);
+ expect(button('Stop') !== undefined).toBe(shown);
+ await act(async () => root.unmount());
+ root = createRoot(container);
+ }
+ });
+
it('reads the draft at once when its run ends, its steps shown till then', async () => {
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'Date'] });
try {
@@ -5063,10 +5135,11 @@ describe('the side panel', () => {
getContentDraft.mockResolvedValue(
draft({ status: 'draft', agentState: 'writing', agentSince: new Date().toISOString() }),
);
+ // A Start on a live page runs as a Fix (content-writer.js startWritingRun).
readAgentRun.mockResolvedValue({
id: 'r1',
- kind: 'write',
- steps: [{ key: 'write_page', count: null }],
+ kind: 'fix',
+ steps: [{ key: 'write_changes', count: null }],
step: 0,
startedAt: new Date().toISOString(),
finishedAt: null,