-
Notifications
You must be signed in to change notification settings - Fork 0
Description
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_usertool - 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_userfrom subagent → 1 premium consumed ❌
Environment
- CodeNomad version: latest
- Platform: All (Electron app)
Steps to Reproduce
- Send a prompt that triggers a subagent
- The subagent calls
ask_userto ask a question - Stay in the main session (do NOT navigate to the subagent session)
- Answer the question in the UI
- 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:
- The question wizard may be creating a user message in the currently-viewed session instead of just sending IPC
- The answer handler may not be routing correctly when the active session != the question's session
- 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 handlerpackages/ui/src/stores/questions.ts- Question queue and session associationpackages/ui/src/lib/mcp-bridge.ts- MCP bridge implementationpackages/mcp-server/src/bridge/ipc.ts- IPC handlers
Investigation Needed
-
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
-
Trace the answer flow:
- When answering from main session, what
sessionIdis associated with the answer? - Is a new user message created in the main session?
- When answering from main session, what
-
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
-
Enable dev mode and look for:
[✅ ANSWER SUBMIT]logs - check theinstanceIdand session info[✅ ROUTING] Using MCP pathvs[❌ ROUTING] Using OpenCode SDK path- Any logs showing user message creation on answer
-
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
- [BUG] Subagent launches consume 1 premium request each #23: Subagent launches consume 1 premium request each
Labels
bug, premium, ask_user, subagent, routing, priority:high