Skip to content

fix(chunk): treat a fully filtered chunk result as the answer - #21552

Open
ccclucky wants to merge 1 commit into
infiniflow:mainfrom
ccclucky:fix/chunk-filter-bypass
Open

ccclucky wants to merge 1 commit into
infiniflow:mainfrom
ccclucky:fix/chunk-filter-bypass

Conversation

@ccclucky

Copy link
Copy Markdown
Contributor

What this fixes

chunk.Run handed the split chunks back as the final result whenever ResultChunks was empty:

if len(ctx.ResultChunks) == 0 && len(ctx.SplitChunks) > 0 {
	ctx.ResultChunks = ctx.SplitChunks
}

That pass-through is meant for a pipeline with no postprocess stage, where the split output is the answer. It cannot tell that apart from the case where the postprocess stage ran and its filter legitimately dropped every chunk — so filter_min_length above every chunk's length silently became a no-op, and the dropped chunks (whitespace-only ones included) came back as the result.

ResultChunks is written only by PostprocessOperator.Execute, so the empty-vs-not distinction is the whole signal the fallback was reading.

How

Gate the fallback on whether a postprocess stage was built (hasPostprocess, the same condition that adds the stage). Split-only pipelines keep passing through; a postprocess stage's empty output is now the answer.

Repro (pre-fix, 0cfa864cc)

Run("a b c", ChunkOptions{SplitStrategy: "char", FilterMinLength: 5}) — five 1-rune chunks, all below the limit:

split=5 result=5
result chunk index=0 content="a"
result chunk index=1 content=" "
result chunk index=2 content="b"
result chunk index=3 content=" "
result chunk index=4 content="c"

After the change: result=0.

Tests

  • TestRun_FilterDroppingEveryChunkYieldsNoChunks — the case above, with the 5-split-chunk premise pinned so the fixture cannot rot.
  • TestRun_FilterKeepsOnlyQualifyingChunks — the filter selects rather than passes everything through.
  • TestRun_SplitOnlyPipelineStillYieldsChunks — guards the pass-through this change narrows.

Verified red/green: removing the !hasPostprocess guard makes the first test fail with got 5 chunks, want none.

CGO_ENABLED=0 go vet ./internal/parser/chunk/
CGO_ENABLED=0 go test -count=1 ./internal/parser/chunk/...   # ok, 0.164s

Real-sample smoke

108 runs over 12 checked-in documents (docs/**.md, agent/schema/**.json) × 3 split strategies × 3 filter_min_length values, comparing pre- and post-fix output counts. All 36 differences sit in the min_length above every chunk (the case this PR fixes); the 72 realistic cases (min_length 1 and 40) are identical, so no currently-working configuration changes.

Scope

Only the fallback condition and its tests. Not touched: the Size unit inconsistency in postprocess.go:97 (bytes vs the documented runes), which #20747 already covers, and the mergeChunks metadata aliasing, which is a separate contract question.

Fixes #21551

The split-to-result pass-through fires whenever ResultChunks is empty, which
also covers the case where the postprocess filter legitimately dropped every
chunk. Gate it on whether a postprocess stage ran.
@ccclucky

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@ccclucky

Copy link
Copy Markdown
Contributor Author

Ping for CI: workflows on fork PRs stay unqueued until a maintainer approves them, so no ragflow_* run exists for head 8bb92973f99dba780428557385e746fb1988b384 yet. Local verification: CGO_ENABLED=0 go vet ./internal/parser/chunk/ clean and CGO_ENABLED=0 go test -count=1 ./internal/parser/chunk/... ok (0.164s); plus the 108-case real-document smoke comparison described in the PR body.

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9934d108-797e-4a46-864e-2185693d512e
Commits

Reviewing files that changed from the base of the PR and between 0cfa864 and 8bb9297.

Files selected for processing: 2
  • internal/parser/chunk/execute.go
  • internal/parser/chunk/execute_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Walkthrough

Run now preserves an empty result when postprocessing filters out every chunk. Split-only pipelines still use split chunks as their result. Tests cover both behaviors and a partially filtered result.

Changes: Chunk postprocess fallback

Layer / File(s) Summary
Gate split-chunk fallback on postprocessing
internal/parser/chunk/execute.go, internal/parser/chunk/execute_test.go
Run uses whether a postprocess stage is configured to decide whether to fall back to split chunks. Tests verify that an empty filtered result stays empty, qualifying chunks remain, and split-only pipelines return split chunks.

Priority: Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested labels: 🐞 bug, parsing, go

Merge Risk: Minimal · up to 8bb92

No merge-blocking issue was identified in the fallback change.

Pre-merge checks: Passed 5
Check name Status Explanation
Description check Passed The description clearly explains the bug, the implementation, the expected behavior, test coverage, verification results, and scope. It does not use the template's exact "### Summary" heading, but it …
Title check Passed The title clearly and concisely describes the main change: preserving a fully filtered chunk result instead of returning the original split chunks.
Linked Issues check Passed Issue #21551 requires an empty postprocess result when FilterMinLength drops every chunk. Run now gates the split-chunk fallback with !hasPostprocess, so the empty filtered result remains empty.…
Out of Scope Changes check Passed The diff changes only internal/parser/chunk/execute.go and its tests. The code change directly implements #21551. The added tests verify the required behavior. No unrelated implementation changes ar…
Docstring Coverage Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviv…
Full details: Description check

Explanation

The description clearly explains the bug, the implementation, the expected behavior, test coverage, verification results, and scope. It does not use the template's exact "### Summary" heading, but it provides the required information in equivalent sections.

Full details: Linked Issues check

Explanation

Issue #21551 requires an empty postprocess result when FilterMinLength drops every chunk. Run now gates the split-chunk fallback with !hasPostprocess, so the empty filtered result remains empty. The fallback remains for split-only pipelines. Added tests cover all-drop filtering, selective filtering, and split-only pass-through.

Full details: Out of Scope Changes check

Explanation

The diff changes only internal/parser/chunk/execute.go and its tests. The code change directly implements #21551. The added tests verify the required behavior. No unrelated implementation changes are present.

Full details: Docstring Coverage

Explanation

Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 5 functions across 2 files.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

A rabbit checks each chunk in line,
The filter keeps what fits its sign.
If none pass through, none return,
Split-only paths still hold their turn.
The rabbit hops; the tests confirm.

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

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@ccclucky

Copy link
Copy Markdown
Contributor Author

Small CI ping: head 8bb92973f is unchanged since 10-27 and still has no ragflow_* run (the checks panel only shows CodeRabbit). CodeRabbit's review on that head produced no actionable comments, and locally CGO_ENABLED=0 go test -count=1 ./internal/chunk/... plus the handler-level filter tests are green.

Could a maintainer approve the workflow run? Nothing has changed since the approval request two days ago.

@yuzhichang
yuzhichang requested a review from 6ba3i November 18, 2026 03:13
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]: chunk.Run bypasses the postprocess filter when it drops every chunk

1 participant