Repository navigation
Conversation
|
@Lubrsy706 is attempting to deploy a commit to the rohitg00's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds project identity resolution and alias expansion (including Git worktree detection), canonicalizes sessions at start, and updates mem::context and mem::search to match lessons/sessions using expanded project aliases so worktree and main-repo paths are treated as the same project. ChangesWorktree Path Canonicalization
Sequence DiagramsequenceDiagram
participant Client as Codex Client
participant APIStart as api::session::start
participant ResolveId as resolveProjectIdentity
participant GitCmd as git rev-parse
participant KV as Session Storage
participant ContextFunc as mem::context
participant ContextSearch as Context Lesson/Session Matching
Client->>APIStart: start session (worktree cwd, worktree path)
APIStart->>ResolveId: canonicalize project identity
ResolveId->>GitCmd: detect git dirs, branch, top-level
GitCmd-->>ResolveId: main repo path, worktree info
ResolveId-->>APIStart: canonical project + aliases (main, worktree, basename)
APIStart->>KV: store Session (project: main repo, cwd: worktree path)
APIStart->>ContextFunc: trigger with canonical project
ContextFunc->>ContextSearch: expand project aliases
ContextSearch->>KV: match lessons/sessions by alias set
KV-->>ContextSearch: results from alias variants
ContextFunc-->>Client: context includes project memories
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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.
Actionable comments posted: 2
🧹 Nitpick comments (1)
test/context-project-alias.test.ts (1)
37-37: 💤 Low valueReplace
as neverwith safer type assertion.The
as neverassertion completely disables type checking. Consider usingas anyor properly typing the mockKV return value to match the expected KV interface for better type safety in tests.♻️ Safer type assertion
- registerContextFunction(sdk, kv as never, 4000); + registerContextFunction(sdk, kv as any, 4000);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/context-project-alias.test.ts` at line 37, The test uses a broad unsafe assertion "kv as never" when calling registerContextFunction(sdk, kv, 4000); replace this with a safer approach: either cast kv to any (kv as any) or, better, give kv a proper typed mock that implements the expected KV interface used by registerContextFunction (e.g., define mockKV: Partial<KVStore> or a mocked type matching the methods registerContextFunction expects) and pass that typed mock instead of using never; update the test variable (kv) and its declaration so the type aligns with registerContextFunction's parameter signature.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/functions/project-identity.ts`:
- Around line 79-84: projectValueMatches currently lets path-like values match
other projects via bare basenames (e.g., "app"), causing cross-project matches;
fix by detecting if the input value is path-like (e.g., contains '/'), and if so
only consider expanded aliases that are path-like when checking intersection
with the provided aliases set; preserve the existing expandProjectAliases-based
matching for non-path (legacy) values but when value is path-like do:
expandProjectAliases(value).filter(a => a.includes('/')).some(a =>
aliases.has(a)) so basename-only aliases are not used for path-like comparisons
(use function names projectValueMatches and expandProjectAliases to locate the
change).
In `@test/context-project-alias.test.ts`:
- Around line 30-40: Replace the manual SDK object in wireContext with a
module-level mock by adding vi.mock("iii-sdk") at the top of the test and using
the mocked SDK from that module; specifically, update wireContext (and its use
of registerContextFunction and ContextHandler) to obtain the mocked sdk (with
registerFunction/trigger spies) from the vi.mocked "iii-sdk" export instead of
constructing the sdk inline, and ensure the test uses the existing mockKV for
kv.get/set/list per test suite convention so registerContextFunction(kv, ...) is
invoked with the mocked kv and the mocked sdk is used to capture the
mem::context handler.
---
Nitpick comments:
In `@test/context-project-alias.test.ts`:
- Line 37: The test uses a broad unsafe assertion "kv as never" when calling
registerContextFunction(sdk, kv, 4000); replace this with a safer approach:
either cast kv to any (kv as any) or, better, give kv a proper typed mock that
implements the expected KV interface used by registerContextFunction (e.g.,
define mockKV: Partial<KVStore> or a mocked type matching the methods
registerContextFunction expects) and pass that typed mock instead of using
never; update the test variable (kv) and its declaration so the type aligns with
registerContextFunction's parameter signature.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 3ee5d146-faec-439b-b5b6-2eaf9cab18c5
📒 Files selected for processing (8)
src/functions/branch-aware.tssrc/functions/context.tssrc/functions/project-identity.tssrc/functions/search.tssrc/triggers/api.tssrc/triggers/events.tstest/context-project-alias.test.tstest/project-identity.test.ts
Signed-off-by: Lubrsy706 <lubrsy706@gmail.com>
4d49166 to
4d652dc
Compare
|
Have you benchmarked the context retrieval? I had a similar solution, and the SessionStart hooks script started timing out as it has a hard cap of 1.5s in the script, and with the git workspace lookup, it was taking longer, so you may also consider changing that timeout. |
|
Thanks for calling this out. I checked this path and agreed the previous implementation was too loose for the SessionStart budget: it ran multiple sequential I pushed
Local validation:
So worst-case git detection is now bounded well below the 1.5s SessionStart inject timeout, and normal local lookup is in the low tens of ms. |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/functions/project-identity.ts`:
- Line 4: Replace the hardcoded GIT_IDENTITY_TIMEOUT_MS by making it
configurable and avoid silent fallback: introduce a configurable timeout value
(e.g., read from env or config) to replace GIT_IDENTITY_TIMEOUT_MS and, inside
detectGitProject(), on timeout reuse a cached last-known identity (store and
read the last successful identity keyed by repo path) instead of returning null;
also update resolveProjectIdentity() to prefer the cached identity when
detectGitProject() fails. Additionally, in detectGitProject() explicitly treat
the literal "HEAD" string as a detached-HEAD sentinel (do not propagate "HEAD"
as a branch name) and handle that case by using the commit hash or cached
identity. Ensure these changes reference GIT_IDENTITY_TIMEOUT_MS (or its new
config key), detectGitProject(), resolveProjectIdentity(), and the cache
read/write locations so reviewers can find the edits.
- Around line 137-139: The returned branch value currently treats the string
"HEAD" as a valid name; update the return object in the function that builds
project identity so that the branch field normalizes detached HEAD to null
(e.g., set branch to null when the local variable branch is falsy or equals the
literal "HEAD", otherwise keep branch). Locate the return with "isWorktree" and
"branch: branch || null" and replace that assignment with a conditional that
filters out the "HEAD" value.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: c5072dd9-dfc8-4157-bbf5-6ce007d87fcc
📒 Files selected for processing (1)
src/functions/project-identity.ts
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/functions/project-identity.ts (1)
23-24: ⚡ Quick winBound the git identity cache.
Each successful detection stores up to five keys, and nothing ever evicts them. In a long-lived agent that touches many temporary repos/worktrees, this turns into an unbounded cache of stale git metadata and makes the fallback path less trustworthy over time.
♻️ Minimal way to cap the cache
const gitProjectCache = new Map<string, GitProjectInfo>(); +const MAX_GIT_PROJECT_CACHE_KEYS = 512; function rememberGitProject(cwd: string, git: GitProjectInfo): void { for (const key of [ cwd, git.topLevel, @@ git.gitDir, git.commonDir, ]) { - gitProjectCache.set(pathKey(key), git); + const normalizedKey = pathKey(key); + gitProjectCache.delete(normalizedKey); + gitProjectCache.set(normalizedKey, git); + while (gitProjectCache.size > MAX_GIT_PROJECT_CACHE_KEYS) { + const oldestKey = gitProjectCache.keys().next().value; + if (!oldestKey) break; + gitProjectCache.delete(oldestKey); + } } }Also applies to: 67-90
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/functions/project-identity.ts` around lines 23 - 24, The gitProjectCache Map currently grows without bounds; add a fixed-size eviction policy by introducing a MAX_GIT_CACHE_ENTRIES constant (e.g. 100 or 5 as desired) and ensure inserts into gitProjectCache evict the oldest/least-recently-used entry when the size would exceed the limit. Update any accessor functions that touch gitProjectCache (e.g., the functions around lines 67-90 that read/write the Map) to maintain LRU order on access (move accessed keys to the "most-recent" position) or use a simple FIFO eviction on insert, so stale git metadata is removed and the cache size is always capped.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/functions/project-identity.ts`:
- Around line 23-24: The gitProjectCache Map currently grows without bounds; add
a fixed-size eviction policy by introducing a MAX_GIT_CACHE_ENTRIES constant
(e.g. 100 or 5 as desired) and ensure inserts into gitProjectCache evict the
oldest/least-recently-used entry when the size would exceed the limit. Update
any accessor functions that touch gitProjectCache (e.g., the functions around
lines 67-90 that read/write the Map) to maintain LRU order on access (move
accessed keys to the "most-recent" position) or use a simple FIFO eviction on
insert, so stale git metadata is removed and the cache size is always capped.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 2565b12c-3f31-4189-aefa-b070dc4fed43
📒 Files selected for processing (2)
src/functions/project-identity.tstest/project-identity.test.ts
|
Thanks @Lubrsy706 — closing here, the worktree-fragmentation root cause is being tracked in #515 for a fuller fix. |
Summary
Fixes #515
Tests
Summary by CodeRabbit
New Features
Tests