Repository navigation
Run internal detached ops at nice 19 - #2130
Merged
Merged
Conversation
`wt remove`'s background `rm -rf` and `sweep_stale_trash` were competing with foreground work for CPU/IO. Extends the treatment already applied to `step_copy_ignored` (see `src/copy.rs::lower_process_priority`) to internal detached spawns: `spawn_detached` and `spawn_detached_exec` now wrap the child in `nice -n 19 --` when `hook_log` is `HookLog::Internal`. User hooks run at normal priority. `nice` is POSIX and shipped in base macOS/Linux; a missing binary would fail the spawn, matching the existing `renice` assumption. Windows is unchanged — priority there is a separate mechanism. Co-authored-by: Claude <[email protected]>
Wrap `sh` / the target binary in `nice -n 19` when `spawn_detached` and `spawn_detached_exec` are called for `HookLog::Internal`. Covers the background `rm -rf` behind `wt remove` and the trash sweep. User hooks are unaffected — they continue to run at normal priority so their visible work isn't slowed. Co-Authored-By: Claude <[email protected]>
worktrunk-bot
previously approved these changes
Apr 12, 2026
worktrunk-bot
left a comment
Collaborator
There was a problem hiding this comment.
codecov/patch dropped below the project floor (95.45% < 96.12%) because low_priority_command is untested — the existing tests don't exercise spawn_detached_unix directly, so the helper's two branches are unobserved. The surrounding spawn_detached_unix body is already uncovered on main, so any new executable line in there sinks the patch average.
A small unit test against Command::get_program() / Command::get_args() closes the gap cheaply:
#[cfg(unix)]
#[test]
fn test_low_priority_command() {
use std::ffi::OsStr;
// low_priority=true wraps in `nice -n 19 --`
let cmd = low_priority_command("sh", true);
assert_eq!(cmd.get_program(), "nice");
let args: Vec<&OsStr> = cmd.get_args().collect();
assert_eq!(
args,
&[OsStr::new("-n"), OsStr::new("19"), OsStr::new("--"), OsStr::new("sh")]
);
// low_priority=false runs the program directly
let cmd = low_priority_command("sh", false);
assert_eq!(cmd.get_program(), "sh");
assert_eq!(cmd.get_args().count(), 0);
}Happy to push this as a follow-up commit if you'd like.
worktrunk-bot
dismissed
their stale review
April 12, 2026 21:38
codecov/patch failed — posted coverage analysis
Cover both branches via `Command::get_program()` and `Command::get_args()` to restore codecov/patch above the project floor. Co-authored-by: Claude <[email protected]>
max-sixty
commented
Apr 12, 2026
max-sixty
left a comment
Owner
Author
There was a problem hiding this comment.
Added the helper test as suggested. Thanks for catching the coverage gap.
worktrunk-bot
approved these changes
Apr 12, 2026
max-sixty
added a commit
that referenced
this pull request
Apr 12, 2026
On Darwin, `nice`/`renice` only affect Mach CPU scheduling priority — disk and network I/O throttling require `PRIO_DARWIN_BG`, set via `setpriority(PRIO_DARWIN_PROCESS, …)` or `taskpolicy -b`. For the workloads we lower priority on (reflink-fallback copy in `step_copy_ignored`, background `rm -rf` behind `wt remove`, trash sweep), disk I/O is the dominant cost — the previous `nice 19` / `renice 19` calls left it un-throttled on APFS. ## Changes - **`copy.rs::lower_process_priority`** — `taskpolicy -b -p <pid>` on macOS; `renice -n 19 -p <pid>` plus best-effort `ionice -c 3 -p <pid>` on Linux. - **`process.rs::low_priority_command`** — wraps the child in `/usr/sbin/taskpolicy -b` on macOS, `nice -n 19 --` elsewhere. Policy is inherited by children, so the detached shell and its grandchildren (the actual `rm -rf`) all run at lowered priority. Shelled out rather than calling the syscalls directly to stay within `forbid(unsafe_code)`. `taskpolicy` ships at `/usr/sbin/taskpolicy` in every macOS base install; a missing binary fails the spawn, matching the existing tolerance model. ## Evidence `man 2 setpriority` on macOS: "When a thread or process is in a background state the scheduling priority is set to the lowest value, disk IO is throttled (with behavior similar to using setiopolicy_np(3) to set a throttleable policy), and network IO is throttled for any sockets opened after going into background state." The Darwin-specific `PRIO_DARWIN_BG` bit is what makes the difference — the POSIX `PRIO_PROCESS` path that `nice`/`renice` use doesn't touch I/O policy. `man taskpolicy`: "uses the setiopolicy_np(3) and setpriority(2) APIs … All children of the specified program also inherit these policies." This builds on #2130 (which added `nice 19` wrapping for internal detached ops); that baseline is preserved for Linux while macOS gets the I/O-throttling upgrade. > _This was written by Claude Code on behalf of @max-sixty_ --------- Co-authored-by: Claude <[email protected]>
max-sixty
added a commit
that referenced
this pull request
Apr 13, 2026
The runtime check (WORKTRUNK_NU_WRAPPER_VERSION, nu_wrapper_status, warn_outdated_nushell_wrapper_once) only catches drift for wrappers that already export WORKTRUNK_SHELL=nu — i.e. anyone who has installed a version-1+ wrapper. Pre-versioning wrappers (everyone before this branch lands) don't set WORKTRUNK_SHELL at all, so they're invisible to the check. That's exactly the cohort that most needs nudging after the split-directive-file migration. Strip it in favor of the TODO(2026-05) in compute_directive_mode, which catches pre-versioning nushell wrappers via the legacy env-var path. For ongoing drift detection after May, `wt config show` already does content comparison on wrapper-based shells (fish and nushell) and prints "Outdated shell extension" — user-initiated, but sufficient. Keeps the merge of #2118 / #2130. Co-Authored-By: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
wt remove's backgroundrm -rfandsweep_stale_trashwere competing with foreground work for CPU/IO. This extends the renicing already done forstep_copy_ignored(seesrc/copy.rs::lower_process_priority) to the detached-spawn paths:spawn_detachedandspawn_detached_execnow wrap the child innice -n 19 --whenhook_logisHookLog::Internal. User hooks keep running at normal priority.The nice value is inherited across fork/exec, so wrapping the outer
sh(for the shell-based path) or the target binary directly (for the exec path) is enough — the backgrounded work inherits it.niceis POSIX and shipped in base macOS/Linux; a missing binary would fail the spawn, matching the existingreniceassumption incopy.rs. Windows is left on its own priority mechanism (not wired up here).A follow-up is under investigation: macOS has
taskpolicy -bwhich also throttles I/O (IOPOL_THROTTLE) rather than just CPU priority. If the research lands in favor of it, the singlelow_priority_commandhelper is the one place to swap the primitive.