Skip to content

fix: traceroute duplication caused by bypassing deduplication logic#2387

Merged
Yeraze merged 1 commit intomainfrom
fix/traceroute-duplication
Mar 22, 2026
Merged

fix: traceroute duplication caused by bypassing deduplication logic#2387
Yeraze merged 1 commit intomainfrom
fix/traceroute-duplication

Conversation

@Yeraze
Copy link
Owner

@Yeraze Yeraze commented Mar 22, 2026

Summary

  • Root cause: meshtasticManager.ts called databaseService.traceroutes.insertTraceroute() (the repository directly), bypassing the deduplication logic in databaseService.insertTraceroute()
  • The DatabaseService method checks for pending traceroute requests (created when a traceroute is sent) and updates them with the response data instead of inserting a new record
  • By going directly to the repo, every response created a new record alongside the existing pending record, causing duplicate entries in traceroute history

Fix

One-line change: redirect the call from the repository's insertTraceroute() to the DatabaseService's insertTraceroute() which contains the deduplication logic.

Test Plan

  • npx vitest run — 3070 tests pass, 0 failures
  • npm run build — no TypeScript errors
  • ./tests/system-tests.sh — 10/10 pass

🤖 Generated with Claude Code

meshtasticManager.ts called databaseService.traceroutes.insertTraceroute()
(the repository directly), bypassing the deduplication logic in
databaseService.insertTraceroute() which checks for pending traceroute
requests and updates them instead of inserting duplicates.

This caused every traceroute response to create a new record even when
a pending request record already existed, resulting in duplicate entries
in traceroute history.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link

github-actions bot commented Mar 22, 2026

Claude finished @Yeraze's task —— View job


PR Review Analysis

Reviewing this pull request for code quality, potential issues, performance, security, and test coverage.

Todo List:

  • Read the changed file to understand the fix
  • Analyze the deduplication logic in DatabaseService
  • Review code quality and best practices
  • Check for potential bugs or issues
  • Evaluate performance implications
  • Assess security concerns
  • Review test coverage

Code Review Feedback

Excellent Fix - Root Cause Correctly Identified

This PR addresses a clear architectural issue where the code was bypassing the intended deduplication logic. The fix is minimal, targeted, and correct.

Original Problem:

  • src/server/meshtasticManager.ts:5150 called databaseService.traceroutes.insertTraceroute() directly
  • This bypassed the deduplication logic in databaseService.insertTraceroute()
  • Result: Duplicate traceroute records for every response

Fix Applied:

  • Changed to call databaseService.insertTraceroute(tracerouteRecord) instead
  • Now properly uses the deduplication logic that checks for pending requests and updates them

Code Quality & Best Practices

Strengths:

  1. Clear documentation: Excellent inline comments explaining why the change was made
  2. Minimal scope: One-line functional change with no side effects
  3. Proper abstraction: Uses the intended service layer instead of bypassing to repository
  4. Good commit message: Detailed explanation of root cause and impact

Note on async/await:

  • The change from await databaseService.traceroutes.insertTraceroute() to databaseService.insertTraceroute() removes the await
  • This is actually correct - the insertTraceroute() method is synchronous for SQLite and fires async operations for PostgreSQL/MySQL without blocking
  • No functional impact, but worth noting the signature change

Deduplication Logic Analysis 🔍

The deduplication works by:

  1. Pending requests: When a traceroute is initiated, a record with route: null is inserted
  2. Response matching: findPendingTraceroute() looks for records with null routes within 5-minute timeout
  3. Update vs Insert: If pending found, updates existing record; otherwise inserts new one
  4. Cleanup: Maintains history limit of 50 records per node pair

This logic is robust and handles the bidirectional nature of traceroutes correctly.

Potential Issues ⚠️

None identified. The fix is clean and addresses the exact problem described.

Performance Implications 🚀

Positive impact:

  • Eliminates duplicate records: Reduces database bloat
  • Proper indexing usage: Uses intended query paths with proper indexes
  • History cleanup: Automatic cleanup prevents unbounded growth

No performance regressions - the deduplication logic is efficient and uses appropriate database patterns.

Security Concerns 🔒

No security issues identified:

  • No user input validation changes
  • No authentication/authorization impact
  • No exposure of sensitive data
  • Maintains existing access patterns

Test Coverage

Strong test validation:

  • ✅ 3070 unit tests pass (0 failures)
  • ✅ Build succeeds with no TypeScript errors
  • ✅ 10/10 system tests pass
  • ✅ Comprehensive test coverage demonstrates the fix works

Missing test coverage:

  • No specific unit tests for traceroute deduplication logic found
  • This would be a good area for future test coverage enhancement

Recommendation: APPROVE

This is an excellent bug fix that:

  • Correctly identifies and fixes the root cause
  • Uses minimal, targeted changes
  • Has comprehensive test validation
  • Follows established architectural patterns
  • Includes clear documentation

The fix will prevent duplicate traceroute entries while maintaining all existing functionality.

@Yeraze Yeraze merged commit 72b01c2 into main Mar 22, 2026
17 checks passed
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