Repository navigation
fix(settings): record the global default when a global capability row toggles - #1964
Conversation
… toggles The MCP and Skills pages built every capability query with the project picker's selection appended, so toggling a global server or skill while a project was selected wrote a per-project override instead of the global default. The switch read as global, but the state only covered one project: turning a server off in project A left it enabled in project B and in sessions with no project, and the only way to stop it everywhere was to delete the definition. The backend has always distinguished the two scopes (agent_capabilities set_enabled: no project path writes the global default, a path writes an override), and the skills page shares that state module, so both pages carried the same defect. The toggle now passes only the row's level; project rows keep the path because the host resolves their definitions through that project's directory. List calls keep the project scope: they exist to show effective per-project state. Fixes vastsa#1957.
vastsa
left a comment
There was a problem hiding this comment.
Thanks for tracing the global write path, and for covering both MCP and Skills. This does not yet fix #1957 for users who already toggled a global row under a selected project. Both list calls still pass projectPath, so the row displays the effective project override, while this patch writes only the global default. Repro from existing data: project A has a global row override false (created by the old UI), global default is true; selecting A shows Off. Clicking it now writes global true (a no-op), optimistically shows On, and a refresh shows Off again. The user cannot turn the global default Off from A. Please make the global row's displayed state and toggle read/write the same scope, while preserving project-level rows and their required path. A behavioral regression covering an existing per-project override and a selected project would prove the fix; the added source regex cannot catch this mismatch.
muzimu217
left a comment
There was a problem hiding this comment.
The diagnosis and the fix are right, and the test's extra assertion that subagents carry no projectPath at all is a good touch — they are global-only, so the absence is structural rather than an oversight.
One thing to decide before merge: this corrects the toggle at the call site, but remove and transfer still go through the unconditional levelQuery, so a global row's remove and a "move to global" still carry the selected project.
That matters most for transfer. mcp.transfer parses from/to as CapabilityTarget and mcp_servers.rs:577 calls self.list(to.level, to.project_path.as_deref()) to check the destination for id/label collisions — so a global destination arrives with a project path attached. It is probably ignored for CapabilityLevel::Global (the directory comes from the level), but "probably ignored" is exactly the kind of assumption that turns into a bug when the destination logic changes.
Two ways to settle it, either is fine:
- keep the call-site ternary as written and add a line to the description saying
remove/transferstill pass the project for global rows because the host ignores it there; or - normalize the helper instead —
...(level === "project" && selectedProjectPath ? { projectPath } : {})— which fixes the toggle and both of those call sites with one rule, and lets the test assert the helper rather than the call site.
I had drafted (2) locally while reviewing #1957 and it is functionally equivalent for the toggle; the only reason to prefer (1) is a smaller diff. Either way the user-visible bug is fixed, so this is not a blocker.
muzimu217
left a comment
There was a problem hiding this comment.
The diagnosis and the fix are right, and the test's extra assertion that subagents carry no projectPath at all is a good touch — they are global-only, so the absence is structural rather than an oversight.
One thing to decide before merge: this corrects the toggle at the call site, but remove and transfer still go through the unconditional levelQuery, so a global row's remove and a "move to global" still carry the selected project.
That matters most for transfer. mcp.transfer parses from/to as CapabilityTarget and mcp_servers.rs:577 calls self.list(to.level, to.project_path.as_deref()) to check the destination for id/label collisions — so a global destination arrives with a project path attached. It is probably ignored for CapabilityLevel::Global (the directory comes from the level), but "probably ignored" is exactly the kind of assumption that turns into a bug when the destination logic changes.
Two ways to settle it, either is fine:
- keep the call-site ternary as written and add a line to the description saying
remove/transferstill pass the project for global rows because the host ignores it there; or - normalize the helper instead —
...(level === "project" && selectedProjectPath ? { projectPath } : {})— which fixes the toggle and both of those call sites with one rule, and lets the test assert the helper rather than the call site.
I had drafted (2) locally while reviewing #1957 and it is functionally equivalent for the toggle; the only reason to prefer (1) is a smaller diff. Either way the user-visible bug is fixed, so this is not a blocker.
|
Thanks for checking the remove/transfer paths. The current blocker is separate: an existing global-row override in project A remains the value returned by |
Review on the first cut left it half-fixed: the toggle wrote the global default, but the global list still passed the selected project, so its rows displayed effective per-project state. A reader with a legacy override under one project - written by the old UI - saw Off, clicked, wrote a no-op global true, watched the switch flip On, and saw Off again on refresh. The global default stayed unreachable from that project. Extract the scope decision into capability-scope.ts and apply it on both sides: the query attaches the project path to project-level rows only (the host resolves those definitions through the project's directory), which fixes the toggle and, as a bonus, stops remove and a move-to-global from carrying a stray path into the host's target parsing. The global list calls drop the project the same way, so what the switch displays is exactly what it writes. A reader with an old override can now clear the mixed state by toggling: the click writes the global default for real. Behavioral coverage in capability-scope.test.mjs narrates that exact override scenario; the page contract now pins the helper delegation and the scope-free global list calls.
|
Pushed 1a8996a addressing both reviews: @vastsa - the display/write mismatch. The global list calls now omit the selected project, so their rows read the global default - the same scope the switch writes. Your repro now works end to end: with project A's legacy override in place, the row shows the global default, the click writes it for real, and the refresh agrees. Once the default matches what the user asked for, the stale override is inert (the effective state equals the default), and the mixed state is cleared by the very act of toggling. @muzimu217 - option 2, the normalized helper. The scope decision moved into a dependency-free module, Coverage: |
vastsa
left a comment
There was a problem hiding this comment.
Thanks for the update. The global settings list now reads the same default that the toggle writes, which resolves the previous settings-refresh mismatch. However, the legacy overrides are not cleared or made inert by toggling: the effective runtime state still checks them first, and the new list hides them.
I reproduced this independently for BOTH MCP and Skills using a Host built from this head (cargo build -p host-core --locked), isolated data/agents/project directories, the new capabilityQuery("global", projectA) helper, and real *.list, *.setEnabled, and *.active RPCs:
- Start with global default On. Reproduce the old UI by calling
*.setEnabled({id, level:"global", projectPath:A, enabled:false}). This persists A=false. - With the new global query, settings reads On. Toggle Off, then On, through the new scope-free query.
- Settings reads On and
*.active({})includes the capability, but*.active({projectPath:A})still excludes it. The original false override survives. An upgrading user cannot re-enable that project from this switch anymore.
The inverse is also reproducible with a supported stored A=true override: global settings reads Off after a scope-free disable, while *.active({projectPath:A}) still includes the capability. This contradicts the issue's global-disable expectation. CapabilityState::set_enabled only mutates the key supplied to that call; it does not remove other project keys when the global default changes. enabled() continues to give those keys precedence.
Please complete the existing approach with an explicit compatibility policy for stored project overrides: either provide an actionable, visible project-override/reset path while clearly labeling the switch as the global default, or implement the intended all-project switch semantics with a deliberate, documented treatment of existing overrides. Please avoid silently discarding legitimate project state without deciding that policy.
Add a behavioral regression that seeds persisted false/true project overrides, exercises list -> toggle -> refresh -> effective runtime lookup for MCP and Skills, and covers Off -> On as well as On -> Off. The current helper test checks only query objects; it does not seed an override or exercise persistence/runtime lookup, so it passes despite this failure.
Validation: the two targeted suites pass (29/29), diff whitespace check passes, all six remote checks are green, and the PR head/integration candidate have the same tree. Those checks do not cover the persisted-state failure above, so I am keeping Request changes and leaving this unmerged.
Review round two, reproduced on a real host: hiding the override from the settings list did not make it inert. The runtime keeps giving a stored per-project key precedence, so an upgrading user with a legacy Off override could see the global switch read On, toggle it uselessly, and watch their project stay Off - and the stored On direction contradicted a global disable the same way. Take the first of the two policies the review laid out: the override becomes actionable and visible instead of silently discarded. When a project is selected, the pages fetch the project-scoped global list beside the scope-free one, deriveProjectOverrides() flags every row whose effective state disagrees with the default, the row shows an override badge (which direction), and the row menu offers a reset that writes the current default under the project's scope - the key the host removes because it matches the default. The switch keeps reading and writing the global default. deriveProjectOverrides is covered behaviorally with persisted false and true overrides in both toggle directions; the page contract pins the surfacing wiring. Four new strings in every locale.
|
Pushed 3b38677 taking the first policy: the override becomes actionable and visible rather than discarded.
On the regression ask: Four new strings land in every locale for the badge and reset affordances. |
vastsa
left a comment
There was a problem hiding this comment.
The new visible/resettable override direction addresses the previous policy concern, and the reset value correctly matches the Host's existing override-removal semantics. All 30 targeted tests pass. There is still a project-switch race in both pages: fetchServers/fetchSkills call setGlobalOverrides inside the async fetcher, before useHostCollection checks its request generation. For example, start a slow A request (override Off), switch to B (no override), let B finish, then A finish: useHostCollection rejects A's collection, but A has already replaced globalOverrides, so B displays A's warning/reset affordance. Reversing the overrides can hide B's actual mismatch and reset action entirely. This defeats the new actionable visibility guarantee.
Please return overrides as part of McpCollection/SkillCollection and derive them from the accepted collection (or use an equivalent generation guard), rather than setting independent state from the fetcher. Add a deferred-response project-switch regression for both pages, asserting that badges and reset actions belong to B after A finishes late. No need to change the Host or erase existing state.
Review round three, reproduced on both pages: the override map lived in its own state and was written from inside the fetcher, before useHostCollection's generation check. A slow fetch for project A landing after the reader switched to B repainted B's badges with A's overrides, and reversing the pair hid B's real mismatch and reset action entirely - defeating the visibility the previous round added. The map now rides inside McpCollection/SkillCollection, so it is accepted or rejected together with the rows it was derived from. The pages read it from the hook's data; the standalone state is gone. Regression coverage drives the real useHostCollection under a minimal React hook runtime (test/helpers/react-hook-stub.mjs, aliased via a resolve hook): a deferred project-A response landing after project B is rejected with its overrides, and the newest generation still wins in the reverse order.
|
Pushed 4cec03c (with current main merged in): the override map now rides inside For the deferred-response regression:
The hook runtime implements the exact hooks the module imports (state cells surviving across renders, |
|
The updated approach resolves the previously reported stale-fetch blocker: both override maps now travel inside the generation-guarded collection, with no fetcher-internal state write. All 32 targeted scope/settings/deferred-hook tests pass, also rerun after incorporating latest main at 5f713e0. Independently exercised real isolated Host RPCs for BOTH MCP and Skills with persisted false and true project overrides: the candidate helper detects each mismatch; the exact reset RPC clears the stored project key and runtime active state follows the global default. This used the existing Host binary (Host implementation is unchanged), not a packaged Electron UI test. The deferred test drives the real collection hook with a minimal hook runtime, not a real renderer. Prior substantive blockers are resolved. I non-destructively updated the PR branch with latest main after merging #1979; the new-head CI is running, so merge remains pending fresh integration checks. No contributor source changes or history rewrite. |
vastsa
left a comment
There was a problem hiding this comment.
All previously reported blockers are resolved at 5f713e0. Reconfirmed 32/32 scope/settings/deferred-hook tests; all six fresh checks pass. Latest main is an ancestor and integration tree ac2e263612bbe9846f0fcebe9bb849ac9b8697ee matches the tested head. Prior independent isolated Host RPC checks cover persisted false/true overrides and reset for both MCP and Skills. Local coverage uses a minimal hook runtime and real Host RPC, not interactive packaged Electron. Approved for merge.
Fixes #1957.
The MCP and Skills settings pages built every capability query through one helper that appends the project picker's selection whenever a project is selected. For the list calls that is the point - they exist to show effective per-project state - but the toggle used the same query, so switching a global server or skill while a project was selected wrote a per-project override instead of the global default. The switch read as global while the state only covered one project: disabling in project A left the server enabled in project B and in sessions with no project (which fall back to the global default), and the only way to stop it everywhere was deleting the definition.
The backend has always distinguished the two scopes -
set_enabledwrites the global default when no project path is given and an override when one is (agent_capabilities.rs), andenabled()reads override, then global default, thentrue. The skills toggle shares that state module (rpc/mod.rsskillscall site), so both pages carried the same defect. Subagents never did: they are global-only, which is also why the shared helper read as harmless.The toggle now passes only the row's own level. Project rows keep the path, because the host resolves project definitions by scanning that project's directory (
mcp_servers::findneeds it). List calls are unchanged.Contract coverage extended in
agent-capability-settings.test.mjs: both toggles must pass{ level }for global rows instead of the project-scopedlevelQuery(level), and the subagents page stays free ofprojectPath.Thanks to @muzimu217 for the exact call-chain and the catch that the skills page shares the defect.