Skip to content

fix: add json output alias on Retrieval node - #20394

Merged
wangq8 merged 4 commits into
infiniflow:mainfrom
flyingwhit:fix/retrieval-json-output
Sep 30, 2026
Merged

wangq8 merged 4 commits into
infiniflow:mainfrom
flyingwhit:fix/retrieval-json-output

Conversation

@flyingwhit

Copy link
Copy Markdown
Contributor

Summary

Fix the Retrieval node's json output when a search returns zero hits.

The tool envelope tags chunks with omitempty, so an empty result dropped the key entirely — the node never wrote json into canvas state, and any downstream {{@JSON}} template failed the whole run with Can't find variable: '@JSON'.

  • internal/agent/component/universe_a_wrappers.go: all returns routed through normalizeRetrievalOutputs; json declared in Outputs().
  • Tests: component-level coverage for empty/error envelopes and the json/chunks mirror; canvas-level Begin → Retrieval → Message regression test asserting a zero-hit search resolves {{retrieval_0@json}} to [] without error.

@flyingwhit flyingwhit changed the title Fix/retrieval json output fix: add json output alias on Retrieval node Sep 29, 2026
@flyingwhit flyingwhit added the ci Continue Integration label Sep 29, 2026
@flyingwhit
flyingwhit requested a review from wangq8 September 29, 2026 11:37
@coderabbitai

coderabbitai Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 61532800-5d75-42a4-9df7-8def04738136

📥 Commits

Reviewing files that changed from the base of the PR and between 48cb8c3 and 42080f1.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: dbf870c3-6c11-47e6-bfed-7f6ad6ec2a8a

📥 Commits

Reviewing files that changed from the base of the PR and between fc578ea and 48cb8c3.

📒 Files selected for processing (3)
  • internal/agent/canvas/retrieval_json_output_test.go
  • internal/agent/component/retrieval_empty_response_test.go
  • internal/agent/component/universe_a_wrappers.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.


📝 Walkthrough

Walkthrough

Retrieval responses now provide non-nil json and chunks arrays for empty results. Missing-dataset responses include empty formalized_content. Component and canvas tests cover empty and nonempty retrieval results.

Changes

Retrieval Output Normalization

Layer / File(s) Summary
Normalize retrieval outputs
internal/agent/component/universe_a_wrappers.go, internal/agent/component/retrieval_empty_response_test.go
Retrieval invocation normalizes chunks to an empty array when absent or nil. It sets json to chunks when json is absent or nil, and preserves existing non-nil json. The missing-dataset response includes empty formalized_content. Component tests check empty outputs, the missing-dataset error value, and matching json and chunks for a nonempty result.
Verify outputs in a canvas
internal/agent/canvas/retrieval_json_output_test.go
A zero-hit retrieval test checks that the canvas exposes an empty retrieval_0@json array and resolves the message to chunks: [].

Priority: ⬇️ Low

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

Change: Bug fix

Suggested reviewers: harry-hz-zhang

Merge Risk: ⚪ Minimal · up to 48cb8

The change makes Retrieval nodes expose an empty json array on zero-hit searches, so downstream json templates resolve instead of failing. No merge-blocking risk was identified.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 48cb8

The change is narrow and does not add retrieval privileges. However, workflows reading only the JSON array can now continue after a missing-dataset error, creating a limited failure-handling risk.

Retained concerns

  • Low · reliability · inferred: Missing-dataset responses now expose usable empty arrays alongside _ERROR. Consumers referencing only json can treat this configuration failure as a successful empty search and continue, reducing failure containment for that wiring. The error marker remains intact, and no security-sensitive consumer or privilege bypass was demonstrated.
Security review details

Security Blast Radius

  • inferred — The demonstrated change affects workflow consumers of Retrieval outputs. The examined request construction and delegation do not expand tenant, dataset, or service access; downstream error interpretation is the remaining exposure question.

Trust Boundaries and Controls

  • observed — Dataset resolution and context-derived TenantID remain upstream of Search. A missing-dataset wrapper response exits without dispatching a search, and service errors remain real invocation errors rather than normalized empty successes. This verifies the local propagation path, not the backend's complete authorization enforcement.

Resilience and Maintainability Implications

  • observed — Failure interpretation remains consumer-dependent: Agent explicitly recognizes the missing-dataset _ERROR marker, whereas the examined Message template path resolves text without that check. The new arrays preserve the marker but remove the incidental absent-json failure.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding the json output alias to the Retrieval node.
Description check ✅ Passed The description includes the required Summary section, explains the zero-hit failure, identifies the implementation changes, and lists relevant test coverage.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 3 files.
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

A rabbit checks the empty tray,
Two tidy arrays now greet the day.
The canvas prints its chunks in view,
Even when the search finds none to chew.
I thump my paws; the outputs line up right.

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

@wangq8
wangq8 requested a review from buua436 September 30, 2026 11:35
@wangq8
wangq8 merged commit 9766c8c into infiniflow:main Sep 30, 2026
6 checks passed
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.

2 participants