Skip to content

Implement router#51

Merged
volcano-sh-bot merged 6 commits intovolcano-sh:mainfrom
VanderChen:frontend
Dec 15, 2025
Merged

Implement router#51
volcano-sh-bot merged 6 commits intovolcano-sh:mainfrom
VanderChen:frontend

Conversation

@VanderChen
Copy link
Copy Markdown
Contributor

No description provided.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @VanderChen, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a dedicated router component to efficiently manage and direct incoming HTTP requests to the appropriate sandbox instances. It establishes a clear separation of concerns, offloading routing logic from other services and integrating with Redis for session state management. The changes include a new Go application for the router, comprehensive design documentation, and updates to build and deployment scripts to support this new service. This enhancement aims to improve the system's scalability, performance, and maintainability by centralizing request routing and session handling.

Highlights

  • New Router Component: Introduced a new agentcube-router component responsible for receiving user HTTP requests and forwarding them to the corresponding sandboxes, focusing on high-performance routing and session integration.
  • Comprehensive Router Design Document: Added a detailed design document (docs/proposal/router-design.md) outlining the architecture, request routing flow, session management, supported request types, error handling, performance metrics, and deployment strategies for the new router.
  • Build and Deployment Configuration Updates: Modified the Makefile and Kubernetes deployment files (k8s/agentcube-router.yaml) to build, run, install, and deploy the new agentcube-router instead of the previous agentcube-apiserver.
  • Session Management with Redis Integration: Implemented a SessionManager that leverages Redis for tracking sandbox sessions and interacts with a workload manager to create new sandboxes when a session ID is not provided.
  • Concurrency Control and Request Handling: The router includes a concurrency limiting middleware and uses gin-gonic/gin for robust HTTP request handling, including health checks, agent invocation, and code interpreter invocation, with optimized HTTP transport settings.
  • Annotation Key Update: Updated the last-activity-time annotation key to agentcube.volcano.sh/last-activity in pkg/agentd/agentd_test.go for consistency.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new router component responsible for routing requests to sandboxes. The implementation includes a new binary, configuration, HTTP handlers, and a session manager for interacting with the workload manager and Redis. The changes also involve renaming the old agentcube-apiserver to agentcube-router in Makefiles and Kubernetes manifests. My review identifies several areas for improvement, focusing on performance, reliability, and maintainability. I've found a critical performance issue related to http.Transport creation, high-severity issues with configuration management and lack of timeouts in HTTP clients, and incorrect graceful shutdown logic. I have also provided suggestions for refactoring to reduce code duplication and improve test coverage.

@VanderChen VanderChen force-pushed the frontend branch 2 times, most recently from 893f0bc to 6fc973a Compare December 3, 2025 01:54
@tjucoder
Copy link
Copy Markdown
Contributor

tjucoder commented Dec 3, 2025

ping @hzxuzhonghu

@VanderChen VanderChen force-pushed the frontend branch 4 times, most recently from 60be8ae to 2e97df2 Compare December 9, 2025 01:19
@hzxuzhonghu
Copy link
Copy Markdown
Member

/ok-to-test

Copy link
Copy Markdown
Contributor

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 implements a router submodule that handles HTTP request routing and forwarding to sandbox instances. The router acts as an entry point for agent runtime and code interpreter invocations, managing sessions through a SessionManager interface and forwarding requests to appropriate sandbox endpoints.

Key changes:

  • Implements SessionManager for sandbox session management and creation
  • Adds router server with HTTP handlers for health checks and invocation forwarding
  • Updates Kubernetes deployment configurations to support the router component

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/router/session_manager.go Implements SessionManager interface for retrieving/creating sandbox sessions
pkg/router/session_manager_test.go Comprehensive test coverage for session management functionality
pkg/router/server.go Router server implementation with concurrency control and HTTP transport pooling
pkg/router/server_test.go Tests for server initialization, configuration, and lifecycle
pkg/router/handlers.go HTTP request handlers for health checks and request forwarding to sandboxes
pkg/router/handlers_test.go Tests for HTTP handlers including health checks and invocation routing
pkg/router/config.go Configuration structure for router server
cmd/router/main.go Router server entry point with command-line flag handling
k8s/agentcube-apiserver.yaml Updated Kubernetes deployment to reflect router component naming and RBAC
Dockerfile.router Multi-stage Docker build configuration for router
Makefile Updated build targets to include router binary
docs/proposal/router-design.md Comprehensive design document for router architecture
pkg/workloadmanager/server.go Import statement formatting adjustment
pkg/workloadmanager/handlers.go Import statement reordering
pkg/workloadmanager/garbage_collection.go Import statement reordering
go.mod Moved k8s.io/utils from indirect to direct dependency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@tjucoder tjucoder left a comment

Choose a reason for hiding this comment

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

view

VanderChen and others added 5 commits December 15, 2025 02:25
Signed-off-by: VanderChen <vanderchen@outlook.com>
Signed-off-by: LeslieKuo <676365950@qq.com>
Signed-off-by: LeslieKuo <676365950@qq.com>
Signed-off-by: VanderChen <vanderchen@outlook.com>
Signed-off-by: VanderChen <vanderchen@outlook.com>
@VanderChen
Copy link
Copy Markdown
Contributor Author

@hzxuzhonghu @tjucoder all comments fixed.

Signed-off-by: VanderChen <vanderchen@outlook.com>
Copy link
Copy Markdown
Member

@hzxuzhonghu hzxuzhonghu left a comment

Choose a reason for hiding this comment

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

/lgtm

@volcano-sh-bot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

Approval requirements bypassed by manually added approval.

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@volcano-sh-bot volcano-sh-bot merged commit eceb3bd into volcano-sh:main Dec 15, 2025
5 checks passed

1. **High-Performance Routing**: Fast routing to corresponding sandbox based on session-id
2. **Session Integration**: Seamless collaboration with SessionManager, supporting dynamic sandbox creation
3. **Long Connection Support**: Support for long-running requests such as code execution and file operations
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.

Is it more appropriate to translate ‘Long Connection Support’ as ‘Persistent Connection Support’?

namespace := c.Param("namespace")
name := c.Param("name")
path := c.Param("path")
s.handleInvoke(c, namespace, name, path, "AgentRuntime")
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.

It is preferable to define "AgentRuntime" and "CodeInterpreter" as type-representing constants.

log.Printf("%s invoke request: namespace=%s, name=%s, path=%s", kind, namespace, name, path)

// Extract session ID from header
sessionID := c.GetHeader("x-agentcube-session-id")
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.

Check whether the sessionID field is null.


// Get sandbox info from session manager
sandbox, err := s.sessionManager.GetSandboxBySession(c.Request.Context(), sessionID, namespace, name, kind)
if err != nil {
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.

Also check that the sandbox variable is returned as expected.

// GetSandboxBySession returns the sandbox associated with the given sessionID.
// When sessionID is empty, it creates a new sandbox by calling the external API.
// When sessionID is not empty, it queries Redis for the sandbox.
func (m *manager) GetSandboxBySession(ctx context.Context, sessionID string, namespace string, name string, kind string) (*types.SandboxRedis, error) {
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.

Is it more appropriate to modify the function name from GetSandboxBySession to GetorCreateSandboxBySessionID?

default:
return nil, fmt.Errorf("unsupported kind: %s", kind)
}

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.

    var kindToEndpointPath = map[string]string{
	    types.AgentRuntimeKind:    "/v1/agent-runtime",
	    types.CodeInterpreterKind: "/v1/code-interpreter",
    }

	path, ok := kindToEndpointPath[kind]
	if !ok {
		return "", fmt.Errorf("unsupported kind: %s", kind)
	}
	endpoint := m.workloadMgrURL + path

Suggest adjusting the code style to the above format to improve extensibility


## 1. Overview

Router apiserver is responsible for receiving user HTTP requests and forwarding them to the corresponding Sandbox. Router focuses on high-performance request routing, while session and sandbox management is handled by SessionManager.
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.

Router APIServer is responsible for receiving user HTTP requests and forwarding them to the corresponding Sandbox. As core modules embedded within the Router APIServer, Router focuses on high-performance request routing, while session and sandbox management are handled by Sandbox Manager.

// Extract endpoint from sandbox - find matching entry point by path
var endpoint string
for _, ep := range sandbox.EntryPoints {
if strings.HasPrefix(path, ep.Path) {
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.

The current path resolution using a simple Prefix Match can lead to incorrect routing when less specific paths appear before more specific ones. We must switch to a Longest Prefix Match (LPM) approach to guarantee the correct and most specific endpoint is selected for request forwarding.

// Only add protocol if not already present
if ep.Protocol != "" && !strings.Contains(ep.Endpoint, "://") {
endpoint = strings.ToLower(ep.Protocol) + "://" + ep.Endpoint
} else {
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.

A potential logic error could arise when ep.protocol has an empty value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants