{
  "schema": "lattice.agents/governance-identity-propagation/v1",
  "headers": [
    {
      "id": "active-tenant",
      "name": "lattice-active-tenant",
      "value": "tenant id",
      "request_context_key": "ol.atid",
      "source": "src/lattice/LatticeActiveTenantAssertion.cs"
    },
    {
      "id": "authorization",
      "name": "authorization",
      "value": "credential, optionally prefixed by the CredentialScheme (default Bearer)",
      "request_context_key": "ol.cred",
      "source": "src/lattice.api.auth.grpc/LatticeAuthApiGrpcOptions.cs#LatticeAuthApiGrpcOptions.CredentialScheme"
    }
  ],
  "request_context_keys": [
    {
      "id": "active-tenant",
      "constant": "LatticeEventConstants.ActiveTenantRequestContextKey",
      "value": "ol.atid",
      "carrier": "TenantId",
      "source": "src/lattice/BPlusTree/LatticeEventConstants.cs"
    },
    {
      "id": "credential",
      "constant": "LatticeEventConstants.CredentialRequestContextKey",
      "value": "ol.cred",
      "carrier": "LatticeCredential",
      "source": "src/lattice/BPlusTree/LatticeEventConstants.cs"
    }
  ],
  "flows": [
    {
      "id": "grpc-apps-active-tenant",
      "entry": "LatticeAppsGrpcService.StampActiveTenant",
      "steps": [
        "Read the configured gRPC metadata active-tenant header.",
        "LatticeActiveTenantAssertion validates syntax and stamps LatticeActiveTenantContext for the facade call.",
        "The apps control facade resolves the active tenant through ITenantContextResolver before it authorizes AppInstall or reads app metadata."
      ],
      "sources": [
        "src/lattice.api.apps.grpc/LatticeAppsGrpcService.cs",
        "src/lattice.api.apps.grpc/LatticeAppsApiGrpcOptions.cs",
        "src/lattice.api.apps/LatticeAppsControl.cs"
      ]
    },
    {
      "id": "grpc-apps-credential",
      "entry": "HeaderLatticeAppsApiCredentialBridge.Resolve",
      "steps": [
        "Read the configured gRPC metadata credential header.",
        "Strip the configured scheme prefix when present.",
        "Stamp LatticeCredentialContext for the app-control facade call.",
        "The apps control facade resolves the caller subject through membership and authorizes AppInstall through the shared access gate."
      ],
      "sources": [
        "src/lattice.api.apps.grpc/HeaderLatticeAppsApiCredentialBridge.cs",
        "src/lattice.api.apps.grpc/LatticeAppsGrpcService.cs",
        "src/lattice.api.apps/LatticeAppsControl.cs"
      ]
    },
    {
      "id": "grpc-auth-credential",
      "entry": "HeaderLatticeAuthApiCredentialBridge.Resolve",
      "steps": [
        "Read the configured gRPC metadata credential header.",
        "Strip the configured scheme prefix when present.",
        "Stamp LatticeCredentialContext for the facade call.",
        "ILatticeMembershipContext resolves the current subject from LatticeCredentialContext."
      ],
      "sources": [
        "src/lattice.api.auth.grpc/HeaderLatticeAuthApiCredentialBridge.cs",
        "src/lattice.api.auth.grpc/LatticeAuthApiGrpcService.cs",
        "src/lattice/ILatticeMembershipContext.cs",
        "src/lattice.membership/MembershipContext.cs"
      ]
    },
    {
      "id": "grpc-tenantadmin-active-tenant",
      "entry": "LatticeTenantAdminGrpcService.StampActiveTenant",
      "steps": [
        "Read the configured gRPC metadata active-tenant header.",
        "LatticeActiveTenantAssertion validates syntax and stamps LatticeActiveTenantContext.",
        "The tenant context resolver validates the asserted tenant against membership before it scopes a tree name."
      ],
      "sources": [
        "src/lattice.api.tenantadmin.grpc/LatticeTenantAdminGrpcService.cs",
        "src/lattice/LatticeActiveTenantAssertion.cs",
        "src/lattice.tenancy/TenantContextResolver.cs"
      ]
    },
    {
      "id": "grpc-tenantadmin-credential",
      "entry": "HeaderLatticeTenantAdminApiCredentialBridge.Resolve",
      "steps": [
        "Read the configured gRPC metadata credential header.",
        "Strip the configured scheme prefix when present.",
        "Stamp LatticeCredentialContext for the facade call.",
        "Tenant facades authorize through ILatticeAccessGate and optional ILatticeMembershipContext."
      ],
      "sources": [
        "src/lattice.api.tenantadmin.grpc/HeaderLatticeTenantAdminApiCredentialBridge.cs",
        "src/lattice.api.tenantadmin.grpc/LatticeTenantAdminGrpcService.cs",
        "src/lattice.api.tenantadmin/LatticeApiTenantAdminServiceCollectionExtensions.cs"
      ]
    },
    {
      "id": "in-process",
      "entry": "LatticeCredentialContext.With and LatticeActiveTenantContext.With",
      "steps": [
        "Caller opens an ambient credential and optional active-tenant scope.",
        "RequestContext carries ol.cred and ol.atid on outgoing grain calls.",
        "The membership context resolves a subject.",
        "The tenant context resolver validates tenant assertions."
      ],
      "sources": [
        "src/lattice/LatticeCredentialContext.cs",
        "src/lattice/LatticeActiveTenantContext.cs",
        "src/lattice.membership/MembershipContext.cs",
        "src/lattice.tenancy/TenantContextResolver.cs"
      ]
    },
    {
      "id": "mcp-active-tenant",
      "entry": "McpToolActiveTenantScope.Stamp",
      "steps": [
        "Resolve HttpContext from the tool invocation service provider.",
        "The MCP active-tenant bridge reads the configured active-tenant header.",
        "Stamp LatticeActiveTenantContext for the tool invocation.",
        "Remote heads re-emit the ambient tenant as outbound gRPC metadata according to MCP options."
      ],
      "sources": [
        "src/lattice.api.mcp/Discovery/McpToolActiveTenantScope.cs",
        "src/lattice.api.mcp/Security/HttpContextLatticeApiMcpActiveTenantBridge.cs",
        "src/lattice.api.mcp/LatticeApiMcpOptions.cs"
      ]
    },
    {
      "id": "mcp-app-tools",
      "entry": "ILatticeApiMcpAppToolSource.GetPermittedToolsAsync and CredentialStampingTool.InvokeAsync",
      "steps": [
        "MCP session discovery passes the resolved caller credential and HttpContext to registered app tool sources.",
        "The app tool source stamps LatticeCredentialContext and the asserted active tenant while it resolves tenant, subject, enabled apps, and role grants.",
        "The session configurator wraps permitted app tools in the per-invocation wrapper so invocation stamps the caller credential and active tenant again.",
        "The namespaced app tool re-checks the current app role grant before invoking the app implementation."
      ],
      "sources": [
        "src/lattice.api.mcp/Discovery/ILatticeApiMcpAppToolSource.cs",
        "src/lattice.api.mcp/Discovery/LatticeApiMcpSessionConfigurator.cs",
        "src/lattice.api.mcp/Discovery/CredentialStampingTool.cs",
        "src/lattice.api.mcp.apps/AppMcpToolSource.cs",
        "src/lattice.api.mcp.apps/AppMcpNamespacedTool.cs"
      ]
    },
    {
      "id": "mcp-credential",
      "entry": "McpToolCredentialScope.Stamp",
      "steps": [
        "Resolve HttpContext from the tool invocation service provider.",
        "The MCP credential bridge requires an authenticated ASP.NET Core principal.",
        "Read the configured credential header or use the principal id as the token for authenticated non-bearer sessions.",
        "Stamp LatticeCredentialContext for the tool invocation."
      ],
      "sources": [
        "src/lattice.api.mcp/Discovery/McpToolCredentialScope.cs",
        "src/lattice.api.mcp/Security/HttpContextLatticeApiMcpCredentialBridge.cs"
      ]
    }
  ],
  "fail_closed": [
    {
      "id": "apps-grpc-blank-credential",
      "rule": "Missing, empty, or bare-scheme app gRPC credential headers stamp no credential; the facade AppInstall gate then resolves the caller through membership and denies when authority is required.",
      "sources": [
        "src/lattice.api.apps.grpc/HeaderLatticeAppsApiCredentialBridge.cs",
        "src/lattice.api.apps/LatticeAppsControl.cs"
      ]
    },
    {
      "id": "apps-grpc-invalid-active-tenant",
      "rule": "An invalid or unauthorized active-tenant assertion on the apps gRPC surface fails before app registry, source, consent, or activation metadata is read.",
      "sources": [
        "src/lattice.api.apps.grpc/LatticeAppsGrpcService.cs",
        "src/lattice.api.apps/LatticeAppsControl.cs"
      ]
    },
    {
      "id": "blank-credential",
      "rule": "Missing, empty, or bare-scheme credential headers resolve to anonymous or null and downstream gates deny when authority is required.",
      "sources": [
        "src/lattice.api.auth.grpc/HeaderLatticeAuthApiCredentialBridge.cs",
        "src/lattice.api.tenantadmin.grpc/HeaderLatticeTenantAdminApiCredentialBridge.cs"
      ]
    },
    {
      "id": "invalid-active-tenant",
      "rule": "Missing, blank, or syntactically invalid active-tenant headers stamp no active tenant; unauthorized assertions validate to the uninitialized tenant and fail closed at composition or gate seams.",
      "sources": [
        "src/lattice/LatticeActiveTenantAssertion.cs",
        "src/lattice.tenancy/TenantContextResolver.cs"
      ]
    },
    {
      "id": "mcp-app-tool-lost-grant",
      "rule": "An app tool grant is checked again at invocation against the current registry and access gate; disabling the app or revoking the compiled grant causes the tool call to fail even if it was listed earlier in the session.",
      "sources": [
        "src/lattice.api.mcp.apps/AppMcpNamespacedTool.cs",
        "src/lattice.api.mcp.apps/AppMcpToolSource.cs"
      ]
    },
    {
      "id": "mcp-region-catalog-tenant-assertion",
      "rule": "The MCP region catalog re-resolves an asserted active tenant through ITenantContextResolver and honours it only on an exact match; a refused or unvalidatable assertion yields the current region alone with no tenantScope annotation.",
      "sources": [
        "src/lattice.api.mcp/Remote/LatticeApiMcpRegionCatalog.cs#LatticeApiMcpRegionCatalog.ResolveTenantScopeAsync"
      ]
    }
  ]
}
