fix(poll-loop) + feat(agent): session routing fix and pre-compaction notification#2440
Open
poisson-le wants to merge 2 commits into
Open
fix(poll-loop) + feat(agent): session routing fix and pre-compaction notification#2440poisson-le wants to merge 2 commits into
poisson-le wants to merge 2 commits into
Conversation
extractRouting(messages) picks messages[0] to determine the reply channel. When an agent-type inbound message (e.g. an approval notification) lands as messages[0], it poisons the routing context, causing all plain-text replies to go to the agent channel instead of the originating user channel. session_routing is written by the host on every container wake and is always the correct reply channel. Override routing.channelType / platformId / threadId from it whenever available. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds a pre-compaction notification in the PreCompact hook so users on the active channel (Telegram, WeChat, etc.) know to expect a brief processing delay before the compaction summary round-trip completes. The post-compaction "Context compacted" message already fires via the compact_boundary event handler; this complements it with an upfront warning. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Changes
fix(poll-loop): use session_routing as authoritative reply channel (55ef489)
When the container restarts with pending inbound messages, the first message in the batch may be an agent-type approval notification rather than a user message. Previously, poll-loop.ts used this first message to determine the reply channel — causing all subsequent responses to be routed back to the agent channel instead of the user's Telegram.
This fix reads
session_routingfrom the inbound DB and uses it as the authoritative reply channel, overriding any routing inferred from the first inbound message. Agent-type notifications can no longer poison routing.Practical impact: Fixes a bug where MCP installations (which trigger a container restart) would cause the agent to stop responding to the user until the next session.
feat(agent): pre-compaction notification to active channel (4ca4b01)
Context compaction produces a multi-second processing gap with no user-facing indication. This adds a pre-compaction hook in
container/agent-runner/src/providers/claude.tsthat:session_routingto identify the active channel (depends on the routing fix above)Users are no longer left wondering why the agent has gone silent mid-session.
Testing
Both fixes have been running in production on a live NanoClaw installation since 11 May 2026 without issues.
Notes