Skip to content

_server_prompt_active flag timing can leak duplicate messages #66

@michal-franc-agent

Description

@michal-franc-agent

Problem

The _server_prompt_active boolean in claude_wrapper.py is set True before the prompt is sent and False after run() returns. The background watcher uses it to decide whether to suppress on_user_message callbacks. Two timing issues:

  1. Leftover entries suppressed — If JSONL entries exist from before the prompt (e.g. from a previous tmux-typed interaction), the watcher may incorrectly suppress them because the flag is already set.
  2. Flag clears too early — If the watcher polls right after run() clears the flag but before the turn's entries are fully processed, a server-initiated user message leaks through as a "tmux-typed" message, causing a duplicate entry in chat.

Impact

  • Low — worst case is a duplicate or missing chat entry on the dashboard/phone.

Possible Fixes

  • Track the JSONL line offset when the server prompt was sent, and use that to distinguish pre-prompt vs post-prompt entries instead of a boolean flag.
  • Use per-prompt request IDs in the JSONL entries (if Claude Code supports it).

From PR #49 reliability audit (concurrency item 2).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions