Skip to content

fix(api): standardize lease/claim scopes to singular#227

Merged
duyet merged 1 commit into
mainfrom
claude/fix-lease-claim-scope-naming
Jun 18, 2026
Merged

fix(api): standardize lease/claim scopes to singular#227
duyet merged 1 commit into
mainfrom
claude/fix-lease-claim-scope-naming

Conversation

@duyet

@duyet duyet commented Jun 18, 2026

Copy link
Copy Markdown
Owner

Bug

The scoped-keys taxonomy introduced plural leases:write / claims:write, but the pre-existing convention uses singular lease:write / claim:write:

  • the v2 lease/claim route guards (scopedAuth({ scope: "lease:write" }) / "claim:write"),
  • the capability-token scopes (CAPABILITY_SCOPES) and already-issued as_cap_ tokens.

So a key granted the plural scope from the dashboard/API was rejected (403) by the actual leases/claims REST routes, and couldn't mint capability tokens for them. A normalization shim had patched only the MCP path, leaving REST broken.

Fix

Standardize on the existing singular form everywhere the plural was introduced (can't change the other way — as_cap_ tokens are already issued with singular scopes): lib/scopes.ts, shared ApiScope, dashboard scope catalog + in-app docs, MCP tools, stdio @agentstate/mcp, docs/*.md, and llms.txt/agents.md/static.ts content. Removed the now-redundant shims (normalizeToApiScopes, capabilityToApiScope). One canonical scope form across keys, capability tokens, routes, and MCP — no mapping.

Verification

  • API: biome + tsc clean, 329 tests pass, plus a new regression test (a lease:write-scoped key can use the leases route).
  • Dashboard build ✅; stdio mcp tsc + 11 tests ✅.

Co-Authored-By: Duyet Le [email protected]
Co-Authored-By: duyetbot [email protected]

…laim:write)

The scoped-keys taxonomy used plural `leases:write` / `claims:write`, but the
pre-existing convention — the v2 lease/claim route guards (scopedAuth), the
capability-token scopes, and already-issued as_cap_ tokens — uses singular
`lease:write` / `claim:write`. The mismatch meant a key granted the plural
scope from the dashboard/API was rejected (403) by the actual leases/claims
routes, and couldn't mint capability tokens for them.

Standardize on the existing singular form everywhere the plural was introduced
(scopes taxonomy, shared ApiScope type, dashboard scope catalog + docs, MCP
tools, stdio MCP, docs, llms.txt/agents.md/openapi content) and remove the now
-unneeded normalization shims (mcp-auth normalizeToApiScopes, tools
capabilityToApiScope). One canonical scope form across keys, capability tokens,
routes, and MCP — no mapping.

Adds a regression test: a key scoped to lease:write can use the leases route.

Co-Authored-By: Duyet Le <[email protected]>
Co-Authored-By: duyetbot <[email protected]>

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @duyet, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request standardizes the authorization scopes for leases and claims from plural (leases:write, claims:write) to singular (lease:write, claim:write) across all documentation, API definitions, dashboard components, and MCP packages. This change unifies the scope format, allowing the removal of legacy normalization helper functions in the API middleware and tools. Feedback suggests updating a test comment in packages/api/test/mcp.test.ts that still incorrectly refers to the lease tool's scope as plural.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.


// The token's singular lease:write must satisfy the lease tool's plural
// leases:write requiredScope, or capability-token delegation is broken.
// lease:write requiredScope, or capability-token delegation is broken.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The comment on line 182 still refers to the lease tool's scope as 'plural', but it has been standardized to the singular lease:write on line 183. Please update the comment on line 182 to say 'singular' (or remove 'plural') to avoid contradiction and confusion.

@duyet duyet merged commit 1dc75aa into main Jun 18, 2026
5 checks passed
@duyet duyet deleted the claude/fix-lease-claim-scope-naming branch June 18, 2026 12:24
@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@duyet, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 44 minutes and 54 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d39811f1-6313-4204-9b68-1ede8be983e7

📥 Commits

Reviewing files that changed from the base of the PR and between a12fe9e and 9931ffd.

📒 Files selected for processing (17)
  • docs/api-reference.md
  • docs/mcp.md
  • docs/oauth.md
  • docs/permissions.md
  • packages/api/src/content/agents.md
  • packages/api/src/content/llms.txt
  • packages/api/src/content/static.ts
  • packages/api/src/lib/scopes.ts
  • packages/api/src/middleware/mcp-auth.ts
  • packages/api/src/routes/mcp/tools.ts
  • packages/api/test/mcp.test.ts
  • packages/api/test/scopes.test.ts
  • packages/dashboard/src/components/docs/docs-data.ts
  • packages/dashboard/src/lib/scopes.ts
  • packages/dashboard/src/pages/docs.astro
  • packages/mcp/src/index.ts
  • packages/shared/src/index.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/fix-lease-claim-scope-naming

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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