anomalyco / anomalyco/opencode

SystemPrompt.environment

Open
#48,372 8 comments 27 reactions 1 assignee View on GitHub

@kitlangton is already working on this.

Since Sep 10, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

Bug: opencode run and TUI both crash with "Unexpected server error" on every prompt — SystemPrompt.environment throws TypeError: undefined is not an object (evaluating 'a.name')

Summary

Every single prompt attempt fails immediately with a generic UnknownError / "Unexpected server error" wrapper. The actual underlying crash (visible in the debug log) happens inside SystemPrompt.environment, before any request reaches the model provider. This reproduces on a completely clean $HOME and working directory, across multiple models, and in both run and the interactive TUI — so it is not caused by user config, agents, skills, or project files.

Environment
  • OpenCode version: 1.18.30
  • OS: Linux (Ubuntu-based, conda env)
  • Providers tested: OpenCode Zen — mimo-v2.5-free, big-pickle
  • Auth: fresh login via opencode auth login, valid key confirmed in auth.json
Error shown to user
Error: {
  "name": "UnknownError",
  "data": {
    "message": "Unexpected server error. Check server logs for details.",
    "ref": "err_<unique>"
  }
}
Actual error from debug log
TypeError: undefined is not an object (evaluating 'a.name')
    at resolve (/$bunfs/root/chunk-13bwg24f.js:2:1659)
    at a (/$bunfs/root/chunk-13bwg24f.js:2:936)
    at map (native:1:11)
    at <anonymous> (/$bunfs/root/chunk-13bwg24f.js:2:1626)
    at a (/$bunfs/root/chunk-13bwg24f.js:2:1166)
    at map (native:1:11)
    at <anonymous> (/$bunfs/root/chunk-13bwg24f.js:2:1626)
    at a (/$bunfs/root/chunk-13bwg24f.js:2:1166)
    at map (native:1:11)
    at <anonymous> (/$bunfs/root/chunk-13bwg24f.js:2:1390)
    at SystemPrompt.environment (/$bunfs/root/chunk-f0kkasg7.js:50:13096)
    at SystemPrompt.environment (definition) (/$bunfs/root/chunk-f0kkasg7.js:4:14254)
    at SessionPrompt.run (/$bunfs/root/chunk-f0kkasg7.js:50:14576)
    at SessionPrompt.run (definition) (/$bunfs/root/chunk-f0kkasg7.js:50:10099)
    at SessionRunState.ensureRunning (/$bunfs/root/chunk-f0kkasg7.js:50:14545)
    at SessionRunState.ensureRunning (definition) (/$bunfs/root/chunk-f0kkasg7.js:2:6720)
    at SessionPrompt.loop (/$bunfs/root/chunk-f0kkasg7.js:50:9849)
    at SessionPrompt.loop (definition) (/$bunfs/root/chunk-f0kkasg7.js:50:14481)
    at SessionPrompt.prompt (/$bunfs/root/chunk-tdg6vc0f.js:6:11695)
    at SessionPrompt.prompt (definition) (/$bunfs/root/chunk-f0kkasg7.js:50:9462)

The crash occurs on a nested .map() chain (three levels deep) inside SystemPrompt.environment, consuming an entry that is missing a .name field.

Steps to reproduce
opencode --pure run --model opencode/big-pickle "Reply with exactly: OK"

Fails every time, with a new ref each run, identical stack trace.

Isolation steps already performed (all still reproduce the crash)
  1. Removed all custom opencode.json / opencode.jsonc files (previously contained a stale llama.cpp local provider — removing this did NOT fix it).
  2. Removed AGENT.md / custom instructions from ~/.config/opencode/.
  3. Ran with OPENCODE_DISABLE_EXTERNAL_SKILLS=1 — no change.
  4. Ran with a completely empty $HOME:
    HOME=/tmp/opencode-clean-home opencode --pure run --model opencode/big-pickle "Reply with exactly: OK"
    
    — still crashes identically.
  5. Ran with both a clean $HOME and a clean working directory (no git repo, no .opencode/, no project files):
    mkdir -p /tmp/opencode-clean-home /tmp/opencode-clean-cwd
    cd /tmp/opencode-clean-cwd
    HOME=/tmp/opencode-clean-home opencode --pure run --model opencode/big-pickle "Reply with exactly: OK"
    
    — still crashes identically.
  6. Tested in the interactive TUI (not just run) — same "Failed to send prompt / Unexpected server error" message.
  7. Tested two different models (mimo-v2.5-free, big-pickle) — same crash both times.
  8. Confirmed via raw curl that the API/auth layer itself is reachable and functioning (separate MissingSessionID response confirmed for direct curl without a client-managed session, as expected) — so this is not an auth or network issue.
Expected behavior

opencode run "<prompt>" should successfully build the system prompt and return a model response, as it presumably does for most users on this version.

Suspected root cause

Per the public source (packages/opencode/src/session/system.ts, SystemPrompt.environment), this function assembles environment context including skill, reference, and MCP guidance. Since the crash reproduces with zero project files, zero custom skills, zero custom agents, and a totally empty $HOME, the malformed entry causing the missing .name is most likely coming from a built-in/bundled list (e.g. default skills, default MCP guidance, or default project-reference handling) rather than anything user-supplied.

Additional log context

A second, unrelated error also appears in the same run for the background session-title generation step (uses gpt-5.4-nano), reporting "No payment method" — this is a separate, expected billing-related issue on a sub-feature and not connected to the main crash, included here only for completeness:

error.error="AI_APICallError: No payment method. Add a payment method here: https://opencode.ai/workspace/.../billing"
Impact

This makes opencode completely unusable for any prompt, on any model, from any directory, on this version — a 100% reproduction rate, not an edge case.

Plugins

No response

OpenCode version

1.18.30

Steps to reproduce

No response

Screenshot and/or share link
Image
Operating System

Ubuntu 26

Terminal

Terminal

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.