You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TUI: theme picked in /themes is sometimes replaced by an earlier preview (saves race for cli.json's lock) #65523
Picking a theme in /themes sometimes doesn't stick: the TUI ends up on a theme that matched the first letters I typed (cursor from "c"), and cli.json keeps it after a restart.
The list calls themes.set on every keystroke and move, and each one fires void config.update(...) without waiting for the previous save. Every save takes the cli.json lock, and Flock.acquire polls with backoff, so the lock isn't granted in call order. An early preview's save can land after the pick's save, and the config watcher then applies it to the running TUI too.
On dev (1645a8a), real TUI in a PTY, clean config, 30 picks each:
keys back to back: 8–11 of 30 end on the wrong theme
60 ms per key, Enter right after: 2 of 30
60 ms per key with a pause before Enter: 0–1 of 30
One pick writes cli.json 3–19 times. It's rare at normal typing speed on a fast disk, but it happens.
Related: #56147 / #62498 (change the theme only on confirm). This one is about saves landing out of order; any other quick config.update calls race the same way.
Thanks for the detailed report, @cevr. I could reproduce this.
The script below runs the TUI headless with a fresh config. On each try it opens /themes, types cur one key at a time, deletes it, types the target theme (nord or opencode), presses Enter right away and reads cli.json 1.5 s later.
2.3.0: 10 of 20 picks left theme.name set to cursor, the theme the c filter previewed, instead of the one picked.
Latest dev (5310e42), run from source: still happens, 9 of 16 picks ended on cursor. themes.set() there still saves the config without waiting for the previous save.
I checked this through cli.json only. I didn't do the restart step. The recording below shows the run.
Related: #56147 and PR #62498 (change the theme only on confirm). That change would avoid this in the theme list, but the out-of-order saves would remain for any other quick config updates.
recording.mp4Reproduction script (drive.ts)
// Repro for #65523: rapid /themes filtering makes an earlier preview's cli.json// save land after the confirmed pick's save.import{Effect}from"effect"import{readFileSync}from"node:fs"import{join}from"node:path"import{OpenCodeDriver}from"opencode-drive"constATTEMPTS=Number(process.env.ATTEMPTS??10)exportdefaultOpenCodeDriver.use({
...(process.env.OC_DEV ? {opencode: {dev: process.env.OC_DEV}} : {}),tui: {recording: true,keypressOverlay: true},tuiConfig: {theme: {name: "opencode"}},},(oc)=>Effect.gen(function*(){constui=oc.uiconstcliJson=join(oc.artifacts,"files",".opencode","cli.json")constsaved=()=>{try{returnJSON.parse(readFileSync(cliJson,"utf8"))?.theme?.name}catch(e){return`unreadable: ${e}`}}yield*Effect.sleep(1500)letwrong=0for(leti=1;i<=ATTEMPTS;i++){consttarget=i%2 ? "nord" : "opencode"yield*ui.type("/themes")yield*ui.enter()yield*ui.waitFor("esc",{timeout: 20000})// type "cur" one key at a time, delete it, type the target, Enter right awayfor(constcof"cur")yield*ui.type(c)for(letk=0;k<3;k++)yield*ui.press("backspace")for(constcoftarget)yield*ui.type(c)yield*ui.enter()yield*Effect.sleep(1500)constname=saved()constok=name===targetif(!ok)wrong++console.log(`attempt ${i}: picked=${target} cli.json theme.name=${name}${ok ? "OK" : "WRONG"}`)if(!ok)yield*ui.screenshot(`wrong-${i}`)}console.log(`RESULT: ${wrong}/${ATTEMPTS} picks ended on the wrong theme in cli.json`)}),)
Run it with opencode-drive: opencode-drive run ./drive.ts. It drives opencode from your PATH; set OC_DEV to the path of an OpenCode checkout to run that from source instead.
Activity
cevr commentedon Nov 22, 2026
I have a fix on a branch (serial config updates, and the theme list previews in memory and saves once on Enter): https://github.com/cevr/opencode/tree/theme-save-order. I'm at the open PR limit here, so I'll open it as a PR when a slot frees up.
opencodejr commentedon Nov 22, 2026
Thanks for the detailed report, @cevr. I could reproduce this.
The script below runs the TUI headless with a fresh config. On each try it opens
/themes, typescurone key at a time, deletes it, types the target theme (nordoropencode), presses Enter right away and readscli.json1.5 s later.theme.nameset tocursor, the theme thecfilter previewed, instead of the one picked.dev(5310e42), run from source: still happens, 9 of 16 picks ended oncursor.themes.set()there still saves the config without waiting for the previous save.I checked this through
cli.jsononly. I didn't do the restart step. The recording below shows the run.Related: #56147 and PR #62498 (change the theme only on confirm). That change would avoid this in the theme list, but the out-of-order saves would remain for any other quick config updates.
recording.mp4
Reproduction script (drive.ts)
Run it with opencode-drive:
opencode-drive run ./drive.ts. It drivesopencodefrom yourPATH; setOC_DEVto the path of an OpenCode checkout to run that from source instead.