anomalyco / anomalyco/opencode

TUI crash: TypeError 'a[t]' in location-state refresh — race between location init and per-provider fetches (v1.18.30, also present in v1.18.29)

Open
#48,220 1 comment 0 reactions 1 assignee View on GitHub

@simonklee is already working on this.

Since Sep 9, 2026.

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

Description

TUI crash: TypeError: undefined is not an object (evaluating 'a[t]') — race between location-state init and per-provider fetch refreshes

Summary

OpenCode TUI (Bun build) crashes with a TypeError inside the location-state refresh path. Multiple concurrent instances of the error appear at once (one per fetch handler), each with a slightly different refresh frame offset. The crash surfaces when exiting shortly after launch, and correlates with the number of enabled/authed providers.

Environment

  • opencode 1.18.30 (also verified present in 1.18.29 binary via strings)
  • macOS (darwin-arm64), Homebrew install
  • 4–5 authed providers (modelscope-ai, opencode-go, zai-coding-plan, openai OAuth) via enabled_providers

Repro

  1. Auth several providers (more providers → wider race window; with 2 providers it almost never triggers, with 4–5 it triggers nearly every launch)
  2. Launch opencode in a real terminal
  3. Exit (/exit) within a few seconds — or just wait; on affected machines the TUI dies ~3s after boot

Observed output (4 concurrent errors, one per handler)

TypeError: undefined is not an object (evaluating 'a[t]')
      at Q (/$bunfs/root/chunk-tpcfr0ps.js:2:113331)
      at Q (/$bunfs/root/chunk-tpcfr0ps.js:2:113298)
      at Q (/$bunfs/root/chunk-tpcfr0ps.js:2:113298)
      at <anonymous> (/$bunfs/root/chunk-tpcfr0ps.js:2:113632)
      at w (/$bunfs/root/chunk-zwn33msg.js:2:11226)
      at e (/$bunfs/root/chunk-tpcfr0ps.js:2:113598)
      at refresh (/$bunfs/root/chunk-sa647m8s.js:8:16134)   ← offsets vary: 15927 / 16134 / 16560 = different refresh call sites

(×4 identical bursts with different refresh offsets. The theme code printed alongside is incidental — it shares the bundled chunk with the state updater.)

Mechanism (from binary inspection)

Startup runs concurrently:

  • creation of the location's state entry, and
  • fetches for integrations / models / references / commands / agents

The fetch handlers write into the entry without ensuring it exists, e.g. (strings from the shipped binary):

"location", g, "agent",   b.data.data
"location", g, "command", b.data.data

i.e. setState("location", locationKey, <field>, response.data). If a fetch resolves before initialization, the recursive state updater indexes an undefined parent → a[t] TypeError. The log corroborates: the last event before the stall is booting location services.

Workarounds

  • Waiting 10–15s before exiting avoids the visible error (fetches have settled)
  • Reducing enabled_providers shrinks the race window (fewer concurrent fetch handlers)
  • An expired OAuth token on an enabled provider (openai in my case, offering zero usable models) adds a refresh round-trip to the same critical path

Suggested fix

Initialize the location entry before launching dependent refreshes, or make each refresh handler create the entry on demand (e.g. upsert semantics / ?? {} guard).

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.