Skip to content

[codex] Repair legacy agent thinking state#93

Merged
utopiafar merged 2 commits into
memex-lab:mainfrom
utopiafar:codex/repair-legacy-agent-thinking-state
May 15, 2026
Merged

[codex] Repair legacy agent thinking state#93
utopiafar merged 2 commits into
memex-lab:mainfrom
utopiafar:codex/repair-legacy-agent-thinking-state

Conversation

@utopiafar
Copy link
Copy Markdown
Collaborator

@utopiafar utopiafar commented May 15, 2026

摘要

  • 在 Memex 加临时兼容修复:加载 agent state 时修复旧 assistant message,避免 thinking/reasoning 上下文丢失后恢复会话失败。
  • 对旧 Claude/Anthropic-compatible 状态合成 thinking / text / tool_use content blocks,并保存修复后的 state。
  • 对旧 DeepSeek V4 tool-call turn 增加窄兜底,避免缺失 reasoning_content 导致下一轮 API 400。
  • 修复 Memex Gemini OAuth replay:thoughtSignature 只挂到一个模型 part,functionResponse.name 使用函数名,并保留可选 call id。
  • 保留已有 provider-native contentBlocks,不覆盖新状态。

根因

dart_agent_core 新版本已经会保存 Anthropic provider-native content blocks,但用户本地可能还有旧的、被中断的 Memex agent state。旧 state 只有扁平字段:thoughttextOutputfunctionCalls,没有 provider 原生 blocks。

当这些旧状态继续跑 thinking/tool-use 模型时,API 要求上一轮 thinking/reasoning 内容必须被传回;如果 Memex 恢复会话时没有补齐,就会出现类似 the reasoning_content in the thinking mode must be passed back to the api 的 400。

这个 PR 是主 app 侧临时方案,用来保护已存在的用户状态。等 core 修复发布后,再升级依赖并收敛这层兼容逻辑。

验证

flutter test --no-pub test/agent/state_util_test.dart
flutter analyze --no-pub lib/agent/state_util.dart lib/llm_client/gemini_oauth_client.dart test/agent/state_util_test.dart

本轮已重新回归,全部通过。

备注:本 workspace 之前 flutter pub get 下载阶段卡住过,所以这里继续使用现有 package config 和 --no-pub 做定向验证。

@utopiafar
Copy link
Copy Markdown
Collaborator Author

Audit update pushed in 403d2db:

  • Added a narrow DeepSeek V4 legacy tool-call repair for persisted state that lost reasoning_content before resume.
  • Fixed Memex Gemini OAuth replay to attach thoughtSignature to one model part, use functionResponse.name for the function name, and preserve optional call IDs.
  • Extended state repair tests for the DeepSeek V4 legacy case.

Validation after this update:

flutter test --no-pub test/agent/state_util_test.dart
flutter analyze --no-pub lib/agent/state_util.dart lib/llm_client/gemini_oauth_client.dart test/agent/state_util_test.dart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant