Skip to content

Fix delegate dedup path scoping#567

Merged
buger merged 1 commit into
mainfrom
fix-delegate-dedup-path-scope
May 21, 2026
Merged

Fix delegate dedup path scoping#567
buger merged 1 commit into
mainfrom
fix-delegate-dedup-path-scope

Conversation

@buger
Copy link
Copy Markdown
Collaborator

@buger buger commented May 21, 2026

Summary

  • Scope search.delegate semantic dedup to prior delegations with the same resolved path instead of the full parent-session history.
  • Keep same-path repeat protection intact while allowing the same concept to be delegated independently across different repos or root paths.
  • Update dedup trace attributes and blocked-message context so they only report same-path prior delegations.

Tests

  • npm test -- tests/unit/search-delegate.test.js --runInBand
  • git diff --check
  • Repo pre-commit hook passed during commit.

Out of scope

  • No changes to non-delegate search dedup behavior.
  • No changes to delegate prompt wording or model selection.

Fixes #566

@buger buger merged commit 4a8ae04 into main May 21, 2026
13 checks passed
@probelabs
Copy link
Copy Markdown
Contributor

probelabs Bot commented May 21, 2026

PR Overview: Fix Delegate Dedup Path Scoping

Summary

This PR fixes a bug in the delegate semantic deduplication logic by scoping duplicate detection to the same resolved path instead of across all previous delegations in the parent session. Previously, the system would block semantically similar queries even when they targeted different repositories or root paths, preventing legitimate multi-repo searches.

Files Changed

  • npm/src/tools/vercel.js (-9 +7 lines)
  • npm/tests/unit/search-delegate.test.js (+61 lines)

Architecture & Impact Assessment

What This PR Accomplishes

Before: Delegate deduplication compared queries against ALL previous delegations in the parent session, regardless of path. This meant asking "FIPS validation" in /workspace/repo-a would block the same query in /workspace/repo-b.

After: Deduplication now only considers prior delegations with the exact same resolved path (delegatePath). The same concept can now be delegated independently across different repos or root paths while still preventing exact duplicates within the same path.

Key Technical Changes

  1. Path-based filtering (vercel.js:722-723):

    const delegatePath = searchPath || '';
    const samePathDelegations = previousDelegations.filter(d => d.path === delegatePath);
  2. Conditional deduplication (vercel.js:726):
    Changed from if (previousDelegations.length > 0) to if (samePathDelegations.length > 0)

  3. Updated telemetry attributes (vercel.js:743-744):

    • dedup.previous_count now reflects same-path count only
    • dedup.previous_queries only includes same-path queries
  4. Updated block message context (vercel.js:761):
    Blocked messages now only reference same-path prior delegations

System Components Affected

  • Search delegate tool: Core deduplication logic in searchTool() function
  • Telemetry/tracing: Span attributes for deduplication now scoped correctly
  • User experience: Multi-repo searches now work as expected

Data Flow

graph TD
    A[User submits search query] --> B{Has same-path delegations?}
    B -->|No| C[Skip dedup check]
    B -->|Yes| D[Run LLM semantic dedup]
    D --> E{Is duplicate?}
    E -->|Yes| F[Block delegation]
    E -->|No| G[Allow delegation]
    C --> G
    G --> H[Execute delegate search]
    H --> I[Store in previousDelegations with path]
    
    style B fill:#f9f,stroke:#333,stroke-width:2px
    style I fill:#bbf,stroke:#333,stroke-width:2px
Loading

Scope Discovery & Context Expansion

Direct Impact

Related Components (Inferred)

  • checkDelegateDedup(): Helper function that performs the actual LLM-based semantic comparison (called from vercel.js:750, 757)
  • Delegate session management: previousDelegations array structure with {query, path} objects
  • Tracing system: options.tracer.withSpan() integration for observability

Out of Scope (Explicitly)

  • Non-delegate search dedup behavior unchanged
  • Delegate prompt wording unchanged
  • Model selection logic unchanged

Testing

The new test (scopes delegate semantic dedup to the same path) validates:

  1. Same query to different paths (repo-a, repo-b) both execute
  2. Same query to same path triggers dedup check
  3. Dedup telemetry attributes reflect same-path count only
  4. Block messages only reference same-path prior queries

Review Notes

  • Complexity: Low - straightforward filtering logic change
  • Risk: Low - scoped reduction in deduplication coverage (less aggressive blocking)
  • Backward compatibility: Improves behavior; no breaking changes to API
Metadata
  • Review Effort: 2 / 5
  • Primary Label: bug

Powered by Visor from Probelabs

Last updated: 2026-05-21T17:28:59.087Z | Triggered by: pr_opened | Commit: 9a0686e

💡 TIP: You can chat with Visor using /visor ask <your question>

@probelabs
Copy link
Copy Markdown
Contributor

probelabs Bot commented May 21, 2026

✅ Security Check Passed

No security issues found – changes LGTM.

Performance Issues (1)

Severity Location Issue
🟡 Warning npm/src/tools/vercel.js:722
The new `samePathDelegations` filter creates a new array on every delegate search by iterating through the entire `previousDelegations` array. This is O(n) per delegation, which becomes inefficient as the session grows with many delegations across different paths. For long-running sessions with hundreds of delegations, this repeated filtering could cause measurable performance degradation.
💡 SuggestionConsider maintaining a Map or object indexed by path for O(1) lookups instead of O(n) filtering. For example: `const delegationsByPath = new Map(); delegationsByPath.set(delegatePath, delegationsByPath.get(delegatePath) || []);` This would eliminate the linear scan on every delegation.
🔧 Suggested Fix
const samePathDelegations = (delegationsByPath.get(delegatePath) || []);

✅ Security Check Passed

No security issues found – changes LGTM.

\n\n \n\n

Performance Issues (1)

Severity Location Issue
🟡 Warning npm/src/tools/vercel.js:722
The new `samePathDelegations` filter creates a new array on every delegate search by iterating through the entire `previousDelegations` array. This is O(n) per delegation, which becomes inefficient as the session grows with many delegations across different paths. For long-running sessions with hundreds of delegations, this repeated filtering could cause measurable performance degradation.
💡 SuggestionConsider maintaining a Map or object indexed by path for O(1) lookups instead of O(n) filtering. For example: `const delegationsByPath = new Map(); delegationsByPath.set(delegatePath, delegationsByPath.get(delegatePath) || []);` This would eliminate the linear scan on every delegation.
🔧 Suggested Fix
const samePathDelegations = (delegationsByPath.get(delegatePath) || []);
\n\n ### ✅ Quality Check Passed

No quality issues found – changes LGTM.


Powered by Visor from Probelabs

Last updated: 2026-05-21T17:14:26.539Z | Triggered by: pr_opened | Commit: 9a0686e

💡 TIP: You can chat with Visor using /visor ask <your question>

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.

Delegate-level dedup should be scoped per path/repo, not global

1 participant