Skip to content

Conversation

nina-instrumentl
Copy link

What this does

Overview

This PR adds support for a configurable log_regexp_timeout used specifically by RubyLLM's logging filters. It allows you to override the global Regexp.timeout for logging without affecting the rest of your application.

Problem It Solves

When handling large or complex files, the default logging filters in RubyLLM may hit a Regexp::TimeoutError. This is because many applications set a low global Regexp.timeout (e.g. 1 second) to protect against ReDoS, which can be too restrictive for logging large payloads.

Solution

This change adds support for a log_regexp_timeout configuration value. If provided, RubyLLM will use this timeout when compiling regular expressions for its Faraday logger filters. This isolates logging-related regex behavior from the broader application, improving reliability without compromising global safety.

Example usage:

RubyLLM.configure do |config|
  config.log_regexp_timeout = 4 # seconds
end

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Performance improvement

Scope check

  • I read the Contributing Guide
  • This aligns with RubyLLM's focus on LLM communication
  • This isn't application-specific logic that belongs in user code
  • This benefits most users, not just my specific use case

Quality check

  • I ran overcommit --install and all hooks pass
  • I tested my changes thoroughly
  • I updated documentation if needed
  • I didn't modify auto-generated files manually (models.json, aliases.json)

API changes

  • Breaking change
  • New public methods/classes
  • Changed method signatures
  • No API changes

Related issues

Implements #331

Copy link
Owner

@crmne crmne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean and simple change. I'll do the changes to the doc myself since I think we'd need a rewrite of the logging options in the configuration guide.

Comment on lines +207 to +210

# Set custom timeout for log filtering
# which is useful when working with large payloads
config.log_regexp_timeout = 4 # seconds
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not categorise this as basic logging. Let's remove that.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be worth having a separate section called "Advanced logging options" where to put also the logger and log file options. Since that requires a rewrite of the section, I'm willing to take that on myself.

@crmne
Copy link
Owner

crmne commented Aug 23, 2025

There's one problem with this: Regexp.timeout is only available from Ruby 3.1. Could you make it conditional to that having Ruby >= 3.2?

@nina-instrumentl
Copy link
Author

There's one problem with this: Regexp.timeout is only available from Ruby 3.1. Could you make it conditional to that having Ruby >= 3.2?

Should we raise an error if a user sets log_regexp_timeout while running Ruby < 3.2, or should we silently ignore the option and proceed?

@crmne
Copy link
Owner

crmne commented Aug 25, 2025

I'd say output a warning and proceed

@crmne crmne linked an issue Aug 29, 2025 that may be closed by this pull request
6 tasks
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.

[FEATURE] Have custom Regexp timeout configuration for logging
2 participants