Skip to content

ENG-4890: Configure Light Sleep and Deep Sleep times from CLI#299

Merged
lukaszo merged 2 commits intomasterfrom
ENG-4890-sleep-config
Feb 13, 2026
Merged

ENG-4890: Configure Light Sleep and Deep Sleep times from CLI#299
lukaszo merged 2 commits intomasterfrom
ENG-4890-sleep-config

Conversation

@lukaszo
Copy link
Member

@lukaszo lukaszo commented Feb 12, 2026

Summary

Adds two new CLI flags to configure light sleep and deep sleep idle delays for services:

  • --light-sleep-delay — Duration after which an idle service enters light sleep (e.g., --light-sleep-delay 5m)
  • --deep-sleep-delay — Duration after which an idle service enters deep sleep (e.g., --deep-sleep-delay 30m)

Set either to 0 to disable that sleep mode.

Available on

  • koyeb service create
  • koyeb service update
  • koyeb deploy

Examples

# Set light sleep to 5 minutes and deep sleep to 30 minutes
koyeb service create myservice --app myapp --docker nginx --port 80 --light-sleep-delay 5m --deep-sleep-delay 30m

# Update only the deep sleep delay
koyeb service update myapp/myservice --deep-sleep-delay 1h

# Disable light sleep
koyeb service update myapp/myservice --light-sleep-delay 0

Implementation

  • Maps to DeploymentScalingTargetSleepIdleDelay.LightSleepValue / DeepSleepValue in the API
  • Upgrades koyeb-api-client-go to pick up the new DeepSleepValue and LightSleepValue fields
  • Follows the existing pattern for scaling target flags in setScalingsTargets

Tests

  • 8 test cases covering: create new, update existing, disable individually, disable both (removes target), preserve other targets, no-op when flags not set
  • go test ./... passes ✅

Resolves ENG-4890

Add two new flags for configuring light sleep and deep sleep idle delays
on services. These flags control after how long an idle service enters
light sleep or deep sleep mode.

- --light-sleep-delay: duration before an idle service enters light sleep
- --deep-sleep-delay: duration before an idle service enters deep sleep
- Set to 0 to disable either sleep mode
- Both flags use Go duration format (e.g., '1m', '5m', '1h')

The flags are available on service create, service update, and deploy
commands. They map to the SleepIdleDelay scaling target in the API.

Also upgrades koyeb-api-client-go to pick up the DeepSleepValue and
LightSleepValue fields on DeploymentScalingTargetSleepIdleDelay.
Copy link

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

Adds CLI support for configuring service idle sleep behavior by introducing flags that map to the API’s DeploymentScalingTargetSleepIdleDelay light/deep sleep delay fields.

Changes:

  • Add --light-sleep-delay and --deep-sleep-delay duration flags to service/deploy commands.
  • Update scaling target parsing to create/update/remove the SleepIdleDelay scaling target based on those flags.
  • Add unit tests covering new/updated/disabled sleep delay scenarios.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
pkg/koyeb/services.go Adds new duration flags and updates setScalingsTargets to manage the SleepIdleDelay target.
pkg/koyeb/services_test.go Adds table-driven tests validating sleep delay flag behavior against scaling targets.
go.mod Bumps koyeb-api-client-go to a version that includes the new sleep delay fields.
go.sum Updates checksums for the bumped API client dependency.

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

Comment on lines +1258 to +1267
if lightSleepDuration > 0 {
sid.SetLightSleepValue(int64(lightSleepDuration.Seconds()))
} else {
sid.LightSleepValue = nil
}
}
if deepSleepChanged {
if deepSleepDuration > 0 {
sid.SetDeepSleepValue(int64(deepSleepDuration.Seconds()))
} else {
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

Duration-to-seconds conversion uses int64(duration.Seconds()) which truncates and goes through float64. For sub-second inputs (e.g. 500ms), this becomes 0 and would be treated as a configured value rather than disabling/unsetting, which is likely unintended. Prefer integer math (e.g., round/ceil to whole seconds using time.Duration arithmetic) and decide explicitly how to handle durations < 1s and negative values.

Copilot uses AI. Check for mistakes.
Comment on lines +1284 to +1290
if lightSleepChanged && lightSleepDuration > 0 {
sid.SetLightSleepValue(int64(lightSleepDuration.Seconds()))
hasValue = true
}
if deepSleepChanged && deepSleepDuration > 0 {
sid.SetDeepSleepValue(int64(deepSleepDuration.Seconds()))
hasValue = true
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

Same truncation issue when creating a new SleepIdleDelay target: int64(duration.Seconds()) can produce 0 for positive sub-second durations and relies on float conversion. Use integer Duration arithmetic to compute whole seconds (ideally rounding/ceiling) so CLI inputs don’t silently turn into 0-second delays.

Copilot uses AI. Check for mistakes.
Sleep delays only apply to scale-to-zero services. Return a clear error
when --light-sleep-delay or --deep-sleep-delay is used with min-scale > 0.
@lukaszo lukaszo merged commit b8aadef into master Feb 13, 2026
2 checks passed
@lukaszo lukaszo deleted the ENG-4890-sleep-config branch February 13, 2026 14:34
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