Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion agent/context_compressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,9 +1181,20 @@ def _effective_threshold_percent(
e.g. Codex gpt-5.5's 85%) always wins; only lower values are raised.
Large-context models keep the configured value — at 512K+ the default
50% trigger already leaves ample post-compaction headroom.

The floor is a safety net for the *default* threshold (0.50), not a
hard override of explicit user configuration. When a user sets
``threshold: 0.3`` to stay within TPM rate limits (e.g. 100K TPM on
a 160K-ctx reasoning model), forcing 75% prevents compression from
ever firing and causes cascading 429s. Respect the user's value when
it is below the default — they chose it deliberately.
"""
if context_length and context_length < _SMALL_CTX_WINDOW_LIMIT:
return max(threshold_percent, _SMALL_CTX_THRESHOLD_PERCENT)
# Only apply the floor when the configured value looks like the
# default (>= 0.50). A value below 0.50 signals deliberate user
# configuration — raising it would defeat the purpose.
if threshold_percent >= 0.50:
return max(threshold_percent, _SMALL_CTX_THRESHOLD_PERCENT)
return threshold_percent

@staticmethod
Expand Down
6 changes: 6 additions & 0 deletions agent/transports/codex.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ def build_kwargs(
# the cache-scope routing headers below. Falls back to session_id when
# there is no static content to hash.
cache_key = _content_cache_key(instructions, response_tools) or session_id
# The backend rejects prompt_cache_key > 64 chars with HTTP 400.
# When _content_cache_key falls back to session_id the key can be
# arbitrarily long (e.g. "paperclip:company:<uuid>:agent:<uuid>" at
# 97 chars). Hash over-length keys so they always fit.
if cache_key and len(cache_key) > 64:
cache_key = f"pck_{hashlib.sha256(cache_key.encode('utf-8', 'replace')).hexdigest()[:24]}"
# xAI Responses takes prompt_cache_key in extra_body (set further
# down); GitHub Models opts out of cache-key routing entirely.
if not is_github_responses and not is_xai_responses and cache_key:
Expand Down
Loading