statewire
The Statewire protocol for Python, on top of pinned.
Statewire is a PinnedAPI (one live instance per id cluster-wide) that replicates
one JSON object — any State — over envelope streams:
GET /stream(SSE) and/ws(WebSocket twin) — every message is an envelope{"ops"?, "res"?, "ack"?, "syn"?, "fin"?}. The first envelope on attach is a full snapshot (ops: [{"op": "replace", "path": [], "value": <state>}]) with thesynhandshake{"lastSeq", "lease"?}: the client's last admitted command seq (-1unknown client) and the attach's writer-lease token. Sessions are single-writer per client id: attaching takes the lease, and any other live stream of that client id ends withfin {"reason": "superseded"}.POST /commands— one command at a time, a method call{"method": <name>, "params": [...]}routed to the@commandhandler registered under that name. Commands carryStatewire-Client-Id, a monotonicStatewire-Command-Seq, and the currentStatewire-Lease. The HTTP response is receipt only (200 {}|400malformed |409seq gap |412unknown client |423stale lease); the protocol statuses carry a discriminator body ({"error": "seq-gap" | "unknown-client" | "stale-lease", "message"?}) so clients can tell statewire's verdict from a middleware-minted bare status; verdicts ride the stream. Over WS the same commands arrive as{"method": <name>, "params": [...], "seq": <int>}frames — no lease header, holding the connection is the lease.
ops are Immer-style deltas with array paths (object keys as strings, list
indices as ints): replace sets a value, add splices — its final int segment
indexes into the parent, so a list parent gains an element and a string parent
gains text at that offset — remove deletes. ack
is the cumulative watermark for the issuing client, emitted after the command's
effect ops. res carries responses ({"seq", "type": "accepted" | "rejected" | "pending" | "crashed" | "result-unavailable", "message"?, "payload"?}): the envelope
that first covers a seq states the command's fate — a terminal response, a
pending response (result follows in a later envelope), or nothing = void. fin
({"reason": "evicted" | "error" | "gone" | "superseded", "message"?}) is always
the last envelope.
Handler outcomes: the return value becomes the terminal accepted payload;
raise StatewireReject becomes rejected; returning a CommandExecution keeps the
command open past the handler's return — its ack() flushes the covering ack
with a pending response, its resolve/reject produce the late terminal
response (post-ack failures are terminal rejected, not stream faults).
Duplicate seqs never re-run: they are answered
from a ~30s result cache / in-flight registry — in the POST body over HTTP
(200 {"res": ...}), as a res on the stream over WS.
The protocol is generic: it says nothing about messages, queues, or agents — it
only replicates whatever self.state dict you assign and dispatches whatever
commands you declare. Domain-specific layers (see the harness-sdk package) sit
on top.
from statewire import Statewire, command
class Thread(Statewire):
async def lifespan(self):
self.state = {"messages": []} # yielding without setting self.state throws
yield
@command
async def addMessage(self, message_id: str, content: str):
self.state["messages"].append({"id": message_id, "content": content})
self.create_task(self.run()) # long work outside the inbox; returning here => ack
@command registers the handler under the method's own name; @command("name")
registers it under an explicit wire name. Params are positional. An unknown
method or a params/signature mismatch is a rejected response on the stream,
not an HTTP error.
self.state is a change-tracking proxy: mutate it plainly and the ops replicate
to every attached stream. += on a string becomes an end-offset text-insert
add op of the suffix; other mutations become narrow replace / add /
remove ops. Mutations within
one synchronous segment coalesce into a single envelope.
Extra routes
Need an endpoint beyond the protocol trio (a health check, a file upload)?
Decorate a method with pinned's route escape hatch:
from pinned import route
from statewire import Statewire
class Thread(Statewire):
@route.get("/health")
async def health(self, request):
return {"ok": True}
The reserved protocol paths /statewire, /stream, /commands, and /ws
are Statewire's own; a subclass that decorates a @route onto any of them
raises at class-definition time rather than silently shadowing the protocol.
GET /statewire is the meta endpoint: {"protocol": 1, "commands": [<names>]}.
Layering
pinned one live instance per id, with an HTTP surface
└─ statewire the Statewire protocol: /stream + /ws (envelopes) + /commands
└─ harness-sdk HarnessState types, queueing, deepagents
Develop
uv sync
uv run pytest
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file statewire-0.9.1.tar.gz.
File metadata
- Download URL: statewire-0.9.1.tar.gz
- Upload date:
- Size: 85.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bac740349ee58c29d91d29e6b1aaca45e230bc07438e0e189504383360c50321
|
|
| MD5 |
d32bb17ab928b7aba0b78ef449e47701
|
|
| BLAKE2b-256 |
a2120dcad68e11b209bc721cf437681a927fe9eedefd01954d47cc9f58e4d4df
|
Provenance
The following attestation bundles were made for statewire-0.9.1.tar.gz:
Publisher:
pypi-publish.yaml on assistant-ui/harness-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
statewire-0.9.1.tar.gz -
Subject digest:
bac740349ee58c29d91d29e6b1aaca45e230bc07438e0e189504383360c50321 - Sigstore transparency entry: 2545256333
- Sigstore integration time:
-
Permalink:
assistant-ui/harness-sdk@75889c2eff438890b02e77734df9edc116565805 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/assistant-ui
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yaml@75889c2eff438890b02e77734df9edc116565805 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file statewire-0.9.1-py3-none-any.whl.
File metadata
- Download URL: statewire-0.9.1-py3-none-any.whl
- Upload date:
- Size: 46.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75c44795775bbcfc9374416d558d187f8d8cc6ddac6d0748812ecec8fbe9d2e9
|
|
| MD5 |
abb699b1d06a250488f0716784d6a0e7
|
|
| BLAKE2b-256 |
6c15ace54f755a7332029d5019ab8e70222aaca7fe1e71f594e3255269b44350
|
Provenance
The following attestation bundles were made for statewire-0.9.1-py3-none-any.whl:
Publisher:
pypi-publish.yaml on assistant-ui/harness-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
statewire-0.9.1-py3-none-any.whl -
Subject digest:
75c44795775bbcfc9374416d558d187f8d8cc6ddac6d0748812ecec8fbe9d2e9 - Sigstore transparency entry: 2545256380
- Sigstore integration time:
-
Permalink:
assistant-ui/harness-sdk@75889c2eff438890b02e77734df9edc116565805 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/assistant-ui
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yaml@75889c2eff438890b02e77734df9edc116565805 -
Trigger Event:
workflow_dispatch
-
Statement type: