Skip to content

Conversation

@Sayan-
Copy link
Contributor

@Sayan- Sayan- commented Oct 21, 2025

Overview

A number of workloads depend on scale to zero and we've noticed some issues with it. Introducing a few changes:

  1. Add a DebouncedController that'll only write to the file when we actually need to
  2. Remove per-method Disable -> Enable in favor of a middleware that'll apply for all methods
  3. Add tests

Testing

Added units


Note

Introduce a debounced scale-to-zero controller with request middleware, replace scattered disable/enable calls, and harden recorder/devtools handling with context-safe enables plus unit tests.

  • Scale-to-Zero:
    • Add DebouncedController to coalesce Disable/Enable calls and track active holders (server/lib/scaletozero/scaletozero.go).
    • Add HTTP Middleware to auto-disable at request start and re-enable after completion (server/lib/scaletozero/middleware.go).
    • Add comprehensive tests for debouncing and Unikraft controller behavior (server/lib/scaletozero/scaletozero_test.go).
  • API/Server:
    • Use NewDebouncedController and install scaletozero.Middleware on both API and DevTools routers (server/cmd/api/main.go).
    • Remove per-endpoint s.stz.Disable/Enable calls from chromium.go, computer.go, and display.go.
    • Drop explicit scale-to-zero toggling in DevTools WS proxy handler (server/lib/devtoolsproxy/proxy.go).
  • Recorder:
    • Use context.WithoutCancel when re-enabling scale-to-zero in FFmpegRecorder paths and ensure enable on failure/teardown (server/lib/recorder/ffmpeg.go).

Written by Cursor Bugbot for commit 522609b. This will update automatically on new commits. Configure here.

@Sayan- Sayan- marked this pull request as ready for review October 21, 2025 22:28
@mesa-dot-dev
Copy link

mesa-dot-dev bot commented Oct 21, 2025

Mesa Description

Overview

A number of workloads depend on scale to zero and we've noticed some issues with it. Introducing a few changes:

  1. Add a DebouncedController that'll only write to the file when we actually need to
  2. Update callsites to fail on Disable + use context.WithCancel for Enable. Note: the context.WithoutCancel isn't actually needed in the current implementation but is a good guard in case that changes
  3. Add tests

Testing

Added units


Note

Introduces a debounced scale-to-zero controller with HTTP middleware, wires it into both routers, refactors handlers to rely on middleware, and hardens recorder enable paths; adds unit tests.

  • Scale-to-Zero:
    • Middleware: Add scaletozero.Middleware to auto Disable/Enable per request (server/lib/scaletozero/middleware.go), applied to both routers in server/cmd/api/main.go.
    • Controller: Introduce DebouncedController wrapping unikraftCloudController to coalesce repeated Disable/Enable calls (server/lib/scaletozero/scaletozero.go).
    • Wiring: Instantiate via NewDebouncedController(NewUnikraftCloudController()) and pass to services and devtools proxy (main.go).
    • Refactor Callers: Remove explicit s.stz.Disable/Enable in api/chromium.go, api/computer.go, api/display.go, and in devtoolsproxy.WebSocketProxyHandler (now handled by middleware).
  • Recorder:
    • Use context.WithoutCancel when calling stz.Enable in error/teardown paths and defers (server/lib/recorder/ffmpeg.go).
  • Tests:
    • Add unit tests for DebouncedController behavior and unikraftCloudController file writes (server/lib/scaletozero/scaletozero_test.go).

Written by Cursor Bugbot for commit a1c4d99. This will update automatically on new commits. Configure here.

Description generated by Mesa. Update settings

@mesa-dot-dev
Copy link

mesa-dot-dev bot commented Oct 21, 2025

Mesa Description

Overview

This PR hardens the scale-to-zero library to address several observed issues. The changes focus on improving reliability and efficiency.

Key changes include:

  1. Introduced a DebouncedController: This minimizes unnecessary file I/O by ensuring writes only occur when the state actually changes.
  2. Improved Lifecycle Management: Callsites for Disable will now fail explicitly on error. The Enable function now uses context.WithCancel for better control over its lifecycle.
  3. Added Tests: New unit tests have been added to validate the new controller logic and behavior.

Testing

Unit tests were added to cover the new functionality.

Description generated by Mesa. Update settings

Copy link

@mesa-dot-dev mesa-dot-dev bot left a comment

Choose a reason for hiding this comment

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

Performed full review of 90cae41...7db51ee

Analysis

While the PR introduces important improvements to scale-to-zero functionality, several potential architectural issues deserve attention:

  1. The DebouncedController implementation may introduce additional complexity in the call chain, potentially making debugging more difficult when tracing failures through the system.

  2. The error handling improvements return 500 errors, but there's no mention of detailed error context or recovery strategies for clients encountering these failures.

  3. The use of context.WithoutCancel(ctx) for Enable calls, while solving the cleanup issue, could lead to resource leaks if Enable operations hang indefinitely as they're now detached from the original cancellation signal.

  4. The PR may require additional operational monitoring and observability enhancements to track the effectiveness of the new debouncing mechanism in production environments.

Tip

⚡ Quick Actions

This review was generated by Mesa.

Actions:

Slash Commands:

  • /review - Request a full code review
  • /review latest - Review only changes since the last review
  • /describe - Generate PR description. This will update the PR body or issue comment depending on your configuration
  • /help - Get help with Mesa commands and configuration options

8 files reviewed | 0 comments | Review on Mesa | Edit Reviewer Settings

@Sayan- Sayan- requested review from hiroTamada and rgarcia October 21, 2025 23:50
@Sayan- Sayan- requested a review from rgarcia October 22, 2025 00:14
@Sayan- Sayan- merged commit 74d3d3a into main Oct 22, 2025
5 checks passed
@Sayan- Sayan- deleted the sayan/kernel-454-debug-scaletozero-issues branch October 22, 2025 18:49
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.

3 participants