Skip to content

fix: require explicit RAG scope before generators use docs - #1161

Merged
madara88645 merged 5 commits into
mainfrom
fix/rag-explicit-context-scope-1155
Aug 4, 2026
Merged

fix: require explicit RAG scope before generators use docs#1161
madara88645 merged 5 commits into
mainfrom
fix/rag-explicit-context-scope-1155

Conversation

@madara88645

Copy link
Copy Markdown
Owner

Summary

  • Fixes RAG: require explicit context scope before generator requests use persisted documents #1155. Generator and compile flows no longer treat leftover indexed documents as automatically “in use.” Prior-session files can stay in the library, but they are not sent into a new request until the user attaches them for this session (or uploads/ingests during this session).
  • Context Manager now shows library availability separately from active scope, including document counts/source and a clear Detach context action. The misleading “Connected = docs attached” signal is replaced with backend health vs. active-scope status.
  • Backend agent/skill generation now defaults enable_context_retrieval to off (same opt-in pattern as compile), so cloud-backed generation cannot silently inherit stale local index content.

Small related improvement

  • Compiler, Agent Generator, and Skill Generator now share one session-scoped context state (instead of separate hook instances), so the “RAG Context Active” banner and the generate request stay in sync.

Test plan

  • python -m pytest tests/test_generator_rag_opt_in_api.py tests/test_context_generation.py -q
  • cd web && npm run test -- --run app/hooks/useContextManager.test.tsx app/components/__tests__/ContextManager.test.tsx app/__tests__/page-rag-context-scope.test.tsx app/agent-generator/page.test.tsx app/skills-generator/page.test.tsx
  • Manual: open Compiler / Agent / Skill pages with a pre-populated local index and confirm no “active” banner until Use library for this session
  • Manual: attach, generate, detach, and confirm later generate requests do not re-enable retrieval without attaching again
  • Manual: upload a file in-session and confirm it auto-attaches for that session only

Made with Cursor

Stop agent/skill generation from silently reading the persisted local
index, and make the UI attach/detach session context deliberately so
prior-session documents cannot contaminate a new request.

Co-authored-by: Cursor <cursoragent@cursor.com>
@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
compiler Ready Ready Preview Aug 4, 2026 3:36pm

Update frontend assertions for enable_context_retrieval so Smoke matches the explicit context-scope behavior.

Co-authored-by: Cursor <cursoragent@cursor.com>
@madara88645
madara88645 marked this pull request as ready for review July 29, 2026 06:23
cursor[bot]
cursor Bot approved these changes Jul 29, 2026
Update hybrid/API assertions for enable_context_retrieval=False by default
and opt into retrieval only in success-path context tests.

Co-authored-by: Cursor <cursoragent@cursor.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale comment

PR Risk Assessment (Automation) — Re-evaluation

Risk level: Low (unchanged)
Code review required: No
Decision: Prior approval retained — no re-approval posted

Trigger

PR synchronized after prior approval (98c1c91). New HEAD: 2b41a12.

Delta since last approval

Only test files changed in the new commit:

  • tests/test_agent_generator.py — add enable_context_retrieval=False to mock expectations
  • tests/test_hybrid.py — pass enable_context_retrieval=True where RAG retrieval is exercised
  • tests/test_multi_agent.py — expect context=None when retrieval is off; add opt-in flag to API mocks
  • tests/test_skills_generator.py — add enable_context_retrieval=False to mock expectations

No production code, infra, auth, or schema changes in the delta.

Full PR evidence (production surface)

9 non-test files modified:

  • api/routes/generators.pyenable_context_retrieval defaults to false on agent/skill generator requests
  • app/llm_engine/hybrid.py — gates context_strategist.process() behind opt-in flag (mirrors compile pattern)
  • web/app/hooks/useContextManager.ts + ContextManager.tsx — session-scoped attach/detach; library visible but inactive until attached
  • web/app/hooks/useCompiler.ts, page.tsx, agent-generator/page.tsx, skills-generator/page.tsx — wire contextAttached into requests; shared context state
  • web/lib/api/types.ts — type annotation only

Why Low (risk did not increase)

  • Conservative behavioral change: defaults to less context sent to LLMs, not more
  • Established pattern: extends existing compile RAG opt-in design to generators
  • Limited blast radius: scoped to RAG context scoping across three related UI flows; no auth, billing, infra, or deployment changes
  • Strong test coverage: dedicated API tests, context-generation updates, frontend scope tests; latest commit tightens mock alignment

Reviewer assignment

Not required at Low risk. No CODEOWNERS file. 0 reviewers currently assigned.

CI

All checks passing (Smoke, Analyze, CodeQL, Snyk, GitGuardian, VS Code Extension, PR Tests).


Automated risk assessment — conclusions derived from diff evidence only.

Open in Web View Automation 

Sent by Cursor Automation: Assign PR reviewers

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale comment

PR Risk Assessment (Automation) — Re-evaluation

Risk level: Low (unchanged)
Code review required: No
Decision: Prior approval retained — no new approval posted (already approved on 98c1c91)

Trigger

PR synchronized (synchronize). New HEAD: 31dc335 (merge main into fix/rag-explicit-context-scope-1155).

Delta since last assessment (2b41a12)

The new commit is a merge from main only — it brings upstream CI/tests/security fixes already on main into the branch. Comparing origin/main...HEAD still shows 29 files / +614 −46, identical in scope to the prior assessment (RAG explicit scope work only). No additional PR-authored production logic in this sync.

Evidence (production surface)

Area Change
api/routes/generators.py enable_context_retrieval defaults to false for agent/skill generator requests
app/llm_engine/hybrid.py Gates context_strategist.process() behind opt-in flag (mirrors compile)
web/app/hooks/useContextManager.ts + ContextManager.tsx Session attach/detach; library visible but inactive until attached
web/app/hooks/useCompiler.ts, page.tsx, generator pages Wire contextAttachedenable_context_retrieval / compile flag
web/lib/api/types.ts Type annotation only

Why Low (risk did not increase)

  • Conservative default: less persisted RAG content sent to LLMs unless the user opts in
  • Cohesive, limited domain: RAG scope across compiler + agent/skill generators; no auth, billing, infra, or schema changes
  • Substantial automated tests: test_generator_rag_opt_in_api.py, context-generation updates, frontend scope tests
  • Merge sync: does not expand the merge-to-main diff beyond the above

Reviewers

Not required at Low risk. No CODEOWNERS file. 0 requested reviewers (under the 2-reviewer cap).

CI

Checks were in progress at assessment time (Smoke, CodeQL Analyze, VS Code Extension); Snyk and GitGuardian already green.

Slack

Automation has no Slack channel configured for this run (slackChannelId null); summary delivered via this PR review only.


Automated risk assessment — conclusions derived from diff evidence only.

Open in Web View Automation 

Sent by Cursor Automation: Assign PR reviewers

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Risk Assessment (Automation) — Re-evaluation

Risk level: Low (unchanged)
Code review required: No
Decision: Prior approval retained — no new approval posted (already approved on 98c1c91)

Trigger

PR synchronized (synchronize). New HEAD: 5146e1e (merge main into fix/rag-explicit-context-scope-1155).

Delta since last assessment (31dc335)

New commit merges upstream main into the branch. Comparing 31dc335..5146e1e touches 9 files (+186 lines), including merged-from-main generator error-artifact handling (_raise_if_generator_error_artifact in api/routes/generators.py, web/lib/generatorErrorArtifact.ts, client asserts on agent/skill pages) plus matching tests.

origin/main...HEAD remains 29 files (+614 −46) — same PR-authored scope as prior runs (explicit RAG scope for compile + generators). The merge does not widen the merge-to-main diff.

Evidence (production surface)

Area Change
api/routes/generators.py enable_context_retrieval defaults to false; passes flag into hybrid generators
app/llm_engine/hybrid.py Gates context_strategist.process() behind opt-in (mirrors existing compile path)
web/app/hooks/useContextManager.ts + ContextManager.tsx Session attach/detach; library visible but inactive until attached
web/app/hooks/useCompiler.ts, page.tsx, generator pages Wire contextAttached → retrieval flags on compile/generate requests
web/lib/api/types.ts Type annotation only

Why Low (risk did not increase)

  • Conservative default: less persisted RAG content sent to LLMs unless the user explicitly attaches context
  • Established pattern: extends existing compile enable_context_retrieval design to agent/skill generators
  • Cohesive domain: RAG scoping across related UI flows; no auth, billing, infra, deployment, or schema changes
  • Merged safety fix: error-as-markdown generator responses are rejected server- and client-side (from main; reduces mistaken export of failures)
  • Strong automated tests: test_generator_rag_opt_in_api.py, context-generation updates, frontend scope tests

Reviewers

Not required at Low risk. No CODEOWNERS file. 0 requested reviewers.

CI

CodeQL, Analyze, Snyk, GitGuardian, and Vercel green; Smoke and VS Code Extension still pending at assessment time.

Slack

No Slack destination is configured for this automation run; summary delivered via this PR review only.


Automated risk assessment — conclusions derived from diff evidence only.

Open in Web View Automation 

Sent by Cursor Automation: Assign PR reviewers

@madara88645
madara88645 merged commit ce75a62 into main Aug 4, 2026
12 checks passed
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.

RAG: require explicit context scope before generator requests use persisted documents

1 participant