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
+8 -3
View File
@@ -432,12 +432,17 @@ template authoringTransaction*(db: DbConn, body: untyped) =
db.exec(sql"PRAGMA synchronous=FULL")
try:
db.exec(sql"BEGIN")
var open = true
try:
body
db.exec(sql"COMMIT")
except CatchableError:
try: db.exec(sql"ROLLBACK")
except CatchableError: discard
open = false
except Exception:
# #32: roll back on every unwind path, `Defect` included, or the shared connection keeps an
# authoring transaction open for the next caller.
if open:
try: db.exec(sql"ROLLBACK")
except Exception: discard
raise
finally:
db.exec(sql"PRAGMA synchronous=NORMAL")