  In this paper we prove formal glueing along an arbitrary closed substack $Z$
of an arbitrary Artin stack $X$ (locally of finite type over a field $k$), for
the stacks of (almost) perfect complexes , and of $G$-bundles on $X$ (for $G$ a
smooth affine algebraic $k$-group scheme). By iterating this result, we get a
decomposition of these stacks along an arbitrary nonlinear flag of closed
substacks in $X$. By taking points over the base field, we deduce from this
both a formal glueing, and a flag-related decomposition formula for the
corresponding symmetric monoidal derived $\infty$-categories of (almost)
perfect modules. When $X$ is a quasi-compact and quasi-separated scheme, we
also prove a localization theorem for almost perfect complexes on $X$, which
parallels Thomason's localization results for perfect complexes. This is one of
the main ingredients we need to provide a global characterization of the
category of almost perfect complexes on the punctured formal neighbourhood. We
then extend all of the previous results - i.e. the formal glueing and
flag-decomposition formulas - to the case when $X$ is a derived Artin stack
(locally almost of finite type over a field $k$), for the derived versions of
the stacks of (almost) perfect modules, and of $G$-bundles on $X$. We close the
paper by highlighting some expected progress in the subject matter of this
paper, related to a Geometric Langlands program for higher dimensional
varieties. In an Appendix (for $X$ a variety), we give a precise comparison
between our formal glueing results and the rigid-analytic approach of
Ben-Bassat and Temkin.
