Skip to content

fix(sdk): avoid implicit directory filtering on /session list#20361

Open
OverHash wants to merge 1 commit intoanomalyco:devfrom
OverHash:fix/tui-worktree-list-sessions
Open

fix(sdk): avoid implicit directory filtering on /session list#20361
OverHash wants to merge 1 commit intoanomalyco:devfrom
OverHash:fix/tui-worktree-list-sessions

Conversation

@OverHash
Copy link
Copy Markdown

Keep x-opencode-directory as a header for GET /session unless callers explicitly set a directory query so worktree and subdirectory users still see project sessions.

A regression test that reproduces SDK session listing from a nested directory against the in-memory server was added, which is how I worked on the minimal fix.

Issue for this PR

Closes #20238

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

I've described more in-depth my investigation at the linked issue, so that is a good reference read. The TL:DR is that OpenCode 1.3.4 and onwards filters session list to be at the exact directory you are at, while not allowing sub-directory sessions. This was a helpful behavior in v1.3.3 and before that allowed Git worktree users to see all OpenCode sessions for their projects.

The behavior broke because TUI calls like sdk.session.list() (with no explicit directory filter) accidentally became GET /session?directory=<cwd>, which hid root/worktree siblings.

Fixed by making GET /session keep the x-opencode-directory header, but not rewrite to force the ?directory=... filter. If the filter is explicitly provided, it will remain.

How did you verify your code works?

I ran OPENCODE_DB="$(opencode db path)" bun dev "/Users/<me>/projects/<sample-project>" (needed to use my existing sessions; so used the true DB I have) and it now displays all my sessions.

I also checked via bun test that nothing else was broken.

Screenshots / recordings

N/A -- bug fix.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Keep x-opencode-directory as a header for GET /session unless callers explicitly set a directory query so worktree and subdirectory users still see project sessions. Add a regression test that reproduces SDK session listing from a nested directory against the in-memory server.
@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found several related PRs addressing similar session listing and directory scoping issues:

Potentially Related PRs:

  1. PR fix: scope session list and children to current worktree #13960 - fix: scope session list and children to current worktree

    • Addresses the same core issue of scoping sessions to worktrees
  2. PR fix(session): scope session list and TUI to current directory #14489 - fix(session): scope session list and TUI to current directory

    • Similar fix for directory-scoped session listings
  3. PR fix(session): scope session list to current directory to prevent cross-worktree leakage #16827 - fix(session): scope session list to current directory to prevent cross-worktree leakage

    • Another attempt at resolving cross-worktree session visibility
  4. PR feat(cli): add -a global mode for session list #15178 - feat(cli): add -a global mode for session list

    • Related feature for controlling session list filtering behavior
  5. PR fix: remove 30-day limit from TUI session list #20341 - fix: remove 30-day limit from TUI session list

    • Recent PR also modifying session list behavior

Note: These appear to be historical attempts at solving the worktree/directory session visibility problem. PR #20361 seems to provide the proper fix by handling the x-opencode-directory header correctly rather than implicitly converting it to a query parameter.

@OverHash
Copy link
Copy Markdown
Author

There's other PRs that are actually already solved by the change in the commit I linked in the issue. However, this PR restores the behavior to OpenCode v1.3.3 and below.

The change wasn't documented in the changelog, so I assume it was a bug, and this PR is merely restoring the original behavior that has always existed in OpenCode.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Session list missing in TUI mode

1 participant