Description
Running migrate-config --in-place twice on the same config file corrupts the output. The second run appends additional section-header comments inline on the existing [section] line and duplicates previously added commented keys.
Reproduction Steps
- Create a minimal config:
echo '[agent]' > /tmp/test.toml
- Run first migration:
cargo run --features full -- migrate-config --config /tmp/test.toml --in-place
- Inspect file — OK so far:
[agent]# comment... with commented keys below
- Run second migration:
cargo run --features full -- migrate-config --config /tmp/test.toml --in-place
- Observe: outputs "19 entries added" (should be 0); file now contains:
[agent]# comment...# comment... (header comment duplicated inline)
- Duplicate
# max_tool_iterations = 10 and # budget_hint_enabled = true entries
Expected Behavior
Second run reports "0 entries added" (or is silent) and the file is identical to after the first run.
Actual Behavior
Second run reports "19 entries added, sections: none". The section header line is mutated to append the comment block again. Previously added commented keys are duplicated in the file. The TOML remains parseable (comments inline after [section] are valid TOML) but the file becomes confusing for manual editing — a user who uncomments an entry may activate the wrong copy.
Environment
- Version: 0.19.1 (HEAD 14f2b73)
- Features: full
- Platform: macOS
Logs / Evidence
After second run, first lines of migrated config:
[agent]# Inject <budget> XML...# name = "Zeph"# Inject <budget> XML...# max_tool_iterations = 10
# budget_hint_enabled = true
# max_tool_iterations = 10
# budget_hint_enabled = true
Root cause: the migration scanner likely uses the [section] line itself as an anchor for insertion, rather than tracking which entries are already present in the file as commented lines.
Description
Running
migrate-config --in-placetwice on the same config file corrupts the output. The second run appends additional section-header comments inline on the existing[section]line and duplicates previously added commented keys.Reproduction Steps
echo '[agent]' > /tmp/test.tomlcargo run --features full -- migrate-config --config /tmp/test.toml --in-place[agent]# comment...with commented keys belowcargo run --features full -- migrate-config --config /tmp/test.toml --in-place[agent]# comment...# comment...(header comment duplicated inline)# max_tool_iterations = 10and# budget_hint_enabled = trueentriesExpected Behavior
Second run reports "0 entries added" (or is silent) and the file is identical to after the first run.
Actual Behavior
Second run reports "19 entries added, sections: none". The section header line is mutated to append the comment block again. Previously added commented keys are duplicated in the file. The TOML remains parseable (comments inline after
[section]are valid TOML) but the file becomes confusing for manual editing — a user who uncomments an entry may activate the wrong copy.Environment
Logs / Evidence
After second run, first lines of migrated config:
Root cause: the migration scanner likely uses the
[section]line itself as an anchor for insertion, rather than tracking which entries are already present in the file as commented lines.