Skip to content

Refactor(task): collapse duplicated debug-result helpers - #17937

Merged
yuzhichang merged 1 commit into
infiniflow:mainfrom
xugangqiang:refactor/task-debug-result-dsl-dedup
Aug 6, 2026
Merged

yuzhichang merged 1 commit into
infiniflow:mainfrom
xugangqiang:refactor/task-debug-result-dsl-dedup

Conversation

@xugangqiang

Copy link
Copy Markdown
Contributor

Summary

Collapses three duplicated/dead code smells in the canvas debug-result path of internal/ingestion/task (remaining findings #2/#3/#4 from the package CTO review):

  • impl tags api #2 — vector-key stripping duplication. isVectorKey (the full stripper: fixed legacy keys vector/embedding/feature/q_vec plus the q_<dim>_vec pattern) was re-implemented as a weaker inline copy in the golden-compare tool (tool/compare_pipeline_golden.go) that only matched q_<dim>_vec and let real vectors leak into the diff. Exported as IsVectorKey and reused by the tool.
  • init requirements #3 — near-duplicate deep copy. deepCopy and deepCopyStrip were identical walkers differing only in vector stripping. Parameterized deepCopy(v any, stripVector bool) any and deleted deepCopyStrip.
  • add PR MD #4 — redundant switch. lookupComponentOutput had two switch cases with identical bodies (both the map[string]map[string]any and map[string]any state shapes). Unified into a single found/ok resolution; nested-state and flat-fallback semantics unchanged.

Why

These are the remaining items from the internal/ingestion/task review. They remove duplicated logic, a second recursive walker, and copy-paste branching, and make the golden-compare tool agree with the production vector stripping rule.

Test plan

  • internal/ingestion/task/tool/compare_pipeline_golden_test.go: TestSanitizeProcessed_StripsVectorKeys (red→green) asserts the tool now strips the full vector-key set (vector/embedding/feature/q_vec/q_<dim>_vec).
  • Existing debug_result_dsl_test.go / debug_log_sink_test.go updated for the new deepCopy(v, stripVector) signature.
  • ./build.sh --test ./internal/ingestion/task/... passes; the full unit suite is green.

Changes

  • 6 files changed, +99 / -51

- #2: export IsVectorKey from debug_result_dsl.go and have the golden
  compare tool reuse it instead of a weaker inline check that only caught
  q_<dim>_vec and let fixed legacy keys (vector/embedding/feature/q_vec)
  leak into the diff.
- #3: parameterize deepCopy(v, stripVector) and delete the near-duplicate
  deepCopyStrip; vector stripping is now a single flag, no second walker.
- #4: unify the two identical switch cases in lookupComponentOutput into a
  shared found/ok resolution; nested-state and flat-fallback semantics kept.

Tests: add TestSanitizeProcessed_StripsVectorKeys (red->green) and update
existing deepCopy / deepCopyStrip_call references. task/indexdoc/tool all pass.

Co-Authored-By: CodeBuddy Code <[email protected]>
@xugangqiang xugangqiang added ci Continue Integration ☯️ refactor Pull request that refactor/refine code size:M This PR changes 30-99 lines, ignoring generated files. labels Aug 6, 2026
@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR consolidates vector-key detection into IsVectorKey, adds configurable recursive deep copying, applies vector filtering to runtime debug output, and broadens pipeline sanitization tests.

Changes

Vector-aware debug output handling

Layer / File(s) Summary
Conditional deep-copy implementation
internal/ingestion/task/debug_result_dsl.go, internal/ingestion/task/debug_result_dsl_test.go
IsVectorKey is exported. deepCopy now conditionally removes vector keys recursively. Static parameters and graphs remain unfiltered, while runtime payloads are filtered.
Debug output lookup and serialization
internal/ingestion/task/debug_result_dsl.go, internal/ingestion/task/debug_log_sink.go, internal/ingestion/task/debug_log_sink_test.go
Component output lookup supports both nested state map types. Debug output serialization uses deepCopy(out, true).
Pipeline sanitization coverage
internal/ingestion/task/tool/compare_pipeline_golden.go, internal/ingestion/task/tool/compare_pipeline_golden_test.go
Pipeline sanitization uses task.IsVectorKey and tests removal of vector and bookkeeping fields while preserving text.

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

Possibly related PRs

Suggested reviewers: jinhai-cn, yingfeng, yuzhichang

Poem

A rabbit copies fields with care,
Strips bright vectors from the air.
Static graphs stay whole and true,
Runtime payloads shed a few.
Tests guard text from vanishing—
Hop, hop, clean logs are flourishing!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.
Description check ✅ Passed The description includes the required Summary section and clearly explains the changes, rationale, and test plan.
Title check ✅ Passed The title clearly and concisely summarizes the refactoring of duplicated debug-result helpers.

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.

@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)
internal/ingestion/task/tool/compare_pipeline_golden_test.go (1)

23-29: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove migration history from the test comment.

Describe the current sanitizeProcessed contract. Do not document the removed inline implementation.

As per coding guidelines, Go doc comments must align with the current runtime path rather than migration history.

🤖 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 `@internal/ingestion/task/tool/compare_pipeline_golden_test.go` around lines 23
- 29, Update the comment above TestSanitizeProcessed_StripsVectorKeys to
describe only the current sanitizeProcessed behavior and its contract: vector
keys are removed using the shared task.IsVectorKey logic. Remove references to
the previous inline check, legacy keys, migration history, and implementation
changes.

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.

Inline comments:
In `@internal/ingestion/task/tool/compare_pipeline_golden_test.go`:
- Around line 34-37: Update the test fixture and expected-removal list in the
relevant comparison test to include the legacy vector key feature in both
places. Ensure the assertion loop verifies that feature is removed while
preserving the existing coverage for the other vector keys.

---

Nitpick comments:
In `@internal/ingestion/task/tool/compare_pipeline_golden_test.go`:
- Around line 23-29: Update the comment above
TestSanitizeProcessed_StripsVectorKeys to describe only the current
sanitizeProcessed behavior and its contract: vector keys are removed using the
shared task.IsVectorKey logic. Remove references to the previous inline check,
legacy keys, migration history, and implementation changes.
🪄 Autofix

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 Plus

Run ID: 2bee03e1-2475-423c-88e5-e830c1f703f7

📥 Commits

Reviewing files that changed from the base of the PR and between 7d0d1ab and 1598b08.

📒 Files selected for processing (6)
  • internal/ingestion/task/debug_log_sink.go
  • internal/ingestion/task/debug_log_sink_test.go
  • internal/ingestion/task/debug_result_dsl.go
  • internal/ingestion/task/debug_result_dsl_test.go
  • internal/ingestion/task/tool/compare_pipeline_golden.go
  • internal/ingestion/task/tool/compare_pipeline_golden_test.go

Comment on lines +34 to +37
"vector": []float64{0.1},
"embedding": []float64{0.2},
"q_1024_vec": []float64{0.3},
"q_vec": []float64{0.4},

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Cover the feature vector key.

The comment states that feature is a fixed legacy vector key. The fixture does not include it. The assertion loop does not verify that it is removed. Add feature to both lists so this test protects the full documented contract.

Proposed fix
 			"vector":               []float64{0.1},
 			"embedding":            []float64{0.2},
+			"feature":              []float64{0.25},
 			"q_1024_vec":           []float64{0.3},
 			"q_vec":                []float64{0.4},
@@
-	for _, k := range []string{"vector", "embedding", "q_1024_vec", "q_vec"} {
+	for _, k := range []string{"vector", "embedding", "feature", "q_1024_vec", "q_vec"} {

Also applies to: 49-53

🤖 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 `@internal/ingestion/task/tool/compare_pipeline_golden_test.go` around lines 34
- 37, Update the test fixture and expected-removal list in the relevant
comparison test to include the legacy vector key feature in both places. Ensure
the assertion loop verifies that feature is removed while preserving the
existing coverage for the other vector keys.

@xugangqiang xugangqiang changed the title refactor(task): collapse duplicated debug-result helpers (#2/#3/#4) Refactor(task): collapse duplicated debug-result helpers Aug 6, 2026
@xugangqiang xugangqiang added ci Continue Integration and removed ci Continue Integration labels Aug 6, 2026
@yuzhichang

Copy link
Copy Markdown
Member

LGTM

@yuzhichang
yuzhichang merged commit 477469f into infiniflow:main Aug 6, 2026
12 checks passed
@xugangqiang
xugangqiang deleted the refactor/task-debug-result-dsl-dedup branch August 7, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration ☯️ refactor Pull request that refactor/refine code size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants