Skip to content

Conversation

@mudler
Copy link
Owner

@mudler mudler commented Nov 14, 2025

Description

This PR migrates to echo. One of the main reason to migrate away from go-fiber/fasthttp is the lack of support of detecting properly client cancellation valyala/fasthttp#468 (comment), which would have the unwanted effect of booking resources for AI inferencing even if clients disconnect.

I've tried several workarounds in #7187 , but none of these was reliable ( had to revert in #7266 ). Finally, I've came to the conclusion that the effort involved in maintaining go-fiber (which is based over fasthttp) is higher overall for the little gain that we would have (the real computation is offloaded, so we don't perform high-intensive tasks in the golang layer) by using it.

Aside from migrating away, this PR brings back support of cancellation of client requests, which propagates back cancellation of request to the grpc backend.

Notes for Reviewers

Signed commits

  • Yes, I signed my commits.

@netlify
Copy link

netlify bot commented Nov 14, 2025

Deploy Preview for localai ready!

Name Link
🔨 Latest commit 4c7c4b0
🔍 Latest deploy log https://app.netlify.com/projects/localai/deploys/691797af8bbede000866d497
😎 Deploy Preview https://deploy-preview-7270--localai.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.


// Handle 404 errors with HTML rendering when appropriate
if code == http.StatusNotFound {
notFoundHandler(c)

Check warning

Code scanning / gosec

Errors unhandled Warning

Errors unhandled
Comment on lines +69 to +71
c.JSON(code, schema.ErrorResponse{
Error: &schema.APIError{Message: err.Error(), Code: code},
})

Check warning

Code scanning / gosec

Errors unhandled Warning

Errors unhandled
if errors.As(err, &he) {
code = he.Code
}
c.NoContent(code)

Check warning

Code scanning / gosec

Errors unhandled Warning

Errors unhandled
return metricsService.Shutdown()
e.Use(localai.LocalAIMetricsAPIMiddleware(metricsService))
e.Server.RegisterOnShutdown(func() {
metricsService.Shutdown()

Check warning

Code scanning / gosec

Errors unhandled Warning

Errors unhandled
if body := c.Body(); len(body) > 0 {
body := make([]byte, 0)
if c.Request().Body != nil {
c.Request().Body.Read(body)

Check warning

Code scanning / gosec

Errors unhandled Warning

Errors unhandled
}

// Decode each request's message content
imgIndex, vidIndex, audioIndex := 0, 0, 0

Check warning

Code scanning / gosec

Errors unhandled Warning

Errors unhandled
_, err := tmpl.New(templateName).Parse(string(data))
if err != nil {
// If parsing fails, try parsing without explicit name (for templates with {{define}})
tmpl.Parse(string(data))

Check warning

Code scanning / gosec

Errors unhandled Warning

Errors unhandled
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
@mudler mudler force-pushed the echo branch 4 times, most recently from f773750 to 58a0b6c Compare November 14, 2025 16:44
app := echo.New()
// Set up a simple renderer for the test
app.Renderer = &testRenderer{}
app.POST("/import-model", ImportModelEndpoint(modelConfigLoader, applicationConfig))
Copy link
Collaborator

Choose a reason for hiding this comment

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

changed PUT to POST, I'm not sure if that is deliberate?

Copy link
Owner Author

Choose a reason for hiding this comment

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

not really, good catch! but it's just used in tests, shouldn't make any difference 🤷

@mudler mudler force-pushed the echo branch 2 times, most recently from 2d1e3ab to a7c4e44 Compare November 14, 2025 20:55
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
@mudler mudler changed the title feat: migrate to echo feat: migrate to echo and enable cancellation of non-streaming requests Nov 14, 2025
@mudler mudler added enhancement New feature or request and removed dependencies labels Nov 14, 2025
@mudler mudler merged commit 1cdcaf0 into master Nov 14, 2025
32 checks passed
@mudler mudler deleted the echo branch November 14, 2025 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants