Skip to content

fix(approvals): replace the opposite rule when one is set - #2149

Merged
elie222 merged 3 commits into
elie222:mainfrom
tc3oliver:fix/approval-rule-single-effect
Oct 25, 2026
Merged

elie222 merged 3 commits into
elie222:mainfrom
tc3oliver:fix/approval-rule-single-effect

Conversation

@tc3oliver

@tc3oliver tc3oliver commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Why

With a require_approval rule on a tool, every call shows a card offering "Always allow this tool". Tapping it saved an always_allow rule next to the existing one. Two rules on the same tool resolve to ask, so the card came back on every later call, and the rule list showed both effects for one tool.

What changed

A tool, site, connector or category now has one rule effect per user and space. Setting one effect, from the card's "Always allow" button or from approvalRules.set, deletes the opposite rule in the same transaction, through one shared helper. The delete ignores case, as rule matching does (compared literally, so _ in a tool name is not a wildcard), and an advisory lock on the match keeps two opposite saves at once from both landing. No migration: existing pairs are fixed the next time either rule is set.

How tested

A new journey test against Postgres sets require_approval (in mixed case), answers a card with "Always", checks that the next call runs without a card and that the list holds only always_allow, then sets require_approval again and checks the list holds only that. A second saves opposite rules on several matches at once and checks each keeps one, and a third checks that replacing tool_a leaves a rule on toolXa alone. Each fails without the change. The answer unit test now checks the delete. Lint and typecheck pass; the unit suite passes except the backup script tests, which fail the same way on main on macOS.

@vercel

vercel Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
rakazo-www Skipped Skipped Oct 25, 2026 1:25pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; all previous findings are addressed and no new actionable issues remain.

Findings

  1. P1 Other tool preferences disappear ▶

Summary

Setting an approval rule now replaces the opposite effect through one shared helper.

  • Saving an approval rule replaces its opposite for that match.

All three previous findings are addressed. No new actionable issues were found.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["approvalRules.set"] --> C["saveApprovalRule inside transaction"]
  B["Always answer"] --> C
  C --> D["Lock user, space, kind, and lowercased value"]
  D --> E["Read opposite-effect rules"]
  E --> F["Compare lowercased values literally"]
  F --> G["Delete matching IDs"]
  G --> H["Save requested rule and commit"]
Loading

Reviews (3) · Last reviewed commit: "fix(approvals): compare rule values lite..." · Reviewed by Greptile

Comment thread apps/api/src/router.ts Resolved
Comment thread packages/db/src/events.ts Resolved
Comment thread packages/db/src/approval-rules.ts Resolved
@elie222
elie222 merged commit 3ba1878 into elie222:main Oct 25, 2026
28 checks passed
@tc3oliver
tc3oliver deleted the fix/approval-rule-single-effect branch November 13, 2026 05:07

This branch was previously deployed

1 inactive deployment
Preview — 63a0e207 Deployed Oct 25, 2026 by vercel[bot]
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.

2 participants