test+polish(compression): pin anti-thrash gate and gateway session_id persistence

Follow-up to @someaka's fix.

Polish:
- Drop the redundant `_preflight_tokens >= threshold_tokens` clause.
  `should_compress(tokens)` already short-circuits when tokens < threshold,
  so the explicit comparison was dead code on the True branch.

Tests:
- Preflight: pin that should_compress() is called (anti-thrash has a vote).
  Mocks should_compress to return False even with tokens past the raw
  threshold and asserts no compression runs — exact bug shape from #29335.
- Gateway: AST scan of gateway/run.py asserts every
  `session_entry.session_id = ...` assignment is followed by a
  `session_store._save()` call within the same block. Three sites mutate
  the session_id after compression; all three must persist or the next
  turn loads the pre-compression transcript and re-loops. Empirically
  verified the test catches the bug (drops the new _save() line → red).

AUTHOR_MAP:
- Map ed@bebop.crew -> someaka so the salvaged commit resolves to
  @someaka in release notes.
This commit is contained in:
Teknium
2026-05-25 01:44:46 -07:00
parent 3914089d52
commit 11c40d6a42
4 changed files with 147 additions and 2 deletions
+1 -2
View File
@@ -484,8 +484,7 @@ def run_conversation(
tools=agent.tools or None,
)
if _preflight_tokens >= agent.context_compressor.threshold_tokens \
and agent.context_compressor.should_compress(_preflight_tokens):
if agent.context_compressor.should_compress(_preflight_tokens):
logger.info(
"Preflight compression: ~%s tokens >= %s threshold (model %s, ctx %s)",
f"{_preflight_tokens:,}",