Skip to content

fix(hooks): harden Pi/OMP shared-extension ownership lifecycle - #3875

Open
KuSh wants to merge 1 commit into
rtk-ai:developfrom
KuSh:fix/pi-omp-ownership-lifecycle
Open

KuSh wants to merge 1 commit into
rtk-ai:developfrom
KuSh:fix/pi-omp-ownership-lifecycle

Conversation

@KuSh

@KuSh KuSh commented Sep 5, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #3707.

#3707 added the .rtk-agents ownership record so that uninstalling one of Pi or OMP does not delete an extension file the other agent shares. As merged, the record is never created for an extension that existed before it, so the protection is inert for every upgrading user, and an extension with local edits can never be uninstalled.

Ownership record

  • A record started over an extension that already existed is marked partial (unknown-prior): RTK cannot tell who installed that file, so it no longer claims sole ownership of it. Example, with both agents' paths resolving to one file: install OMP over an existing Pi extension, then rtk init --agent pi --uninstall now asks before removing the file OMP uses, where it used to delete it and exit 0.
  • A readable record is merged into rather than reset, and is re-read just before it is written, since a confirmation prompt sits between the first read and the write.
  • An unreadable record left beside a deleted extension is replaced by the next install, as develop does.
  • Whether the Pi and OMP paths resolve to one file is worked out once per command, so reading the record, the warnings and the decisions act on one answer. Recording checks again when the paths did not meet at the start, since the install itself can make them meet (by creating the directory a link points to).

Install and uninstall

  • Install's question before overwriting a non-stock extension, and its --dry-run preview, say when the other agent loads the same file, or may load it, since the overwrite reaches both.
  • Edited RTK content gets install's Ask/Auto/Skip policy instead of a permanent "remove the file manually": rtk init --agent pi --uninstall --auto-patch removes it. The prompt says the edits are lost; no backup is kept.
  • That prompt, its --dry-run preview, and the refusal that suggests --auto-patch say when the other agent loads the same file, or may load it, since removing it removes it for both. The shared-file decision re-reads the record after the prompt.
  • --dry-run previews that prompt instead of the old refusal.
  • Pi and OMP go through one install and one uninstall function instead of two near-copies.
  • rtk init --show --agent pi shows the Pi extension instead of the generic configuration.

The Pi README no longer says the extension returns { block: true, reason } on a pipeline rule: since 2b96061 pipeline rules act on Claude Code only, and the extension only rewrites.

Where a write lands through symlinks, keeping project writes inside the project, and backups are left to #4269, which routes every init write through one guarded path.

Tests

tests/omp_init_test.rs covers the partial record and its completion, merging, the repair of an unreadable record, the single report of a bad record, the uninstall policy for both agents, the other-agent sentence for a shared, partial and missing record in both directions, an install whose own write makes the paths meet, and that a declined shared install is not announced; each new test was checked by reverting the code it pins. test_global_uninstall_detects_shared_pi_omp_extension no longer creates an empty .omp/ in the checkout it runs from.

Verification

cargo fmt --all --check, cargo clippy --workspace --all-targets and cargo test --all clean, also with --no-default-features; cargo doc --no-deps clean; type-checked for x86_64-pc-windows-gnu with --all-targets.

🤖 Generated with Claude Code

@KuSh
KuSh force-pushed the fix/pi-omp-ownership-lifecycle branch 6 times, most recently from f497ce1 to 0bfa30a Compare September 20, 2026 23:01
@KuSh
KuSh force-pushed the fix/pi-omp-ownership-lifecycle branch from 0bfa30a to 8615434 Compare September 21, 2026 05:49
@KuSh
KuSh force-pushed the fix/pi-omp-ownership-lifecycle branch from 8615434 to fed0895 Compare September 28, 2026 01:10
@KuSh
KuSh force-pushed the fix/pi-omp-ownership-lifecycle branch 2 times, most recently from 2dfbe3f to 58b5c56 Compare October 7, 2026 16:34
@KuSh
KuSh force-pushed the fix/pi-omp-ownership-lifecycle branch 2 times, most recently from 3382937 to fa7fde9 Compare October 19, 2026 22:37
@KuSh
KuSh force-pushed the fix/pi-omp-ownership-lifecycle branch from fa7fde9 to 67ef054 Compare October 31, 2026 13:26
Follow-up to rtk-ai#3707. The ownership sidecar could not protect the case it
exists for, and an edited extension could not be uninstalled at all.

Ownership:
- Record ownership for an extension that pre-dates the sidecar, marking
  the record partial instead of claiming sole ownership. Without this the
  sidecar is never created for an upgrading user, so shared-file
  protection is inert for everyone who already had the extension.
- Merge into an existing record rather than resetting it: deleting the
  file does not unconfigure an agent that still resolves to that path.
- Re-read the record immediately before writing, since a confirmation
  prompt sits between the caller's read and the write.
- Work out once, up front, whether the Pi and OMP paths resolve to the
  same file, so reading the record and warning act on one answer; an
  install checks again before recording, since creating the directory
  can make the paths meet.

Uninstall:
- Give uninstall the same Ask/Auto/Skip policy as install, so a
  hand-edited or fork-built extension stays removable with --auto-patch
  instead of being permanently stuck. The question says the edits are
  discarded.
- That question, and the advice to rerun with --auto-patch when it is
  declined, say whether the other agent loads the same file, since
  removing it removes it for both. The shared-file decision re-reads the
  record after the question.
- Make --dry-run describe what the real run does.
- Install's question before overwriting a non-stock extension says the
  same, since the overwrite reaches the other agent too.
- Pi and OMP share one install and one uninstall path instead of
  near-copies.

`rtk init --show --agent pi` reports the Pi extension instead of the
generic configuration. The Pi README no longer says the extension blocks
commands on a pipeline rule; it only rewrites.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant