Skip to content

remapAgentKeysToDisplayNames drops original agent keys, causing Agent.get() to return undefined #1922

@Wongbuer

Description

@Wongbuer

Bug Description

remapAgentKeysToDisplayNames() replaces original agent keys (e.g. "prometheus") with display names (e.g. "Prometheus (Plan Builder)"), but does not retain the original key. Upstream opencode's Agent.get(name) performs a direct dictionary lookup using the original internal key, which no longer exists in the agent map → returns undefined → crashes at agent.name.

Error

TypeError: undefined is not an object (evaluating 'agent.name')
  at createUserMessage (src/session/prompt.ts:960:14)

Environment

  • opencode-ai: v1.2.6 (also reproduced on v1.1.65)
  • oh-my-opencode: v3.7.1 (also reproduced on v3.3.2, though v3.3.2 doesn't have remapAgentKeysToDisplayNames — it has a different root cause)
  • OS: Linux (Ubuntu)
  • oh-my-opencode loaded as plugin (not as main binary)

Root Cause

In remapAgentKeysToDisplayNames():

function remapAgentKeysToDisplayNames(agents) {
  const result = {};
  for (const [key, value] of Object.entries(agents)) {
    const displayName = AGENT_DISPLAY_NAMES[key];
    if (displayName && displayName !== key) {
      result[displayName] = value;  // ← only display name kept, original key dropped
    } else {
      result[key] = value;
    }
  }
  return result;
}

After this function runs, config.agent contains keys like "Prometheus (Plan Builder)" but not "prometheus". When a user selects Prometheus mode, upstream opencode calls Agent.get("prometheus") which does a simple x["prometheus"] lookup → undefined → crash.

Debug Evidence

Injected console.error at key points confirmed:

  1. ✅ Plugin IS imported
  2. OhMyOpenCodePlugin() IS called and returns successfully
  3. configHandler IS called
  4. ✅ Agent keys after config hook: ["Sisyphus (Ultraworker)", "Hephaestus (Deep Agent)", "Prometheus (Plan Builder)", "Atlas (Plan Executor)", "Sisyphus-Junior", "oracle", ...]
  5. "prometheus" in agentResultfalse
  6. "Prometheus (Plan Builder)" in agentResulttrue

Fix

Retain original keys alongside display names:

function remapAgentKeysToDisplayNames(agents) {
  const result = {};
  for (const [key, value] of Object.entries(agents)) {
    const displayName = AGENT_DISPLAY_NAMES[key];
    if (displayName && displayName !== key) {
      result[displayName] = value;
      result[key] = value;  // ← also keep original key
    } else {
      result[key] = value;
    }
  }
  return result;
}

Related Issues

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