Lesson 1 · 12 min
From chat to queue: why save tasks
In chat, the agent does one thing at a time and only while the window is open. A durable queue stores each request, runs one at a time, resumes after a crash, and separates what worked from what failed.
Start lesson
In this lesson, you’ll
- 1The limit of chat: you have to keep watching
- 2The four guarantees of a durable queue
- 3Task states, from request to result
- 4Where inemaccbot fits in step 3
Goal: explain the four guarantees of a durable queue and why they let you step away.
01Chat × queue
The same request, in two different places.
Scroll down: each step below lights up its part of the diagram.
- 1/5
Chat
In chat, you type, wait, copy, and paste. If you close the window or the computer shuts down, the work in progress disappears. Ten tasks = ten waits with you in front.
- 2/5
Durable queue
The request is saved before it runs. In inemaccbot, the queue is a SQLite database on disk; in the homemade queue, it’s one file per task in a folder. Shut down? The task is still there.
- 3/5
Worker
A worker picks up a task, hands it to the agent, and waits. If the process crashes midway, on the next startup it recovers what was in flight before accepting new work.
- 4/5
Result
Each task ends in a clear state: it worked (with the file or text) or it failed (with the reason). That’s what you check in the morning.
- 5/5
Why this lets you step away
Save before running, one at a time, resume after a crash, and separate done from failed: with these four guarantees, turning off the screen doesn’t cost you work.
In inemaccbot, the request comes through Telegram; in the homemade queue from lesson 3, it’s an .md file in a folder. The idea is the same.
02The four guarantees
What you should expect from any queue, homemade or otherwise.
1. Save before running
The request becomes a record on disk as soon as it arrives. It doesn’t depend on an open window or the program’s memory.
In inemaccbot, each request becomes a job in a database table. It has a number (j13), a queue, a status, and a number of attempts remaining.
You send the request from your phone, the computer restarts, and the request is still in the list.
2. One at a time (per queue)
Each worker picks up a task, finishes it, and only then picks up the next one. This keeps two jobs from competing for the same machine.
In inemaccbot, there are five queues with different limits: the render queue runs one at a time on purpose because it uses the graphics card; the network queue accepts ten.
3. Resume after a crash
If the process crashes midway, the task isn’t lost or left half done forever. On the next startup, anything in progress goes back into the queue.
inemaccbot does this before accepting new work and writes to the log: boot: recuperação de leases — requeued=N failed=M. Requeued means it went back into the queue; failed means it had already used up all its attempts.
4. Separate done from failed
A task that errors doesn’t disappear or block the queue: it goes to the failures side, with the reason recorded, and the queue moves on.
inemaccbot prompts require the agent to finish with RESULT: <path> or ERRO: <short reason>. This contract lets you know how each task ended without opening anything.
03Task states
The names change from one queue to another; the idea is the same.
fila/ entrada/ # requests waiting their turn rodando/ # the task the agent is working on now feito/ # request + response falhou/ # request + ERRO and the reason
queued # in the queue, waiting its turn running # a worker picked it up and is running it done # finished with a result failed # ran out of attempts, with the reason canceled # you canceled it (/cancelar)
- Homemade queue: when you run it again, anything in
rodando/goes back toentrada/. - inemaccbot: the worker renews a task “lease” while it works. If the lease expires because the process crashed, the task goes back to
queuedas long as attempts remain.
In the homemade queue: an empty response or an error code from the agent. In inemaccbot: the agent didn't finish with RESULT:, the deadline (timeout) expired, or the attempts (max_tentativas, 2 to 4 in the catalog skills) ran out.
04Step 3 in video
inemaccbot's durable queue and approval gate, in a minute and a half.
05Test what you learned
The explanation appears after your answer.
Question 1 of 3
What's the essential difference between asking in chat and sending something to a durable queue?skill
Question 2 of 3
The bot log showed requeued=2 failed=1 on startup. What happened?
Question 3 of 3
A task failed at 3 a.m. What does a good queue do?
Choose an option. The explanation appears after you try.