ego_ablation
Per-channel ego-ablation (non-dual pronoun) mode backed by Redis.
Stores a single per-channel toggle in Redis under star:ablate_ego: keys
that, when active, makes the bot suppress singular first-person pronouns in its
output. The module exposes the key builders (redis_key(),
redis_key_for_channel_key()), the read/write pair (is_active(),
set_active()), and merge_into_room_context_if_missing(), which
backfills the active flag and the EGO_ABLATION_DIRECTIVE text into a
prompt room-context dict. Reads merge across Discord family channel-key aliases
and honour a module killswitch, a config-level global disable, and per-user
absolute bypasses (via feature_toggles); the directive itself is injected
into the SpiritGraph and subagent system prompts elsewhere in the codebase.
- ego_ablation.redis_key(platform, channel_id)[source]
Build the Redis flag key for a single
platform:channel_idpair.Returns the canonical
star:ablate_ego:{platform}:{channel_id}string key under which the per-channel ego-ablation toggle is stored. This is the exact-prefix key written byset_active(); reads go throughredis_key_for_channel_key()instead so they can also match Discord family aliases. This is a pure string formatter that performs no I/O.Called only by
set_active()in this module.
- ego_ablation.redis_key_for_channel_key(channel_key)[source]
Build the Redis flag key from an already-composed
platform:channel_idkey.Returns
star:ablate_ego:prefixed onto a pre-joinedplatform:channel_idcomposite. This variant exists so the read path inis_active()can build a key for each Discord family alias produced bydiscord_family_channel_key_variants()without re-splitting the composite. This is a pure string formatter that performs no I/O.Called only by
is_active()in this module (once per alias variant).
- async ego_ablation.is_active(redis, platform, channel_id, user_id='', config=None)[source]
Report whether ego-ablation mode is active for a channel right now.
Resolves the effective per-channel toggle, honouring every layer of suppression in order: the module-level
enabledkillswitch, theego_ablation_global_disabledconfig flag, and the per-user/per-channel absolute bypass viafeature_toggles.is_absolute_bypass(). If none of those short-circuit, it reads Redis for each Discord family alias of the channel (viadiscord_family_channel_key_variants()andredis_key_for_channel_key()) and treats any truthy stored value (1/true/yes/on) as active, so a flag set under one Discord channel-key prefix still applies across that channel’s known aliases. Per-key RedisGETfailures are logged at debug level and skipped rather than raising. This is the read counterpart toset_active().Called by
merge_into_room_context_if_missing()in this module and by the prompt-context assembly inprompt_context.py(the ego-ablation branches around lines 2746 and 2834).- Parameters:
redis (
Redis) – Async Redis client used for the per-aliasGETlookups.platform (
str) – The platform prefix for the channel being checked.channel_id (
str) – The channel/room identifier on that platform.user_id (
str) – The sender’s user id, consulted only for the absolute bypass check; empty by default.config (
Config|None) – Optional config providing the global-disable flag and bypass rules; whenNonethose checks are skipped.
- Returns:
Trueif ego ablation should apply to this channel, elseFalse.- Return type:
- async ego_ablation.set_active(redis, platform, channel_id, active)[source]
Persist the ego-ablation toggle for one channel under its exact prefix.
Writes (or clears) the per-channel flag in Redis using the exact
platform:channel_idkey fromredis_key(). When active is true it stores1; when false it deletes the key entirely (absence is read as inactive). Note the asymmetry withis_active(), which on read merges across Discord family aliases — this writer only ever touches the literal platform prefix it was given, so a toggle set on one alias is visible to reads of its siblings but is cleared only on the prefix written here.Called by the message processor’s toggle handler in
message_processor/processor.py(around line 3428).- Parameters:
- Return type:
- async ego_ablation.merge_into_room_context_if_missing(room_context, redis, platform, channel_id, user_id='', config=None)[source]
Backfill the ego-ablation flags into a room context dict if not already set.
Ensures room_context carries both
ego_ablation_active(a bool) andego_ablation_directive(theEGO_ABLATION_DIRECTIVEtext when active, else an empty string) so the system-prompt template can render consistently even when the context was assembled by a minimal path that did not populate them. Ifego_ablation_activeis already present the dict is left untouched; otherwise the flag is resolved viais_active()(which reads Redis and applies all suppression layers) and both keys are written in place. The module killswitch and a missing Redis client both force the inactive defaults, and any unexpected error is swallowed (logged at debug) with the same inactive fallback so prompt assembly never fails on this.Called by
message_processor/generate_and_send.py(around line 826) andmessage_processor/channel_heartbeat.py(around line 300).- Parameters:
room_context (dict[str, Any]) – The prompt room-context dict, mutated in place to carry the two ego-ablation keys.
redis (Redis | None) – Async Redis client for the lookup; when
Nonethe inactive defaults are written without any I/O.platform (str) – The platform prefix for the channel.
channel_id (str) – The channel/room identifier on that platform.
user_id (str) – The sender’s user id, forwarded to
is_active()for the absolute-bypass check; empty by default.config (Config | None) – Optional config forwarded to
is_active().
- Return type:
None