Skip to content

improvement(search-replace): dedupe double indexed segments#4517

Merged
icecrasher321 merged 3 commits intostagingfrom
improvement/search-replace
May 8, 2026
Merged

improvement(search-replace): dedupe double indexed segments#4517
icecrasher321 merged 3 commits intostagingfrom
improvement/search-replace

Conversation

@icecrasher321
Copy link
Copy Markdown
Collaborator

Summary

Deduplicate workflow-ref resolver + text ref double counting. Helps keeps UI counts accurate.

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link
Copy Markdown

vercel Bot commented May 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped May 8, 2026 7:11pm

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented May 8, 2026

PR Summary

Low Risk
Low risk: limits search results client-side by collapsing overlapping matches within the same subblock/range scope, primarily affecting UI counts and which match is selected for overlap cases.

Overview
Prevents double-counting in workflow search/replace by deduplicating overlapping matches (e.g., a text hit overlapping a workflow-reference) before rendering and navigation.

Adds dedupeOverlappingWorkflowSearchMatches in resources/resolvers.ts to collapse overlaps only within the same block/subblock/valuePath, preferring the narrower range (or non-text when ranges are equal), and includes new Vitest coverage for the overlap-selection rules and field-scope isolation.

Reviewed by Cursor Bugbot for commit 3fb4354. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 8, 2026

Greptile Summary

This PR fixes double-counting in the workflow search-replace panel by adding a dedupeOverlappingWorkflowSearchMatches utility that removes redundant matches when a text hit and a workflow-reference/environment hit cover overlapping character ranges in the same field. It also removes a duplicate workflow-change guard from the chat PATCH route.

  • resolvers.ts: Introduces a kind-priority table and five helper functions that implement an overlap-aware dedup pass; narrower range wins over wider, then kind priority (workflow-reference > environment > text) breaks ties at equal span.
  • workflow-search-replace.tsx: Applies the dedup to hydratedMatches so both the displayed count and the replacement plan (buildWorkflowSearchReplacePlan) operate on the deduplicated set.
  • resolvers.test.ts: New test file with four cases covering the primary dedup scenarios.

Confidence Score: 5/5

Safe to merge — the dedup pass is applied consistently to both the display list and the replacement plan, and the route cleanup removes a redundant guard without weakening any validation.

All four changed files make narrow, well-tested changes. The dedup function correctly handles the text vs. workflow-reference overlap case that caused double-counting, the replacement plan now uses the same deduped list as the UI, and the duplicate chat guard removal leaves the remaining guard intact.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/lib/workflows/search-replace/resources/resolvers.ts Adds deduplication logic for overlapping workflow search matches, with a kind-priority table and helper functions; logic is correct for the text vs. workflow-reference case.
apps/sim/lib/workflows/search-replace/resources/resolvers.test.ts New test file covering four key dedup scenarios: narrower text win, same-span kind-priority, equal-span non-text priority stability, and different-field non-collapse.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/search-replace/workflow-search-replace.tsx Wraps the filtered hydratedMatches with dedupeOverlappingWorkflowSearchMatches; both the UI count and the replacement plan now use the deduped list.
apps/sim/app/api/chat/manage/[id]/route.ts Removes a duplicate guard that rejected workflowId changes; an equivalent guard with clearer messaging already exists earlier in the handler.

Reviews (2): Last reviewed commit: "address comments" | Re-trigger Greptile

Comment thread apps/sim/lib/workflows/search-replace/resources/resolvers.ts Outdated
@icecrasher321
Copy link
Copy Markdown
Collaborator Author

@greptile

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.

1 participant