Skip to content

feat(vscode): prevent system sleep during tasks - #13690

Open
JeanLuX wants to merge 3 commits into
Kilo-Org:mainfrom
JeanLuX:feat/inhibit-sleep
Open

JeanLuX wants to merge 3 commits into
Kilo-Org:mainfrom
JeanLuX:feat/inhibit-sleep

Conversation

@JeanLuX

@JeanLuX JeanLuX commented Sep 2, 2026

Copy link
Copy Markdown

Summary

Add opt-in, cross-platform system sleep prevention while VS Code agent tasks are actively running.

  • Add the disabled-by-default kilo-code.new.preventSleepDuringTasks setting.
  • Add a 30-minute active-execution limit per task; 0 removes only Kilo’s time limit.
  • Add the localized Power settings panel, using a battery icon and a nested timeout field.
  • Pause the active-time budget while a task awaits a question, permission, network recovery, or blocking suggestion.
  • Do not prevent display sleep or screen locking.

Why

Long-running agent tasks can be interrupted by automatic system sleep. Existing operating-system power settings are still respected, but users need an explicit way to keep the system awake while work is actually executing.

The feature is opt-in because changing power behaviour should never be a surprise. The timeout is based on active execution rather than wall-clock time so time spent waiting for the user is not charged.

Behaviour

stateDiagram-v2
    [*] --> Running: task becomes busy/retry
    Running --> Paused: question / permission / network / blocking suggestion
    Paused --> Running: reply / recovery
    Running --> Finished: idle / completed / failed / cancelled / limit reached
    Paused --> Finished: task ends
    Finished --> [*]
Loading
flowchart LR
    A[Active task] --> B[Session sleep tracker]
    B --> C{Any task actively running?}
    C -- No --> D[Release native inhibitor]
    C -- Yes --> E[Shared native inhibitor]
    E --> F{Platform}
    F --> G[Windows: ES_SYSTEM_REQUIRED]
    F --> H[macOS: caffeinate -i]
    F --> I[Linux: systemd-inhibit]
    I --> J[Fallback: gnome-session-inhibit]
    G --> K[Ready signal]
    H --> K
    I --> K
    J --> K
    K --> L[Report inhibition active]
Loading

Implementation notes

  • Native helpers use readiness checks, parent-lifetime watchdogs, reference counting, and bounded retry/fallback behaviour.
  • Windows requests system execution state only; it never requests display-required state.
  • macOS uses caffeinate -i.
  • Linux prefers systemd-inhibit --what=sleep and falls back to gnome-session-inhibit --inhibit=suspend.
  • Reconnection restores task status, titles, pending input, network waits, and blocking suggestions without overwriting newer SSE events.
  • Multiple tasks keep one shared native helper alive until the final active task releases it.

Visual evidence

Kilo Settings:
Screenshot_20260902_113743

VSCode status bar:
Screenshot_20260902_113611

System notification (KDE Plasma 6.7.4)
image

Verification

Completed:

cd packages/kilo-vscode

bun test tests/unit/sleep-inhibitor.test.ts \
  tests/unit/kilo-provider-indexing-refresh.test.ts
# 44 passing, 0 failing, 126 assertions

bun run typecheck
bun run lint
bun run format:check
bun run knip
bun run check-kilocode-change

The VSIX archive was also built and verified with unzip -tq.

bun script/dev-snapshot.ts build stalled locally while invoking bun esbuild.js --production. As substitute verification, node esbuild.js --production completed successfully and the same @vscode/vsce packaging path produced a valid VSIX archive.

Add opt-in, task-scoped system sleep inhibition for the VS Code extension.

- Add the preventSleepDuringTasks setting, with a disabled-by-default 30-minute limit and 0 for no extension-imposed limit.

- Add the Power settings panel with nested timeout control, battery icon, Save-state handling, persistence, and translations.

- Track each task independently and pause its active-time budget while waiting for questions, permissions, network recovery, or blocking suggestions.

- Restore task state safely across reconnects, concurrent requests, helper restarts, and partial backend failures.

- Use readiness-checked native inhibitors with watchdogs and reference counting on Windows, macOS, and Linux without preventing display sleep or screen locking.

- Add unit coverage, user documentation, and a release changeset.
@JeanLuX

JeanLuX commented Sep 2, 2026

Copy link
Copy Markdown
Author

Maybe duplicate #12974 ?

Comment thread packages/kilo-vscode/src/services/sleep-inhibitor.ts
Comment thread packages/kilo-vscode/src/services/sleep-inhibitor.ts Outdated
@kilo-code-bot

kilo-code-bot Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/kilo-vscode/src/services/sleep-inhibitor.ts 341 Spawn error while closing never clears this.child, so inhibition can stay dead
packages/kilo-vscode/src/services/sleep-inhibitor.ts 890 Reconnect restores suggestions from only the first known directory
Files Reviewed (57 files)
  • packages/kilo-vscode/src/services/sleep-inhibitor.ts - 2 issues
  • packages/kilo-vscode/tests/unit/sleep-inhibitor.test.ts - 0 issues
  • packages/kilo-vscode/src/extension.ts - 0 issues
  • packages/kilo-vscode/src/kilo-provider/early-message.ts - 0 issues
  • packages/kilo-vscode/src/kilo-provider/sleep-settings.ts - 0 issues
  • packages/kilo-vscode/webview-ui/src/components/settings/SleepTab.tsx - 0 issues
  • packages/kilo-vscode/webview-ui/src/components/settings/Settings.tsx - 0 issues
  • packages/kilo-vscode/webview-ui/src/context/config.tsx - 0 issues
  • packages/kilo-vscode/package.json - 0 issues
  • .changeset/prevent-task-sleep.md - 0 issues
  • Host/webview i18n, README, icon, CSS, and message types - 0 issues

Fix these issues in Kilo Cloud


Reviewed by grok-4.6 · Input: 191.3K · Output: 20.7K · Cached: 968.6K

Review guidance: REVIEW.md from base branch main

Handle ChildProcess close independently from exit so a helper stopped during a failed spawn cannot remain tracked indefinitely.

Restart the native inhibitor when active task references return before the closing helper completes.
Query directory-scoped suggestions for every known directory during reconnect.

Reconcile suggestion waits only for directories whose request succeeded, preventing sleep inhibition from resuming while user input remains pending.
@marius-kilocode

Copy link
Copy Markdown
Collaborator

@JeanLuX thanks for it. We probably would ship this instead: #12974 . It's currently a bit tricky to get through, due to enterprise compliance questions.

@marius-kilocode

Copy link
Copy Markdown
Collaborator

It might make sense maybe to ship this as optional plugin. I haven't tested if that is possible, yet.

@JeanLuX

JeanLuX commented Sep 2, 2026

Copy link
Copy Markdown
Author

No problem if you prefer the other one. I had not seen it before starting this work, but since I had already completed it, I thought I would put it forward anyway, just in case.

As for compliance within the company, I am having trouble understanding the concern. Why would this raise a compliance issue, given that the feature can be disabled, especially since it is disabled by default? Could you tell me more about it?

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