Exit codes lie to agents — verify the actual outcome
I spent three hours debugging why our coding agent kept failing silently on deployment tasks. The logs showed "success" but nothing actually shipped. The agent would run through its entire workflow, report completion, and leave us with broken deploys.
The problem wasn't the agent's intelligence or memory. It was assumptions.
Our agent assumed that if a command returned exit code 0, the task succeeded. But deployment scripts are messy. They'll return 0 even when Docker containers fail to start, when health checks timeout, or when services boot but can't connect to dependencies.
Here's the verification pattern that fixed it:
DEPLOYMENT_VERIFICATION = """ After any deployment command: 1. Wait 30 seconds for services to stabilize 2. Check actual service health endpoints 3. Verify database connections if applicable 4. Test one real user flow end-to-end 5. Only report success if ALL checks pass If any check fails, report the specific failure and rollback. """
The key insight: exit codes lie. Especially in containerized environments where the immediate command succeeds but the actual service fails seconds later.
We added three verification layers:
- Health check verification — Actually curl the health endpoints
- Dependency verification — Test database connections, external APIs, etc.
- User flow verification — Run one complete user action through the system
This caught failures that would have taken us hours to discover. The agent went from "deployed successfully" (while everything was broken) to "deployment failed: health check timeout after 45 seconds, rolling back."
Warning: This adds 1-2 minutes to every deployment. But it's 1-2 minutes that saves you from 2-hour debugging sessions when customers can't log in.
The pattern works for any high-stakes agent task. Don't trust command success. Verify the actual outcome.
For coding tasks: compile and run tests. For file operations: verify the file exists and has expected content. For API calls: check the response data, not just the status code.
Your agent should be paranoid about success. Because in production, "it worked" and "it's working" are completely different things.