Repository navigation
fix(trace): route every command spawn through one CommandTrace chokepoint - #3134
Conversation
…oint `git worktree add` ran via a raw `std::process::Command` spawn that bypassed `shell_exec::Cmd`, so it emitted no `[wt-trace]` record and showed up as an unattributed multi-second gap in `wt-perf timeline`. An audit found several other in-process spawn paths with the same gap. Promote the trace recorder out of `Cmd` into a single `#[must_use]` `CommandTrace` guard in `src/trace/emit.rs` — the sole emitter of command records (the `command_completed`/`command_errored` writers are now module-private). A debug-build drop assertion trips if a guard is constructed but never resolved, so a future spawn site can't silently skip tracing. Route every in-process spawn through it: `Cmd` gains a `delayed_stream` mode (moving the buffer-then-stream logic + `StreamCommandError` out of `Repository`), and the concurrent runner, pipeline steps, `wt step tether`, custom subcommands, and the fsmonitor daemon launch construct a `CommandTrace` directly. Detached background children, pagers, and shell probes stay intentionally untraced. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
I traced the CommandTrace must-resolve invariant across every new spawn site — custom.rs, run_pipeline.rs (including the concurrent-group teardown loop), step/tether.rs, output/concurrent.rs, and Cmd::{run, stream, pipe_into, delayed_stream}. Every error and teardown path resolves its guard: spawn-fail and wait-fail arms call fail, torn-down children call complete(false), wait_first_error fully drains its iterator so no concurrent child drops unresolved, and the drop tripwire is panic-safe (std::thread::panicking() guard). The refactor also closes a couple of pre-existing trace gaps — Cmd::run's stdin spawn/write error paths used to ? past the recorder and now route through record_captured. The logic looks correct.
The one blocker is codecov/patch (FAILURE). Per this repo's CLAUDE.md it gates merge despite being marked "not required," so flagging rather than approving over it.
The gap breaks down as:
- Mostly inherently hard to test — the misses are concentrated in subprocess
Err(e) => trace.fail(&e)spawn/wait arms across all six files. Hitting them needs fault injection (e.g. spawning a nonexistent program sospawn()errors). - Two arms are strictly unreachable from production and will never be covered as written:
- the
Nonebranch oflog_delayed_stream_start(shell_exec.rs) — its sole caller,Repository::run_command_delayed_stream, always sets.context(self.logging_context()), socontextis neverNonehere. None => Ok(())inCmd::run's stdin path —.stdin(Stdio::piped())is set immediately beforespawn(), sochild.stdin.take()always returnsSome.
- the
To get patch coverage green: either add a fault-injection test for the spawn-fail arms, trim the two unreachable arms above, or sign off on the coverage gate explicitly before merge. Otherwise no concerns — nice consolidation, and the #[must_use] + drop-assert tripwire is a good guard against future spawn sites silently skipping tracing.
Patch-coverage follow-up. Adds fault-injection tests that spawn a
non-existent program so the `trace.fail` spawn-error arms across
`Cmd::{run, delayed_stream, pipe_into}`, `run_custom`, and `step_tether`
are exercised, plus a `pipe_into` sink-spawn-failure test for the
source-teardown (`complete(false)`) path and a `cat`-stdin test that pins
the "drop stdin before wait" fix.
Removes the now-dead `None` arm of `Cmd::run`'s stdin handling: stdin is
piped immediately before spawn, so `child.stdin.take()` is always `Some`
(use `.expect`, matching `pipe_into`).
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
… Display Reachable-arm coverage follow-up. The absolute-path pipe_into tests hit the `record_failed` precondition arms (vs the relative-path spawn-failure tests), and a Display test covers the StreamCommandError impl that callers otherwise bypass via extract_failed_command. The remaining patch-coverage misses are wait()-failure and sh-spawn-failure error arms that can't be exercised without invasive fault injection. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
worktrunk 0.61.0 Created-by: HarmonybrewBot Commit-by: HarmonybrewBot Merged-by: HarmonybrewBot Description: Created by `brew bump` --- Created with `brew bump-formula-pr`.<details> <summary>release notes</summary> <pre>## Release Notes ### Improved - **`wt list` custom columns**: Each `[list.custom-columns.<Header>]` entry in user config adds a column to `wt list` (and the `wt switch` picker), rendered per row as a minijinja template over `branch`, `worktree_path`, `worktree_name`, and `vars.*`, with optional `width` and drop priority. Values expand from in-memory data only — no subprocess runs per cell — and a column that is empty on every row is dropped. `wt list --format=json` gains a `columns` map per item. The feature is experimental, so the config shape may still change. ([#3073](max-sixty/worktrunk#3073)) - **`--config-set` for inline config overrides**: A global, repeatable `--config-set <toml>` flag overrides any user-config key for a single invocation, layered above config files and `WORKTRUNK_*` env vars. The value is a real TOML fragment, so arrays and tables work natively (`wt --config-set list.full=true list`); nested tables deep-merge, and a malformed or invalid override drops the whole `--config-set` layer with an attributed warning rather than failing the command. ([#3138](max-sixty/worktrunk#3138)) - **Picker shows cached PR/MR numbers**: The `wt switch` picker skips the networked CI-status fetch, so it previously had no CI column. It now fills PR/MR numbers from the local `.git/wt/cache/ci-status/` cache populated by earlier `wt list --full` or statusline runs, with zero network access. A stale entry (TTL passed or branch head moved) keeps its number dimmed; expired entries without a number are dropped. ([#3073](max-sixty/worktrunk#3073)) - **Faster file copies on macOS**: After a reflink (`clonefile` on APFS, which already preserves mode bits), worktrunk now skips the redundant follow-up `chmod` on macOS, saving one syscall per file in `wt step copy-ignored` and every other copy path. Linux (btrfs/XFS) still sets permissions, since `FICLONE` clones data extents only and drops the execute bit. ([#3149](max-sixty/worktrunk#3149)) ### Internal - **Picker migrated to skim 4.8 (ratatui/crossterm)**: The `wt switch` picker moved off skim 0.20.5 (tuikit) to skim 4.8.0, dropping the vendored `vendor/skim-tuikit/` patch tree (both patches it carried are now native or upstream). Two cosmetic picker changes come with it: the match counter no longer overlaps the preview-tab header, and the HEAD column shows the full short-SHA. ([#3137](max-sixty/worktrunk#3137)) - **All command spawns route through one trace chokepoint**: `CommandTrace` is now the sole emitter of `[wt-trace]` command records, so a spawn path can't silently skip tracing — `git worktree add`, previously an unattributed gap, now shows up as a labeled slice in `wt-perf timeline`. ([#3134](max-sixty/worktrunk#3134)) ### Documentation - **Hook-approval skill guidance**: The bundled worktrunk skill now frames hook approvals as user consent and no longer advocates `--yes` to bypass prompts. ([#3146](max-sixty/worktrunk#3146)) ## Install worktrunk 0.61.0 ### Install prebuilt binaries via shell script ```sh curl --proto '=https' --tlsv1.2 -LsSf https://github.com/max-sixty/worktrunk/releases/download/v0.61.0/worktrunk-installer.sh | sh && wt config shell install ``` ### Install prebuilt binaries via powershell script ```sh powershell -ExecutionPolicy Bypass -c "irm https://github.com/max-sixty/worktrunk/releases/download/v0.61.0/worktrunk-installer.ps1 | iex"; git-wt config shell install ``` ### Install prebuilt binaries via Homebrew ```sh brew install worktrunk && wt config shell install ``` ## Download worktrunk 0.61.0 | File | Platform | Checksum | |--------|----------|----------| | [worktrunk-aarch64-apple-darwin.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.61.0/worktrunk-aarch64-apple-darwin.tar.xz) | Apple Silicon macOS | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.61.0/worktrunk-aarch64-apple-darwin.tar.xz.sha256) | | [worktrunk-x86_64-apple-darwin.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.61.0/worktrunk-x86_64-apple-darwin.tar.xz) | Intel macOS | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.61.0/worktrunk-x86_64-apple-darwin.tar.xz.sha256) | | [worktrunk-x86_64-pc-windows-msvc.zip](https://github.com/max-sixty/worktrunk/releases/download/v0.61.0/worktrunk-x86_64-pc-windows-msvc.zip) | x64 Windows | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.61.0/worktrunk-x86_64-pc-windows-msvc.zip.sha256) | | [worktrunk-aarch64-unknown-linux-musl.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.61.0/worktrunk-aarch64-unknown-linux-musl.tar.xz) | ARM64 MUSL Linux | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.61.0/worktrunk-aarch64-unknown-linux-musl.tar.xz.sha256) | | [worktrunk-x86_64-unknown-linux-musl.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.61.0/worktrunk-x86_64-unknown-linux-musl.tar.xz) | x64 MUSL Linux | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.61.0/worktrunk-x86_64-unknown-linux-musl.tar.xz.sha256) | ### Install via Cargo ```sh cargo install worktrunk && wt config shell install ``` ### Install via Winget (Windows) ```sh winget install max-sixty.worktrunk && git-wt config shell install ``` ### Install via AUR (Arch Linux) ```sh paru worktrunk-bin && wt config shell install ``` </pre> <p>View the full release notes at <a href="https://github.com/max-sixty/worktrunk/releases/tag/v0.61.0">https://github.com/max-sixty/worktrunk/releases/tag/v0.61.0</a>.</p> </details> <hr> See merge request: Harmonybrew/homebrew-core!12090
What
git worktree addwas invisible inwt-perf timeline— it showed up as an unattributed multi-second gap rather than a labeled slice. The root cause: it ran viaRepository::run_command_delayed_stream, which built a rawstd::process::Commandand spawned it directly, bypassingshell_exec::Cmd. OnlyCmd's methods emitted[wt-trace]records (via a privateWtTraceLog). An audit found this was one of several in-process spawn paths silently skipping tracing — so this fixes the reporting and restructures emission so it can't be skipped by omission.The chokepoint
CommandTrace(insrc/trace/emit.rs, the module that owns the[wt-trace]grammar) is now the sole emitter of command records —command_completed/command_erroredare private to that module, so the only way to produce acmd=…record is to construct aCommandTraceand resolve it withcomplete/fail. It's#[must_use]and trips a debug-build drop assertion if constructed but never resolved, so a future spawn site that forgets to wire up tracing fails tests rather than leaving a gap. Duration is snapshotted at resolution, so streamed commands (whose duration isn't known until the stream finishes) still record the correct spawn → wait span.Where to look
src/trace/emit.rs— theCommandTraceguard + module docstring describing the chokepoint.src/shell_exec.rs—WtTraceLogreplaced byCommandTrace; newCmd::delayed_streammode (the delayed-stream buffer-then-stream logic +StreamCommandErrormoved here fromRepository);run/stream/pipe_intomigrated.src/git/repository/mod.rs—run_command_delayed_streamis now a thinCmd::delayed_streamwrapper (~160 lines removed);start_fsmonitor_daemon_attraced.src/output/concurrent.rs,src/commands/run_pipeline.rs,src/commands/step/tether.rs,src/commands/custom.rs— spawn paths that can't beCmdmethods construct aCommandTracedirectly.Detached background children, pagers, and shell probes stay intentionally untraced (they outlive the invocation or aren't part of its timeline) — noted in
CLAUDE.md.Testing
pre-mergeis green (3981 tests, clippy, all hooks includingno-direct-cmd-output). New coverage:CommandTracedrop-tripwire unit tests andtest_switch_create_traces_worktree_add, which asserts the streamedgit worktree addemits a record. The tripwire earned its keep during development — it surfaced a few unresolved-drop paths in the partial-spawn-failure cleanups, and the snapshot suite caught a stdin-pipe deadlock the refactor briefly introduced inCmd::run(the child'sstdinhandle was held open acrosswait_with_output(), hanginggit … --stdinchildren).