handleText calls dispatch with no exception handling. A CatchableError escaping a handler kills the WS event loop task for that connection (or the thread) without an ack, so the client's reqId hangs forever, and a Defect leaves the shared SQLite connection inside an open transaction because withTransaction only rolls back CatchableError. The next caller then runs its statements inside the dead transaction, or the commit chain corrupts.
Where
server/main.nim:2007-2019 — handleText parses the envelope and calls dispatch(conn, env) bare.
server/db.nim:197-208 — withTransaction / authoringTransaction: except CatchableError: rollback; a Defect skips the ROLLBACK entirely and unwinds.
One DbConn is shared by all handlers, so a leaked open transaction is global.
Failure scenario
A handler raises (a Defect from an arithmetic edge, a nil deref, a RangeDefect from a bad index in a scene/token path). The frame is consumed and no ok/error is sent: the client waits on the reqId until its own timeout, with no closing and no diagnostic. If the raise happened inside withTransaction, the connection is left with an uncommitted BEGIN, so the following mutation's BEGIN fails or its COMMIT commits someone else's half-written state. The server keeps accepting intents while behaving incorrectly.
Confidence
Medium-high on the mechanism (plain to read); the frequency depends on undiscovered defects.
Fix direction
Bound the damage: wrap dispatch in a try/except that logs the failure and always answers the request (an error code, or a closing when the connection is no longer trustworthy), so no reqId can hang. Make transaction cleanup unconditional (finally-style rollback that also covers Defect, e.g. a rollback on unwind plus a connection-health flag that forces a restart of the connection), instead of relying on CatchableError alone.
Acceptance
An injected handler failure (test hook that raises from dispatch) produces an error or closing on the wire, never silence, and the server continues to serve other connections.
An injected failure inside withTransaction leaves the shared connection with no open transaction; the next mutation succeeds and its data is its own.
Regression test: fault.test.mjs gains a case that forces a raise inside a locked mutation and asserts both the wire answer and the next intent's success.
## Summary
`handleText` calls `dispatch` with no exception handling. A `CatchableError` escaping a handler kills the WS event loop task for that connection (or the thread) without an ack, so the client's `reqId` hangs forever, and a `Defect` leaves the shared SQLite connection inside an open transaction because `withTransaction` only rolls back `CatchableError`. The next caller then runs its statements inside the dead transaction, or the commit chain corrupts.
## Where
- `server/main.nim:2007-2019` — `handleText` parses the envelope and calls `dispatch(conn, env)` bare.
- `server/db.nim:197-208` — `withTransaction` / `authoringTransaction`: `except CatchableError:` rollback; a `Defect` skips the `ROLLBACK` entirely and unwinds.
- One `DbConn` is shared by all handlers, so a leaked open transaction is global.
## Failure scenario
A handler raises (a `Defect` from an arithmetic edge, a nil deref, a `RangeDefect` from a bad index in a scene/token path). The frame is consumed and no `ok`/`error` is sent: the client waits on the `reqId` until its own timeout, with no `closing` and no diagnostic. If the raise happened inside `withTransaction`, the connection is left with an uncommitted `BEGIN`, so the following mutation's `BEGIN` fails or its `COMMIT` commits someone else's half-written state. The server keeps accepting intents while behaving incorrectly.
## Confidence
Medium-high on the mechanism (plain to read); the frequency depends on undiscovered defects.
## Fix direction
Bound the damage: wrap `dispatch` in a `try/except` that logs the failure and always answers the request (an `error` code, or a `closing` when the connection is no longer trustworthy), so no `reqId` can hang. Make transaction cleanup unconditional (`finally`-style rollback that also covers `Defect`, e.g. a rollback on unwind plus a connection-health flag that forces a restart of the connection), instead of relying on `CatchableError` alone.
## Acceptance
- An injected handler failure (test hook that raises from dispatch) produces an `error` or `closing` on the wire, never silence, and the server continues to serve other connections.
- An injected failure inside `withTransaction` leaves the shared connection with no open transaction; the next mutation succeeds and its data is its own.
- Regression test: `fault.test.mjs` gains a case that forces a raise inside a locked mutation and asserts both the wire answer and the next intent's success.
## Related
- #23, #25 (slice 8, slice 10).
- #2 (M3 planning map).
Category: bug Summary: an error escaping intent handling must still produce exactly one ack (static code internal) and must never leave an open DB transaction behind
Current behavior:
The frame handler parses a readable envelope and calls the dispatch entry bare, with no guard. If anything on that path raises — a CatchableError thrown by a handler, or a Defect (range/index/nil/arithmetic) anywhere in validation, mutation or egress — the raise unwinds out of intent handling with nothing written to the wire: the client's reqId never gets its ack, so the client sits on its pending request until its own timeout, and it gets no closing and no diagnostic either. On the storage side the transaction helper rolls back only CatchableError; a Defect escaping the transaction body skips the ROLLBACK and unwinds, and because one connection is shared by all handlers, the next intent runs inside a BEGIN nobody will finish, or its COMMIT commits somebody else's half-written state. The server keeps accepting intents while behaving incorrectly.
Desired behavior:
Exactly one ack per readable intent, always. A readable envelope (string t, integer reqId) must be answered even when handling fails. An escaping error yields ack {reqId, ok:false, code:"internal"}: a new static refusal code, no detail — no exception message, class name, stack, source location, SQL text, id or path. Refusals never carry state, and a leak-free diagnostic belongs in the log, not on the wire.
The ack is never doubled. If the failure happens after the ack for that intent was already enqueued (errors during egress/effects), the client still sees exactly one ack for that reqId: the existing ack wins and no internal ack is appended. The rollback and the logging still happen.
Nothing is applied from a failed intent. A failed intent commits nothing, and any frames it had already enqueued must not describe state that is not durable.
Transactions are rolled back on every unwind path, recoverable error or Defect, for both the ordinary transaction path and the authoring (FULL durability) transaction path. Rollback must not depend on the error's class. After the unwind the shared connection holds no open transaction: the next mutation from any connection is acked ok, and its data is its own.
The connection and the server stay usable. Subsequent intents on the same connection are served and acked in order; other connections are unaffected; no intent is dropped silently.
The failure is logged once, through the existing structured event log, redacted: intent t, reqId, the error class and a fixed message — never payload contents, names, keys, session material or SQL. The repo's existing "no secret in any log" gate must still pass.
If the implementation decides a connection is no longer trustworthy after a Defect, it may close it, but only in the existing shape: closing (an existing static reason and code) and then the close frame. Staying usable is the default and the acceptance path; closing is an allowed extra, not a licence for a new close reason.
Key interfaces:
DESIGN 6.5's ack-code table: gains internal, meaning "the server failed while handling this intent; nothing was applied". It carries no state and no detail. Record it as an owner decision taken during #32's triage. It is additive within proto 1: a client that does not know the code treats it as a generic refusal, and no existing code's meaning changes.
The transaction helper(s) (the ordinary one and the authoring one, whatever they are called at the time you implement this): both must roll back on any unwind path, including Defect. A construct that catches the defect, rolls back and re-raises, or a finally-style rollback guarded by an explicit "transaction open" flag, both satisfy this — the requirement is behavioural, not which construct.
The dispatch entry point called by the frame handler: one guard covering the whole handling of a readable envelope, at a level that covers every intent handler including the not-yet-implemented catalogue answers. Per-handler try/except does not satisfy this: a handler added later would reopen the hole.
A test-only fault hook in the same style as the existing leak-fault hooks: compiled in only under a build define, enabled by an environment variable, absent from the shipped build (assert that absence exactly the way the existing hook's absence is asserted). It must be able to raise a CatchableError and a Defect from at least two points: inside a mutation that holds the transaction, and after the ack has been enqueued.
The repo's mutation set: gains a mutation that deletes the dispatch guard, and one that removes the rollback-on-Defect, each of which must make at least one test fail.
Acceptance criteria:
Fault hook raising a CatchableError inside a locked mutation: the sender receives exactly one ack for that reqId, ok:false, code:"internal", with no result fields and no position, and no state message caused by the failed intent.
Fault hook raising a Defect inside the same mutation: same single internal ack.
Fault hook raising after the ack was already enqueued: the reqId still has exactly one ack and it is the handler's own ack, not internal.
After each failed intent, no transaction is open: the next mutation (on the same connection and on a second connection) is acked ok, and a read-back of the affected data shows no partial rows from the failed intent.
The server survives: a follow-up intent on the same connection and an intent from a second, unaffected connection both succeed after the injected failure.
The failure emits exactly one log event naming the intent and error class, containing no payload, name, key, session or SQL text; the existing log-secret gate still passes.
Ordinary validation is untouched: malformed envelopes, unknown types, bad fields and missing targets still get their existing codes and never internal.
The shipped build contains no fault hook, and the full suite (Nim plus the Node harnesses) passes with it.
The internal code is in DESIGN 6.5's table with no state and no detail, annotated as an owner decision from #32's triage, and DESIGN 6.2's additive list or note mentions that a new refusal code is an additive change.
Each new mutation in the repo's mutation set fails at least one test (guard removed; rollback-on-Defect removed).
Out of scope:
Hunting, fixing or auditing the defects that can raise (this bounds the damage; finding them is separate work).
Retry, resume or idempotency for a failed intent; replaying an intent after internal.
The closing reason/code table and the connection-outcome rows of 6.5 (no new close reason, no internal on the close path).
The heartbeat/Ping-after-closing race (#34) and the M5 bounded outbox / single guarded send path.
Changing the refusal code semantics of any existing code, or adding detail fields to ack.
> *This was generated by AI during triage.*
## Agent Brief
**Category:** bug
**Summary:** an error escaping intent handling must still produce exactly one `ack` (static code `internal`) and must never leave an open DB transaction behind
**Current behavior:**
The frame handler parses a readable envelope and calls the dispatch entry bare, with no guard. If anything on that path raises — a `CatchableError` thrown by a handler, or a `Defect` (range/index/nil/arithmetic) anywhere in validation, mutation or egress — the raise unwinds out of intent handling with nothing written to the wire: the client's `reqId` never gets its ack, so the client sits on its pending request until its own timeout, and it gets no `closing` and no diagnostic either. On the storage side the transaction helper rolls back only `CatchableError`; a `Defect` escaping the transaction body skips the `ROLLBACK` and unwinds, and because one connection is shared by all handlers, the next intent runs inside a `BEGIN` nobody will finish, or its `COMMIT` commits somebody else's half-written state. The server keeps accepting intents while behaving incorrectly.
**Desired behavior:**
- **Exactly one ack per readable intent, always.** A readable envelope (string `t`, integer `reqId`) must be answered even when handling fails. An escaping error yields `ack {reqId, ok:false, code:"internal"}`: a new static refusal code, no detail — no exception message, class name, stack, source location, SQL text, id or path. Refusals never carry state, and a leak-free diagnostic belongs in the log, not on the wire.
- **The ack is never doubled.** If the failure happens after the ack for that intent was already enqueued (errors during egress/effects), the client still sees exactly one ack for that `reqId`: the existing ack wins and no `internal` ack is appended. The rollback and the logging still happen.
- **Nothing is applied from a failed intent.** A failed intent commits nothing, and any frames it had already enqueued must not describe state that is not durable.
- **Transactions are rolled back on every unwind path**, recoverable error or `Defect`, for both the ordinary transaction path and the authoring (`FULL` durability) transaction path. Rollback must not depend on the error's class. After the unwind the shared connection holds no open transaction: the next mutation from any connection is acked `ok`, and its data is its own.
- **The connection and the server stay usable.** Subsequent intents on the same connection are served and acked in order; other connections are unaffected; no intent is dropped silently.
- **The failure is logged once**, through the existing structured event log, redacted: intent `t`, `reqId`, the error class and a fixed message — never payload contents, names, keys, session material or SQL. The repo's existing "no secret in any log" gate must still pass.
- If the implementation decides a connection is no longer trustworthy after a `Defect`, it may close it, but only in the existing shape: `closing` (an existing static reason and code) and then the close frame. Staying usable is the default and the acceptance path; closing is an allowed extra, not a licence for a new close reason.
**Key interfaces:**
- **DESIGN 6.5's ack-code table**: gains `internal`, meaning "the server failed while handling this intent; nothing was applied". It carries no state and no detail. Record it as an owner decision taken during #32's triage. It is additive within proto 1: a client that does not know the code treats it as a generic refusal, and no existing code's meaning changes.
- **The transaction helper(s)** (the ordinary one and the authoring one, whatever they are called at the time you implement this): both must roll back on any unwind path, including `Defect`. A construct that catches the defect, rolls back and re-raises, or a `finally`-style rollback guarded by an explicit "transaction open" flag, both satisfy this — the requirement is behavioural, not which construct.
- **The dispatch entry point called by the frame handler**: one guard covering the whole handling of a readable envelope, at a level that covers every intent handler including the not-yet-implemented catalogue answers. Per-handler try/except does not satisfy this: a handler added later would reopen the hole.
- **A test-only fault hook** in the same style as the existing leak-fault hooks: compiled in only under a build define, enabled by an environment variable, absent from the shipped build (assert that absence exactly the way the existing hook's absence is asserted). It must be able to raise a `CatchableError` and a `Defect` from at least two points: inside a mutation that holds the transaction, and after the ack has been enqueued.
- **The repo's mutation set**: gains a mutation that deletes the dispatch guard, and one that removes the rollback-on-`Defect`, each of which must make at least one test fail.
**Acceptance criteria:**
- [ ] Fault hook raising a `CatchableError` inside a locked mutation: the sender receives exactly one `ack` for that `reqId`, `ok:false`, `code:"internal"`, with no result fields and no position, and no state message caused by the failed intent.
- [ ] Fault hook raising a `Defect` inside the same mutation: same single `internal` ack.
- [ ] Fault hook raising after the ack was already enqueued: the `reqId` still has exactly one ack and it is the handler's own ack, not `internal`.
- [ ] After each failed intent, no transaction is open: the next mutation (on the same connection and on a second connection) is acked `ok`, and a read-back of the affected data shows no partial rows from the failed intent.
- [ ] The server survives: a follow-up intent on the same connection and an intent from a second, unaffected connection both succeed after the injected failure.
- [ ] The failure emits exactly one log event naming the intent and error class, containing no payload, name, key, session or SQL text; the existing log-secret gate still passes.
- [ ] Ordinary validation is untouched: malformed envelopes, unknown types, bad fields and missing targets still get their existing codes and never `internal`.
- [ ] The shipped build contains no fault hook, and the full suite (Nim plus the Node harnesses) passes with it.
- [ ] The `internal` code is in DESIGN 6.5's table with no state and no detail, annotated as an owner decision from #32's triage, and DESIGN 6.2's additive list or note mentions that a new refusal code is an additive change.
- [ ] Each new mutation in the repo's mutation set fails at least one test (guard removed; rollback-on-`Defect` removed).
**Out of scope:**
- Hunting, fixing or auditing the defects that can raise (this bounds the damage; finding them is separate work).
- Retry, resume or idempotency for a failed intent; replaying an intent after `internal`.
- The `closing` reason/code table and the connection-outcome rows of 6.5 (no new close reason, no `internal` on the close path).
- The heartbeat/Ping-after-`closing` race (#34) and the M5 bounded outbox / single guarded send path.
- Changing the refusal code semantics of any existing code, or adding detail fields to `ack`.
Fixed in a5c0ee5 (fix: dispatch guard and Defect-safe rollback (#32)), pushed to main.
Cause:handleText called dispatch bare, and both transaction helpers rolled back only CatchableError. Reproduced red on 38941da: a Defect inside withTransaction left BEGIN open, so the next mutation failed with cannot start a transaction within a transaction; the authoring helper failed with Safety level may not be changed inside a transaction.
Fix: one guard around dispatch for every readable envelope. A threadvar records the reqId whose ack was enqueued during the call; an escaping Exception (Defect included) gets exactly one ack {ok:false, code:"internal"} unless the handler's own ack already stands. withTransaction and authoringTransaction now roll back on every unwind path (except Exception, not CatchableError). A test-only dispfault build injects a catchable error, a Defect inside the locked mutation, and a failure after the ack; the shipped binary contains no hook. internal is recorded in DESIGN 6.5 (owner-delegated from this triage) and named as additive in 6.2.
Proof:tests/tdb.nim suite "transaction unwind (#32)" (both helpers roll back a Defect, next transaction succeeds, synchronous restored); tools/fault.test.mjs 4 cases (single internal ack, no double ack after the effects point, next intent on the same and a second connection ok, DB read-back shows no partial row, one log event with no exception message, shipped binary lacks DISP_FAULT). Full nimble test -y and node --test --test-concurrency=1 tools/*.test.mjs (149/149) green after rebasing on origin/main. Mutation entries e4/e5 cover the rollback removal.
Fixed in a5c0ee5 (`fix: dispatch guard and Defect-safe rollback (#32)`), pushed to `main`.
**Cause:** `handleText` called `dispatch` bare, and both transaction helpers rolled back only `CatchableError`. Reproduced red on 38941da: a Defect inside `withTransaction` left `BEGIN` open, so the next mutation failed with `cannot start a transaction within a transaction`; the authoring helper failed with `Safety level may not be changed inside a transaction`.
**Fix:** one guard around `dispatch` for every readable envelope. A threadvar records the reqId whose ack was enqueued during the call; an escaping `Exception` (Defect included) gets exactly one `ack {ok:false, code:"internal"}` unless the handler's own ack already stands. `withTransaction` and `authoringTransaction` now roll back on every unwind path (`except Exception`, not `CatchableError`). A test-only `dispfault` build injects a catchable error, a Defect inside the locked mutation, and a failure after the ack; the shipped binary contains no hook. `internal` is recorded in DESIGN 6.5 (owner-delegated from this triage) and named as additive in 6.2.
**Proof:** `tests/tdb.nim` suite "transaction unwind (#32)" (both helpers roll back a Defect, next transaction succeeds, `synchronous` restored); `tools/fault.test.mjs` 4 cases (single internal ack, no double ack after the effects point, next intent on the same and a second connection ok, DB read-back shows no partial row, one log event with no exception message, shipped binary lacks `DISP_FAULT`). Full `nimble test -y` and `node --test --test-concurrency=1 tools/*.test.mjs` (149/149) green after rebasing on origin/main. Mutation entries e4/e5 cover the rollback removal.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Summary
handleTextcallsdispatchwith no exception handling. ACatchableErrorescaping a handler kills the WS event loop task for that connection (or the thread) without an ack, so the client'sreqIdhangs forever, and aDefectleaves the shared SQLite connection inside an open transaction becausewithTransactiononly rolls backCatchableError. The next caller then runs its statements inside the dead transaction, or the commit chain corrupts.Where
server/main.nim:2007-2019—handleTextparses the envelope and callsdispatch(conn, env)bare.server/db.nim:197-208—withTransaction/authoringTransaction:except CatchableError:rollback; aDefectskips theROLLBACKentirely and unwinds.DbConnis shared by all handlers, so a leaked open transaction is global.Failure scenario
A handler raises (a
Defectfrom an arithmetic edge, a nil deref, aRangeDefectfrom a bad index in a scene/token path). The frame is consumed and nook/erroris sent: the client waits on thereqIduntil its own timeout, with noclosingand no diagnostic. If the raise happened insidewithTransaction, the connection is left with an uncommittedBEGIN, so the following mutation'sBEGINfails or itsCOMMITcommits someone else's half-written state. The server keeps accepting intents while behaving incorrectly.Confidence
Medium-high on the mechanism (plain to read); the frequency depends on undiscovered defects.
Fix direction
Bound the damage: wrap
dispatchin atry/exceptthat logs the failure and always answers the request (anerrorcode, or aclosingwhen the connection is no longer trustworthy), so noreqIdcan hang. Make transaction cleanup unconditional (finally-style rollback that also coversDefect, e.g. a rollback on unwind plus a connection-health flag that forces a restart of the connection), instead of relying onCatchableErroralone.Acceptance
errororclosingon the wire, never silence, and the server continues to serve other connections.withTransactionleaves the shared connection with no open transaction; the next mutation succeeds and its data is its own.fault.test.mjsgains a case that forces a raise inside a locked mutation and asserts both the wire answer and the next intent's success.Related
Agent Brief
Category: bug
Summary: an error escaping intent handling must still produce exactly one
ack(static codeinternal) and must never leave an open DB transaction behindCurrent behavior:
The frame handler parses a readable envelope and calls the dispatch entry bare, with no guard. If anything on that path raises — a
CatchableErrorthrown by a handler, or aDefect(range/index/nil/arithmetic) anywhere in validation, mutation or egress — the raise unwinds out of intent handling with nothing written to the wire: the client'sreqIdnever gets its ack, so the client sits on its pending request until its own timeout, and it gets noclosingand no diagnostic either. On the storage side the transaction helper rolls back onlyCatchableError; aDefectescaping the transaction body skips theROLLBACKand unwinds, and because one connection is shared by all handlers, the next intent runs inside aBEGINnobody will finish, or itsCOMMITcommits somebody else's half-written state. The server keeps accepting intents while behaving incorrectly.Desired behavior:
t, integerreqId) must be answered even when handling fails. An escaping error yieldsack {reqId, ok:false, code:"internal"}: a new static refusal code, no detail — no exception message, class name, stack, source location, SQL text, id or path. Refusals never carry state, and a leak-free diagnostic belongs in the log, not on the wire.reqId: the existing ack wins and nointernalack is appended. The rollback and the logging still happen.Defect, for both the ordinary transaction path and the authoring (FULLdurability) transaction path. Rollback must not depend on the error's class. After the unwind the shared connection holds no open transaction: the next mutation from any connection is ackedok, and its data is its own.t,reqId, the error class and a fixed message — never payload contents, names, keys, session material or SQL. The repo's existing "no secret in any log" gate must still pass.Defect, it may close it, but only in the existing shape:closing(an existing static reason and code) and then the close frame. Staying usable is the default and the acceptance path; closing is an allowed extra, not a licence for a new close reason.Key interfaces:
internal, meaning "the server failed while handling this intent; nothing was applied". It carries no state and no detail. Record it as an owner decision taken during #32's triage. It is additive within proto 1: a client that does not know the code treats it as a generic refusal, and no existing code's meaning changes.Defect. A construct that catches the defect, rolls back and re-raises, or afinally-style rollback guarded by an explicit "transaction open" flag, both satisfy this — the requirement is behavioural, not which construct.CatchableErrorand aDefectfrom at least two points: inside a mutation that holds the transaction, and after the ack has been enqueued.Defect, each of which must make at least one test fail.Acceptance criteria:
CatchableErrorinside a locked mutation: the sender receives exactly oneackfor thatreqId,ok:false,code:"internal", with no result fields and no position, and no state message caused by the failed intent.Defectinside the same mutation: same singleinternalack.reqIdstill has exactly one ack and it is the handler's own ack, notinternal.ok, and a read-back of the affected data shows no partial rows from the failed intent.internal.internalcode is in DESIGN 6.5's table with no state and no detail, annotated as an owner decision from #32's triage, and DESIGN 6.2's additive list or note mentions that a new refusal code is an additive change.Defectremoved).Out of scope:
internal.closingreason/code table and the connection-outcome rows of 6.5 (no new close reason, nointernalon the close path).closingrace (#34) and the M5 bounded outbox / single guarded send path.ack.Fixed in
a5c0ee5(fix: dispatch guard and Defect-safe rollback (#32)), pushed tomain.Cause:
handleTextcalleddispatchbare, and both transaction helpers rolled back onlyCatchableError. Reproduced red on38941da: a Defect insidewithTransactionleftBEGINopen, so the next mutation failed withcannot start a transaction within a transaction; the authoring helper failed withSafety level may not be changed inside a transaction.Fix: one guard around
dispatchfor every readable envelope. A threadvar records the reqId whose ack was enqueued during the call; an escapingException(Defect included) gets exactly oneack {ok:false, code:"internal"}unless the handler's own ack already stands.withTransactionandauthoringTransactionnow roll back on every unwind path (except Exception, notCatchableError). A test-onlydispfaultbuild injects a catchable error, a Defect inside the locked mutation, and a failure after the ack; the shipped binary contains no hook.internalis recorded in DESIGN 6.5 (owner-delegated from this triage) and named as additive in 6.2.Proof:
tests/tdb.nimsuite "transaction unwind (#32)" (both helpers roll back a Defect, next transaction succeeds,synchronousrestored);tools/fault.test.mjs4 cases (single internal ack, no double ack after the effects point, next intent on the same and a second connection ok, DB read-back shows no partial row, one log event with no exception message, shipped binary lacksDISP_FAULT). Fullnimble test -yandnode --test --test-concurrency=1 tools/*.test.mjs(149/149) green after rebasing on origin/main. Mutation entries e4/e5 cover the rollback removal.