Skip to content

[BUG] ask_user answered from main session (while question from subagent) consumes 1 premium request #24

@bizzkoot

Description

@bizzkoot

Bug Report

Summary

When a subagent calls the ask_user tool and the user answers while viewing the MAIN session (not navigated to the subagent session), 1 premium request is consumed. However, if the user navigates directly to the subagent session before answering, no premium is consumed.

Expected Behavior

  • Subagent calls ask_user tool
  • User answers the question from ANY session view (main or subagent)
  • Answer is delivered via IPC to the waiting subagent
  • NO additional premium request should be consumed

Actual Behavior

  • Scenario A (Working): User navigates to subagent session, answers ask_user → No premium consumed ✅
  • Scenario B (BUG): User stays in main session, answers ask_user from subagent → 1 premium consumed ❌

Environment

  • CodeNomad version: latest
  • Platform: All (Electron app)

Steps to Reproduce

  1. Send a prompt that triggers a subagent
  2. The subagent calls ask_user to ask a question
  3. Stay in the main session (do NOT navigate to the subagent session)
  4. Answer the question in the UI
  5. Observe that the premium request count increases by 1 ❌

Root Cause Analysis

Key Observation: When the user answers while viewing the MAIN session, the answer is being routed incorrectly.

Hypothesis: Session association issue

  • When answering from main session view, the system may create a new user message in the MAIN session
  • This triggers a new LLM request in the main session (premium consumed)
  • The answer is NOT being properly routed via IPC to the waiting subagent

What should happen:

// Current flow when answering from main session:
User answers (in main session view)
  
Creates user message in MAIN session 
  
Triggers LLM request in MAIN session 
  
Premium consumed 

// Correct flow:
User answers (from any session view)
  
Sends via mcp:answer IPC 
  
Resolves subagent's ask_user Promise ✅
  
No premium consumed 

Possible causes:

  1. The question wizard may be creating a user message in the currently-viewed session instead of just sending IPC
  2. The answer handler may not be routing correctly when the active session != the question's session
  3. There may be session ID confusion in the answer routing logic

Relevant Files

  • packages/ui/src/components/instance/instance-shell2.tsx (lines 280-343) - Answer submission handler
  • packages/ui/src/stores/questions.ts - Question queue and session association
  • packages/ui/src/lib/mcp-bridge.ts - MCP bridge implementation
  • packages/mcp-server/src/bridge/ipc.ts - IPC handlers

Investigation Needed

  1. Check session association in question queue:

    • Verify that pending questions store their originating session ID
    • Check if the answer handler uses the question's session ID or the current active session ID
  2. Trace the answer flow:

    • When answering from main session, what sessionId is associated with the answer?
    • Is a new user message created in the main session?
  3. Compare the two scenarios:

    • Scenario A (working): Answer from subagent session view
    • Scenario B (broken): Answer from main session view
    • What's different in the code path?

Debug Steps

  1. Enable dev mode and look for:

    • [✅ ANSWER SUBMIT] logs - check the instanceId and session info
    • [✅ ROUTING] Using MCP path vs [❌ ROUTING] Using OpenCode SDK path
    • Any logs showing user message creation on answer
  2. Add logging to track:

    • Which session the question originated from
    • Which session is currently active when answering
    • Whether a user message is created in the main session

Priority

High - This significantly impacts UX when using subagents, as users must navigate away from the main conversation to avoid consuming premium

Related Issues

Labels

bug, premium, ask_user, subagent, routing, priority:high

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