Skip to content

Commit 5678c46

Browse files
committed
fix: avoid tracing recorder itself
1 parent c1cf4bc commit 5678c46

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

.agents/codebase-insights.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
No insights yet. Please add content here and remove this line.
1+
When the pure Ruby recorder traces a script that holds a reference to the
2+
`PureRubyRecorder` instance in a local variable, the variable inspection code
3+
would recursively serialise the tracer's internal state. This results in an
4+
explosive amount of output and may appear as an infinite recursion when running
5+
`examples/selective_tracing_pure.rb`. To avoid this, `load_variables` now skips
6+
values that refer to the recorder or its `TraceRecord`.

gems/codetracer-pure-ruby-recorder/lib/codetracer_pure_ruby_recorder.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -268,16 +268,20 @@ def disable_tracepoints
268268
@tracing = false
269269
end
270270

271+
# Collect local variables from the current binding and convert them
272+
# into CodeTracer values. Variables that refer to the recorder itself
273+
# (or its TraceRecord) are ignored to avoid serialising the entire
274+
# tracer state, which quickly leads to deep recursion and huge traces.
271275
def load_variables(binding)
272-
if !binding.nil?
273-
# $stdout.write binding.local_variables
274-
binding.local_variables.map do |name|
275-
v = binding.local_variable_get(name)
276-
out = @record.to_value(v)
277-
[name, out]
278-
end
279-
else
280-
[]
276+
return [] if binding.nil?
277+
278+
binding.local_variables.filter_map do |name|
279+
v = binding.local_variable_get(name)
280+
281+
next if v.equal?(self) || v.equal?(@record)
282+
283+
out = @record.to_value(v)
284+
[name, out]
281285
end
282286
end
283287
end

0 commit comments

Comments
 (0)