Skip to content

fix(plugin-profiles): roll back an apply's record only while it is still ours - #18249

Merged
kyle-sexton merged 2 commits into
mainfrom
fix/18218-profiles-rollback-cas
Nov 22, 2026
Merged

kyle-sexton merged 2 commits into
mainfrom
fix/18218-profiles-rollback-cas

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Closes #18218

Summary

When two applies race on one settings file and the second one's settings write fails, its rollback overwrote or deleted the first apply's record, so clear and reset could no longer undo the first apply.

Fix

  • lib/record.mjs: new rollbackRecord(path, ours, previous) puts the previous record back (through swapRecord's compare-then-rename) or deletes the file, only while the file still holds the record this apply wrote; otherwise it leaves the file alone.
  • scripts/profiles.mjs commit: both rollback branches use it.

Verification

  • New lib/record.test.mjs (3 tests): restore and delete while the record is ours, and both leave another apply's record in place.
  • node --test scripts/profiles.test.mjs: 219 pass.

Related

  • Found in the context-budget profiles follow-up; the acceptance run for plugin profiles needs this fix (item 4: two applies at once keep both records).

🤖 Generated with Claude Code

https://claude.ai/code/session_01RAoAtSsNvSGmqHFVRFAugW

@kyle-sexton
kyle-sexton marked this pull request as ready for review November 22, 2026 21:49
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T21:57:49.630138Z 622ecb7 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 21319dd7ea1049092c8256acca10c8887214f554: read 2 of 2 changed file(s); 0 finding(s), 0 as inline comments.

Security review (incremental, blocking only): no security issues found

I reviewed the changes since 622ecb7b, and found no security issues. This lane already reviewed an earlier head, so the review was blocking only: it reports CRITICAL and IMPORTANT findings only.

I read every hunk of both files in scope:

  • plugins/plugin-profiles/scripts/profiles.test.mjs adds two node:test cases for plugin-profiles: a failed concurrent apply's rollback deletes the other apply's record #18218. They run the CLI in a child process, under the existing temp-dir world() fixture, with --import pointing at a new preload.
  • plugins/plugin-profiles/tests/race-settings-write.mjs is a new test-only preload. It wraps fs.renameSync so that the first rename onto a settings.local.json does two things:
    • it overwrites the record file the run last renamed, using another apply's profile name;
    • it then throws EIO, simulating a race.

What was checked:

  • Where the preload runs: both files are test fixtures. The preload loads only through the RACE URL, which is built from STUB_BIN, a path inside the repository. It is passed as an explicit --import to children spawned by the tests. Nothing in the shipped plugin code or manifest loads it.
  • Inputs and outside access: no untrusted input reaches either file. Neither adds a network call, a shell string, credential handling or a new path outside the test temp dirs.
  • Manifests and controls: neither file is on a trusted path. No plugin.json or marketplace.json changed, so there is no manifest block. No trust control or standing instruction changed.
  • Prior findings: the only prior entry is last round's no-findings summary, so nothing is re-posted.
  • PR text: the PR context contains no embedded instructions to the lane.

critical-findings: 0

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

claude-review: 1 inline finding(s) on 622ecb7b90e0a705ba3037cbb8c2a5cb41a96d1e; the summary is in this lane's pull request comment.

claude-lane: claude-review

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed 21319dd7ea1049092c8256acca10c8887214f554: read 2 of 2 changed file(s); 0 finding(s), 0 as inline comments.

Code review: PR #18249 (incremental, 622ecb7 → 21319dd)

This was a blocking-only review. The prior-findings file says blocking only: yes, so only blocking findings would be posted. I found none.

Scope: plugins/plugin-profiles/scripts/profiles.test.mjs and the new plugins/plugin-profiles/tests/race-settings-write.mjs. I read every hunk of both.

Does this push answer the earlier finding? The earlier finding (no test fails if commit's rollback wiring breaks) is settled: its thread was resolved with an owner reply, and its lines in scripts/profiles.mjs have not changed. I traced the new tests through the code at head to check that they really cover that wiring:

  • The hook. race-settings-write.mjs patches fs.renameSync and calls syncBuiltinESMExports(). That makes the named import of renameSync in lib/atomic-file.mjs call the patch, so the record write and the settings write both go through it.
  • The order. In commit, claimRecord renames the record first. The settings write comes after, at scripts/profiles.mjs:565-568. So the hook has a record to overwrite before it fails the settings rename.
  • Plain branch, no earlier record. rollbackRecord(p.recPath, ours, null) sees text that is not ours and leaves the file. The old deleteRecord would have removed it, and ["other-apply"] would then fail.
  • Plain branch, with an earlier record. swapRecord's compare-then-rename leaves the other apply's text in place. The old saveRecord(previous) would have overwritten it with review.
  • Finishing branch. claimRecord renames the data-folder record, then the repository record. The hook overwrites the repository record, which was renamed last. On rollback, the data record is put back to the pending text and the repository record is kept. The old deleteRecord would have left .git/plugin-profiles/records empty.

From this tracing, the new tests would fail on the old wiring and pass on the fix. I did not run them. The "224/224" in the owner's reply is the author's claim, not checked here.

Other notes:

  • No embedded instructions were found in the PR context, settled-threads or prior-findings files.
  • No plugin manifest changed in this push, so there are no manifest lines.
  • Loosened-check criterion: nothing in this push loosens a check. Loosened checks would be marked: fail (the default, since the prompt has no loosened_check_verdict: or loosened_check_patterns: line); patterns: 0. With no loosened_check_decision_record: line, the citation requirement was not checked.

Verifier dropped 0 of 0 candidates.

…write

A preload loaded with node --import overwrites the record an apply
just saved with another apply's record, then fails the settings
rename. The tests cover commit()'s plain rollback, with and without a
record before, and a finish whose record moves from the data folder to
the repository. Both fail on the old deleteRecord/saveRecord wiring.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 22, 2026
Merged via the queue into main with commit ac1c362 Nov 22, 2026
52 checks passed
@kyle-sexton
kyle-sexton deleted the fix/18218-profiles-rollback-cas branch November 22, 2026 22:49
@github-actions github-actions Bot added the merge-path: owner-agent Post-merge accounting record (README.md, Merge paths) label Nov 22, 2026
kyle-sexton added a commit that referenced this pull request Nov 22, 2026
Two applies racing on one folder still lost a record after #18249:
apply B read no record, apply A then saved its record and wrote the
settings file, and B's claim overwrote A's record. B's settings write
then failed on the changed file, and its rollback, finding its own
record there with nothing before it, deleted it. Clear then had no
record of A's 97 entries.

claimRecord now swaps the record only while the file still holds the
text prepare read, and raises SettingsConflict otherwise, so apply
re-plans with A's record as the previous one. saveRecord has no caller
left and is removed.

Found by the plugin-profiles acceptance run (item 4).

Refs: #18218

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-path: owner-agent Post-merge accounting record (README.md, Merge paths)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant