|
|
@@ -6,34 +6,6 @@
|
|
|
- Encoding: JSON objects; `tx` payloads are Transit strings.
|
|
|
- Note: keep this document in sync with the current implementation.
|
|
|
|
|
|
-## websocket message state machine
|
|
|
-### client
|
|
|
-| State | Event | Next state | Notes / error handling |
|
|
|
-| START | send 'hello' | hello-wait | Send immediately after connection opens |
|
|
|
-| hello-wait | recv 'hello' | hello-done | Update t; if remote > local then send `pull` |
|
|
|
-| hello-wait | recv other | END | Unexpected message |
|
|
|
-| hello-done | send 'pull' | pull-wait | Triggered by `hello` / `changed` / `stale` |
|
|
|
-| hello-done | send 'tx/batch' | tx/batch-wait | Flush pending local txs (inflight empty and ws open) |
|
|
|
-| hello-done | recv 'changed' | hello-done | If local < remote, send `pull` then enter pull-wait |
|
|
|
-| hello-done | recv 'error' | END | Fail fast |
|
|
|
-| hello-done | recv 'pong' | hello-done | Ignore (client does not send ping currently) |
|
|
|
-| hello-done | recv other | END | Unknown message type |
|
|
|
-| pull-wait | recv 'pull/ok' | hello-done | Apply remote txs, update local t |
|
|
|
-| pull-wait | recv 'changed' | pull-wait | If local < remote, re-send `pull` |
|
|
|
-| pull-wait | send 'tx/batch' | tx/batch-wait | Flush pending local txs (inflight empty and ws open) |
|
|
|
-| pull-wait | recv 'error' | END | Fail fast |
|
|
|
-| pull-wait | recv 'pong' | pull-wait | Ignore (client does not send ping currently) |
|
|
|
-| pull-wait | recv other | END | Unknown message type |
|
|
|
-| tx/batch-wait | recv 'tx/batch/ok' | hello-done | Update local t, clear inflight, continue flush; stay pull-wait if active |
|
|
|
-| tx/batch-wait | recv 'changed' | tx/batch-wait | Mark pull pending; pull after tx/batch completes |
|
|
|
-| tx/batch-wait | recv 'tx/reject' (stale) | tx/reject/stale | Handle stale branch |
|
|
|
-| tx/batch-wait | recv 'tx/reject' (cycle) | tx/reject/cycle | Handle cycle branch |
|
|
|
-| tx/batch-wait | recv 'error' | END | Fail fast |
|
|
|
-| tx/batch-wait | recv other | END | Unknown message type |
|
|
|
-| tx/reject/stale | send 'pull' | pull-wait | Immediately pull on stale |
|
|
|
-| tx/reject/cycle | (reconcile/requeue/flush) | hello-done | Reconcile cycle then resume normal flow (stay pull-wait if active) |
|
|
|
-| END | | | Connection closed; reconnection handled elsewhere |
|
|
|
-
|
|
|
## Client -> Server
|
|
|
- `{"type":"hello","client":"<repo-id>"}`
|
|
|
- Initial handshake from client.
|