Skip to content

Commit a14549b

Browse files
Claw AgentClaw Agent
authored andcommitted
Fix TaskFlow stale audit for ended blocked flows
1 parent 13ecca5 commit a14549b

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

‎src/tasks/task-flow-registry.audit.test.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,49 @@ describe("task-flow-registry audit", () => {
226226
});
227227
});
228228

229+
it("does not flag ended blocked flows as stale", async () => {
230+
await withTaskFlowAuditStateDir(async () => {
231+
const flow = createManagedTaskFlow({
232+
ownerKey: "agent:main:main",
233+
controllerId: "tests/task-flow-audit",
234+
goal: "Terminal blocked work",
235+
status: "running",
236+
createdAt: 1,
237+
updatedAt: 1,
238+
});
239+
240+
setFlowWaiting({
241+
flowId: flow.flowId,
242+
expectedRevision: flow.revision,
243+
blockedTaskId: "task-missing",
244+
blockedSummary: "Completion handoff did not produce a visible reply",
245+
updatedAt: 1,
246+
});
247+
248+
const blocked = listTaskFlowAuditFindings({ now: 31 * 60_000 });
249+
expect(requireFinding(blocked, "stale_blocked", flow.flowId).flow?.flowId).toBe(flow.flowId);
250+
251+
const terminalFlow: TaskFlowRecord = {
252+
...flow,
253+
status: "blocked" as const,
254+
blockedTaskId: "task-missing",
255+
blockedSummary: "Completion handoff did not produce a visible reply",
256+
endedAt: 1,
257+
updatedAt: 1,
258+
};
259+
260+
const terminalFindings = listTaskFlowAuditFindings({
261+
flows: [terminalFlow],
262+
now: 31 * 60_000,
263+
});
264+
expect(
265+
terminalFindings.some(
266+
(finding) => finding.code === "stale_blocked" && finding.flow?.flowId === flow.flowId,
267+
),
268+
).toBe(false);
269+
});
270+
});
271+
229272
it("reports cancel-stuck before maintenance finalizes the flow", async () => {
230273
await withTaskFlowAuditStateDir(async () => {
231274
const flow = createManagedTaskFlow({

‎src/tasks/task-flow-registry.audit.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export function listTaskFlowAuditFindings(
192192
);
193193
}
194194

195-
if (flow.status === "blocked" && ageMs >= staleBlockedMs) {
195+
if (flow.status === "blocked" && flow.endedAt == null && ageMs >= staleBlockedMs) {
196196
findings.push(
197197
createFinding({
198198
severity: "warn",

0 commit comments

Comments
 (0)