Omit null media in history frames (schema-conformant)

history() wrote "media": null for streaming finals, but the frame
schema says array. The app's HistoryMessage.media was non-nullable, so
deserialization threw and every history page was silently dropped.
Omit the key when media is absent instead.
This commit is contained in:
ARIA committed 2026-08-21 20:56:16 +02:00
1 parent 17bf41a0b9
commit 9a519e3c5a
1 file changed
+8 -5
+8 -5
View File
@@ -207,8 +207,7 @@ class Outbox:
role = payload.get("role")
if role not in ("user", "assistant"):
continue
final.append(
{
msg = {
"cursor": int(r["cursor"]),
"message_id": payload.get("message_id"),
"role": role,
@@ -218,10 +217,15 @@ class Outbox:
"tokens": payload.get("tokens"),
"runtime": payload.get("runtime"),
"ts": payload.get("ts"),
"media": payload.get("media"),
}
)
# Omit ``media`` when absent (schema: array, not null) — a
# ``"media": null`` would break the app's deserialization.
if payload.get("media"):
msg["media"] = payload["media"]
final.append(msg)
elif ftype == "message.stop":
# Streaming finals carry no media (offers are separate
# frames); omit the key (schema: array, not null).
final.append(
{
"cursor": int(r["cursor"]),
@@ -233,7 +237,6 @@ class Outbox:
"tokens": payload.get("tokens"),
"runtime": payload.get("runtime"),
"ts": payload.get("ts"),
"media": None,
}
)
# Deduplicate by message_id (keep the latest occurrence), keep order.