Skip to content

Commit d757b59

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. Spawn a Thread that calls Temporalio::Activity::Context.current.heartbeat every 30s, joined in ensure when handle.result returns. Survives realistic operator delays. Existing tests still pass.
1 parent 0c822ed commit d757b59

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

tool_registry_incident_triage/triage_activity.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,24 @@ def self.real_request_human_approval(alert, req)
285285
# operator should not get a second prompt for the same incident.
286286
id_conflict_policy: Temporalio::WorkflowIDConflictPolicy::USE_EXISTING
287287
)
288-
handle.result
288+
289+
# Heartbeat every 30 seconds while waiting on the approval workflow.
290+
# AgenticSession only heartbeats between LLM turns, so a multi-hour
291+
# operator wait inside this handler would otherwise trigger heartbeat
292+
# timeout in 120s and kill the activity.
293+
stop = false
294+
ticker = Thread.new do
295+
until stop
296+
sleep 30
297+
Temporalio::Activity::Context.current.heartbeat unless stop
298+
end
299+
end
300+
301+
begin
302+
handle.result
303+
ensure
304+
stop = true
305+
ticker.join
306+
end
289307
end
290308
end

0 commit comments

Comments
 (0)