Repository navigation
Task state machine - #938
Eliot Horowitz (erh) wants to merge 10 commits into
Conversation
A task is a unit of robot work with a start, an end and an outcome: Run streams progress and ends with a Result, GetStatus reports idle or running. A state machine is a configured graph of states that runs tasks and reacts to events: GetState, SendEvent, GetHistory, GetDefinition, Stop and Reset. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018vMsNdievPPiRY8gB5KrKR
Run returns the result when the task is finished; progress is read with GetStatus rather than streamed. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018vMsNdievPPiRY8gB5KrKR
|
Hey Eliot Horowitz (@erh) — this PR has been approved and CI has been green for 5+ business days. Ready to merge? Auto-comment from overwatch. Will not re-nudge for 7 days. |
|
Hey Eliot Horowitz (@erh) — this PR has been approved and CI has been green for 6+ business days. Ready to merge? Auto-comment from overwatch. Will not re-nudge for 7 days. |
…tatus GetDefinition now returns the machine's states (path, initial child, handled triggers, whether it runs a task), its top-level transitions and every trigger, instead of an untyped Struct. GetCurrentJobId identifies the current run of the machine: a new job starts at startup and on Reset. The task service's typed status RPC is GetTaskStatus; GetStatus is the standard resource status every other service exposes. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018vMsNdievPPiRY8gB5KrKR
Nick Hehr (HipsterBrown)
left a comment
There was a problem hiding this comment.
Some feedback from building a small toy program against this API: a task implementation, a minimal state-machine engine, and a client that drives it.
| repeated StateDefinition states = 2; | ||
| // Every trigger any state or the machine itself handles. Task outcomes and | ||
| // external events share this namespace; an agent may send any of them. | ||
| repeated string events = 3; |
There was a problem hiding this comment.
Task outcomes and external events share one namespace, and this says an agent may send any of them. In practice that means a client can send an outcome like done while a task is running; the machine cancels the task and transitions as if it had finished. The only trace in history is an empty task_result.
Suggest separating the two namespaces (e.g. outcomes vs events here), or having SendEvent reject names that are only task outcomes.
There was a problem hiding this comment.
We looked at splitting them and decided to keep the shared namespace, for two reasons. Outcomes are free strings produced by tasks at runtime, so the engine cannot classify a name as outcome-only without a second config list that would have to track every task's possible outcomes. And sending an outcome name from the outside is useful on purpose: it is how an operator unsticks a machine whose task is wedged, without a Reset that loses the whole job.
What was missing was the audit trail, which the new source field on Transition supplies: an outcome name that arrives through SendEvent is recorded with source EVENT, so history shows the override rather than an empty task_result. The events doc now says this explicitly (e8e4d12). Happy to revisit if you have a case where the override is harmful rather than merely visible.
Generated by Claude Code
Review feedback from building against the API: - Transition carries source (initial, outcome, event, timeout, stop, reset, fault) and job_id, so history shows what caused a change without inferring it from task_result and can be grouped by job. - GetStateResponse carries job_id, read together with the state so a client cannot straddle a Reset between GetState and GetCurrentJobId. - StateDefinition names the task resource a state runs and its timeout instead of a bare has_task flag. - A task outcome no state handles now faults the machine; the reserved outcomes (done, error, cancelled, timeout) and the failure contract for Run are written down, as are the context merge rules and the shared outcome/event namespace. - GetHistory ordering is documented once: most recent limit transitions, oldest first. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018vMsNdievPPiRY8gB5KrKR
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018vMsNdievPPiRY8gB5KrKR
GetHistory returns JobHistory entries, one per job with its start time and its transitions oldest first, instead of a flat list; the request takes an optional job_id filter and limit now counts jobs. Transition drops job_id, which the grouping makes redundant. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018vMsNdievPPiRY8gB5KrKR
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018vMsNdievPPiRY8gB5KrKR
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018vMsNdievPPiRY8gB5KrKR
needs more work - but close