Skip to content

fix(llm): prevent IndexError when reasoning items are absent in responses API - #2511

Merged
endxxxx merged 2 commits into
MemTensor:dev-v2.0.36from
keeponlight:fix/openai-responses-empty-reasoning
Oct 24, 2026
Merged

endxxxx merged 2 commits into
MemTensor:dev-v2.0.36from
keeponlight:fix/openai-responses-empty-reasoning

Conversation

@keeponlight

Copy link
Copy Markdown

Description

Fix IndexError: list index out of range in OpenAIResponsesLLM.generate and AzureResponsesLLM.generate when response.output does not contain any ResponseReasoningItem (for example, when enable_thinking=False by default or when calling non-reasoning models).

Currently, both methods evaluate summary = output_reasoning[0].summary unconditionally right after filtering output_reasoning, which raises IndexError whenever output_reasoning is empty ([]). Guarding the lookup with output_reasoning[0].summary if output_reasoning else None safely handles both missing ResponseReasoningItem entries and empty summary lists.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Ran unit tests covering OpenAIResponsesLLM.generate and AzureResponsesLLM.generate across three scenarios:

  1. Responses without any ResponseReasoningItem (output_reasoning == [])
  2. Responses with ResponseReasoningItem(summary=[])
  3. Responses with non-empty reasoning summary (remove_think_prefix=False and remove_think_prefix=True)
pytest tests/llms/test_openai_responses_llm.py -vv
ruff check src/memos/llms/openai_new.py tests/llms/test_openai_responses_llm.py
  • Unit Test

Checklist

  • I have performed a self-review of my own code | 我已自行检查了自己的代码
  • I have commented my code in hard-to-understand areas | 我已在难以理解的地方对代码进行了注释
  • I have added tests that prove my fix is effective or that my feature works | 我已添加测试以证明我的修复有效或功能正常
  • I have created related documentation issue/PR in MemOS-Docs (if applicable) | 我已在 MemOS-Docs 中创建了相关的文档 issue/PR(如果适用)
  • I have linked the issue to this PR (if applicable) | 我已将 issue 链接到此 PR(如果适用)
  • I have mentioned the person who will review this PR | 我已提及将审查此 PR 的人

@Memtensor-AI Memtensor-AI added area:model llm + embedder + reranker status:in-progress Someone or AI is working on it | 人工或 AI 正在处理 labels Oct 17, 2026
@Memtensor-AI
Memtensor-AI requested a review from endxxxx October 17, 2026 12:02
@Memtensor-AI

Memtensor-AI commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

🤖 Open Code Review

Target: PR #2511
Task: 19043f5148060094
Base: dev-v2.0.36
Head: fix/openai-responses-empty-reasoning

✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s).

Generated by cloud-assistant via Open Code Review.

@Memtensor-AI

Copy link
Copy Markdown
Collaborator

✅ Automated Test Results: PASSED

All tests passed (8/8 executed). memos_python_core/changed-repo-python: 8/8. Duration: 13s

Branch: fix/openai-responses-empty-reasoning

@Memtensor-AI Memtensor-AI added status:ready Ready for implementation; waiting for assignee or AI dispatch | 可进入实现,等待认领或派发 and removed status:in-progress Someone or AI is working on it | 人工或 AI 正在处理 labels Oct 17, 2026
@keeponlight
keeponlight force-pushed the fix/openai-responses-empty-reasoning branch from 263c543 to 9b4fea3 Compare October 18, 2026 02:23
@Memtensor-AI Memtensor-AI added status:in-progress Someone or AI is working on it | 人工或 AI 正在处理 and removed status:ready Ready for implementation; waiting for assignee or AI dispatch | 可进入实现,等待认领或派发 labels Oct 18, 2026
@Memtensor-AI

Copy link
Copy Markdown
Collaborator

✅ Automated Test Results: PASSED

All tests passed (8/8 executed). memos_python_core/changed-repo-python: 8/8. Duration: 9s [advisory, non-gating] AI-generated tests on branch test/auto-gen-19043f5148060094-20261024221242: 84/87 passed, 3 failed — these do NOT affect the PR verdict; review the branch manually.

Branch: fix/openai-responses-empty-reasoning

@Memtensor-AI Memtensor-AI added status:ready Ready for implementation; waiting for assignee or AI dispatch | 可进入实现,等待认领或派发 and removed status:in-progress Someone or AI is working on it | 人工或 AI 正在处理 labels Oct 24, 2026
@endxxxx
endxxxx merged commit 5fa7293 into MemTensor:dev-v2.0.36 Oct 24, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:model llm + embedder + reranker status:ready Ready for implementation; waiting for assignee or AI dispatch | 可进入实现,等待认领或派发

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants