Sub topic 3
Alerting on Failure and on Silence
Assume you can use a shell, Git branches, exit codes, and environment variables. A scheduled agent needs two kinds of monitoring: alert when a run fails, and alert when no run appears at all.
Detect failures and silence
Make the wrapper return a nonzero exit status when the agent, validation step, or timeout fails. Configure the scheduler or CI system to notify on that status. Also write a run record containing the start time, end time, exit status, commit, and output location.
Failure alerts do not detect a job that never started. For that case, send a heartbeat after each successful run to a monitoring service. Configure the service to alert if the heartbeat is missing beyond the expected schedule plus a grace period.
| Signal | Example condition | Response |
|---|---|---|
| Failure | Exit status is nonzero | Inspect the run log |
| Timeout | Process exceeds its limit | Stop it and investigate |
| Silence | No heartbeat by the deadline | Check the scheduler and host |
Make retries safe
A retry can repeat a commit, create duplicate tickets, or apply the same migration twice. Make each run idempotent, meaning repeating it produces the same intended result. Use a stable input identifier, check whether the desired change already exists, and write outputs to a run-specific directory.
Retry only transient errors such as network failures or rate limits. Use bounded exponential backoff. Do not retry authentication errors, malformed output, or a failed validation step without human review.
Deliver reviewable results
Have the agent create or update a dedicated branch instead of changing the default branch. Require tests and structured output before opening a pull request. The pull request should include the run identifier, summary, test results, and links to logs. Keep merging as a separate approval step.
Treat unattended input as hostile
Repository files, issue descriptions, and fetched web content can contain instructions aimed at the agent. Treat them as untrusted data. Limit tools and permissions, keep secrets out of prompts and logs, and instruct the agent to modify only the intended paths. Validate generated output before executing commands or publishing results.
Control cost and test first
Set a maximum runtime, maximum output size, and model or API budget. Add rate limits to retries. Run the wrapper manually with a test prompt, a temporary branch, and schedule disabled. Test success, timeout, malformed output, duplicate execution, and missing credentials. Confirm that alerts arrive before enabling the recurring schedule.
Exercise
Why is a heartbeat needed in addition to checking the agent's exit status?
Show answer
An exit status exists only when the job starts. A heartbeat reveals that the scheduler or host failed before the job could run.