Repository navigation
Closed
Labels
Description
Problem
A person had a setting ssh.key_prefix in the local config.yaml. The setting is gone. The person reports that the main cause was tests that did not isolate the environment, so they wrote the real file. Nothing records which test or command changed the file, and nothing can restore it.
Evidence
config.yamlis ignored by git. Its last write was on 2026-10-07 at 16:10. It holds nokey_prefix, and the copy of 2026-09-28 (.data/config copy.yaml) holds none either. The loss happened before 2026-10-22, and no history shows who wrote it.- The loss has a visible effect. The managed key of this project is named
devops_cli-id_ed25519-20260831(underscore), and without the setting the derived prefix isdevops-cli(hyphen). This is whydevops ssh listlisted the keys of other projects (issue fix(ssh): the key prefix matches with a hyphen or an underscore in one place, and list, register, rotate and status never fall back to the keys of other projects #1920, fixed). get_active_config_pathresolvesDEVOPS_CLI_CONFIG, then a projectconfig.yamlfound from the working directory, then~/.config/devops-cli/config.yaml. A test that callssave_settingsor a writing command withoutDEVOPS_CLI_CONFIGset writes one of the real files. A walk from a git worktree stops at its.gitfile, so a worktree does not find the config of the main checkout.- Eight call sites run
save_settingsinsrc/devops_cli/commands/:ai_runs.py:171,k8s/networking.py:977,k8s/cluster_context.py:66,ai.py:484,telemetry.py:194,ai_gateway.py:219andconfig.py:196and:295. It rewrites the whole file from the in-memory model and keeps no backup. tests/support/workspace_tripwire.pyfails a test session that changedconfig.yaml, but it compares bytes at the start and the end of the session. It detects after the damage and names no test.- An audit of the current suite on 2026-10-22 (tip
80e07bb1): the whole suite ran with asys.addaudithookthat logs every write to a file namedconfig.yamloutside the pytest tmp directories, withHOMEset to a throwaway directory. The suite passed and the hook logged no write. The hook fired on a probe write outside the suite. So no test of the current suite writes a real-looking config file, and the earlier escape is fixed or is not reachable by this run.
Remedy
- Make the escape impossible and named at the moment it happens. Extend the hermetic floor (it already refuses network sockets and programs) with a stdlib audit hook, loaded for the test process and its subprocesses the way the socket block is, that raises when anything opens for writing, renames onto or copies onto a file named
config.yamlor the user-level config path outside the pytest tmp directories, and names the test (PYTEST_CURRENT_TEST) and the stack. Test the hook with a probe test, and show that a test which callssave_settingswithout isolation fails with the test name. Do not add test detection to product code. - Before each write, copy the file to
config.yaml.bak-<YYYYMMDD-HHMMSS>and keep the newest ten copies, so a real write can be undone. The write issave_settings(one function). - Append one line to
<data_dir>/audit/config-writes.jsonlfor each write: the time, the command line and the dotted names of the keys that changed. Never write the value of a secret key. - Optional: write only the changed keys and keep comments and unknown keys (
ruamel.yamlround trip), and decide for each of the eight call sites whether the command must persist a detected value. These are not needed to stop the loss. Checkruamel.yamlfor maintenance before use and write the cost. - Optional second layer: a person adds permission entries that deny the writing commands to agents in
.claude/settings.json.
Proposed design
Problem statement
Tests write to real config.yaml files. This causes data loss and makes it hard to track changes.
Acceptance criteria
- Criterion 1: A test that writes to config.yaml fails with a clear error message naming the test.
Verification: Run a test that calls save_settings without isolation. The test should fail and show PYTEST_CURRENT_TEST in the error. - Criterion 2: Before each write to config.yaml, a backup file is created with timestamp.
Verification: Run a test that saves settings. Check that config.yaml.bak-YYYYMMDD-HHMMSS exists in the directory. - Criterion 3: Each config write is logged to audit/config-writes.jsonl with time, command line and changed keys.
Verification: Run a test that modifies config. Verify that audit/config-writes.jsonl contains one new line with the expected information.
Key questions
- What is the function that saves settings to config files?: The function save_settings in src/devops_cli/config/settings.py. [sources: src/devops_cli/commands/config.py:196]
- Where are the call sites that use save_settings?: Eight call sites in src/devops_cli/commands/: ai_runs.py:171, k8s/networking.py:977, k8s/cluster_context.py:66, ai.py:484, telemetry.py:194, ai_gateway.py:219 and config.py:196 and :295. [sources: src/devops_cli/commands/ai_runs.py:171, src/devops_cli/commands/k8s/networking.py:977, src/devops_cli/commands/k8s/cluster_context.py:66, src/devops_cli/commands/ai.py:484, src/devops_cli/commands/telemetry.py:194, src/devops_cli/commands/ai_gateway.py:219, src/devops_cli/commands/config.py:196, src/devops_cli/commands/config.py:295]
- How does the system currently detect config changes?: The workspace tripwire in tests/support/workspace_tripwire.py compares bytes at start and end of session. It detects damage after it happens and does not name the test. [sources: tests/support/workspace_tripwire.py]
Fit
Needs splitting into 3 items:
- Extend hermetic floor with audit hook that raises on config.yaml writes
- Create backup files before each write to config.yaml
- Log config writes to audit/config-writes.jsonl
Suspected block
None.
Dependencies
None.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty commentedon Oct 22, 2026
Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.
The candidate fixes a problem with config file handling and data loss.The issue causes data loss and affects core functionality of the tool.The change prevents data loss and improves user experience for config management.The fix requires changes to file handling, backup logic, audit logging, and multiple call sites.[-]fix(config): a config write keeps a backup, records what changed and edits only the changed keys, and eight commands stop saving values nobody asked for[/-][+]fix(tests): a test that writes a real config.yaml fails at the write and names itself, and every config write keeps a backup and a change record[/+]dan-petty commentedon Oct 23, 2026
Proposal needs splitting into 3 items at 72b8a3c (see proposed design in issue body).
fix(telemetry): the command span holds no argument value, so a secret…