Repository navigation
fix(python): a logpoint's message is checked by the program's own interpreter before it is sent - #1371
Merged
Conversation
…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
…feat/python-logpoint-check
`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
…feat/python-logpoint-check
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
…feat/python-logpoint-check
… 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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…, 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 loggedinvalid syntaxat every hit, and a literal%in the text loggedunsupported 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.
runs{step:=99}), which the answer namesrewritten{f'{entry!r}'}), a%in the text doubled where the template cannot formatlogMessageSentandlogMessageCheck, with the Python and debugpy it was checked onfails%formatting error, or debugpy's unbalanced-braces line)uncheckedlist_breakpointskeeps 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.uncheckedon a recursion or memory failure or when an audit hook added from Python raised during the compile.python,pythonPathorpythonArgs; 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
{*items}) has the%in its text unexamined, whatever the verdict:{*items} 100%is answeredruns, 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.SyntaxErrororValueErrorit raises is read as the text's. Read from the code; no test builds such a hook.env,envFile) is not seen by the check, which runs with the adapter's environment.PYTHONPATHthat stands in for the compiler'sunicodedatamakes every check of the rununcheckedonly 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
runslogs 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.set_breakpointcalls 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).python-logpoint-corpus.yml, runs the corpus on 3.12 and 3.13 when the checker or its callers change.Evidence
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%.4ccea882.git diff --stat 4ccea882 64ef50a2is the guide and the changelog fragment only, so what ran there carries over:structure:check,typecheck:all,check-docsandchangelog:checkclean; unit project 475 files, 10,893 passed, 7 skipped; Python adapter suites 23 files, 109 passed, 4 skipped.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).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.unicodedatafrom a file (CI's Python does, Ubuntu's own does not).Review
4788ed44,4ccea882and64ef50a2(the guide, the changelog fragment, one test's second outcome, a test title).84128db3; atcae512ae, the guide's over-claims, the starred-group gap (python logpoints: a message with a starred group has its % unexamined (answered as running, or rewritten with the % as written) #1372) and two assertions that could not fail; at4ccea882, prose only; at64ef50a2: merge. Every sentence of the guide's section and the changelog fragment, and of this description except its Evidence and Review sections, was judged against the code in the last two turns. Those two sections are mine and were read by no model.unicodedatafrom a file.Found along the way
launchrequest, with advice to retry.setBreakpoints(641 logpoints in a 2,600-line file: 16 to 21 s). The live test launches with 100 at a time because of it.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