pi-memory icon indicating copy to clipboard operation
pi-memory copied to clipboard

Project-scoped facts leak through embedding hits and domain expansion

Open VladimirMonin opened this issue 2 months ago • 0 comments

Version / scope

@samfp/[email protected], buildSelectiveBlock() with an available embedding model. This is a follow-up to #19: the FTS/project result filter exists, but later candidate sources do not apply it. The Windows separator behavior is separately tracked in #32.

Expected

For a session whose project slug is alpha, facts with keys project.beta.* must not be injected, regardless of whether the candidate came from FTS, vector similarity, or domain expansion.

Actual / code path

buildSelectiveBlock() initially filters results by the second key segment:

const filteredResults = slug ? results.filter((r) => {
  if (!r.key.startsWith("project.")) return true;
  const parts = r.key.split(".");
  return parts.length >= 2 && parts[1] === slug;
}) : results;

But after that, the embedding loop can append any key without checking its project:

for (const { key } of semanticHits) {
  semanticKeys.add(key);
  if (!seen.has(key)) {
    const entry = store.getSemantic(key);
    if (entry) filteredResults.push(entry);
  }
}

Then domain expansion also appends siblings without rechecking scope:

for (const sibling of store.listSemantic(prefix, limit)) {
  if (!seen.has(sibling.key)) filteredResults.push(sibling);
}

For example, with synthetic keys project.alpha.own, project.beta.one, and project.beta.two, a vector hit for project.beta.one in an alpha session can both inject that unrelated fact and expand project.beta.two. Instrumentation on a local 1.5.0 installation confirmed cross-project raw keys arriving through the embedding/expansion path. No personal database or session content is included here.

Suggested fix

Apply one project-scope predicate to every candidate source (FTS, embedding hits, and sibling expansion), ideally with a regression test using synthetic facts and vectors. The separate Windows projectSlug() normalization issue (#32) also affects which project slug is computed, but fixing it alone will not close this bypass.

VladimirMonin avatar Sep 29 '26 14:09 VladimirMonin