Skip to content

Reduce Resource base class coupling to config and global context #425

@jessica-claude

Description

@jessica-claude

Summary

The Resource base class hardcodes access to Hassette config for cache setup and shutdown timeouts, and the global singleton in context.py enables implicit coupling bypass.

Findings

From the comprehensive codebase audit:

  • MEDIUM: Resource.cache property directly accesses self.hassette.config.data_dir and default_cache_size (resources/base.py:164-173). Every Resource carries this dependency whether it uses caching or not.
  • MEDIUM: Resource.cleanup() accesses self.hassette.config.resource_shutdown_timeout_seconds (resources/base.py:328).
  • MEDIUM: Global ContextVar singleton in context.py makes the Hassette instance available globally, enabling any code to bypass the explicit dependency graph.

Acceptance Criteria

  • Cache setup moved to an opt-in mixin (only caching-aware resources carry the dependency)
  • Shutdown timeout uses a default with optional override, not direct config access
  • context.get_hassette() call sites audited and limited to framework plumbing
  • Existing tests pass

Audit Reports

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:corePart of the core Hassette framework, not necessarily user-facingenhancementNew feature or requestsize:smallQuick win, < 1 hour

    Projects

    Status

    Refinement

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions