Address cursor bot review: session-gate, transcript tail, mobile noise

- workflow-logic: settle in-flight agents to "error" when terminalizing
  a run whose session died, so a stopped chip never sits above pulsing
  "running" agents; drop the dead hasStartedActivity field (snapshot-only
  runs render intentionally after history trims)
- ChatView: gate workflow liveness on derivePhase so interrupted
  sessions also terminalize runs, matching disconnected-session UX
- WorkflowPanel: fetch the transcript once more when a run leaves
  "running" so lines appended after the last poll tick are not lost
- mobile: suppress workflow-owned task.progress/task.completed rows in
  the work log, mirroring desktop (mobile has no workflow card yet)

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
Theo BrowneandClaude Fable 5 committed 2026-07-02 05:07:28 -07:00
1 parent e5b721efc6
commit 1610d39a1d
5 files changed
+123 -15

No files matched your search

+51 -1
View File
@@ -229,18 +229,68 @@ function resolvePendingUserInputAnswer(
return normalizeDraftAnswer(draft?.selectedOptionLabel);
}
/**
* Task ids owned by a workflow run. Mirrors the desktop derivation in
* apps/web/src/workflow-logic.ts (collectWorkflowTaskIds) — mobile has no
* workflow card yet, so all rows for those tasks are suppressed rather than
* rendered as per-tick noise.
*/
function collectWorkflowTaskIds(
activities: ReadonlyArray<OrchestrationThreadActivity>,
): Set<string> {
const taskIds = new Set<string>();
for (const activity of activities) {
const payload = activity.payload as Record<string, unknown> | null | undefined;
const taskId =
payload && typeof payload === "object" && typeof payload["taskId"] === "string"
? payload["taskId"]
: undefined;
if (!taskId) continue;
const workflowName =
payload && typeof payload === "object" ? payload["workflowName"] : undefined;
const taskType = payload && typeof payload === "object" ? payload["taskType"] : undefined;
if (
activity.kind === "task.workflow-updated" ||
activity.kind === "task.workflow-meta" ||
(activity.kind === "task.started" &&
(taskType === "local_workflow" || typeof workflowName === "string"))
) {
taskIds.add(taskId);
}
}
return taskIds;
}
function activityBelongsToWorkflow(
activity: OrchestrationThreadActivity,
workflowTaskIds: ReadonlySet<string>,
): boolean {
const payload = activity.payload as Record<string, unknown> | null | undefined;
const taskId = payload && typeof payload === "object" ? payload["taskId"] : undefined;
return typeof taskId === "string" && workflowTaskIds.has(taskId);
}
function deriveWorkLogEntries(
activities: ReadonlyArray<OrchestrationThreadActivity>,
): DerivedWorkLogEntry[] {
const ordered = Arr.sort(activities, activityOrder);
const workflowTaskIds = collectWorkflowTaskIds(activities);
const entries: DerivedWorkLogEntry[] = [];
for (const activity of ordered) {
if (activity.kind === "tool.started") continue;
if (activity.kind === "task.started") continue;
// Workflow snapshot/meta activities back the desktop workflow card; on
// mobile they would render as ever-mutating raw rows, so skip them.
// mobile they would render as ever-mutating raw rows, so skip them —
// along with the per-tick task rows the workflow owns.
if (activity.kind === "task.workflow-updated") continue;
if (activity.kind === "task.workflow-meta") continue;
if (
(activity.kind === "task.progress" || activity.kind === "task.completed") &&
workflowTaskIds.size > 0 &&
activityBelongsToWorkflow(activity, workflowTaskIds)
) {
continue;
}
if (activity.kind === "context-window.updated") continue;
if (activity.summary === "Checkpoint captured") continue;
if (isPlanBoundaryToolActivity(activity)) continue;
+3 -5
View File
@@ -1730,11 +1730,9 @@ function ChatViewContent(props: ChatViewProps) {
const phase = derivePhase(activeThread?.session ?? null);
const threadActivities = activeThread?.activities ?? EMPTY_ACTIVITIES;
const workLogEntries = useMemo(() => deriveWorkLogEntries(threadActivities), [threadActivities]);
const workflowSessionActive =
activeThread?.session !== null &&
activeThread?.session !== undefined &&
activeThread.session.status !== "stopped" &&
activeThread.session.status !== "error";
// Mirrors derivePhase: interrupted/stopped/error sessions are all
// disconnected, and a workflow cannot still be running under any of them.
const workflowSessionActive = phase !== "disconnected";
const workflowRuns = useMemo(
() => deriveWorkflowRuns(threadActivities, { sessionActive: workflowSessionActive }),
[threadActivities, workflowSessionActive],
@@ -425,9 +425,12 @@ function AgentTranscriptView({
};
}, [loadMore]);
// Keep polling for new lines while the run is live.
// Keep polling for new lines while the run is live; when the run settles
// (or the row opens on an already-terminal run), fetch once more so lines
// appended after the last poll tick are not lost.
useEffect(() => {
if (runStatus !== "running") {
void loadMore();
return;
}
const id = setInterval(() => {
+34
View File
@@ -256,6 +256,40 @@ describe("deriveWorkflowRuns", () => {
expect(runs).toEqual([]);
});
it("terminalizes a still-running run and settles in-flight agents when the session is gone", () => {
const runs = deriveWorkflowRuns(
[
workflowStartedActivity("task-1"),
workflowUpdatedActivity("task-1", [
{ type: "workflow_agent", index: 0, state: "done" },
{ type: "workflow_agent", index: 1, state: "start", startedAt: 1000 },
{ type: "workflow_agent", index: 2, state: "start" },
]),
],
{ sessionActive: false },
);
const run = runs[0];
expect(run?.status).toBe("stopped");
const agents = run?.phases.flatMap((phase) => phase.agents) ?? [];
expect(agents.map((agent) => agent.status)).toEqual(["done", "error", "error"]);
expect(agents[1]?.error).toBe("Interrupted before completion");
expect(run?.agentCounts).toEqual({ total: 3, queued: 0, running: 0, done: 1, error: 2 });
});
it("keeps a running run untouched while the session is active", () => {
const runs = deriveWorkflowRuns(
[
workflowStartedActivity("task-1"),
workflowUpdatedActivity("task-1", [
{ type: "workflow_agent", index: 0, state: "start", startedAt: 1000 },
]),
],
{ sessionActive: true },
);
expect(runs[0]?.status).toBe("running");
expect(runs[0]?.phases.flatMap((phase) => phase.agents)[0]?.status).toBe("running");
});
it("detects remote runs from session handles", () => {
const runs = deriveWorkflowRuns([
workflowStartedActivity("task-remote"),
+31 -8
View File
@@ -270,9 +270,7 @@ export function groupWorkflowAgentsByPhase(parsed: {
.toSorted((a, b) => a.index - b.index);
}
interface MutableWorkflowRun extends WorkflowRun {
hasStartedActivity: boolean;
}
type MutableWorkflowRun = WorkflowRun;
function isWorkflowTaskStartedPayload(payload: Record<string, unknown>): boolean {
return payload.taskType === "local_workflow" || asString(payload.workflowName) !== undefined;
@@ -326,7 +324,6 @@ export function deriveWorkflowRuns(
phases: [],
logs: [],
agentCounts: { total: 0, queued: 0, running: 0, done: 0, error: 0 },
hasStartedActivity: false,
};
runs.set(taskId, run);
return run;
@@ -349,7 +346,6 @@ export function deriveWorkflowRuns(
}
const run = ensureRun(taskId, activity);
run.revision += 1;
run.hasStartedActivity = true;
run.createdAt = activity.createdAt;
run.turnId = activity.turnId;
const name = asString(payload.workflowName);
@@ -440,16 +436,43 @@ export function deriveWorkflowRuns(
// A workflow cannot outlive its provider session: when the session is gone
// and no task_notification ever arrived (crash, interrupt, app restart),
// surface the run as stopped instead of running forever.
// surface the run as stopped instead of running forever. Runs derived only
// from snapshot/meta activities (no task.started — e.g. after a checkpoint
// revert trimmed it) are kept intentionally: partial history still renders.
const sessionActive = options?.sessionActive ?? true;
return [...runs.values()]
.map(({ hasStartedActivity: _hasStartedActivity, ...run }) => run)
.map((run) =>
run.status === "running" && !sessionActive ? { ...run, status: "stopped" as const } : run,
run.status === "running" && !sessionActive ? terminalizeInterruptedRun(run) : run,
)
.toSorted((a, b) => a.createdAt.localeCompare(b.createdAt) || a.taskId.localeCompare(b.taskId));
}
/**
* Settle a run whose session died before a terminal task notification:
* the run becomes "stopped" and its in-flight agents settle to "error" so
* nothing keeps rendering (or polling) as live work.
*/
function terminalizeInterruptedRun(run: WorkflowRun): WorkflowRun {
const settleAgent = (agent: WorkflowRunAgent): WorkflowRunAgent =>
agent.status === "running" || agent.status === "queued"
? { ...agent, status: "error", error: agent.error ?? "Interrupted before completion" }
: agent;
const phases = run.phases.map((phase) => ({ ...phase, agents: phase.agents.map(settleAgent) }));
const agents = phases.flatMap((phase) => phase.agents);
return {
...run,
status: "stopped",
phases,
agentCounts: {
total: agents.length,
queued: agents.filter((agent) => agent.status === "queued").length,
running: agents.filter((agent) => agent.status === "running").length,
done: agents.filter((agent) => agent.status === "done").length,
error: agents.filter((agent) => agent.status === "error").length,
},
};
}
export function isRemoteWorkflowRun(run: WorkflowRun): boolean {
return run.handles?.taskType === "remote_agent" || run.handles?.sessionUrl !== undefined;
}