DebugMCP icon indicating copy to clipboard operation
DebugMCP copied to clipboard

get_debug_status mixes the selected frame ID with top-frame source metadata

Open hahnfk opened this issue 1 month ago • 1 comments

The program stops inside Synchronous, but the user selects its caller Main to inspect that caller's variables. Expression evaluation correctly follows Main. The status response reports Main's frame ID together with the name and source of Synchronous, without saying that these fields describe two different frames. This report asks for that distinction to be made explicit.

Environment

  • Windows x64; VS Code 1.143.1.
  • DebugMCP extension 2.4.3; C# extension 2.160.4; C# Dev Kit 3.40.215.
  • .NET SDK 10.0.402; runtime 10.0.13; Debug build with portable PDBs.
  • Reproduction project: hahnfk/debugmcp-repro.

Reproduction steps

  1. Clone and build the sample in a new folder:

    git clone --branch main https://github.com/hahnfk/debugmcp-repro.git
    cd debugmcp-repro
    dotnet restore DebugMcpRepro.csproj --configfile NuGet.Config
    dotnet build DebugMcpRepro.csproj --configuration Debug --no-restore
    
  2. Open the checkout in a separate VS Code window. Use the DebugMCP connection associated with that workspace for all following MCP calls. The included workspace settings use http://localhost:3002/mcp.

  3. Call add_breakpoint with the absolute path to Scenarios.cs and line: 12 (marker BREAK A).

  4. Call start_debugging with these inputs, replacing <absolute-checkout> with the actual absolute checkout path:

    {
      "fileFullPath": "<absolute-checkout>/Scenarios.cs",
      "workingDirectory": "<absolute-checkout>",
      "configurationName": "Repro A - synchronous"
    }
    
  5. At the breakpoint, call get_debug_status and evaluate localNumber through MCP to record the initial top-frame context.

  6. In Run and Debug → CALL STACK, select the caller Program.Main(string[] args) Line 20. Do not step or resume execution.

  7. In Debug Console, evaluate 1+1, args.Length, and localNumber as three separate submissions, confirming each with Enter.

  8. On the same MCP connection, call get_debug_status, evaluate those same three expressions separately with evaluate_expression, then call get_debug_status again. Keep Program.Main selected throughout.

Process, thread, and frame IDs are assigned locally and can change between runs and machines. No particular PID, thread ID, or frame ID is required. Compare identifiers only within the same paused session; select frames by their method names and source positions.

Expected result

The response should distinguish these two contexts:

  • Physical execution stop: Scenarios.Synchronous, Scenarios.cs:12.
  • Selected evaluation frame: Program.Main, Program.cs:20.

If state.frameId identifies the selected Main frame, its associated name and source metadata should identify that frame. Alternatively, expose stopped-frame and selected-frame information as explicitly separate fields/objects.

The selected Main frame should evaluate 1+1 to 2 and args.Length to 1. localNumber should produce CS0103 there, because that local belongs to Scenarios.Synchronous.

Actual result

The direct Console and MCP expressions both use the selected Main scope correctly:

Expression Direct Debug Console MCP after selecting Main
1+1 2 2
args.Length 1 1
localNumber CS0103, expected CS0103, expected

After selecting Program.Main, get_debug_status returned the following fields. The frame ID 1001 identifies the selected Main frame in this local run, but the name and source still identify Synchronous:

{
  "frameId": 1001,
  "frameName": "DebugMcpRepro.dll!DebugMcpRepro.Scenarios.Synchronous() Line 12",
  "fileName": "Scenarios.cs",
  "currentLine": 12
}

Calling get_debug_status again after the expression evaluations returned the same fields.

These IDs are examples from the recorded local run, not reproduction constants. The physical stop correctly remains at Scenarios.cs:12; selecting a caller does not move execution. The inconsistency is that the response does not distinguish that stopped-frame metadata from the selected evaluation frame's identity. For example, an agent trusting frameName: Synchronous could expect localNumber to be available. Its evaluation actually uses the selected Main frame, where the resulting CS0103 is correct. The status should make that evaluation context clear; it should not imply that all returned frame fields belong to the same frame.

Evidence and related report

Findings, full procedure, and curated synthetic evidence contain the recorded source positions and MCP status responses before and after expression evaluation.

Issue #82 concerns stale source positions after stepping. This case changes the selected caller without any step or execution transition.

Investigation tooling

This investigation and its reproduction work were carried out with assistance from OpenAI Codex.

  • Codex desktop app version: 26.1021.31345 (build 21828).
  • Version verified on 2026-10-25, when this tooling disclosure was added.

The desktop app version used during the original 2026-10-24 investigation was not recorded; the version above identifies the environment at disclosure time.

hahnfk avatar Oct 24 '26 09:10 hahnfk

Confirmed the frame-metadata mismatch in the VS Code executor: getCurrentDebugState() takes frameId/threadId from activeStackItem, but extractFrameName() used stackFrames[0] for the name and source. Selecting a caller therefore changes evaluation context without changing the reported metadata. PR #184 keeps those fields aligned with the selected frame, preserves adapter stack order, and leaves name/source unavailable if the selected frame is absent from the bounded response. Both regression tests failed before the fix; compilation, lint, and 72 focused extension tests passed after it. I checked the open PRs: #149 concerns sourceless pause detection and does not address this mismatch. #184 is open and unmerged, pending maintainer confirmation.

ozzafar avatar Oct 25 '26 10:10 ozzafar