Skip to content

Bug: Options auto-select during session resume/respawn #133

@craigvandotcom

Description

@craigvandotcom

Description

When the agent presents options in the UI and the user takes time to respond, the system sometimes appears to auto-continue as if an option was already selected. The user sees the conversation as "finished", then suddenly work appears as if they had responded.

Root Cause Analysis

After investigating the logs and source code, this appears to be a race condition in session resume with message queue timing:

Flow:

  1. Agent presents options, finishes responding, waits for user input via message queue
  2. Daemon respawns the Claude process (seen repeatedly in logs with --resume)
  3. New process:
    • Resumes from existing Claude Code session
    • Calls await opts.nextMessage() at claudeRemote.ts:85
    • If message exists in queue or arrives during respawn, processes immediately

Contributing Factors:

  • SESSION_READY_TIMEOUT_MS = 10000 (10s) in sync.ts sends messages after timeout even if not "ready"
  • Multiple --resume flags in daemon logs showing frequent process restarts
  • No idempotency checks between message queue and session resume state

Relevant Files:

  • src/claude/claudeRemote.ts:85 - Initial message wait on resume
  • src/api/apiSession.ts:140-144 - Message callback processing
  • infrastructure/happy-web/sources/sync/sync.ts:287-289 - Ready timeout logic

Reproduction

  1. Start a conversation with an agent
  2. Get to a point where options are presented
  3. Wait ~10+ seconds before selecting an option
  4. Observe if work continues without explicit user selection

Potential Fixes

  1. Add a "waiting for user input" lock state when options are presented
  2. Implement idempotency/deduplication between session resume and pending messages
  3. Clear message queue on session resume to prevent stale message processing
  4. Add confirmation mechanism before processing option selections after delay

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions