Skip to content

fix(run_agent): strip temperature from flush_memories Codex fallback path#15390

Closed
24601 wants to merge 2 commits into
NousResearch:mainfrom
24601:fix/flush-memories-codex-temperature
Closed

fix(run_agent): strip temperature from flush_memories Codex fallback path#15390
24601 wants to merge 2 commits into
NousResearch:mainfrom
24601:fix/flush-memories-codex-temperature

Conversation

@24601

@24601 24601 commented Apr 24, 2026

Copy link
Copy Markdown

Problem

Two related bugs in the flush_memories Codex path cause "Auxiliary memory flush failed" with HTTP 400 errors.

Bug 1 — temperature in fallback path

When flush_memories is in codex_responses mode and the auxiliary client fails for any reason, the fallback path explicitly sets codex_kwargs["temperature"] = _flush_temperature (0.3) before calling _run_codex_stream. The Codex Responses endpoint does not accept temperature and returns:

HTTP 400: Unsupported parameter: temperature

The error propagated to the outer except Exception as e: and surfaced as "Auxiliary memory flush failed" — misleadingly implicating temperature rather than the actual aux failure.

The bug was latent before 8a2506af (which widened except RuntimeErrorexcept Exception as e:). After that commit the inner failure started triggering the fallback path more frequently, exposing this.

Bug 2 — unsupported message roles in adapter

_CodexCompletionsAdapter.create() passes all non-system message roles through to the Responses API unchanged. The Codex endpoint only accepts user and assistant in the input array. Sessions that include memory tool results (prior flush calls) contain role: 'tool' messages, causing:

HTTP 400: Invalid value: 'tool'. Supported values are: 'assistant', 'system', 'developer', and 'user'.

Root Cause

Bug 1run_agent.py, flush_memories Codex fallback:

if _flush_temperature is not None:
    codex_kwargs["temperature"] = _flush_temperature  # ← sends to Codex endpoint

Bug 2agent/auxiliary_client.py, _CodexCompletionsAdapter.create():

for msg in messages:
    role = msg.get("role", "user")
    # ...
    else:
        input_msgs.append({"role": role, ...})  # ← passes role='tool' through

Note: _CodexCompletionsAdapter already correctly omits temperature from resp_kwargs. The fallback path failed to do the same.

Fix

Bug 1: Strip temperature unconditionally from codex_kwargs before _run_codex_stream.

Bug 2: In _CodexCompletionsAdapter, skip role='tool' and role='function' messages; map role='developer' to instructions; silently skip unknown roles.

Tests

Existing test_codex_mode_no_aux_uses_responses_api in tests/run_agent/test_flush_memories_codex.py covers the fallback path.

24601 and others added 2 commits April 24, 2026 15:21
…path

When the auxiliary client fails for any reason (_call_llm raises), the
codex_responses fallback path explicitly set codex_kwargs["temperature"] =
_flush_temperature (0.3). _run_codex_stream then sent this to the Codex
Responses endpoint (chatgpt.com/backend-api/codex), which rejects
temperature with HTTP 400 "Unsupported parameter: temperature".

The error propagated to the outer except block and surfaced as
"Auxiliary memory flush failed: HTTP 400 - Unsupported parameter:
temperature", misleadingly pointing at temperature rather than the
original aux failure.

Fix: strip temperature unconditionally from codex_kwargs before calling
_run_codex_stream, consistent with how _CodexCompletionsAdapter already
omits temperature from Responses API calls.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…nput

The _CodexCompletionsAdapter passed all non-system message roles through
to the Codex Responses endpoint unchanged. The endpoint only accepts
user and assistant roles in the input array; tool/function messages
(from prior memory flush calls in the session) caused HTTP 400:
'Invalid value: tool. Supported values are: assistant, system,
developer, and user.'

Changes:
- Skip role='tool' and role='function' messages (tool results not
  needed for the flush summary context)
- Map role='developer' to instructions, same as role='system'
- Silently skip any other unknown roles rather than sending them
- Note: temperature was already stripped in run_agent.py (prior commit)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder provider/openai OpenAI / Codex Responses API labels Apr 24, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Thanks @24601! This same fix landed independently via #15620 (flush_memories codex_responses fallback, strips temperature up front) and #15623 (universal reactive retry across all providers). The reported symptom is fixed on main. Closing as superseded — credit to you for catching and reporting it.

@teknium1 teknium1 closed this Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists provider/openai OpenAI / Codex Responses API type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants