vk-org-resolution

vk-org-resolution is a cursor rule for Cursor from AlphaBitCore/nexus-gateway. It costs 0 tokens per session (740 once invoked), scanned A, original, Apache-2.0.

A coding rule for finding the organization linked to a virtual API key when the key can belong to either an application or a person.

In plain words
What is it for?
Apply it when changing SQL that reads virtual keys or organization-related data, using both Project and NexusUser paths and combining their results with COALESCE.
Why use it?
It prevents personal keys from returning no organization because the code only follows the application link.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/alphabitcore/nexus-gateway/vk-org-resolution
Clone the repo
git clone --depth 1 https://github.com/AlphaBitCore/nexus-gateway

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for vk-org-resolution

README.md
[![agentmods](https://agentmods.dev/badge/rules/alphabitcore/nexus-gateway/vk-org-resolution.svg)](https://agentmods.dev/rules/alphabitcore/nexus-gateway/vk-org-resolution)
Your own site
<a href="https://agentmods.dev/rules/alphabitcore/nexus-gateway/vk-org-resolution"><img src="https://agentmods.dev/badge/rules/alphabitcore/nexus-gateway/vk-org-resolution.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 740 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00740
Opus 5 $0.00000 $0.00370
Sonnet 5 $0.00000 $0.00148
Haiku 4.5 $0.00000 $0.00074

Measured 5d ago against content hash 603238aff624, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

vk-org-resolution scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/vk-org-resolution.mdc · 63 lines

How it starts

The opening of the file, as written. The whole thing — 63 lines — stays where its author put it; the contents beside it link to each section on GitHub.

VK org resolution — two join chains (binding)

packages/ai-gateway/internal/platform/store/virtualkey.go:vkSelectSQL resolves VirtualKey → Organization through TWO independent chains:

VK type Chain
application VirtualKey.projectIdProjectOrganization
personal VirtualKey.ownerIdNexusUserOrganization

The SQL JOINs both and COALESCEs the application chain first.

Required SQL pattern

LEFT JOIN "Project"      p     ON vk."projectId" = p.id
LEFT JOIN "Organization" org   ON p."organizationId" = org.id
LEFT JOIN "NexusUser"    u     ON vk."ownerId" = u.id
LEFT JOIN "Organization" u_org ON u."organizationId" = u_org.id

COALESCE(p."organizationId", u."organizationId") AS organization_id
COALESCE(org.name,           u_org.name)         AS organization_name
COALESCE(org.timezone,       u_org.timezone)     AS organization_timezone

When to apply

Touching any of:

  • vkSelectSQL itself (or any sibling SELECT that joins through Project/Org/NexusUser)
  • A new column on traffic_event that depends on the VK's parent (timezone, billing account, primary AccountManager, parent org id)
  • A new VK type beyond application / personal
  • The audit pipeline's identity JSONB stamping

Why this matters

Latent bugs in the personal-VK code path hide indefinitely when traffic is dominated by application VKs — a missing join surfaces only on the first personal-VK request. Touching personal-VK-adjacent code without testing both VK types = silent NULL columns in prod. Memory anchor: [[feedback_vk_org_dual_join_chain]].

Forbidden

  • "Simplifying" the SQL by dropping the second LEFT JOIN or the COALESCE. The two Organization joins via different aliases (org, u_org) are load-bearing.
  • Adding a Go-side fallback in caller code (e.g. "if meta.OrganizationID == "" then look up meta.OwnerID and read nexus_user.organizationId"). The fallback belongs in SQL — caller code reads the resolved value, not raw chains.
  • Adding a new VK-derived column without verifying it has both chains' coverage.

Read the full file on GitHub · 63 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 63 lines · 0 tokens per session scan A 603238aff624

Subscribe to this mod's changes

vk-org-resolution is a cursor rule published in the GitHub repository AlphaBitCore/nexus-gateway (23 stars, last pushed 3d ago), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 740 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.