fix: Telegram callback persistence queue discards per-session ordering and spawns untracked goroutines when full#829
Closed
sam-saffron-jarvis wants to merge 1 commit into
Conversation
…g and spawns untracked goroutines when full
Owner
|
Closing as requested: the high-confidence fixes have been applied or superseded in the current working tree. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
runStoreOpWithoutCancelin an untracked goroutine when the 128-slot queue filled.telegramStoreOpQueue.enqueue()always hand work to the single serialized worker so per-session persistence stays ordered even under backpressure.TestTelegramStoreOpQueueFullStillSerializesOpsto cover the full-queue case and assert that a trailing callback op does not escape the queue and thatcloseAndWait()does not return before it finishes.Why this is high-value
The existing overflow path broke the core guarantee that this queue is a single serialized persistence lane for a Telegram session. Once the buffer filled, later writes could run concurrently with earlier queued writes, so transcript rows, metrics updates, and context-estimate updates could be persisted out of order. It also spawned unbounded 5-second store goroutines that
closeAndWait()never tracked, which directly risks durability and responsiveness during slow-store or tool-heavy runs.This fix applies backpressure instead of bypassing serialization, which preserves message ordering and ensures shutdown waits on the same persistence path that handled the callbacks.
Validation
gofmt -w internal/serve/telegram.go internal/serve/telegram_queue_test.gogo build ./...go test ./...go test ./internal/serve -run TestTelegramStoreOpQueueFullStillSerializesOps -count=1