Skip to content

fix(python): a logpoint's message is checked by the program's own interpreter before it is sent - #1371

Merged
debugmcpdev merged 12 commits into
mainfrom
feat/python-logpoint-check
Nov 29, 2026
Merged

debugmcpdev merged 12 commits into
mainfrom
feat/python-logpoint-check

Conversation

@debugmcpdev

@debugmcpdev debugmcpdev commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1334. Closes #1349. Supersedes #1346, which refused such messages; this one refuses nothing.

The class this removes, for Python

The server modelled what an engine would do with text it handed over, instead of asking the engine. debugpy evaluates each {...} group of a logpoint's message as a plain Python expression inside one %-template, so 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.

What this does

When a launch starts, and for a logpoint set while the program runs, the program's own interpreter checks each message, with the debugpy it runs. A small checker process on that interpreter asks the real compiler and tokenizer.

Verdict What is sent What the answer says
runs the message exactly as written nothing, unless it holds an assignment expression ({step:=99}), which the answer names
rewritten a repair that interpreter compiles, and formats where the number of values is known: a failing group as the same field written as an f-string ({f'{entry!r}'}), a % in the text doubled where the template cannot format logMessageSent and logMessageCheck, with the Python and debugpy it was checked on
fails the message as written why, and what every hit logs in its place (a compile error, a % formatting error, or debugpy's unbalanced-braces line)
unchecked the message as written why it was not checked
  • Nothing is refused, and list_breakpoints keeps the message as written. The check is advice in one direction: what it finds cannot compile is meant to fail in every process; what it finds compiles can still fail in a program that made its own compiler stricter.
  • A logpoint never waits on the check for long: one check has one budget, 2 s from the moment it is asked (5 s when it starts the checker), time spent queued included. Past it the message goes as written and the answer says it was not checked.
  • The checker keeps its own process's settings out of the verdict where it can: it lifts the integer digit limit, ignores warnings filters, and answers unchecked on a recursion or memory failure or when an audit hook added from Python raised during the compile.
  • Not checked, and said so: an attach; a launch that names its own python, pythonPath or pythonArgs; a child process whose interpreter cannot be confirmed as the checked one (always the case on macOS); a check that ran out of its time.

Known limits, stated in the guide

  • A message with a starred group ({*items}) has the % in its text unexamined, whatever the verdict: {*items} 100% is answered runs, and {x!r} {*items} 100% is sent as {f'{x!r}'} {*items} 100%; every hit of either logs an error, as before this change. The test property that would catch it shares the shortcut. python logpoints: a message with a starred group has its % unexamined (answered as running, or rewritten with the % as written) #1372 is the repair.
  • An audit hook registered from C in the checker's process is not told apart from the compiler: a SyntaxError or ValueError it raises is read as the text's. Read from the code; no test builds such a hook.
  • What a launch sets for the program alone (env, envFile) is not seen by the check, which runs with the adapter's environment.
  • The one-line summary in the tool schema and the skill ("debugpy's own reading wins whenever it can run the message") is not qualified for the C-hook case; the guide is.
  • A file on the checker's PYTHONPATH that stands in for the compiler's unicodedata makes every check of the run unchecked only where the interpreter loads that module from a file. Ubuntu 24.04's own Python 3.12 has it built in and never loads the file.

What the tests hold

  • A corpus of stated counterexamples and generated messages (single-group and multi-group sets), checked against what pydevd itself logs at a hit (the stated rows, the table and the multi-group set; the three large generated sets are checked by evaluating debugpy's own expression, and one row whose hit would allocate gigabytes is not run), on recorded Python 3.11, 3.12 and 3.13 and three debugpy versions. Two properties are checked for every row: a message answered runs logs no compile error and no unbalanced-braces line, and its template formats when the number of values is known (not for a starred group, see above); and a message that runs as written is never sent rewritten.
  • Recorded expectations are keyed by Python minor version. An interpreter named explicitly without recordings fails by name; the default interpreter without them skips those tests with the reason and still runs the properties. A row whose logged line depends on the platform says what it depends on, and its lines are not compared.
  • Live tests through the server for what is sent and logged, for the process-settings cases (the checker stricter than the program, and the reverse), and for the bound: five set_breakpoint calls at once against a checker that takes 1.6 s an answer are each held by their check for no more than its 2 s (the answers arrived after 1.6 to 2.2 s on both machines; the rest is the request itself).
  • A new workflow, python-logpoint-corpus.yml, runs the corpus on 3.12 and 3.13 when the checker or its callers change.

Evidence

  • CI at 64ef50a2: 20 checks green, among them both "Build and Test" jobs (Ubuntu and Windows), both "Logpoint corpus" jobs (Python 3.12 and 3.13), and patch coverage at 99.26% against a target of 96.05%.
  • The last head with code changes is 4ccea882. git diff --stat 4ccea882 64ef50a2 is the guide and the changelog fragment only, so what ran there carries over:
    • Windows (Python 3.13.12, debugpy 1.8.20): build, lint, structure:check, typecheck:all, check-docs and changelog:check clean; unit project 475 files, 10,893 passed, 7 skipped; Python adapter suites 23 files, 109 passed, 4 skipped.
    • A two-core Ubuntu 24.04 machine (Python 3.12.3, debugpy 1.8.0, Node 22.22.3): unit project 475 files, 10,893 passed; Python adapter suites 22 files passed and 1 skipped, 108 tests passed; JavaScript adapter suites 11 files, 67 passed.
    • Patch coverage in CI at that head: 99.26% against a target of 96.05% (it was 95.83% at cae512ae, where the unreached lines were the failure paths of the checker's process manager; each now has a test of what a caller sees, was deleted because nothing called it, or is listed with the reason it stays).
  • End to end at 64ef50a2 (the Python smoke tests, the Python attach smoke test and the Python case of the logpoint test): 3 files, 7 tests passed on Windows (Python 3.13.12, debugpy 1.8.20) and on the Ubuntu machine (Python 3.12.3, debugpy 1.8.0); the 14 skipped on each are the logpoint test's cases for the other languages.
  • As the builder reports: the four logpoint test files on seven interpreter and debugpy pairs; the corpus and the settings tests on Python 3.11.15, 3.12.3, 3.12.13 and 3.13.12; each new test of the last round broken by hand and restored.
  • What the Linux machine found that CI could not, all fixed: a recorded line that depended on the platform's recursion budget; a launch with 641 logpoints in one file that outran the 30 s window on two cores; a test that assumed Python loads unicodedata from a file (CI's Python does, Ubuntu's own does not).

Review

Found along the way

Not in this change

The same class in other engines, listed on the tracker: the JavaScript logpoint scanner (#1359, #1360), the COBOL splitter, the Java bridge's expression parser. The checker's hand-made time helper moves onto the deadline primitive in a later change; two of its decisions still read a flag that only its timer writes (a question that arrives after a silent checker's time is up but before the timer has run is queued on that checker and answered unchecked), noted on #1362.

🤖 Generated with Claude Code

https://claude.ai/code/session_015BDrn82vMcRzWFDD9aUbZs

cynarlab and others added 9 commits November 28, 2026 14:29
…erpreter, and only a part that cannot run is rewritten

debugpy evaluates the text between a logpoint's braces as a plain Python
expression at every hit, so a message written like an f-string ({x!r},
{total:.2f}, {x=}) was accepted and then logged a syntax error at every hit,
and a literal % in the text broke the line.

The session now asks its own interpreter, with debugpy's own conversion and
CPython's own compiler, when a run starts and when a logpoint is set on a
live run. A message that runs as written is sent unchanged. A group that
cannot compile alone is sent as an f-string literal inside the group, which
the program's Python evaluates itself; a literal % is doubled only when the
template cannot format for any values. Nothing is refused. An attach, a
program on another interpreter, and any failure of the checker itself are
"not checked", and the message goes out as written.

`list_breakpoints` keeps the message the caller wrote; `logMessageSent` shows
what was sent when it differs.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn82vMcRzWFDD9aUbZs
…feat/python-logpoint-check

# Conflicts:
#	src/session/session-manager-core.ts
…erdict, and its budget starts when it is asked

From two independent reviews of the first version and a run on Linux:

- The checker lifts or ignores every setting of its own process that the
  compiler and tokenizer consult (the integer digit limit, warnings as
  errors, audit hooks, a shadowed unicodedata), and declines instead of
  answering where it cannot. A compile failure is quoted as what the checker
  saw, not as the line every hit logs.
- One check has one budget that covers every question asked through it,
  queue time included; a question whose budget runs out while queued is
  never sent.
- Closing a session waits for every checker of its tree, a previous run's
  included; the run ends when the root and every descendant are terminal;
  no path leaves a logpoint without a verdict silently.
- The tests survive other interpreters: pins are keyed by Python minor
  version, an unpinned default interpreter skips the pins and still runs the
  properties, the attach test waits for a ready line on a kernel-assigned
  port, and the windows-hide guard sees untracked files too.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn82vMcRzWFDD9aUbZs
`validateLogMessage` was js-debug's alone; the Python policy implements it
now, so the contract check's recorded count of members used by exactly one
adapter goes from 47 to 46. Re-recorded with `structure:update`, as the
check asks when a count falls.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn82vMcRzWFDD9aUbZs
Two tests failed on Linux, neither through the check's fault:
- A pin recorded one platform's recursion budget: a 3,000-deep expression
  compiles on Linux and raises RecursionError on Windows. Such a row now
  says what its logged lines depend on (`linesDependOn`); its verdict stays
  pinned, its lines are not recorded or compared, and the properties still
  apply. No row was dropped.
- The live test set 641 logpoints in one launch. debugpy re-reads and
  recompiles the whole file for every breakpoint of a setBreakpoints, so
  that request took 16 to 21 s and passed the server's 30 s launch window
  on a slow machine. The test launches with 100 at a time.

From the second review:
- A queued question is no longer sent after its budget ran out: the turn
  asks the clock, where it used to read a flag that only a timer writes.
- A run that ends while a child is being adopted leaves the child's
  logpoints marked as not checked, with the reason; closing the last live
  child of a root that has already ended waits for the tree's checkers.
- The two validations that each covered for the other are now guarded
  together (a multi-group message with %d, and a generated set of such
  messages); warnings turned into errors at import time and
  PYTHONIOENCODING no longer end the check; the guide names what it cannot
  see (hooks registered from C, a child's executable on macOS).
- Tests that passed with the guard they named deleted now fail for that
  reason; the live test reports its pins as skipped when they are.

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

A second confirming review and a run on Linux found sentences that claimed
more than the check does, and one test that assumed a Windows fact.

The test. "A unicodedata on the path without its name table makes every
check not checked" holds only where the interpreter loads that module from
a file. Ubuntu's own Python has it built in: the import never searches the
path, the file is not loaded, and the checker answers as usual, which the
test read as a failure. It now asks the interpreter first and expects the
outcome that interpreter gives (both outcomes are stated; the run prints
which one it met).

The guide and the changelog fragment, each corrected to the code:
- An audit hook registered from C in the checker's process is not told
  apart from the compiler, so "an audit hook makes the message not checked,
  never failed" is now said of a hook added from Python only, and the C
  case is stated with its outcome.
- A message with a starred group ({*items}) is checked for what compiles
  only: the % in its text is not examined and never doubled, whatever the
  verdict. `{*items} 100%` is answered as running and `{x!r} {*items} 100%`
  is sent rewritten with its % as written; every hit of either logs an
  error. The sentences that promised a repair for every message that
  cannot run now say "the check finds".
- The helper ignores warnings whatever its environment says, so the
  sentence that a launch's PYTHONWARNINGS "is checked against the
  adapter's" is gone; what a launch sets for the program alone is not seen.
- "Relaxes every setting the compiler consults" is now "the settings the
  compiler is known to consult".

No change to the checker or the server.

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

codecov Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.26606% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/session/log-message-checkers.ts 99.25% 2 Missing ⚠️
src/session/session-manager-core.ts 94.73% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

cynarlab and others added 3 commits November 28, 2026 22:45
…, two mutation survivors

CI's patch coverage named the changed lines no test reached: the failure
paths of the checker's process manager. Each now has a test of what a
caller sees, or is deleted, or is left with its reason.

- Tested: the checker's own spawn (working directory, environment, pipes,
  nothing left running); a spawn that throws (answered with why, not tried
  again in the run, closed at once); the last line the checker wrote to
  stderr reaching the answer when it exits before answering; a question
  that cannot be written; a run left unchecked once its checker cannot be
  had, and the next run starting afresh; a close that is bounded even when
  the checker survives its kill (with a fake: no real process survives
  SIGKILL in-process); a child's interpreter question that got no answer;
  a policy's own working directory; a policy that cannot describe its
  adapter.
- Deleted: `checkerPids()` and the `pid` getter it used. Nothing in src,
  tests or packages called them.
- Left, with the reason: a write to an ended child's stdin never throws on
  Node 22 or 24 (the pipe's error event is handled); `kill()` after exit
  sends nothing; two catch arms in the core that their callees cannot
  reach today.

Two tests the second review showed could not fail:
- The live guarantee test now holds that the launch answer lists a
  logpoint if and only if its check has something to say, with the
  checker's verdict and what was sent. Broken by hand it reported 330
  wrongly listed and 1 omitted.
- A row whose logged lines depend on the platform now runs live on every
  version: its sent text is checked and only its lines are skipped.

Two survivors of the mutation pass:
- W1 (warnings ignored before the checker's imports): a module on the
  path that warns as it loads, under PYTHONWARNINGS=error. It bites where
  the interpreter loads that module from a file and says so where it does
  not.
- F9 (a tokenizer failure read as "not one literal"): a stated row whose
  f-string form 3.12.13's tokenize module cannot read (SystemError) and
  3.12.3's can. Where the tokenizer raises, the message is not checked;
  elsewhere it is rewritten and logs 1. The row reports what this
  interpreter's tokenizer does, since two patch releases of one minor
  version differ.

No change to the checker's Python or to any behaviour of the server.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn82vMcRzWFDD9aUbZs
…est title made true

- The guide now states the behaviour the new test holds: when the helper
  cannot be started, exits before it has answered, or does not answer in
  its first 5 seconds, the run's later checks are answered at once as not
  checked with that reason, and a helper that fails after it had answered
  is started again once in the run. Until now only the module's header
  said so.
- The list of what the check itself cannot finish names the interpreter's
  tokenizer raising on a field (Python 3.12.13 does on one known shape).
- "Ubuntu's own Python" is narrowed to what was measured: Ubuntu 24.04's
  Python 3.12.
- The live bound test's title said each answer arrives within 2 s. What it
  holds is that no call is held by its check past the 2 s a check has; the
  answers arrive after 1.6 to 2.2 s, the rest being the call's own round
  trip, and the assertion allows 3.5 s.

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

The reviewer passed the change with prose corrections only:

- A "fails" answer says why and what every hit logs in its place. It is a
  compile error in one of three cases; the others are a % formatting error
  and debugpy's unbalanced-braces line. The guide and the changelog said
  "a compile error" for all three.
- The bound on % directives sums widths and precisions, and a message with
  a starred group is not held to it.
- "Answers not checked where it cannot relax a setting" is said of what the
  checker can tell (its recursion limit, its memory, an audit hook added
  from Python); an audit hook registered from C is named as the limit.
- Two summary sentences in the guide are qualified: a launched session is
  needed but is not always enough, and debugpy's own reading wins where
  the check finds the message can run.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn82vMcRzWFDD9aUbZs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants