anomalyco / anomalyco/opencode
NotFoundError: Message not found: msg_f95b9........
@jlongster is already working on this.
Since Jul 25, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Describe the bug
Session revert cleanup deletes messages without updating child parentID references, leaving orphaned messages that crash the session view with NotFoundError.
To Reproduce
- Open a project in
opencode web - In an active session, use
/undoto revert to an earlier message - Continue the session (new messages created after revert point)
- Reload the page or reopen the session
- Session fails to load with:
Message not found: msg_XXXXX
Expected behavior
Messages are deleted during revert cleanup without leaving orphaned parentID references. Child messages are either reparented to the nearest surviving ancestor or have their parentID cleared.
Actual behavior
cleanup() in packages/opencode/src/session/revert.ts (lines 100-134) calls sessions.removeMessage() for each message at/after the revert point. Any messages created after the revert that have parentID pointing to a deleted message become orphaned. The API returns 404 when loading these orphaned messages, crashing the session view.
Error
NotFoundError: Message not found: msg_f95b93c2e001CmgY3q2JKDV77E
Environment
- OpenCode version: 1.18.3
- Platform: Linux
Additional context
The orphaned messages can be identified via SQL:
SELECT m.id, json_extract(m.data, '$.parentID') as parent_id
FROM message m
WHERE json_extract(m.data, '$.parentID') IS NOT NULL
AND json_extract(m.data, '$.parentID') != ''
AND NOT EXISTS (
SELECT 1 FROM message m2 WHERE m2.id = json_extract(m.data, '$.parentID')
);
Manual workaround: reparent orphaned messages to the last surviving user message before the revert point.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.