Skip to content

fix: preserve URL fallback chunk parameters - #10167

Open
iuiu-py wants to merge 1 commit into
AstrBotDevs:masterfrom
iuiu-py:fix/9999-kb-url-fallback-params
Open

iuiu-py wants to merge 1 commit into
AstrBotDevs:masterfrom
iuiu-py:fix/9999-kb-url-fallback-params

Conversation

@iuiu-py

@iuiu-py iuiu-py commented Sep 21, 2026

Copy link
Copy Markdown

Modifications

Test Results

  • Red: uv run pytest tests/test_kb_helper_cleaning_fallback.py -q failed before the fix; both fallback branches produced 500-character chunks when 128/16 was requested.
  • Green: after the fix, the same command passes with 2 passed.
  • uv run ruff format astrbot/core/knowledge_base/kb_helper.py tests/test_kb_helper_cleaning_fallback.py completed; focused uv run ruff check ... passed.

Checklist

  • This is NOT a breaking change.
  • My changes have been well-tested, and verification commands/results are provided above.
  • No WebUI navigation or terminology changed, so no WebUI documentation update is needed.
  • No new dependencies are introduced.
  • My changes do not introduce malicious code.

Summary by Sourcery

Preserve URL fallback chunk parameters when content cleaning cannot be performed.

Bug Fixes:

  • Preserve caller-specified chunk size and overlap when content-cleaning fallbacks are used for missing or unavailable providers.

Tests:

  • Add regression coverage for both cleaning fallback paths to verify the requested chunking parameters are retained.

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tests/test_kb_helper_cleaning_fallback.py" line_range="18-28" />
<code_context>
+    helper = object.__new__(KBHelper)
+    helper.chunker = RecursiveCharacterChunker()
+
+    chunks = await helper._clean_and_rechunk_content(
+        content="x" * 1000,
+        url="https://example.invalid/document",
+        enable_cleaning=True,
+        cleaning_provider_id=None,
+        chunk_size=128,
+        chunk_overlap=16,
+    )
+
+    assert len(chunks) > 1
+    assert max(len(chunk) for chunk in chunks) == 128
+
+
</code_context>
<issue_to_address>
**issue (testing):** Both regression tests pass when the fallback ignores `chunk_overlap`, because they assert only that chunks have the requested maximum size and never verify overlap between adjacent chunks. The tests therefore do not protect the second half of the forwarding fix.

**Suggested fix:** Assert that adjacent chunks share the requested overlap, for example by checking `chunks[0][-16:] == chunks[1][:16]` for the test input.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: tests/test_kb_helper_cleaning_fallback.py:28


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment on lines +18 to +28
chunks = await helper._clean_and_rechunk_content(
content="x" * 1000,
url="https://example.invalid/document",
enable_cleaning=True,
cleaning_provider_id=None,
chunk_size=128,
chunk_overlap=16,
)

assert len(chunks) > 1
assert max(len(chunk) for chunk in chunks) == 128

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.

issue (testing): Both regression tests pass when the fallback ignores chunk_overlap, because they assert only that chunks have the requested maximum size and never verify overlap between adjacent chunks. The tests therefore do not protect the second half of the forwarding fix.

Suggested fix: Assert that adjacent chunks share the requested overlap, for example by checking chunks[0][-16:] == chunks[1][:16] for the test input.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 知识库 URL 清洗回退时丢失 chunk_size/chunk_overlap,按默认参数入库

1 participant