GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(tui): scope non-git sessions by directory, not hierarchical path by malventano · Pull Request #31210 · anomalyco/opencode

Conversation

@malventano

@malventano malventano commented Jun 7, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Issue for this PR

Closes #8836, Closes #18890, Closes #19340, Closes #26099, Closes #28972, Closes #9881

Type of change

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

What does this PR do?

PR #24849 introduced hierarchical path filtering (eq(path, X) OR like(path, X + "/%")) for git repos to support worktrees. But non-git projects set worktree = "/" (a truthy value), so the TUI's sessionListQuery() check !worktree never triggered — it fell through to the path branch instead.

path.relative("/", "<parent>") → "<parent>" then matched ALL sessions under that parent hierarchically, including sessions from unrelated subdirectories.

Changes:

  1. packages/tui/src/context/sync.tsx: Check worktree === "/" explicitly and return { directory } for non-git projects so the server's existing eq(directory) fallback is used.
  2. packages/opencode/src/cli/cmd/session.ts: Pass directory: process.cwd() to CLI session list so it's also scoped.

The server already has the else if (scope !== "project") fallback that performs eq(directory, ...) matching - no server changes needed. Git repo hierarchical filtering is untouched.

Security impact

This is not only a listing/filtering annoyance. Because subdir sessions surface at the parent, opencode -c from the parent reopens the most recently closed child session (started in a subdir) under the parent's pwd. The session's stored context/history assumes the subdir scope, but the process now runs with the parent's working directory and filesystem access. This effectively bypasses the external_directory security setting for that session, since tool calls execute against the broader parent tree instead of the subdir the session was authored in.

The broader the parent, the wider the unintended access. A session intended for a nested subdirectory would, reopened from its parent, be free to read/edit any sibling under that parent.

This PR restores exact eq(directory) matching for non-git projects, so subdir sessions no longer surface at the parent and cannot be reopened outside their original directory scope.

How did you verify your code works?

Tested locally with a local build:

  • TUI session list from a non-git directory shows only sessions from that directory
  • CLI session list from a non-git directory shows only sessions from that directory
  • Git repo sessions continue to use hierarchical path filtering as intended by feat(core): filter sessions by path and add setting to disable #24849

Screenshots / recordings

N/A - not a UI change.

Checklist

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mtt0 and samiralibabic reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
@malventano
fix(tui): scope non-git sessions by directory, not hierarchical path
c6e0cf9
PR #24849 introduced hierarchical path filtering for git repos. But non-git
projects set worktree = "/" (truthy), so sessionListQuery() never triggered
the !worktree fallback and fell through to the path branch instead.

path.relative("/", "/root/oc") -> "root/oc" then matched ALL sessions
under /root/oc/ hierarchically, including sessions from unrelated
subdirectories.

Fix:
- sync.tsx: check worktree === "/" explicitly, return { directory } for
  non-git projects so server-side eq(directory) matching is used
- session.ts: pass directory: process.cwd() to CLI session list

Closes #8836, Closes #18890, Closes #19340, Closes #26099, Closes #28972, Closes #9881
@github-actions

github-actions Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

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

Potential Duplicates Found

PR #29026 - fix(tui): scope session list to current worktree directory

  • fix(tui): scope session list to current worktree directory #29026
  • Why related: Directly addresses the same issue of scoping session lists to the current directory/worktree, which is the core fix in PR fix(tui): scope non-git sessions by directory, not hierarchical path #31210.

PR #29582 - fix(tui): show home sessions in global project

  • fix(tui): show home sessions in global project #29582
  • Why related: Related to session scoping and filtering logic in the TUI.

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

  • fix(sdk): avoid implicit directory filtering on /session list #20361
  • Why related: Addresses similar directory filtering issues on session list endpoints.

PR #29539 - fix(tui): handle non-git project paths in autocomplete and session fi…

  • fix(tui): handle non-git project paths in autocomplete and session fi… #29539
  • Why related: Specifically handles non-git project path handling in session-related features.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@malventano

malventano commented Jun 7, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Author

This PR focuses on non-git directory filtering, restoring the behavior to what it was pre-#24849 (while not impacting that PR's intent for git repos). The 4 potential duplicates address different problems:

  • fix(tui): scope session list to current worktree directory #29026 (scope session list to current worktree directory) - Git worktrees. Sends directory + path for git repos and adds a UI toggle. Still has the same !worktree bug for non-git (worktree = "/" is truthy) - doesn't fix that case.

  • fix(tui): show home sessions in global project #29582 (show home sessions in global project) - Different edge case. When launched from home, the global project reports worktree = "/" and filters hide older home sessions stored with empty path. Not related to non-git directory filtering.

  • fix(sdk): avoid implicit directory filtering on /session list #20361 (avoid implicit directory filtering on /session list) - Opposite direction. Wants to relax filtering so worktree users see project sessions from nested directories. This PR tightens filtering for non-git.

  • fix(tui): handle non-git project paths in autocomplete and session fi… #29539 (handle non-git project paths in autocomplete and session filter) - Catches the same worktree === "/" but only returns { scope: "project" } (no filtering). This PR returns { directory } which actually enables exact directory filtering for non-git. It also fixes CLI session list. fix(tui): handle non-git project paths in autocomplete and session fi… #29539 and this are complementary - fix(tui): handle non-git project paths in autocomplete and session fi… #29539 fixes autocomplete, this fixes session list filtering and CLI.

All 4 remain open. None supersede this fix.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@malventano malventano mentioned this pull request Jun 7, 2026
feat(core): filter sessions by path and add setting to disable #24849
Merged
3 of 6 tasks
@malventano

malventano commented Jun 11, 2026

Copy link
Copy Markdown
Author

Looks like #30804 partially addresses the issue, but this PR is still needed to correctly address path scope for non-git sessions.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@malventano
Merge branch 'dev' into fix/session-directory-filter
ad09156
@github-actions github-actions Bot mentioned this pull request Jun 12, 2026
📊 AI CLI 工具社区动态日报 2026-06-12 zx0828/big_model_radar#109
Open
@malventano
Merge branch 'dev' into fix/session-directory-filter
d4824b8
This was referenced Jun 18, 2026
feat(tui): add directory + project session filter modes #32855
Closed
fix(opencode): scope --continue to the current worktree directory #33521
Closed
@malventano

malventano commented Jul 2, 2026

Copy link
Copy Markdown
Author

Updated this PR to include text about the vulnerability it also corrects.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@malventano

malventano commented Jul 2, 2026

Copy link
Copy Markdown
Author

For reviewers: #34842 is a server-side complement to this PR, not a replacement.

  • This PR (fix(tui): scope non-git sessions by directory, not hierarchical path #31210) fixes the TUI client. sessionListQuery() was sending the wrong query shape for non-git projects (worktree = "/" is truthy), so subdir sessions leaked into parent listings. The fix sends { directory } for exact eq(directory) matching instead of falling into the hierarchical path branch.
  • fix(opencode): filter session list by resolved instance directory #34842 fixes the server. The directory query param was passed through verbatim without resolving it against InstanceState.directory, so path separator differences (e.g. trailing path.sep) could cause eq(directory) matches to miss sessions that should have matched. The fix resolves the query through InstanceState.directory before matching.

Both are needed. This PR ensures the client sends the right query shape; #34842 ensures the server normalizes the directory value before comparing. Neither alone closes the full bug.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Jul 23, 2026
fix(session): scope default lists by directory #38532
Closed
3 of 6 tasks
@samiralibabic

samiralibabic commented Jul 27, 2026

Copy link
Copy Markdown

#38532 is the current-dev alternative for #38529. It adds automated CLI/TUI query regression coverage and intentionally applies exact-directory default filtering in both Git and non-Git contexts; this PR preserves hierarchical Git filtering. Linking the two so maintainers can choose the intended default behavior.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Aug 2, 2026
fix(server): isolate sessions per-worktree — require an explicit directory #40143
Closed
@malventano

malventano commented Aug 9, 2026

Copy link
Copy Markdown
Author

closed due to no action by devs

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@malventano malventano closed this Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Hierarchical session filter from #24849 has no exact-match mode; -c from parent dir picks wrong child session and widens permission scope Regression: /sessions command no longer filters by current working directory Sessions from different non-git directories are mixed when using --continue [FEATURE]: Filter TUI session list by current directory/worktree session list is showing all sessions not only the ones scopes to the curent dir
session list and TUI expose non-git/global sessions that can resume with wrong cwd

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@malventano @samiralibabic
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.