Skip to content

Pin secret_key_base in the test app to stop a flaky Rails 8 CI failure - #449

Merged
exoego merged 1 commit into
masterfrom
fix/flaky-secret-key-base
Sep 9, 2026
Merged

exoego merged 1 commit into
masterfrom
fix/flaky-secret-key-base

Conversation

@exoego

@exoego exoego commented Sep 9, 2026

Copy link
Copy Markdown
Owner

Problem

The test (ruby:4.0, 8.1.2, coverage) job fails now and then with this error.

ArgumentError:
  `secret_key_base` for test environment must be a type of String`

spec/apps/rails/tmp/local_secret.txt is gitignored, so it does not exist when CI starts. scripts/parallel_rspec starts 4 workers at once, and each spawns a Rails child against the same app root. Rails' generate_local_secret checks for the file, creates it, writes it and then reads it. A child can read the file after another child created it but before it was written. That returns an empty string. Rails 8.0+ rejects an empty string in the secret_key_base= setter, so only the Rails 8.x jobs fail, and only sometimes.

Seen on #448. A local simulation of the Rails code with 4 concurrent processes hit the empty read 15 times in 300 trials.

Fix

Set a fixed config.secret_key_base in the test environment. Rails then never touches tmp/local_secret.txt. The setting works the same way on Rails 6.1 through 8.1.

Verification

Removed the local secret files and ran bundle exec scripts/parallel_rspec on Rails 8.0.2. All 88 examples passed and the secret file was not recreated.

🤖 Generated with Claude Code

Rails 8.x generate_local_secret checks, creates, writes and then reads
tmp/local_secret.txt. The file is gitignored, so it is missing when CI
starts, and the parallel spec workers boot Rails at the same time. One
child can read the file before another has written it and get an empty
string, which Rails 8.0+ rejects. A fixed value skips the file entirely.
@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: f117fe0d-bde7-45e1-b303-6ca3fe5655d9

📥 Commits

Reviewing files that changed from the base of the PR and between af2b203 and fa40cc1.

📒 Files selected for processing (1)
  • spec/apps/rails/config/environments/test.rb

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

Changes

Rails test configuration

Layer / File(s) Summary
Fixed test secret configuration
spec/apps/rails/config/environments/test.rb
The test environment sets a fixed config.secret_key_base value and documents its purpose for parallel application boots.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to fa40c

Rails test boots now use a stable secret key, preventing parallel workers from observing an incomplete local secret file. The change is limited to test configuration and has no remaining merge-blocking risk.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: pinning secret_key_base in the test app to prevent flaky Rails 8 CI failures.
Description check ✅ Passed The description directly explains the concurrent file access problem, the fixed config.secret_key_base solution, and the verification results.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.42%. Comparing base (af2b203) to head (fa40cc1).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #449   +/-   ##
=======================================
  Coverage   98.42%   98.42%           
=======================================
  Files          29       29           
  Lines        1144     1144           
  Branches      222      222           
=======================================
  Hits         1126     1126           
  Partials       18       18           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mergify

mergify Bot commented Sep 9, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@exoego exoego added the chore label Sep 9, 2026
@exoego
exoego merged commit 33090ec into master Sep 9, 2026
19 checks passed
@exoego
exoego deleted the fix/flaky-secret-key-base branch September 9, 2026 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant