From eb7d288a82c8bf031d9fdba203ab472cf5b7ca51 Mon Sep 17 00:00:00 2001 From: majdyz Date: Tue, 14 Apr 2026 18:57:01 +0700 Subject: [PATCH] fix(backend/copilot): make --session-id and --resume mutually exclusive CLI >=2.1.97 rejects combining --session-id with --resume unless --fork-session is also specified. Pass --session-id only on T1 (when no --resume is used) and --resume only on T2+ (which already implies the session UUID). Verified T1/T2/T3 multi-turn context preserved. --- .../backend/backend/copilot/sdk/service.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/autogpt_platform/backend/backend/copilot/sdk/service.py b/autogpt_platform/backend/backend/copilot/sdk/service.py index 765d62db17..7be70abc78 100644 --- a/autogpt_platform/backend/backend/copilot/sdk/service.py +++ b/autogpt_platform/backend/backend/copilot/sdk/service.py @@ -2297,10 +2297,6 @@ async def stream_chat_completion_sdk( "disallowed_tools": disallowed, "hooks": security_hooks, "cwd": sdk_cwd, - # Force CLI to use the app session UUID so the native session file - # lands at a predictable path: {projects_base}/{encoded_cwd}/{session_id}.jsonl - # This enables cross-pod --resume without pod affinity. - "session_id": session_id, "max_buffer_size": config.claude_agent_max_buffer_size, "stderr": _on_stderr, # --- P0 guardrails --- @@ -2330,7 +2326,16 @@ async def stream_chat_completion_sdk( if sdk_env: sdk_options_kwargs["env"] = sdk_env if use_resume and resume_file: + # --resume {uuid} implies the session UUID — do NOT also pass + # --session-id here. CLI >=2.1.97 rejects the combination of + # --session-id + --resume unless --fork-session is also given. sdk_options_kwargs["resume"] = resume_file + else: + # No --resume on this turn: force the CLI to write its native + # session JSONL to a predictable path so upload_cli_session() + # can find it after the turn completes. + # Path: {projects_base}/{encoded_cwd}/{session_id}.jsonl + sdk_options_kwargs["session_id"] = session_id # Optional explicit Claude Code CLI binary path (decouples the # bundled SDK version from the CLI version we run — needed because # the CLI bundled in 0.1.46+ is broken against OpenRouter). Falls