I keep hearing the same complaint from people running agents 24/7:
“It's flaky.”
Not dead. Not consistently broken. Just randomly bad on first turn, after reconnects, or right after a restart.
OpenClaw forgets a tool.
n8n workers miss state.
A custom FastAPI tool server comes up, but the first call fails.
Then someone blames GPT-5 or Claude because retrying magically fixes it.
That pattern usually has nothing to do with model quality.
Most of the time, the real bug lives in the first 30-60 seconds after boot.
If Redis, Postgres, OpenClaw Gateway, or a generated config file is merely running, but not actually ready, your agent gets work too early and falls on its face.
That’s not flaky AI. That’s bad startup orchestration.
The mistake: "container started" != "service ready"
This is the root of a lot of fake LLM bugs.
A lot of agent stacks assume this sequence is safe:
- Start containers
- Start agent
- Send work
It isn’t.
A running Postgres container can still reject queries.
A running Redis container can still be warming.
A running OpenClaw Gateway can still be missing profile or channel state.
A config file can exist on disk while still being written.
That’s how you get:
- first-turn tool failures
- missing memory on reconnect
- random startup errors that disappear on retry
- “Claude was weird” reports that are actually infra bugs
If you’re self-hosting agent workflows, the boot path matters more than people think.
Docker Compose already tells you this
Compose does not treat “running” as “ready.”
If your agent depends on Postgres, gate it with a health check.
services:
agent:
build: .
depends_on:
db:
condition: service_healthy
restart: true
db:
image: postgres:18
environment:
POSTGRES_USER: app
POSTGRES_PASSWORD: secret
POSTGRES_DB: appdb
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
interval: 10s
timeout: 10s
retries: 5
start_period: 30s
Two important details here:
-
condition: service_healthymeans the agent waits for actual readiness -
restart: truehelps the dependent reconnect correctly after an explicit dependency restart
That second one is underrated.
A lot of “session reset” bugs are just reconnect bugs with better branding.
If you have Redis, probe Redis
Same rule.
Don’t assume Redis is usable because the process exists.
Example health check:
services:
redis:
image: redis:7
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 10
If your memory layer, queue worker, or agent session cache depends on Redis, this one check can remove a surprising amount of startup chaos.
Kubernetes got this right years ago
If you run agents in Kubernetes, stop using liveness probes as a universal hammer.
There are three different concepts for a reason:
-
startupProbe: the app is still initializing -
readinessProbe: the app can receive traffic now -
livenessProbe: the app is unhealthy and should be restarted
Those are not interchangeable.
If your OpenClaw worker or tool server needs time to:
- connect to Postgres
- connect to Redis
- load embeddings
- mount volumes
- read generated files
- hydrate caches
then you want startup and readiness checks first.
If you use liveness too aggressively, you can create a reboot loop and call it “self-healing.”
That’s not resilience. That’s a denial-of-service attack you wrote yourself.
Quick rule of thumb
| Probe | Use it for |
|---|---|
| startupProbe | Slow initialization that should not trigger restarts |
| readinessProbe | Blocking traffic until the service is truly ready |
| livenessProbe | Deadlocks, wedged processes, and real unhealthy states |
Some startup bugs aren’t network bugs at all
This is where things get more annoying.
Sometimes the dependency isn’t Postgres or Redis.
Sometimes it’s a file.
Examples:
- a generated config file
- a plugin bundle
- a socket file
- a memory index
- a credentials file written by another process
And yes, these can absolutely break agent startup.
The ugly version looks like this:
- file appears
- startup script sees it
- agent boots
- file was still mid-write
- first request fails
- retry works
- everyone blames the model
That’s why file readiness checks matter.
Use a watcher when file state is the dependency
For Node.js, I like Chokidar.
It smooths over a bunch of fs.watch weirdness and gives you practical options like:
awaitWriteFinishatomicready
Example:
import chokidar from 'chokidar';
const watcher = chokidar.watch('./runtime/config.json', {
persistent: true,
atomic: true,
awaitWriteFinish: true,
});
watcher.on('ready', () => {
console.log('Initial scan complete. Safe to continue startup.');
});
watcher.on('change', (path) => {
console.log(`Config updated: ${path}`);
});
That ready event is the useful part.
It gives you a real signal that initial file discovery is complete, instead of guessing.
If your agent depends on a generated artifact, this is often better than sleeping for 10 seconds and hoping for the best.
For Python, use watchdog.
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
import time
class Handler(FileSystemEventHandler):
def on_created(self, event):
print(f"created: {event.src_path}")
observer = Observer()
observer.schedule(Handler(), path="./runtime", recursive=False)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
Don’t watch your whole repo unless you really need to.
Watch the one file or directory that proves readiness.
That’s the trick.
OpenClaw gives you the right debugging path
One thing I like about OpenClaw is that the troubleshooting flow points you toward runtime health instead of mystical prompt tweaking.
If an assistant feels broken, start here:
openclaw status
openclaw status --all
openclaw gateway probe
openclaw gateway status
openclaw doctor
openclaw channels status --probe
openclaw logs --follow
That is exactly the right mindset.
Before you ask why the model behaved badly, ask whether the control plane was actually warm and connected.
If the Gateway came up with the wrong profile, stale session state, or missing tools, the assistant will look dumb for reasons that have nothing to do with reasoning.
That’s especially true if you’re switching profiles or relying on specific tool exposure.
If the assistant suddenly seems “limited,” check the runtime state before touching prompts.
This also shows up in n8n and custom workflow stacks
Same story, different stack.
If you run n8n with workers, queues, Redis, Postgres, and custom AI nodes, your reliability is mostly an orchestration problem before it becomes a model problem.
The weak points are boring:
- workers starting before Redis is reachable
- encryption key mismatch across nodes
- stale queue connections after restart
- tool servers not ready when jobs begin
- generated env/config artifacts landing late
Those are classic startup and reconnect bugs.
They just get misdiagnosed because the visible failure happens inside an LLM-powered workflow.
What I’d actually do tomorrow morning
If you’re running agents 24/7, here’s the checklist.
1) Gate every dependency with a real readiness signal
Examples:
- Postgres:
pg_isready - Redis:
redis-cli ping - HTTP tool server:
/healthor/readyz - OpenClaw Gateway:
openclaw gateway probe
2) Split startup from liveness
A slow warm-up is not the same as a dead process.
Don’t restart a healthy service just because initialization takes time.
3) Add one narrow file watcher if startup depends on generated artifacts
Good targets:
- config file
- plugin output directory
- socket file
- memory index
Bad target:
- your whole monorepo because “maybe something matters in there”
4) Make reconnect behavior explicit
If Postgres, Redis, or OpenClaw Gateway restarts, your agent should reconnect cleanly.
Don’t assume libraries will handle this the way you want.
Test it.
Actually restart the dependency and watch what happens.
5) Log the first minute like it matters
Because it does.
The first 30-60 seconds after boot, reconnect, or session reset is where a lot of “random” failures are born.
Log:
- dependency probe results
- config load timing
- tool registration timing
- reconnect attempts
- first successful query to Postgres/Redis
- first successful Gateway probe
A tiny shell gate is often enough
If you want a dead-simple startup guard, use a script like this before launching the agent:
#!/usr/bin/env bash
set -e
until pg_isready -h db -U app -d appdb; do
echo "waiting for postgres..."
sleep 2
done
until redis-cli -h redis ping | grep -q PONG; do
echo "waiting for redis..."
sleep 2
done
until openclaw gateway probe; do
echo "waiting for openclaw gateway..."
sleep 2
done
echo "all dependencies ready, starting agent"
exec python agent.py
It’s not fancy.
It is also dramatically better than “start everything and pray.”
Why this matters even more when you pay per token
Here’s the part people don’t talk about enough:
bad startup orchestration burns tokens.
If your agent crashes through half-ready dependencies, retries the same step three times, reconnects badly, and replays context, you’re not just dealing with reliability pain. You’re paying for avoidable mistakes.
That’s one reason predictable AI infrastructure matters.
If you’re building automations that run constantly, you want two things:
- startup discipline so the agent only runs when the stack is actually ready
- predictable pricing so retries and long-running workflows don’t turn into billing anxiety
That’s the appeal of Standard Compute for this kind of workload.
It gives you an OpenAI-compatible API with flat monthly pricing, so you can run agents, automations, and retries without staring at token burn all day. If you’re already wiring up OpenAI SDKs, n8n flows, or custom agent runners, the drop-in part is the point.
But even with flat-rate compute, the engineering lesson stays the same:
if your boot sequence is sloppy, your agent will still look flaky.
You’ll just be debugging the wrong layer.
The better question to ask
When an agent fails on first turn, don’t start with:
“Why did GPT-5 do that?”
Start with:
“What exactly was true about the environment when the model got work?”
Was Postgres ready?
Was Redis reachable?
Was OpenClaw Gateway warm?
Was the right tool profile loaded?
Was the config file complete?
Did a liveness probe kill a process that was still warming up?
That’s where a lot of the mystery goes away.
And honestly, that’s good news.
Because once you realize your “flaky” agent is usually just a badly orchestrated startup sequence, the problem becomes normal engineering again.
Normal engineering is fixable.
Top comments (0)