Avoid Global Mutable State
BOUNDARY-AVOID-GLOBAL-MUTABLE-STATE
Summary
Keep shared process state behind explicit owners, handles, synchronization, and reset policy. This preserves test isolation and lifecycle reasoning while still allowing deliberate globals such as caches or registries when their contract is visible.
Rule
Avoid global mutable state.
Why
Global mutable state hides ownership, ordering, reset, and concurrency requirements. In Rust apps it can make tests order-dependent, make alternate runtimes hard to inject, and make agents miss that changing one path affects unrelated callers.
Helps
- Improves test isolation, explicit lifecycle management, and reasoning about shared state.
Limits
Caches, registries, metrics handles, and process-level coordination can be global when owner, reset policy, synchronization, and caller contract are explicit.
Agent Instruction
Avoid global mutable state because it hides ownership, ordering, reset, and concurrency
requirements.Mechanisms
Supported by dependency injection, owned handles, OnceLock with explicit policy, test reset hooks,
narrow visibility, and concurrency tests.