Skip to content

Commit ef3ccc9

Browse files
committed
fix: skip corrupted message/part files instead of crashing session load
A single corrupted JSON file would cause the messages endpoint to return 500, making the entire session unloadable. Now corrupted files are skipped so the rest of the session remains accessible.
1 parent f9ae306 commit ef3ccc9

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

packages/opencode/src/session/message-v2.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -663,18 +663,19 @@ export namespace MessageV2 {
663663
export const stream = fn(Identifier.schema("session"), async function* (sessionID) {
664664
const list = await Array.fromAsync(await Storage.list(["message", sessionID]))
665665
for (let i = list.length - 1; i >= 0; i--) {
666-
yield await get({
666+
const msg = await get({
667667
sessionID,
668668
messageID: list[i][2],
669-
})
669+
}).catch(() => undefined)
670+
if (msg) yield msg
670671
}
671672
})
672673

673674
export const parts = fn(Identifier.schema("message"), async (messageID) => {
674675
const result = [] as MessageV2.Part[]
675676
for (const item of await Storage.list(["part", messageID])) {
676-
const read = await Storage.read<MessageV2.Part>(item)
677-
result.push(read)
677+
const read = await Storage.read<MessageV2.Part>(item).catch(() => undefined)
678+
if (read) result.push(read)
678679
}
679680
result.sort((a, b) => (a.id > b.id ? 1 : -1))
680681
return result

0 commit comments

Comments
 (0)