Skip to content

Conversation

FalcoSuessgott
Copy link
Contributor

This PR introduces actually cancelling the root context when receiving an OS signal such as CTRL+C so that the context is cancelled throughout the kagent CLI

@Copilot Copilot AI review requested due to automatic review settings August 26, 2025 02:01
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds proper signal handling to the kagent CLI to cancel the root context when receiving OS signals like CTRL+C or SIGTERM. This ensures graceful shutdown throughout the application when users interrupt the process.

  • Adds signal handling for OS interrupt signals (CTRL+C, SIGINT, SIGTERM)
  • Implements context cancellation when signals are received
  • Adds error message output when the application exits with an error

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

fmt.Fprintf(os.Stderr, "kagent aborted.\n")
fmt.Fprintf(os.Stderr, "Exiting.\n")

cancel()
Copy link
Preview

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

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

The cancel() function is called in a goroutine without any synchronization mechanism. This could lead to a race condition where the main goroutine exits before the signal handler completes, potentially causing the process to terminate before cleanup is finished. Consider using sync.WaitGroup or another synchronization mechanism to ensure proper cleanup.

Copilot uses AI. Check for mistakes.

Signed-off-by: Tom Morelly <tom.morelly@cba.com.au>
@FalcoSuessgott
Copy link
Contributor Author

FalcoSuessgott commented Aug 26, 2025

I believe test-e2e fails because the job does not have access to secrets when triggered from a fork. Adding something like

on:
  pull_request_target:

should fix it

@EItanya
Copy link
Contributor

EItanya commented Aug 27, 2025

I believe test-e2e fails because the job does not have access to secrets when triggered from a fork. Adding something like

on:
  pull_request_target:

should fix it

We originally thought that, but that doesn't work as expected. We are going to mock those calls in the future.

@EItanya EItanya merged commit 1dfcf59 into kagent-dev:main Aug 27, 2025
13 of 14 checks passed
yanivmn pushed a commit to yanivmn/kagent that referenced this pull request Aug 28, 2025
…-dev#810)

This PR introduces actually cancelling the root context when receiving
an OS signal such as CTRL+C so that the context is cancelled throughout
the `kagent` CLI

Signed-off-by: Tom Morelly <tom.morelly@cba.com.au>
Co-authored-by: Tom Morelly <tom.morelly@cba.com.au>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants