Skip to content

plugin-profiles: a failed concurrent apply's rollback deletes the other apply's record #18218

Closed

Description

@kyle-sexton

Refs: #16428

Steps to reproduce

  1. Two writers apply a profile to the same settings file at nearly the same time (for example /plugin-profile finishing a pending switch beside a terminal apply, or two sessions switching the same repository).
  2. Both read the same file hash and record. Apply A saves its record and writes the settings file.
  3. Apply B saves its record, then its settings write fails the hash guard.

Expected behavior

Apply B's failure leaves Apply A's record in place, so clear and reset can still undo Apply A.

Actual behavior

Apply B's rollback runs saveRecord(p.recPath, p.previous) or deleteRecord(p.recPath), which overwrites Apply A's record with the pre-A record or deletes it (plugins/plugin-profiles/scripts/profiles.mjs:568-574). Apply A's entries then sit in the settings file with no record: clear reports no record, and reset can only offer to remove every enabledPlugins/skillOverrides entry of that file.

The existing concurrency test (AC21, scripts/profiles.test.mjs:567-585) covers only a non-profile writer, not two profile applies.

Severity

Medium

Severity justification

It needs two writers racing on one file, but the result is a profile change that the plugin's own undo paths can no longer reverse.

Suggested fix location

plugins/plugin-profiles/scripts/profiles.mjs:568-574: roll back with the same compare-then-swap as swapRecord (lib/record.mjs:131-143), restoring the previous record only if the record on disk is still the one this apply wrote; add a test with two profile applies racing.

Environment

plugin-profiles 0.9.5, Claude Code 2.1.330, WSL2. Found by a read-only code audit; not reproduced live.

Owned by the session that filed it (session-owned); worked, if at all, in the profiles follow-up at the end of that session.

Activity

  1. added
    session-owned
    on Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    session-owned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions