Enhance channel_ai_bot with history context and auto-reconnect#5
Open
shanw4 wants to merge 4 commits into
Open
Enhance channel_ai_bot with history context and auto-reconnect#5shanw4 wants to merge 4 commits into
shanw4 wants to merge 4 commits into
Conversation
- Fetch last 50 channel messages and include as context in the system prompt so the AI can reference and cite prior discussion - Add auto-reconnect loop with exponential backoff so the bot recovers from disconnects without manual intervention - Re-send user-join auth on every reconnect (fixes silent deaf-socket bug where the old version reconnected but stopped receiving events) - Add CLAUDE.md with project overview and architecture notes
- Reset exponential backoff delay to 5s after a successful connection so long-running bots don't wait up to 5 minutes after a clean reconnect - Log HTTP status when channel history fetch fails instead of silently returning an empty list
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.
This PR extends the channel_ai_bot example with two improvements:
Channel history context
The bot now fetches the last 50 messages from the channel before responding and includes them in the system prompt. This allows the AI to reference and cite prior discussion, making it significantly more useful in active team channels.
Auto-reconnect with exponential backoff
The original implementation had a silent reliability bug: after a socket disconnect, the bot would reconnect the socket but not re-send the user-join authentication event. The server would accept the connection but stop routing events:channel events to it, leaving the
bot silently deaf until a full process restart.
This PR replaces the single connect/wait cycle with a loop that re-authenticates on every reconnect, with exponential backoff (5s → 10s → ... → 5 min cap) to avoid hammering a temporarily unavailable server.
Tested against Open WebUI 0.5.10.