Read history on a thread that has never run as empty - #71
Open
stephschofield wants to merge 1 commit into
Open
Conversation
A thread id is minted before the thread exists — the platform creates it on the first run — so reading history on a conversation nobody has spoken in yet is the normal opening move. The runtime reports the platform's THREAD_NOT_FOUND as a bare 500, which reads as a broken server and buries a stack trace in the log every time somebody opens a new chat. Only a thread the platform does not list is treated as empty. A 500 for a thread that does exist is a real failure and stays a 500: answering it with empty history would tell the browser the conversation is gone and invite it to start over. Wrapped rather than added with handler.use, because Hono matches middleware only against routes declared after it and the handler arrives with its own already registered.
stephschofield
requested review from
MikeRyanDev,
davidmckayv,
guidovizoso and
tylerslaton
as code owners
August 21, 2026 05:19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #72
What
Reading message history on a thread that has never been run returns
500 {"error":"Failed to fetch thread messages"}.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, not an error. The runtime reports the platform's
THREAD_NOT_FOUNDas a bare 500, which reads as a broken server and buries a stack trace in the log each time somebody opens a new chat.Reproduced against a live Intelligence deployment:
d3ff669d…55569917…THREAD_NOT_FOUNDHow
After a GET on
/threads/:threadId/messagesreturns 500, ask the platform whether it lists that thread. Not listed →200 {"messages": []}.Only a thread the platform does not list is treated as empty. A 500 for a thread that does exist is a real failure — an outage, a bad key — and stays a 500, because answering it with empty history would tell the browser the conversation is gone and invite it to start over. Same for a failed listing, or a request with no
agentIdto list against.The middleware wraps the handler rather than being added with
handler.use: Hono matches middleware only against routes declared after it, and the handler arrives with all of its own already registered.Test plan
server/src/copilot.test.tscovers the decision over a stub runtime:agentIdto list againstVerified against a live deployment: minted thread →
{"messages":[]}, existing thread → 200 with history intact.typecheckandbiome checkclean.