tracer: keep the whole block body, and say why capture failed - #724
Merged
Merged
Conversation
A comment at column 0 inside a trace body truncated it: `_parse_block` ended the slice at any non-blank line indented back to the header's column, and Python ignores a comment's indentation. What was left still parsed as a `with`, so the whole-file fallback never fired and the statements after the comment silently never ran. Blanks and comments no longer end the slice, and the docstring no longer claims the slice never returns a wrong node — this was the case where it did. `WithBlockNotFoundError` carried no message, and at least five unrelated causes reach it. It now says which — no readable source, a file whose source has gone stale, or source whose line numbers don't match the running code. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
JadenFiotto-Kaufman
force-pushed
the
fix/tracer
branch
from
September 8, 2026 19:10
40411db to
48a9d41
Compare
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.
Two findings from the agent stress sweep, both in the
with-block capture path(items 14.2 and 22 in the review notes).
A column-0 comment truncated the trace body
Tracer._parse_blockended its slice at any non-blank line indented back to theheader's column. A comment is non-blank and Python ignores its indentation, so
commented-out code at column 0 — where every editor leaves it — cut the body
short. The truncated slice still parsed as a valid
ast.With, so the whole-filefallback never fired and the statements after the comment silently never ran.
Blanks and comments no longer end the slice. The docstring's "It never returns a
wrong node" was exactly wrong for this case and now says which bound is unsafe
and why.
Before / after on the repro
(
tasks/trace-body-capture-and-save/skills/repro_7_col0_comment_truncates_body.py):NameError: name 'o' is not defined→after comment ran/o = 2.0.WithBlockNotFoundErrorcarried no messageraise WithBlockNotFoundError()gave the bare class name for at least fivedistinct causes — a trace typed into stdin,
python -c, anexec'd string notin
linecache, a%%timecell magic, an edit that shifted line numbers — andthe user could not tell them apart.
_not_found_messagenow branches on what theraise site knows:
exec'd string not inlinecache) —say where a trace body has to live;
withat that line — name the file, line and the text ofthat line, and say the source looks stale (nnsight reads each file once) or
that the tracer was entered without a
with;own body, so line numbers have to match (a
%%timecell magic, generatedsource out of step with its
linecacheentry).docs/errors/index.mdnow carries the real message text for all three.Deliberately not fixed: the stale compiled-body cache itself (
BLOCKS/SOURCESnever re-validated), per the review. The second branch only reports that the
source looks stale.
Docs
docs/errors/index.md, plus the two lines my change made false —docs/errors/with-block-not-found.mdanddocs/errors/symptom-index.mdbothasserted the exception carries no message — and the
_parse_blockbound and_not_found_messagesentences indocs/developing/tracing-pipeline.md.Not in this PR
An earlier revision of this branch also restored the thread's trace function
around a block (
skip_contextclobbers it,__exit__sets it toNone, so adebugger breakpoint set after a trace never fires and coverage reports every line
after the first block as missed). The maintainer has decided against that change,
and it has been removed in full:
skip_contextinstalls the bare no-op and__exit__keeps its unconditionalsys.settrace(None), exactly as on0.8.Testing
PYTHONPATH=<worktree>/srcthroughout, so the worktree is what ran.tests/test_tracing.py: 63 passed (56 before; 7 added). The two comment testsfail on
origin/0.8and pass here — verified against a scratch checkout oforigin/0.8'ssrc. The four_not_found_messagetests are new-API and canonly run here.
tests/vllm,tests/tp,tests/performance: 1008 passed,3 skipped, 1 xfailed.
origin/0.8on the same command: 1001 passed, sameskips — the difference is exactly the 7 added tests.
test_serialization.py,test_editing.py,test_diffusion.py,test_encoder.py): nothing here stores anything new on theTracer, and__getstate__/__setstate__are untouched relative to0.8.multi-GPU. Neither item touches those paths.
Note:
pytest tests/test_serialization.pyon its own dumps core partway throughin this environment on
origin/0.8too — pre-existing, unrelated, and it doesnot happen in the full run.
🤖 Generated with Claude Code