Skip to content

[bug] Inbox messages delivered twice due to race condition in check_and_send_pending_messages #164

@wutong0218

Description

@wutong0218

Description

Every inbox message is delivered exactly twice to the receiving terminal. This corrupts
agent input streams in multi-agent workflows using assign + send_message.

Root Cause

In inbox_service.py, check_and_send_pending_messages() calls send_input() before
update_message_status(DELIVERED). The send_input() types into tmux, which updates the
terminal log file, which triggers the watchdog's on_modified handler. The second watchdog
invocation calls get_pending_messages() and finds the message still PENDING (because
update_message_status hasn't committed yet), so it delivers the message again.

Reproducer

  1. Create a session with a supervisor agent
  2. Use assign to create a worker agent
  3. Worker calls send_message back to supervisor
  4. Observe the message appears twice in the supervisor's tmux window

Fix

Move update_message_status(message.id, MessageStatus.DELIVERED) before
terminal_service.send_input(). PR: #

Environment

  • CAO version: 2.0.0 (commit d2e9b56)
  • OS: macOS
  • Provider: kiro_cli

File the issue first, then reference it in the PR. Want me to help with anything else on this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions