Skip to content

fix: cache_enabled never reaches the launcher Migrator gate#3

Merged
aradng merged 1 commit into
mainfrom
fix/cache-enabled-singleton-gate
Jun 7, 2026
Merged

fix: cache_enabled never reaches the launcher Migrator gate#3
aradng merged 1 commit into
mainfrom
fix/cache-enabled-singleton-gate

Conversation

@aradng

@aradng aradng commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Bug

Migrator().run() in the launcher lifespan is gated on Configs.cache_enabled (launcher/main.py:40) — and that gate has been permanently False on every service, so redis-om RediSearch indexes are never created at boot. Symptom downstream: redis.exceptions.ResponseError: No such index cache:... on any BaseCache.find().

Two stacked causes:

  1. SelfSustainingMeta.__getattr__ only fires on attribute miss. A class-body default like cache_enabled: bool = False lives in Configs.__dict__, so class access (Configs.cache_enabled) resolves to the stale default and never delegates to the singleton instance.
  2. _setup_redis read RedisHandler.enabled (class access) — the same shadow (enabled: bool = False), and one line before RedisHandler(...) was even constructed — so even the instance-side self.cache_enabled ended up False.

Minimal repro of the metaclass semantics:

class Probe(SelfSustaining):
    flag: bool            # annotation-only
    legacy: bool = False  # class default

    def __init__(self):
        super().__init__()
        self.flag = self.legacy = False

p = Probe(); p.flag = p.legacy = True
Probe.flag    # True  — lookup misses, __getattr__ delegates to singleton
Probe.legacy  # False — class default shadows the instance

Fix (+5/−3, one file)

  • cache_enabled: bool annotation-only, initialised to False in __init__ — class access now delegates through the metaclass.
  • _setup_redis constructs RedisHandler first and reads enabled off the instance.

RedisHandler.enabled's own class default is left untouched: tenant/depends.py:64 reads it at class level on non-redis services where the handler is never constructed, and removing the default would turn that into an AttributeError.

Verification

Dropped the FT indexes in redis, restarted a fastloom service (assistant) with this patch — boot-time Migrator recreated them with no manual intervention:

cache:assistant.schemas.curve_graph.CurveGraphContextCache:index
cache:assistant.schemas.product.ProductCache:index

🤖 Generated with Claude Code

Two stacked issues left `Migrator().run()` permanently skipped on every
service:

1. SelfSustainingMeta.__getattr__ only fires on attribute miss, so a
   class-body default (`cache_enabled: bool = False`) shadows the
   singleton — `Configs.cache_enabled` in the launcher lifespan always
   read the stale class default, never the instance value.
2. `_setup_redis` read `RedisHandler.enabled` (same class-default
   shadow, and one line before RedisHandler was even constructed), so
   the instance value was False as well.

Drop the class default (annotation-only delegates through the
metaclass), initialise it in __init__, and read `enabled` off the
constructed handler instance.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@aradng aradng force-pushed the fix/cache-enabled-singleton-gate branch from 2727d70 to 71476f3 Compare June 7, 2026 00:23
@aradng aradng merged commit 71476f3 into main Jun 7, 2026
1 check passed
aradng added a commit that referenced this pull request Jun 7, 2026
HostTenantMapping defines its own Meta (model_key_prefix override), so it
never chains to BaseCache.Meta.database and its db() resolves to aredis_om's
import-time default (localhost:6379, unauthenticated). On deployments where
redis requires AUTH this crashes the boot-time Migrator with
AuthenticationError as soon as the cache_enabled gate (fixed in #3) lets it
run.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
aradng added a commit that referenced this pull request Jun 7, 2026
HostTenantMapping defines its own Meta (model_key_prefix override), so it
never chains to BaseCache.Meta.database and its db() resolves to aredis_om's
import-time default (localhost:6379, unauthenticated). On deployments where
redis requires AUTH this crashes the boot-time Migrator with
AuthenticationError as soon as the cache_enabled gate (fixed in #3) lets it
run.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant