Skip to content

fix: use active interrupt from thread instead of saving to global state - #2031

Merged
ranst91 merged 3 commits into
mainfrom
fix/remove-active-interrupt-global-state
Jun 20, 2025
Merged

ranst91 merged 3 commits into
mainfrom
fix/remove-active-interrupt-global-state

Conversation

@ranst91

@ranst91 ranst91 commented Jun 20, 2025 •

Copy link
Copy Markdown
Contributor

See #2026 for discussions & final resolution

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of interrupt events during streaming, ensuring more reliable and predictable behavior when interrupts occur.
  • Refactor
    • Streamlined interrupt management for better performance and maintainability, resulting in a more robust user experience during thread interactions.

@vercel

vercel Bot commented Jun 20, 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 Jun 20, 2025 5:44pm
demo-viewer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 20, 2025 5:44pm
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 20, 2025 5:44pm
examples-coagents-ai-travel-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 20, 2025 5:44pm
examples-coagents-research-canvas-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 20, 2025 5:44pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
examples-coagents-ai-researcher-ui ⬜️ Ignored (Inspect) Visit Preview Jun 20, 2025 5:44pm

@coderabbitai

coderabbitai Bot commented Jun 20, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

The changes refactor interrupt event handling in the streamEvents function. The global interrupt tracking variable is removed, and interrupts are now managed by directly inspecting the thread state. A new helper function, emitInterrupt, centralizes interrupt event emission logic, and the streaming flow is updated to accommodate these changes.

Changes

File(s) Change Summary
.../runtime/src/lib/runtime/remote-lg-action.ts Refactored interrupt handling in streamEvents; removed global interrupt variable; added emitInterrupt helper; updated streaming logic to check thread state for interrupts and emit events accordingly.
.changeset/ninety-items-scream.md Added patch update note describing the interrupt handling fix in @copilotkit/runtime.

Sequence Diagram(s)

sequenceDiagram
    participant Controller
    participant streamEvents
    participant ThreadState
    participant emitInterrupt

    Controller->>streamEvents: Start streaming with args
    streamEvents->>ThreadState: Inspect tasks[0]?.interrupts
    alt Outstanding interrupts exist
        streamEvents->>emitInterrupt: Emit interrupt event(s)
        emitInterrupt-->>streamEvents: Event emission complete
        streamEvents-->>Controller: Return early (no further streaming)
    else No interrupts
        streamEvents->>Controller: Proceed with streaming run
    end
Loading

📜 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 d4753f0 and 4e643a1.

📒 Files selected for processing (1)
  • CopilotKit/.changeset/ninety-items-scream.md (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test (20.x)
  • GitHub Check: Test (18.x)
🔇 Additional comments (1)
CopilotKit/.changeset/ninety-items-scream.md (1)

1-6: Changeset description LGTM
The patch version bump and concise summary accurately reflect the interrupt-handling fix and conform to the repository’s changeset conventions.


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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
CopilotKit/packages/runtime/src/lib/runtime/remote-lg-action.ts (1)

899-919: Well-designed interrupt emission helper.

The emitInterrupt function effectively centralizes interrupt handling logic with proper support for both CopilotKit-specific and regular interrupts. The conditional JSON stringification for non-string values is handled correctly.

Consider adding JSDoc documentation to describe the function's purpose and the two interrupt types it handles:

+/**
+ * Emits interrupt events to the stream.
+ * Handles two types of interrupts:
+ * 1. CopilotKit interrupts with __copilotkit_interrupt_value__ property
+ * 2. Regular interrupts
+ */
 function emitInterrupt(interruptValue: any, emit: (data: string) => void) {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5bdce77 and d4753f0.

📒 Files selected for processing (1)
  • CopilotKit/packages/runtime/src/lib/runtime/remote-lg-action.ts (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (15)
  • GitHub Check: Build Images (coagents-qa-text, ui)
  • GitHub Check: Build Images (coagents-qa-native, agent, js, local-deps)
  • GitHub Check: Build Images (next-openai, next-openai)
  • GitHub Check: Build Images (coagents-qa-text, agent, python, local-deps)
  • 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, js, local-deps)
  • GitHub Check: Build Images (coagents-qa-native, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-routing, agent, js, local-deps)
  • GitHub Check: Build Images (coagents-routing, ui)
  • GitHub Check: Build Images (coagents-qa-text, agent, js, local-deps)
  • GitHub Check: Build Images (coagents-research-canvas, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-research-canvas, ui)
  • GitHub Check: Test (18.x)
  • GitHub Check: Test (20.x)
🔇 Additional comments (5)
CopilotKit/packages/runtime/src/lib/runtime/remote-lg-action.ts (5)

5-7: LGTM!

The addition of Interrupt and ThreadState imports is appropriate for the interrupt handling refactoring.


191-191: Good type safety improvement.

Explicitly typing agentState as ThreadState improves code maintainability and helps catch type errors at compile time.


314-327: Excellent interrupt resolution logic.

The implementation correctly handles two interrupt resolution scenarios:

  1. Auto-resolution via upcoming messages when no meta event exists
  2. Immediate emission and early return when meta event is present

The early return prevents unnecessary streaming operations when interrupts need resolution first.


360-360: Good refactoring to use the centralized helper.

Replacing inline interrupt emission with the emitInterrupt helper improves code maintainability and ensures consistent interrupt handling.


227-230: ```shell
#!/bin/bash

Refined search to locate ThreadState and its tasks property in TS files

Search for any mention of ThreadState in .ts files

rg -n "ThreadState" -g "*.ts"

Specifically look for interface or type definitions

rg -n -e "interface ThreadState" -g ".ts"
rg -n -e "type ThreadState" -g "
.ts"

Search for where tasks is declared on any State type

rg -n -e "tasks\s*:" -g "*.ts"


</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

@github-actions

github-actions Bot commented Jun 20, 2025 •

Copy link
Copy Markdown
Contributor

Preview environments destroyed for this pull request.

@github-actions

github-actions Bot commented Jun 20, 2025 •

Copy link
Copy Markdown
Contributor

Test Results

Status: ✅ Passed (View Run)

Commit: 0a5a75b

Duration: 299.1s

Total Tests: 20

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 -
Google Generative AI chromium ✅ PASSED -
LangChain (OpenAI) chromium ✅ PASSED -
LangChain (Anthropic) chromium ✅ PASSED -
LangChain (Gemini) chromium ✅ PASSED -
Groq chromium ✅ PASSED -

@changesets-bot-copilotkit

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 864cf60

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

@the-waste-land

Copy link
Copy Markdown

@ranst91 Could you please release a version to fix this issue? Thank you!

@ranst91

ranst91 commented Jun 23, 2025

Copy link
Copy Markdown
Contributor Author

@the-waste-land There would probably be a release today.
Meanwhile, you can already use the latest release candidate, which includes the fix:
1.9.2-next.8

This branch was successfully deployed

5 active deployments
Preview – docs — 864cf600 Deployed Jun 20, 2025 by vercel[bot]
Preview – examples-coagents-research-canvas-ui — 864cf600 Deployed Jun 20, 2025 by vercel[bot]
Preview – demo-viewer — 864cf600 Deployed Jun 20, 2025 by vercel[bot]
Preview – examples-coagents-ai-travel-app — 864cf600 Deployed Jun 20, 2025 by vercel[bot]
Preview – copilotkit-feature-viewer — 864cf600 Deployed Jun 20, 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.

2 participants