Skip to content

fix(poll-loop) + feat(agent): session routing fix and pre-compaction notification#2440

Open
poisson-le wants to merge 2 commits into
nanocoai:mainfrom
poisson-le:feat/pre-compaction-notify
Open

fix(poll-loop) + feat(agent): session routing fix and pre-compaction notification#2440
poisson-le wants to merge 2 commits into
nanocoai:mainfrom
poisson-le:feat/pre-compaction-notify

Conversation

@poisson-le
Copy link
Copy Markdown

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_routing from 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.ts that:

  1. Reads session_routing to identify the active channel (depends on the routing fix above)
  2. Writes an outbound message before compaction begins: "Compacting context — brief processing delay expected."
  3. After compaction, the existing compact_boundary event delivers: "Context compacted (N tokens compacted)."

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

  • The second commit depends on the first. Both must be included together.
  • These are the only two commits in this PR. Other local modifications are specific to this installation and are not included.

Aaron and others added 2 commits May 13, 2026 11:31
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>
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