Skip to content

fix(channels): clear _in_processing on task cancellation or batch error - #409

Open
KuljeetSinghXDA wants to merge 1 commit into
bubbuild:mainfrom
KuljeetSinghXDA:fix/buffered-handler-recovery
Open

KuljeetSinghXDA wants to merge 1 commit into
bubbuild:mainfrom
KuljeetSinghXDA:fix/buffered-handler-recovery

Conversation

@KuljeetSinghXDA

Copy link
Copy Markdown

Summary

Fixes BufferedMessageHandler in src/bub/channels/handler.py so a cancelled or failed batch task cannot permanently wedge message processing for a session.

Previously, self._in_processing = None only ran sequentially inside _process() after ChannelMessage.from_batch(self._pending_messages). If _process() was cancelled while waiting (or before its first await) or if from_batch() raised, self._in_processing remained non-None forever and subsequent messages were appended to _pending_messages without ever scheduling _process().

Changes

  • src/bub/channels/handler.py:
    • Added _ensure_processing / _clear_processing with a task done-callback and try ... finally in _process() so _in_processing is always cleared on normal completion, cancellation, or error.
    • Guarded against empty _pending_messages before calling ChannelMessage.from_batch.
  • tests/test_channels.py: added regression tests for cancellation before processing and from_batch failure recovery.

Verification

  • uv run ruff check src/bub/channels/handler.py tests/test_channels.py: passed
  • uv run mypy src: Success: no issues found in 77 source files
  • uv run pytest tests/test_channels.py -q: 89 passed

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant