[Bug] A plugin appending user/message without message.id permanently bricks the session history #1121
jilian-dsh
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Summary A single malformed user/message event (missing message.id) can permanently block an entire session's history from loading: the session fails with SessionPersistenceCorruptionError ... session event at seq N lacks an identified message. We hit this in a real session (508k events; one bad event at seq 440160).
Root cause — write/load validation asymmetry
Write path: Agent.followup() → send() → inbox.splice() (packages/core/agent-loop) performs no validation of message.id; session.append only checks JSON-serializability. A user/message without id is silently persisted.
Load path: Session.fromRestore() → assertMessageEventShape() (packages/core/session) strictly requires a non-empty message.id. Because the bad event sits inside an already-committed prefix, the whole session refuses to load; the only recovery is manual log surgery.
Reproduction
Any plugin registers a command whose handler calls agent.followup({ role: "user", content: [...], source: { kind: "user" } }) without an id (easy in plain JS — the UserMessage type is not enforced at runtime).
Run the command in a session.
Restart DSH and reopen the session → "history unavailable … lacks an identified message".
Suggested fixes
Validate message.id on the write path (in Agent.followup/send, or in session.append for message events), matching the load-time invariant — turn silent data corruption into a loud, early error.
Optionally, make the load path resilient: skip/quarantine a single malformed message event with a warning instead of refusing the whole log.
Workaround for plugin authors: always build messages with createUserMessage() (from @deepseek-ai/dsh-llm) or include id: crypto.randomUUID().
Environment: DSH 0.1.0-rc.6 (npm), Windows, web profile.
中文摘要:发现 DSH 写入/加载校验不对称的 bug——agent.followup 和 session.append 对消息 id 零校验,而加载历史时严格校验 message.id 非空。插件构造消息漏写 id 会让坏事件落盘,最终锁死整个会话历史(实测:50.8 万事件中仅 1 条坏事件即可导致全部历史无法加载)。建议:① 写入路径补校验(与加载对齐);② 加载路径对单条坏事件容错。插件作者应使用官方 createUserMessage()(自动生成 id)。
All reactions