Skip to content

[BUG] Subagent launches consume 1 premium request each #23

@bizzkoot

Description

@bizzkoot

Bug Report

Summary

When any subagent is launched via the Task tool, it consumes 1 premium request. This is unexpected behavior since subagents are internal operations that should not consume user's premium quota.

Expected Behavior

  • Only the main agent's initial user prompt should consume 1 premium request
  • Subagent launches and operations should NOT consume additional premium requests

Actual Behavior

  • Every subagent launch consumes 1 premium request
  • This causes quota exhaustion to occur significantly faster when using subagent-based features

Environment

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

Steps to Reproduce

  1. Send a prompt to the main agent that will trigger a subagent
  2. Observe the premium request count increases by 1 for the main agent
  3. Observe the premium request count increases by ANOTHER 1 when the subagent is launched
  4. Total: 2+ premium requests instead of expected 1

Root Cause Analysis

Based on code review, there is already a fix in place in packages/ui/src/stores/message-v2/instance-store.ts:

function updateUsageWithInfo(info: MessageInfo | undefined) {
  // ...
  const session = state.sessions[info.sessionID]
  if (session?.parentId != null) {
    if (import.meta.env.DEV) {
      console.log(`[Usage Debug] ⏭️ SKIPPING subagent session ${info.sessionID} - parentId: ${session.parentId}`)
    }
    return  // Skip usage tracking for subagents
  }
  // Track usage for main sessions
}

However, the issue may be that:

  1. The Task tool completion in the MAIN session might be generating an assistant message that IS tracked
  2. Or there's a timing issue where session.parentId is not yet populated when usage is tracked
  3. Or the session hydration (rebuildUsageStateFromInfos) is not properly filtering subagent messages

Relevant Files

  • packages/ui/src/stores/message-v2/instance-store.ts (lines 367-391)
  • packages/server/src/workspaces/instance-events.ts (session cache with parentID)
  • tasks/done/prd-subagent-premium-fix.md (PRD for the fix)

Investigation Needed

  1. Verify that session.parentId is being set correctly before message.updated events
  2. Check if tool completions in the main session are being incorrectly tracked
  3. Add debug logging to trace when and where premium requests are being counted
  4. Verify rebuildUsageStateFromInfos is properly filtering during hydration

Priority

High - This affects all users and causes significant quota waste

Labels

bug, premium, subagent, 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