Repository navigation
[CTX-1876] fix(platform): adopt the legacy plugins-state root (bitty#3236) - #3238
Conversation
…3236) bitty#3226 made the Windows data root prefer %LOCALAPPDATA% over $HOME. PR #3230 adopted the plugin store from the pre-change root; the plugins-state sibling was still resolved by a join at its one call site, so an upgraded install kept its packages and silently lost the state they wrote. Resolve both entries through one data-tier resolver (PluginDataTier:: Store/State): one legacy predicate, one one-time migration, one read-only variant for --safe, `doctor` without --repair, and shell completion. An existing current root still wins and is never merged, so discovery reads exactly one index and the capability model is unchanged. discover_with_roots now takes the resolved state root instead of reading the live one inside the CTX-1115 seam, so a test can no longer adopt a real user's tree. Tests: a Windows-only fixture drives the built bitty.exe (legacy store present and absent) and a Windows unit fixture covers both tiers over the real filesystem; the platform-independent policy tests now cover the state tier on every leg. Refs #3236
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 41 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Xuepoo
left a comment
There was a problem hiding this comment.
Review: adopt the legacy plugins-state root (CTX-1876 / bitty#3236)
Reviewed at 6affd86cbad5fd178e76f19f4a46d5d9679d06ae. Scope: plugin_runtime.rs (tier resolver + seam), tests/windows_legacy_store_migration.rs, the PluginRuntimeConfig::data_dir doc, CHANGELOG. #3230's store adoption is already in main; this adds the State sibling to the same resolver and removes the ad-hoc join at the discovery call site.
What I actually ran (lane worktree, CARGO_TARGET_DIR=.targets/ctx-1876):
RUSTFLAGS="-D warnings" cargo check -p bitty-terminal -p bitty-runtime --tests --target x86_64-pc-windows-gnu --offline→Finishedin 2.06s,Checking bitty-terminal(real re-check, not a no-op), zero diagnostics.cargo +1.85 check -p bitty-terminal -p bitty-runtime --tests --offline→ re-checkedbitty-runtime+bitty-terminalin 12.57s (60s CPU), zero warnings on the non-Windows leg.cargo test -p bitty-terminal --offline -- legacy|store_root|adopt→ 21 + 1 + 23 tests pass, including both new state tests.- Mutation reproduction in
/home/fuyu/.hermes/cache/scratch/review-3238/with its own target dir (details in check 4).
1. Single authority — PASS
One resolver, one legacy predicate, one adoption for both tiers: tier_root_with_platform_env (crates/bitty-terminal/src/plugin_runtime.rs:1236) is the only place a tier path is built; PluginDataTier::{Store,State} (:1204-1225) carries only the leaf name, so plugins and plugins-state cannot drift. The pure, non-adopting form is now #[cfg(test)] (:1256), so no shipped caller can read the pre-adoption root by accident.
Every surface resolves through that body:
- startup discovery →
startup_store_root/startup_plugins_state_root(:1520,:1567), safe mode → read-only variants (:1552-1564) list plugins,list services,config_reload,x→store_root()(:1168; callerslist.rs:888,list.rs:1423,x.rs:120,config_reload.rs:819)plugin install|remove|doctor --repair|extension→plugin.rs:5620-5637;doctorwithout--repair→ read-only (plugin.rs:5623)- shell completion →
candidates.rs:203 bitty init→init.rs:3241;--safesnapshot →runtime_inspect.rs:206-221
Grep for a second resolution: grep -rn "plugins-state" crates/ finds no production join outside PLUGIN_STATE_DIR_NAME (:1193); grep -rn 'join("plugins")' finds only tests, config-layer file names, and plugin_settings.rs:1072 (the config plugins/ dir, a different tier). The only remaining direct data_home() caller is the third-party wheel dir (config_manage.rs:89), which is documented as owning its own layout (:1596-1612). No second -state suffix exists.
2. Security invariants — PASS
- Discovery stays single-authority. The diff adds no discovery root:
bundled_roots/third_party_roots/dev_rootsare untouched, and the state root is passed asPluginRuntimeConfig::data_dir(:1823, consumed atbitty-runtime/src/plugin_runtime/mod.rs:4927-4934), which is a plugin-writable key-value directory, never a package source. Existing current root ⇒ no merge (legacy_store.rs:256-258), so exactly one index is ever read; capability/deny-by-default code is not in the diff at all (git diff --stat= 4 files, none in the policy host), so R-006/R-015/R-017 are unaffected. - Legacy tree is never written by the legal read paths:
read_only_store_root(legacy_store.rs:160-168) only stats/read_dirs; safe/doctor/completion resolve throughread_only_tier_root_with_platform_env(:1397) and create, move and copy nothing. - Failed migration keeps the legacy tree serving:
effective_tier_root_with_platform_envreturnsoutcome.store_root(&root, &legacy)(:1360-1363), andFailed/Unreadablere-probe and fall back to the legacy path (legacy_store.rs:113-137).Unreadableexplicitly returns before anycreate_dir_all(legacy_store.rs:241-252), so a transient enumeration failure cannot fork an empty second tree. The tier-generic warning now names the tier (:1354-1386), so the operator sees "plugin state" vs "plugin store".
3. Windows correctness — PASS
- The
cfg(windows)fixtures exercise real paths:windows_legacy_tier_fixture(:6626-6890) plantsUsers/u/.local/share/bitty/{plugins,plugins-state}plusAppData/Local, calls the real resolvers, and asserts the file/package moved (store.json is_file,rows.len()==1,name == "Legacy Store"), the legacy tree is gone, and a second resolution is idempotent.startup_plugins_state_root_with_platform_env(true, …)is asserted to leave the legacy state in place while the non-safe call adopts it (:6815-6840) — that contrast is what discriminates, not a tautology. - No Unix-only assertion: the fixtures use
std::fs,Path,to_string_lossy;windows_legacy_store_migration.rs:53usesSystemTime::now().duration_since(UNIX_EPOCH), which is portable. Both compile under--target x86_64-pc-windows-gnu --testswith-D warnings. - Non-Windows leg is clean:
cargo +1.85 check … --testsprinted nodead_code/unused_imports, so#[cfg(test)] store_root_with_platform_envand the tuple-only helpers do not leak. Bothbitty-runtimeandbitty-terminalwere genuinely recompiled, so this is not a replayed cache hit.
4. Test discrimination — PASS (reproduced, then restored)
Copied the worktree to /home/fuyu/.hermes/cache/scratch/review-3238/repo, mutated exactly one function — effective_plugins_state_root_with_platform_env (:1454-1467) reverted to the pre-PR plain join (tier_root_with_platform_env(PluginDataTier::State, …), i.e. the old data_home().join("bitty").join("plugins-state")) — and ran with a separate CARGO_TARGET_DIR=…/review-3238/target:
test plugin_runtime::tests::legacy_plugins_state_adoption_covers_the_same_population ... FAILED
panicked at crates/bitty-terminal/src/plugin_runtime.rs:6451:9:
the state file moved with its tier
test result: FAILED. 0 passed; 1 failed; 0 ignored; 1666 filtered out
Restore: reverted the mutation, diff -q against the lane file reported identical, and the same target dir then ran legacy_plugins_state_adoption_covers_the_same_population … ok / legacy_plugins_state_is_never_adopted_outside_the_windows_home_population … ok. The claim is real; the lane worktree was not modified.
5. Docs accuracy — PASS
CHANGELOG.md:8-29 is under ## [Unreleased] and makes no release claim (the only dated heading stays ## [0.0.31] - 2026-10-29). Every factual statement checks out against code: precedence $XDG_DATA_HOME > %LOCALAPPDATA% > $HOME/.local/share > %APPDATA% (bitty-runtime/src/component/mod.rs:184-229), component state $XDG_STATE_HOME > %LOCALAPPDATA% > $HOME/.local/state (component/activation.rs:214-226), one-time rename with bounded copy fallback, failed move keeps reading the legacy tree, and the three read-only verbs. PluginRuntimeConfig::data_dir (bitty-runtime/src/plugin_runtime/mod.rs:354-362) now states the caller resolves it and why. The entry does describe #3226/#3230 behaviour that is already in main but was previously undocumented — acceptable for an unreleased bullet, worth keeping in mind at release time.
6. Behavioural risk — PASS
- Merge with an existing current root: never.
new_root_exists(legacy_store.rs:216-218) is asymlink_metadatapresence test and short-circuits toNewRootPresentbefore anycreate_dir_all/rename (:256-258). - Symlinks: the legacy root is classified with
symlink_metadataand a symlinked or non-directory root isAbsent(legacy_store.rs:187-199), so no adoption follows a link. The copy walk uses non-followingentry.file_type()and refuses any non-regular entry withFailed(:397-418) — a planted symlink/FIFO leaves the legacy tree serving instead of producing a partial store. - Unbounded copy: genuinely bounded — depth 8 (
:49), 8192 entries (:55), 256 MiB (:67), one shared budget decremented across the recursion (:371-411), byte budget checked before eachfs::copy. Overrun abandons the staging tree (:319-331) and returnsFailed, which keeps the legacy root. There is a unit test for each bound (:568,:793). The only residual is a metadata-vs-copy TOCTOU on a file that grows betweenlen()andfs::copy, bounded in practice by the entry/depth caps — not worth a change. - Staging names are leaf-derived (
plugins.adopting-<pid>/plugins-state.adopting-<pid>,:344-353), so the state tier cannot collide with the store's staging dir.
Non-blocking notes (not required for this PR)
- The new
plugins_state_rootseam is compile-verified but never exercised: the production call passesstartup_plugins_state_root(safe_mode)(:1741), while every test call site passesNone(:2719,:2834,:3172,:3405,:3572). Becausedata_dir: Nonedegrades to an in-memoryPluginStore(bitty-runtime/src/plugin_runtime/mod.rs:4927-4934), a future regression that drops this argument would be as silent as the bug being fixed. One test threading a real state root throughdiscover_with_rootsand asserting<root>/<id>/store.jsonwould close that hole. - Same stranding shape exists for the component/extension tier:
components_root_for(bitty-runtime/src/component/descriptor.rs:93-103) andcomponent_state_root_for(component/activation.rs:236-247) joinbitty/extensionsdirectly with no legacy adoption. Out of scope for bitty#3236, but the CHANGELOG's "one data-root resolver" should not be read as covering it. init_plugin_inventory_for_env(init.rs:3238) documents "nothing is written" while calling the adopting resolver — pre-existing inmain, but it is the same doc/reality gap this PR is cleaning up elsewhere.
VERDICT: APPROVE
What
Completes bitty#3236 (the residual bitty#3226 / PR #3230 left open): after the Windows data root began preferring
%LOCALAPPDATA%over$HOME, an install that hadHOMEexported kept neither of the two entries it wrote to the old root.PR #3230 moved the store. The
plugins-statesibling — each plugin's<plugin-id>/store.json— was still resolved by a second, ad-hoc join at the one call site that needed it (data_home().join("bitty").join("plugins-state")), so it stayed behind in$HOME/.local/share/bitty/plugins-state: the plugins stay installed and silently start from an empty state. That is the same defect class the store had, in the entry the fix did not cover, which is why it is fixed here by removing the second resolution rather than by adding a second migration.The policy (one resolver)
One-time migration + convergent read-only fallback, now for every data tier instead of the store only:
adopt_legacy_store: rename; a bounded, staged copy when the roots are on different volumes);--safe,bitty plugin doctorwithout--repair, shell completion) use the read-only variant of the same precedence and move nothing.PluginDataTier(Store,State) plustier_root_with_platform_env/legacy_tier_root_with_platform_env/effective_tier_root_with_platform_env/read_only_tier_root_with_platform_envare now the only place that answers "where does a data tier live". The store and the state sibling differ by one enum arm, so a future tier cannot drift out of the policy the wayplugins-statedid.Surfaces
store_root(startup discovery)effective_store_root_with_platform_env(PR #3230)PluginDataTier::Storewrapper over the shared bodydata_home/data_home_with_platform_envplugins-statedata_home()…join("plugins-state")at the call site — no legacy handlingstartup_plugins_state_root_with_platform_env→PluginDataTier::State(+ read-only variant under--safe)bitty pluginCLI (install/remove/doctor/list)effective_/read_only_store_root_with_platform_env(PR #3230)discover_with_rootsnow takes the resolved state root as a parameter instead of reading the live one inside the CTX-1115 test seam, so a test can no longer adopt — i.e. move — a developer's realplugins-statetree.Tests (non-vacuous)
Windows-only, on the real filesystem:
tests/windows_legacy_store_migration.rs(#![cfg(windows)]) drives the builtbitty.exewithHOMEexported,%LOCALAPPDATA%set and$XDG_DATA_HOMEunset, plants a real installed package (manifest +lua/init.lua, index with the realmanifest_hashandcontent_digest) in$HOME/.local/share/bitty/plugins, and assertsbitty plugin list --format jsonlists it with the package name (so the bytes moved, not just the index), that the store now sits under%LOCALAPPDATA%\bitty\plugins, that the legacy tree is gone, and that a second run moves nothing.tests/windows_legacy_store_migration.rs::current_windows_root_untouched_when_no_legacy_store_exists— legacy absent: the command succeeds, nothing is listed, no store is created, no legacy path is invented, and the resolver still answers afterwards.plugin_runtime::tests::windows_legacy_tier_fixture(#[cfg(windows)]), same fixture shape for both tiers: store present/absent,plugins-statepresent/absent,--safeleaving a present legacy state tree in place while the non-safe startup adopts it, and one install where the store migrates first and the state tier still finds its own legacy tree.Platform-independent policy tests (they run on every leg and are what the Windows fixture is checked against) keep covering the legacy-root predicate and its exhaustion: XDG set,
%LOCALAPPDATA%unset, empty legacy root, existing current root,--safe, and the concurrent-resolution race.Each Windows test asserts the observable consequence of the adoption (the tree is at the current root, the legacy one is gone, the package/state bytes are readable through it), so it fails whenever the corresponding adoption does; see Discrimination below for the run that proves the state tests bite. No Unix-only assertion is introduced, and the Windows leg compiles the new test targets under
-D warnings.Gates (local, this commit
6affd86c)Run in the worktree with
CARGO_TARGET_DIRoutside it; every command below is the exact one run.cargo fmt --all -- --checkcargo clippy -p bitty-terminal --all-targets --offline -- -D warningscargo clippy -p bitty-runtime --all-targets --offline -- -D warningscargo test -p bitty-terminal --offlinecargo test -p bitty-runtime --offlineRUSTFLAGS="-D warnings" cargo check -p bitty-terminal --tests --target x86_64-pc-windows-gnu --offlineRUSTFLAGS="-D warnings" cargo check -p bitty-runtime --tests --target x86_64-pc-windows-gnu --offlinecargo +1.85 check -p bitty-terminal --tests --offlinecargo +1.85 check -p bitty-runtime --tests --offlineRUSTDOCFLAGS="-D warnings" cargo doc -p bitty-terminal --no-deps --offlineRUSTDOCFLAGS="-D warnings" cargo doc -p bitty-runtime --no-deps --offlinejust scratch-pathsNotes:
cargo test -p bitty-terminalrun faileddoctor::tests::dry_run_writes_nothing(noinstance-socketreceipt) while the machine was also building. It passes 3/3 in isolation and the suite is green in two subsequent full runs;doctor.rsis untouched by this diff.just markdownlintcurrently reports 12 pre-existingMD060/MD049issues in five files this PR does not touch (crates/bitty-render/assets/README.md,packaging/README.md,packaging/upgrade.md,specifications/fuzz-campaign-ctx-1877-evidence.md,vendor/winit/PATCHES.md). TheCHANGELOG.mdentry added here is not among them, and CI's markdownlint step passed at5a9b3eb3, so this is local tool-resolution drift rather than a repository defect. Not fixed here.just ci-local(theactleg) was not run: it builds a Docker image and needs network access this task cannot rely on. Everything above ran.Discrimination
Removing the state tier's adoption (calling
tier_root_with_platform_envdirectly instead ofeffective_tier_root_with_platform_env, i.e. the pre-fix behaviour) makesplugin_runtime::tests::legacy_plugins_state_adoption_covers_the_same_populationfail withthe state file moved with its tier, whilelegacy_plugins_state_is_never_adopted_outside_the_windows_home_populationstill passes — the test bites on the migration, not on the predicate. The mutation was reverted before the commit above and the tree was verified clean (git status --porcelainempty).Documentation
CHANGELOG.mdgains an## [Unreleased]→### Fixedentry (the release-notes file inside this repository; its newest section is far behindCargo.toml, so the entry goes underUnreleasedrather than inventing a version heading).bitty-terminal-docsis not edited here: its working tree is shared and may hold other agents' edits. The platform-reference text is proposed below as a follow-up for that repository.Follow-up for
bitty-terminal-docs(please apply in its own PR)configuration/lua-and-xdg.md§"Data, state, cache, and runtime layouts" is still marked candidate layouts and its tree listsplugin-state/under$XDG_STATE_HOME/bitty/, which no longer describes the shipped code. Proposed replacement for the data tree plus a new note:Deliberately out of scope
bitty_plugin_host::grant::grants_path_for(persisted grants) still resolves$XDG_STATE_HOME>$HOME/.local/statewith no%LOCALAPPDATA%arm. It is a security-relevant store, so moving it strands existing grants and needs its own migration — not a diagnostics or plugin-state projection.stall_watchdog::state_file_pathkeeps its own order (XDG_STATE_HOME>HOME>LOCALAPPDATA); unifying the two state resolvers is a separate change.config_manageresolves the third-partywheeldata directory fromdata_home()directly.wheelowns that layout and has no Bitty tier or pre-change population in this repository.Closes #3236