Repository navigation
fix(python): stop turning debugpy's debug log on inside the debugged program - #1392
Conversation
…program (#1264) The adapter started debugpy with DEBUGPY_LOG_DIR set to the session's log directory for every launch. With that variable set, debugpy also turns its debug log on inside the debugged program, where pydevd writes a line for every message it sends, on the program's threads. The adapter no longer sets the variable, and the policy's fallback spawn no longer passes --log-dir. A DEBUGPY_LOG_DIR in the server's environment passes through as the rest of the environment does, which is how an operator asks for debugpy's logs. No shared interface changes: the server's log level cannot reach the adapter without one, and tying the engine's in-program log to our level would slow a debugged program exactly when someone raises it to investigate. Measured on the fixed build, with the same machine and harness as the table of #1218, on mains power, Python 3.13.12 + debugpy 1.8.20: log off (default) DEBUGPY_LOG_DIR set logpoint hit 11.7 us 26.1 us false condition 5.3 us 5.6 us whole function 56x 57x So the log was more than half the cost of a hit. It is not the delivery bottleneck the issue suspected: with it off the loop runs twice as fast and no more of its lines get through (6,000 to 6,900 of 180,000, against 9,600 to 11,500 of 78,000). It also bears on #1384: with the log on, 6 of 8 sessions of a two-thread breakpoint loop froze; with it off, none in 600 rounds. The docs, the Python skill reference and the set_breakpoint description carry the new figures, and the troubleshooting docs say how to turn debugpy's logs on. The source change, its tests and the two troubleshooting sentences were written by a Gemini worker, which also found that the level could not reach the adapter and stopped there as briefed. The manager session decided the rule, ran the measurement, and wrote the figures into the docs, the code comment and the changelog entry. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015BDrn82vMcRzWFDD9aUbZs
…1264) The previous commit changed the set_breakpoint description (24.7 to 11.7 microseconds per Python logpoint hit), and the 24 tool-list snapshots pin that text. Each changed line differs only in the figure. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015BDrn82vMcRzWFDD9aUbZs
Review findings on the previous two commits; no source change. - README still said about 25 microseconds per Python hit and 58x. - 1e6 / 11.7 is 85,000 hits a second when rounded down like its neighbours, not 86,000. - The 2026-11-27 check in the tool reference, and the changelog entry of the logpoint-costs change, compare launch with attach for Python. Both were measured while a launched program still ran with debugpy's debug log on; they now say so. - The Python guide's known limitation repeated delivery rates measured with that log on, and its tip named only one of the two switches that turn the in-program log on (--log-to does it too). - The changelog entry compared sessions with rounds: both are rounds now (6 freezes in 600 with the log on, none in 600 with it off). - The adapter tests assert the whole spawn environment (the server's own plus PYTHONUNBUFFERED), so another logging switch cannot slip in, and read the variable without regard to case, as Windows does. Found by a Claude (Opus) review; written by the manager session. 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! |
Brings in the two Java bridge fixes (#1387, #1393). No conflicts; no file of this change is touched by them. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015BDrn82vMcRzWFDD9aUbZs
|
Correction to what I wrote here about the freeze of #1384. I said that debugpy's in-program log is what made that freeze frequent ("6 freezes in 600 rounds with it on, none in 600 with it off"). The comparison does not show that. A freeze needs both threads at their breakpoints together, so what counts is how often the second thread got there. With the log on it completed 15 loop iterations across the eight sessions, and 6 of them ended in a freeze. With the log off it completed 4, and none did. Six of fifteen against none of four cannot be told apart (Fisher's exact test, p about 0.18). What the runs do show is narrower. Per round, the log-on runs froze more often (6 in 600 against 0 in 600), because the second thread got to run about four times as often with the log on. That is a fact about this harness's tight loop, not about the race. The two runs also differed in more than the log: the harness version, an hour between them, and the power state, which was recorded for one only. What stands is the cost of a logpoint hit (26.1 µs with the log, 11.7 µs without), which is what #1264 was about. Whether the log changes how often the freeze happens is open, and #1384 says so. The changelog entry and two code comments carried the same claim; #1397 corrects them. (Edited once: my first version of this correction compared loop iterations on one side with wait exits on the other, which made the gap look larger than it is.) |
…eze frequent (#1397) The changelog entry of the debugpy log change (#1392), and two comments beside the code, said or implied that the in-program log made the multi-thread freeze far more likely: 6 freezes in 600 rounds with the log on, none in 600 with it off. The comparison does not show that. A freeze needs both threads at their breakpoints together, so what counts is how often the second thread got there. With the log on it completed 15 loop iterations across the eight sessions and 6 of them ended in a freeze; with the log off it completed 4 and none did. Six of fifteen against none of four cannot be told apart (Fisher's exact test, p about 0.18). Per round the log-on runs froze more often, because the second thread got to run about four times as often: a fact about the measurement's loop, not about the race. What stands is the cost of a logpoint hit (26.1 to 11.7 microseconds), which is what that change was for. The entry, the comments and two doc references now say only that. Whether the log changes how often the freeze happens is open in the issue for that race. The claim was the manager session's, and so is this correction. Gemini reviewed it and found a fifth place; Claude Opus recounted the figures from the raw traces. The squash message of the earlier change carries the claim too and cannot be changed. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015BDrn82vMcRzWFDD9aUbZs
Closes #1264.
What changes
The Python adapter started debugpy with
DEBUGPY_LOG_DIRset to the session's log directory for every launch. With that variable set, debugpy also turns its debug log on inside the debugged program: pydevd writes a line for every message it sends, on the program's own threads.buildAdapterCommandno longer sets the variable, and the Python policy's fallback spawn no longer passes--log-dir.DEBUGPY_LOG_DIRin the server's environment passes through with the rest of the environment. That is how an operator asks for debugpy's logs; the troubleshooting docs say so.Measured
On the fixed build, with the harness and machine behind the logpoint table in
docs/tool-reference.md, on mains power, Python 3.13.12 + debugpy 1.8.20, medians of 5 runs:DEBUGPY_LOG_DIRsetSo the log was more than half the cost of a hit. The issue also asked whether it was what limits the delivery of logpoint lines. It is not: with it off the loop runs twice as fast and no more of its lines get through (6,000 to 6,900 of 180,000, against 9,600 to 11,500 of 78,000 with it on).
It also bears on the freeze in the multi-thread issue (number 1384): a two-thread breakpoint loop froze 6 times in 600 rounds with the log on, and not once in 600 with it off. The race itself is debugpy's and that issue stays open.
The README, the docs, the Python skill reference and the
set_breakpointdescription carry the new figures, and the 24 tool-list snapshots are regenerated (each changed line differs only in the figure). Two older statements that compare launch with attach for Python were measured while a launched program still had the log on; they now say so.Tests
python-debug-adapter.test.ts: by default the spawn environment is the server's own plusPYTHONUNBUFFERED, with noDEBUGPY_LOG_DIR; a value already in the environment passes through. Both fail on the previous source.adapter-policy-python.test.ts: the fallback spawn's arguments carry no--log-dir. Fails on the previous source.Verified
955790dc: Python end-to-end suites 23 of 23; across their 16 session directories, nodebugpy.*.logfile was written. Python integration suites 77 passed and one failed:python-attach-close-busy-target, the open flake (number 1376), on a machine loaded by other runs. It passed on a re-run, and the adapter log it kept is now on that issue.955790dc: Python unit 180, integration 77 passed and 5 skipped, end-to-end 23.955790dcchange snapshot files, docs, the changelog and one test file: no source.Who wrote what
The source change, its tests and the two troubleshooting sentences were written by a Gemini worker. It also found that the log level could not reach the adapter and stopped there, as briefed. The manager session (Claude) decided the rule, ran the measurement, and wrote the figures into the docs, the code comment, the changelog entry and this description.
🤖 Generated with Claude Code
https://claude.ai/code/session_015BDrn82vMcRzWFDD9aUbZs