fix: dispatch guard and Defect-safe rollback (#32)

A readable intent that fails in handling now always gets exactly one ack:
the new static internal code, unless the handler's own ack was already
enqueued. Both transaction helpers roll back on every unwind path,
Defect included, so the shared SQLite connection never keeps an open
transaction. Test-only dispfault build covers catchable/defect/after-ack;
DESIGN 6.5 records internal as an owner decision and 6.2 names refusal
codes as additive.
This commit is contained in:
2026-11-20 21:36:44 +01:00
parent 38941da003
commit a5c0ee5d4c
9 changed files with 246 additions and 12 deletions
+12 -2
View File
@@ -402,7 +402,9 @@ Invariants (carry from prototype):
relative to other messages is flush order, not mutation order.
- Ack after COMMIT (a client never sees a state that a crash can undo, except under
`synchronous=NORMAL` power loss, 4.4).
- A failed validation mutates nothing, bumps nothing, persists nothing.
- A failed validation mutates nothing, bumps nothing, persists nothing. A mutation that raises
after its transaction began rolls back on every unwind path, `Defect` included, so the shared
connection never keeps an open transaction (6.5 step 10, #32).
- Refusals never echo state: only a refused move of a controlled token acks with its old position
(uniform nack, 5.5); every other refusal is an `ack` with a static `code` and no position (6.5).
Each intent gets exactly one `ack` (6).
@@ -1710,7 +1712,8 @@ view), so deletion and moving away look identical to the player.
- Within one proto version: additive only (new optional fields, new message types). The client
ignores unknown server message types and unknown fields; the server ignores unknown fields in
intents and answers an unknown `t` with `ack {ok:false, code:"unknown-type"}` (or `error
{code:"malformed"}` if there is no `reqId`).
{code:"malformed"}` if there is no `reqId`). A new static refusal code is additive too: a client
that does not know it treats it as a generic refusal (`internal`, 6.5, is the first, #32).
- Breaking change -> bump `proto`, document in `docs/` changelog.
- **Proto history.** `1` (M3, 2026-11-15): 29 intents, 15 server messages, `wall` records as `kind`
+ `open` + `flags`. `2` (#49, 2026-11-17): the wall record's typed fields (`thickness`,
@@ -1788,6 +1791,12 @@ on any failure.
8. Target lookup. Player senders: a target that is not theirs or does not exist is one and the same
`not-allowed` (no existence oracle, T9). GM senders: missing target -> `not-found`.
9. Semantic validation (GM: `invalid`; player move: the uniform nack, 5.5).
10. Handling raises after step 4 (any unwind path, `Defect` included): `ack internal`, unless the
handler's own ack for that `reqId` was already enqueued, in which case that ack stands and no
second one is appended [FIXED (owner-delegated), 2026-11-20, #32]. The failure is logged once with
the intent, `reqId` and error class; no payload, name, key, session or SQL text. A `Defect` does
not require a restart in v1: the transaction helpers roll back on every unwind path, so the shared
connection stays usable.
**Ack codes (static strings, never carry state).**
@@ -1802,6 +1811,7 @@ on any failure.
| `cap-reached` | `key.create` would exceed 6 players (3.2) |
| `in-use` | `character.remove` while a token links the character |
| `no-rules` | `act.do` (reserved, 9) |
| `internal` | the server failed while handling a readable intent; nothing was applied [FIXED (owner-delegated), 2026-11-20, #32] |
Player name text: trimmed, NFC, 1 to 32 code points, no control characters. Deviation [FIXED
(owner-delegated), #23]: Nim 2.2.12's stdlib has no Unicode normalisation (it lives in a package the