Skip to content

symfonic.devtools.archgate.processglobals

processglobals

Forbidden process globals.

LAY-ADR SS4: a compiled plan is frozen and per-run state lives in kernel run state โ€” "never in process-global config (forbidden pattern)". The detectable form of that pattern is a global statement: module-level state rebound at runtime, shared by every tenant, every invocation, and every test in the process.

Module-level constants are not the target โ€” a frozen table read by many callers is the opposite of hidden state. What this rule looks for is the rebinding.

check_forbidden_globals

check_forbidden_globals(facts: dict[str, ModuleFacts], sanctioned: tuple[str, ...]) -> list[Violation]

One violation per module that rebinds module state from a function.

Source code in src/symfonic/devtools/archgate/processglobals.py
def check_forbidden_globals(
    facts: dict[str, ModuleFacts], sanctioned: tuple[str, ...]
) -> list[Violation]:
    """One violation per module that rebinds module state from a function."""
    violations: list[Violation] = []
    for name in sorted(facts):
        bindings = facts[name].global_bindings
        if not bindings or owns(sanctioned, name):
            continue
        rebound = ", ".join(
            f"{binding.name} in {binding.function}() line {binding.lineno}"
            for binding in bindings
        )
        violations.append(
            Violation(
                rule="forbidden-global",
                message=(
                    f"{name} rebinds process-global state: {rebound}. "
                    "Per-run state belongs in kernel run state, not a module global "
                    "(LAY-ADR SS4); register an exception if the latch is genuinely "
                    "process-wide."
                ),
                modules=(name,),
            )
        )
    return violations