@@ -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 ( {
0 commit comments