fix(lmtool): stop double-counting classNameDetection on every invoke#1651
Open
wenytang-ms wants to merge 2 commits into
Open
fix(lmtool): stop double-counting classNameDetection on every invoke#1651wenytang-ms wants to merge 2 commits into
wenytang-ms wants to merge 2 commits into
Conversation
findFullyQualifiedClassName was called twice for every invocation that used a simple class name: 1. inside constructDebugCommand to resolve the actual command 2. immediately after, to build the targetInfo message shown to the model Each call also emitted its own classNameDetection telemetry event, so the classNameDetection success/failure counts in ddtelfiltered were inflated by 2x. This makes the apparent ~49% noPackage failure rate look much worse than reality (the true rate is closer to ~25% before accounting for other root causes addressed in #1650). Fix: resolve the detection once at the caller, emit telemetry once, and pass the resolved name into both constructDebugCommand and the targetInfo branch. Side benefit: removes a redundant file system walk from the hot launch path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR refactors debugJavaApplication to resolve a simple Java class name to a fully-qualified class name once per invocation and reuse that result for both command construction and the user-facing targetInfo message.
Changes:
- Adds a single, caller-owned
findFullyQualifiedClassNamelookup and reuses its result across the launch flow. - Updates
constructDebugCommandto accept an optionalpreDetectedClassNameto avoid redundant lookups and centralize telemetry emission at the caller.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Reviewer correctly pointed out that the original main branch only had a duplicate findFullyQualifiedClassName FS walk in the targetInfo branch; the recordLaunchInternal({name:'classNameDetection'}) emission was only inside constructDebugCommand, not duplicated. The 'inflates noPackage by 2x' rationale was wrong — observed metrics are not inflated by the dup.
Reworded both comments to focus on the FS-walk dedup + ownership clarity. Functional code unchanged; only comments updated.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
debugJavaApplication(thedebug_java_applicationLMT handler) was callingfindFullyQualifiedClassNametwice per invocation for the simple-class-name path:constructDebugCommand(to resolve the FQN for the actualjava -cp ... ClassNamecommand), where it also emittedrecordLaunchInternal({name: 'classNameDetection', detected: <bool>}).constructDebugCommand, just tobuild the user-facing
targetInfostring ("com.example.App (detected from App)").findFullyQualifiedClassNamewalkssrc/main/java(or equivalent) recursivelyup to
MAX_FILE_SEARCH_DEPTH, stats every.javafile, and reads candidatesto extract the package. Doing it twice on every launch is wasted work on the
hot path.
Fix
classNameDetectiontelemetry emit) intothe caller (
debugJavaApplication, Step 3), so it runs exactly once perinvocation.
preDetectedClassName?: string | nulltoconstructDebugCommand. When the caller has already resolved the FQN, itpasses that result in and
constructDebugCommandskips re-detection.targetInfoformatting block — nosecond FS walk.
Scope
debugjavacommand, and the telemetry event content are identical.classNameDetectionstill fires exactlyonce per invocation (it always did; the second call site was not emitting).
Test
npx tsc --noEmit— cleannpm run tslint— cleanValidation plan
This PR is a refactor, so there is no metric we expect to move. Post-ship
sanity check: per-invocation
classNameDetectionevent volume should stayflat (1:1 with
debug_java_application.invoke). If it drops by ~50%, thatwould actually confirm a pre-existing 2× emission elsewhere we missed; if it
stays equal, the refactor is a pure perf win, which matches the code reading.
Related
All three can land in any order.
classNameDetection.failedevent (withfailureReason∈noPackageDeclaration / fileNotFound / sourceDirMissing / parseError).debugagent/06-深度诊断-PR定向-2026-06-09.md.Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com