#2589·mempalace

Codex JSONL: _try_codex_jsonl doesn't recognize item_completed/UserMessage/AgentMessage shape, silently dumps raw file as one conversation

Author: mackelitoCreated Sep 24, 2026Updated Sep 24, 2026

What happened?

_try_codex_jsonl() in mempalace/normalize.py only recognizes the legacy Codex CLI rollout shape:

json
{"type": "event_msg", "payload": {"type": "user_message", "message": "..."}}
{"type": "event_msg", "payload": {"type": "agent_message", "message": "..."}}

Current Codex CLI (0.147+) emits conversation turns under a different, now-canonical shape instead:

json
{"type": "event_msg", "payload": {"type": "item_completed", "item": {"type": "UserMessage", "content": [{"type": "text", "text": "..."}]}}}
{"type": "event_msg", "payload": {"type": "item_completed", "item": {"type": "AgentMessage", "content": [{"type": "Text", "text": "..."}]}}}

(Confirmed against openai/codex source: ItemCompletedEvent / TurnItem::UserMessage / TurnItem::AgentMessage. Third-party tools like codex-sessions-manager and apache/maka have already shipped compatibility patches for this same schema change.)

Because payload.type is never "user_message"/"agent_message" in these rollouts, _try_codex_jsonl() finds zero messages and returns None. Every other parser in _try_normalize_json_split also fails (it's JSONL, not a single JSON document), so normalize_conversations() falls through to its last line and returns the entire raw rollout file, unparsed, as one "conversation."

chunk_exchanges() then finds no > markers and falls back to paragraph/line-group chunking on the raw JSON blob, slicing the whole file (including tool-call payloads, reasoning traces, token-usage records, etc.) into ~800-char drawers.

Impact

On a 185 MB real-world session file, this produced 210,378 drawers from a single conversation — almost entirely raw JSON noise, not actual dialogue. Across a ~9k-file sessions wing this pattern accounted for ~970k of ~988k total vectors in the palace (98%+), inflating the on-disk index to multiple GB and making every mine of a growing session file (each Stop-hook fire) re-purge and re-chunk the entire raw blob from scratch, since _is_unchanged_since_last_mine treats the still-growing file as changed every time.

Reproduction

python
from mempalace.normalize import normalize_conversations

# Rollout with real turns recorded only as item_completed/UserMessage/AgentMessage
result = normalize_conversations("path/to/rollout-*.jsonl")
# result == [<entire raw file content>] instead of a clean `> user\nassistant` transcript

Minimal fixture line shapes that reproduce it:

json
{"type": "session_meta", "payload": {}}
{"type": "event_msg", "payload": {"type": "item_completed", "item": {"type": "UserMessage", "id": "...", "content": [{"type": "text", "text": "hello"}]}}}
{"type": "event_msg", "payload": {"type": "item_completed", "item": {"type": "Reasoning", "summary_text": [], "raw_content": []}}}
{"type": "event_msg", "payload": {"type": "item_completed", "item": {"type": "AgentMessage", "id": "...", "content": [{"type": "Text", "text": "hi there"}], "phase": "commentary"}}}

Expected behavior

_try_codex_jsonl() should also extract turns from event_msg.payload.type == "item_completed" records where item.type == "UserMessage" (text from item.content[].text, block type: "text") or item.type == "AgentMessage" (text from item.content[].text, block type: "Text"), skipping other item.type values (Reasoning, CommandExecution, etc.) — mirroring the existing response_item skip rationale, but for the new canonical event shape.

Ideally both the old (user_message/agent_message) and new (item_completed/UserMessage/AgentMessage) shapes should be supported side by side, since older rollout files on disk still use the legacy shape.

More generally, given how easily this can happen again, it may be worth having normalize_conversations() refuse to fall back to "return the raw file as-is" for a recognized-but-unparseable JSONL source (.codex/sessions/...), rather than silently defeating exchange chunking.

Environment

  • MemPalace version: 3.9.0 (confirmed same _try_codex_jsonl on current main/3.10.0 — not yet fixed)
  • Codex CLI: session schema is from a build using the item_completed/UserMessage/AgentMessage canonical shape (Codex CLI 0.147+ era)
  • OS: macOS