Repository navigation
Prevent sleep while running for increased reliability #7049
Replies: 12 comments 1 reply
|
I have a working implementation of this, following what the issue proposed: a Scope decisions to keep it small:
Verified live on macOS: the assertion shows up in Windows and Linux go through the same cross-platform Electron API, but I could only verify end to end on macOS. If a Windows or Linux user wants to try the branch and confirm ( Opening a PR shortly. |
|
Filling in the Windows and Linux evidence that #5535 asked for and could not get, because it was only verified on macOS. Why the WSL case is not covered by the provider's own flagFor a WSL environment, a provider's sleep prevention cannot help. Codex's The same applies to a WSL-hosted Codex thread specifically, which is why enabling What I measuredWSL2 on Windows 11 Home, "Legion Balance Mode" power scheme,
What I can addI can build the #5535 branch, run a turn against a WSL environment, and confirm the assertion appears in |
|
Asking for an explicit scope decision The two reasons #5535 was closed (no selected default, no rule for remote hosts) were already answered in this thread: @leo-mathurin's comment above and @satyalyadav's #13893 both propose that it is off by default and that only turns on local/WSL environments hold the blocker. Could a maintainer confirm whether that scope is acceptable, or say what would need to change? Two small additions to that scope, if helpful:
I can verify on macOS; @satyalyadav has offered to cover Windows/WSL. |
|
+1, with a use case and two points on scope. I run several Claude Code threads at once in T3 Code, each with subagents and delegated tasks. Right now I keep the Mac awake with On the scope question above:
I can test on macOS (MacBook Pro, Apple Silicon) with |
|
I have created a menu bar app for macOS that prevents the mac from sleeping with the option to keep it awake until auto-resume is triggered. There is also a new experimental feature that I've added today but still gotta test that it let's your mac sleep while you wait for the auto-resume (to save energy) and then it automatically wakes up. It also keeps mac awake when agent is waiting for user input for 2 hours so you can still reply from your phone or other device. It also supports keeping the mac awake while the lid is closed and disconnecting bluetooth devices while you do it (requires root) |
|
One fact that matters for the scope here: on a MacBook, none of these assertions survives closing the lid. Since that is OS policy rather than something T3 Code should own (the closing note on #5535), a small docs change could help whatever is decided about the feature: one sentence in "Platform support" of
A vendor-neutral version without the link works too. If a maintainer agrees with the direction, I can open a docs-only PR that links this discussion. Disclosure: I make Keep Mac Awake, a paid macOS app (3-day free trial, then 9 USD once per Mac) that keeps a MacBook with Apple silicon awake with the lid closed for a session you start, with a watchdog that restores normal sleep if a service stops or hangs. I use T3 Code daily with it. |
|
Another use case: reaching the Mac from my phone I mostly use T3 Code from the iPhone app over T3 Connect, with my MacBook on the charger at my desk. Since I fully switched from the Codex app to T3 Code, the phone gets stuck on "Reconnecting" ( It took me over half an hour with I've now turned on macOS's "Prevent automatic sleeping on power adapter when the display is off", but that keeps the Mac awake even when I'm not using any of these apps. I'm confused why T3 Code doesn't offer this as an option, especially since being reachable from my phone is a big part of why I use it. Drafted with Claude Opus 5.5 (Claude Code) on behalf of @lingolooper-simon. |
|
I'd like T3 Code to match the user-visible behavior of ChatGPT/Codex desktop's “Prevent sleep while running” setting. I use it on KDE Plasma, and it already fits my use case: start a task, step away, and let the computer return to its normal sleep policy once the work ends. My preferred scope:
Keeping the computer reachable from a phone is a separate need. ChatGPT has a separate keep-awake control under its connection settings; I would keep that separate here too, with remote-host availability restricted to AC power. It should not make task sleep prevention AC-only or keep an idle laptop awake on battery. For lid closure, follow the platform's normal behavior rather than adding a privileged system-wide override to this feature. OpenAI's Mac guidance describes plugged-in operation and an external display for closed-lid use. My request is to prevent automatic sleep from inactivity while work is running. References: ChatGPT settings, remote connections. The documentation confirms the separate settings, but does not establish every internal detail, including battery thresholds or all background-work transitions. Those bullets express my requested behavior rather than claiming a complete implementation audit of ChatGPT. Drafted with Codex (gpt-6.1-sol) in T3 Code on my behalf. |
|
I built this in my fork and run it on a MacBook Air, in case a working reference helps settle the scope. What it does
What I have and have not checked Tested by hand on macOS desktop. The Linux path has unit tests but I have not hand-tested it on a desktop Linux session. Windows is not implemented. Code Server service and tests are under Written with Claude (Fable 5.2) via Claude Code. |
|
Note 🤖 Composer responding on behalf of wSedlacek Prior effort: #30651 (closed in the unvouched sweep; Macroscope had approved the approach). What we learned trying it
|
|
Data point from KDE Plasma 6.6 (Wayland, desktop PC), for the Linux side of this. My PC suspended this week while threads were running. I want to keep idle suspend, just not while agents are working. Until this lands I run a small watcher, and testing it turned up a few things:
The workaround, for Linux users who want it nowA systemd user service runs this. It polls every 30 s and holds QUERY="SELECT count(*) FROM orchestration_v2_projection_runs
WHERE status IN ('queued', 'preparing', 'starting', 'running')"
holder=""
while :; do
count=$(systemctl --user is-active --quiet t3code.service &&
sqlite3 -readonly -cmd ".timeout 2000" ~/.t3/userdata/statev2.sqlite "$QUERY")
if [ "${count:-0}" -gt 0 ] && [ -z "$holder" ]; then
kde-inhibit --power tail -f /dev/null & holder=$!
elif [ "${count:-0}" -eq 0 ] && [ -n "$holder" ]; then
pkill -P "$holder"; wait "$holder"; holder=""
fi
sleep 30
doneIts weak spot is reading T3's internal SQLite state, which any update can break. The CLI can't answer "is any run active, across projects and including subagents?" yet; I asked for that in #33971. Drafted with Claude Opus 5.5 (Claude Code) in T3 Code on my behalf. |
|
macOS counterpart of the watcher above, for anyone who wants it before this lands. Same query, same rule: hold an assertion only while a run is
The workaround, for Mac users who want it nowCall this script from a LaunchAgent to run on login. QUERY="SELECT count(*) FROM orchestration_v2_projection_runs
WHERE status IN ('queued', 'preparing', 'starting', 'running')"
home="${T3CODE_HOME:-$HOME/.t3}/userdata"
holder=
while :; do
pid=$(sed -n 's/.*"pid":[[:space:]]*\([0-9]*\).*/\1/p' "$home/server-runtime.json")
count=$(kill -0 "$pid" 2>/dev/null &&
sqlite3 -readonly -cmd ".timeout 2000" "$home/statev2.sqlite" "$QUERY")
if [ "${count:-0}" -gt 0 ] && [ -z "$holder" ]; then
caffeinate2 -i -w $$ & holder=$!
elif [ "${count:-0}" -eq 0 ] && [ -n "$holder" ]; then
kill "$holder" 2>/dev/null; wait "$holder" 2>/dev/null; holder=
fi
sleep 30
doneSame weak spot as the Linux version: this reads internal SQLite state, which an update can break. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Currently when running long-tasks there is a risk of the device falling asleep, this can cause connection issues & interrupt the active task. This is a feature I've found useful on the Codex app.
We should ensure it only runs while a thread is active/running.
I think this would use https://www.electronjs.org/docs/latest/api/power-save-blocker ? And we'd want to use
prevent-app-suspensionso the app isn't suspended but the screen etc can still turn off e.g. so policies like auto-locking the device after 10 mins of inactivity isn't affected by long running tasks.I can work on this feature in my free time if needed.
All reactions