A module-level variable mutated from anywhere — the agent reading any single call site cannot bound its impact without paying completeness-check cost across every consumer. The agent reasoning about any read must hold the full mutation timeline in working context window; missing a writer ships an edit that depends on a state assumption the codebase doesn't guarantee.
All reads and writes go through a named function the agent can grep for, find every consumer of, and reason about as a closed surface. The single audit surface bounds the per-edit reasoning step count; the agent verifies state transitions against the wrapper's contract rather than reconstructing them from scattered call sites.
Smellier version
let currentUser = null;// ...some files later...currentUser = newUser;
Fresher version
function setCurrentUser(user) {currentUser = validate(user);}function getCurrentUser() {return currentUser;}
Behavior depends on hidden write-order between callers the agent discovers one at a time; tracing any bug requires reconstructing a global mutation timeline — high verification-surface cost. The agent generates an edit consistent with the order it discovered and ships it; runtime hits a different order and produces a behavior the agent never reasoned about.
Wrapping the global doesn't eliminate the shared-state dependency — every reader still depends on the same value, and the agent still has to model the timeline to reason about reads. The wrapper bounds the visible write surface but not the underlying state; the agent's cache-staleness cost stays the same when the global drifts between sessions.
A single named function becomes the audit point; the agent attaches logging, validation, or cache logic in one place instead of chasing every consumer. The agent's per-edit search surface contracts to the wrapper and its callers; retrieval cost on any reasoning about the global drops to the single call to the wrapper.
Wrapping globals without narrowing access creates a false safety signal — the wrapper appears to guarantee something it doesn't, and silent leaks become harder to diagnose. The agent reads the wrapper's signature and reasons as if the contract holds; verification-surface cost stays as broad as before, and the agent's downstream edits inherit the violation.