Skip to content

Regression: message navigation jumps to wrong lines after #490 (session tabs) #495

Description

@wzj-zz

Description

After updating opencode.nvim from 5e89ef9 to 6071fe7, the output-window message navigation actions (prev_message, next_message, prev_user_message, next_user_message) intermittently jump to the wrong place — the cursor lands on a wrong line/message instead of the message adjacent to the current position. Before the update navigation was always accurate.

I bisected by pinning: the problem is gone when pinned to b629972 (the commit immediately before #490) and present at 6071fe7 (#490 "Wip/session tabs"), so the session-tabs rework is the likely culprit.

Suspected cause

From reading the diff of #490, renderer.on_session_changed gained an early return:

function M.on_session_changed(_, new, old)
  if state.active_session_tab ~= rendered_session_tab then
    return
  end
  ...

If state.active_session_tab and the renderer-local rendered_session_tab get out of sync (e.g. session_tabs clears the active tab via store.set_raw('active_session_tab', nil), which does not fire the store subscription), the renderer skips re-rendering on session change. The output buffer and render_state line numbers then still describe the previous session while state.messages holds the new one, so navigation targets computed from render_state:get_message(id).line_start land on stale/wrong lines.

Possibly also related to the renderer context snapshot/restore (ctx:snapshot() / ctx:restore()) added in the same PR.

Steps to reproduce

Intermittent ("sometimes"). In my usage it shows up in longer sessions, seemingly more often after switching sessions via the session tree and scrolling up into older messages:

  1. Open the opencode windows with a long session (enough messages to trigger lazy rendering)
  2. Switch between sessions and/or scroll up into older messages
  3. Trigger prev_user_message / prev_message repeatedly
  4. Occasionally the cursor lands on a wrong line instead of the previous message

Environment

  • Neovim version: 0.12.2
  • OpenCode version: 1.18.29
  • opencode.nvim version or commit: broken at 6071fe7; works at b629972 and 5e89ef9
  • OS: Windows 11

Configuration

opencode.nvim configuration

Relevant keymaps (the behavior is also reproducible with the default [[ / [u mappings):

require('opencode').setup({
  keymap = {
    output_window = {
      ['<C-p>'] = { 'prev_message', desc = 'Prev message' },
      ['<M-p>'] = { 'prev_user_message', desc = 'Prev user message' },
    },
  },
})

Logs and screenshots

Happy to capture debug logs if you tell me what to enable.

Checklist

  • I have searched existing issues.
  • I have included all relevant details.
  • I have removed sensitive information from configs and logs.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions