Skip to content

Resolve Issue #117: Fix evidence tree orphan nesting, outline leakage, and enforce English agent reasoning - #118

Merged
EricNGOntos merged 4 commits into
stagingfrom
feat/wuchengke/dev
Jun 1, 2026
Merged

EricNGOntos merged 4 commits into
stagingfrom
feat/wuchengke/dev

Conversation

@EricNGOntos

Copy link
Copy Markdown
Contributor

Closes #117

Summary

This PR fixes three bugs in the agentic retrieval evidence pipeline discovered during E2E trace analysis (T2/T4/T6):

Fix 1: Evidence Tree Orphan Nesting (Bug 1)

Root cause: _build_outline_subtree created new parent nodes but failed to migrate pre-existing children under them. Additionally, _hydrate_collected passed unfiltered outline_items containing ancestor/sibling context from load_child_sections, causing echo structures.

Changes:

  • document.py: Added reparenting logic in _build_outline_subtree (lines 712-726) to recursively move existing children under newly created parent nodes
  • document.py: Added startswith filter in _hydrate_collected (lines 331-334) to exclude ancestor/sibling items from child node outlines

Fix 2: Outline-Only Evidence Leakage (Bug 2)

Root cause: render_evidence() used has_content() which returns True for outline-only trees. When KG Select picks a document but Navigate returns collect=[], STOP (no relevant content), the top-level outline skeleton still leaked into evidence_text (950 chars of wasted context budget).

Change:

  • builder.py: Changed guard from has_leaf_content() or has_content() to has_leaf_content() only. Documents without hydrated chunks are now skipped entirely.

Fix 3: English Agent Reasoning (Bug 3)

Changes:

  • prompts.py: Added IMPORTANT block to COLLECTOR_PROMPT requiring reason and other free-text fields to be written in English
  • planner.py: Added IMPORTANT block to _PLANNER_PROMPT requiring reasoning_summary to be in English while preserving original language for sub-queries

Cleanup

  • Removed 3 unused imports flagged by ruff lint (_find_covering_path, normalize_section_path, DocTreeNode)

Verification

All fixes verified via E2E debug suite:

Test Before After Status
T2 (Deep Drill Vendor) Orphan nodes at wrong depth, echo structures Correct L1→L2→L3 nesting
T4 (No Relevant Doc) evidence=950 chars (outline leakage) evidence=0 chars
T6 (Cross Doc Construction) L2→L5 nesting correct No regression, unchanged
cd apps/worker && python scripts/debug_retrieval.py --test T2 --test T4 --test T6

Quality Gates

  • make lint: All checks passed ✅
  • make typecheck: 0 errors, 0 warnings ✅

Files Changed (4 files)

  • packages/shared-python/shared/services/retrieval/agentic/evidence/builder.py — Outline leakage fix
  • packages/shared-python/shared/services/retrieval/agentic/navigation/document.py — Orphan nesting + outline filter + lint cleanup
  • packages/shared-python/shared/services/retrieval/agentic/tools.py — Lint cleanup
  • packages/shared-python/shared/services/retrieval/agentic/prompts.py — English reasoning rule
  • packages/shared-python/shared/services/retrieval/workflow/planner.py — English reasoning rule

…and enforce English agent reasoning

- Fix _build_outline_subtree to reparent existing children under newly
  created parent nodes, preventing orphan depth errors (Bug 1)
- Filter outline_items in _hydrate_collected to exclude ancestor/sibling
  context from load_child_sections, eliminating echo structures (Bug 1)
- Change render_evidence guard from has_content() to has_leaf_content(),
  skipping documents with outline-only trees when no chunks were
  collected (Bug 2)
- Add English language requirement to COLLECTOR_PROMPT and _PLANNER_PROMPT
  for agent-generated free-text fields like reason and reasoning_summary (Bug 3)
- Remove unused imports flagged by ruff lint

Closes #117
@EricNGOntos EricNGOntos added bug Something isn't working agentic-rag-core Core agentic RAG retrieval pipeline labels Jun 1, 2026
@EricNGOntos EricNGOntos self-assigned this Jun 1, 2026
…use_agentic, Intent Step TODOs

- Add DEFAULT_TOP_K = 10 constant to retrieval settings, replace all hardcoded top_k defaults
- MCP retrieval.query: add exclude_document_ids, exclude_sections, force use_agentic=True
- Add Intent Step TODO injection points in plan.py, channels.py, retrieval_server.py
- Align API route top_k default to use the shared constant
The function was updated to return (hint_lines, hint_by_path, excluded_hints)
but the test still unpacked only 2 values, causing ValueError in CI.
@EricNGOntos
EricNGOntos merged commit c896b3a into staging Jun 1, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agentic-rag-core Core agentic RAG retrieval pipeline bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant