Skip to content

fix: keep paused debug location range valid in chat - #342379

Merged
Connor Peet (connor4312) merged 3 commits into
microsoft:mainfrom
cipheraxat:fix/329777-debug-chat-column-zero
Oct 19, 2026
Merged

Connor Peet (connor4312) merged 3 commits into
microsoft:mainfrom
cipheraxat:fix/329777-debug-chat-column-zero

Conversation

@cipheraxat

@cipheraxat Akshat Anand (cipheraxat) commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #329777

A debug adapter may report line/column 0 for a stack frame when it doesn't know them, which the Debug Adapter Protocol allows (GDB-based adapters commonly do this). "Add to Chat" on a variable, watch expression or scope attaches the paused location through createPausedLocationEntry, which passed that range through as-is. Converting it for chat participants (Range.to → new Position(line, -1)) throws Illegal argument: character must be non-negative, and because prepareHistoryTurns replays the attachment with the history, every later request in the session fails.

When the column is unknown, the paused location now covers the whole line, the same shape the existing empty-range branch produces. When the line is unknown, it attaches the file without a range and tells the model the debugger is paused somewhere in that file (in the named frame) and that the adapter didn't report the line, rather than pointing at line 1. The debug model keeps the adapter's values; only the chat attachment is normalized, so other stack frame consumers are unchanged.

Stack frame range from the adapter Attached range before After
5:3 (empty) 5:3 → 6:1 5:3 → 6:1
5:0 (unknown column) 5:0 → 6:1 5:1 → 6:1
0:0 (unknown line and column) 0:0 → 1:1 Whole file, no range; the description says the line is unknown

Testing

  • New debugChatIntegration.test.ts covers the three cases above. It fails before the fix and passes after; the CallStack, Hover, Source and Session debug suites still pass.
  • To try it manually: debug with an adapter that reports column: 0 for the top frame (for example mock-debug patched to return column: 0), pause, right-click a variable → Add to Chat and send a prompt. Without this change, requests in that chat fail with Illegal argument: character must be non-negative (full trace in the issue).

Sessions that already hit this keep the bad range in their saved history. Guarding the reference conversion in prepareHistoryTurns would cover those too; happy to follow up with that separately if you'd like.

Debug adapters may report a line or column of 0 when it is unknown, as
the Debug Adapter Protocol allows. "Add to Chat" on a variable, watch
expression or scope attached the paused location with that range as-is.
Converting it for chat participants produced a negative position and
threw "Illegal argument: character must be non-negative", and because
the attachment is replayed with the chat history, every later request in
that session failed.

Attach the whole line instead when the line or column is unknown, and add
a unit test for the paused location range.

Fixes microsoft#329777
Copilot AI balanced review requested due to automatic review settings October 18, 2026 09:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused fix preserves existing valid-range behavior and includes regression coverage; tests were not independently executed.

No open issues 🎉

What changed in this PR

Fixes #329777 by normalizing unknown debugger positions in chat attachments without changing the debug model.

Changes:

  • Converts zero-valued starting positions into valid whole-line ranges.
  • Adds regression coverage for valid positions, unknown columns, and unknown lines.
File Description
src/​vs/​workbench/​contrib/​debug/​test/​browser/​debugChatIntegration.test.ts Tests the three paused-location range cases.
src/​vs/​workbench/​contrib/​debug/​browser/​debugChatIntegration.ts Normalizes unknown positions before attaching them to chat.

Review effort: Balanced

When a debug adapter reports line 0 for the paused stack frame, attach
the file without a range and tell the model that the debugger is paused
somewhere in that file (in the named frame) and that the line is
unknown, instead of attaching line 1. An unknown column with a known
line still attaches the whole line.

@connor4312 Connor Peet (connor4312) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks!

@connor4312
Connor Peet (connor4312) merged commit a5c167e into microsoft:main Oct 19, 2026
49 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.144.0 milestone Oct 19, 2026
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.

Debug: "Add to Chat" on a stack frame with column 0 (per-spec "unknown") corrupts Range and permanently poisons the chat session

5 participants