Skip to content

bug: agent start response shows credentials_injection: failed for subscription-mode agents #612

Closed

Description

@vybe

Summary

When a subscription-mode agent is stopped and started, the start API response includes \"credentials_injection\": \"failed\" with error \"No .credentials.enc file found in agent workspace\". This is misleading — subscription-mode agents (SUB-002) use CLAUDE_CODE_OAUTH_TOKEN env var injection, not file-based credential injection. The message implies a real failure when there is none, causing operators to take unnecessary remediation actions (e.g. re-assigning the subscription, which recreates the container and disrupts running state).

Component

Backend / Agent Lifecycle / Subscription Management

Priority

P3

Error

{
  "message": "Agent <name> started",
  "credentials_injection": "failed",
  "credentials_result": {
    "status": "failed",
    "error": "No .credentials.enc file found in agent workspace"
  }
}

Root Cause

The agent start endpoint attempts file-based credential injection regardless of the agent's auth mode. When the agent is in subscription mode, no .credentials.enc file exists (by design — SUB-002 uses CLAUDE_CODE_OAUTH_TOKEN env var set at container creation time), so the injection step fails and surfaces that failure in the response. The response does not distinguish between a real failure (missing credentials on an API-key-mode agent) and an expected non-operation (subscription-mode agent where file injection is irrelevant).

Reproduction Steps

  1. Register a subscription and assign it to an agent
  2. Verify the agent container has CLAUDE_CODE_OAUTH_TOKEN set and ANTHROPIC_API_KEY absent
  3. Call POST /api/agents/{name}/stop then POST /api/agents/{name}/start
  4. Observe: start response contains credentials_injection: failed despite the agent being correctly configured

Suggested Fix

In the agent start endpoint, check the agent's auth mode before attempting file-based credential injection:

# Before running file injection, check auth mode
agent_auth = db.get_agent_auth_mode(agent_name)

if agent_auth.auth_mode == "subscription":
    # Subscription agents use CLAUDE_CODE_OAUTH_TOKEN env var — no file injection needed
    credentials_result = {
        "status": "skipped",
        "reason": "subscription mode — credentials injected via CLAUDE_CODE_OAUTH_TOKEN env var"
    }
else:
    # Attempt file-based injection for API-key-mode agents
    credentials_result = inject_credentials_file(agent_name)

return {
    "message": f"Agent {agent_name} started",
    "credentials_injection": credentials_result["status"],
    "credentials_result": credentials_result
}

This makes the response self-documenting: "credentials_injection": "skipped" with a clear reason is unambiguous, while "failed" is reserved for genuine failures on API-key-mode agents.

Environment

  • Trinity version: 7d8abe8
  • Docker version: 24.x
  • OS: Ubuntu 22.04

Related

  • SUB-002: subscription token injection via CLAUDE_CODE_OAUTH_TOKEN env var
  • Agent start endpoint in src/backend/routers/agents.py (or equivalent)

Activity

  1. added
    status-in-progress
    on May 5, 2026
  2. self-assigned this
    on May 5, 2026
  3. added
    status-in-dev
    and removed
    status-in-progress
    on May 5, 2026
  4. vybe commented on Jun 1, 2026

    @vybe
    ContributorAuthor

    Shipped in v0.6.0 (released via #998).

  5. added
    complexity-low
    theme-ui-ux
    and removed
    status-in-dev
    on Jun 1, 2026
  6. added a commit that references this issue on Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

complexity-lowpriority-p3theme-ui-uxtype-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions