From 5dbbdf9b2724f6cfdad07c7e04507b648cbc7cad Mon Sep 17 00:00:00 2001 From: majdyz Date: Mon, 13 Apr 2026 04:23:54 +0000 Subject: [PATCH] fix(copilot): address round-6 review nits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove redundant inner `ChatConfig` import in `_prewarm_cli` — it was already imported at module scope on line 16 (style guide: inner imports only for heavy optional deps) - Correct stale comment in `sdk_compat_test.py`: 2.1.63/2.1.70 pre-date the context-management regression and are OpenRouter-safe without any env var; only 2.1.97+ requires CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 - Update `_assert_no_forbidden_patterns` error message in `cli_openrouter_compat_test.py`: remove the stale "above 0.1.45" ceiling (we've already upgraded to 0.1.58) and point at the correct remediation steps (add to _KNOWN_GOOD_BUNDLED_CLI_VERSIONS after bisect verification) - Plug test coverage gap in `env_test.py`: add `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS == "1"` assertions to three OpenRouter test methods that were missing it (test_strips_trailing_v1, test_strips_trailing_v1_and_slash, test_no_v1_suffix_left_alone) — guards against the env var being accidentally dropped from a code path that the main test didn't exercise --- .../backend/backend/copilot/executor/processor.py | 2 -- .../copilot/sdk/cli_openrouter_compat_test.py | 15 ++++++++------- .../backend/backend/copilot/sdk/env_test.py | 3 +++ .../backend/copilot/sdk/sdk_compat_test.py | 12 +++++++----- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/autogpt_platform/backend/backend/copilot/executor/processor.py b/autogpt_platform/backend/backend/copilot/executor/processor.py index 2f9e563784..96bcadcaab 100644 --- a/autogpt_platform/backend/backend/copilot/executor/processor.py +++ b/autogpt_platform/backend/backend/copilot/executor/processor.py @@ -183,8 +183,6 @@ class CoPilotProcessor: back to the bundled binary when no override is set. """ try: - from backend.copilot.config import ChatConfig - cfg = ChatConfig() cli_path: str | None = cfg.claude_agent_cli_path if not cli_path: diff --git a/autogpt_platform/backend/backend/copilot/sdk/cli_openrouter_compat_test.py b/autogpt_platform/backend/backend/copilot/sdk/cli_openrouter_compat_test.py index 64bdf5f656..386631f8ec 100644 --- a/autogpt_platform/backend/backend/copilot/sdk/cli_openrouter_compat_test.py +++ b/autogpt_platform/backend/backend/copilot/sdk/cli_openrouter_compat_test.py @@ -443,14 +443,15 @@ def _assert_no_forbidden_patterns( f"Bundled Claude Code CLI sent OpenRouter-incompatible features in " f"{len(all_findings)} request(s):\n - " + "\n - ".join(all_findings) - + "\n\nThis is the regression that prevents us from upgrading " - "`claude-agent-sdk` above 0.1.45. See " - "https://github.com/Significant-Gravitas/AutoGPT/pull/12294 and " + + "\n\nThe bundled CLI is sending OpenRouter-incompatible features. " + "See https://github.com/Significant-Gravitas/AutoGPT/pull/12294 and " "https://github.com/anthropics/claude-agent-sdk-python/issues/789. " - "If you intended to upgrade, ensure " - "`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` is set in the SDK env " - "or use a known-good CLI binary via `claude_agent_cli_path` (env: " - "`CLAUDE_AGENT_CLI_PATH` or `CHAT_CLAUDE_AGENT_CLI_PATH`)." + "If you bumped `claude-agent-sdk`, verify the new bundled CLI works " + "with `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` set (injected by " + "``build_sdk_env()`` in ``env.py``), then add the CLI version to " + "`_KNOWN_GOOD_BUNDLED_CLI_VERSIONS` in `sdk_compat_test.py`. " + "Alternatively, pin a known-good binary via `claude_agent_cli_path` " + "(env: `CLAUDE_AGENT_CLI_PATH` or `CHAT_CLAUDE_AGENT_CLI_PATH`)." ) diff --git a/autogpt_platform/backend/backend/copilot/sdk/env_test.py b/autogpt_platform/backend/backend/copilot/sdk/env_test.py index 3e748e5be2..4418ff4ce4 100644 --- a/autogpt_platform/backend/backend/copilot/sdk/env_test.py +++ b/autogpt_platform/backend/backend/copilot/sdk/env_test.py @@ -138,6 +138,7 @@ class TestBuildSdkEnvOpenRouter: result = build_sdk_env() assert result["ANTHROPIC_BASE_URL"] == "https://openrouter.ai/api" + assert result.get("CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS") == "1" def test_strips_trailing_v1_and_slash(self): """Trailing slash before /v1 strip is handled.""" @@ -149,6 +150,7 @@ class TestBuildSdkEnvOpenRouter: # rstrip("/") first, then remove /v1 assert result["ANTHROPIC_BASE_URL"] == "https://openrouter.ai/api" + assert result.get("CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS") == "1" def test_no_v1_suffix_left_alone(self): """A base URL without /v1 is used as-is.""" @@ -159,6 +161,7 @@ class TestBuildSdkEnvOpenRouter: result = build_sdk_env() assert result["ANTHROPIC_BASE_URL"] == "https://custom-proxy.example.com" + assert result.get("CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS") == "1" def test_session_id_header(self): cfg = self._openrouter_config() diff --git a/autogpt_platform/backend/backend/copilot/sdk/sdk_compat_test.py b/autogpt_platform/backend/backend/copilot/sdk/sdk_compat_test.py index fcc03939bd..c705d26c22 100644 --- a/autogpt_platform/backend/backend/copilot/sdk/sdk_compat_test.py +++ b/autogpt_platform/backend/backend/copilot/sdk/sdk_compat_test.py @@ -215,17 +215,19 @@ def test_sdk_exports_hook_event_type(hook_event: str): # message that points the next person at the OpenRouter compat issue # instead of letting them silently re-break production. -# CLI versions verified to work against OpenRouter when the -# ``CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`` env var is set -- -# bisected via the reproduction test in ``cli_openrouter_compat_test.py``. +# CLI versions bisect-verified as OpenRouter-safe. 2.1.63 and 2.1.70 pre-date +# the context-management beta regression and work without any env var. 2.1.97+ +# requires ``CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1`` (injected by +# ``build_sdk_env()`` in ``env.py``) to strip the beta header. _KNOWN_GOOD_BUNDLED_CLI_VERSIONS: frozenset[str] = frozenset( { "2.1.63", # claude-agent-sdk 0.1.45 -- original pin from PR #12294. "2.1.70", # claude-agent-sdk 0.1.47 -- first version with the # tool_reference proxy detection fix; bisect-verified # OpenRouter-safe in #12742. - "2.1.97", # claude-agent-sdk 0.1.58 -- works with the - # CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 env var. + "2.1.97", # claude-agent-sdk 0.1.58 -- OpenRouter-safe only with + # CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 (injected by + # build_sdk_env() in env.py). } )