Skip to content

tui: /models drops provider grouping when the session location differs from the default location #62105

Done

Description

@andycostintoma

Description

When the TUI opens a session whose directory is not the client's default location, /models shows one flat list without provider groups, Favorites or Recent, and its action reads "View all integrations" as if nothing were connected. The integrations dialog in the same session shows the providers as connected.

useConnected() in packages/tui/src/component/use-connected.tsx calls data.location.integration.list() without a location, so it reads the default location's store. LocationProvider only syncs the active location, so when the two differ that store stays empty and useConnected() returns false. The model dialog and the integrations dialog already pass the active location (location.ref); useConnected() doesn't.

I hit it with --server against a remote service: the client's cwd doesn't exist on the server, so the default location falls back to the server's cwd while the session lives in a project directory. The same happens locally with -s <session> for a session in another directory.

Plugins

None needed to reproduce.

OpenCode version

2.2.1 (still present on dev)

Steps to reproduce

  1. Connect any provider, e.g. Anthropic.
  2. Start the service from one directory (cd ~ && opencode service start).
  3. Create a session in a different directory via POST /api/session with {"location":{"directory":"/path/to/project"}}.
  4. From a directory that isn't that project (or from another machine with --server), run opencode -s <session-id>.
  5. Open /models: flat list, "View all integrations". Open the integrations dialog: providers show as connected.

Screenshot

Not attached; /models renders a single flat list with "View all integrations" as its action.

Operating System

Linux (NixOS / Ubuntu)

Terminal

Reproduces independent of terminal (state bug, not rendering).

Activity

  1. opencodejr commented on Nov 5, 2026

    @opencodejr
    Contributor

    Thanks for the precise steps and root-cause analysis. I could reproduce this on 2.2.1.

    What I did:

    1. Connected a provider (the test harness's simulated provider, connected with an API key).
    2. Created a session through POST /api/session with location.directory set to a directory other than the TUI's cwd.
    3. Opened it with --server <url> -s <session id> from the original directory.
    4. Opened /models.

    The result was one flat list with no provider header, no Favorite action and "View all integrations" as the action. A TUI whose session is in its own directory, on the same service, shows the provider group, "Connect an integration" and "Favorite". The first screenshot below shows that baseline, the second shows the problem, and the recording and script below cover the whole run.

    It still happens on the latest dev (187486e), where useConnected() still calls data.location.integration.list() without the active location.

    Related:

    recording.mp4

    Screenshot

    Screenshot

    Reproduction script (drive.ts)
    // Repro for #62105: /models loses provider groups when the TUI opens a session
    // whose directory differs from the TUI's default location.
    // Drive launches OpenCode through a small wrapper that appends `-s <session>` to the
    // second TUI, i.e. `opencode -s <id>` run from a directory other than the session's.
    // OC_DEV=/path/to/checkout runs the CLI from source instead of `opencode2` on PATH.
    import { Effect } from "effect"
    import { OpenCodeDriver } from "opencode-drive"
    import { mkdirSync, writeFileSync, rmSync, readFileSync, readdirSync } from "node:fs"
    import { join } from "node:path"
    
    const SESS = "/tmp/opencode/repro-session"
    const OTHER = "/tmp/opencode/otherproj"
    const WRAPPER = "/tmp/opencode/opencode-wrapper.sh"
    const REAL = process.env.OC_DEV
      ? `${process.execPath} --conditions=browser --preload=${process.env.OC_DEV}/packages/tui/node_modules/@opentui/solid/scripts/preload.js ${process.env.OC_DEV}/packages/cli/src/index.ts`
      : "opencode2"
    mkdirSync("/tmp/opencode", { recursive: true })
    writeFileSync(
      WRAPPER,
      `#!/bin/sh
    case " $* " in
      *" --server "*) if [ -s ${SESS} ]; then exec ${REAL} "$@" -s "$(cat ${SESS})"; fi ;;
    esac
    exec ${REAL} "$@"
    `,
      { mode: 0o755 },
    )
    rmSync(SESS, { force: true })
    
    export default OpenCodeDriver.use(
      {
        opencode: { command: [WRAPPER] },
        project: { git: true, files: { "README.md": "project\n" } },
      },
      ({ tuis, artifacts, ui: primary }) =>
        Effect.gen(function* () {
          mkdirSync(OTHER, { recursive: true })
          // service endpoint registered by the isolated OpenCode service
          const dir = join(artifacts, "home/.local/state/opencode")
          const reg = JSON.parse(readFileSync(join(dir, readdirSync(dir).find((f) => /^service.*\.json$/.test(f))!), "utf8"))
          const api = (path: string, init: RequestInit = {}) =>
            Effect.promise(async () => {
              const res = await fetch(new URL(path, reg.url), {
                ...init,
                headers: {
                  "content-type": "application/json",
                  "x-opencode-directory": encodeURIComponent(join(artifacts, "files")),
                  ...(reg.password ? { authorization: "Basic " + btoa(`${reg.username ?? "opencode"}:${reg.password}`) } : {}),
                },
              })
              const text = await res.text()
              return { status: res.status, text }
            })
          yield* Effect.log(JSON.stringify(reg))
          const ints = yield* api("/api/integration")
          yield* Effect.log(ints.status + " " + JSON.stringify(JSON.parse(ints.text).data.map((i: any) => [i.id, i.connections.length, i.methods.map((m: any) => m.type).join("/")])))
          if (process.env.SKIP) return
          // 1. connect a provider with a (fake) API key
          yield* Effect.log(JSON.stringify(yield* api(`/api/integration/${process.env.INTEGRATION ?? "simulation"}/connect/key`, { method: "POST", body: JSON.stringify({ key: "sk-fake" }) })))
          // baseline: the primary TUI (session in its own default location) shows grouped /models
          yield* Effect.sleep(1500)
          yield* primary.type("/models")
          yield* Effect.sleep(800)
          yield* primary.enter()
          yield* Effect.sleep(2500)
          yield* primary.screenshot("baseline-models-default-location")
          yield* primary.press("escape")
          // 2. create a session in a different directory
          const created = yield* api("/api/session", { method: "POST", body: JSON.stringify({ location: { directory: OTHER } }) })
          yield* Effect.log(created.text)
          const session = JSON.parse(created.text).data
          writeFileSync(SESS, session.id)
          yield* Effect.log(`session ${session.id} in ${OTHER}`)
          // 3. open a TUI on that session (`opencode -s <id>` from the project dir)
          const t = yield* tuis.launch({ recording: true, keypressOverlay: true })
          const ui = t.ui
          yield* Effect.sleep(3000)
          yield* t.recording!.mark("TUI opened with -s <session in another directory>")
          yield* ui.screenshot("session")
          // 4. /models
          yield* t.recording!.mark("/models")
          yield* ui.type("/models")
          yield* Effect.sleep(800)
          yield* ui.enter()
          yield* Effect.sleep(2500)
          yield* ui.screenshot("models")
          yield* ui.press("escape")
          yield* Effect.sleep(800)
          // 5. integrations dialog for comparison
          yield* t.recording!.mark("integrations dialog")
          yield* ui.type("/connect")
          yield* Effect.sleep(800)
          yield* ui.enter()
          yield* Effect.sleep(2500)
          yield* ui.screenshot("integrations")
          yield* ui.press("escape")
          yield* Effect.sleep(500)
        }),
    )

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions