Repository navigation
fix(config): stop reporting valid empty per-project sections as unknown - #4123
Conversation
seed_schema_skeleton restored only top-level schema keys into the round-tripped view diff_tables compares against, so a nested section that serialized away at its default read back as an unknown field. Seed each [projects."<id>"] entry from the UserProjectOverrides schema too. Closes #4115
The top-level pass inserts the scoped map before the lookup, so its absence branch could never be taken.
worktrunk-bot
left a comment
There was a problem hiding this comment.
Self-review. The unknown-field fix itself is right — the skeleton had to reach one level down, and seeding only schema-valid keys keeps genuine unknowns warning. One finding on the behavior that rides along with it, which I've pushed a fix for.
The preserve-set change is wider than the PR body says
compute_unknown_tree feeds both the warning and save_to's preserve set, so seeding [projects."<id>".<section>] as known also takes it out of the set the stale-key sweep in merge_tables consults. The PR body frames that as "an empty per-project section is now dropped". It also drops a non-empty one: a per-project section whose only contents are schema-unknown keys — a typo, or a field a newer worktrunk wrote — is deleted on save along with those keys.
[projects."example.com/org/repo".list]
future-knob = 1The section equals its default, so it is absent from the desired document; before this PR it survived because it read as unknown, and at 48afc26 a save_to round-trip returns it verbatim. At 93faffc the same round-trip returns an empty file. That contradicts what save_to is documented to do — "Schema-unknown keys at any nesting level (typos, fields from newer wt versions) are preserved so older wt versions don't silently strip forward-compatible config data" — and the consistency argument doesn't rescue it, because the top-level form ([list] with only future-knob in it) already loses the key today for the same reason. Consistent, but consistently wrong.
The PR body weighed splitting warn_tree from preserve_tree and called it too large. It doesn't need that split: the defect is one clause in the stale-key filter, which drops a key when it is absent from desired and not in preserve.keys, without consulting preserve.nested. Pushed as a one-clause change plus a regression test covering both scopes; it fixes the pre-existing top-level case too. An empty section, with nothing recorded below it, is still removed, so the behavior this PR set out to change is unaffected — test_save_to_existing_file_removes_stale_projects_and_sections still passes unchanged.
Also folded in
The new valid_scoped_keys stood up a second OnceLock<Vec<String>> over schema_top_level_keys::<UserProjectOverrides>, duplicating the one inside is_user_project_override_key in the same file. Both now read one user_project_override_keys().
For a human
@max-sixty — flagging rather than merging: this widens what worktrunk deletes from the user's own config file, which is the protected class the review guidance holds for even though no force-delete call appears in the diff. Worth a look at the tradeoff specifically, since "an empty section disappears" and "a forward-compat key disappears" are different sizes of change and only the first was called out.
One thing I verified and want on the record, because it is a silent improvement rather than a regression: pre-create / post-create under [projects."<id>"] are serde aliases for pre-start / post-start, and schema_top_level_keys adds them. Before this PR they read as unknown per-project, so a save wrote the migrated pre-start and kept the pre-create the config already had — two entries for one hook. They now round-trip to the canonical name alone.
How the round-trip was checked
A scratch test calling UserConfig::save_to on a tempdir file, run at 48afc26b1 (merge base) and at 93faffc9a (PR head), over: an empty section in each scope; a section holding only an unknown key in each scope; a section with a real value plus an unknown key; and an unknown section. The only divergence between the two refs is the per-project cases. Removed before committing.
Seeding the per-project scope also took those sections out of the preserve set `save_to` consults, so a `[projects."<id>".list]` holding only a forward-compat key was deleted on save along with the key. The stale-key sweep asked only whether the key itself was unknown; it now also asks whether unknowns were recorded below it, which covers the top-level `[list]` form that already lost the key the same way. An empty section, with nothing recorded below it, is still removed. Also collapses the duplicate `UserProjectOverrides` key-list static onto one `user_project_override_keys()`.
# Conflicts: # CHANGELOG.md
worktrunk-bot
left a comment
There was a problem hiding this comment.
Self-review of aa1e983. The stale-key clause does what the commit message says, and test_save_to_existing_file_keeps_section_holding_only_unknown_keys pins it in both scopes. Two consequences of it aren't recorded anywhere, and the first bears directly on the delete-surface question this PR is asking for a judgment on.
The clause also stops an unrelated save from deleting a deprecated key
list.task-timeout-ms is a Structural deprecation: remove_section_key_in strips it on every load, and at the top level it leaves the emptied [list] behind. So reload_from hands save_to a config whose list is default while the raw file still holds the key — the same shape as future-knob, because a deprecated key is schema-unknown too.
Before this commit the sweep took [list] and the key with it. Setting an unrelated value on a config of just [list] task-timeout-ms = 500 wrote a file with no [list] at all; the deprecation warning stopped firing because the key had been silently deleted. With the clause it survives, and the warning keeps pointing at wt config update until the user runs it.
That is the right direction — merge_tables already documents "deprecated keys not yet migrated" as something it preserves, and CLAUDE.md's Config Deprecation section says never to silently drop an old config key — so this reads as a second bug the one-clause fix happens to close. But it is a user-visible change in the opposite direction from the empty-section removal the PR body calls out, and a maintainer weighing what this changes about deletion should see both. Worth a line in the changelog entry rather than being left for someone to discover.
Keeping the subtree whole also keeps schema-known keys inside it
The clause keeps the section rather than pruning it to what preserve records, so a section absent from desired is kept verbatim — including a schema-known key whose in-memory value is now None. A file with [list] full = true plus future-knob = 1, saved from a config whose list is default, comes back with full = true still there; without future-knob beside it the section would have been removed.
No shipped path reaches this: every save_to call goes through with_locked_mutation, which reloads from disk first, and the mutators only set values. It becomes live the first time something clears one — an unset-style mutator would silently no-op on any section that also holds a typo. Pruning to the preserved keys would be the precise fix, but that is more deletion machinery on the surface this PR is already asking a human to weigh; naming the limitation on merge_tables is the proportionate move, and I'm pushing that wording along with the changelog line.
Overlap
#4120 rewrites the inline-table branch of this same merge_tables and edits the doc-comment bullets immediately below the one this PR changes. Not a duplicate — that PR fixes the inline branch, this one fixes the stale sweep — but they conflict textually, so whichever lands second needs a rebase.
The sweep was also deleting a deprecated key whose migration empties its section — `[list] task-timeout-ms` — as a side effect of writing an unrelated setting. Name that in the changelog beside the forward-compat case it shares a mechanism with. Name the limitation on `merge_tables` too: a section kept for its unknowns is kept whole, so a schema-known key inside it survives a `desired` that no longer carries it.
Drop this PR's CHANGELOG.md entry. Changelog entries are written from the commits at release time (CLAUDE.md, Releases), so an open PR carrying an entry drops it rather than resolving a conflict on it.
max-sixty
left a comment
There was a problem hiding this comment.
ok, but we can't just not do all this? can't we just delegate all toml parsing to serde?
|
Yes for the half that produced this bug, and further than I expected — but not for free. I tested both shapes in a scratch crate against Why the machinery exists, and why it keeps failing. What serde can decide. The shape that does work. A catch-all
Warnings become a walk over the What it costs. A field on each config struct that maps to a TOML table — One thing that wouldn't help: dropping the unknown-key warning entirely doesn't delete the tree, since Where that leaves this PR. It's a small fix for a warning printed on valid config today, and the redesign is config-wide with its own review surface. I'd land this and do the serde version as its own PR — say the word and I'll write it. I haven't filed an issue for it, since Test program and outputStructs mirror the worktrunk shape — a flattened top-typo = 1
[unknown-section]
x = 1
[list]
columns = ["a"]
typo-top = 1
[projects."example.com/org/repo"]
future-knob = 2
[projects."example.com/org/repo".list]
[projects."example.com/org/repo".merge]
squas = true
Catch-all |
…obable environments (#4137) Four times in the last 24 hours, `max-sixty` asked a bot PR for less code, and each time the ask was the same one in a different costume: stop encoding another tool's rules in `wt`, and stop defending environments that are already broken. Nothing in `CLAUDE.md` said either, so each PR re-learned it in review. The first extends **Code Quality → Use Existing Dependencies**, which already tells you to reach for a dependency before hand-rolling a utility; the second gets its own heading beside it, since defending an environment has nothing to do with dependencies. Both cases the delegation rule came from resolved *into* its exception rather than out of it — #4085 established that zsh has no "where should the config file go" to ask, and #4124 that MiniJinja exposes no binding list without `unstable_machinery`. The guidance names neither: cited as examples, they read as debt still to pay off, and the zsh decision already lives in `zsh_config_dir`'s docstring, which is where the rule says that reasoning belongs. The generalisation is the maintainer's, not an inference from the diffs — on #4085: *"can we try to remove as much as possible from our code that attempts to interpret the internals of other libraries?"*, prefaced with *"we hit this on some of the sibling issues"*. #4106 is the standing backlog that same instinct produced. **Second half, the anxiety one.** On #4104: *"this is totally fine; we're an order of magnitude too anxious here. if someone doesn't have a resolvable home dir, then honoring the xdg config in worktrunk is the least of their problems"* — the wording here is close to his deliberately. The earlier instance is #4107, where a bot self-review invented a scan of a stranded fish config directory and he cut it: *"if someone moves the config dir, then we'll miss the uninstall, that's fine"*. The **Data Safety** carve-out is explicit because that section rules the opposite way on purpose, and this paragraph must not be read as licensing a silent loss. **Why now rather than at the next instance.** The behaviour is stochastic, so it carries a 5-occurrence floor; the window took it to six (#4085, #4104, #4123, #4124 here, plus #4104's `nu-config` round and #4107 recorded on 2026-09-15 in #3980). The bot also has seven PRs open, over the self-initiated budget — this one is filed anyway because the cost class is a wrong outward action, not compute: #4124 shipped a hand-rolled MiniJinja binding scanner whose correctness gap the maintainer had to find himself. <details><summary>The four corrections, and what each one cost</summary> | PR | Correction | Outcome | |----|-----------|---------| | [#4085](#4085) | "can we just ask `zsh` for whether the config file should go?" | Bot showed the `zsh -f -c` probe relocates the rule rather than removing it, deleted the zsh-source docstring, and gave `zsh_config_dir` the absolute-only guard the module already applied to `$XDG_DATA_HOME`. The rule itself stays in `wt`. Merged. | | [#4104](#4104) | "we're an order of magnitude too anxious here" | Taken as a precondition in `c4089e3c`; `read_tea_config`'s two home-directory resolutions collapsed into one candidate list. Merged. | | [#4123](#4123) | "can't we just delegate all toml parsing to serde?" | Bot tested `serde_ignored` in a scratch crate and reported where `#[serde(flatten)]` blinds it, rather than answering from reasoning. Open. | | [#4124](#4124) | "the new binding scanner still misses parenthesized tuple targets that MiniJinja 2.24 accepts" | Fixed in `5fe64767` across `for`/`set`/`with`; deriving bindings from MiniJinja's parse needs `unstable_machinery`. Open. | Only the last is a correctness defect — the other three are complexity the maintainer declined to carry. The bot absorbed all four within hours, so the gap is not in how it responds but in it not knowing beforehand. Evidence for this run is appended to the `review-runs-tracking` issue [#3980](#3980); the prior two occurrences are under `Run 34943713746`. </details> `CLAUDE.md` is hand-edited, not generated, so no mirror regenerates from it and `test_docs_are_in_sync` is unaffected. --------- Co-authored-by: worktrunk-bot <[email protected]> Co-authored-by: worktrunk-bot <[email protected]> Co-authored-by: Maximilian Roos <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Version bump to 0.78.0 plus the changelog section for this release, a comment-preservation fix the release review turned up, a PTY test-filter fix, and merges of `main` (commits that landed during the review, including #4124, #4122, #4141, #4140 and #4145). **Bump level**: minor. `cargo semver-checks` reports 2 breaking library changes — a new `leftover_branch` field on the `GitError::WorktreeCreationFailed` struct variant, and `DEPRECATED_TEMPLATE_VARS` removed. Pre-1.0, so a breaking change takes a minor bump. ## Comment-preservation fix A config save — declining the commit-generation offer, say — dropped the trailing comment on every value it rewrote. That was already true in v0.77.0 for a line the save itself changed (`skip-commit-generation-prompt = false # note` → `true`, reproduced on the v0.77.0 binary). #4080 widened it to lines the command never touched: retired template variables now migrate on every load, so the next unrelated save rewrote any line naming one. #4080's own PR said this "needs a call before merge" and merged without one. - `replace_keeping_decor` keeps the value's decor (spacing after `=`, trailing comment) when `merge_tables` replaces a scalar. Comments *above* a line sit on the key and were never at risk. - `main`'s #4120 independently reworked the inline-table arm and moved a key's leading comment onto the rewritten header, but documented that a trailing comment after the closing brace "is still dropped". `replace_inline_with_table` now carries it after the header's `]`, so both of its callers keep it. - Tests: the existing comment-preservation test goes back to a retired name (the only fixture that exercises the replacement) and adds a comment on the mutated line; a new test snapshots and re-parses an inline `[projects]` entry. Each fails without its half of the fix. Not fixed, and identical on v0.77.0: a save deletes an explicitly written *default* value (e.g. `skip-commit-generation-prompt = false # note`) as a stale key, comment included. ## `--help` correction #4104 moved the OpenCode plugin path to etcetera's `Xdg` strategy, which uses `$XDG_CONFIG_HOME` only when absolute — a deliberate, documented choice — but `wt config plugins opencode --help` still said install mirrors OpenCode's precedence. OpenCode reads a relative value as-is, so the help now says an empty `$OPENCODE_CONFIG_DIR` and an empty or relative `$XDG_CONFIG_HOME` are ignored. ## Data-loss surface review Independent finders swept the full diff, including the five commits merged from `main`. Nothing holds the tag; candidates were adjudicated against v0.77.0 binaries: - **Fixed in this release, reproduced on v0.77.0**: #4104 stops `wt config shell install` (with Nushell) deleting a `nushell/vendor/autoload/wt.nu` under the current directory when `$XDG_CONFIG_HOME` is empty or relative; #4120 stops a save or migration from writing an inline section's comment inside `[commit]` brackets, which made the config unparseable, and from dropping unknown keys. - **`wt step prune --min-age` doesn't apply where no reflog exists** — pre-existing, proven by building the pre-#4077 binary. `git clone --bare` and `git fetch` into `refs/heads/*` write no reflog, so in the bare layout `tips-patterns.md` recommends every branch starts unprotected. Docstring corrected here; behavioral fix is follow-up. - **`wt config update --output <path>` replaces any named file whole**, no existence check or prompt — pre-existing, follow-up. - **`wt config shell install fish --yes` replaces a hand-written wrapper at the XDG path** — accepted ("ownership is the path", predates #3602), newly reachable only for users with `$XDG_CONFIG_HOME` set. The FAQ's delete inventory now cross-references it. - **`--var <retired-name>` binds a name nothing references** after #4080 — inert, no shipped usage; follow-up. - **#4135 migrates nothing**: an existing oh-my-pi hook stays put, `pi uninstall` points at `omp uninstall`. `PI_CODING_AGENT_DIR='~/x'` is used literally (Pi expands `~`) — creates a stray directory, deletes nothing; follow-up. ## Changelog 37 entries; each new or edited entry was re-verified against v0.77.0 until a pass came back clean (six passes in all). Passes caught, among others: the OpenCode `-x` recipe was wrong since 0.76.0, not 0.75.0; #4080's JSON reaches every hook, not just `pre-start`/`post-start`; a quoted git error string git never prints; a copy-button overlap that existed only inside this release; #4104's relative-`XDG_CONFIG_HOME` OpenCode change described as a fix when OpenCode reads that path as-is; and which commands a broken inline section stopped. **Fixed** leads with the data-loss entries. ## Open PRs checked against v0.77.0 - **#4124** fixed a bug new in this release, caused by #4080, and has landed and been merged in here. The hand-rolled template-variable scanner it extends is slated for removal; see its commit message. - **#4112** — no data-loss regression vs v0.77.0; two small non-safety regressions from #4111 (an uncapped auto-staging file list, a narrow `Nothing to commit` refusal under `status.showUntrackedFiles = no`). Not merged, by decision. - **#4122** (merged in) and **#4123** — pre-existing bugs, identical on v0.77.0. ## PTY filter fix `test (macos)` failed once on a shell's failed-`setpgid` diagnostic that landed straight after the capture's trailing `\x1b[0m`, with no newline between, so #4136's line-anchored filter missed it. The filter now also matches right after an SGR escape and keeps the escape; its test gains that shape and fails on the old pattern. ## Validation - `cargo run -- hook pre-merge --yes` — 4930 tests passed, 1 skipped; clippy, fmt, doc-sync, snapshot and lockfile checks green - Nightly on the original cut-from tip (https://github.com/max-sixty/worktrunk/actions/runs/35060617020): green across `full-tests` on linux/macos/windows, `feature-powerset`, all `release-target`s, `nix-flake`, `minimal-versions`, `link-check` > _This was written by Claude Code on behalf of max-sixty_ 🤖 Generated with [Claude Code](https://claude.com/claude-code)
# Conflicts: # src/config/unknown_tree.rs # src/config/user/persistence.rs
|
Merged #4156 already fixed the stale-key half, more thoroughly#4156 replaced the Nothing is lost by that. The "one behavior change worth a look" no longer happensThe PR body flags that an empty [list]
[projects."example.com/org/repo".list]So the one user-visible regression this PR was asking you to weigh is gone, removed by #4156 rather than by anything here. What's leftThe net diff against All four required checks pass on |
# Conflicts: # src/config/user/tests.rs
0.79.0 was prepared and merged in #4181 but never tagged, so it never shipped. Cargo.toml and Cargo.lock already carry the version, so this reuses it and folds the thirteen commits that landed since into the same changelog section. New entries cover the worktree-side rename fixes (#4190, #4191), the per-project unknown-field warning (#4123), and the unterminated code fence in the picker's preview (#4183, combined with #4178's column fix). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Problem
[projects."example.com/org/repo".list]is valid config, accepted on load — and every command printedunknown field projects.example.com/org/repo.listfor it.A section equal to its default is skipped during serialization, so it is absent from the round-tripped view
diff_tablescompares the raw file against.seed_schema_skeletonexists to rescue exactly that, but it restored only top-level keys: an emptied[list]read as known, the same section one level down read as unknown. All sevenUserProjectOverridessections carryingskip_serializing_if = "is_default"are affected —list,commit,merge,remove,switch,step,forge.Solution
WorktrunkConfiggainsvalid_scoped_keys()— a top-level key whose entries are themselves schema-typed tables, with the valid keys for one entry. User config returns("projects", UserProjectOverrides schema keys); project config has no such key and keeps the defaultNone.seed_schema_skeletonapplies the same restore inside each entry.Only schema-valid keys are seeded, so a genuine unknown in that scope still warns. The
UserProjectOverrideskey list has one home —user_project_override_keys(), shared withis_user_project_override_key.remove_section_key_inindeprecation.rsalready described this false positive in a comment and worked around it by deleting the section it emptied. That comment is updated to match the fixed behavior; the deletion itself is unchanged.Scope after #4160
This PR originally carried a second half, against
UserConfig::save_to'smerge_tablesstale-key sweep:compute_unknown_treefed both the warning and the preserve set that a whole-config rewrite consulted, so making a section stop reading as unknown also changed what a save kept. #4160 replaced that rewrite with a single-value edit throughtoml_editand deletedsave_toandmerge_tablesoutright, socompute_unknown_treenow feeds the warning only. Mergingmaindropped that half and its test (test_save_to_existing_file_keeps_section_holding_only_unknown_keys, which called the removedsave_to).What remains is a warning-path fix with no save-path behavior change. The "empty
[projects."<id>".list]is now dropped on save" note in the earlier description no longer applies — nothing rewrites the file wholesale for it to apply to.Testing
empty_per_project_section_is_known— the reported input produces an empty tree and no warnings. Fails before the change withNestedUnknown { path: "projects.example.com/org/repo.list" }.unknown_key_in_per_project_scope_still_warns— three cases that must keep warning: an unknown sibling section, an unknown key nested inside a known section, and a root-only user setting (skip-shell-integration-prompt) that has no per-project form.cargo test --lib config::is 537 passed at the merged head;cargo fmt --checkandcargo clippy --lib --testsare clean.Reported by @zach-hammad-vs from source inspection; the reproduction above confirms it.
Closes #4115 — automated triage