Skip to content

API Reference parrot.handlers.crew._tenancy

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.handlers.crew._tenancy

View source

Session-derived tenant resolver for the crew handler surface (FEAT-446).

Interim, PRIVATE helper (hence the leading underscore in the module name): tenant identity for the crew handlers (handler.py, execution_handler.py, execution_history_handler.py) must come from the authenticated session, never from request body or query string (spec Goals G2/G3). S1 (FEAT-442 program, resolved question U1) will supersede this helper with the core TenantContext + a per-route decorator; nothing outside handlers/crew/ should import from this module.

Attribute logger

Function resolve_session_tenant

Resolve the caller's tenant from their authenticated session.

When no tenant can be resolved: PARROT_SAAS_MODE=true raises web.HTTPForbidden; with the flag off, returns "global" for legacy single-tenant compatibility.

declared — a tenant value the caller found in the request body or query string — is NEVER used as the source of truth. If provided and it differs from the resolved tenant, this raises web.HTTPBadRequest (FEAT-421 assert_body_tenant_matches semantics). This function does not itself read the request body; callers extract declared and pass it in.

resolve_session_tenant(request: web.Request, *, declared: str | None = None) -> str

Parameter Type Default Description
request web.Request The incoming aiohttp request with a Guardian-populated session (or one resolvable via navigator_session.get_session).
declared str | None None A tenant value the caller found in the request body or query string, for the compatibility check only. None skips the check.

Returns: str — The resolved tenant slug (or "global" in legacy mode when unresolvable).

Raises:

  • web.HTTPForbidden — No tenant could be resolved and PARROT_SAAS_MODE is true.
  • web.HTTPBadRequest — declared is not None and differs from the resolved tenant.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally