Skip to content

The agent that grows with you

fix(discord): the triggering-message note no longer depends on message_id presence

John Paul Soliva38151eed64b1
diff --git a/gateway/run_agent_cache.py b/gateway/run_agent_cache.py
index 6adcce2674c..b9b8f72dda8 100644
--- a/gateway/run_agent_cache.py
+++ b/gateway/run_agent_cache.py
@@ -730,11 +730,9 @@ class GatewayAgentCacheMixin:
if src.platform == Platform.DISCORD:
from gateway.session import _discord_tools_loaded
discord_tools = "1" if _discord_tools_loaded() else "0"
- # message_id: only PRESENCE is rendered (the id itself arrives per-turn in the user
- # message) — keying on the value would re-render every message for zero byte change.
+ # message_id is not rendered (value nor presence): it arrives per-turn in the user message.
discord_ids = (
_s(src.guild_id), _s(src.parent_chat_id), _s(src.thread_id), _s(src.chat_id),
- "1" if src.message_id else "0",
)
# Slack's capability-aware platform note is gated on _slack_tools_loaded() — the gate state must
# be in the key (same parity contract as the Discord gate above) so a config / MCP-registration
diff --git a/gateway/session.py b/gateway/session.py
index 6e6c6dd2926..3645a885830 100644
--- a/gateway/session.py
+++ b/gateway/session.py
@@ -327,13 +327,13 @@ def _discord_platform_notes(context: SessionContext) -> List[str]:
lines.append(f" - Thread: `{src.thread_id}` (use as `channel_id` for fetch_messages etc.)")
else:
lines.append(f" - Channel: `{src.chat_id}`")
- if src.message_id:
- # The volatile per-turn message id must stay OUT of this cached block (it would bust the
- # agent-cache signature every message); run.py injects it into the user message instead.
- lines.append(
- " - Triggering message: provided per-turn in the incoming user message (use it as "
- "`message_id` for reply/react/pin)"
- )
+ # Neither the volatile id nor its presence belongs in this pinned block: slash and voice
+ # turns have no triggering message, so a presence-gated line flips the prompt between them
+ # and typed turns. run.py injects the real id into the user message when there is one.
+ lines.append(
+ " - Triggering message: when available, its ID is provided per-turn in the incoming "
+ "user message (use it as `message_id` for reply/react/pin)"
+ )
else:
lines = ["", (
"**Platform notes:** You are running inside Discord. You do NOT have access to "
diff --git a/tests/gateway/test_discord_turn_prompt_parity.py b/tests/gateway/test_discord_turn_prompt_parity.py
index 1c61ff913b4..64253fcb547 100644
--- a/tests/gateway/test_discord_turn_prompt_parity.py
+++ b/tests/gateway/test_discord_turn_prompt_parity.py
@@ -62,7 +62,8 @@ def _adapter(monkeypatch, bound_id) -> DiscordAdapter:
async def _typed(adapter, channel):
await adapter._handle_message(SimpleNamespace(
id=123, content="what broke?", mentions=[], attachments=[], reference=None,
- created_at=datetime.now(timezone.utc), channel=channel, author=_USER))
+ created_at=datetime.now(timezone.utc), channel=channel, author=_USER,
+ guild=getattr(channel, "guild", None)))
return adapter.handle_message.await_args.args[0]
@@ -93,8 +94,11 @@ def _interaction(channel):
@pytest.mark.asyncio
[email protected]("tools", [False, True], ids=["no-discord-tools", "discord-tools"])
@pytest.mark.parametrize("case", ["dm", "channel", "thread", "thread-starter"])
-async def test_slash_and_thread_starter_turns_match_a_message_turn(monkeypatch, case):
+async def test_slash_and_thread_starter_turns_match_a_message_turn(monkeypatch, case, tools):
+ # With Discord tools on, the pinned notes list IDs; a slash turn has no triggering message.
+ monkeypatch.setattr("gateway.session._discord_tools_loaded", lambda: tools)
parent = _parent()
channel = {"dm": _DM(500), "channel": parent}.get(case) or _Thread(800, parent)
adapter = _adapter(monkeypatch, channel.id)