Skip to content

fix: connect streaming errors to runtime onError handler - #2143

Merged
suhasdeshpande merged 4 commits into
mainfrom
suhas/catch-on-erro
Jul 11, 2025
Merged

suhasdeshpande merged 4 commits into
mainfrom
suhas/catch-on-erro

Conversation

@suhasdeshpande

@suhasdeshpande suhasdeshpande commented Jul 11, 2025 •

Copy link
Copy Markdown
Contributor
  • Modified RuntimeEventSource to accept error handler and context
  • Updated processRuntimeRequest to pass runtime error handler to event source
  • Updated processAgentRequest to pass error handler for agent requests
  • Streaming errors now properly route to onError handler while preserving original streaming behavior
  • Fixes issue where OpenAI authentication errors were not reaching onError handler

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of streaming errors by ensuring they are properly routed to the runtime’s error handler, resulting in more reliable error reporting during streaming operations.
  • Chores

    • Removed request logging functionality for a cleaner runtime experience.

@vercel

vercel Bot commented Jul 11, 2025 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
copilotkit-feature-viewer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 11, 2025 5:11pm
demo-viewer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 11, 2025 5:11pm
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 11, 2025 5:11pm
examples-coagents-ai-travel-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 11, 2025 5:11pm
examples-coagents-research-canvas-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 11, 2025 5:11pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
examples-coagents-ai-researcher-ui ⬜️ Ignored (Inspect) Visit Preview Jul 11, 2025 5:11pm

@coderabbitai

coderabbitai Bot commented Jul 11, 2025 •

Copy link
Copy Markdown
Contributor

"""

Walkthrough

This update introduces structured, contextual error handling for streaming operations in the @copilotkit/runtime package. The RuntimeEventSource now accepts an asynchronous error handler and context, ensuring that errors during runtime and agent requests are routed to the runtime's error management system with enriched context.

Changes

File(s) Change Summary
CopilotKit/.changeset/long-planets-change.md, CopilotKit/.changeset/afraid-seahorses-warn.md Adds changesets describing patch updates that fix streaming error handling by connecting errors to the runtime's onError handler and removing request logging.
CopilotKit/packages/runtime/src/lib/runtime/copilot-runtime.ts Updates internal methods to instantiate RuntimeEventSource with an error handler and detailed context for structured error reporting during runtime and agent requests.
CopilotKit/packages/runtime/src/service-adapters/events.ts Extends RuntimeEventSource to accept an async error handler and context, invoking it on streaming and action execution errors with error handling for the handler itself.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant CopilotRuntime
    participant RuntimeEventSource
    participant ErrorHandler

    Client->>CopilotRuntime: processRuntimeRequest/processAgentRequest
    CopilotRuntime->>RuntimeEventSource: Instantiate (with errorHandler, errorContext)
    RuntimeEventSource->>RuntimeEventSource: Process events/stream
    RuntimeEventSource-->>ErrorHandler: On error, invoke errorHandler(error, context)
    ErrorHandler-->>CopilotRuntime: Log/handle error with context
Loading

Possibly related PRs

Suggested reviewers

  • mme
  • ranst91
    """

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 46b4e42 and e22b794.

📒 Files selected for processing (4)
  • CopilotKit/.changeset/afraid-seahorses-warn.md (1 hunks)
  • CopilotKit/.changeset/long-planets-change.md (1 hunks)
  • CopilotKit/packages/runtime/src/lib/runtime/copilot-runtime.ts (2 hunks)
  • CopilotKit/packages/runtime/src/service-adapters/events.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • CopilotKit/.changeset/afraid-seahorses-warn.md
  • CopilotKit/.changeset/long-planets-change.md
  • CopilotKit/packages/runtime/src/lib/runtime/copilot-runtime.ts
  • CopilotKit/packages/runtime/src/service-adapters/events.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: Build Images (coagents-routing, ui)
  • GitHub Check: Build Images (coagents-qa-native, agent, python, local-deps)
  • GitHub Check: Build Images (next-openai, next-openai)
  • GitHub Check: Build Images (coagents-qa-text, ui)
  • GitHub Check: Build Images (coagents-qa-text, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-research-canvas, ui)
  • GitHub Check: Build Images (coagents-qa-native, ui)
  • GitHub Check: Build Images (coagents-routing, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-research-canvas, agent, python, local-deps)
  • GitHub Check: Test (18.x)
  • GitHub Check: Test (20.x)
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

suhasdeshpande and others added 4 commits July 11, 2025 09:35
- Modified RuntimeEventSource to accept error handler and context
- Updated processRuntimeRequest to pass runtime error handler to event source
- Updated processAgentRequest to pass error handler for agent requests
- Streaming errors now properly route to onError handler while preserving original streaming behavior
- Fixes issue where OpenAI authentication errors were not reaching onError handler
@changesets-bot-copilotkit

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e22b794

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@copilotkit/runtime Patch
@copilotkit/runtime-client-gql Patch
@copilotkit/react-core Patch
@copilotkit/react-textarea Patch
@copilotkit/react-ui Patch
@copilotkit/sdk-js Patch
@copilotkit/shared Patch

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Jul 11, 2025 •

Copy link
Copy Markdown
Contributor

Preview environments destroyed for this pull request.

@github-actions

github-actions Bot commented Jul 11, 2025 •

Copy link
Copy Markdown
Contributor

Test Results

Status: ✅ Passed (View Run)

Commit: a9c7ee2

Duration: 295.2s

Total Tests: 33

Pass Rate: 100.0%

Failed Tests: 0

🔍 Detailed Results

coagents-research-canvas

CoAgents Research Canvas (UI) - Local Depenencies

Model Browser Status Video
OpenAI chromium ✅ PASSED -
Anthropic chromium ✅ PASSED -
CrewAI chromium ✅ PASSED -

coagents-qa-native

CoAgents QA Native (UI) - Local

Model Browser Status Video
OpenAI chromium ✅ PASSED -
Anthropic chromium ✅ PASSED -

coagents-qa-text

CoAgents QA Text (UI) - Local

Model Browser Status Video
OpenAI chromium ✅ PASSED -
Anthropic chromium ✅ PASSED -
OpenAI (LGC Python) chromium ✅ PASSED -
Anthropic (LGC Python) chromium ✅ PASSED -
OpenAI (LGC JS) chromium ✅ PASSED -
Anthropic (LGC JS) chromium ✅ PASSED -

coagents-routing

CoAgents Routing (UI) - Local

Model Browser Status Video
OpenAI chromium ✅ PASSED -
Anthropic chromium ✅ PASSED -

next-openai

Next OpenAI - Self Hosted

Model Browser Status Video
OpenAI chromium ✅ PASSED -
Anthropic chromium ✅ PASSED -
LangChain (OpenAI) chromium ✅ PASSED -
Groq chromium ✅ PASSED -

@suhasdeshpande
suhasdeshpande merged commit f3f0181 into main Jul 11, 2025
@suhasdeshpande
suhasdeshpande deleted the suhas/catch-on-erro branch July 11, 2025 17:25
johannhartmann pushed a commit to johannhartmann/CopilotKit that referenced this pull request Oct 31, 2025
BenTaylorDev added a commit that referenced this pull request Aug 12, 2026
## Summary

`CopilotRuntime` exposes an `onError` callback, but the v1-to-v2
delegation drops it before server request processing. Runtime failures
therefore can't provide the incoming request headers that applications
use to correlate errors with a user or tenant.

## Root cause

The legacy constructor retains the callback type, while delegated
runtime options omit it. Common, SSE, and Intelligence handlers consume
failures inside their own boundaries, before a generic endpoint hook can
reconstruct the legacy event.

## Changes

- Add one internal runtime reporter that snapshots incoming Fetch
request headers.
- Attach the configured legacy callback to the delegated runtime
instance.
- Route common, SSE, and Intelligence agent-run failures, including
standard `RUN_ERROR` events, through that reporter exactly once.
- Redact sensitive request headers (authorization, proxy-authorization,
cookie, set-cookie, x-api-key, api-key, and the CopilotKit public-key
header) before they reach the `onError` event.
- Preserve responses, stream close behavior, telemetry, cleanup,
logging, endpoint hooks, and callback isolation.
- Add production-path regressions.

## Compatibility

The existing `CopilotErrorEvent` type and optional
`context.request.headers` field remain unchanged. Header names and
values come from the failing request's Fetch `Headers` object, with
sensitive credentials stripped before the event is emitted. The callback
receives a fresh record, so mutation cannot alter the request or a later
event.

## Out of scope

React provider propagation, Chat, CopilotMessages, the deprecated
runtime-client hook, redaction policy, HTTP response exposure, v2
endpoint-hook semantics, and non-agent runtime routes remain outside
this slice.

## Related PRs and Issues

Addresses #2716.

Scope follows
#2716 (comment).
Runtime error-routing precedent:
#2143.

## Test plan

- [x] Runtime error regression and reporter tests, 12 + 4 tests passed.
Covers public routing, sanitized header propagation with credential
redaction, callback rejection containment, snapshots, mutation
isolation, and malformed requests.
- [x] SSE and Intelligence telemetry tests, 7 + 14 tests passed. Covers
agent-run failures, `RUN_ERROR`, setup boundaries, exact-once reporting,
telemetry, cleanup, and response preservation.
- [x] Runtime preservation suites, 57 + 129 + 56 tests passed. Existing
request, endpoint-hook, and runtime-library behavior remains intact.
- [x] Typecheck, formatting, and lint passed on changed runtime files;
lint reported four pre-existing warnings.
- [ ] CI green (`static / quality`, `test / unit` on Node 20/22/24).

This branch was successfully deployed

5 active deployments
Preview – copilotkit-feature-viewer — e22b794d Deployed Jul 11, 2025 by vercel[bot]
Preview – examples-coagents-research-canvas-ui — e22b794d Deployed Jul 11, 2025 by vercel[bot]
Preview – demo-viewer — e22b794d Deployed Jul 11, 2025 by vercel[bot]
Preview – docs — e22b794d Deployed Jul 11, 2025 by vercel[bot]
Preview – examples-coagents-ai-travel-app — e22b794d Deployed Jul 11, 2025 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant