fix: restore message tool suppression to prevent duplicate messages #19

Merged
code-server merged 3 commits from fix/message-tool-suppression into main 2026-03-05 07:40:50 +01:00
Collaborator

Summary

Restores the message tool suppression feature that was accidentally removed during refactoring. This prevents users from receiving duplicate messages when the agent uses the message tool to reply to them.

Problem

When the agent uses the message tool to send a reply to the same channel/chat_id as the incoming message, users receive TWO messages:

  1. The message from the message tool
  2. The automatic final reply

Solution

  • Add _sent_in_turn tracking to MessageTool
  • Set flag when message tool sends to same target as incoming message
  • Suppress automatic final reply when flag is set

Changes

  • nanobot/agent/tools/message.py: Add _sent_in_turn field, start_turn() method, and tracking logic
  • nanobot/agent/loop.py: Call start_turn() at beginning, check flag before sending final reply

Testing

All 5 tests in test_message_tool_suppress.py now pass:

  • Suppress when sent to same target
  • Don't suppress when sent to different target
  • Don't suppress when message tool not used
  • Turn tracking works correctly
  • start_turn() resets flag

History

This feature was originally implemented in commits fafd8d4 (Feb 26) and 29e6709 (Feb 27), but was accidentally removed during subsequent refactoring.

🤖 Generated with Claude Code

## Summary Restores the message tool suppression feature that was accidentally removed during refactoring. This prevents users from receiving duplicate messages when the agent uses the message tool to reply to them. ## Problem When the agent uses the `message` tool to send a reply to the same channel/chat_id as the incoming message, users receive TWO messages: 1. The message from the message tool 2. The automatic final reply ## Solution - Add `_sent_in_turn` tracking to MessageTool - Set flag when message tool sends to same target as incoming message - Suppress automatic final reply when flag is set ## Changes - `nanobot/agent/tools/message.py`: Add `_sent_in_turn` field, `start_turn()` method, and tracking logic - `nanobot/agent/loop.py`: Call `start_turn()` at beginning, check flag before sending final reply ## Testing All 5 tests in `test_message_tool_suppress.py` now pass: - ✅ Suppress when sent to same target - ✅ Don't suppress when sent to different target - ✅ Don't suppress when message tool not used - ✅ Turn tracking works correctly - ✅ start_turn() resets flag ## History This feature was originally implemented in commits fafd8d4 (Feb 26) and 29e6709 (Feb 27), but was accidentally removed during subsequent refactoring. 🤖 Generated with Claude Code
code-server added 3 commits 2026-03-05 05:31:09 +01:00
fix: remove dead last_consolidated field from Session
Build Nanobot OAuth / build (pull_request) Successful in 5m51s
Build Nanobot OAuth / cleanup (pull_request) Has been skipped
83d2acf07f
The `last_consolidated` marker was designed for incremental consolidation
assuming append-only messages. However, deferred trim removes messages from
the session, which broke the incremental assumption and caused consolidation
to fail silently (early exit when end_idx <= stale last_consolidated).

After trim, the session only contains NEW unconsolidated messages, making
the marker unnecessary. Consolidation now always starts from index 0,
processing all messages in the session (which are by definition not yet
consolidated due to trim).

Fixes the bug where extraction completely stopped working after trim
(zero facts extracted despite multiple consolidation attempts).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
test: remove obsolete last_consolidated tests
Build Nanobot OAuth / build (pull_request) Successful in 5m59s
Build Nanobot OAuth / cleanup (pull_request) Has been skipped
b854d9a888
The test_consolidate_offset.py file contained ~100 tests for the
last_consolidated field which no longer exists. Since the field and its
incremental consolidation behavior have been removed, these tests are
obsolete.

Also removed redundant empty check in memory.py consolidation (if
len <= keep_count, then slice will be empty).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
fix: restore message tool suppression to prevent duplicate messages
Build Nanobot OAuth / build (pull_request) Successful in 7m14s
Build Nanobot OAuth / cleanup (pull_request) Has been skipped
f7cebfe7f3
When the agent uses the message tool to reply to the same channel/chat_id
as the incoming message, the final automatic reply is now suppressed to
prevent duplicate messages to the user.

Changes:
- MessageTool: add _sent_in_turn flag and start_turn() method
- MessageTool.execute(): set flag when sending to same target as context
- AgentLoop._process_message(): call start_turn() at beginning
- AgentLoop._process_message(): return None if message tool already sent

This restores functionality that was accidentally removed during refactoring
(originally implemented in commits fafd8d4, 29e6709).

Fixes 3 failing tests in test_message_tool_suppress.py

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
code-server merged commit f1cbd4d730 into main 2026-03-05 07:40:50 +01:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: wylab/nanobot#19