Skip to content

feat: lock $env.config.history.path after REPL startup - #18190

Merged
fdncred merged 4 commits into
nushell:mainfrom
kx0101:lock-history-path-after-startup
May 21, 2026
Merged

fdncred merged 4 commits into
nushell:mainfrom
kx0101:lock-history-path-after-startup

Conversation

@kx0101

@kx0101 kx0101 commented May 12, 2026 •

Copy link
Copy Markdown
Contributor

Description

Reedline takes ownership of the history backend the moment the REPL finishes calling setup_history. After that point, mutating $env.config.history.path from the prompt has no effect, reedline keeps writing to wherever it was originally pointed, which is what was reported in #18188

Per the discussion in the issue, this PR matches the approach @fdncred suggested: instead of trying to live-reload
reedline's history backend, refuse the assignment from the REPL with a clear error. This is conceptually similar to how
$nu is protected today, but enforced one layer down (at config-apply time) since $env itself has to remain mutable

How it works:

  • A new history_path_locked: bool flag on EngineState (defaults to false) gets flipped to true immediately after setup_history succeeds in get_line_editor
  • Stack::update_config reads that flag and forwards it to a new Config::update_from_value_with_options(..., history_path_locked). The original update_from_value is kept as a thin wrapper for non-REPL callers
  • The flag is threaded through ConfigErrors, so HistoryConfig::update can check it when handling the path field. If the lock is set and the new value differs from the current one, it pushes a new ConfigError::LockedAfterStartup instead of applying
  • Setting the same value (no-op) is still allowed, so reassigning the whole $env.config record doesn't trigger spurious errors

config.nu, --config, env-based config, and -c are all unaffected because the lock is only flipped after setup_history runs, which happens after config has already been loaded.

User-facing changes (Release notes)

Locked history related config values during REPL

The following $env.config.history fields are now read-only after the REPL starts, since reedline only reads them once at startup and silently ignored later changes:

  • $env.config.history.path
  • $env.config.history.max_size
  • $env.config.history.file_format
  • $env.config.history.isolation

sync_on_enter and ignore_space_prefixed remain mutable from the REPL since they are re-read on each prompt.

Attempting to change one of the locked fields from the REPL now produces a clear error instead of being silently ignored:

> $env.config.history.path = "/tmp/elsewhere.txt"
Error: nu::shell::config_option_locked_after_startup

  × $env.config.history.path cannot be changed after Nushell has started
   ╭─[repl_entry #1:1:28]
  1 │ $env.config.history.path = "/tmp/elsewhere.txt"
    ·                            ─────────┬──────────
    ·                                     ╰── cannot be changed at runtime
    ╰────
  help: set $env.config.history.path in your config.nu (or via --config / the relevant env var) and restart Nushell

Additional notes

Closes #18188

@github-actions

Copy link
Copy Markdown

Hey, just a bot checking in! You edited files related to the configuration.
If you changed any of the default values or added a new config option, don't forget to update the doc_config.nu which documents the options for our users including the defaults provided by the Rust implementation.
If you didn't make a change here, you can just ignore me.

@ErrorPower2001

ErrorPower2001 commented May 13, 2026 •

Copy link
Copy Markdown

#18188 (comment)

If the goal is to unify the behavior of setting the history option, I believe an error should not be thrown.

Currently, for the history option, except for sync_on_enter and ignore_space_prefixed, other options cannot actually take effect when modified in the REPL, but they can still be modified to a certain value without any error.

If, after discussion, we only need to label which options are for the startup phase and which are for the REPL phase, then we do not need the changes in this PR.

@kx0101

kx0101 commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

Fair point on consistency. To clarify the scope I was working from: this PR was specifically implementing the behavior @fdncred suggested in #18188 (comment), "disallow $env.config.history.path changing from the repl and give an error"

you're right though that max_size, file_format, and probably isolation have the same silent-no-op problem and aren't covered here.

  1. We can either keep this narrow, merge the history.path lock now (since that's what the original issue is about) and open a follow-up to do the same for the other startup-only history fields.
  2. Expand this PR, also lock max_size, file_format, and isolation against REPL changes in the same way
  3. Doc-only update, basically drop the enforcement here and just annotate startup-only vs REPL-mutable options in doc_config.nu

I'm happy with any of them, but the call on which direction (and whether the broader "annotate all $env.config entries / split into a $env.config_repl" idea is worth taking on) feels like a core-team design decision rather than something to settle in this PR. @fdncred, any thoughts 😄

@fdncred

fdncred commented May 13, 2026

Copy link
Copy Markdown
Contributor

Thanks @kx0101 for being so willing to help. I think all repl-immutable options should give an error explaining that it cannot be set in the repl but only in config.nu with a restart. I'm not sure what all those options are though. I think it would just be good to pack all the history ones in this PR.

@kx0101

kx0101 commented May 14, 2026

Copy link
Copy Markdown
Contributor Author

@fdncred of course, happy to help! 😄

I'll work on it this weekend, if you don't mind. I'm currently on a business trip until Saturday

It's noted though, I'll share an update by Sunday!

@kx0101

kx0101 commented May 17, 2026

Copy link
Copy Markdown
Contributor Author

@fdncred @ErrorPower2001 just pushed an update extending the lock to the rest of the startup-only history fields (max_size, file_format, isolation) so the behavior is consistent across the board. sync_on_enter and ignore_space_prefixed stay mutable since the REPL re-reads them each loop

tested manually and added unit tests for each field. Doc note in doc_config.nu updated too

@fdncred

fdncred commented May 17, 2026

Copy link
Copy Markdown
Contributor

thanks. restarted ci. it pukes inexplicably sometimes

@kx0101

kx0101 commented May 17, 2026

Copy link
Copy Markdown
Contributor Author

all good, thanks! Let's see

@fdncred

fdncred commented May 21, 2026

Copy link
Copy Markdown
Contributor

Can you update the user-facing-changes part so that it lists all the keys that are immutable after startup? This part will go in the release notes.

@kx0101

kx0101 commented May 21, 2026

Copy link
Copy Markdown
Contributor Author

@fdncred how's that? 😄

@fdncred

fdncred commented May 21, 2026

Copy link
Copy Markdown
Contributor

Looks great! Thanks for working on this!

@fdncred
fdncred merged commit d266453 into nushell:main May 21, 2026
31 of 34 checks passed
@github-actions github-actions Bot added this to the v0.113.0 milestone May 21, 2026
@kx0101

kx0101 commented May 21, 2026

Copy link
Copy Markdown
Contributor Author

@fdncred of course! happy to help 😄 see you in the next one!

@fdncred

fdncred commented May 21, 2026

Copy link
Copy Markdown
Contributor

looking for to more great work from you!

@fdncred fdncred added A:configuration Issue related to nu's configuration notes:ready Indicates Ready for Release notes notes:additions Noted in "Additions" section labels May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:configuration Issue related to nu's configuration notes:additions Noted in "Additions" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

$env.config.history.path setting is completely ignored – history always writes to $nu.history-path

3 participants