Files
Heimdall/skills/agent-heartbeat-timeout/SKILL.md
T
arnaud.dartois 1b512ab040
Heimdall Gitea / Detect CI scope (push) Successful in 12s
Heimdall Gitea / Build and tests (push) Successful in 25m48s
Heimdall Gitea / Publish versioned release (push) Skipped
Heimdall Gitea / Build and scan agent image (push) Successful in 10m1s
Heimdall Gitea / Build and scan server image (push) Successful in 10m4s
Heimdall Gitea / Publish Docker Hub latest tags (push) Successful in 2m13s
Heimdall Gitea / Build and scan NVIDIA Agent image (push) Successful in 23m19s
Heimdall Gitea / CI policy (push) Successful in 7s
fix(agent): keep heartbeat timeouts transient (#277)
Co-authored-by: Arnaud Dartois <admin@tordais.cc>
2026-11-07 10:24:31 +01:00

2.7 KiB

name, description
name description
agent-heartbeat-timeout Diagnose and validate Central heartbeat timeouts without terminating the Heimdall Agent background service.

Agent heartbeat timeout

AgentRegistrationService sends periodic Central heartbeats through the named Central HttpClient, whose timeout is configured in src/Heimdall.Agent/Program.cs. An HttpClient.Timeout surfaces as OperationCanceledException/TaskCanceledException, even though the host's stoppingToken is not canceled. SendHeartbeatAsync must log this as a transient timeout and return to the loop. Preserve cancellation when stoppingToken.IsCancellationRequested so host shutdown remains cooperative.

Change and test

  • Keep the timeout handling local to SendHeartbeatAsync; registration cancellation and shutdown semantics have different retry behavior.
  • Catch OperationCanceledException only under !stoppingToken.IsCancellationRequested, log it as a timeout, and allow the next loop iteration to retry. The existing general exception handler continues to cover other transient failures.
  • In tests/Heimdall.Agent.Tests/AgentRegistrationServiceTests.cs, use an asynchronous HTTP handler that waits on the request cancellation token. Give its HttpClient a short timeout, then assert that a second heartbeat arrives. This verifies both the timeout source and continued service operation without waiting 10 seconds.
  • Run dotnet test tests/Heimdall.Agent.Tests/Heimdall.Agent.Tests.csproj --filter FullyQualifiedName~Heartbeat_HttpTimeout_DoesNotStopService_AndNextHeartbeatSucceeds, then the full Agent test project.

Disposable Compose acceptance

Run bash skills/agent-heartbeat-timeout/acceptance.sh from the repository root. The recipe builds the Agent image from docker/Dockerfile.agent in this checkout and a small local fake Central image. The fake Central delays the first heartbeat for 12 seconds (longer than the Agent's configured 10-second Central client timeout), then accepts later heartbeats. Acceptance requires the Agent health endpoint to respond after the timeout and the fake Central to observe a subsequent heartbeat. The script uses a random Compose project, random site token, Compose-managed isolated volume/network, dynamically assigned loopback Agent port, and unique local image tags. Its EXIT trap tears down only that project, verifies its containers/volumes/networks are gone, removes and verifies absence of both exact image tags, and removes temporary files. It retains shared SDK/runtime/base images.

This synthetic recipe proves local retry behavior only. It does not validate a production runner, Central instance, or post-deployment GlitchTip telemetry; record that follow-up on Gitea issue #248.