Magento 2.4.9 Valkey Session Configuration: The Silent Discard Bug

Uncovering a Silent Configuration Flaw in Magento 2.4.9 Valkey Session Setup

As e-commerce experts at Shopping Mover, we constantly monitor the Magento ecosystem for critical insights that can impact our clients' migrations and ongoing operations. A recent GitHub issue (#41747) has brought to light a significant, albeit latent, bug in Magento Open Source and Adobe Commerce 2.4.9 concerning Valkey session configuration. This flaw causes the setup:config:set command to silently discard specified Valkey session parameters, defaulting to standard settings without warning.

The Problem: Your Valkey Session Settings Are Being Ignored

The issue, reported by tim-breitenstein-it, details a scenario where users attempting to configure Valkey as their session save handler using the Magento CLI command bin/magento setup:config:set with parameters like --session-save-valkey-host, --session-save-valkey-db, or --session-save-valkey-port will find their custom values are not persisted. Instead, the system defaults to 127.0.0.1, database 2, and port 6379.

bin/magento setup:config:set \
  --session-save=valkey \
  --session-save-valkey-host=1.2.3.4 \
  --session-save-valkey-db=5 \
  --session-save-valkey-port=6380

Upon checking the app/etc/env.php file, the expected custom Valkey configuration is absent, replaced by the defaults. Crucially, no error or warning is displayed during the setup process, making this a 'silent' failure that could lead to significant debugging headaches down the line.

The Root Cause: A Dead Code Branch

The core of the problem lies within the Magento framework's Magento\Setup\Model\ConfigOptionsList\Session::createConfig() method. The issue author meticulously identified a logical error in how the configuration map is selected:

if (ConfigOptionsListConstants::SESSION_SAVE_REDIS) {        // constant 'redis' → always truthy
    $inputToC>redisInputKeyToConfigPathMap;
} elseif (ConfigOptionsListConstants::SESSION_SAVE_VALKEY) {  // unreachable
    $inputToC>valkeyInputKeyToConfigPathMap;
}

The condition ConfigOptionsListConstants::SESSION_SAVE_REDIS evaluates to true because it's a non-empty string constant ('redis'), not a comparison to the *selected* session handler. This means the code always enters the Redis branch, making the Valkey branch unreachable. Since the Redis and Valkey input key maps are disjoint, any --session-save-valkey-* parameters are simply ignored because they don't match any keys in the Redis map.

Furthermore, the setDefaultValkeyConfig() method, which is invoked when Valkey is selected, only seeds default values and does not read from the CLI options, compounding the problem.

Impact and Proposed Solution

Currently, the impact is considered 'latent' because the runtime Valkey session handler itself is missing (a separate issue, #41108 / PR #41099). However, once the Valkey handler is implemented and merged, this configuration bug will become critical. Operators expecting their custom Valkey host, port, or database settings to be applied will silently connect to the default localhost instance, potentially leading to performance issues, data conflicts, or unexpected behavior.

The proposed fix is straightforward: correctly select the input map based on the chosen session handler:

$saveHandler = $options[ConfigOptionsListConstants::INPUT_KEY_SESSION_SAVE] ?? null;
if ($saveHandler === ConfigOptionsListConstants::SESSION_SAVE_VALKEY) {
    $inputToC>valkeyInputKeyToConfigPathMap;
} else {
    $inputToC>redisInputKeyToConfigPathMap;
}

This ensures that if Valkey is selected, its specific configuration map is used, allowing the CLI parameters to be correctly processed and persisted.

Community Engagement and Helpfulness

The issue was quickly reported and self-assigned by the author, indicating a proactive approach to resolving core Magento bugs. While there wasn't extensive community discussion in the comments beyond bot interactions and the author's self-assignment, the detailed bug report and proposed fix provide immense value. It's a clear, actionable insight for developers and system administrators working with Magento 2.4.9, especially those planning to utilize Valkey for session management.

This type of deep dive into core code logic is invaluable for maintaining system stability and preventing frustrating, hard-to-diagnose issues. It underscores the importance of the open-source community in identifying and resolving such critical flaws.

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools