fix(team): authorise a tools edit after the existence check, not before - #764
The change looks sound. The PR reorders a conditional admin check from before th
The change looks sound. The PR reorders a conditional admin check from before the write lock to after the existence (409/404) checks, so that a per-field admin-only route gives a consistent answer about whether an agent exists regardless of which body fields are sent. The authorization check still runs before any mutation: require_admin at the relocated site precedes the field-parsing and write path, so a non-admin sending tools is still refused before the record changes. The moved check now occurs inside the write lock, so a refused tools edit briefly holds that lock where it previously did not; that is a contention nuance, not a security hole, and the lock is released on failure. The existence information exposed by ordering the 404 before the 403 is already available to any signed-in member via the open GET route, so the reordering does not widen disclosure. The added test is driven as a member (the only actor for whom the two orderings differ) and asserts both paths agree on 404, which is the correct defense. Code retrieval was unavailable (model: openrouter embeddings returned 404 Not Found: {"error":{"message":"No allowed providers are available for the selected model. Providers serving openai/text-embedding-3-small: openai, azure, but your account's allowed-providers setting permits only: deepinfra, streamlake, digitalocean. To change your allowed providers, visit: https://openrouter.ai/settings/privacy","code":404,"metadata":{"available_providers":["openai","azure"],"requested_prov), so this review saw the diff alone.
No findings.