Repository navigation
fix(python): a logpoint whose message cannot evaluate is refused when it is set, with the form that works - #1346
debugmcpdev wants to merge 4 commits into
Conversation
… 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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…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
…fix/1334-python-logmessage
|
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):
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. |
…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
|
Superseded by #1371, merged as |
What
set_breakpointwith a PythonlogMessagesuch as"stale={entry!r}"answered success, and when the line was hit the logged line wasinvalid syntax (<string>, line 1). In agent trials every one of 5 messages that used!rfailed 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_expressionin the vendored pydevd), stores it without compiling it, and evaluates it at each hit.entry!randtotal:.2fare 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:
logMessage{x},{x != 1},{items[1:3]},{d['a:b']},{(lambda v: v)(x)},{ {'k': total} },{y := 7}{x!r},{x!s},{x!a}invalid syntax (<string>, line 1){repr(x)},{str(x)},{ascii(x)}{total:.2f}invalid decimal literal (<string>, line 1){format(total, '.2f')}{x!r:>10}invalid syntax (<string>, line 1){format(repr(x), '>10')}{{literal}}name 'literal' is not defined(debugpy has no{{escape: it is a set literal)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.lambda's colon and:=are not format specs.Verification
{x!r}and reads the value logged by{repr(x)}.tests/adapters/python: 77 passed.typecheck:all,lint,check-docs,changelog:checkpass.Not in this change
The
logMessageparameter's description in the tool list (another pull request is changing that file); a logpoint'scondition.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