Problem: Most loop talk drifts back into theory. I wanted something that actually wakes up, picks up work, writes something down, and goes back to sleep.
Solution: I made two tiny versions behind one Worker. One uses a Durable Object alarm. The other uses Workflows. Same basic job. Wake up. Check for work. Do the tiny part. Sleep again.
task -> KV inbox -> loop wakes up
|
+-> claim one item
+-> write result
+-> sleep
TODO: hand off to Codex CLI runnerThis is mostly a self-experiment. I wanted to see how small I could make a real loop on Cloudflare before it stopped feeling real.
Not a pattern post. Not a big theory of agent infrastructure. Just a little thing that runs.
Code
- acoyfellow/self .. standalone repo
- src/index.ts .. the whole loop in one file
- wrangler.jsonc .. bindings and deploy config
- self.coey.dev .. live Worker
What I Made
The Durable Object version is the scrappier one. Alarm fires. Durable Object calls back into the Worker. Worker claims one task. Alarm sets the next wake-up and does it again.
The Workflow version is cleaner. Same pickup pattern. Better history. If I wanted named steps and a more official shape, I would probably reach for that first.
What I'm Actually Testing
I'm not really trying to prove that Cloudflare is secretly a forever process machine. I just wanted to see whether it could hold the loop open long enough to count.
That split is the part I care about. Cloudflare wakes the thing up. KV holds the task. Some other environment can do the heavier work.
Open the repo. Run `codex`. Apply a patch. Report back. At that point it stops feeling like one process and starts feeling like a handoff.
The First Two Things I Tried
I started with two tiny tasks because that felt like enough to make the loop concrete.
One is a todo closer. Open `todo.md`. Pick the first unchecked line. Make the smallest valid patch.
The other is a CI sweeper. Read the latest failing logs. Draft the smallest fix. Stop when the checks go green.
Both are small enough to imagine. Both are annoying enough that I want the loop.
What It Doesn't Do Yet
Right now `self` stops at claim plus log. It proves the wake-up pattern. It proves the queue. It proves the handoff works.
It does not run `codex` yet. That still needs an external runner. I'm fine with that. It makes the boundary clearer.
Related
- Loop .. The repo is the thing that persists.
- Workflow Live .. Durable workflow visibility on the edge.
- Durable Objects Gotchas .. The sharp edges are real.