Skip to content

The agent that grows with you

refactor(gateway): skip the unused session-row read on a resident no-op /compress

Teknium2a3be7dd5b8e
diff --git a/gateway/session_mutation_compress.py b/gateway/session_mutation_compress.py
index a103ce15d9e..b45d2b8d2d2 100644
--- a/gateway/session_mutation_compress.py
+++ b/gateway/session_mutation_compress.py
@@ -86,7 +86,8 @@ async def prepare_compress(authority, live, payload, prepared):
if compressed is None:
# Nothing removable (a short session keeps every message): main's read-only
# "No changes from compression" report, estimated like main's (system prompt + tools).
- tokens = _request_tokens(resident, messages, authority.db.get_session(snapshot['target']))
+ row = None if resident is not None else authority.db.get_session(snapshot['target']) # resident: row unused
+ tokens = _request_tokens(resident, messages, row)
return {'status': 'noop', 'summary': summarize_manual_compression(
messages, messages, tokens, tokens, compression_state=compressor)}
summary = summarize_manual_compression(messages, compressed, estimate_request_tokens_rough(messages),
@@ -118,7 +119,6 @@ def _request_tokens(agent, messages, row=None):
"""Main's /compress request estimate: the agent's system prompt and tool schemas plus the messages.
No resident agent (a cold session): the prompt and tools[] pin the session row stores, which the
next agent restores and sends, so the figure matches what main's resident agent reported."""
- import json
from agent.model_metadata import estimate_request_tokens_rough
prompt = getattr(agent, '_cached_system_prompt', '') or ''
tools = getattr(agent, 'tools', None) or None