feature_toggles

Per-channel feature toggles stored in Redis.

Allows authorised users to disable the NCM neurotransmitter subsystem (cadence post-processing + NCM tools like inject_ncm) or the RAG subsystem on a per-channel basis via !emotions on/off and !rag on/off.

Full NCM disable (inhale, exhale, Golden Goddess reflex, emotion tools, cadence) is controlled by:

  • ncm_fully_disabled_channels (platform:channel_id strings, default includes Aesir-Hall), and/or

  • Redis key stargazer:toggle:ncm:{channel_key} (same pattern as other toggles; set via SET / DEL or a future admin command).

NOTE: !emotions off does NOT affect the Sigma Limbic Recursion Core. The limbic inhale (context injection) and exhale (emotional feedback loop) always run. Star always knows her emotions. The toggle only disables the surface layer: cadence text degradation and tool access to NCM. Use the ncm toggle or config list when the entire NCM stack must be off.

Redis key scheme

stargazer:toggle:{feature}:{channel_key}

where feature is "emotions", "rag", or "ncm" and channel_key is "{platform}:{channel_id}".

For Discord, discord and discord-self share the same numeric channel ID; is_disabled_resolving_discord_aliases() and is_ncm_fully_disabled() treat toggles under either prefix as equivalent.

feature_toggles.discord_family_channel_key_variants(channel_key)[source]

Return unique platform:channel_id strings to check for Discord aliases.

The bot adapter uses discord and the selfbot uses discord-self for the same numeric channel ID. Toggles may be set under either prefix; callers should treat them as equivalent.

Return type:

tuple[str, ...]

Parameters:

channel_key (str)

feature_toggles.strip_ncm_surface_layer_from_context(ctx)[source]

Delete the NCM surface-layer keys from a prompt context dict in place.

Implements the !emotions off degradation: it pops each of the NCM_SURFACE_LAYER_KEYS (cadence directive/instruction/refinement profile and the limbic/cascade cue blobs) out of ctx so the rendered prompt loses cadence text and limbic surface cues while the underlying limbic respiration keeps running. Mutates ctx directly and returns nothing; only keys that are present are removed.

Called when limbic injection has been merged but the channel has emotions disabled: by prompt_context.py (PromptContextBuilder) on the per-turn injection dict, by message_processor/channel_heartbeat.py on the heartbeat room context, and by tests/test_feature_toggles.py.

Parameters:

ctx (dict[str, Any]) – The prompt context dictionary to strip in place.

Return type:

None

Returns:

None.

async feature_toggles.is_disabled(redis, feature, channel_key, guild_id=None)[source]

Return True if feature is disabled for the exact channel_key.

For default-off features the logic is reversed: disabled when no key exists, enabled only when the key is explicitly created.

Parameters:
  • redis (Redis) – Async Redis client.

  • feature (str) – Feature name.

  • channel_key (str) – "{platform}:{channel_id}".

  • guild_id (str | None) – Optional guild ID for guild-scoped default lookups.

Return type:

bool

async feature_toggles.is_disabled_resolving_discord_aliases(redis, feature, channel_key, guild_id=None)[source]

Check is_disabled() across all Discord-alias variants.

Parameters:
  • redis (Redis) – Async Redis client.

  • feature (str) – Feature name.

  • channel_key (str) – "{platform}:{channel_id}".

  • guild_id (str | None) – Optional guild ID for guild-scoped default lookups.

Return type:

bool

async feature_toggles.set_disabled(redis, feature, channel_key, disabled, guild_id=None)[source]

Persist the on/off state of feature for channel_key in Redis.

Parameters:
  • redis (Redis) – Async Redis client.

  • feature (str) – Feature name.

  • channel_key (str) – "{platform}:{channel_id}".

  • disabled (bool) – True to disable, False to enable.

  • guild_id (str | None) – Optional guild ID for guild-scoped default lookups.

Return type:

None

feature_toggles.is_absolute_bypass(config, user_id=None, channel_key=None)[source]

Return True if a user or channel is on a config-level absolute override list.

The global escape hatch that forces NCM/limbic/egregore subsystems on (bypassing any per-channel disable) for explicitly allow-listed users or channels. It reads overall_user_id_absolute_override_list and overall_channel_id_absolute_override_list off config via getattr (so a missing attribute degrades to empty). A user_id matches by string equality against the user list; a channel_key matches either by Discord-alias-expanded key (via discord_family_channel_key_variants()) or by comparing the numeric suffix after the first : against each list entry’s suffix, so a bare numeric id, a discord: key, and a discord-self: key all resolve alike. Pure config inspection with no I/O.

Called widely as a precedence gate before applying per-channel toggles: by is_ncm_fully_disabled() here, and across prompt_context.py, flash_dyadic_mirror.py, ego_ablation.py, lore_amplifier.py, entrainment_loopfield.py, and several message_processor modules (generate_and_send.py, proactive_gates.py, context_injections.py), plus the override test suites.

Parameters:
  • config (Any | None) – A Config-like object exposing the absolute override lists, or None (in which case this returns False).

  • user_id (str | int | None) – Optional user id to test against the user override list; stringified before comparison.

  • channel_key (str | None) – Optional "{platform}:{channel_id}" (or bare id) to test against the channel override list, alias- and suffix-aware.

Returns:

True if the user or channel is absolutely overridden, else False.

Return type:

bool

async feature_toggles.is_limbic_respiration_disabled(redis, channel_key, cfg, user_id=None)[source]

True when NCM limbic respiration (inhale/exhale) is disabled for this channel.

NOTE: Channel ‘1424991476668170351’ is explicitly allowed (returns False) and bypasses the disabling effects of overall absolute overrides.

Return type:

bool

Parameters:
  • redis (Redis | None)

  • channel_key (str)

  • cfg (Any | None)

  • user_id (str | int | None)

async feature_toggles.is_ncm_fully_disabled(redis, channel_key, cfg, user_id=None)[source]

Return True when the entire NCM stack must be off for this channel.

The authoritative “is NCM fully disabled” decision, combining static config and live Redis state. It returns True if cfg sets ncm_global_disabled, OR if is_absolute_bypass() flags this user/channel (absolute overrides force the disabled-style respiration path), OR if the channel is listed in ncm_fully_disabled_channels per _ncm_config_matches_channel(). Failing those, when redis is provided it consults the per-channel "ncm" toggle via is_disabled_resolving_discord_aliases(), swallowing and debug-logging any Redis error so a backend hiccup never spuriously disables NCM. The only I/O is that optional Redis read; config checks are in-memory.

Called by is_limbic_respiration_disabled() (after its single-channel allow-list carve-out), and directly by the inference/heartbeat paths in message_processor/generate_and_send.py and message_processor/channel_heartbeat.py, plus the toggle/override test suites.

Parameters:
  • redis (Redis | None) – Optional async Redis client for the per-channel toggle check; when None only config is consulted.

  • channel_key (str) – The "{platform}:{channel_id}" key under evaluation.

  • cfg (Any | None) – Optional Config-like object supplying the global flag, override lists, and disabled-channel set.

  • user_id (str | int | None) – Optional user id forwarded to is_absolute_bypass().

Returns:

True if NCM is fully disabled for this channel, else False.

Return type:

bool

async feature_toggles.check_toggle_permission(msg, config, redis=None)[source]

Return True if the user is allowed to toggle features.

Allowed when any of the following are true:

  1. The user is a bot admin (config.admin_user_ids).

  2. The user has the CTX_MANAGE or GUILD_ADMIN privilege bit.

  3. The channel is a DM.

Return type:

bool

Parameters: