Repository navigation
fix: stabilize wiki planning and artifact graph rendering - #17473
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
📝 WalkthroughWalkthroughThe PR increases wiki-graph loading capacity, adds bounded concurrent wiki planning with strict page validation, restricts rendered links to surviving pages, and filters frontend graph relations to loaded nodes. ChangesWiki compilation
Artifact graph integrity
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant WikiPlanner
participant PlanningBatches
participant PlanningLLM
participant RefineRenderer
WikiPlanner->>PlanningBatches: split oversized planning inputs
PlanningBatches->>PlanningLLM: request bounded page plans
PlanningLLM-->>WikiPlanner: return candidate pages
WikiPlanner->>RefineRenderer: pass valid planned slugs
RefineRenderer-->>WikiPlanner: render content and recompute outlinks
Suggested labels: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
wangq8
left a comment
There was a problem hiding this comment.
Thanks for this well-structured fix! The multi-layered approach (batching, token limits, validation, link filtering, re-render) is thorough. A few observations:
wiki.py – planning batching (_batch_depth):
- Nice use of
_batch_depthto prevent recursive re-batching. The semaphore limiting to 4 concurrent batches is sensible. - Slug-based deduplication in merged results is correct. Consider logging a warning when a duplicate slug is dropped, for observability.
wiki.py – page validation:
-
The slug regex
r"(?:entity|concept|topic)/[a-z0-9]+(?:-[a-z0-9]+)*"matches the documented convention. One edge case: slugs that already exist but happen to have underscores or uppercase would fail validation—is that intentional or should the regex be more lenient? (e.g.,[a-zA-Z0-9_-]+). If the planner always produces lowercase-hyphenated slugs this is fine, but worth confirming. -
Good defense against missing
action,slug,title,page_type,topic. The logging at warning level will help debug planner output issues.
wiki.py – _wiki_transform_links valid_slugs:
-
The
_is_validgate correctly strips whitespace on both sides. When a link targets an invalid slug, it falls back to plain text — this prevents D3 crashes and is a clean UX choice. ✅ -
The post-refine re-render loop (lines ~3800-3818) overwrites
content_md,content_md_rendered,outlinks, andsummary— does_wiki_extract_summaryneedcontent_md_rendered(processed) orcontent_md_raw(raw)? If summary extraction benefits from the rendered artifact-link format, this is fine; just flagging it because the original per-page render only ran summary extraction once.
web – use-artifact-graph-data.ts:
- Moving
nodesByIdbeforelinksconstruction and filtering out incomplete relations is the right fix. Clean. ✅
api – dataset_api_service.py:
- Bumping
_WIKI_GRAPH_MAX_LOADING_ENTITYfrom 128 to 512 is reasonable for larger knowledge bases. No concern.
Overall this is a high-quality defensive fix. The main one to double-check is the slug regex strictness vs existing data.
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (1)
rag/advanced_rag/knowlege_compile/wiki.py (1)
2069-2108: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winLog batch fan-out and merge results.
Record item count, batch count, and merged-page count for this new planning path, without logging entity content. As per coding guidelines, “Add logging for new flows.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@rag/advanced_rag/knowlege_compile/wiki.py` around lines 2069 - 2108, In the batching path around _plan_batch, add logging for the fan-out and merge flow that records the total item count, number of batches, and final merged-page count. Use the existing logger available in this module, avoid including entity or concept content, and emit the merge result after all batch plans have been combined before returning.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@rag/advanced_rag/knowlege_compile/wiki.py`:
- Around line 2179-2195: Update the validation in the PLAN page filtering flow
around valid_pages.append so fields are validated jointly: require every UPDATE
slug to match a reconciled page_slug value, and require the slug’s
entity/concept/topic prefix to equal page_type. Preserve the existing
independent validation and dropping behavior for invalid pages.
- Around line 2069-2107: Update the batching logic in _wiki_planning_call so the
parent derives a plan-wide page cap from target_page_count and applies it while
merging batch_plan pages. Preserve slug deduplication, but stop accepting pages
once the cap is reached and ensure estimated_page_count reflects the capped
merged_pages.
- Around line 3802-3818: The post-filtered rendering in the results cleanup loop
must be persisted before returning. Update the persistence flow around the draft
save near line 3750 and the loop using actual_slugs so each cleaned page is
re-persisted with plan_input_hash, or move draft persistence after this
rendering pass, ensuring resumed drafts contain current links, outlinks, and
summaries.
- Around line 2134-2142: Update the WIKI_PLAN_USER_TEMPLATE.format call so
target_page_count receives the requested target count variable rather than
max_page_count, while keeping max_page_count assigned to the max_page_count
placeholder.
In `@web/src/components/artifact-force-graph/use-artifact-graph-data.ts`:
- Around line 50-62: Update the link-building logic near nodesById to resolve
relation.from and relation.to through a map keyed by each node’s slug, rather
than filtering against configurable node IDs. Retain only relations whose both
slug endpoints are loaded, then emit the resolved nodes’ actual id values as
source and target while preserving relation.type.
---
Nitpick comments:
In `@rag/advanced_rag/knowlege_compile/wiki.py`:
- Around line 2069-2108: In the batching path around _plan_batch, add logging
for the fan-out and merge flow that records the total item count, number of
batches, and final merged-page count. Use the existing logger available in this
module, avoid including entity or concept content, and emit the merge result
after all batch plans have been combined before returning.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 7d4bde82-b2c8-413d-9212-bfc28949d1db
📒 Files selected for processing (3)
api/apps/services/dataset_api_service.pyrag/advanced_rag/knowlege_compile/wiki.pyweb/src/components/artifact-force-graph/use-artifact-graph-data.ts
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #17473 +/- ##
==========================================
- Coverage 94.56% 90.65% -3.91%
==========================================
Files 10 10
Lines 717 717
Branches 118 118
==========================================
- Hits 678 650 -28
- Misses 25 39 +14
- Partials 14 28 +14 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
What problem does this PR solve?
Wiki planning could produce truncated or malformed page objects when the planning response exceeded the model context limit. These invalid pages could be persisted and later generate malformed artifact links.
The artifact graph API can also return relations whose endpoint entities are not included in the current graph slice. Passing these incomplete relations directly to the frontend ForceGraph causes D3 to throw
node not foundand can interrupt the entire graph rendering.What does this PR change?
Type of change