Skip to content

fix(tracespans): update tracespans tool calls to accurately display inputs for successive identical tool calls#3140

Merged
waleedlatif1 merged 1 commit intostagingfrom
fix/trace-spans
Feb 5, 2026
Merged

fix(tracespans): update tracespans tool calls to accurately display inputs for successive identical tool calls#3140
waleedlatif1 merged 1 commit intostagingfrom
fix/trace-spans

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • update tracespans tool calls to accurately display inputs for successive identical tool calls

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

vercel bot commented Feb 5, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Feb 5, 2026 3:21am

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 5, 2026

Greptile Overview

Greptile Summary

Fixed critical bug where multiple tool calls to the same tool (e.g., search_tool called 3 times) would incorrectly display the first call's inputs/outputs for all subsequent calls.

Key Changes:

  • Replaced Array.find() lookup (which always returns first match) with sequential matching using a Map-based index tracker
  • Tool calls are now grouped by normalized name in toolCallsByName Map, and toolCallIndices tracks position for each tool name
  • Each time segment matches against the next tool call in sequence for that specific tool name
  • Added comprehensive test case validating sequential matching with 3 identical tool calls with different inputs/outputs

Additional Improvements:

  • Converted tests to it.concurrent for better test performance in both files
  • Refactored test setup in snapshot service tests to avoid shared state

Confidence Score: 5/5

  • This PR is safe to merge with no concerns
  • The fix correctly addresses the bug with a clean, well-tested solution. The logic change is isolated, properly tested with a new comprehensive test case, and doesn't introduce any side effects. Test refactoring is a bonus improvement.
  • No files require special attention

Important Files Changed

Filename Overview
apps/sim/lib/logs/execution/trace-spans/trace-spans.ts Fixed tool call matching to use sequential order instead of name-only lookup, preventing incorrect input/output display for repeated tool calls
apps/sim/lib/logs/execution/trace-spans/trace-spans.test.ts Added comprehensive test for sequential tool call matching and converted tests to concurrent execution with improved descriptions
apps/sim/lib/logs/execution/snapshot/service.test.ts Refactored tests to use concurrent execution and moved service instantiation into individual test cases

Sequence Diagram

sequenceDiagram
    participant TS as timeSegments
    participant Map as toolCallsByName Map
    participant Idx as toolCallIndices Map
    participant Seg as Segment Processing
    
    Note over TS,Seg: Building trace spans for agent execution
    
    TS->>Map: Group tool calls by normalized name
    loop For each toolCall
        Map->>Map: toolCallsByName.set(normalizedName, [...calls])
    end
    
    Note over Idx: Initialize index tracking (empty)
    
    loop For each timeSegment
        alt segment.type === 'tool'
            Seg->>Map: Get calls for normalizedName
            Seg->>Idx: Get current index (default 0)
            Map-->>Seg: Return toolCallsForName[currentIndex]
            Seg->>Idx: Increment index for this tool name
            Seg->>Seg: Match segment to tool call sequentially
        else segment.type === 'model'
            Seg->>Seg: Create model segment
        end
    end
    
    Note over Seg: Result: Each tool segment matched<br/>to correct tool call by order
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1 waleedlatif1 merged commit 2147309 into staging Feb 5, 2026
12 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/trace-spans branch February 5, 2026 03:32
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