Skip to content

fix(core): normalize session directory lookup separators - #53924

Closed
poijygfdyy wants to merge 20 commits into
anomalyco:devfrom
poijygfdyy:v2-session-separators
Closed

poijygfdyy wants to merge 20 commits into
anomalyco:devfrom
poijygfdyy:v2-session-separators

Conversation

@poijygfdyy

@poijygfdyy poijygfdyy commented Oct 8, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #

Type of change

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

What does this PR do?

Please provide a description of the issue, the changes you made to fix it, and why they work. It is expected that you understand why your changes work and if you do not understand why at least say as much so a maintainer knows how much to value the PR.

If you paste a large clearly AI generated description here your PR may be IGNORED or CLOSED!

How did you verify your code works?

Screenshots / recordings

If this is a UI change, please include a screenshot or recording.

Checklist

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

If you do not follow this template your PR will be automatically rejected.

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Hey! Your PR title V2 session separators doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Oct 8, 2026
@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • No issue referenced. Please add Closes #<number> linking to the relevant issue.
  • "How did you verify your code works?" section is empty. Please explain how you tested.
  • Not all checklist items are checked. Please confirm you have tested locally and have not included unrelated changes.

Please edit this PR description to address the above within 72 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

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

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked this against a live serve from the base and the PR: with the PR, GET /api/session?directory=<dir>/ (and <dir>//) now finds sessions stored as <dir>, so #53735 is fixed. Type check and session-store.test.ts pass, and the new test fails on the base as it should.

One regression: session creation doesn't normalize the directory, so POST /api/session with location.directory: "<dir>/" stores <dir>/. Before this PR, that session could be listed with ?directory=<dir>/. With the PR, the lookup value is trimmed but the saved value isn't, so the session can't be listed under any form of its path (checked live). Trimming only one side of the comparison causes this. Please normalize in one place that covers both saving and lookup (see the inline comment), and extend the test with a session created with a trailing separator.

Comment thread packages/core/src/session/store.ts Outdated
const conditions: SQL[] = []
if ("directory" in input) conditions.push(eq(SessionTable.directory, input.directory))
if ("directory" in input) {
const trimmed = input.directory.replace(/[\\/]+$/, "")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This trims only the lookup value. Session creation saves location.directory as given (canonical leaves it unchanged on POSIX, and path.normalize keeps a trailing separator on Windows). So a session created with directory: "/x/" is saved as /x/, and with this change no query finds it anymore. I checked this live: before the change, ?directory=/x/ returned it.

Normalizing in directoryColumn.toDriver (packages/core/src/database/path.ts) would cover both saving and lookup, because drizzle's eq() passes its value through the column's toDriver. It would also sit next to the existing Windows separator handling. Normalizing where the location is canonicalized would work too.

Smaller point: [\\/]+$ also strips trailing backslashes on Linux and macOS, where \ is a legal file-name character, so it may be worth limiting that to Windows.

@poijygfdyy poijygfdyy changed the title V2 session separators fix(core): normalize session directory lookup separators Oct 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@thdxr
thdxr changed the base branch from v2 to dev October 10, 2026 19:36
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 72-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Oct 11, 2026
@github-actions github-actions Bot closed this Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant