Skip to content

bug: Chat tab fails with misleading 'token expired' error — missing model default from #81 fix #138

Closed

Description

@webmixgamer

Summary

The Chat tab fails with "Subscription token may be expired or revoked. Generate a new one with 'claude setup-token'" when the agent's ~/.claude/settings.json contains a model incompatible with the assigned subscription. The Tasks tab works fine because Issue #81 added a model="sonnet" default — but that fix was only applied to execute_headless_task(), not to execute_claude_code() which the Chat tab uses.

Component

Agent Runtime — docker/base-image/agent_server/services/claude_code.py

Error

Task execution failed (exit code -9): Subscription token may be expired or revoked. Generate a new one with 'claude setup-token'.

Root Cause

Issue #81 identified that headless task execution failed when no --model flag was passed, causing Claude Code to fall back to the agent's settings.json model which might be incompatible with the subscription type.

The fix (defaulting to model="sonnet") was applied only to execute_headless_task() (line 746), which serves the Tasks tab via /api/task. The Chat tab uses a different code path — execute_claude_code() (line 425) — which has no model defaulting logic. It relies on agent_state.current_model (line 473), which may be None or an incompatible model.

Code paths

Tab Backend route Agent endpoint Function Model default?
Tasks task_execution_service.py /api/task execute_headless_task() ✅ Defaults to "sonnet" (Issue #81)
Chat routers/chat.py /api/chat execute_claude_code() ❌ No default — uses agent_state.current_model as-is

Reproduction Steps

  1. Create an agent and assign a Claude Max subscription
  2. Ensure the agent's ~/.claude/settings.json has an incompatible model (e.g., claude-3-5-haiku-latest) or no model set
  3. Send a task via the Tasks tab → works (defaults to sonnet)
  4. Send a message via the Chat tab → fails with "token expired" error

Suggested Fix

Apply the same model defaulting logic from execute_headless_task() to execute_claude_code():

# In execute_claude_code(), before building the command:
if model is None and not agent_state.current_model:
    model = "sonnet"
    logger.debug("[Chat] No model specified, defaulting to 'sonnet' for subscription compatibility")

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority-p1type-bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions