Repository navigation
Fix non-interactive (rake / rails runner) audit on Evergreen - #9
Merged
Merged
Conversation
rails runner when Rake is only partially loaded`require "rake/file_list"` (pulled in by rails/test_unit/railtie) defines the Rake module without Rake.application, so detection raised NoMethodError and the fail-open rescue silently skipped the noninteractive_command record. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Railtie's after_initialize is registered at Bundler.require, so it ran before hooks from gems later in the Gemfile. rails_semantic_logger patches ActiveJob's logging in its after_initialize; until then ActiveJob calls `logger.formatter.current_tags` on a SemanticLogger logger with no formatter, so every rake / rails runner enqueue raised and failed open. Registering the hook from an initializer places it after all gem hooks, regardless of Gemfile order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
grantcox
force-pushed
the
stagility/runner-detection-partial-rake
branch
from
September 29, 2026 00:52
815a9f8 to
bc74dc1
Compare
grantcox
marked this pull request as ready for review
September 29, 2026 00:56
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.
Problem
On Evergreen,
rails runnerandrakecommands produce nononinteractive_commandrecord. Interactive consoles and the same commands ondatadog-proxy-stagingwork. Both failures below are swallowed by the gem's fail-open rescues, so the only symptom is a warning on the one-off dyno's stderr.1. Rake is only partially loaded
NoninteractiveAudit.detectcheckeddefined?(Rake)before callingRake.application. Evergreen requiresrails/test_unit/railtie, and in Rails 8.1 that chain ends inrequire "rake/file_list". That definesRakewithoutRake.application.Fix: check
defined?(Rake.application)instead.2. The enqueue runs before
rails_semantic_loggerhas patched ActiveJobThe Railtie's
after_initializeis registered when Bundler requires the gem, so it runs before the hooks of gems listed later in the Gemfile.rails_semantic_loggerswapsRails.loggerfor a SemanticLogger during initializers, but only patches ActiveJob's logging in its ownafter_initialize. Until that patch runs, ActiveJob'slogger_tagged_by_active_job?callslogger.formatter.current_tags, and a SemanticLogger has no formatter. In Evergreen,rails_semantic_loggersits in theproductiongroup belowconsole_audit. In datadog-proxy it comes first, which is why datadog-proxy worked. Interactive consoles enqueue long after boot, so they're unaffected.Fix: the non-interactive audit's
after_initializeis now registered from aninitializer. Initializers run afterBundler.require, so the hook runs after every gem'safter_initialize, whatever the Gemfile order.Tests
noninteractive_audit_spec: a bareRakemodule still detectsrails runner.railtie_spec: boots a forked app with anafter_initializehook registered afterconsole_auditloads, standing in for a later gem. The spec checks that the audit runs after that hook, and not at all when auditing is disabled.Both new specs fail without their fix. The full suite (72 examples) and
standardrbpass.Manual testing
I have tested these changes on Evergreen PR https://github.com/ynab/evergreen/pull/30446 , working through our full console auditing test script.
Release
This bumps
VERSIONto1.0.1and moves the changelog entries under1.0.1. Tagv1.0.1onmainafter merge. Evergreen then needs to pinconsole_auditto that tag.🤖 Generated with Claude Code