Skip to content

fix(config): atomic write for config.yaml to prevent data loss on crash - #700

Closed
alireza78a wants to merge 1 commit into
NousResearch:mainfrom
alireza78a:fix/atomic-config-yaml-write-v2
Closed

fix(config): atomic write for config.yaml to prevent data loss on crash#700
alireza78a wants to merge 1 commit into
NousResearch:mainfrom
alireza78a:fix/atomic-config-yaml-write-v2

Conversation

@alireza78a

Copy link
Copy Markdown
Contributor

save_config() was using open("w") which truncates the file immediately.
A crash mid-write leaves config.yaml empty — on next start, load_config()
catches the parse error and silently returns defaults. The user's model,
personality, and tool settings all reset with no warning.

Same tempfile.mkstemp + os.replace pattern already used in
gateway/session.py and cron/jobs.py.

Added 3 tests covering the crash simulation, temp file cleanup, and
valid YAML output.

@teknium1

Copy link
Copy Markdown
Contributor

Great pattern — matches the existing atomic_json_write approach. Rebased onto main, resolved 1 conflict (integrated with max_turns normalization + commented sections from recent merges), added extra_content param to atomic_yaml_write for the commented sections, fixed a test for the normalized config structure. All 2860 tests pass. Merged. Thanks @alireza78a! 🎉

teknium1 added a commit that referenced this pull request Mar 10, 2026
…ata loss on crash

Authored by alireza78a. Adds atomic_yaml_write() to utils.py (mirrors
existing atomic_json_write pattern), replaces bare open('w') in
save_config(). Integrated with max_turns normalization and commented
sections via extra_content param. 3 new tests for crash safety.
@teknium1 teknium1 closed this Mar 10, 2026
angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 27, 2026
…to prevent data loss on crash

Authored by alireza78a. Adds atomic_yaml_write() to utils.py (mirrors
existing atomic_json_write pattern), replaces bare open('w') in
save_config(). Integrated with max_turns normalization and commented
sections via extra_content param. 3 new tests for crash safety.
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
…to prevent data loss on crash

Authored by alireza78a. Adds atomic_yaml_write() to utils.py (mirrors
existing atomic_json_write pattern), replaces bare open('w') in
save_config(). Integrated with max_turns normalization and commented
sections via extra_content param. 3 new tests for crash safety.
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.

2 participants