Your agent sends a table request to a restaurant and the reply never arrives. The worker restarts. What should the agent believe?
Most retry code knows two answers: it worked, or it failed. This request has a third. It went out, and the agent cannot tell whether the restaurant acted on it. If you code that as “failed” and retry, you may book two tables. If you code it as “success”, you may promise a table that does not exist. This article shows how Robotelos keeps the third answer alive and resolves it with evidence. It assumes you know what an idempotency key is and nothing about Robotelos.
Two crashes that look the same
Before it calls, the agent saves the request, its key T-17 and the fact that it may have been sent. Then take two versions of the evening. In the first, the worker stopped just before it called the restaurant, so there is no reservation. In the second, the restaurant booked the table and the worker stopped before it saved the receipt.
The saved records are identical in both. Sending the request again helps in the first and leaves you with two tables in the second. Nothing in the agent’s own records can tell them apart, and a timeout does not help, because it says something about the agent’s patience and nothing about the restaurant. The only way out is to ask the restaurant about the original request.
What Robotelos records
Every call an agent makes is a row in an operation ledger. The row exists before anything is sent:
CREATE TABLE robotelos_engine_operations (
run_id text NOT NULL,
op_key text NOT NULL, -- m<k> for a model call, c/<8 hex of the step identity>/<step key> for a capability
requested_digest text NOT NULL, -- what was asked; the replay match
idempotency_key text NOT NULL, -- sent to the provider on every attempt
state text NOT NULL CHECK (state IN
('AUTHORIZED', 'DISPATCHING', 'SUCCEEDED', 'FAILED', 'UNKNOWN')),
attempt integer NOT NULL DEFAULT 0,
dispatch_epoch bigint NOT NULL DEFAULT 0, -- the epoch that last dispatched it
result json,
PRIMARY KEY (run_id, op_key)
);
The idempotency key is the run id and the operation key joined by a slash. It belongs to the request, not to the attempt, so a resend uses the same key. The operation key is derived from what the step does: its key, its capability, the capability’s version and a hash of its input. If you change the request (“German instead”), the step is a different step with a new key, and the old table still has an outcome to settle.
Sending is three steps. A commit moves the row from AUTHORIZED to DISPATCHING and counts the attempt, and that commit is fenced, so a worker that lost the run cannot send. Then the provider is called with the idempotency key. Then the result is recorded and the row becomes SUCCEEDED, FAILED or UNKNOWN. A worker that dies in between leaves a row in DISPATCHING. That row is the evidence that a request may be in flight, and nobody has to remember anything.
How an unknown outcome is resolved
When a worker with a newer claim finds a capability call in DISPATCHING, it marks the row UNKNOWN and reconciles it. A model call is different: it has no effect on the world, so it is simply asked again. For a capability the engine goes down a ladder:
- Ask the provider. If it has a record under the idempotency key, that record is the result, and the row becomes
SUCCEEDEDorFAILEDfrom the evidence. - No evidence, and the capability is declared retry-safe. The row returns to
AUTHORIZEDand is sent again under the same key. - No evidence, and it is not retry-safe. The engine stops the run with the reason
unknown_outcomeand leaves the decision to a person. It does not guess.
Retry safety and the meaning of success are declared by the capability, next to its input schema:
func restaurantReserve() taskplanner.CapabilityDef {
return taskplanner.CapabilityDef{
ID: "restaurant.reserve", Version: "1",
InputSchema: /* date, time, party_size, restaurant_name; additionalProperties: false */,
Outputs: []string{"status", "reservation_id"},
RetrySafe: true,
Kind: taskplanner.KindAction,
Outcome: &taskplanner.Outcome{Field: "status", Op: "equals", Value: json.RawMessage(`"confirmed"`)},
}
}
RetrySafe: true is a promise by the capability’s author that the provider honors the key, so a repeat returns the same reservation. Outcome says the result counts as the promised effect only when status equals "confirmed". Adapters that implement the typed outcome interface return evidence instead of a bare error, and the engine is strict about it: applied evidence wins over a transport error that came with it, and a malformed or ambiguous outcome never claims success. It becomes UNKNOWN.
How we test it
The tests kill processes. TestEngineProcessKilledAfterTheProviderActed starts an engine as a separate process, waits until the test restaurant has booked the table, and kills the process with SIGKILL before it records the result. Nothing survives in memory. A second engine takes the run when the lease expires, finds the row in DISPATCHING and resolves it from the provider’s evidence. The test asserts one booking and one provider call: unknown was settled by evidence, not by sending again. Test hooks stop the engine between “the intent is committed” and “the provider was called”, and between “the provider was called” and “the result is recorded”. Those are the two gaps a recovery design has to survive. The test code is in fault_test.go and the engine in engine.go.
What this does not solve
- Exactly-once. Robotelos does not claim it. A sender can deliver at least once and make a repeat harmless where it controls the receiver. At a restaurant it does not, and only the provider’s contract says what a second request does.
- A lookup that lags. “Not found” may mean the request has not reached the system the lookup searches. A provider whose lookup is not read-your-writes should not be declared retry-safe. A request still on its way can also arrive just after a lookup reported it absent.
- Providers with neither. With no key support and no reliable lookup, the honest outcome is a paused run and a person. That costs the person some waiting. I think it is the right trade against a double booking that was reported as success.
Takeaways
- Give “sent, outcome unknown” its own state, and do not let it collapse into success or failure.
- Save the intent and the key before the call, and use the same key for every attempt.
- Decide per provider whether a resend is safe, and write that decision down where the code can read it.
- The engine is experimental today. The execution model describes the states, and What you can use today tracks the maturity.
