Skip to content

fix: normalize Windows drive letter casing in extractCwd#126

Merged
matt1398 merged 2 commits intomainfrom
fix/windows-drive-letter-casing
Mar 23, 2026
Merged

fix: normalize Windows drive letter casing in extractCwd#126
matt1398 merged 2 commits intomainfrom
fix/windows-drive-letter-casing

Conversation

@matt1398
Copy link
Owner

@matt1398 matt1398 commented Mar 23, 2026

CLI uses uppercase (C:...) while VS Code extension uses lowercase (c:...), causing sessions from the same project to be split into different groups.

Fixes #123

Summary by CodeRabbit

  • Bug Fixes
    • Improved file path consistency by normalizing Windows drive-letter casing so CLI and editor path comparisons behave reliably on Windows.
  • Tests
    • Made test cleanup more robust by adding retry behavior to temporary-directory removal to reduce flaky failures.

CLI uses uppercase (C:\...) while VS Code extension uses lowercase (c:\...),
causing sessions from the same project to be split into different groups.

Fixes #123

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 23, 2026 03:31
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves an inconsistency in how Windows drive letters are handled, specifically between the CLI and VS Code extension, which previously caused project sessions to be miscategorized. By introducing a path normalization utility that forces drive letters to uppercase, the change ensures that current working directories are consistently represented, thereby correctly grouping related sessions.

Highlights

  • Drive Letter Normalization: Introduced a new utility function, normalizeDriveLetter, to ensure consistent casing for Windows drive letters (e.g., C: vs c:).
  • extractCwd Enhancement: Modified the extractCwd function to utilize normalizeDriveLetter, ensuring that the returned current working directory always has an uppercase drive letter.
  • Session Grouping Fix: Addressed an issue where inconsistent drive letter casing between CLI and VS Code extension led to sessions from the same project being incorrectly split into different groups.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a function to normalize Windows drive letter casing, addressing an issue where different casings caused session splitting. The implementation is straightforward, but the normalization logic should be specific to the Windows platform to prevent unintended side effects on other operating systems. I've provided a suggestion to add a platform check to the normalization function.

* CLI uses uppercase (C:\...) while VS Code extension uses lowercase (c:\...).
*/
function normalizeDriveLetter(p: string): string {
if (p.length >= 2 && p[1] === ':') {

Choose a reason for hiding this comment

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

medium

This logic correctly normalizes Windows drive letters, but it will also run on other platforms like macOS and Linux. This could lead to unintended behavior if a path on a non-Windows system happens to match the pattern (e.g., c:foo/bar). Since this normalization is specific to Windows pathing conventions, it's safer to guard this logic to only execute on Windows by checking process.platform === 'win32'. The process object is globally available in Node.js, so no import is needed.

Suggested change
if (p.length >= 2 && p[1] === ':') {
if (process.platform === 'win32' && p.length >= 2 && p[1] === ':') {

@coderabbitai coderabbitai bot added the bug Something isn't working label Mar 23, 2026
Windows may hold file handles briefly after stream close, causing
ENOTEMPTY on rmSync. Adding maxRetries with retryDelay resolves this.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses Windows-specific session grouping issues by normalizing drive-letter casing when extracting cwd from session JSONL files, ensuring sessions from the same project don’t split into separate groups due to C:\... vs c:\....

Changes:

  • Add a helper to normalize Windows drive letters to uppercase.
  • Apply drive-letter normalization to the cwd returned by extractCwd().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

* CLI uses uppercase (C:\...) while VS Code extension uses lowercase (c:\...).
*/
function normalizeDriveLetter(p: string): string {
if (p.length >= 2 && p[1] === ':') {
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

normalizeDriveLetter() currently uppercases the first character of any string whose second character is ':'. This will also match non-Windows strings like 'a:b' (valid relative path on POSIX) and could mutate a real cwd on case-sensitive filesystems. Consider tightening the check to only treat Windows drive prefixes (e.g., /^[A-Za-z]:/ and optionally requiring a following path separator).

Suggested change
if (p.length >= 2 && p[1] === ':') {
if (process.platform === 'win32' && p.length >= 2 && /^[A-Za-z]:/.test(p)) {

Copilot uses AI. Check for mistakes.
Comment on lines 59 to 63
if ('cwd' in entry && entry.cwd) {
rl.close();
fileStream.destroy();
return entry.cwd;
return normalizeDriveLetter(entry.cwd);
}
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

This change alters extractCwd() behavior on Windows-style paths by normalizing the drive letter casing, but there is no test asserting that sessions with 'c:\...' and 'C:\...' are grouped together (and not split) during discovery. Adding a focused unit test (e.g., in ProjectScanner.cwdSplit.test.ts and/or ProjectPathResolver.test.ts) would prevent regressions.

Copilot uses AI. Check for mistakes.
@coderabbitai
Copy link

coderabbitai bot commented Mar 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d13a8c4e-8f0e-40e1-b9e5-c17235a58e33

📥 Commits

Reviewing files that changed from the base of the PR and between 7f5fbda and c5d3372.

📒 Files selected for processing (1)
  • test/main/services/discovery/SessionSearcher.test.ts
✅ Files skipped from review due to trivial changes (1)
  • test/main/services/discovery/SessionSearcher.test.ts

📝 Walkthrough

Walkthrough

Normalize Windows drive-letter casing by uppercasing the drive letter in extracted cwd values; tests updated to retry rm on cleanup.

Changes

Cohort / File(s) Summary
Path Normalization
src/main/utils/metadataExtraction.ts
Added non-exported normalizeDriveLetter(p: string) and updated extractCwd(...) to return the normalized cwd (uppercased Windows drive letter).
Tests — cleanup retry
test/main/services/discovery/SessionSearcher.test.ts
Adjusted afterEach cleanup to call fs.rmSync with maxRetries: 3 and retryDelay: 100 in addition to existing recursive: true and force: true options.

Possibly related issues

  • #123: [BUG] Some sessions are missing due to inconsistent drive letter casing in cwd on Windows — This PR implements drive-letter normalization in extractCwd, addressing the reported inconsistency.
  • WSL project paths decode to /mnt/d/... instead of D:\ on Windows #118 — Related (same file touched) but not addressed: that issue requests WSL /mnt/xX:/ translation, which this PR does not implement.
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR normalizes Windows drive-letter casing in extractCwd to ensure consistent path comparison across CLI and VS Code extension sources [#123], directly addressing session grouping discrepancies.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing Windows drive-letter casing: normalizeDriveLetter helper, extractCwd return value normalization, and test retry configuration for cleanup stability.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7f5fbdab09

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

rl.close();
fileStream.destroy();
return entry.cwd;
return normalizeDriveLetter(entry.cwd);

Choose a reason for hiding this comment

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

P2 Badge Add migration for persisted project IDs after cwd normalization

For Windows users upgrading from a build that already indexed the same repo as separate c:\.../C:\... subprojects, returning a normalized cwd here changes the derived projectId on the next scan (often from composite IDs back to the plain encoded dir, or at least to a different hash). That breaks any state keyed by the old ID: pinned/hidden sessions are stored under the exact projectId in src/main/services/infrastructure/ConfigManager.ts:749-858, and restored selection/tabs are dropped when contextSlice no longer finds the saved ID in src/renderer/store/slices/contextSlice.ts:82-101. Without an alias/migration, affected users silently lose pins/hidden state and reopened tabs after upgrading.

Useful? React with 👍 / 👎.

@matt1398 matt1398 merged commit f6783c7 into main Mar 23, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Some sessions are missing due to inconsistent drive letter casing in cwd on Windows

2 participants