Resolve Issue #117: Fix evidence tree orphan nesting, outline leakage, and enforce English agent reasoning - #118
Merged
Merged
Conversation
…selection prompts
…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
…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.
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.
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_subtreecreated new parent nodes but failed to migrate pre-existing children under them. Additionally,_hydrate_collectedpassed unfilteredoutline_itemscontaining ancestor/sibling context fromload_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 nodesdocument.py: Addedstartswithfilter in_hydrate_collected(lines 331-334) to exclude ancestor/sibling items from child node outlinesFix 2: Outline-Only Evidence Leakage (Bug 2)
Root cause:
render_evidence()usedhas_content()which returns True for outline-only trees. When KG Select picks a document but Navigate returnscollect=[], 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 fromhas_leaf_content() or has_content()tohas_leaf_content()only. Documents without hydrated chunks are now skipped entirely.Fix 3: English Agent Reasoning (Bug 3)
Changes:
prompts.py: AddedIMPORTANTblock toCOLLECTOR_PROMPTrequiringreasonand other free-text fields to be written in Englishplanner.py: AddedIMPORTANTblock to_PLANNER_PROMPTrequiringreasoning_summaryto be in English while preserving original language for sub-queriesCleanup
_find_covering_path,normalize_section_path,DocTreeNode)Verification
All fixes verified via E2E debug suite:
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 fixpackages/shared-python/shared/services/retrieval/agentic/navigation/document.py— Orphan nesting + outline filter + lint cleanuppackages/shared-python/shared/services/retrieval/agentic/tools.py— Lint cleanuppackages/shared-python/shared/services/retrieval/agentic/prompts.py— English reasoning rulepackages/shared-python/shared/services/retrieval/workflow/planner.py— English reasoning rule