Skip to content

Task state machine - #938

Open
Eliot Horowitz (erh) wants to merge 10 commits into
mainfrom
task-state-machine
Open

Eliot Horowitz (erh) wants to merge 10 commits into
mainfrom
task-state-machine

Conversation

@erh

Copy link
Copy Markdown
Member

needs more work - but close

Eliot Horowitz (erh) and others added 2 commits October 16, 2026 05:11
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
@viambot viambot added the safe to test committer is a member of this org label Nov 2, 2026
@viam-overwatch

viam-overwatch Bot commented Nov 9, 2026

Copy link
Copy Markdown

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.

@viam-overwatch

Copy link
Copy Markdown

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.

Eliot Horowitz (erh) and others added 2 commits November 23, 2026 22:13
…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

@HipsterBrown Nick Hehr (HipsterBrown) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread proto/viam/service/task/v1/task.proto Resolved
Comment thread proto/viam/service/task/v1/task.proto Resolved
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe to test committer is a member of this org

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants