Skip to content

Commit 285ff4d

Browse files
committed
Heartbeat every 30s while waiting on the approval workflow
The approval handler blocks on handle.result() for as long as the operator takes to decide. agenticSession only heartbeats between LLM turns, so a multi-hour wait inside this handler would trigger heartbeat timeout (default 120s) and kill the activity. setInterval fires heartbeat() every 30s, cleared in finally when handle.result() returns. Survives realistic operator delays. Existing tests still pass (the test path uses a fake deps record that doesn't go through this code path).
1 parent ce0176c commit 285ff4d

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

  • tool-registry-incident-triage/src/activities

tool-registry-incident-triage/src/activities/triage.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121
import { exec } from "node:child_process";
2222
import { promisify } from "node:util";
23+
import { heartbeat } from "@temporalio/activity";
2324
import { Connection, Client } from "@temporalio/client";
2425
import { WorkflowIdConflictPolicy } from "@temporalio/common";
2526
import { ToolRegistry, agenticSession, type AgenticSession } from "@temporalio/tool-registry";
@@ -316,7 +317,16 @@ async function realRequestHumanApproval(alert: AlertPayload, request: ApprovalRe
316317
workflowIdConflictPolicy: WorkflowIdConflictPolicy.USE_EXISTING,
317318
});
318319

319-
const response = (await handle.result()) as ApprovalResponse;
320-
await connection.close();
321-
return response;
320+
// Heartbeat every 30 seconds while waiting on the approval workflow.
321+
// agenticSession only heartbeats between LLM turns, so a multi-hour
322+
// operator wait inside this handler would otherwise trigger heartbeat
323+
// timeout in 120s and kill the activity.
324+
const ticker = setInterval(() => heartbeat(), 30_000);
325+
try {
326+
const response = (await handle.result()) as ApprovalResponse;
327+
return response;
328+
} finally {
329+
clearInterval(ticker);
330+
await connection.close();
331+
}
322332
}

0 commit comments

Comments
 (0)