Repository navigation
fix(runtime): a thread that does not exist yet is not a server error on read - #7430
Conversation
…on read
`GET /threads/:id/{events,messages,state}` wrapped the platform call in one
catch-all, so the platform's typed `THREAD_NOT_FOUND` — 404, category
"not_found", explicitly marked not retryable — became a logged error and a flat
500 "Failed to fetch …".
A thread nobody has spoken in yet is the opening state of EVERY conversation,
and a freshly mounted chat asks for all three. So the runtime produced a server
error on every new chat as a matter of course.
The two halves of the same route already disagreed about this: the in-memory
branch returns `{ events: [] }` for an unknown thread, and has a test saying so
("returns empty events for an unknown threadId via the in-memory runner"). Only
the Intelligence branch called it a failure.
The cost is not the noise, it is that the noise is indistinguishable from a real
fault. Measured while demoing: a genuinely failing run and a normal empty chat
produced the same red error badge, so the badge carried no signal and a real
break went unnoticed twice.
Reads now answer with the empty result the caller can use — `{ events: [] }`,
`{ messages: [] }`, `{ state: null }` — logged at debug rather than error.
Deliberately NOT applied to the mutation paths: renaming, archiving or deleting
a thread that does not exist IS a client error, and 404 is the useful answer
there.
Everything else in those catch blocks now routes through the same status mapping
the memory handlers already had (4xx forwarded, platform 5xx as 502, non-platform
as 500), so a platform outage still fails loudly and is never swallowed into an
empty result — the same mistake pointed the other way. That mapper moves to
`handlers/shared/platform-error.ts` and both handlers share the one copy.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughA shared helper maps platform and non-platform errors for memory handlers and Intelligence thread reads. Thread message, event, and state handlers use the helper for Intelligence-path errors. ChangesIntelligence Handler Error Responses
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to Thread reads for missing conversations now return 404 instead of 500, and rejected runtime credentials (401) map to 502. No merge-blocking risk was identified in the supplied changes. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The implemented change preserves rejection responses and existing identity checks rather than returning successful empty results. No introduced security concern was established. Per-user ownership enforcement for event and state reads remains dependent on the upstream service and was not independently verified. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…-not-500 # Conflicts: # packages/runtime/src/v2/runtime/handlers/intelligence/memories.ts
@copilotkit/a2ui-renderer
@copilotkit/agentcore-runner
@copilotkit/angular
@copilotkit/channels
@copilotkit/channels-core
@copilotkit/channels-discord
@copilotkit/channels-intelligence
@copilotkit/channels-slack
@copilotkit/channels-teams
@copilotkit/channels-telegram
@copilotkit/channels-ui
@copilotkit/channels-whatsapp
@copilotkit/core
@copilotkit/intelligence-langgraph
@copilotkit/intelligence-mastra
@copilotkit/learning
@copilotkit/mcp-apps-renderer
@copilotkit/react-core
@copilotkit/react-native
@copilotkit/react-textarea
@copilotkit/react-ui
@copilotkit/runtime
@copilotkit/runtime-client-gql
@copilotkit/sdk-js
@copilotkit/shared
@copilotkit/sqlite-runner
@copilotkit/voice
@copilotkit/vue
@copilotkit/web-components
@copilotkit/web-inspector
commit: |
|
Size Change: 0 B Total Size: 1.77 MB ℹ️ View Unchanged
|
…n empty result
The platform hides another user's thread behind the same 404 it returns for
a missing one, so the runtime cannot tell "not spoken in yet" from "not
yours". Answering that 404 with `{ messages: [] }` turned a foreign-thread
read into a 200, which the shared access.thread-identity-*-messages
conformance cases reject. Forward the 404 through platformErrorResponse
instead: still not a 500, and the same answer native runtimes give.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A platform 401/403 rejects the runtime's own API key (e.g. after a rotation), which the user and browser cannot fix. Forwarding it told the client the user was unauthorized; map it to 502 like other upstream faults. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ntime key
The platform answers a user denied an action (e.g. a write to read-only
memory) with 403, which the client must see; the shared conformance case
access.memory-read-only-writes broke when 403 became 502. A runtime
credential rejection is 401 ("Bad project key"), so only 401 maps to 502.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The bug
GET /threads/:id/events,/messagesand/statewrap the platform call in one catch-all. The platform's answer for a conversation that has not been spoken in yet is specific and typed — 404, categorynot_found, explicitly not retryable — and the runtime flattens it into a logged error plus a generic 500.A thread with no events is the opening state of every conversation, and a freshly mounted chat asks for all three. So the runtime produces a server error on every new chat, as a matter of course.
Why it is worth fixing
Not the log noise. The noise is indistinguishable from a real fault.
Found while demoing this repo's showcase app: a genuinely failing run and a perfectly normal empty chat produced the same red error badge. The badge had been on all evening, so it carried no signal, and a real break went unnoticed twice — once for about twenty minutes.
The change
The three read catch blocks now route through the status mapping the memory handlers already had: client-actionable 4xx (404, 409, 422, …) forwarded verbatim, platform 5xx as
502, non-platform as500.A fresh thread's read now answers 404, the platform's own typed answer, instead of a generic 500. That mapper moves to
handlers/shared/platform-error.ts, so both handlers share one copy instead of two that would drift.A platform 401 is the exception and also surfaces as
502. It rejects the runtime's own credentials (e.g. a rotated API key,"Bad project key"), not the end user, so forwarding it would tell the browser the user is unauthenticated for a fault only the server can fix. A platform 403 stays forwarded: the platform uses it to deny the user an action (e.g. a write to read-only memory), which the client must see, and the sharedaccess.memory-read-only-writescase asserts it. Because the memory handlers share the mapper, they get the same treatment.Why not an empty result
An earlier revision answered the 404 with
{ events: [] }/{ messages: [] }/{ state: null }. That broke the sharedaccess.thread-identity-*-messagesconformance cases. The platform deliberately answers another user's thread with the same 404 as a missing one, so that a caller cannot learn which threads exist. The runtime cannot tell the two apart, and an empty 200 turned a foreign-thread read into a success. Forwarding the 404 keeps that contract and matches what the native runtimes already return. If the empty-chat noise should go away entirely, the place to do it is the client, which knows it just created the thread.Tests
Read paths forward a platform 404 as 404; a platform 5xx surfaces as 502; a platform 401 surfaces as 502 while a 403 is forwarded; a non-platform throw stays 500.
@copilotkit/runtimetest and check-types: 193 files / 2739 tests passed.run.mjs -- node tools/runtime-conformance/typescript-driver.mjs): 132 cases passed, 0 failed, including bothaccess.thread-identity-*-messagescases.runtime-conformancetest and lint: passed.oxfmtclean;oxlint0 errors.Related
Independent of #7352, but found in the same session — both are cases of the runtime reporting an expected state as a failure.
🤖 Generated with Claude Code
Summary by CodeRabbit