Expand description
The waiter: something that keeps waiting on a question after the process that asked it is gone.
magi ask blocks in the agent’s own shell tool, and that tool kills a wait
that runs long (see ask::WAIT_SLICE). An agent can also background the
call and simply finish. Either way the question outlives the only process
that would have read the owner’s answer, and the owner’s reply lands in a
file nobody is polling - the phone then says “waiting for the agent” while
there is no agent to wait for.
This module is the guarantee that something is always on the other end. It
runs inside magi serve, on its own cadence rather than the queue’s, and
for every question a magi ask filed it decides one of three things:
- the asker is still there (its
Leaseis fresh): do nothing. A second agent must never be started while the first is blocked; - the asker is gone and the owner has said or answered something the agent has not read: resume the same seat’s CLI session with the question, the thread so far and the owner’s words, so the agent that holds the context carries on;
- nobody answered before
answer_timeout: abandon it, in the same words the asker would have used.
§Shape
Same split as crate::queue and crate::ask: decide is pure - a
question, a lease, a clock and a bool in, an Action out - and every
filesystem or process effect is in Waiter::tick. State lives on disk (the
question record and its lease), so a restarted daemon picks up exactly where
the last one stopped, including an answer nobody has read yet.
§What it will not do
It never starts a fresh consultant. If the seat’s session cannot be resumed
(agent::has_session says no, the working directory is gone, the run is
over, the agent left the roster) the question stays as it is, the owner
gets a notification saying why, and nothing else runs. A new agent would
have to be caught up on everything the first one knew, and would act on the
owner’s words without the context they were written against.
It never assumes a resume worked either: a turn that fails or times out leaves the word undelivered, and a later tick tries again.
Structs§
- Waiter
- The waiter’s state: the store it watches and what it must remember between ticks (only which inputs it has already failed on).
Enums§
Constants§
- TICK
- How often the waiter looks at the store.
Functions§
- decide
- The whole decision, with no I/O.
- decide_
owned decide, told whether the daemon owns the answer’s action.- run
- The waiter’s loop, until
stopis asked for.