From 8be30cfd828a954f08961b8e9ed7b63047ff4b78 Mon Sep 17 00:00:00 2001 From: Younes Belkada Date: Thu, 3 Dec 2026 09:49:41 +0000 Subject: [PATCH 1/2] harbor: let DeepSeek Harness compact only when a full reply no longer fits dsh's compaction-basic compacts at min(0.8 x window, window - maxTokens - headroomTokens), with headroomTokens 65536 by default. With a 131072-token window and 32768-token replies that is 32768 tokens, while a compaction keeps 0.16 x 98304 tokens, so the context is back at the threshold after every summary and dsh compacts again on nearly every step. Set headroomTokens to 0 in the profile patch. Co-Authored-By: Claude Opus 5.5 --- src/openenv/harbor/deepseek_harness.py | 6 ++++++ tests/envs/test_harbor_deepseek_harness.py | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/src/openenv/harbor/deepseek_harness.py b/src/openenv/harbor/deepseek_harness.py index d8eb948286..12fc12a122 100644 --- a/src/openenv/harbor/deepseek_harness.py +++ b/src/openenv/harbor/deepseek_harness.py @@ -99,6 +99,12 @@ def profile_patch( "id": "tool-web", "config": {"search": False, "fetch": web_fetch, "searchTimeoutMs": 60000}, }, + # dsh compacts at min(0.8 x window, window - maxTokens - headroomTokens), headroom 65536 by default (sized + # for DeepSeek's 1M window). At 131072 / 32768 that is 32768 tokens while it keeps 0.16 x 98304 after a + # summary, so it compacted again on nearly every step (~72% of a TB 2.1 attempt). Headroom 0: compact only + # when the next full-length reply would no longer fit (98304 at 131072 / 32768; 32768 at 65536 / 32768, + # where the default leaves no budget and dsh compacts only after an overflow) + {"id": "compaction-basic", "config": {"headroomTokens": 0}}, ] diff --git a/tests/envs/test_harbor_deepseek_harness.py b/tests/envs/test_harbor_deepseek_harness.py index bace77fab3..90d36db082 100644 --- a/tests/envs/test_harbor_deepseek_harness.py +++ b/tests/envs/test_harbor_deepseek_harness.py @@ -78,6 +78,15 @@ def test_profile_routes_the_model_to_the_proxy(): assert by_id["tool-web"]["search"] is False +def test_compaction_waits_for_the_window(): + # dsh compacts at min(0.8 x window, window - maxTokens - headroomTokens); its default headroom (65536) put that at + # 32768 of a 131072 window, so it compacted on nearly every step. Headroom 0: only when a full reply no longer fits. + for window, max_tokens in ((131072, 32768), (65536, 32768)): + patch = dsh.profile_patch("m", "http://proxy", "high", window, max_tokens) + by_id = {entry["id"]: entry["config"] for entry in patch} + assert by_id["compaction-basic"] == {"headroomTokens": 0} + + def test_effort_none_is_dsh_off(): patch = dsh.profile_patch("m", "http://proxy", "none", 65536, 32768) route = patch[0]["config"]["providers"][dsh.DSH_PROVIDER] From dbde1d7a0e4c8e148852f11aa684254c3d14c079 Mon Sep 17 00:00:00 2001 From: burtenshaw Date: Thu, 3 Dec 2026 10:58:22 +0100 Subject: [PATCH 2/2] fix(harbor): keep DeepSeek Harness compaction config valid --- src/openenv/harbor/deepseek_harness.py | 19 +++++++++---------- tests/envs/test_harbor_deepseek_harness.py | 18 +++++++++++------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/openenv/harbor/deepseek_harness.py b/src/openenv/harbor/deepseek_harness.py index 12fc12a122..c0a8ad6b02 100644 --- a/src/openenv/harbor/deepseek_harness.py +++ b/src/openenv/harbor/deepseek_harness.py @@ -7,13 +7,13 @@ - the same package and pin (npm `@deepseek-ai/dsh` 0.2.2-rc.1, every release a prerelease), on Node 24 through nvm; - the same command, `dsh headless --patch --json --permission-mode danger-full-access -- ` (no sandbox, no approvals, as every harness runs), with a fresh `DSH_HOME` per trial; -- the same three-entry profile patch: the route model as a custom `openai-completions` provider of its pi-ai adapter - (the model's context window and longest reply, the run's effort, the system prompt as role `system`), that model as - the agent's default, and its web search off (it needs a DeepSeek platform key the sandbox does not hold). +- the same model routing and web search settings: a custom `openai-completions` provider in the pi-ai adapter sets + the model's context window, longest reply, reasoning effort and system role. The profile selects that model as + the default and disables web search (it needs a DeepSeek platform key the sandbox does not hold). What differs from the board: the provider's base URL is the capture proxy and its key the capture session; the input is text only (vLLM serves the language model alone); the model's limits are the run's (`--max-model-len`, -`--max-output-tokens`), not the model's own. +`--max-output-tokens`), not the model's own. The compaction policy drops extra headroom for smaller context windows. The `deepseek-harness` seam (`seams.py`) points its `import_path` here. The run's effort and limits come from `OPENENV_DSH_EFFORT`, `OPENENV_DSH_CONTEXT_WINDOW` and `OPENENV_DSH_MAX_TOKENS` where the server runs (read in @@ -99,12 +99,11 @@ def profile_patch( "id": "tool-web", "config": {"search": False, "fetch": web_fetch, "searchTimeoutMs": 60000}, }, - # dsh compacts at min(0.8 x window, window - maxTokens - headroomTokens), headroom 65536 by default (sized - # for DeepSeek's 1M window). At 131072 / 32768 that is 32768 tokens while it keeps 0.16 x 98304 after a - # summary, so it compacted again on nearly every step (~72% of a TB 2.1 attempt). Headroom 0: compact only - # when the next full-length reply would no longer fit (98304 at 131072 / 32768; 32768 at 65536 / 32768, - # where the default leaves no budget and dsh compacts only after an overflow) - {"id": "compaction-basic", "config": {"headroomTokens": 0}}, + # Zero headroom requires an explicit summary limit. Bound dsh's default by the route's reply budget. + { + "id": "compaction-basic", + "config": {"headroomTokens": 0, "maxTokens": min(65_536, max_tokens)}, + }, ] diff --git a/tests/envs/test_harbor_deepseek_harness.py b/tests/envs/test_harbor_deepseek_harness.py index 90d36db082..23debce6cd 100644 --- a/tests/envs/test_harbor_deepseek_harness.py +++ b/tests/envs/test_harbor_deepseek_harness.py @@ -78,13 +78,17 @@ def test_profile_routes_the_model_to_the_proxy(): assert by_id["tool-web"]["search"] is False -def test_compaction_waits_for_the_window(): - # dsh compacts at min(0.8 x window, window - maxTokens - headroomTokens); its default headroom (65536) put that at - # 32768 of a 131072 window, so it compacted on nearly every step. Headroom 0: only when a full reply no longer fits. - for window, max_tokens in ((131072, 32768), (65536, 32768)): - patch = dsh.profile_patch("m", "http://proxy", "high", window, max_tokens) - by_id = {entry["id"]: entry["config"] for entry in patch} - assert by_id["compaction-basic"] == {"headroomTokens": 0} +@pytest.mark.parametrize( + "window,max_tokens,summary_limit", + [(65_536, 32_768, 32_768), (131_072, 32_768, 32_768), (1_048_576, 131_072, 65_536)], +) +def test_profile_removes_extra_compaction_headroom(window, max_tokens, summary_limit): + patch = dsh.profile_patch("m", "http://proxy", "high", window, max_tokens) + by_id = {entry["id"]: entry["config"] for entry in patch} + assert by_id["compaction-basic"] == { + "headroomTokens": 0, + "maxTokens": summary_limit, + } def test_effort_none_is_dsh_off():