fix: remove stale project path caching that caused cross-project misattribution#262
Merged
Conversation
…ttribution Two bugs caused knowledge entries and all idle background work to be attributed to whichever project the gateway saw first: 1. handleCompaction preferred cachedProjectPath (frozen from the first request) over fresh getProjectPath() inference. Removed cachedProjectPath entirely — it has zero valid consumers. 2. buildIdleWorkHandler closed over a single projectPath parameter captured at init time. Changed to read state.projectPath at call time so each session's idle work uses the correct project. Added tests for inferProjectPath/getProjectPath (20 tests) and idle handler project isolation (2 tests) to prevent regression.
Run idle handler tests in a separate Bun process so mock.module calls on @loreai/core don't leak into cache-warmer and other tests that import the same module.
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
cachedProjectPathfrompipeline.ts—handleCompactionnow callsgetProjectPath()fresh on every request, matchinghandleConversationTurn's behaviorbuildIdleWorkHandlerto readstate.projectPathat call time instead of closing over a singleprojectPathcaptured at init — each session's idle work now uses the correct projectinferProjectPath/getProjectPath(20) and idle handler project isolation (2)Root Cause
Two bugs caused all compaction and idle background work (distillation, curation, knowledge export) to run against whichever project the gateway saw first:
handleCompaction(pipeline.ts:1597) preferredcachedProjectPath(frozen from the first request) over fresh inference. If the first request came from project A, all subsequent compaction requests for project B would use A's path.buildIdleWorkHandler(idle.ts:163) was constructed once with a singleprojectPathparameter captured in a closure. All sessions' idle work used that path, even thoughSessionStatealready had a correct per-sessionprojectPathfield.Fix
cachedProjectPathremoved entirely — it had zero valid consumers after the fix.handleCompactionnow matcheshandleConversationTurn's behavior of callinggetProjectPath()fresh.buildIdleWorkHandlerno longer takes aprojectPathparameter — readsstate.projectPathinside the handler instead.