Skip to content

Agent.get() returns undefined without error handling, causing crash #9437

Closed as duplicate

Description

@rcdailey

Description

Agent.get() returns undefined when an agent doesn't exist, but callers like createUserMessage() don't handle this case, causing a crash:

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

The issue is in src/agent/agent.ts line 246-248:

export async function get(agent: string) {
  return state().then((x) => x[agent])  // Returns undefined if not found
}

And src/session/prompt.ts line 825, 833:

const agent = await Agent.get(input.agent ?? (await Agent.defaultAgent()))
// ...
agent: agent.name,  // Crashes here when agent is undefined

This can be triggered by any caller passing an invalid agent name - in my case, it was the plannotator plugin defaulting to "build" when I had that agent disabled.

Plugins

@plannotator/opencode@0.6.6

OpenCode version

v1.1.25

Steps to reproduce

  1. Disable the default build agent in opencode config:
    { "agent": { "build": { "disable": true } } }
  2. Install plannotator plugin
  3. Use plannotator to create and approve a plan (without changing agent switch setting in plannotator UI)
  4. OpenCode crashes with TypeError

Screenshot and/or share link

N/A - crash occurs before UI can render

Operating System

Fedora Linux

Terminal

Ghostty


Suggested Fix

Either:

  1. Agent.get() should throw a descriptive error when agent not found
  2. Or createUserMessage() should validate and provide a helpful message like: "Agent 'build' not found. Available agents: [list]"

This is a defensive fix - callers shouldn't need to know that Agent.get() can return undefined.

Related

Activity

  1. github-actions commented on Jan 19, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Feel free to ignore if none of these address your specific case.

  2. rcdailey commented on Jan 21, 2026

    @rcdailey
    Author

    @rekram1-node duplicate of what issue specifically?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions