Skip to content

Commit 3fdb732

Browse files
committed
docs(insights): document recursion issue with recorder
1 parent 3af4156 commit 3fdb732

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

.agents/codebase-insights.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
No insights yet. Please add content here and remove this line.
1+
When tracing scripts with the pure Ruby recorder, avoid including the
2+
`RubyRecorder` instance (or its `TraceRecord`) among the inspected local
3+
variables. Otherwise the serializer will descend into the tracer's own
4+
state which quickly explodes in size and appears as infinite recursion.
5+
`load_variables` filters these objects out.

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,21 @@ def deactivate
215215

216216
private
217217

218+
# Collect local variables from the current +binding+. Variables that refer to
219+
# the tracer itself or the trace record are ignored to avoid recursively
220+
# serialising the internal state of the tracer.
218221
def load_variables(binding)
219-
if !binding.nil?
220-
# $stdout.write binding.local_variables
221-
binding.local_variables.map do |name|
222-
v = binding.local_variable_get(name)
223-
out = to_value(v)
224-
[name, out]
225-
end
226-
else
227-
[]
222+
return [] if binding.nil?
223+
224+
binding.local_variables.filter_map do |name|
225+
v = binding.local_variable_get(name)
226+
227+
next if v.equal?(self) || v.equal?(@record)
228+
next if defined?(RubyRecorder) && v.is_a?(RubyRecorder)
229+
next if defined?(TraceRecord) && v.is_a?(TraceRecord)
230+
231+
out = to_value(v)
232+
[name, out]
228233
end
229234
end
230235
end

0 commit comments

Comments
 (0)