The agent shows you a taxi at 18 euros with an Approve button. You are on the train and tap it twenty minutes later. In between, the quote changed to 22, the worker that asked the question was replaced in a release, and your friend also said “yes” in the group chat. What does your tap approve?
If the answer is “whatever the agent is doing now”, you have built an approval that can book the wrong thing. This article is about waiting for a person as a durable, checkable state instead of a sleeping thread, and about binding a yes to the exact action it was given for. It assumes you have built a human-in-the-loop step before. Robotelos terms are explained as they appear.
Why a sleeping worker is the wrong design
The simplest implementation holds the question in memory: send the card, block a thread or a callback, resume when the tap arrives. That fails the first time the process restarts, and keeping a process alive for every wait fails at the next restart. A wait that may last hours belongs in the database, with a way to end it. The same goes for a provider’s reply, as the lost reply at the restaurant showed.
There is a second, quieter failure. A “yes” is a sentence, and a sentence means whatever the current state says it means. A yes needs a subject.
A wait is a row
When a step needs approval, the engine writes a row to robotelos_engine_waits with its kind (APPROVAL, or INPUT for a question), its status, an expiry and the step it belongs to. Nothing sleeps. The status moves through OPEN to RESOLVED, EXPIRED, CANCELLED or SUPERSEDED. A default approval lapses after 30 minutes. A conversation has at most one open approval at a time, which the schema enforces with a unique index:
CREATE UNIQUE INDEX robotelos_engine_waits_one_open_approval
ON robotelos_engine_waits (conversation_id) WHERE status = 'OPEN' AND kind = 'APPROVAL';
When a worker has nothing left to do, it releases the run and sets wake_at to the earliest open expiry. If nothing else arrives, a worker picks the run up when the approval lapses, so expiry is handled as work and not forgotten. The wait id is derived from the run, the node and a counter, so asking again is a new row and the old one stays as history.
A yes is bound to a fingerprint
An approval carries a fingerprint: the identity of the step, which is its key, its capability, the capability’s version and a hash of its exact input, and nothing of the plan around it. The migration’s own comment says it plainly: a yes for another fingerprint is no yes.
// ApprovalFingerprint names what an approval is for: this step, with this input, against this version
// of the capability. An approval given for one fingerprint is no approval for another, so a step that
// changed after the person said yes is asked again, and a step that did not change is not, whatever
// else in the plan was revised.
func ApprovalFingerprint(p Plan, s Step) string {
return "sha256:" + StepIdentity(p, s)
}
Take the taxi. If the quoted fare is part of the step’s input, then when the quote moves from 18 to 22 the step has a new fingerprint, and the old approval no longer speaks for it. The engine closes it and asks again in a new row, so your tap on the old card counts for nothing and the booking stays on hold. If someone only revises a different part of the plan, the step is the same step, and you are not asked a second time. The same identity names the operation in the ledger, so a step that was already sent is not sent again.
At the protocol level, the obligation your client shows carries an id, a version, an expiry and a digest of the capability id, the contract version and the effective arguments. The server checks that the sender may answer, that the obligation is open with the expected version, that it has not expired and that the digest matches. A late or duplicate answer is STALE, and an answer after expiry is REJECTED. Buttons carry only the obligation id and the choice, never the digest.
The engine decides what a yes means
Your tap is not an action. The application records it as a command, APPROVE or REJECT, and the engine decides what it means in one decision. An approval that is open and fits the step is resolved as you said. One that lapsed, no longer fits the step or was decided already is left as it is, and the command is rejected. The consequences are deliberate:
- A late yes cannot undo a no.
- A yes for something else sends nothing.
- When two goals in one conversation each wait for a yes, a bare “yes” approves neither. The caller gets
ErrAmbiguousand asks which. - A yes that was already used keeps its row in force, because asking again would send the step a second time.
- Each question is itself an operation under its own key, so it is sent once, even if the worker that asked it is replaced.
The behavior tree puts an Await node in front of every step that needs approval. Its outcome is simple: asked and unanswered is running, yes is success, and no, lapse or “no longer fits” is failure, which stops the run with a code such as approval_declined or approval_expired. Nothing after the wait starts until the engine has seen the yes.
What this does not do
- Approval is not consent. An approval permits one action. Permission to use data or a capability at all is a separate question, and policy decides which actions need a yes.
- The environment is not in the digest yet. The protocol digest covers capability, version and arguments, and not where the agent runs.
- Natural language is messy. “Yes, but only tomorrow” is an amendment, not a boolean. The right design proposes the changed interpretation and applies the authority rule. It does not squeeze the sentence into a yes.
- Experimental. The engine and the goal strategy are experimental today. What you can use today tracks the maturity, and the approvals guide shows how a client answers an obligation.
Takeaways
- Store a wait as data with an expiry and a way to end, not as a sleeping process.
- Bind every approval to a fingerprint of the exact action, and compare it on every answer.
- Let the engine decide what an answer means, and record the answer as a command.
- Test the awkward cases: a tap after expiry, a tap on an old card, two goals waiting at once.
