fix(permissions): stop always-allow/deny persistence from clobbering concurrent config writes#118
Merged
Merged
Conversation
…concurrent config writes persist_decisions_to_agent wrote the workspace config via a bare load->mutate->save, bypassing the process-wide writer lock in workspace_config::update(). A permission decision racing another config write (starring a workspace, re-anchoring a schedule) could silently discard that write and refresh the workspace index from the stale snapshot — the same lost-update class already fixed for mark_opened in commands/workspace.rs. - Run the read-modify-write inside workspace_config::update() and refresh the index from the config returned under the lock. - Fast path: skip the lock + disk round-trip entirely when decisions contain nothing durable (Once-only, or Always with blank prefixes). - Extract the list surgery into apply_decisions_to_shell_policy(), a pure function over WorkspaceAgent, and unit-test it: allow/deny list moves, idempotency (no change reported on re-apply, no duplicates), trimming, and no-op decisions. Found by Codex during the PR #116 review.
juacker
marked this pull request as ready for review
July 23, 2026 10:44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a lost-update race: persisting an always-allow/always-deny permission decision could silently clobber a concurrent workspace-config write.
Problem
persist_decisions_to_agent(src-tauri/src/commands/permissions.rs) wrote the workspace config via a bareload -> mutate -> save, bypassing the process-wide writer lock inworkspace_config::update(). A permission decision racing another config write (starring a workspace, the scheduler re-anchoringnext_run_at_unix_ms) could discard that write and refresh the workspace index from the stale snapshot. Same lost-update class already fixed formark_openedincommands/workspace.rs.Change (1 file)
workspace_config::update(); the index refresh uses the config returned under the lock.apply_decisions_to_shell_policy(), a pure function overWorkspaceAgent, with 5 new unit tests (allow/deny list moves, idempotency + no duplicates, no-op decisions, prefix trimming).Deliberate tradeoffs (flagged in review)
update()saves unconditionally): harmless atomic rewrite, kept in favor of the uniform locked helper.submit_permission_decision, dropping the oneshot sender and cancelling the awaiting tool even for a plain Allow-once — the new behavior is strictly better.Follow-up recorded in TODO
Deduplicate the
update() + insert_configplumbing shared withupdate_workspace_config_for_id(commands/workspace.rs) andupdate_workspace_config(commands/workspace_agents.rs) into onepub(crate)helper.Verification
cargo test --lib: 810 passed. Clippy clean,cargo fmt --checkclean.Found by Codex during the PR #116 review.