Skip to content

fix(python): a logpoint whose message cannot evaluate is refused when it is set, with the form that works - #1346

Closed
debugmcpdev wants to merge 4 commits into
mainfrom
fix/1334-python-logmessage
Closed

debugmcpdev wants to merge 4 commits into
mainfrom
fix/1334-python-logmessage

Conversation

@debugmcpdev

Copy link
Copy Markdown
Collaborator

What

set_breakpoint with a Python logMessage such as "stale={entry!r}" answered success, and when the line was hit the logged line was invalid syntax (<string>, line 1). In agent trials every one of 5 messages that used !r failed this way and none of 36 without it, and the agents spent several turns setting the logpoint again (#1334).

debugpy turns a log message into an expression by taking the text between each pair of braces as a Python expression (convert_dap_log_message_to_expression in the vendored pydevd), stores it without compiling it, and evaluates it at each hit. entry!r and total:.2f are f-string syntax, not expressions.

A message that is certain to fail when hit is now refused when it is set, with the form that works:

Invalid logpoint: {entry!r}: debugpy evaluates the text between braces as a Python expression, and !r is f-string syntax, not an expression; use {repr(entry)} instead.
logMessage debugpy logs Now
{x}, {x != 1}, {items[1:3]}, {d['a:b']}, {(lambda v: v)(x)}, { {'k': total} }, {y := 7} the value accepted, untouched
{x!r}, {x!s}, {x!a} invalid syntax (<string>, line 1) refused; names {repr(x)}, {str(x)}, {ascii(x)}
{total:.2f} invalid decimal literal (<string>, line 1) refused; names {format(total, '.2f')}
{x!r:>10} invalid syntax (<string>, line 1) refused; names {format(repr(x), '>10')}
{{literal}} name 'literal' is not defined (debugpy has no {{ escape: it is a set literal) accepted: not a syntax error

Every row was run as a real logpoint through the built server against debugpy 1.8.20, and each replacement the refusal names logs the value. Anything the check cannot be certain about is accepted.

How it is built

  • validateLogMessage, the existing policy member that the JavaScript policy uses to refuse a logpoint that cannot compile, gains a Python implementation (packages/shared/src/utils/python-logpoint.ts). No new member; the member now has two users.
  • The scanner follows debugpy's own brace matching (nested braces counted, no string awareness for the braces themselves) and looks for a conversion or a format spec only at the top level of a group, outside brackets, parentheses, nested braces and string literals; a lambda's colon and := are not format specs.

Verification

  • 55 unit tests over the table and the edges of "top level"; the server's refusal path for Python before and after launch; an integration test that gets the refusal for {x!r} and reads the value logged by {repr(x)}.
  • Unit project: 446 files, 10,058 passed. tests/adapters/python: 77 passed. typecheck:all, lint, check-docs, changelog:check pass.
  • The review and the Linux run: in progress; results will be added here.

Not in this change

The logMessage parameter's description in the tool list (another pull request is changing that file); a logpoint's condition.

Review

Written by a Gemini worker (Google) from the manager's brief and the design call on the issue. A Codex review (OpenAI) with a mutation pass follows before this leaves draft.

Fixes #1334.

🤖 Generated with Claude Code

https://claude.ai/code/session_015BDrn82vMcRzWFDD9aUbZs

… it is set, with the form that works

set_breakpoint with a Python logMessage such as "stale={entry!r}" answered
success, and every hit then logged "invalid syntax (<string>, line 1)":
debugpy takes the text between each pair of braces as a Python expression
and evaluates it at the hit, and "entry!r" is f-string syntax (#1334).

Python now implements validateLogMessage, the policy member JavaScript
already uses to refuse a logpoint that cannot compile. A brace group with
an f-string conversion (!r, !s, !a) or a format spec at its top level is
refused, and the refusal names the replacement: {repr(x)},
{format(total, '.2f')}, {format(repr(x), '>10')}. Everything else is
passed through untouched: comparisons, slices, string literals holding a
colon, lambdas, :=, nested dict and set literals. The scanner follows
debugpy's own brace matching.

Checked as real logpoints against debugpy 1.8.20: the validator refuses
exactly the messages that logged a syntax error, and each replacement it
names logs the value.

Written by a Gemini worker (Google, gemini-4-carbon-high) from the
manager's brief and the design call on the issue.

Fixes #1334.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn82vMcRzWFDD9aUbZs
@codecov

codecov Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

cynarlab and others added 3 commits November 28, 2026 07:52
…ebug form, and names the right replacement for a dict

Review round on #1334.

- The 540-line validator is replaced by one tokenizer of 361 lines that
  reads groups and f-string fields the same way. It gives the same answers
  on every message debugpy can evaluate (none of 780,357 generated messages
  that compile is refused) and drops the code the review showed had no
  effect.
- `match` and `case` are ordinary names: `{match!r}` was accepted and
  logged a syntax error at every hit.
- The f-string `=` form is refused with its replacement: `{x=}` becomes
  `x={repr(x)}`, `{total=:.2f}` becomes `total={format(total, '.2f')}`.
- A top-level colon gets the advice that fits how it is written: a quoted
  key or several pairs is a dict and needs its own braces; nothing after
  the colon is a format spec; a space after it gets both forms, the format
  form first.
- A group that does not parse alone ends the check: debugpy may read what
  follows differently, and a wrong refusal breaks a call that worked.
- One refusal names up to three groups and counts the rest.
- The unit test's tables are a live recording (debugpy 1.8.20, Python
  3.13): 342 cases with what each replacement logged. The unit project
  executes every statement and branch of the file.

Written by a Claude Opus worker (Anthropic), who had reviewed round 1 and
measured the smaller scanner there; round 1 was a Gemini worker's.

Fixes #1334.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn82vMcRzWFDD9aUbZs
One conflict, in the Python policy's unit test: main (#1344) added the
describeStepInFilter tests where this branch added the validateLogMessage
test. Both are kept.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn82vMcRzWFDD9aUbZs
@debugmcpdev

Copy link
Copy Markdown
Collaborator Author

Held; not for merge as it stands.

Round 2 was reviewed by a second model family (a reviewer from a different family than the writer), and its verdict is do not merge. I ran its candidate wrong refusals against real debugpy (1.8.20, Python 3.13):

  • Confirmed: a # comment inside a group that is ended by a bare carriage return. CPython's tokenizer ends the comment there and the scanner does not, so four messages that debugpy evaluates (a slice, a triple-quoted string, a dict display and a lambda after such a comment) are refused. Exotic, and exactly the kind of refusal this change must never make.
  • Not confirmed: fullwidth and other NFKC-equivalent spellings of lambda. CPython does not treat them as the keyword, so those messages fail in debugpy too and refusing them is not wrong.
  • Not yet run: replacements that would not compile for unusual specs (nested fields with mixed quotes, a line continuation before !r, a generator expression with a spec), and five mutants that the unit test does not kill.

That is three rounds of review on one check, each finding another corner where a hand-written model of Python's tokenizer and of pydevd's conversion differs from the real thing. A fourth patch would be the same kind of fix. The check is the wrong structure: the authority on whether a message evaluates is the interpreter the adapter already runs under, with its own debugpy, and it can be asked.

A design note for the whole seam (what a logpoint's message is, where it is parsed and by what authority, for every engine, and whether the server should refuse, warn or render) is being written and will be reviewed twice before anything is built. It also weighs the project's standing rule that the server does not refuse on an adapter's behalf. This branch stays as it is: its scanner, its 562-row table recorded against two debugpy versions and its harness are the acceptance corpus for whatever replaces it.

What is already established and stays true: on both debugpy 1.8.0 and 1.8.20, every one of the 562 recorded logpoints behaves as the table says, and none of 780,357 generated messages that debugpy can compile is refused.

@debugmcpdev debugmcpdev added the blocked Waiting on a decision or an upstream fix; not ready to be picked up label Nov 28, 2026
debugmcpdev added a commit that referenced this pull request Nov 29, 2026
…erpreter before it is sent (#1371)

debugpy evaluates each {...} group of a logpoint's message as a plain
Python expression inside one %-template. A message written like an
f-string ({entry!r}, {total:.2f}, {x=}) was accepted and logged "invalid
syntax" at every hit, and a literal % in the text logged "unsupported
format character" (#1334, #1349). The server had modelled what the engine
would do with the text instead of asking the engine.

When a launch starts, and for a logpoint set while the program runs, the
program's own interpreter now checks each message with the debugpy it
runs, in a small helper process:

- runs: sent exactly as written; the answer says nothing, unless the
  message holds an assignment expression, which it names.
- rewritten: a failing group is sent as the same field written as an
  f-string, and a % in the text is doubled where the template cannot
  format; the answer shows logMessageSent and logMessageCheck.
- fails: sent as written; the answer says why and what every hit logs in
  its place.
- unchecked: sent as written, with the reason (an attach; a launch that
  names its own interpreter; a child whose interpreter cannot be
  confirmed; a check that ran out of its time: 2 s from the question, 5 s
  when it starts the helper).

Nothing is refused, and list_breakpoints keeps the message as written.
The check is advice in one direction: a program that made its own
compiler stricter can still fail where the check said the message runs.

Known limits, stated in the Python guide: a message with a starred group
({*items}) has the % in its text unexamined (#1372); an audit hook
registered from C in the helper's process is not told apart from the
compiler; what a launch sets for the program alone is not seen.

Tests: a corpus of stated and generated messages checked against what
pydevd itself logs at a hit, with recorded expectations for Python 3.11,
3.12 and 3.13; live tests through the server; the failure paths of the
helper's process manager; a workflow that runs the corpus when the
checker or its callers change.

Supersedes #1346, which refused such messages.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn82vMcRzWFDD9aUbZs
@debugmcpdev

Copy link
Copy Markdown
Collaborator Author

Superseded by #1371, merged as 06d547f3. This draft refused a logpoint message that cannot evaluate; the merged change refuses nothing: the program's own interpreter checks each message, a message that cannot run is sent in a repaired form where one exists, and the answer says what was sent and why. Closing without merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocked Waiting on a decision or an upstream fix; not ready to be picked up

Projects

None yet

Development

Successfully merging this pull request may close these issues.

python logpoints: a logMessage with f-string syntax ({x!r}, {x:.2f}) is accepted and logs only "invalid syntax" when hit; say so when it is set

2 participants