Operate agents with safe execution paths and robust error handling
Unlock the complete study guide.
Bundled into the existing Developing in Agentic AI Systems premium course — no separate purchase.
14-day money-back guarantee — no questions asked.
Included in this chapter:
- Classify the failure before choosing a recovery
- Match the hook event to the failure job
- Retry the smallest failed unit, and bound every retry
- Recover a broken MCP connection without replaying the call
- Escalate through a channel that exists where the agent runs
- Stop the agent outright, not only the current request
- Treat a waiting gate as a job for a person, not an error
- Check what happens when a policy hook itself fails
- Keep attributable evidence that outlives the run
- Roll back at the boundary where the change lives
- Treat generated commands as untrusted at the execution boundary
- Exam reasoning: choosing the safe recovery
Failure signals and the safe next move
| Signal you see | What it tells you | Safe next move | Tempting but wrong |
|---|---|---|---|
| MCP JSON-RPC error for an unknown tool or malformed request | The request itself was rejected | Fix the request or the tool choice | Treating it as a tool result the model can argue with |
| MCP tool result with isError: true | The tool ran and failed on API, validation, or business logic | Return the error to the model so it can correct its arguments | Reconnecting as if the server were broken |
| gh pr create exits nonzero but prints a pull request URL | Some attachments failed; the pull request exists | Inspect the result and continue with that pull request | Running creation again and opening a duplicate |
| HTTP 404 on a request that carries MCP-Session-Id under the legacy 2025-11-25 Streamable HTTP transport | The server terminated that session | Send a new InitializeRequest without the old session ID | Resending the expired ID with backoff |
| Stream closed after an event with a retry field (legacy 2025-11-25 Streamable HTTP transport) | The response is still resumable | Wait the retry delay, then GET with Last-Event-ID | Reconnecting instantly or re-sending tools/call |
| REST rate-limit error with retry-after | You must pause for the stated time | Wait, then retry a bounded number of times | Retrying immediately or indefinitely |
| Workflows on a cloud-agent pull request are waiting | The default approval gate for a person with write access | Review the code and choose Approve and run workflows | Re-running the workflow as if it had failed |
| Artifact digest mismatch warning | The download does not match the uploaded digest | Investigate before trusting the evidence | Assuming the mismatch already failed the run automatically |
Decision tree
Cheat sheet
Unlock with Premium — includes all practice exams and the complete study guide.
Also tested in
References
- Tools: error handling (Model Context Protocol specification 2025-11-25)
- Versioning (MCP specification 2026-07-28)
- gh pr create (GitHub CLI manual)
- Hooks reference (GitHub Copilot)
- Agent operations controls (Microsoft Learn training unit)
- gh run rerun (GitHub CLI manual)
- Re-running workflows and jobs (GitHub Actions)
- Enabling debug logging (GitHub Actions)
- Rate limits for the REST API
- Best practices for using the REST API
- Lifecycle: timeouts (MCP 2025-11-25)
- Cancellation (MCP specification)
- Transports: Streamable HTTP resumability and session management (MCP 2025-11-25)
- Using hooks with Copilot cloud agent
- gh run cancel (GitHub CLI manual)
- About commit signature verification
- Reviewing Copilot output
- Storing and sharing data from a workflow (GitHub Actions)
- Rolling back changes made during a Copilot CLI session
- GitHub Copilot CLI command reference
- Get an agent back on track (VS Code)
- Review and revert agent changes: chat checkpoints (VS Code)
- Reverting a pull request
- LLM05:2025 Improper Output Handling (OWASP GenAI Security Project)
- OS Command Injection Defense Cheat Sheet (OWASP)