Skip to content

A refused second session message makes the in-flight message lose its reply and stops the turn #452

Closed

Description

@barelyworkingcode

Found while working #434.

Problem

A relay session message refused because a turn is already running (409, session: already processing a message) makes the first, in-flight relay session message lose its reply. The first CLI waits the full 5 minutes, exits 1 with session host answered 500 Internal Server Error (session: response timeout after 5m0s), and relay then stops the turn, although the agent answered long before.

Seen in the real app on the devbox (a host session: a long message, then a second message while it ran) and reproduced on main with an e2e test through the CLI: hold a local session's turn open, send a second message (409), release the turn; the first message never returns its reply.

Root cause

Manager.SendMessageSync registers its response collector in m.collectors[id] before SendMessage accepts the message, replacing the collector of the call already waiting. When SendMessage refuses the second call, its deferred cleanup deletes m.collectors[id], the first call's slot. The first call's collector then never sees turn_done, times out, and StopGeneration ends the turn.

Fix

A refused SendMessageSync leaves the in-flight call's collector in place: it does not replace a collector that is already waiting, and its cleanup removes only its own collector.

Acceptance criteria

  • A relay session message refused while another message runs leaves the first one's reply intact.
  • The first relay session message prints its reply when the turn ends, and exits 0.

Contract

  • Owned files: internal/sessions/session/manager.go (SendMessageSync), e2e/features/bug452_refused_message_keeps_reply_test.go, docs/FEATURES.md (G1.05 names the test).

Activity

  1. barelyworkingcode commented on Oct 16, 2026

    @barelyworkingcode
    OwnerAuthor

    Coordinator approval: a bug proven on main through the CLI door (e2e repro) and in the real app, inside the threat model's scope only as a correctness defect; the fix only restores the intended behaviour of relay session message. Listed on the retro list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions