fix(chat): always persist reasoning_content on assistant event_payload

Non-thinking profiles previously wrote model reasoning only as separate
event_type=reasoning rows whose event_payload held chunk_index metadata, so
JSON inspection showed tool payloads but no reasoning_content key.

Store the full merged reasoning blob on the primary assistant row whenever
present (same shape as thinking mode). Update instruction-leak filtering to
scan event_payload.reasoning_content as well as legacy reasoning rows.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-05-12 23:02:38 +08:00
parent c938147fdb
commit 5efac74f87
3 changed files with 35 additions and 19 deletions

View file

@ -238,12 +238,20 @@ def _filter_internal_instruction_user_messages(msgs: list[Any]) -> list[Any]:
instruction_texts: set[str] = set()
for m in msgs:
role = str(getattr(m, "role", "") or "")
event_type = str(getattr(m, "event_type", "") or "")
if role != "assistant" or event_type != "reasoning":
if role != "assistant":
continue
instr = _extract_manager_instruction_text(str(getattr(m, "content", "") or ""))
if instr:
instruction_texts.add(instr)
event_type = str(getattr(m, "event_type", "") or "")
candidates: list[str] = []
if event_type == "reasoning":
candidates.append(str(getattr(m, "content", "") or ""))
ep = _safe_json_object(getattr(m, "event_payload", None))
rc = str(ep.get("reasoning_content") or "").strip()
if rc:
candidates.append(rc)
for text in candidates:
instr = _extract_manager_instruction_text(text)
if instr:
instruction_texts.add(instr)
if not instruction_texts:
return msgs
filtered: list[Any] = []