tenseleyflow/loader / 2c94bf4

Browse files

Clamp compaction to small contexts

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
2c94bf45d3898209d201d213a60ed49396fc37ba
Parents
bba591d
Tree
88a8e4e

3 changed files

StatusFile+-
M src/loader/runtime/compaction.py 3 4
M tests/test_compaction.py 4 0
M tests/test_runtime_public_shell.py 1 1
src/loader/runtime/compaction.pymodified
@@ -76,10 +76,9 @@ def resolve_auto_compaction_input_tokens_threshold(
7676
     if context_window is None or context_window <= 0:
7777
         return threshold
7878
 
79
-    context_bound = max(
80
-        MIN_AUTO_COMPACTION_INPUT_TOKENS_THRESHOLD,
81
-        int(context_window * 0.75),
82
-    )
79
+    context_bound = max(1, int(context_window * 0.75))
80
+    if context_window >= int(MIN_AUTO_COMPACTION_INPUT_TOKENS_THRESHOLD / 0.75):
81
+        context_bound = max(MIN_AUTO_COMPACTION_INPUT_TOKENS_THRESHOLD, context_bound)
8382
     context_bound = min(DEFAULT_AUTO_COMPACTION_INPUT_TOKENS_THRESHOLD, context_bound)
8483
     return min(threshold, context_bound)
8584
 
tests/test_compaction.pymodified
@@ -338,4 +338,8 @@ def test_resolve_auto_compaction_threshold_uses_context_window_as_upper_bound()
338338
     assert resolve_auto_compaction_input_tokens_threshold(
339339
         100_000,
340340
         context_window=8_192,
341
+    ) == 6_144
342
+    assert resolve_auto_compaction_input_tokens_threshold(
343
+        100_000,
344
+        context_window=16_000,
341345
     ) == 12_000
tests/test_runtime_public_shell.pymodified
@@ -392,7 +392,7 @@ def test_refresh_runtime_shell_capability_profile_reclamps_session_threshold(
392392
     backend = ProfiledBackend()
393393
     handle = _runtime_handle(temp_dir, backend=backend)
394394
 
395
-    assert handle.session.auto_compaction_input_tokens_threshold == 12_000
395
+    assert handle.session.auto_compaction_input_tokens_threshold == 6_144
396396
 
397397
     backend.context_window = 131_072
398398
     refresh_runtime_shell_capability_profile(handle)