Skip to content

The agent that grows with you

fix(discord): gate relay-only thread rename kwargs

Michael Nguyen808a22ea00d9
diff --git a/gateway/run.py b/gateway/run.py
index 89aa4acde23..77915549b25 100644
--- a/gateway/run.py
+++ b/gateway/run.py
@@ -24835,19 +24835,31 @@ class GatewayRunner(GatewayAuthorizationMixin, GatewayKanbanWatchersMixin, Gatew
"relay" if use_connector_guard else "native",
thread_name,
)
+ rename_kwargs = (
+ {
+ "prefer_connector_created": True,
+ "parent_chat_id": parent_chat_id,
+ }
+ if use_connector_guard
+ else {"only_if_current_name": guard_name}
+ )
try:
renamed = await rename_thread(
target_thread_id,
thread_name,
- prefer_connector_created=use_connector_guard,
- only_if_current_name=guard_name,
- parent_chat_id=parent_chat_id,
+ **rename_kwargs,
)
logger.info(
"discord auto-thread rename result: thread=%s applied=%s",
target_thread_id,
bool(renamed),
)
+ except TypeError:
+ logger.warning(
+ "Discord semantic thread rename raised TypeError (adapter=%s)",
+ type(adapter).__name__,
+ exc_info=True,
+ )
except Exception:
logger.debug("Failed to rename Discord auto-thread for generated session title", exc_info=True)
diff --git a/tests/gateway/test_session_title_rename_lane.py b/tests/gateway/test_session_title_rename_lane.py
index 691f31c19f9..a821b67ca70 100644
--- a/tests/gateway/test_session_title_rename_lane.py
+++ b/tests/gateway/test_session_title_rename_lane.py
@@ -14,7 +14,7 @@ import types
import pytest
from gateway.config import Platform
-from gateway.run import TurnRunner
+from gateway.run import GatewayRunner, TurnRunner
def _attach(lane):
@@ -53,3 +53,51 @@ def test_the_rename_waits_for_the_model_title(lane):
callback("Fix flaky auth test", "llm")
assert renames == ["Fix flaky auth test"]
+
+
+async def test_native_thread_rename_passes_only_the_initial_name_guard():
+ """The shared rename lane must honor the strict native adapter contract."""
+ calls: list[tuple[str, str, str | None]] = []
+
+ class StrictNativeAdapter:
+ async def rename_thread(
+ self,
+ thread_id: str,
+ name: str,
+ *,
+ only_if_current_name: str | None = None,
+ ) -> bool:
+ calls.append((thread_id, name, only_if_current_name))
+ return True
+
+ class NativeRenameRunner:
+ _is_discord_auto_thread_lane = GatewayRunner._is_discord_auto_thread_lane
+ _sanitize_discord_thread_title = GatewayRunner._sanitize_discord_thread_title
+ _rename_discord_auto_thread_for_session_title = (
+ GatewayRunner._rename_discord_auto_thread_for_session_title
+ )
+
+ def __init__(self, adapter):
+ self.adapters = {Platform.DISCORD: adapter}
+
+ def _adapter_for_source(self, source):
+ return self.adapters[source.platform]
+
+ source = types.SimpleNamespace(
+ platform=Platform.DISCORD,
+ chat_id="999",
+ chat_type="thread",
+ thread_id="999",
+ auto_thread_created=True,
+ auto_thread_initial_name="Initial words",
+ )
+
+ runner = NativeRenameRunner(StrictNativeAdapter())
+ await runner._rename_discord_auto_thread_for_session_title(
+ source,
+ "session-1",
+ "Semantic Session Title",
+ )
+
+ assert calls == [("999", "Semantic Session Title", "Initial words")]