Skip to content

fix: cache inferred project path in session state to avoid cwd fallback#276

Merged
BYK merged 1 commit into
mainfrom
fix/cache-session-project-path
May 12, 2026
Merged

fix: cache inferred project path in session state to avoid cwd fallback#276
BYK merged 1 commit into
mainfrom
fix/cache-session-project-path

Conversation

@BYK
Copy link
Copy Markdown
Owner

@BYK BYK commented May 12, 2026

Summary

  • getProjectPath() now returns a { path, source } tuple so callers can distinguish successful inference from a process.cwd() fallback
  • New resolveSessionProjectPath() helper 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)

Problem

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 through handleConversationTurn where getProjectPath() falls back to process.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 via ensureProject().

Changes

File Change
packages/gateway/src/config.ts getProjectPath() returns ProjectPathResult tuple; warning moved to call sites
packages/gateway/src/pipeline.ts resolveSessionProjectPath() helper; used in both handleConversationTurn and handleCompaction
packages/gateway/test/project-path.test.ts Tests for new return type + 6 resolveSessionProjectPath tests covering upgrade, cache writeback, and no-upgrade scenarios

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)
@BYK BYK force-pushed the fix/cache-session-project-path branch from 3fa457d to 0cdc2d5 Compare May 12, 2026 23:41
@BYK BYK merged commit 793166c into main May 12, 2026
7 checks passed
@BYK BYK deleted the fix/cache-session-project-path branch May 12, 2026 23:42
This was referenced May 13, 2026
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