opencode icon indicating copy to clipboard operation
opencode copied to clipboard

TUI: Renaming a session after pressing Ctrl+D submits the delete confirmation as its title

Open 521ox opened this issue 1 week ago • 2 comments

Description

After the first delete keystroke in the Sessions picker, Rename uses the row's temporary confirmation prompt instead of the selected session's title. Accepting the default submits the prompt as the new title. The session is not deleted.

Plugins

No external plugins in the reproduction.

OpenCode version

V2 dev at 521ceac004e59fbbfca0929596107cd8430f2b26 (CLI package 2.3.0).

Steps to reproduce

  1. Open /sessions and highlight a named, disposable session.
  2. Press Ctrl+D once. Without moving the selection or confirming deletion, press Ctrl+R.
  3. The rename field shows Press ctrl+d again to confirm rather than the session name. Pressing Enter without editing submits that string. With Ctrl+R alone the original name is preserved.

Reproduced 3/3 times with the production list and rename dialog using the existing TUI fixture and a fake transport. The control preserved the original title 3/3 times. No DELETE request was sent. The rename action should read the session title, not its temporary display label.

Operating System

Windows 11 x64, Bun 1.4.4.

Terminal

OpenTUI test renderer; not a manual terminal recording.

521ox avatar Nov 18 '26 09:11 521ox

Seen with a simulated model or a mock server, not a real provider; a maintainer should confirm.

Thanks for the precise report. I reproduced this on 2.3.0, and it still happens on the latest dev (2237765).

The script below creates a session titled "Disposable session", opens /sessions, presses Ctrl+D once and then Ctrl+R. The Rename session field is prefilled with Press ctrl+d again to confirm. Pressing Enter saves that text as the session's title: it then shows in the session tab and in the Sessions list. The session is not deleted. The recording and screenshots below show it.

opencode-drive's simulated model was used only to create the named session; it plays no part in the bug.

The cause seems to be in packages/tui/src/component/dialog-session-list.tsx. While a delete is waiting for confirmation, the row's title is replaced by the confirmation prompt. The rename action prefills from that row title instead of the session's real title.

https://github.com/user-attachments/assets/71dab960-4f3b-401d-810d-84085d73e7ec

Screenshot

Screenshot

Reproduction script (drive.ts)
// Reproduces anomalyco/opencode#64622: in the Sessions picker, Ctrl+D (first press) then Ctrl+R
// prefills the rename field with the delete-confirmation prompt, and Enter saves it as the title.
import { Effect, Stream } from "effect"
import { Llm, OpenCodeDriver } from "opencode-drive"

// Wait until the captured terminal frame contains `text` (polls the rendered cells).
type Ui = { capture: () => Effect.Effect<any, any>; screenshot: (name: string) => Effect.Effect<any, any> }
const waitText = (ui: Ui, text: string, timeout = 20000) =>
  Effect.gen(function* () {
    const deadline = Date.now() + timeout
    while (Date.now() < deadline) {
      const frame: any = yield* ui.capture()
      const screen = frame.lines.map((l: any) => l.spans.map((s: any) => s.text).join("")).join("\n")
      if (screen.includes(text)) return
      yield* Effect.sleep(200)
    }
    yield* ui.screenshot("timeout")
    return yield* Effect.fail(new Error(`timed out waiting for ${text}`))
  })

export default OpenCodeDriver.use(
  {
    ...(process.env.OC_DEV ? { opencode: { dev: process.env.OC_DEV } } : {}),
    tui: { recording: true, keypressOverlay: true },
  },
  ({ ui, llm }) =>
    Effect.gen(function* () {
      // Create a session; the simulated model answers every request (reply and title) with "Disposable session".
      yield* llm.serve(() => Stream.make(Llm.text("Disposable session")))
      yield* ui.submit("Hello")
      yield* waitText(ui, "Disposable session")
      yield* Effect.sleep(1500)

      // Open the Sessions picker.
      yield* ui.type("/sessions")
      yield* Effect.sleep(500)
      yield* ui.enter()
      yield* waitText(ui, "Sessions")
      yield* ui.screenshot("1-sessions-list")

      // First delete keystroke: row shows the confirmation prompt.
      yield* ui.press("d", { ctrl: true })
      yield* waitText(ui, "again to confirm")
      yield* ui.screenshot("2-after-ctrl-d")

      // Rename without moving the selection.
      yield* ui.press("r", { ctrl: true })
      yield* Effect.sleep(1000)
      yield* ui.screenshot("3-rename-dialog")

      // Accept the default value.
      yield* ui.enter()
      yield* Effect.sleep(1500)
      yield* ui.screenshot("4-after-enter")

      // Re-open the picker to see the stored title.
      yield* ui.press("escape")
      yield* Effect.sleep(500)
      yield* ui.type("/sessions")
      yield* Effect.sleep(500)
      yield* ui.enter()
      yield* Effect.sleep(1500)
      yield* ui.screenshot("5-sessions-list-after-rename")
      yield* Effect.sleep(1000)
    }),
)

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.

opencodejr[bot] avatar Nov 18 '26 09:11 opencodejr[bot]

I'd like to work on this. Plan: reproduce on my setup, add a focused fix with a test if the repo already has coverage in this area. Is it still available for an outside PR?

amrsorne avatar Nov 18 '26 10:11 amrsorne