Skip to content

The agent that grows with you

fix(slack): preserve explicit suspension after timer removal

Tekniumd79575cb89a7
diff --git a/gateway/run_agent_cache.py b/gateway/run_agent_cache.py
index 7ffa809afe4..968d9974931 100644
--- a/gateway/run_agent_cache.py
+++ b/gateway/run_agent_cache.py
@@ -295,7 +295,7 @@ class GatewayAgentCacheMixin:
return False
def _clear_conversation_scope(self, session_key: str, *, reason: str) -> None:
- """THE single conversation-boundary funnel (/new, /resume, auto-reset, expiry finalization,
+ """THE single conversation-boundary funnel (/new, /resume, suspension replacement,
compression-exhausted reset). New conversation-scoped dicts go in _CONVERSATION_SCOPED_STATE
so every boundary picks them up. Turn-scoped state (_running_agents/_ts, slot leases, turn-
lease tokens) is owned by _release_running_agent_state and NOT cleared. Idle agent-cache
@@ -692,10 +692,9 @@ class GatewayAgentCacheMixin:
from the persisted session next turn). Never touched: agents mid-turn, the most recently
used sessions, and transcripts not yet on disk.
- A gateway serving many chats therefore holds every warm transcript indefinitely: agents that took a
- turn within the TTL are never idle-swept, and the sweep additionally defers finalizable sessions
- until they expire. RSS climbs until the cgroup throttles and SIGTERM can no longer flush inside
- systemd's stop timeout (#80764).
+ A gateway serving many chats can hold every warm transcript for the TTL window.
+ Pressure eviction bounds that heap before the cgroup throttles and SIGTERM can
+ no longer flush inside systemd's stop timeout (#80764).
"""
from gateway.run import _AGENT_PENDING_SENTINEL
from gateway.agent_cache_pressure import (
diff --git a/plugins/platforms/slack/adapter.py b/plugins/platforms/slack/adapter.py
index 5cd278a3e6f..173647d4ddd 100644
--- a/plugins/platforms/slack/adapter.py
+++ b/plugins/platforms/slack/adapter.py
@@ -5819,7 +5819,6 @@ class SlackAdapter(BasePlatformAdapter):
if not session_store:
return False
try:
- source = self._thread_session_source(channel_id, thread_ts, user_id, team_id, chat_type)
session_key = self._build_thread_session_key(
channel_id, thread_ts, user_id, team_id=team_id, chat_type=chat_type)
if not session_key:
@@ -5828,11 +5827,9 @@ class SlackAdapter(BasePlatformAdapter):
entry = session_store._entries.get(session_key)
if entry is None:
return False
- # A key the reset policy (daily/idle/suspended) would roll is NOT active:
- # treating it as such would suppress the first-turn thread-history reseed.
- # See #55239.
- should_reset = getattr(type(session_store), "_should_reset", None)
- return not (callable(should_reset) and should_reset(session_store, entry, source))
+ # Explicit suspension starts a fresh conversation on the next turn and
+ # must not suppress thread-history reseeding. Elapsed time is not a boundary.
+ return not entry.suspended
except Exception:
return False
diff --git a/tests/gateway/test_slack_approval_buttons.py b/tests/gateway/test_slack_approval_buttons.py
index bfe3b0ef61d..e926a22502c 100644
--- a/tests/gateway/test_slack_approval_buttons.py
+++ b/tests/gateway/test_slack_approval_buttons.py
@@ -481,6 +481,24 @@ class TestSlackThreadContext:
# ===========================================================================
+def test_thread_suspension_requires_a_fresh_context(tmp_path):
+ """Stopping a Slack thread must re-enable first-turn history seeding."""
+ from gateway.config import GatewayConfig
+ from gateway.session import SessionStore
+
+ adapter = _make_adapter()
+ store = SessionStore(tmp_path / "sessions", GatewayConfig())
+ adapter._session_store = store
+ source = adapter._thread_session_source("C1", "1000.0", "U123", "", "group")
+ entry = store.get_or_create_session(source)
+ try:
+ assert adapter._has_active_session_for_thread("C1", "1000.0", "U123")
+ store.suspend_session(entry.session_key)
+ assert not adapter._has_active_session_for_thread("C1", "1000.0", "U123")
+ finally:
+ store._db.close()
+
+
class TestSessionKeyChatType:
"""Test that _has_active_session_for_thread passes event-derived chat_type.
diff --git a/website/docs/developer-guide/gateway-internals.md b/website/docs/developer-guide/gateway-internals.md
index 7982c62c81a..e321569e658 100644
--- a/website/docs/developer-guide/gateway-internals.md
+++ b/website/docs/developer-guide/gateway-internals.md
@@ -237,11 +237,9 @@ AIAgent._invoke_tool()
### Memory Flush Lifecycle
-When a session is reset, resumed, or expires:
-1. Built-in memories are flushed to disk
-2. Memory provider's `on_session_end()` hook fires
-3. A temporary `AIAgent` runs a memory-only conversation turn
-4. Context is then discarded or archived
+Explicit conversation boundaries (such as `/new`, `/reset`, or `/resume`) flush and finalize the outgoing session. Idle time and daily boundaries never finalize it.
+
+Resource-only TTL, LRU, and memory-pressure eviction commits the cached transcript to configured memory providers before releasing the agent's clients. It does not close the durable conversation: the next turn reloads the same transcript and identity.
## Background Maintenance
diff --git a/website/docs/user-guide/features/hooks.md b/website/docs/user-guide/features/hooks.md
index cb94d9130b4..cecfd57856a 100644
--- a/website/docs/user-guide/features/hooks.md
+++ b/website/docs/user-guide/features/hooks.md
@@ -994,7 +994,7 @@ def register(ctx):
### `on_session_finalize`
-Fires when the CLI or gateway **tears down** an active session — for example, when the user runs `/new`, the gateway GC'd an idle session, or the CLI quit with an active agent. Use it to flush state tied to the outgoing session ID. On gateway reset, the replacement session already exists before this callback runs.
+Fires when the CLI or gateway **tears down** an active session — for example, when the user runs `/new` or the CLI quits with an active agent. Resource-only idle cache eviction does not finalize the durable conversation. Use it to flush state tied to the outgoing session ID. On gateway reset, the replacement session already exists before this callback runs.
**Callback signature:**
diff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/developer-guide/gateway-internals.md b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/developer-guide/gateway-internals.md
index 60db451e9d5..b67a6c872ee 100644
--- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/developer-guide/gateway-internals.md
+++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/developer-guide/gateway-internals.md
@@ -235,11 +235,9 @@ AIAgent._invoke_tool()
### 内存刷写生命周期
-当会话被重置或恢复时:
-1. 内置内存刷写至磁盘
-2. 内存提供者的 `on_session_end()` hook 触发
-3. 临时 `AIAgent` 运行仅含内存的对话轮次
-4. 上下文随后被丢弃或归档
+显式对话边界(例如 `/new`、`/reset` 或 `/resume`)会刷新并结束原会话。空闲时间和每日时间边界不会结束会话。
+
+TTL、LRU 和内存压力触发的资源缓存淘汰会先将缓存的对话记录提交给已配置的记忆提供者,再释放 agent 客户端。它不会关闭持久化对话:下一轮会重新加载相同的对话记录和会话标识。
## 后台维护
diff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/features/hooks.md b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/features/hooks.md
index 1b01af81d6b..a169b6aed7f 100644
--- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/features/hooks.md
+++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/user-guide/features/hooks.md
@@ -773,7 +773,7 @@ def register(ctx):
### `on_session_finalize`
-当 CLI 或 gateway **销毁**活跃会话时触发——例如用户执行 `/new`、gateway GC 了空闲会话,或 CLI 在 agent 活跃时退出。可用它刷新与旧 session ID 绑定的状态。Gateway reset 时,替代会话会先创建并持久化,然后才调用此回调。
+当 CLI 或 gateway **销毁**活跃会话时触发——例如用户执行 `/new`,或 CLI 在 agent 活跃时退出。仅回收资源的空闲缓存淘汰不会结束持久化对话。可用它刷新与旧 session ID 绑定的状态。Gateway reset 时,替代会话会先创建并持久化,然后才调用此回调。
**回调签名:**