Repository navigation
fix(ai-vault): ignore non-absolute env overrides for agent scan roots - #13118
Conversation
📝 WalkthroughWalkthroughAdded Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: 🔵 Low · up to Valid absolute overrides can cause the new Windows test to fail. Use Node’s absolute-path predicate before merging. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/shared/absolute-dir-override.ts (1)
3-12: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winShorten the helper documentation.
The block comment includes issue history and launch details. Keep the helper contract and the syntactic-validation warning in a concise comment.
As per coding guidelines, comments must be concise, limited to non-obvious information, and preferably one line.
Proposed change
-/** - * Resolve an environment-provided directory override, ignoring non-absolute values. - * - * Why: a relative override (`.`, `..`, `rel/path`, or a drive-relative `C:foo`) resolves against - * the main process cwd — `/` for a Finder- or Dock-launched app — and turns a scan root into an - * unbounded walk of the whole disk (`#13082`). - * - * Note `isAbsolute` is syntactic only: `/..` is absolute and collapses to `/`. That is acceptable - * for read-only discovery, but this helper is not an allowlist check. - */ +/** Return a trimmed absolute override or fallback. This is not an allowlist check. */Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 59cfe6f6-533e-4d62-b371-14d780e2c690
📥 Commits
Reviewing files that changed from the base of the PR and between ce20a10 and f867e237710d997f167b84957a1b60244c687f55.
📒 Files selected for processing (6)
src/main/ai-vault/session-scanner-agent-sources.tssrc/main/ai-vault/session-scanner-kimi-paths.tssrc/shared/absolute-dir-override.test.tssrc/shared/absolute-dir-override.tssrc/shared/grok-session-paths.test.tssrc/shared/grok-session-paths.ts
|
Adding my X handle per CONTRIBUTING: @manuaudiomix |
f867e23 to
ca12914
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
Six scan roots took a directory from an environment variable and used it verbatim. A relative value is resolved by whichever Orca process reads it — main sits at `/` when Finder-launched, the terminal daemon chdirs itself to the user data dir, the AI Vault service inherits main's cwd — so one value names a different directory in each, and walkSessionFiles walks it with no depth cap, no entry cap and no time budget, about once a minute per the session-list cache TTL. The agent CLIs do accept a relative home (verified against real Grok 1.0.30: `GROK_HOME=myhome grok du` creates `<grok-cwd>/myhome`), but they resolve it against their own per-terminal cwd, which no Orca reader shares. Falling back to the default home is therefore not a lost configuration — it replaces an unbounded walk of an arbitrary tree with a bounded read of a known one, and matches what readGrokHomeEnvelope, skill-provider normalizedRoot and absoluteConfiguredDir already do with the same values. Add resolveAbsoluteDirOverride and apply it to CODEX_HOME, COPILOT_HOME, OPENCLAW_STATE_DIR, DEVIN_HOME, KIMI_CODE_HOME and GROK_HOME. It takes an explicit platform so the Windows shapes are provable from a POSIX CI box: `C:\...`, `C:/...` and UNC roots are kept, while the drive-relative `C:foo` and bare `C:` fall back. Tilde expansion stays out of it — Grok creates a literal `~` directory rather than expanding one — so absoluteConfiguredDir keeps its own Pi/Prime-specific expansion and delegates the absolute check. isAbsolute is syntactic only, so `/..` still collapses to `/`. That is fine for read-only discovery; these roots never gate renderer-supplied paths. Tests assert at the call sites, not just on the helper: the four session-scanner-agent-sources roots are module-level consts evaluated at import time, so they are exercised through AI_VAULT_AGENT_SOURCES with vi.stubEnv plus vi.resetModules. Reverting any one of the six call sites fails them (11-33 cases each). Closes stablyai#13082 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
ca12914 to
d9726f7
Compare
|
Picked this up and pushed a rebase + follow-up work to the branch (authorship preserved, @manuaudio). Rebased onto Resolving the "breaks relative-path configs" holdThe review hold said this breaks supported relative-path setups, on the grounds that real Grok accepts a relative Verified with real Grok 1.0.30, then ran Orca's actual The old behaviour only worked when the reading process's cwd happened to equal the Grok CLI's cwd. That is false for every realistic Electron launch — main sits at Also checked the obvious alternative fix: Grok does not expand Four already-merged precedents reject the same values: What I changed on top
Tests proven non-blind — reverting call sites makes them fail: CODEX only → 11 failed; KIMI+GROK → 26 failed; COPILOT+OPENCLAW+DEVIN → 33 failed. All restored. Behaviour delta worth naming
Verification
One correction needed in the PR descriptionIt states that Known accepted gap (documented in the helper): |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 2bc8852a-ea53-43f7-a164-7137be40a1f9
📥 Commits
Reviewing files that changed from the base of the PR and between ca12914cd7c95ef2401818f04fcf36ee319da12f and d9726f7.
📒 Files selected for processing (7)
src/main/ai-vault/session-scanner-agent-root-overrides.test.tssrc/main/ai-vault/session-scanner-agent-sources.tssrc/main/ai-vault/session-scanner-kimi-paths.tssrc/main/ai-vault/session-scanner-values.tssrc/shared/absolute-dir-override.test.tssrc/shared/absolute-dir-override.tssrc/shared/grok-session-paths.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.
| const roots = await rootDirsFor(testCase.agent, { [testCase.envVar]: value }) | ||
| for (const root of roots) { | ||
| expect(root).toBe(join(root)) | ||
| expect(root.startsWith('/') || /^[A-Za-z]:[\\/]/.test(root)).toBe(true) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Use isAbsolute for the root assertion.
On Windows, join('/srv/codex', 'sessions') produces a rooted \srv\... path. Node treats that path as absolute, but line 112 rejects it because it has neither a leading / nor a drive prefix. The absolute-override cases then fail on Windows.
Proposed fix
-import { join } from 'node:path'
+import { isAbsolute, join } from 'node:path'
...
- expect(root.startsWith('/') || /^[A-Za-z]:[\\/]/.test(root)).toBe(true)
+ expect(isAbsolute(root)).toBe(true)
nwparker
left a comment
There was a problem hiding this comment.
Verified: rebased, evidence-backed, full CI green. Approving.
Closes #13082.
Summary
A typo'd or relative agent-home environment variable no longer turns AI Vault session discovery into an unbounded walk of the disk.
Six scan roots took a directory straight from an environment variable and used it verbatim. A relative value (
.,..,rel/path) resolves against the cwd of whichever Orca process reads it — and those cwds deliberately differ: main sits at/when Finder- or Dock-launched, the terminal daemonchdirs itself toORCA_USER_DATA_PATHor/(spawn-preflight.ts), and the AI Vault service isforked with nocwd.walkSessionFilesthen walks that tree with no depth cap, no entry cap and no time budget. The session-list cache TTL is 60s, so it re-runs about once a minute, with each agent's discovery fanned out concurrently against the same disk.What changed
New
resolveAbsoluteDirOverrideinsrc/shared/, applied at all six sites:CODEX_HOMEsession-scanner-agent-sources.tsCOPILOT_HOMEsession-scanner-agent-sources.tsOPENCLAW_STATE_DIRsession-scanner-agent-sources.tsDEVIN_HOMEsession-scanner-agent-sources.tsKIMI_CODE_HOMEsession-scanner-kimi-paths.tsGROK_HOMEshared/grok-session-paths.tsThe helper lives in
src/shared/rather than besidenormalizeAgentSessionsDirbecause the Grok site is itself insrc/shared/and cannot import fromsrc/main/.Note the issue's line numbers had already drifted by the time this was picked up — the four
session-scanner-source-discovery.tssites now live insession-scanner-agent-sources.ts. Same six env vars, same shape.Does this break relative-path configurations?
This was the main review concern, and it deserves a direct answer: real Grok does accept a relative
GROK_HOME— but it resolves it against its own process cwd, which is the terminal's, never a reader's.Verified with real Grok 1.0.30, then by running Orca's actual
resolveGrokSessionsDir/resolveGrokChatHistoryPathSyncagainst a genuine Grok-created relative home (session planted at the exact layout Grok writes,sessions/<encodeURIComponent(cwd)>/<uuid>/chat_history.jsonl), old implementation vs new, from three cwds:The old behaviour only worked when the reading process's cwd happened to equal the Grok CLI's cwd — false for every realistic Electron launch. The configuration being protected is a cwd coincidence, and the cost of preserving it is an unbounded walk of an arbitrary tree.
The obvious alternative fix does not work either: Grok does not expand
~.GROK_HOME='~/x'makes it create a literal~directory under cwd, so adding tilde expansion here would point Orca at a directory no agent writes to. That asymmetry is now documented atabsoluteConfiguredDir, which keeps its Pi/Prime-specific expansion local.Four already-merged precedents reject the same values:
readGrokHomeEnvelope,normalizedRootinskill-provider-runtime-roots.ts(which already ships aGROK_HOME: '../grok'test),absoluteConfiguredDir, andresolveWslGrokSkillProviderRoot.Behaviour delta worth naming
resolveGrokHomeDiralso backs a write path (grok/hook-service.ts→$GROK_HOME/hooks/orca-status.json). With a relativeGROK_HOMEthat write previously targeted<orca-cwd>/.grokhome/...— from a Finder launch,/.grokhome/..., which fails EACCES. It now goes to~/.grok/hooks/: deterministic, writable, and consistent withreadGrokHomeEnvelope, which already refuses a non-absolute hook-reported home. A pre-existing orphan file at the old location is harmless — the managed script is bounded (--connect-timeout 0.5 --max-time 1.5) and exits 0.Screenshots
No visual change.
Testing
pnpm typecheck— exit 0oxlint+pnpm run check:code-quality:changed— 0 new findings across all five gatespnpm test— 2509 passed / 62 skipped across 288 filesFull CI green — 16/16, including
package (windows)and all 8 test shardsAdded or updated high-quality tests that would catch regressions
src/shared/absolute-dir-override.test.ts— covers absolute, whitespace-padded, relative, drive-relative, empty, null and undefined. The helper now takes an explicitplatform(defaulting toprocess.platform, so runtime behaviour is unchanged), which makes the Windows shapes provable from a POSIX box:C:\...,C:/..., UNC\\server\shareand\grokare kept;C:fooand bareC:fall back.src/shared/grok-session-paths.test.ts— asserts a non-absoluteGROK_HOMEis ignored at the call site, not just in the helper.src/main/ai-vault/session-scanner-agent-root-overrides.test.ts— drives all six roots throughAI_VAULT_AGENT_SOURCESwithvi.stubEnv+vi.resetModules, covering the four module-levelconstsites.Verified non-blind by reverting call sites while leaving the helper intact: CODEX only → 11 failed / 73 passed; KIMI + GROK → 26 failed / 79 passed; COPILOT + OPENCLAW + DEVIN → 33 failed / 51 passed. All restored. These catch a helper that exists but isn't wired in, not merely the helper's own logic.
Review
C:fooand a bareC:are not absolute — they resolve against that drive's current directory — and both fall back. All four relative shapes are pinned on both platforms via the injectedplatformparameter. No separator assumptions, no shell behaviour, no accelerators or shortcut labels touched.grokSessionsDir/kimiSessionsDir/openclawStateDirscan options have no production producers (test seams only,session-scanner-test-fixtures.ts), and remote discovery resolves throughremote-session-scanner-sources.ts, which has no grok/env handling. No wire change.isAbsoluteper module load or resolver call.Security
/..is deliberately accepted.isAbsoluteis syntactic only, so/..is absolute and collapses to/. Acceptable here because these six feed read-only discovery and never gate renderer-supplied paths — onlyclaudeProjectsRootDirsandompSessionsRootDirsdo that. The helper's doc comment says so explicitly so nobody later mistakes it for an allowlist check. If it ever needs to gate a renderer-supplied path, it needs real containment checking, notisAbsolute.Notes
The
AiVaultScanIssuenotice. Issue #13082 notes that falling back silently makes a typo'd override look like it worked, and suggests surfacing akind: 'notice'. Deliberately left out: theissuesarray reaches the foursession-scanner-agent-sources.tsroots, but those are module-levelconsts evaluated at import time, and the Grok and Kimi resolvers are pure path functions inshared/with no access to it. Doing it properly means restructuring those roots into lazily-resolved values that can report — worth its own PR rather than smuggling it into this one.Maintainer note: rebased onto current
mainand extended by @nwparker — original authorship preserved. Added the shared-helper reuse (the original reimplemented logic that already existed asabsoluteConfiguredDir), the injectableplatformfor provable Windows coverage, and the missing call-site tests. AC:\-separator-stripping rationale in the original description was inaccurate — no trailing-separator stripping happens at these sites — and has been corrected above; theC:test case remains valid for a different reason.X: @manuaudiomix