Skip to content

fix: stabilize wiki planning and artifact graph rendering - #17473

Merged
wangq8 merged 4 commits into
infiniflow:mainfrom
buua436:b125
Jul 28, 2026
Merged

wangq8 merged 4 commits into
infiniflow:mainfrom
buua436:b125

Conversation

@buua436

@buua436 buua436 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

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 found and can interrupt the entire graph rendering.

What does this PR change?

  • Add output token and page-count limits to Wiki planning.
  • Split large planning inputs into batches of up to 40 entities/concepts.
  • Run planning batches with bounded concurrency and merge results by slug.
  • Validate planner output before persisting pages.
  • Remove links targeting pages that were not successfully generated.
  • Re-render final Wiki content against the actual persisted page set.
  • Increase the default Wiki graph entity loading budget from 128 to 512.
  • Filter graph relations whose source or target entity is missing from the current graph response.

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • Performance improvement
  • Data consistency improvement

@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7e5dab97-23f8-473f-8a40-a9b69f4a8d68

📥 Commits

Reviewing files that changed from the base of the PR and between 81b7c0d and f481280.

📒 Files selected for processing (1)
  • rag/advanced_rag/knowlege_compile/wiki.py
💤 Files with no reviewable changes (1)
  • rag/advanced_rag/knowlege_compile/wiki.py

📝 Walkthrough

Walkthrough

The 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.

Changes

Wiki compilation

Layer / File(s) Summary
Bounded wiki planning
rag/advanced_rag/knowlege_compile/wiki.py
Planning derives token and page limits, batches oversized inputs with bounded concurrency, merges unique pages, and validates the resulting plan.
Validated REFINE links
rag/advanced_rag/knowlege_compile/wiki.py
REFINE restricts artifact links to planned slugs and recomputes rendered content, outlinks, and summaries from pages that survive the run.

Artifact graph integrity

Layer / File(s) Summary
Loaded-node graph validation
api/apps/services/dataset_api_service.py, web/src/components/artifact-force-graph/use-artifact-graph-data.ts
The wiki-graph entity cap increases from 128 to 512, and frontend links are emitted only when both endpoint nodes exist.

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
Loading

Suggested labels: 🌈 python

Poem

I’m a rabbit with pages to plan,
Batching each hop as fast as I can.
Links point where nodes truly stay,
Lost slugs quietly fade away.
More graph leaves now fill the view—
Hop, hop, the wiki grew! 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.77% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: stabilizing wiki planning and artifact graph rendering.
Description check ✅ Passed The description covers the problem, the implemented fixes, and the change type, though it doesn't use the exact template heading.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@buua436 buua436 added the ci Continue Integration label Jul 28, 2026
@buua436
buua436 requested a review from wangq8 July 28, 2026 06:16
@buua436
buua436 marked this pull request as ready for review July 28, 2026 06:16
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jul 28, 2026

@wangq8 wangq8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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_depth to 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_valid gate 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, and summary — does _wiki_extract_summary need content_md_rendered (processed) or content_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 nodesById before links construction and filtering out incomplete relations is the right fix. Clean. ✅

api – dataset_api_service.py:

  • Bumping _WIKI_GRAPH_MAX_LOADING_ENTITY from 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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 5

🧹 Nitpick comments (1)
rag/advanced_rag/knowlege_compile/wiki.py (1)

2069-2108: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Log 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

📥 Commits

Reviewing files that changed from the base of the PR and between cc0fbd3 and b4d215a.

📒 Files selected for processing (3)
  • api/apps/services/dataset_api_service.py
  • rag/advanced_rag/knowlege_compile/wiki.py
  • web/src/components/artifact-force-graph/use-artifact-graph-data.ts

@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.65%. Comparing base (8b793ee) to head (b4d215a).
⚠️ Report is 6 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants