Skip to content

fix(agent): ignore a Switch condition item with no operand - #22667

Merged
JinHai-CN merged 1 commit into
infiniflow:mainfrom
1BugKiller:fix/switch-empty-condition
Nov 23, 2026
Merged

JinHai-CN merged 1 commit into
infiniflow:mainfrom
1BugKiller:fix/switch-empty-condition

Conversation

@1BugKiller

Copy link
Copy Markdown
Contributor

Fixes #22666

What was wrong

A Switch condition item with no operand — no cpn_id, no left — was not skipped by normalizeLegacyGroup. The clause was built with left: "", and comparing "" with the item's absent value satisfies contains, = and empty, so the group matched and the run was routed to that branch instead of falling through to ELSE / end_cpn_ids.

The web form creates this item on its own: "Add" appends {operator} only, cpn_id is a plain z.string() with no minimum length, and nothing filters unfilled rows before save.

This is the second half of #15643. evaluateGroup already refuses to match an empty clause list and its comment names "all skipped cpn_ids", but nothing ever skipped them, so the guard never fired for this shape. The existing TestSwitch_LegacyEmptyItemsFallsThrough covers the intent yet only passes because its item carries value: "x", which cannot match an empty left.

The change

internal/agent/component/switch.go — skip the item when legacySwitchLeft yields nothing, matching Python's if not item["cpn_id"]: continue. An item that names a left literal or a cpn_id is untouched, so the newer left form keeps working.

Tests

internal/agent/component/switch_test.go:

  • TestSwitch_LegacyIncompleteItemFallsThrough — four shapes of an unfilled row (contains without value, = with an empty value, empty, not empty) must land on the default target. Three of the four fail without the fix; not empty is included so the table covers both polarities.
  • TestSwitch_IncompleteItemDoesNotDisableSiblingClauses — one unfilled row plus one configured clause still routes on the configured clause.

Full package run:

go test ./internal/agent/component/ -count=1
ok  ragflow/internal/agent/component  4.069s

gofmt, go vet and the repo's tools/hooks/check_files.py checks (eof, trailing whitespace, mixed line endings, ASCII comments, case conflicts, merge conflicts) are clean.

Not covered

The newer clauses form is unchanged: it is produced by the Go canvas rather than the web form, so an empty left there has no Python counterpart to compare against. I kept the change to the legacy items path where parity is defined.

The front end's "Add" button appends `{operator}` and nothing else, and the
schema accepts an empty cpn_id, so a condition row can be saved without an
operand. normalizeLegacyGroup built a clause for it anyway: left became "", and
comparing "" with the absent value satisfies contains, "=" and empty, so the
group matched and the run was routed to a branch whose condition was never
configured.

The Python implementation skips those items (`if not item["cpn_id"]: continue`),
and this is the second half of infiniflow#15643: evaluateGroup already refuses to match an
empty clause list, with a comment naming the skipped cpn_id items, but nothing
ever skipped them, so that guard never fired.

Skip the item when neither cpn_id nor left names an operand. A sibling clause
that is fully configured still decides the group, which the second test pins.
@1BugKiller

Copy link
Copy Markdown
Contributor Author

The ci label has not been applied, so the sep-tests jobs on this PR are skipped rather than run: the workflow triggers on synchronize / labeled and every job is gated on contains(github.event.pull_request.labels.*.name, 'ci').

Could someone add it? Everything else is ready: one commit on current main, go test ./internal/agent/component/ green locally (4.1s), gofmt / go vet / check_files.py clean, and the regression test fails on the parent revision (_next = [WRONG_TARGET] instead of the default) so the guard has teeth.

@1BugKiller
1BugKiller requested a review from 6ba3i as a code owner November 23, 2026 06:54
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Go Switch component now skips legacy condition items with no resolved operand. Regression tests cover default routing when all items are skipped and matching when a valid sibling clause remains.

Changes: Legacy Switch operand handling

Layer / File(s) Summary
Normalize legacy items and verify routing
internal/agent/component/switch.go, internal/agent/component/switch_test.go
normalizeLegacyGroup skips items with an empty left operand. Tests verify that incomplete items fall through to DEFAULT and that a valid sibling clause can route to its target.

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

Change: Bug fix · Severity of issue fixed: Low

Possibly related PRs

  • infiniflow/ragflow#22315: Updates Go Switch no-match and ELSE routing, which is the path used when all legacy items are skipped.

Suggested labels: 🐞 bug, ci

Suggested reviewers: 6ba3i, xugangqiang

Merge Risk: Minimal · up to 2553e

Legacy Switch rows with no operand are now ignored, so they no longer match a branch by accident. Configured sibling rows still work, and a group with no usable rows falls through to the default. The change is narrow and tested, and no merge-blocking risk is evident.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a Switch condition item with no operand is now ignored. It is specific and matches the switch.go change and the linked issue #22666. The change is limited to the legac…
Description check Passed The description follows the repository template. It has a clear background and purpose section that explains the bug, its cause, and the link to #15643 and #22666. It also covers the change, the tests…
Linked Issues check Passed Issue #22666 requires three coding behaviors in the Go legacy Switch items path:
1. Ignore a legacy condition item with no operand. Met. normalizeLegacyGroup in `internal/agent/component/switch.go…
Out of Scope Changes check Passed The whole-PR diff against the merge base e2cf39ad8 contains one source hunk in internal/agent/component/switch.go (+10 lines). It adds an empty-operand check in the legacy items loop of `normali…
Full details: Title check

Explanation

The title names the main change: a Switch condition item with no operand is now ignored. It is specific and matches the switch.go change and the linked issue #22666. The change is limited to the legacy items path, and the title does not claim more than that.

Full details: Description check

Explanation

The description follows the repository template. It has a clear background and purpose section that explains the bug, its cause, and the link to #15643 and #22666. It also covers the change, the tests, the verification results, and the scope limits. The template's Summary heading is not used literally, but the content fills its purpose. The author notes the ci label is missing, which is a process item and not a template requirement.

Full details: Linked Issues check

Explanation

Issue #22666 requires three coding behaviors in the Go legacy Switch items path:

  1. Ignore a legacy condition item with no operand. Met. normalizeLegacyGroup in internal/agent/component/switch.go now calls continue when legacySwitchLeft(item) returns "". This check runs before the clause is appended, so no {left: "", op, ...} clause is created for an unfilled row.
  2. Keep evaluating configured sibling clauses. Met. Only operand-less items are skipped. Items with a left literal or a cpn_id still build clauses through the unchanged code path. The added sibling-clause test (TestSwitch_IncompleteItemDoesNotDisableSiblingClauses, per the PR description) covers this case.
  3. Do not match a group with no remaining clauses. Met. When every item is skipped, evaluateGroup receives an empty clause list and returns false through its existing short-circuit (lines near 174). The run then reaches the default or end_cpn_ids target.
    The change does not alter the newer clauses form, which the issue does not request. I did not re-run the tests. The test results are author-reported (go test ./internal/agent/component/ -count=1 passes). I inspected the source diff only, not the test file contents.
Full details: Out of Scope Changes check

Explanation

The whole-PR diff against the merge base e2cf39ad8 contains one source hunk in internal/agent/component/switch.go (+10 lines). It adds an empty-operand check in the legacy items loop of normalizeLegacyGroup, with a comment that explains the change. The raw summary also reports test additions in internal/agent/component/switch_test.go (+91 lines). Those tests support the objectives of #22666. The clauses path and all other Switch logic are unchanged in the diff. The PR description notes a missing ci label. That is a workflow concern outside the code diff and is not a code change in this PR. No unrelated code change was found.

  • 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 branch with care,
Skips empty operands in the air.
A valid clause can lead the way,
While defaults catch the rest today.
The carrot waits; the tests all pass.

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: 5a24bd6f-3515-41f1-8422-15b30fa58329
Commits

Reviewing files that changed from the base of the PR and between fed836b and 2553e28.

Files selected for processing: 2

  • internal/agent/component/switch.go
  • internal/agent/component/switch_test.go

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

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

LGTM

@6ba3i 6ba3i added the ci Continue Integration label Nov 23, 2026
@JinHai-CN
JinHai-CN merged commit 5b2817b into infiniflow:main Nov 23, 2026
7 checks passed
@1BugKiller
1BugKiller deleted the fix/switch-empty-condition branch November 25, 2026 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Go Switch matches a condition item that has no operand

3 participants