Skip to content

Commit 24972aa

Browse files
fix(console): a screen run finished from Flow Runs no longer reads as paused (#34085)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9FFs7vCo5s4ZwH6FsmHDE8q)_ Fixes #33856 Clause-②: no Metadata-protocol: none Claim by `domain:ui#2` (comment 6898241442), card-thread session `session_01ADHkmSmRojhM8vYjHkVSeg`. ## 维护者速读 - 改了什么:开发者 Flow Runs 页的测试面板里,屏幕流程被 FlowRunner 跑完后,面板重读这条运行记录(`automation.getRun`),把它当作结果显示(绿色「Result」、最终状态与耗时),不再显示「Waiting for input」和「Continue run」。 - 为什么改:原来完成回调只关掉对话框,面板仍保留触发时的暂停应答;「Continue run」又出现,点开是旧屏幕,提交得到 404 `RUN_NOT_FOUND`。 - 风险与回滚:只改 `FlowRunsPage.tsx` 的完成回调(加一次运行读取和一个代次守卫,防止旧读取覆盖新一次运行);用户手动关掉对话框、运行仍暂停时的「Continue run」不变。回滚即 revert。 - 先看:`ui/apps/console/src/pages/developer/FlowRunsPage.tsx`(`handleComplete`),`FlowRunsPage.test.tsx` 末尾新增的 describe。 - 两分钟验证:`pnpm --dir ui exec vitest run apps/console/src/pages/developer/FlowRunsPage.test.tsx`,预期 4 passed;把 `onComplete={handleComplete}` 换回旧的内联回调,新用例转红。 - 需要你做的:无,席位落地。 ## What changes - **`ui/apps/console/src/pages/developer/FlowRunsPage.tsx`** (`FlowTestRunner`): `FlowRunner`'s `onComplete` now runs `handleComplete`. It closes the runner, clears the trigger answer held in `result` (the paused envelope, whose screen the server no longer holds), refreshes the run list as before, then reads the run back with `client.automation.getRun(flow.name, runId)` and shows the stored run as the result. The panel header then takes its status branch from the run row (`completed` reads green "Result"), and the "Continue run" affordance, which needs `status === 'paused'` plus a `screen`, is gone. - `FlowRunner`'s `onComplete` takes no arguments, so the resume answer the runner received is not reachable from this file; reading the run back is the in-surface route (card reading kept on the card, 6895948571). - A client without `automation.getRun` gets the page's existing "… is not available on this client" panel error; a failed read shows its message. A ref counter, bumped by every new run and by a flow switch, drops a read that lands after the tester has moved on. - Unchanged: the runner dismissed while the run is still paused (`onClose`) keeps the paused answer and its "Continue run". ## Tests - **`ui/apps/console/src/pages/developer/FlowRunsPage.test.tsx`**, new top-level describe in the existing harness: run the screen flow, submit the screen, then assert `getRun('reassign_wizard', 'run_1')` was called, the header reads "Result", the shown run says `"status": "completed"`, and neither "Waiting for input", "This run is paused at screen", nor a "Continue run" button remain. - Harness change (not a forced edit of any existing assertion): the stubbed client gains a hoisted `getRun` that answers a completed run row, cleared in `beforeEach`. - CONTROL, already in the file and still green: "offers a \"Continue run\" affordance after the runner is dismissed" (a still-paused run keeps Continue). <details><summary>Readings (head 6c401b3)</summary> - `pnpm --dir ui exec vitest run apps/console/src/pages/developer/FlowRunsPage.test.tsx` under the verify lock: Test Files 1 passed, Tests 4 passed, VERDICT command-exit 0 (after `pnpm --filter '@object-ui/console^...' build`, also exit 0). - Ablation through `scripts/ablation-replace.mjs` (fix committed first): anchor `onComplete={handleComplete}` replaced by the old inline `onComplete` (anchor 1 to 0, blob 8c147b8 to 19a1de0d). The new test went red ("expected vi.fn() to be called with arguments: [ 'reassign_wizard', 'run_1' ]"), 1 failed and 3 passed; restored, blob equals HEAD, `git diff HEAD` empty. The page source is imported from `src` by the test, so no rebuild leg applies. - `pnpm --filter @object-ui/console run type-check`: exit 0. The console tsc program does not list `FlowRunsPage.test.tsx` (`--listFiles` count 0), so this covers the page, not the test. - `node scripts/pm/dispatch-gates.mjs --commands`: 36 commands, each run, each exit 0; `--ran` reconciliation: 36 derived, 36 run, 0 NOT-MEASURED. Also `pnpm check:changeset-fixed` (its roster is under `.changeset`): exit 0. </details> ## Acceptance notes - Read-only inference, not measured, outside this file surface: the same stale-`result` shape can follow `onClose` in two cases. (1) A run that ends `refused` shows the refusal in the runner, which never calls `onComplete`; closing it leaves the paused answer, so "Continue run" would return for a terminal run. (2) A multi-step wizard dismissed at step 2 keeps step 1's screen in `result`, so "Continue run" would reopen step 1. Both need `FlowRunner` to tell its host where the run ended (a run row has no `screen` to re-read), which is `@object-ui/app-shell`, not this page. Carrier: the seat. ## Verification Changeset: `.changeset/33856-flow-runs-completed-run.md`, `@object-ui/console` patch. --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmSmRojhM8vYjHkVSeg)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 393a576 commit 24972aa

3 files changed

Lines changed: 81 additions & 5 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/console': patch
3+
---
4+
5+
fix(console): a screen run finished from the Flow Runs test panel no longer reads as paused
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
On the developer Flow Runs page, a screen flow's test run that the runner drove to completion left the Test Run panel showing the trigger's paused answer: "Waiting for input", "This run is paused at screen …" and a "Continue run" button. Continuing reopened the old screen, and submitting it answered 404 `RUN_NOT_FOUND`, because the server no longer holds a suspended run. When the runner completes the run, the panel now reads the run back (`automation.getRun`) and shows it as the result, with its final status and duration, and offers no "Continue run". A run the tester dismisses while it is still paused keeps its "Continue run", as before.

‎ui/apps/console/src/pages/developer/FlowRunsPage.test.tsx‎

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import userEvent from '@testing-library/user-event';
1818
// Hoisted so the vi.mock factories below can close over them, and so the
1919
// adapter is a STABLE singleton (a fresh object per render loops the page's
2020
// fetch effects).
21-
const { execute, ADAPTER, authFetch } = vi.hoisted(() => {
21+
const { execute, getRun, ADAPTER, authFetch } = vi.hoisted(() => {
2222
const flow = {
2323
name: 'reassign_wizard',
2424
label: 'Reassign',
@@ -38,11 +38,22 @@ const { execute, ADAPTER, authFetch } = vi.hoisted(() => {
3838
fields: [{ name: 'new_assignee', label: 'New Assignee', type: 'text', required: true }],
3939
},
4040
}));
41+
// The run row as the server records it once the resume finished it.
42+
const getRun = vi.fn(async () => ({
43+
id: 'run_1',
44+
flowName: 'reassign_wizard',
45+
status: 'completed',
46+
trigger: { type: 'manual' },
47+
steps: [],
48+
startedAt: '2026-11-15T00:00:00.000Z',
49+
completedAt: '2026-11-15T00:00:01.000Z',
50+
durationMs: 1000,
51+
}));
4152
const ADAPTER = {
4253
getClient: () => ({
4354
// The served list item IS the flow definition (objectui#12829).
4455
meta: { getItems: async (type: string) => (type === 'flow' ? [flow] : []) },
45-
automation: { execute, listRuns: async () => ({ runs: [] }) },
56+
automation: { execute, getRun, listRuns: async () => ({ runs: [] }) },
4657
}),
4758
};
4859
const authFetch = vi.fn(async () =>
@@ -51,7 +62,7 @@ const { execute, ADAPTER, authFetch } = vi.hoisted(() => {
5162
headers: { 'Content-Type': 'application/json' },
5263
}),
5364
);
54-
return { execute, ADAPTER, authFetch };
65+
return { execute, getRun, ADAPTER, authFetch };
5566
});
5667

5768
vi.mock('@object-ui/app-shell', async (importOriginal) => {
@@ -76,6 +87,7 @@ import { FlowRunsPage } from './FlowRunsPage';
7687

7788
beforeEach(() => {
7889
execute.mockClear();
90+
getRun.mockClear();
7991
authFetch.mockClear();
8092
});
8193
afterEach(cleanup);
@@ -146,3 +158,29 @@ describe('Flow Runs — screen flows are completable from the Test Run panel', (
146158
expect(reopened.queryByText('reassign_wizard')).not.toBeInTheDocument();
147159
});
148160
});
161+
162+
describe('Flow Runs — a screen run completed from the Test Run panel stops reading as paused', () => {
163+
it('shows the completed run and drops "Waiting for input" and "Continue run"', async () => {
164+
const user = userEvent.setup();
165+
render(<FlowRunsPage />);
166+
167+
await screen.findByRole('button', { name: /Run Flow/i });
168+
await user.click(screen.getByRole('button', { name: /Run Flow/i }));
169+
await screen.findByRole('dialog');
170+
// The pause is what the panel reads before the run is finished.
171+
expect(screen.getByText('Waiting for input')).toBeInTheDocument();
172+
173+
const textboxes = screen.getAllByRole('textbox');
174+
await user.type(textboxes[textboxes.length - 1], 'ada@example.com');
175+
await user.click(screen.getByRole('button', { name: 'Submit' }));
176+
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
177+
178+
// The panel re-reads the run the runner finished and shows it as the result.
179+
await waitFor(() => expect(getRun).toHaveBeenCalledWith('reassign_wizard', 'run_1'));
180+
expect(await screen.findByText('Result')).toBeInTheDocument();
181+
expect(screen.getByText(/"status": "completed"/)).toBeInTheDocument();
182+
expect(screen.queryByText('Waiting for input')).not.toBeInTheDocument();
183+
expect(screen.queryByText(/This run is paused at screen/)).not.toBeInTheDocument();
184+
expect(screen.queryByRole('button', { name: /Continue run/i })).not.toBeInTheDocument();
185+
});
186+
});

‎ui/apps/console/src/pages/developer/FlowRunsPage.tsx‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* from here too.
1717
*/
1818

19-
import { useEffect, useMemo, useState, useCallback } from 'react';
19+
import { useEffect, useMemo, useRef, useState, useCallback } from 'react';
2020
import { useDisplayLocale, useObjectTranslation } from '@object-ui/i18n';
2121
import { ConsolePageHeader, useAdapter, useMetadata, FlowRunner, type ScreenFlowState, DeveloperNamespaceGate } from '@object-ui/app-shell';
2222
import { createAuthenticatedFetch } from '@object-ui/auth';
@@ -367,8 +367,12 @@ function FlowTestRunner({
367367
// The paused screen a test run stopped at — driven to completion by
368368
// <FlowRunner>, exactly as a `type: 'flow'` action would.
369369
const [screenFlow, setScreenFlow] = useState<ScreenFlowState | null>(null);
370+
// Bumped by every new run and flow switch: a completed run's re-read that
371+
// lands after either belongs to a panel the tester has already left.
372+
const runGeneration = useRef(0);
370373

371374
useEffect(() => {
375+
runGeneration.current += 1;
372376
setValues({});
373377
setResult(null);
374378
setError(null);
@@ -382,6 +386,7 @@ function FlowTestRunner({
382386
setError({ unavailable: 'automation.execute' });
383387
return;
384388
}
389+
runGeneration.current += 1;
385390
setRunning(true);
386391
setError(null);
387392
setResult(null);
@@ -410,6 +415,29 @@ function FlowTestRunner({
410415
}
411416
};
412417

418+
// The runner drove the paused run to completion. The trigger answer in
419+
// `result` still describes the pause, and its screen no longer exists on the
420+
// server, so it is replaced by the run as the server now records it: the
421+
// panel reads the run's final status and offers no "Continue run".
422+
const handleComplete = async () => {
423+
const runId = screenFlow?.runId ?? result?.runId;
424+
const generation = runGeneration.current;
425+
setScreenFlow(null);
426+
setResult(null);
427+
onExecuted?.();
428+
if (!runId) return;
429+
if (!client?.automation?.getRun) {
430+
setError({ unavailable: 'automation.getRun' });
431+
return;
432+
}
433+
try {
434+
const res: any = await client.automation.getRun(flow.name, runId);
435+
if (generation === runGeneration.current) setResult(res?.run ?? res);
436+
} catch (e: any) {
437+
if (generation === runGeneration.current) setError({ message: e?.message ?? String(e) });
438+
}
439+
};
440+
413441
return (
414442
<Card>
415443
<CardHeader className="pb-3">
@@ -527,7 +555,7 @@ function FlowTestRunner({
527555
dataSource={adapter}
528556
objects={objects}
529557
onClose={() => { setScreenFlow(null); onExecuted?.(); }}
530-
onComplete={() => { setScreenFlow(null); onExecuted?.(); }}
558+
onComplete={handleComplete}
531559
/>
532560
</Card>
533561
);

0 commit comments

Comments
 (0)