Skip to content

Fix Codex WSL project trust conflating case-distinct Linux paths - #8333

Merged
AmethystLiang merged 5 commits into
mainfrom
fix-f1-codex-wsl-path-trust
Jul 12, 2026
Merged

AmethystLiang merged 5 commits into
mainfrom
fix-f1-codex-wsl-path-trust

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Problem

normalizeCodexProjectPathForLookup in src/main/codex/config-toml-trust.ts lowercased the entire Windows/UNC-shaped path — including the Linux path segment under \\wsl$\<distro>\.... That correctly merges Windows drive-letter spellings, but it conflated two case-distinct Linux directories under a WSL UNC share (e.g. .../Repo and .../repo) onto one project trust key. The mirror dedupe in codex-config-mirror.ts (getTomlSectionHeaderKey) uses that same key, so it inherited the bug.

Fix

normalizeCodexProjectPathForLookup now splits WSL UNC paths at the case-insensitive Windows share prefix (\\wsl$\<distro> / \\wsl.localhost\<distro>):

  • The share prefix (scheme + distro) is lowercased — Windows matches it case-insensitively, so separator/distro-casing variants of the same path still merge.
  • The Linux path underneath is preserved verbatim — it is case-sensitive, so distinct dirs stay distinct.
  • True Windows drive letters and normal UNC shares still case-fold exactly as before.

Minimal diff: one function reworked plus a small matchWslUncSharePrefix helper.

Tests

src/main/codex/config-toml-trust.test.ts:

  • Unit describe('normalizeCodexProjectPathForLookup') proving: C:\repo ≡ c:/repo; \\wsl$\Ubuntu\home\u\Repo ≠ \\wsl$\Ubuntu\home\u\repo; separator/distro-casing variants of the same WSL path merge; wsl.localhost behaves like wsl$; normal UNC still case-folds; POSIX paths untouched.
  • Integration test proving upsertProjectTrustLevelInContent keeps case-distinct WSL Linux paths as two separate [projects.*] blocks.

pnpm vitest run config-toml-trust codex-config-mirror → 122 passed / 3 skipped. Oxlint clean; typecheck clean (only pre-existing unrelated typescript-api module errors). CRLF header repair (#8197) and hook-path trust (#8191) tests unaffected.

Made with Orca 🐋

@coderabbitai

coderabbitai Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: beca5ba4-97d5-48dc-967e-4fe1214385eb

📥 Commits

Reviewing files that changed from the base of the PR and between aff1459 and 16b12ce.

📒 Files selected for processing (7)
  • src/main/codex/codex-config-mirror.test.ts
  • src/main/codex/codex-config-mirror.ts
  • src/main/codex/config-toml-trust.test.ts
  • src/main/codex/config-toml-trust.ts
  • src/main/codex/hook-service.ts
  • src/shared/wsl-paths.test.ts
  • src/shared/wsl-paths.ts

📝 Walkthrough

Walkthrough

Project trust normalization now handles WSL UNC paths by normalizing share aliases, distro casing, separators, and drvfs prefixes while preserving Linux-tail case where required. Revocation lookup uses separate drift-tolerant normalization, and configuration mirroring preserves trusted entries while applying matching revocations. Hook trust lookup and WSL reconciliation use the same normalized path keys. Tests cover Windows, UNC, WSL, drvfs, POSIX, trust, revocation, and mirror behavior.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the problem, fix, and tests, but it omits several required template sections like Screenshots, AI Review Report, Security Audit, and Notes. Add the missing template sections with a brief user-facing Summary, Screenshots note, AI Review Report, Security Audit, and Notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: fixing WSL project trust handling for case-distinct Linux paths.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6203e718-c282-483a-8a13-6285e6fd03c2

📥 Commits

Reviewing files that changed from the base of the PR and between 3c4518a and 1620e7f.

📒 Files selected for processing (2)
  • src/main/codex/config-toml-trust.test.ts
  • src/main/codex/config-toml-trust.ts

@AmethystLiang

Copy link
Copy Markdown
Contributor Author

Follow-up: extended the fix to hook-trust key lookup

Per review, normalizeHookTrustKeyForLookup had the identical latent bug: on a win32 host it lowercased the whole Windows-shaped path, folding the case-sensitive Linux tail of a \\wsl$\<distro> UNC hook path — directly contradicting its own comment that WSL sources stay case-sensitive even on a Windows host. (The pre-existing test only covered POSIX-shaped /windows/... keys, which never enter the folding branch, so this was uncaught.)

Both normalizers now share one helper, foldWindowsCaseInsensitivePath, which folds only the case-insensitive drive-letter / \\wsl$ / \\wsl.localhost share prefix and preserves the Linux tail. The hook key's event:group:handler suffix is already lowercase, so there's no behavior change there.

Added a win32-gated readHookTrustEntries test proving two case-distinct WSL UNC hook sources (.../Repo vs .../repo) stay as separate trust rows while distro-casing/separator variants of the same path still fold to one key.

Not changed — normal UNC (\\server\share\...) still fully case-folds. A Linux Samba share is technically case-sensitive too, but there is no way to tell from the path shape, and Windows/Codex convention treats UNC as case-insensitive (encoded in the existing "server UNC merges" test). Folding it would break the common Windows-share case, so it's intentionally left as-is.

Full src/main/codex suite: 234 passed / 9 skipped. Oxlint + typecheck clean.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (2)
src/main/codex/codex-config-mirror.ts (1)

292-300: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract shared logic between getTomlSectionHeaderKey and getRevocationTomlSectionHeaderKey.

Both functions (Lines 285-289 and 292-299) are structurally identical except for the normalization function passed in. Consolidating into one parameterized helper removes the duplication and prevents the two from drifting out of sync if the header-parsing logic changes later.

♻️ Proposed refactor
+function buildProjectTomlSectionHeaderKey(
+  header: string,
+  normalize: (projectPath: string) => string
+): string {
+  const projectPath = parseCodexProjectHeaderPath(header)
+  return projectPath === null ? header.trim() : `project:${normalize(projectPath)}`
+}
+
 function getTomlSectionHeaderKey(header: string): string {
-  const projectPath = parseCodexProjectHeaderPath(header)
-  return projectPath === null
-    ? header.trim()
-    : `project:${normalizeCodexProjectPathForLookup(projectPath)}`
+  return buildProjectTomlSectionHeaderKey(header, normalizeCodexProjectPathForLookup)
 }

 // Why: configs written before WSL tails compared case-sensitively can hold a
 // revocation under drifted casing; match it loosely so trust is not resurrected.
 function getRevocationTomlSectionHeaderKey(header: string): string {
-  const projectPath = parseCodexProjectHeaderPath(header)
-  return projectPath === null
-    ? header.trim()
-    : `project:${normalizeCodexProjectPathForRevocationLookup(projectPath)}`
+  return buildProjectTomlSectionHeaderKey(header, normalizeCodexProjectPathForRevocationLookup)
 }
src/main/codex/codex-config-mirror.test.ts (1)

447-497: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Strengthen assertions to verify header/trust_level pairing, not just presence.

Both new tests check toContain('trust_level = "trusted"') and toContain('trust_level = "untrusted"') independently of which [projects...] block they belong to. If the merge logic ever attached the wrong trust level to the wrong block (e.g. swapped trusted/untrusted between the drifted-case and exact-case headers), these assertions would still pass. Test 1 (Lines 425-445) avoids this by using not.toContain, but tests 2 and 3 don't pin the value to its header.

♻️ Suggested stronger assertion for the re-trust test (Lines 472-476)
     const runtimeConfig = readFileSync(getRuntimeConfigPath(), 'utf-8')
-    expect(runtimeConfig).toContain("[projects.'\\\\wsl$\\Ubuntu\\home\\u\\Repo']")
-    expect(runtimeConfig).toContain('trust_level = "trusted"')
-    expect(runtimeConfig).toContain('trust_level = "untrusted"')
+    const repoIdx = runtimeConfig.indexOf("[projects.'\\\\wsl$\\Ubuntu\\home\\u\\Repo']")
+    expect(repoIdx).toBeGreaterThanOrEqual(0)
+    expect(runtimeConfig.slice(repoIdx, repoIdx + 120)).toContain('trust_level = "trusted"')
+    expect(runtimeConfig).toContain('trust_level = "untrusted"')

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f6fab642-ee8d-4311-91fa-44877dada9b6

📥 Commits

Reviewing files that changed from the base of the PR and between 41ed989 and aff1459.

📒 Files selected for processing (7)
  • src/main/codex/codex-config-mirror.test.ts
  • src/main/codex/codex-config-mirror.ts
  • src/main/codex/config-toml-trust.test.ts
  • src/main/codex/config-toml-trust.ts
  • src/main/codex/hook-service.ts
  • src/shared/wsl-paths.test.ts
  • src/shared/wsl-paths.ts

AmethystLiang and others added 5 commits July 12, 2026 00:36
normalizeCodexProjectPathForLookup lowercased the entire Windows/UNC
path, including the case-sensitive Linux portion under \\wsl$\<distro>.
Two distinct WSL project dirs (.../Repo vs .../repo) collapsed onto one
trust key, and the mirror dedupe (codex-config-mirror) inherited it.

Preserve case for the Linux path after the case-insensitive
\\wsl$\<distro> / \\wsl.localhost\<distro> share prefix; true Windows
drive letters and normal UNC shares still case-fold as before.

Co-authored-by: Orca <[email protected]>
normalizeHookTrustKeyForLookup had the identical latent bug: on a win32
host it lowercased the whole Windows-shaped path, folding the
case-sensitive Linux tail of a \\wsl$\<distro> UNC hook path — contrary
to its own comment that WSL sources stay case-sensitive.

Extract foldWindowsCaseInsensitivePath (shared with the project-path
normalizer): fold only the case-insensitive drive/\\wsl$ share prefix,
preserve the Linux tail. Existing suffix (event:group:handler) is already
lowercase, so behavior is unchanged there.

Co-authored-by: Orca <[email protected]>
- Case-drifted or share-spelling-varied WSL revocations were being
  ignored on merge, letting stale "trusted" entries survive; fold
  revocation lookups fully so matching errs toward revoked.
- Hook-trust key folding was gated on process.platform === 'win32',
  so WSL/SSH-remote hook sources weren't folded when Orca itself ran
  on macOS/Linux; fold by path shape instead, via the new shared
  foldWslUncPathCaseInsensitiveParts helper (also covers /mnt drvfs
  automounts and wsl$/wsl.localhost share aliasing).
- Don't fold case-variant `/MNT` dirs as if they were the drvfs
  automount; only literal lowercase `/mnt/<drive>` folds.
- Preserve an exact-cased trusted project entry in ~/.codex during
  runtime merge instead of letting a loosely-matched, case-drifted
  revocation clobber a user's re-granted trust on every mirror pass.
- Minor cleanup: inline foldWindowsCaseInsensitivePath and hoist the
  repeated normalizeHookTrustKeyForLookup call in findTrustBlockRanges.
Extract path variables and assert against escapeTomlString(incomingPath) instead of a hardcoded escaped string literal, so the fixture can't silently drift from the actual TOML header serialization.
@AmethystLiang
AmethystLiang force-pushed the fix-f1-codex-wsl-path-trust branch from aff1459 to 16b12ce Compare July 12, 2026 07:36
@AmethystLiang
AmethystLiang merged commit 6ee81dc into main Jul 12, 2026
1 check failed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…blyai#8333)

* Fix Codex WSL project trust conflating case-distinct Linux paths

normalizeCodexProjectPathForLookup lowercased the entire Windows/UNC
path, including the case-sensitive Linux portion under \\wsl$\<distro>.
Two distinct WSL project dirs (.../Repo vs .../repo) collapsed onto one
trust key, and the mirror dedupe (codex-config-mirror) inherited it.

Preserve case for the Linux path after the case-insensitive
\\wsl$\<distro> / \\wsl.localhost\<distro> share prefix; true Windows
drive letters and normal UNC shares still case-fold as before.

Co-authored-by: Orca <[email protected]>

* Apply the same WSL case-fold fix to hook-trust key lookup

normalizeHookTrustKeyForLookup had the identical latent bug: on a win32
host it lowercased the whole Windows-shaped path, folding the
case-sensitive Linux tail of a \\wsl$\<distro> UNC hook path — contrary
to its own comment that WSL sources stay case-sensitive.

Extract foldWindowsCaseInsensitivePath (shared with the project-path
normalizer): fold only the case-insensitive drive/\\wsl$ share prefix,
preserve the Linux tail. Existing suffix (event:group:handler) is already
lowercase, so behavior is unchanged there.

Co-authored-by: Orca <[email protected]>

* Fix Codex WSL trust revocation and hook-key case folding

- Case-drifted or share-spelling-varied WSL revocations were being
  ignored on merge, letting stale "trusted" entries survive; fold
  revocation lookups fully so matching errs toward revoked.
- Hook-trust key folding was gated on process.platform === 'win32',
  so WSL/SSH-remote hook sources weren't folded when Orca itself ran
  on macOS/Linux; fold by path shape instead, via the new shared
  foldWslUncPathCaseInsensitiveParts helper (also covers /mnt drvfs
  automounts and wsl$/wsl.localhost share aliasing).

* Fix Codex WSL trust key case-folding regressions

- Don't fold case-variant `/MNT` dirs as if they were the drvfs
  automount; only literal lowercase `/mnt/<drive>` folds.
- Preserve an exact-cased trusted project entry in ~/.codex during
  runtime merge instead of letting a loosely-matched, case-drifted
  revocation clobber a user's re-granted trust on every mirror pass.
- Minor cleanup: inline foldWindowsCaseInsensitivePath and hoist the
  repeated normalizeHookTrustKeyForLookup call in findTrustBlockRanges.

* Refactor case-fold WSL trust test to assert real serializer output

Extract path variables and assert against escapeTomlString(incomingPath) instead of a hardcoded escaped string literal, so the fixture can't silently drift from the actual TOML header serialization.

---------

Co-authored-by: Orca <[email protected]>
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.

1 participant