Skip to content

refactor(priority): unify low-priority spawning in priority module - #2140

Merged
max-sixty merged 3 commits into
mainfrom
renice-ionice-best-effort
Apr 13, 2026
Merged

max-sixty merged 3 commits into
mainfrom
renice-ionice-best-effort

Conversation

@max-sixty

@max-sixty max-sixty commented Apr 12, 2026 •

Copy link
Copy Markdown
Owner

Collapses the two priority-lowering helpers (copy::lower_process_priority and commands::process::low_priority_command) into a single worktrunk::priority module. The module-level doc-comment now documents the policy (macOS taskpolicy -b vs Linux ionice+nice), the forbid(unsafe_code) rationale for shelling out, and the two forms in which we apply it.

Follow-up to #2133. Two small behaviour notes:

  • The Linux child-wrapping path now does best-effort ionice -c 3 -- nice -n 19 -- (was just nice -n 19), matching what taskpolicy -b already covers on macOS. ionice availability is probed once per process via which. ionice ships in util-linux on every mainstream distro and is enabled in Alpine's busybox, so the nice-only fallback is only hit on stripped-down environments (distroless, minimal busybox, etc.).
  • copy.rs's self-lowering path now also gates ionice behind the same which probe, so we don't unconditionally fork ionice on hosts without it.

The command() function delegates Linux branching to a small linux_low_priority_command(program, has_ionice) helper so both has_ionice arms are unit-testable regardless of whether the CI runner has ionice installed. Tests cover the macOS taskpolicy wrap, both Linux arms, the non-unix no-op, and lower=false passthrough.

One canonical policy in one place.

This was written by Claude Code on behalf of Maximilian

Collapses the two priority-lowering helpers (`copy::lower_process_priority`
and `commands::process::low_priority_command`) into a single
`worktrunk::priority` module with a spec doc-comment, two entry points
(`lower_current_process` and `command`), and a shared `HAS_IONICE`
`LazyLock` probe via `which`.

On Linux the child-wrapping path now does best-effort `ionice -c 3 --
nice -n 19 --`, matching the I/O-throttle story `taskpolicy -b` already
gave us on macOS. `ionice` ships in util-linux on every mainstream
distro and is enabled in Alpine's busybox, so the `nice`-only fallback
is only hit on stripped-down environments.

Co-Authored-By: Claude <[email protected]>
@worktrunk-bot

Copy link
Copy Markdown
Collaborator

codecov/patch fails at 91.42% (target 96.13%) with 3 missed lines in src/priority.rs. Looks like a rename false positive:

  • On main, copy::lower_process_priority (lines 47-76) and commands::process::low_priority_command (lines 237-260) are both completely uncovered. This PR moves that same shell-out code into src/priority.rs, and codecov treats the new file as all-new patch lines.
  • The only genuinely new logic is the HAS_IONICE probe (line 49) and the ionice -c 3 -- nice -n 19 -- branch (lines 108-112). That branch isn't test-reachable in CI without spawning a real backgrounded process and asserting on its scheduler/IO class, which isn't a thing the existing test harness does.

Confirmed by querying main-branch coverage for the same byte ranges:

src/copy.rs lines 47,51-58,67-76: all 0
src/commands/process.rs lines 237-240,249-253: all 0

So no net coverage regression — just patch-vs-file accounting. Deferring to you on whether this is acceptable to merge.

Covers the cfg-gated branches of `command()` that integration tests don't
exercise directly (macOS taskpolicy wrap, Linux ionice/nice wrap, non-unix
no-op, and `lower=false` passthrough), plus a smoke test of
`lower_current_process()`.

Addresses `codecov/patch` gap on #2140.

Co-Authored-By: Claude <[email protected]>
The Linux CI runner has `ionice` installed, so the `HAS_IONICE=false` arm
of `command()` was never hit under coverage. Pull the branching into a
small `linux_low_priority_command(program, has_ionice)` helper and test
both values directly.

Closes the remaining codecov/patch gap on #2140.

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit a78541a into main Apr 13, 2026
22 checks passed
@max-sixty
max-sixty deleted the renice-ionice-best-effort branch April 13, 2026 00:39
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