Repository navigation
Description
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
- Create an agent and assign a Claude Max subscription
- Ensure the agent's
~/.claude/settings.jsonhas an incompatible model (e.g.,claude-3-5-haiku-latest) or no model set - Send a task via the Tasks tab → works (defaults to sonnet)
- 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
- bug: Task execution ignores terminal model override, fails on subscription-incompatible default model #81 — Original issue (closed, partial fix)
docker/base-image/agent_server/services/claude_code.py:425—execute_claude_code()(missing fix)docker/base-image/agent_server/services/claude_code.py:746—execute_headless_task()(has fix)docker/base-image/agent_server/services/claude_code.py:681-687—_diagnose_exit_failure()(error message origin)
Activity
fix: Default Chat tab model to sonnet for subscription compatibility (A…
fix: Default Chat tab model to sonnet for subscription compatibility (#…
feat(portal): chat-first app shell — sidebar history, agent picker, b…
fix(portal): tint the avatar fallback when there is no image (ent#186)
feat(portal): agent avatar on chat-history rows (ent#186) (#1734)
feat(workspace): rename Client Portal to Workspace and open it in one…
fix(workspace): sidebar roster — loading state, top 5, label not slug (…