Skip to content

fix: scope compilation template names by group - #16998

Merged
wangq8 merged 3 commits into
infiniflow:mainfrom
buua436:b111
Jul 16, 2026
Merged

wangq8 merged 3 commits into
infiniflow:mainfrom
buua436:b111

Conversation

@buua436

@buua436 buua436 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Compilation template names were incorrectly unique across the entire tenant, preventing different groups from using the same template name.

This change scopes template-name uniqueness to each template group and updates the model definition accordingly.

Type of change

  • Bug Fix (non-breaking change which fixes an issue)

@coderabbitai

coderabbitai Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

CompilationTemplate uniqueness and duplicate checks now include group_id. WIKI REFINE link rewriting now handles Markdown artifact links and uses planned page titles for slug-like labels.

Changes

Compilation template group scope

Layer / File(s) Summary
Group-scoped template uniqueness
api/db/db_models.py
The CompilationTemplate compound unique index now includes group_id.
Group-scoped duplicate checks
api/db/services/compilation_template_group_service.py
Duplicate-name queries in group updates and child insertion filter by group_id and omit the is_builtin condition.

Wiki link rendering

Layer / File(s) Summary
Title-aware link rewriting
rag/advanced_rag/knowlege_compile/wiki.py
The link transformer rewrites Markdown artifact links and wikilinks using planned titles or humanized slugs.
REFINE pipeline wiring
rag/advanced_rag/knowlege_compile/wiki.py
The REFINE pipeline builds page_titles and passes them to link transformation when writing generated Markdown.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant WikiPlanner
  participant LinkTransformer
  participant RefineWriter
  WikiPlanner->>RefineWriter: pages_spec with planned titles
  RefineWriter->>LinkTransformer: markdown and page_titles
  LinkTransformer-->>RefineWriter: rewritten artifact links and wikilinks
Loading

Possibly related PRs

Suggested labels: 🌈 python

Suggested reviewers: wangq8, kevinhush

Poem

A bunny linked each page with care,
Found Markdown paths hiding there.
Planned titles made the labels bright,
While groups kept template names right.
“Hop!” cried the rabbit, pleased to see—
“A tidy wiki tree for me!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: scoping compilation template names by group.
Description check ✅ Passed The description explains the problem, the fix, and the change type, covering the required summary content.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 requested a review from wangq8 July 16, 2026 09:37
@buua436 buua436 added the ci Continue Integration label Jul 16, 2026
@buua436
buua436 marked this pull request as ready for review July 16, 2026 09:37
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jul 16, 2026
@buua436
buua436 marked this pull request as draft July 16, 2026 09:37
@dosubot dosubot Bot added the 🐞 bug Something isn't working, pull request that fix bug. label Jul 16, 2026
@buua436
buua436 marked this pull request as ready for review July 16, 2026 09:37
@buua436
buua436 marked this pull request as draft July 16, 2026 09:38
@buua436
buua436 marked this pull request as ready for review July 16, 2026 09:38

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

🧹 Nitpick comments (1)
api/db/services/compilation_template_group_service.py (1)

333-343: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add focused tests for the group boundary.

Cover same-name templates across different groups, duplicate names within one group, and the existing built-in behavior.

Also applies to: 417-425

🤖 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 `@api/db/services/compilation_template_group_service.py` around lines 333 -
343, Add focused tests around the duplicate-name validation in the template
group service, covering same-name templates in different groups, duplicate names
within the same group, and preservation of the existing built-in-template
behavior. Exercise both create and update paths as applicable, including the
target-exclusion behavior used by the duplicate_query logic.

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.

Nitpick comments:
In `@api/db/services/compilation_template_group_service.py`:
- Around line 333-343: Add focused tests around the duplicate-name validation in
the template group service, covering same-name templates in different groups,
duplicate names within the same group, and preservation of the existing
built-in-template behavior. Exercise both create and update paths as applicable,
including the target-exclusion behavior used by the duplicate_query logic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5fe37188-6c6b-4b15-baca-d42adb5bc544

📥 Commits

Reviewing files that changed from the base of the PR and between feba9e1 and b28a97b.

📒 Files selected for processing (2)
  • api/db/db_models.py
  • api/db/services/compilation_template_group_service.py

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (4518a58) to head (b28a97b).
⚠️ Report is 23 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16998   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

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

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Jul 16, 2026

@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: 1

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

2900-2904: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Apply title awareness to piped wikilinks.

The _piped function retains the explicit label exactly as written, even if the LLM emitted a raw slug like [[my-slug|my-slug]]. Since _display_text safely falls back to the original label if it doesn't match the slug, you can wrap text in _display_text(text, slug) to consistently apply readable titles across both standard Markdown links and piped wikilinks.

♻️ Proposed refactor
     def _piped(m: re.Match) -> str:
         slug = m.group(1).strip()
         text = m.group(2).strip()
         _track(slug)
-        return f"[{text}](artifact/{kb_id_str}/{slug})"
+        return f"[{_display_text(text, slug)}](artifact/{kb_id_str}/{slug})"
🤖 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 2900 - 2904, Update
the nested _piped function to pass the extracted text and slug through
_display_text before constructing the artifact link, while preserving slug
tracking and the existing URL format.
🤖 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 2889-2890: Update the parts-length guard in the artifact slug
parsing logic to reject only lists shorter than two elements, changing the check
from len(parts) < 3 to len(parts) < 2 while preserving the kb_id_str validation.

---

Nitpick comments:
In `@rag/advanced_rag/knowlege_compile/wiki.py`:
- Around line 2900-2904: Update the nested _piped function to pass the extracted
text and slug through _display_text before constructing the artifact link, while
preserving slug tracking and the existing URL format.
🪄 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

Run ID: 0de97110-0083-432f-a4ca-0525f749beb6

📥 Commits

Reviewing files that changed from the base of the PR and between b28a97b and 6d2c416.

📒 Files selected for processing (1)
  • rag/advanced_rag/knowlege_compile/wiki.py

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jul 16, 2026
@wangq8
wangq8 merged commit bd485db into infiniflow:main Jul 16, 2026
3 of 4 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Jul 16, 2026
1 task done
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:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants