Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/opencode/src/server/instance/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,17 @@ export const SessionRoutes = lazy(() =>
await AppRuntime.runPromise(
Effect.gen(function* () {
const sessions = yield* Session.Service
// Surface the route's declared 404 instead of silently succeeding:
// deleting a part that does not exist is a not-found, not a no-op.
// The check lives in the route, not Session.removePart, because
// removePart is also called internally by the message processor,
// which must stay a tolerant no-op for an already-gone part.
const part = yield* sessions.getPart({
sessionID: params.sessionID,
messageID: params.messageID,
partID: params.partID,
})
if (!part) throw new NotFoundError({ message: `Part not found: ${params.partID}` })
yield* sessions.removePart({
sessionID: params.sessionID,
messageID: params.messageID,
Expand Down
8 changes: 8 additions & 0 deletions packages/opencode/test/server/session-messages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,14 @@ describe("session messages endpoint", () => {
expect(await remove.json()).toBe(true)
expect((await svc.messages({ sessionID: session.id }))[0].parts).toHaveLength(0)

// The route's declared 404 is now real: deleting an already-removed
// part surfaces NotFoundError instead of silently succeeding.
const missing = await app.request(`/session/${session.id}/message/${messageID}/part/${partID}`, {
method: "DELETE",
})
expect(missing.status).toBe(404)
expect((await missing.json()).name).toBe("NotFoundError")

await svc.remove(session.id)
},
}),
Expand Down
Loading