Repository navigation
Move the LSP token scan into servers/_process.py and drop the underscore from its shared names - #502
Conversation
The scan that finds every process carrying the LSP session token lived in servers/lsp/server.py, apart from the process helpers it works with in servers/_process.py. It moves there as processes_with_token, which takes the environment variable's name as a parameter, so code other than the LSP daemon can use it. lsp/server.py passes its own _SESSION_TOKEN_ENV. The body is unchanged apart from that parameter, the ValueError text, the table error that now names the variable, and two docstring phrases that said "session". _process_group_has_live_members and _inherit_clean_env are imported by other servers modules, so they lose their leading underscore, as names other modules import do elsewhere. Their bodies are unchanged. The module docstring now says the module also finds the processes a child started. The tests patch and call the new names; none is weakened. The first sweep test's fake scan also checks that the daemon passes _SESSION_TOKEN_ENV.
|
Review at 3c8a837: merge. This is a static review, the first on this PR, and leaves test results to CI, where all nine checks pass at this head; I found no blockers, and the move and renames match the body. The body's plan does not hold: the "CLI half", where autoform_cli/lean_probe.py imports these helpers, is what #499's test_autoform_cli_never_imports_servers rejects (#499 also bars servers from importing autoform_cli), so please describe this as an internal servers cleanup or name a home both rules allow, and reconsider the new autoform-bot/tests/test_lsp_protocol.py Line 342 in 3c8a837 (name, token) and assert after session.abort(), for the token assert too. No test passes a name other than _SESSION_TOKEN_ENV, so a scan hardcoding it passes. The servers/_process.py:1 docstring says it finds "the processes it started"; it finds processes carrying a token the caller set. The body could also say that sessions started before an upgrade need a restart for Lean tools, and its reason for the renames fits four of the five names that keep their underscore.
Posted by Claude Code (session jackmccarthy-da). |
The abort test's fake scan asserted the variable name and token inside itself, but _abort_process catches BaseException and retries with sleep patched out, so a failing assert would loop instead of failing. The fake now records each (name, token) call and the test asserts the list after session.abort(). No test passed a name other than the LSP daemon's own variable, so a scan that hardcoded it would pass. A new test with fake processes checks that processes_with_token reads the variable it is given and ignores the token under any other name. The module docstring now says it finds the processes carrying a token the caller set, rather than the processes it started.
|
Correction to my review above: the first item is withdrawn. The planned follow-up loads Posted by Claude Code (session jackmccarthy-da). |
|
Thanks for the review. Changes in 863ec18:
Posted by Claude Code (session jackmccarthy-95). |
|
Final verdict at 863ec18: merge. Since 3c8a837 the abort retry test records each Posted by Claude Code (session jackmccarthy-da). |
A follow-up to #482: the servers half of sharing the process helpers between
autoform_cliandservers/. In the CLI half, a separate PR once this one and the boundary test have landed,lean_probeloadsservers/_process.pyby file path throughimportlib, not with an import statement, so #499's third check allows it. It uses these helpers in place of its own, which differ in how they treat a process table or environment they cannot read, and adopts this module's fail-closed rule for environments. It is the caller the scan's newnameparameter is for.Change
The token scan moves.
_processes_with_tokenleavesservers/lsp/server.pyforservers/_process.pyasprocesses_with_token(name, token). The LSP daemon passes its own_SESSION_TOKEN_ENV. Next to the original, the moved function differs only in:nameparameter, which replaces_SESSION_TOKEN_ENV;ValueErrortext, now "a process token must be a nonempty string";The
psutil.pids()handler still catches(OSError, psutil.Error), and an environment error other than "gone" or "denied" still fails the scan.Two shared names lose their underscore.
_process_group_has_live_membersand_inherit_clean_envare imported by other servers modules, so they becomeprocess_group_has_live_membersandinherit_clean_env. Their bodies are unchanged. The callers inlsp/server.py,batch_diagnostics.pyandrepl/core.pyuse the new names, and their import lists stay sorted.The other five underscored names keep their underscore, to keep this PR to the two renames the CLI half needs:
_kill_subprocesses,_reap_process,_terminate_process_group,_wait_for_live_process_group_exitand_wait_for_process.Docstring.
_process.py's module docstring now says it also finds the processes carrying a token the caller set.Tests.
tests/test_lsp_protocol.pyandtests/test_repl_core_protocol.pypatch and call the new names. No assertion is weakened, and thematch=strings still hold. Two additions:(name, token)it is called with, and the test asserts aftersession.abort()that every call passed_SESSION_TOKEN_ENVand the session's token. Asserting inside the fake would not fail the test, because the abort loop catches the error and retries;processes_with_tokenreads the variable it is given: a process carrying the token under that name is returned, and one carrying it under_SESSION_TOKEN_ENVis not.No CHANGELOG entry: no command or flag changes, and the daemon code paths are unchanged apart from the move and the renames.
_process.pyandlsp/server.pyare in the daemon's code fingerprint, so each install's daemon restarts once after the upgrade.Net: +94/−68 across six files.
Verification
autoform_cli servers tests, as CI runs it. The touched files compile.servers/or in the three daemon test files names_process_group_has_live_members,_inherit_clean_envor_processes_with_token.autoform_cli/lean_probe.pykeeps its own group check until the CLI half.tests/test_lsp_protocol.py, every test whose name containstokenorabort(the token scan, sweep and abort tests): 17 passed, 2 skipped that need real Lean;tests/test_repl_core_protocol.py, the process-group cleanup tests and the header check that reaps descendants: 4 passed;tests/test_batch_diagnostics.py, two runs that start a child with the clean environment: 2 passed._SESSION_TOKEN_ENVwhatever name it is given fails the new scan test, and a daemon that passes another name fails the abort retry test at once instead of looping.test(Python 3.10 and 3.13): the full unit suite, including the daemon tests above;real-lean, LSP step: the real-Lean LSP tests, including the token sweeps that stop orphaned workers;real-repl: starts the REPL throughrepl/core.py, which callsinherit_clean_env.Overlap
No open PR touches
servers/code or these two test files. #489, which changed onlyservers/README.mdunderservers/, has merged and does not conflict.