Skip to content

fix: prevent cross-project knowledge entries from leaking into AGENTS.md#36

Merged
BYK merged 1 commit intomainfrom
fix/cross-project-agents-md-leak
Mar 9, 2026
Merged

fix: prevent cross-project knowledge entries from leaking into AGENTS.md#36
BYK merged 1 commit intomainfrom
fix/cross-project-agents-md-leak

Conversation

@BYK
Copy link
Owner

@BYK BYK commented Mar 9, 2026

Problem

Cross-project knowledge entries from unrelated projects were appearing in a project's AGENTS.md (reported on getsentry/devinfra-deployment-service#832). Entries like "Consola prompt cancel returns truthy Symbol", "Zod z.coerce.number() converts null to 0", and "Craft v2 GitHub App must be installed per-repo" appeared in devinfra-deployment-service's AGENTS.md — none of which are relevant to that repo.

Root Causes

Three interrelated issues:

  1. Curator creates project-scoped duplicates: The curator saw all cross-project entries via ltm.forProject(path, cfg.crossProject=true), then the LLM created near-duplicates scoped to the current project. The title dedup guard only checked same project_id, missing cross-project originals.

  2. importFromFile defaults crossProject to true: Entries imported from AGENTS.md got crossProject: true (the ltm.create() default), leaking them into other projects' system prompts.

  3. Consolidation count inflated: ltm.forProject(projectPath) included cross-project entries from all repos, triggering unnecessary consolidation.

Fix

Source changes (5 files)

  • src/curator.ts: Curator and consolidation now use forProject(path, false) — only see project-specific entries
  • src/ltm.ts:
    • Default crossProject changed from true to false in create()
    • Dedup guard extended to also check cross-project entries by title
    • forProject(path, false) no longer includes project_id IS NULL entries
  • src/index.ts: Consolidation count uses forProject(path, false)
  • src/config.ts: crossProject config default changed to false
  • src/agents-file.ts: Both import paths explicitly set crossProject: false

Backward compatibility

  • forSession() is unaffected — it has its own SQL queries with relevance gating for cross-project entries, so they still appear in system prompts when relevant
  • Existing cross-project entries remain in the DB and accessible via forSession()

Tests

7 new tests added covering:

  • create() defaults crossProject to false
  • Dedup guard catches title matches against cross-project entries
  • importFromFile creates entries with cross_project = 0
  • Cross-project entries don't appear in exportToFile output
  • Cross-project entries don't inflate forProject(path, false) count

All 194 tests pass (187 existing + 7 new).

@BYK BYK enabled auto-merge (squash) March 9, 2026 19:56
Cross-project entries from unrelated projects were appearing in a
project's AGENTS.md. Three interrelated causes fixed:

1. Curator saw all cross-project entries and created project-scoped
   duplicates. Fix: curator and consolidation now use
   forProject(path, false) to only see project-specific entries.

2. ltm.create() defaulted crossProject to true, so entries imported
   from AGENTS.md leaked into other projects. Fix: default changed
   to false; importFromFile now explicitly sets crossProject: false.

3. Consolidation entry count included cross-project entries from all
   repos, triggering unnecessary consolidation. Fix: use
   forProject(path, false) for the count.

Additional hardening:
- Dedup guard in ltm.create() now also checks cross-project entries
  by title, preventing duplicate creation even if curator tries.
- forProject(path, false) no longer includes project_id IS NULL
  entries (global entries don't belong to any specific project).
- Config crossProject default changed from true to false.

forSession() is unaffected — it has its own SQL queries with
relevance gating for cross-project entries.
@BYK BYK force-pushed the fix/cross-project-agents-md-leak branch from ec727dd to 24a1c54 Compare March 9, 2026 20:00
@BYK BYK merged commit 1a546f3 into main Mar 9, 2026
1 check passed
@BYK BYK deleted the fix/cross-project-agents-md-leak branch March 9, 2026 20:00
@craft-deployer craft-deployer bot mentioned this pull request Mar 9, 2026
2 tasks
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