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)
@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,openaiOAuth) viaenabled_providers
Repro
- Auth several providers (more providers → wider race window; with 2 providers it almost never triggers, with 4–5 it triggers nearly every launch)
- Launch
opencodein a real terminal - 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_providersshrinks the race window (fewer concurrent fetch handlers) - An expired OAuth token on an enabled provider (
openaiin 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.