Our coding agent debugged phantom failures for 2 hours because it trusted terminal history
I watched our coding agent spend 2 hours debugging a "failed" deployment that was actually running perfectly. The issue? It was reading terminal history as current state.
Here's what happened: The agent ran npm run build, saw an old error message from a previous session still visible in the terminal scrollback, and decided the current build had failed. It spent the next two hours "fixing" problems that didn't exist while our perfectly good deployment served traffic.
This is the core problem with long-running coding agents: they treat terminal output as a stream of current events, not a historical log. Every old error becomes a present crisis.
The pattern that fixes this:
#!/bin/bash # Clear terminal before each major operation clear echo "=== STARTING: $1 ===" # Run the actual command $@ EXIT_CODE=$? echo "=== COMPLETED: $1 (exit: $EXIT_CODE) ==="
We wrapped every significant command in this pattern. Now our agent sees clean boundaries between operations instead of archaeological layers of terminal history.
But clearing the terminal isn't enough. The agent also needs to verify outcomes independently:
# Don't trust the build output - verify the result npm run build if [ -f "dist/index.html" ]; then echo "BUILD_VERIFIED: Success" else echo "BUILD_VERIFIED: Failed" fi
The key insight: verification beats interpretation. Instead of having the agent parse complex build output, we make it check for the expected artifacts. File exists? Build succeeded. Server responds to curl? Deployment worked. Tests create a report file? Test run completed.
This pattern extends beyond coding agents. Our support agent was "fixing" resolved tickets because it saw old complaint emails in the thread. Now it checks ticket status in the system, not email sentiment.
Pro tip: Add verification commands to your agent's standard operating procedures. Don't just tell it how to deploy—tell it how to confirm the deployment worked.
The debugging session that should have taken 10 minutes stretched to 2 hours because we trusted the agent to interpret terminal noise correctly. Now we give it clean signals and explicit verification steps.
Your coding agent is probably making the same mistake right now, debugging phantom problems while real work waits in the queue.