Files
archie/internal
sam c2b6823eba fix(telegram): guarantee no message is stranded on gateway stop/restart
A daemon shutdown or /restart cancels turnCtx without any guarantee
that the goroutine owning a liveReply ever runs again to notice and
clean up after itself -- a full process exit gives it no chance at
all. Gateway now tracks every liveReply mid-turn in a registry and
Stop drains it, marking each as interrupted so nothing is left ending
in the "typing" cursor forever.

finalize and abandon now run their bodies inside a per-reply
sync.Once (the terminal field): a turn finishing naturally and a
concurrent Stop draining the same reply were reaching it from two
goroutines at once, both sending their own edit for the same message
with the outcome decided nondeterministically by which HTTP response
Telegram processed last -- including a complete real answer getting
silently overwritten by the restart marker. Only one side's body now
ever runs; the other blocks on the winner and then does nothing.

The drain itself is bounded (liveDrainTimeout, default 5s): a single
stalled Telegram API call must not hang gateway, and therefore
daemon, shutdown indefinitely. Entries still in flight past the
deadline keep running in the background rather than blocking Stop.

A liveReply created in the narrow window between Stop claiming the
registry and its own registration call is abandoned immediately
instead of being registered into (and lost from) a registry nothing
will drain again.

Regression tests cover the mutual-exclusion race directly (20
iterations of finalize and abandonRestarted racing on the same
reply, asserting exactly one outcome ever wins), the bounded drain
against a deliberately hung API call, and the post-stop registration
gap.
2026-08-15 02:19:53 +10:00
..
2026-08-06 01:40:15 +10:00
2026-08-06 01:40:15 +10:00