fix: cache inferred project path in session state to avoid cwd fallback#276
Merged
Conversation
Claude Code sends alternating streaming and non-streaming requests. The
non-streaming prompt-caching probes have stripped-down system prompts
that lack path references, causing getProjectPath() to fall back to
process.cwd() even though the session already knows the correct path
from a prior streaming turn.
- getProjectPath() now returns a { path, source } tuple so callers can
distinguish successful inference from cwd fallback
- resolveSessionProjectPath() upgrades cwd fallbacks from the session's
cached path and updates the cache when fresh inference succeeds
- Warning only fires when the cwd fallback truly sticks (no session
cache available to upgrade from)
3fa457d to
0cdc2d5
Compare
This was referenced May 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
getProjectPath()now returns a{ path, source }tuple so callers can distinguish successful inference from aprocess.cwd()fallbackresolveSessionProjectPath()helper upgrades cwd fallbacks from the session's cached path and updates the cache when fresh inference succeedsProblem
When Claude Code sends requests through the lore gateway, it alternates between streaming conversation turns (with full system prompts containing
Primary working directory:) and non-streaming caching probes (stream=false, messages=1, ~4K token stripped system prompt lacking path references). The caching probes aren't classified as meta requests (they have many tools and high maxTokens), so they go throughhandleConversationTurnwheregetProjectPath()falls back toprocess.cwd()— even though the session already has the correct path from an earlier streaming turn.This causes
[lore] warning: project path falling back to process.cwd()on every other turn and can misattribute data to the wrong project viaensureProject().Changes
packages/gateway/src/config.tsgetProjectPath()returnsProjectPathResulttuple; warning moved to call sitespackages/gateway/src/pipeline.tsresolveSessionProjectPath()helper; used in bothhandleConversationTurnandhandleCompactionpackages/gateway/test/project-path.test.tsresolveSessionProjectPathtests covering upgrade, cache writeback, and no-upgrade scenarios