Skip to content

Conversation

@egreer
Copy link
Contributor

@egreer egreer commented Nov 24, 2025

ChatGPT

The loop is caused by your phi_wrap_method calling logging, which calls tagged, which calls back into the wrapped method again. The repeating cycle is very clear in the trace.

Here are the repeating segments (the recursive loop):

Core repeating block:

from phi_attrs/phi_record.rb:637:in `block in phi_wrap_method'
from phi_attrs/phi_record.rb:647:in `block (2 levels) in phi_wrap_method'
from active_support/tagged_logging.rb:138:in `block in tagged'
from active_support/tagged_logging.rb:38:in `tagged'
from active_support/tagged_logging.rb:138:in `tagged'
from phi_attrs/logger.rb:17:in `tagged'

This exact 6-line sequence repeats over and over.

Precursor (entry)
The whole cycle starts whenever phi_wrap_method tries to compute PHI log keys, which itself calls .attributes, which triggers logging:

from active_record/attribute_methods.rb:346:in `attributes'
from phi_attrs/phi_record.rb:556:in `phi_log_keys'
from phi_attrs/phi_record.rb:637:in `block in phi_wrap_method'

Then .tagged logging calls back into the wrapped method, producing infinite re-entry.

Summary

Your wrapper method logs something inside the method it wraps, but the logging itself triggers the wrapped method again (likely because logger metadata accesses model attributes). The fix is to guard your wrapper to avoid invoking logging during attribute access, or extract the logging so it doesn't depend on attributes/to_hash.

Rails docs for TaggedLogging:
https://api.rubyonrails.org/classes/ActiveSupport/TaggedLogging.html

ActiveModel attribute_set:
https://api.rubyonrails.org/classes/ActiveModel/AttributeSet.html

ActiveRecord attributes:
https://api.rubyonrails.org/classes/ActiveRecord/AttributeMethods/ClassMethods.html#method-i-attributes

@egreer egreer requested a review from wkirby November 24, 2025 21:47
@egreer egreer force-pushed the remove-attributes-call branch from ef91f42 to af41766 Compare December 4, 2025 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants