jcode icon indicating copy to clipboard operation
jcode copied to clipboard

TUI power inhibitor ignores prevent_sleep_while_streaming=false

Open pigmej opened this issue 4 months ago • 2 comments

Summary

[power].prevent_sleep_while_streaming = false disables the shared daemon power inhibitor, but the TUI client can still acquire a power inhibitor while a turn is processing.

On Linux this can still hit the systemd-inhibit / polkit / pkttyagent path even though the config says sleep prevention is disabled.

Repro

  1. Set:

    [power]
    prevent_sleep_while_streaming = false
    
  2. Start a Linux TUI/remote-client session.

  3. Run an agent turn.

  4. Observe the power-inhibit path can still be used from the TUI sleep guard.

Expected

When prevent_sleep_while_streaming = false, neither the daemon nor the TUI should acquire a power inhibitor.

Reference fix

I could not create a PR from this account, but pushed a minimal reference fix here:

  • branch: https://github.com/pigmej/jcode/tree/fix/power-inhibit-config-tui
  • compare: https://github.com/1jehuang/jcode/compare/master...pigmej:fix/power-inhibit-config-tui?expand=1
  • commit: https://github.com/pigmej/jcode/commit/5184c30baa06ef81e5b4a34f03d507dcad4a6690

The main change gates sync_sleep_guard() on config().power.prevent_sleep_while_streaming, matching the existing daemon-side config gate.

pigmej avatar Jul 06 '26 18:07 pigmej

Fixed in 6b94b54b. The TUI sleep guard (sync_sleep_guard()) now re-checks [power].prevent_sleep_while_streaming on every call, matching the daemon-side gate, so neither the daemon nor the TUI acquires a power inhibitor when the config disables it. Thanks @pigmej for the reference fix, which this follows (the dev_cargo.sh linker hunk in the reference branch was unrelated and not taken).

Will be included in the next release.

1jehuang avatar Jul 07 '26 01:07 1jehuang

Confirmed the user-visible Linux failure mode on jcode v0.55.0 over an SSH/TTY session: when streaming begins with sleep prevention enabled, the terminal polkit path writes text such as org.freedesktop.login1.inhibit-block-sleep, polkit-agent-helper-1, and Password: directly over the Ratatui screen.

The post-fix configuration works as expected in v0.55.0:

[power]
prevent_sleep_while_streaming = false

After changing it, fully exit the affected TUI, run reset, and restart jcode to clear the already-contaminated frame. No polkit rule, password, or elevated permission is needed.

Trade-off: jcode no longer prevents the machine from sleeping during model streaming; normal OS power policy and other inhibitors remain unchanged.

0p9b avatar Jul 23 '26 16:07 0p9b