Skip to content

#340: Prune orphan prompt values on pack removal#342

Merged
bguidolim merged 2 commits intomainfrom
bruno/340-prune-orphan-prompt-values
Apr 24, 2026
Merged

#340: Prune orphan prompt values on pack removal#342
bguidolim merged 2 commits intomainfrom
bruno/340-prune-orphan-prompt-values

Conversation

@bguidolim
Copy link
Copy Markdown
Collaborator

Why

Closes #340. After #339 introduced prompt-value reuse on re-sync, removing a pack leaves its prompt keys behind in project state. A later-installed pack that happens to declare the same key (realistic collisions: BRANCH_PREFIX, LABEL_PREFIX, DEFAULT_ASSIGNEE) sees the removed pack's answer as a "prior" in the reuse gate — surfacing a value the current pack selection never authored. Prompt values can also hold MCP env vars (API keys, tokens), so orphan retention is a minor credential-hygiene issue in addition to the surprise factor.

Changes

  • After unconfiguring a pack, drop any resolved-value entries whose keys are not declared by the packs that remain configured.
  • Both removal paths now prune: mcs sync deselecting a pack, and mcs pack remove (which unconfigures per affected scope).
  • When the last declaring pack goes away, the key is dropped entirely; when another configured pack still declares it, the value is retained.

Test plan

  1. Add a pack that declares a prompt, sync, answer with a custom value, then deselect the pack — inspect .claude/.mcs-project and confirm the key is gone.
  2. Add a second pack that declares the same key with a different default, sync — confirm no "Reuse N values?" gate surfaces the old value and the new pack's default is used.
  3. With two packs both declaring the same key, remove one via mcs pack remove — confirm the shared value is retained because the remaining pack still declares it.

- Drop resolvedValues entries whose keys no surviving pack declares, so later packs declaring the same key are asked fresh instead of inheriting a stale prior from a removed pack.
- Apply pruning inside unconfigurePack so both mcs sync deselection and mcs pack remove federated cleanup benefit from the same logic.
- Cover orphan removal and shared-key retention with lifecycle tests.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Prunes orphaned prompt resolvedValues from persisted project/global state when a tech pack is deselected/removed, preventing stale cross-pack prompt reuse (and improving credential hygiene for prompt-stored secrets).

Changes:

  • Prune ProjectState.resolvedValues after pack unconfiguration to keep only keys still declared by remaining configured packs.
  • Add ProjectState.pruneResolvedValues(keepingKeys:) helper to encapsulate the pruning behavior.
  • Add lifecycle integration tests covering orphan pruning and shared-key retention when removing one of multiple declaring packs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
Tests/MCSTests/LifecycleIntegrationTests.swift Adds lifecycle tests asserting orphan prompt values are removed on pack deselection and retained when still declared by another pack.
Sources/mcs/Sync/Configurator.swift Invokes pruning after unconfigurePack completes (including the “no artifact record” path) and computes surviving declared prompt keys.
Sources/mcs/Core/ProjectState.swift Introduces pruneResolvedValues(keepingKeys:) to drop resolved values not in a provided key set.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Sources/mcs/Sync/Configurator.swift Outdated
- Skip pruning entirely when any configured pack is unresolvable from the registry, matching ResourceRefCounter's conservative fallback.
- Cover the fail-safe with a lifecycle test that drives unconfigurePack with a narrowed registry.
- Drop incidental WHAT comments in the new tests.
@bguidolim bguidolim enabled auto-merge (squash) April 24, 2026 21:30
@bguidolim bguidolim merged commit 7f0c45a into main Apr 24, 2026
4 checks passed
@bguidolim bguidolim deleted the bruno/340-prune-orphan-prompt-values branch April 24, 2026 21:32
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.

Prune orphan prior prompt values on pack removal

2 participants