Skip to content

Statecharts for Reboot state types - #343

Open
benh wants to merge 61 commits into
mainfrom
claude/practical-brown-wd2pry
Open

benh wants to merge 61 commits into
mainfrom
claude/practical-brown-wd2pry

Conversation

@benh

@benh benh commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Implements the design Statecharts for Reboot state types: a state type can declare a statechart, in pydantic (Type(statechart=Statechart(...))) or in protobuf (the statechart field of (rbt.v1alpha1.state)), which rbt generate checks, the developer dashboard draws, and an interpreter runs.

Status: draft. Ten commits, one per part. The series was rebuilt several times in review; this description is of the current head. The database change in commit 6 is C++ that I could not build locally: only CI has compiled it or run its tests. Everything in Python was run locally against the published 1.7.2 wheel with the repository's sources laid over it and a shim standing in for the database's handling of the status: every tests/reboot/statechart test and tests/reboot/state_manager_tests.py pass at the head, and each commit passes its own tests when checked out alone. The dashboard's TypeScript was type-checked and unit-tested outside the page's build, and the page has not been looked at in a browser.

What is in each commit

# Commit What it adds
1 The Statechart message rbt/v1alpha1/statechart/statechart.proto, the helpers of reboot.statechart that build the message, and tree.py, lookups over it.
2 Validation Every rule in the design's list, each with a message naming the state and transition.
3 Step function The Status message, and the pure function from chart, status, state and methods to the next status, the actions to run and the activities to stop and start.
4 The state option StateOptions.statechart, and the build changes that follow from options.proto importing a new file.
5 Pydantic entry point Type(statechart=...), StateType.statechart in api.proto, and the translator writing the option and the event messages.
6 The status, stored beside the state Actor.statechart_status in the database, and the state manager carrying it with the state.
7 The plugin rbt generate checks the chart for both forms; generated Machine, typed declarations of the chart's methods, self.statechart.
8 Interpreter, no activities The RunStatechart task, scheduled only when there is work.
9 Timers and activities Timer, Schedule, and waiting for an activity before leaving its state (leaving).
10 Dashboard and documentation The types pane draws a state type's chart; documentation/docs/statecharts.md.

The shape of it

  • The protobuf messages are the only representation of anything they describe. A chart is the Statechart message everywhere, and where an instance is, is the Status message everywhere. There are no parallel Python classes or TypeScript interfaces, and no converters. The pydantic helpers only build the messages.
  • A state type declares nothing but the chart. There is no field for the status and no rpc for the interpreter, in either form.
  • The status is stored beside the state, not in it. Actor has an optional statechart_status, stored under a key of its own (statechart-status:<state_ref>) in the actor's column family, in the same batch as the state. The state manager keeps it wherever it keeps the state (cache, transaction, nested-transaction snapshot, prepare, commit), a method changes it through Effects.statechart_status, and reads it with StateManager.statechart_status(context). No method of the type can write it.
  • The interpreter is a task that is not an rpc. The generated middleware dispatches a task named RunStatechart to the runtime, and only the runtime creates one, as a task effect of a method of the state. Nothing outside the type can call it and no authorizer needs a rule for it. A type with a statechart cannot have an rpc named RunStatechart.
  • Every step is one commit. A step's inline write stores the state, the status, and the tasks for what the step starts (an activity, a timer, the next run) together.
  • Conditions, guards, actions and activities are each an Inline, a method of the servicer that only the chart calls, inside a oneof so that a reader, writer, transaction or workflow can be added later. Call.Inline lists the events it injects (handled next, ahead of what is waiting) and Schedule.Inline the events it enqueues (at the back) by returning them. An activity is a class method given a WorkflowContext.
  • Events are named by their message's full name ("shop.v1.ServiceDue"), and a chart lists every event it mentions in events. A queued event is a google.protobuf.Any; a fixed event's fields in the chart are a Struct.

Things to know when reviewing

  • Commit 6 touches the database and the state manager. DatabaseClient.load_actor_state became load_actor and returns the Actor. An actor upsert still always has the state, and stores the status with it when it has one; effects that change only the status store the state as it is alongside. Export now takes its snapshot explicitly so that it can read each actor's status as of the same moment, and exports it with the actor's state, carried as ExportImportItem.statechart_status beside state. A transaction whose only effect is a new status takes its lock exclusively, and a status stored without a new state notifies streaming readers. Existing data needs no migration.
  • Commit 8 lets two more kinds of effects carry tasks, for a type with a statechart: an inline write's and a transaction method's. A task that a step schedules is dispatched from within that step's task and starts with a copy of its context variables, which RunStatechart resets rather than asserting they are unset.
  • options.proto now imports statechart.proto, which imports any.proto and struct.proto. Generated Python imports the _pb2 module of every file its .proto reaches, so the Python golden files change by those lines and the Node.js golden by the compressed copy it embeds. js_proto_library hands protoc only the descriptor sets of its listed proto_deps, so the macro adds the new files for any library that lists options_proto or api_proto.
  • An event's class is defined in the API file or in a module beside it, because its message is generated into the API's package.
  • Within a transaction, events are queued in the order their methods commit, so an event a transaction method enqueues comes after those enqueued by writers it called.
  • Stale timers are recognised by their record, not by epoch. Comparing epochs would drop an ancestor's timer after a move between its children.
  • A run hands over to a fresh run after 100 steps, so no single workflow's history grows without bound.
  • A Node.js servicer cannot have a chart yet: its plugin refuses one with a message.
  • The dashboard draws the chart as nested boxes with their transitions listed, not as a laid-out diagram with arrows.

Not done

How to try it

tests/reboot/statechart/traffic_light_api.py and proto/traffic_light.proto are the same chart in the two forms, traffic_light_servicer.py beside each is its servicer, and traffic_light_test.py runs one set of tests against both.

🤖 Generated with Claude Code

https://claude.ai/code/session_017sw2rydNyewFGnC8Fj1T7f

@aviator-app

aviator-app Bot commented Nov 10, 2026

Copy link
Copy Markdown

Current Aviator status

Aviator will automatically update this comment as the status of the PR changes.
Comment /aviator refresh to force Aviator to re-examine your PR (or learn about other /aviator commands).

This pull request is currently open (not queued).

How to merge

To merge this PR, comment /aviator merge or add the mergequeue-ready label.


See the real-time status of this PR on the Aviator webapp.
Use the Aviator Chrome Extension to see the status of your PR within GitHub.

benh commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

"Build public repo for MacOS arm64" failed on ee8eb30, and the failure is not this PR's. Bazel timed out fetching an external repository on the runner: whl_library.ExtractWheel(mypy_integration_pip_deps_mypy, mypy-1.18.1-cp310-cp310-macosx_11_0_arm64.whl) hit its 600 second timeout with Timed out on stderr, which aborted analysis (no such package '@@mypy_integration_pip_deps_mypy//') before any target of this change was reported failing. This PR does not touch the mypy integration, WORKSPACE.bazel or bazel/deps.bzl. There is no fix to port: the job needs a re-run. I tried to re-run the failed job and the integration's token is not allowed to (403 Resource not accessible by integration), so someone with access needs to re-run it, or the next push will.

The earlier Linux arm64 failure on 61ad1f6 was this PR's (reboot.statechart reached the pydantic to proto tool without its __init__.py) and is fixed in ee8eb30. On that commit the style check, the documentation build, both Manylinux tests, the Maestro test and the development containers have passed; the two Linux Bazel builds are still running.


Generated by Claude Code

@benh
benh force-pushed the claude/practical-brown-wd2pry branch 9 times, most recently from 0009d81 to 41635e3 Compare November 11, 2026 19:58

benh commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

"Test React Native mobile app (Maestro)" failed on 41635e3 before any repository code ran. The dev container image build died at add-apt-repository ppa:deadsnakes/ppa: Launchpad answered the signing-key request with HTTP 500 and the body GPGKeyTemporarilyNotFoundError, so Maestro never started. That is Launchpad's side and nothing in this PR touches the image or the mobile app; the same job passed on the earlier heads of this branch.

There is nothing to fix in the PR for it. The job needs a re-run, which I could not do: the re-run request was refused with 403 Resource not accessible by integration. Could someone with access re-run the failed job? I am still watching the other checks on this head.


Generated by Claude Code

@benh
benh force-pushed the claude/practical-brown-wd2pry branch 18 times, most recently from 4939da2 to 63a608b Compare November 14, 2026 05:13
@benh
benh force-pushed the claude/practical-brown-wd2pry branch 4 times, most recently from 8253218 to ded0d2f Compare November 17, 2026 20:56
Storing an actor replaces what is stored for it, statechart status
included. The state manager knew only of an actor's state, so
storing an actor's new state would have removed its statechart
status.

The state manager now keeps the statechart status beside the state,
wherever it keeps the state:

  * `_statechart_statuses` is beside `_states`, and is filled when
    an actor is loaded;
  * a transaction has `statechart_status` beside `state`, copied
    from what was loaded when the state is, kept in the snapshot for
    a nested transaction so that a rollback restores it, and moved
    to `_statechart_statuses` when the transaction commits;
  * a store, and a transaction that prepares, send the statechart
    status that the actor has with its new state.

To have the status to keep, `DatabaseClient.load_actor`, which was
`load_actor_state`, returns the `Actor` and not only its state, and
preloading resolves to the `Actor` too. A transaction that defers
its writes sends its state when it prepares, so
`TransactionParticipantPrepareRequest` gets `statechart_status` to
send with it, and the database stores the two as one `Actor`.

Nothing sets a statechart status yet, so nothing changes in what is
stored. It is carried, and no longer dropped.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017sw2rydNyewFGnC8Fj1T7f
@benh
benh force-pushed the claude/practical-brown-wd2pry branch from ded0d2f to 8b7b59e Compare November 17, 2026 21:02
benh and others added 9 commits November 17, 2026 21:24
The state manager loads, keeps and stores where a state's statechart
is, but nothing could read it or change it.

`Effects` gets `statechart_status`. Effects that have one change
where the state's statechart is, in the same store as the state, and
within a transaction as part of it, so that it commits or rolls back
with the state. Effects that have none leave it as it was. Changing
it needs the exclusive lock, the way changing the state does.

The state and the statechart status are always stored together,
since storing an actor replaces what is stored for it: effects that
change only one of the two store the other as the actor has it.

`StateManager.statechart_status(context)` returns a copy of where
the statechart of the state that `context` is for is, and within a
transaction the transaction's own.

A method cannot reach either. It is not given the state manager, and
it is what calls a method that makes the `Effects` from what the
method returns. Nothing is added to the context.

What a reader returns may depend on where the statechart is, so a
statechart status that changes on its own notifies the streaming
readers of the state, with the state as it is, the way a state that
changes does.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017sw2rydNyewFGnC8Fj1T7f
The database exports an actor whole, statechart status included, but
the item that an actor is exported as and imported from had only the
actor's state. An actor that was exported and imported again lost
where its statechart is.

`ExportImportItem` gets `actor`, an `ExportImportItem.Actor` that
has the actor's state and its statechart status, each as a
`google.protobuf.Struct` the way a task and an idempotent mutation
are. Exporting writes `actor`, and importing gives both to
`StateManager.import_actor`, which stores them together.

`state`, which is all that was exported of an actor until now, is
still imported, as an actor without a statechart status, since it is
from before there was one. What is exported from now on does not
import into a Reboot from before it.

Importing overwrites, so an actor that is imported without a
statechart status is left with none, whatever it had.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017sw2rydNyewFGnC8Fj1T7f
`check_statechart` checks a statechart on its own. Two things about
a statechart can only be checked against the file that its state is
declared in: what an event is, and what else the state has methods
for. Generating code for a statechart needs both to hold.

`rbt generate` now checks, for a statechart that has no problems of
its own, that:

  * each of its `events` is the full name of a message, in the
    state's file or in a file that it imports;

        Error processing 'shop/v1/order.proto': The statechart of
        'shop.v1.Order' has the event 'shop.v1.Payed', which is not
        a message; an event is the full name of a message of
        'shop/v1/order.proto' or of a file that it imports.

  * no method that it names, as a `guard`, a `condition`, a `call`
    or a `schedule`, is also what an rpc of the state is as a
    method, which is the rpc's name in snake case.

        Error processing 'shop/v1/order.proto': The statechart of
        'shop.v1.Order' names the method 'get_id', which is also
        what the rpc 'GetID' of 'shop.v1.OrderMethods' is as a
        method; a method of a statechart and an rpc cannot have the
        same name.

Every event that a statechart mentions is one of its `events`, so
those are all that there is to look up. The methods come from
`on_transitions`, `when_transitions`, `calls` and `schedules`, which
`validation.py` had for its own use and are no longer private.

Nothing is generated for a statechart yet.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017sw2rydNyewFGnC8Fj1T7f
A statechart named a method "the way an rpc is", as in
`IsPaidInFull`, and the method was to be implemented as
`is_paid_in_full`. Getting from the one to the other loses what
tells two names apart: `GetID` and `GetId` are both `get_id`. So two
methods of a statechart could have been one method to implement
without anything noticing.

A statechart now names a method by what it is called where it is
implemented, in snake case:

    guard { inline { method: "is_paid_in_full" } }

`check_statechart` gets its twenty-seventh rule, for the method of a
`guard`, a `condition`, a `call` and a `schedule`. It is in snake
case, and it is not a Python keyword:

    Error processing 'shop/v1/order.proto': The statechart of
    'shop.v1.Order' has 1 problem:
      - the `guard` of an `on` transition of state `PENDING` has the
        method `IsPaidInFull`, which is not in snake case, as
        `is_paid_in_full` is

Two methods of a statechart are then the same method exactly when
they are named the same, which is how the rule that a method is
named in only one way already compares them.

The tests' statecharts name their methods in snake case.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017sw2rydNyewFGnC8Fj1T7f
A statechart names a method for each guard and each condition. The
Python servicer of a state with a statechart now declares each one,
so that an implementation of the state provides them:

    def is_settled(
        self,
        state: Order.State,
        event: order_pb2.Paid | order_pb2.Refunded,
    ) -> bool: ...

    def is_cancelled(self, state: Order.State) -> bool: ...

A guard takes the state and the event of the transition it is on; a
guard on transitions on more than one event takes any of them. A
condition takes the state. Both are synchronous and take no context:
each answers a question about what it is given.

The methods are abstract and are declared on the base servicer, so
a servicer that leaves one out cannot be instantiated, whichever of
`Servicer` and `singleton.Servicer` it derives from.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017sw2rydNyewFGnC8Fj1T7f
A statechart names a method for each call. The Python servicer of a
state with a statechart now declares each one, as it does the guards
and the conditions:

    def record_payment(
        self,
        state: Order.State,
        event: order_pb2.Paid,
    ) -> Optional[order_pb2.Settled]: ...

    def send_receipt(self, state: Order.State) -> None: ...

A call takes the state, which it may change. A call that is an
action of an `on` transition also takes the event of that
transition, which is how what an event carries gets into the state.
An `entry`, an `exit` and an action of a `when` transition have no
one event that they are for, so they take only the state.

A call that has `injects` returns the event to inject, or `None`;
any other call returns `None`.

A method has one signature, so a statechart is now checked to not
name the same method both by a call that is given the event and by
one that is not.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017sw2rydNyewFGnC8Fj1T7f
A statechart names a method for each schedule. The Python servicer
of a state with a statechart now declares each one, as it does the
guards, the conditions and the calls:

    @classmethod
    async def charge_card(
        cls,
        context: WorkflowContext,
    ) -> Optional[order_pb2.Paid | order_pb2.Refunded]: ...

    @classmethod
    async def send_reminders(cls, context: WorkflowContext) -> None:
        ...

A schedule is declared as a workflow of the servicer is: an
asynchronous class method that takes a `WorkflowContext`. It takes
no event, since a schedule is an `entry`.

A schedule that has `enqueues` returns the event to enqueue when it
finishes, or `None`; any other schedule returns `None`.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017sw2rydNyewFGnC8Fj1T7f
The Python servicer of a state with a statechart now has
`statechart()`, with which a method reads where the statechart is:

    async def status_from_reader(
        self,
        context: ReaderContext,
        request: Empty,
    ) -> statechart_pb2.Status:
        return self.statechart(context).status()

`statechart()` is given the context of a reader, a writer or a
transaction, each of which has the state, and returns an
`ImmutableStatechart`. Its `status()` returns a copy of the `Status`
that is stored with the state, and an empty one for a state whose
statechart has not started; within a transaction it is the
transaction's own.

The statechart is lent to a method the way the `state` of a servicer
is. For each call the generated code makes an `ImmutableStatechart`
from the status that the state manager has and puts it in a context
variable for as long as the method runs, and `statechart()` returns
what the context variable has. A state type has it as
`Order.ImmutableStatechart`.

Nothing sets a statechart status yet, so the test gives an order
one where the state manager keeps it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017sw2rydNyewFGnC8Fj1T7f
A writer or a transaction of a state with a statechart now enqueues
one of the statechart's events with the statechart of its servicer:

    async def pay(
        self,
        context: WriterContext,
        request: order_pb2.Paid,
    ) -> Empty:
        await self.statechart(context).enqueue(request)
        return Empty()

There are now two kinds of statechart. `statechart()` returns an
`ImmutableStatechart`, which has only `status()`, for the context of
a reader, and a `Statechart`, which also has `enqueue()`, for the
context of a writer or a transaction. A reader cannot enqueue
because what it is given has no such method. A state type has the
second as `Order.Statechart`.

The event goes at the end of the queue of the statechart status, by
the full name of its message and with its fields as a `Struct`.
`enqueue()` is a coroutine, as scheduling a task from a writer is,
so that it can come to do more than append.

`status()` of a `Statechart` has every event that the method has
enqueued. When the method returns, the status goes into the method's
effects if the method changed it. An event is therefore stored with
the method's change to the state, and a method that fails enqueues
nothing.

An event may be enqueued before the statechart has started: the
status then has a queue and no active state.

A workflow cannot enqueue yet; the inline writer has a TODO to let
it take the statechart as well as the state.

The test of `status()` no longer sets a status where the state
manager keeps it, now that a method can change one, and it gains a
reactive reader that gets an event that is enqueued.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017sw2rydNyewFGnC8Fj1T7f

benh commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

CI on e65cb41: "Build public repo for Linux arm64" and "Test React Native mobile app (Maestro)" both failed while building the dev-container image, before Bazel or any test started, so nothing from this PR was built or checked in either job. "Build public repo for Linux x86_64" failed at about the same time and very likely for the same reason, though I have only read the logs of the first two.

The failing step is in the Dockerfile, which this PR does not touch:

#66 RUN codex mcp add chrome-devtools -- npx --yes chrome-devtools-mcp@latest --headless=true
Error: Missing optional dependency @openai/codex-linux-arm64. Reinstall Codex: npm install -g @openai/codex@latest

(@openai/codex-linux-x64 on the x64 job.) The step before it, RUN npm install -g @openai/codex, is deliberately unpinned and now installs only the wrapper package without the platform binary, so the codex command that follows throws. It fails the same way on both architectures, so it will keep failing on any PR until the Dockerfile pins a working @openai/codex version or installs the platform package explicitly, or the package is fixed upstream. A rerun alone will not clear it.


Generated by Claude Code

benh and others added 3 commits November 20, 2026 03:10
A workflow of a state with a statechart now gets the statechart
along with the state from an inline reader and an inline writer:

    state, statechart = await Order.ref().read(context)

    async def record_charge(
        state: Order.State,
        statechart: Order.Statechart,
    ) -> None:
        state.owed_cents = 0
        await statechart.enqueue(order_pb2.Paid(cents=500))

    await Order.ref().write(context, record_charge)

An inline reader returns the state and an `ImmutableStatechart`, and
an inline writer is given the state and a `Statechart`, so a
workflow enqueues an event with an inline writer. Both always have
the statechart for a state type that has one, and are as they were
for a state type that has none.

What an inline writer enqueues goes into the effects of the write,
with its change to the state and its result, so it is stored once
however often the workflow runs again, and an inline writer that
fails enqueues nothing.

The state manager's `read()` now returns the statechart status with
the state, which is `None` for a state type that has no statechart,
so that the two are of the same store. An inline reader of a state
type with a statechart that remembers what it read remembers both.
One of a state type without a statechart remembers the state alone,
as before, so a workflow that is running across an upgrade finds
what it stored. The generated code for every state type takes the
state from what `read()` returns, which is the change to the
goldens.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017sw2rydNyewFGnC8Fj1T7f
An event of a statechart is a message, and in the queue of a
statechart status it is the full name of that message with its
fields as a `Struct`. `reboot/statecharts/events.py` now has what
makes each from the other: `status_event_from_message()` and
`message_from_status_event()`.

`enqueue()` of a generated `Statechart` makes what it adds to the
queue with the first, and the tests of `enqueue()` say what they
expect in a queue with it in place of a helper of their own.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017sw2rydNyewFGnC8Fj1T7f
The statechart of a state is now run when a writer, a transaction or
an inline writer of the state returns, on the state as the method
left it and before the method's effects are stored. Whatever the
statechart does is therefore stored with the method's own change: a
method that enqueues an event leaves the event handled, and a reader
never finds one that is waiting.

`run()` in `reboot/statecharts/interpreter.py` runs a statechart
until it has nothing left to do:

  1. A statechart that has not started starts: the statechart is
     entered, and then its `initial` and on into the states within
     that.
  2. Every `when` transition that fires is taken.
  3. The event at the head of the queue is taken from it, and the
     `on` transition that fires for it is taken; an event that no
     transition fires for is dropped. Then 2 again, until the queue
     is empty.

`maybe_when_transition()` and `maybe_on_transition()` say which
transition fires. A state has its own transitions and inherits those
of each state it is within and of the statechart, innermost first;
the first whose guard or condition holds fires, and each, which is
a method of the servicer as a call is, is asked only if what it
answers decides that.

`states_exited_and_entered_from_transition()` says what taking a
transition exits and enters: every active state that its `to` is
not within is exited, and its `to` is entered and on into the states
within it, from their `initial` or, with `resume`, from their
history.

Taking a transition calls the methods of the servicer that the
statechart names with the state: each `exit` of each state that is
exited, each action of the transition, which alone is given the event,
and each `entry` of each state that is entered. An event that is
injected goes ahead of every event that is waiting.

`run()` and what it calls leave the status that they are given as
it is. Each returns the status that the statechart has come to, or
`None` if that is the one it was given, so `run()` returns `None`
for a statechart that had nothing to do. The state is what the
methods of the servicer change, as a method of a servicer does.

A method that the statechart calls and that fails fails the method
that is returning, and a statechart that takes more than 1000
transitions in one run is stopped with an error.

The order that the tests have is now one whose statechart does
something to see: its calls add their names to the order, and the
tests of an application say what the order and its statechart have
come to. A `schedule` and a `timer` are not started yet.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017sw2rydNyewFGnC8Fj1T7f

benh commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

CI on dc0ce7a: "Build public repo for Linux arm64" failed on one test that this PR does not touch, //tests/reboot/dashboard:features_watcher_tests_py (Executed 238 out of 287 tests: 286 tests pass and 1 fails).

ERROR: test_recordings_are_named_against_scenarios_and_steps (__main__.FeaturesWatcherTest)
http.client.BadStatusLine: ... Unexpected HTTP/1.x request: GET /recordings/sign?path=tests%2Fbank.recordings%2F...

The test's plain HTTP request reached a listener that only speaks HTTP/2, which is a transport-level mismatch in the dashboard test harness rather than an assertion about behaviour. The same test passed on the Linux x86_64 build of this same commit, and the previous head (ce3e268) was fully green; the only content that changed since is under tests/reboot/statecharts, a comment in statechart.proto and a comment in reboot.py.j2. All //tests/reboot/statecharts targets passed on arm64, including the new activity_test case.

This looks like a flake. It needs "Re-run failed jobs" on run 44695500350, which this session's GitHub access is not allowed to trigger. If it fails the same way again it should be investigated rather than rerun.


Generated by Claude Code

benh and others added 10 commits November 20, 2026 19:34
`run()` had two statuses: the one it was given, and the one that the
statechart had come to once that was another, so it read where the
statechart is as `modified_status or status` throughout.

It now has one `status`, which is always where the statechart is,
and remembers the one it was given. Nothing changes a status: what
`run()` calls returns the status that the statechart then has, which
is the very status it was given if it left the statechart where it
was. `_take_transition()` returned `None` for that, and now returns
the status it was given. So the statechart is where it was if and
only if `status` is still the one that `run()` was given, which is
what it looks at to return `None`.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017sw2rydNyewFGnC8Fj1T7f
The effects that a transaction completes with may have tasks, as
those of a writer may. They were stored, and counted in deciding
whether the transaction needs its lock exclusively, but they were
not among the tasks of the transaction, which are what is validated
when the transaction prepares and dispatched once it has committed.
So a task in the effects of a transaction would never have run.

Nothing put a task there: a transaction schedules a task by calling
the state that it is of, and the writer that the call runs has the
task in its effects. A transaction is about to, for an activity of
a statechart that it starts.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017sw2rydNyewFGnC8Fj1T7f
An asyncio task starts with a copy of the context that it is created
in, so a task that the tasks dispatcher dispatched started with every
context variable of the request that dispatched it: the context of
that request, its idempotency seeds, whether it is within a loop,
and, when that request is a workflow, the servicer of that workflow.

A workflow of a servicer finds its servicer in a context variable,
which the generated code sets when the workflow starts, after it has
checked that none is set. A task that is dispatched from within a
workflow would fail that check every time it is run. Nothing
dispatched one from there: a workflow schedules a task by calling the
state that it is of, and the effects of an inline write had no tasks.
Those of an inline write of a state with a statechart are about to,
for an activity of the statechart that the write starts.

A task is run as a request of its own, so the tasks dispatcher now
creates its asyncio task in an empty context.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017sw2rydNyewFGnC8Fj1T7f
A `schedule` and a `timer` of a statechart are activities: each runs
while the state that has it is active. Entering a state now
schedules each of them, a statechart waits for a schedule before it
exits the state, and a timer of a state that is exited enqueues
nothing.

  - Scheduling. The status of a statechart now has the activities
    that are running, each by the state that has it and the
    `schedule` or the `timer` that it is. The interpreter adds one
    for each `schedule` and `timer` of a state that is entered, and
    of the statechart itself when it starts. The generated code
    makes a task for each and has it in the effects of the method
    that is returning, so an activity runs only if that method
    completes. The task of a timer is to run after the delay of the
    timer.

  - Running. The task is that of a workflow that every state type
    with a statechart now has, `__RunStatechartActivity__`. For a
    schedule it calls the method of the servicer, as a workflow of
    the servicer is called. It is a method of no rpc, so it cannot
    be called, and an rpc cannot have its name. The generated code
    dispatches and runs it as it does any workflow, so a schedule
    that fails is run again as a workflow is.

  - Finishing. In one inline write, the workflow takes the activity
    from those that are running and enqueues an event: the one that
    the method of a schedule returned, if any, or the one of a
    timer. The statechart is then run as it is after any write.

  - Waiting for a schedule. A transition that would exit a state
    that has a schedule that is running is not taken. `run()` stops
    there, with the event that the transition fires for still at the
    head of the queue and every later event behind it, until the
    write that finishes the schedule runs the statechart again. A
    schedule of the statechart itself is of no state and is never
    waited for.

  - Exiting a state with a timer. No transition waits for a timer.
    Taking a transition takes each timer of a state that it exits
    from those that are running, so when the task of the timer
    comes to finish, it finds that the timer is not running and
    enqueues nothing.

An activity is not cancelled yet: a statechart always waits for a
schedule, and the task of a timer of a state that was exited still
runs, to no effect.

The schedules that the order of the tests had are now those of a
shipment, in `shipment.proto`, which also has timers, so that an
order does not start tasks.

The statechart's own `entry` and `exit` have a note to show them in
whatever the dashboard draws of a statechart.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017sw2rydNyewFGnC8Fj1T7f
A transition that would exit a state that has a schedule that is
running waits until the schedule has finished. Nothing made the
schedule finish, so a schedule that waits for what never happens
kept its state from ever being exited.

A `Schedule` now says whether it is `cancellable`, which is required.
When a transition waits for a schedule that is, `run()` marks the
activity as `cancelling` in the status. The transition still waits,
for that schedule as for one that is not cancellable, until the
activity has finished.

The task that runs a schedule now runs the method of the schedule in
an asyncio task of its own, and waits for either that or an event
that it keeps, by its UUID, in a class variable of the servicer. Once
a status that says an activity is being cancelled has been stored, or
committed for a transaction, the state manager tells the tasks
dispatcher of the state type, which is what it has of the state type
there, and that tells the middleware it was made by, which sets the
event of the activity. The task then cancels the method, waits for it
to finish, and finishes the activity as it does for a schedule that
returned, with no event to enqueue. The write that does so runs the
statechart again, which takes the transition that was waiting.

A schedule that is not running when it is cancelled, because it
failed and its task is waiting to be run again, or because the
application has restarted, has no event to set. So each time the
task is run it first reads where the statechart is, and calls the
method only if its activity is running and is not being cancelled.
That also keeps a task that is run again after it has finished its
activity, as one is to validate its effects, from calling the method
of a schedule that was cancelled, which nothing would cancel again.

The Reboot task itself is not cancelled: cancelling it while it
waits to be run again would end it with nothing left to finish the
activity.

No transition waits for a timer. A timer of a state that is exited
was taken from the activities that are running, and its task found
it gone. It is now marked as `cancelling` as well, when a transition
that would exit its state fires, which is when a cancellable
schedule is, whether or not the transition has to wait. It stays
until its delay is over, when its task takes it from the activities
and enqueues nothing.

Every `TasksDispatcher` is made with what cancels the activities of
its state type, so the generated code of every state type changes,
and with it the goldens.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017sw2rydNyewFGnC8Fj1T7f
An activity of a statechart is cancelled by the statechart, when a
transition would exit the state that the activity is of. The task
that runs it could still be cancelled from outside, with
`Tasks.CancelTask`, which `rbt task cancel` and the inspect page
call. The task then ended as cancelled without having finished the
activity, which the statechart kept as one that is running with
nothing left to finish it: a transition that waited for it waited
forever, and a timer never enqueued its event.

The tasks dispatcher now leaves such a task running, and answers
with the new status `IGNORED`, for which `rbt task cancel` says that
the cancellation was ignored.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017sw2rydNyewFGnC8Fj1T7f
A statechart has an `exit` of its own, as each of its states has,
and nothing ran it: no transition exits the statechart.

`_enter_state()` now exits the statechart once it has entered a
final state of the statechart itself, rather than one within another
state, after the `entry` of that state: each `exit` of the
statechart is run, in order. A final state has no transitions, so
the statechart is exited once.

For the same reason no transition would fire for an event that is
injected then, so it is now a problem for an `exit` of the
statechart to be an `inject`, or a `call` that may inject.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017sw2rydNyewFGnC8Fj1T7f
A statechart has activities of its own, which are of no state, so no
transition exited what they are of: they ran on after the statechart
had entered a final state of its own, and the `exit` of the
statechart was run while a schedule of the statechart was still
running.

A transition that enters a final state of the statechart itself
exits the statechart, so it now does for the activities of the
statechart what a transition does for those of a state that it would
exit: each timer and each schedule that is `cancellable` is marked
as `cancelling`, and the transition waits until every schedule has
finished.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017sw2rydNyewFGnC8Fj1T7f
A statechart could only be declared in a `.proto` file, as the
`rbt.v1alpha1.statechart` option of the message of a state type, so
a state type of a Pydantic API could not have one.

`Type` now takes a `statechart`, which is a `Statechart` message. A
statechart names an event by the full name of a message, and an
event of a Pydantic API is a model, whose message is not there while
the API file is run: its package is decided from the path that the
file is generated from, and a message is only generated for a model
that the API is known to mention. So an event that is a model is
named as the model is imported, "shop.events.Paid" for the `Paid` of
`shop/events.py`, and there are two statecharts from there on.

The statechart of the API, which the `StateType` of the API has, is
what was declared, with each event that is a model named as a
`Reference` to the model is. It is part of what the API declares and
of its digest, and the schema of each such model is among those of
the API.

The statechart that is generated is that one with each such event
named by a message, which is generated for the model, in the package
of the API file and under the name of the model, whether or not a
method mentions the model. It is written as the option of the
message that is generated for the state, and from there on it is
checked and generated for as a statechart that was declared in a
`.proto` file is. An event that names no model is left as it is in
both.

The JavaScript that is generated for `api.proto` now imports that of
`statechart.proto`, which the bundle of the dashboard is given.

A method of the servicer for such a statechart is still given what a
statechart of a `.proto` file gives it: a servicer that is given the
models is still to come, as is declaring a statechart with them.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017sw2rydNyewFGnC8Fj1T7f
An event of a statechart that comes from outside the state type had
to be enqueued by a method that the developer wrote for it, whose
whole body was to enqueue what it was given. Nothing in the
statechart said that the event came from there, and an event that no
transition fired for was dropped without the caller being told, so a
method that was to fail for one had to look at where the statechart
was itself, which is to decide what the statechart is there to
decide.

A statechart now has `event_methods`, each the method for an event.
The method is what an rpc of the state type is as a method, as every
other method of the state type is: a writer, and no constructor,
that takes the event and returns `google.protobuf.Empty`, which is
checked when the code is generated. What is generated for a servicer
is what the method does, so a servicer does not implement it.

The method enqueues the event that it is given, and the statechart,
which is run when a method that can change the state returns,
handles it. If no transition fires for the event where the
statechart is, the method fails with `FailedPrecondition` instead,
having changed nothing. A statechart that has events waiting is
waiting for a schedule to finish, and what becomes of an event
behind them is not known yet, so the method then enqueues the event
and does not fail.

A statechart of a Pydantic API has no event methods yet.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017sw2rydNyewFGnC8Fj1T7f

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant