Skip to content

Reading history on a thread that has never run returns 500 #72

Description

@stephschofield

Problem

GET /api/copilotkit/threads/:threadId/messages returns 500 {"error":"Failed to fetch thread messages"} for any thread that has not been run yet.

A thread id is minted before the thread exists — the platform creates it on the first run — so this is the normal opening move for every new conversation. Each time somebody opens a new chat the server answers 500 and writes a stack trace to the log.

Reproduced against a live Intelligence deployment, same endpoint, two ids:

thread state result
d3ff669d… has a prior run 200, history returned
55569917… minted via /api/threads/mint, never run 500

The underlying response from the platform:

{"error":{"code":"THREAD_NOT_FOUND","message":"Thread not found.","category":"not_found","retryable":false}}

The runtime's handleGetThreadMessages catches everything and returns a bare 500, so a 404 meaning "not created yet" is indistinguishable from a real outage.

Expected behavior

A thread the platform does not know about has no history, and should read as empty:

{"messages": []}

A 500 for a thread that does exist must stay a 500. It means an outage or a bad key, and reporting it as empty history would tell the browser the conversation is gone and invite it to start over.

Notes

The frontend already guards with if (response.ok), so there is no visible breakage today — the cost is a 500 and a stack trace on every new chat, and no way to distinguish a missing thread from a broken platform.

Fix in #71.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions