Skip to content

perf(harness-ops): read the cache-content check's streams from a file, not a pipe - #12637

Merged
kyle-sexton merged 2 commits into
mainfrom
host-run/12541-cache-content-check-join
Nov 3, 2026
Merged

kyle-sexton merged 2 commits into
mainfrom
host-run/12541-cache-content-check-join

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Refs: #12541

Summary

The cache-content check (/harness-ops:plugins sync Step 5b, 10.3 s in #12539's audit) spends its time in bash, not in git. Measured on a 91-install fixture where every melodic-software user record points at the marketplace clone's HEAD, so all 91 installs are compared:

  • Bash's read and mapfile builtins read one byte per read() call when they cannot buffer the input. On Linux that is a pipe. The 17,491-entry git ls-tree stream took 2,198,223 read() calls from a pipe and 571 from a file, 0.199 s against 0.005 s. The find | sort -z and check-ignore streams pay the same way.
  • Under __CYGWIN__, bash reads one byte per call from every descriptor, regular files included: bash 5.2's builtins/mapfile.def sets unbuffered_read = 1 there, and builtins/read.def sets input_is_pipe = 1. MSYS2's bash, and so Git Bash, is a Cygwin build: its PKGBUILD applies 0001-bash-4.4-cygwin.patch. That __CYGWIN__ is defined in that build is inferred, not checked. On that host the check still pays about one emulated syscall per byte it reads through a builtin. That is the main suspect for the 10.3 s, and this PR does not change it there.
  • The tree and cache joins looked up every ancestor of every path. Most files share a directory with the file before them in sorted order.
  • The 33 not-at-head installs cost almost nothing. Pass 1 settles them with one rev-parse for the whole marketplace, before any tree, find or hash work.

Fix

  • cache-content-check.sh writes its ls-tree, find | sort -z and check-ignore output to one private mktemp file, removed on exit, and runs mapfile on that file. This cuts the read calls on Linux and macOS.
  • The tree join finds a path's owning sources once per directory, and the cache join finds a file's install root once per directory. Both still handle nested sources and single-file sources. This change helps every platform.
  • The header comment no longer claims process count is the only cost, and it names the temporary file.
  • Changelog fragment for harness-ops, bump: patch.

Verification

  • cache-content-check.test.sh: 28 cases, 0 failed, including the read-only and process-budget cases.
  • scripts/check-affected.sh --tests on the first commit: 13 passed, 2 failed. The failing cases are home-path and live-claude cases in fleet-state.test.sh, reset-refresh.test.sh and sync-run.test.sh. The first two fail the same way on an unchanged checkout on this host. sync-run.test.sh stubs cache-content-check.sh, and the other two do not call it, so this change cannot affect any of them. CI decides those.
  • The output is byte-identical before and after (cmp), on the fixture and on this host's real state (--all --scope all).
  • Linux (WSL2) timing, five warm runs interleaved: median 3.39 s before, 2.83 s after. A cold first run took 8.1 s. The extra time is file reads in find and hash-object, which this change does not touch.
  • read() calls across the whole process tree for one fixture run, Linux (strace -f -c): 4,510,439 before, 217,438 after.

Remaining on #12541

  • On Git Bash, avoid byte-wise builtin reads. Command substitution reads in blocks on every platform, but it drops NUL. The options are a NUL-to-newline capture, with newline-bearing paths moved to the existing per-path fallback, or moving the join into one awk process. Either one changes the script's path transport, so it belongs in its own change.
  • Re-time on the Windows Git Bash host that measured the 10.3 s: compare timings.cache_content_check in a sync digest before and after. This host cannot measure it.
  • Per-file processes this PR leaves in place, with their counts on the fixture:
    • Pass 7 runs one git hash-object --path re-hash per raw hash mismatch: 54 on the fixture, all of them real differences in its 27 stale installs.
    • Pass 5 runs one readlink + hash-object pair per symlink: 0 on the fixture, which has no symlinks.
    • A clean fleet pays neither.

Related

🤖 Generated with Claude Code

https://claude.ai/code/session_01VcuponMacsFYBfNzLKb3ws

…, not a pipe

bash reads a pipe one byte per read() call because it cannot seek back
over bytes past the delimiter, so `mapfile -d ''` from a process
substitution cost one syscall per byte of git ls-tree, find and
check-ignore output: 2,198,223 read() calls for the 17,491-entry ls-tree
alone, 571 when the same bytes come from a file. Each stream is now
written to one private temporary file and read back from it.

The tree and cache joins also find each path's owning source directory
and install root once per directory instead of once per file. Output
is byte-identical on a 91-install fixture and on this host's real
install state.

Refs: #12541

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VcuponMacsFYBfNzLKb3ws
@kyle-sexton

Copy link
Copy Markdown
Member Author
  • verify skipped by kyle-sexton for this run: the suites ran locally on this head (cache-content-check.test.sh 28/28); the only failures are home-path and live-claude cases in fleet-state, reset-refresh and sync-run tests that fail the same way on unchanged main on this host; CI runs every suite on ready

@kyle-sexton
kyle-sexton marked this pull request as ready for review November 3, 2026 03:26
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T03:28:01.721135Z 39cf618 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 0230c3bd069a1808058fe7fff7831d49b327c43b: read 2 of 2 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #12637, incremental since 39cf6181 (complete: I read every hunk of both changed files)

I found no security issues.

What changed since the last review

  • plugins/harness-ops/skills/plugins/scripts/cache-content-check.sh: only the comment above SPOOL=$(mktemp ...) changed. It now says that Cygwin and MSYS2 builds of bash read one byte per call from any descriptor. No code changed. Creating the temporary file, stopping on a mktemp failure, and removing the file on exit all work as they did at the last review.
  • .changes/harness-ops/perf-12541-cache-check-spool-7c2e91a4.md: the changelog wording was changed to match that comment. It is prose only.

What I checked

  • Neither file matches a TRUSTED PATHS glob. The change touches no plugin manifest, workflow, token, kill switch, merge hold or instruction file, and it removes no standing instruction.
  • No embedded instructions were found in the changed text.
  • Prior findings: the last review posted no findings, so nothing carries over. Round cap: 0 of 3 rounds used, so the cap does not apply.

critical-findings: 0

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed 0230c3bd069a1808058fe7fff7831d49b327c43b: read 2 of 2 changed file(s); 0 finding(s), 0 as inline comments.

Code review (incremental since 39cf618): no findings

I read every hunk of both files changed in this push.

  • plugins/harness-ops/skills/plugins/scripts/cache-content-check.sh (L391–395): the only change is the header comment for SPOOL. It now says a Cygwin or MSYS2 bash reads one byte per call from any descriptor. No code changed, and the comment matches the PR description's account of builtins/mapfile.def and builtins/read.def under __CYGWIN__.
  • .changes/harness-ops/perf-12541-cache-check-spool-7c2e91a4.md: the changelog line now limits the block-read benefit to Linux and macOS bash and says Cygwin/MSYS2 builds read one byte at a time either way. It still says the per-directory join helps every platform and that the report is unchanged. That agrees with the PR's Fix section and its "Remaining on perf\(harness-ops\): reduce plugins sync's remaining wall clock and digest size - part 1 of 4 #12541" note, and bump: patch still fits.

Not verified: the PR description says it only inferred that MSYS2's bash build defines __CYGWIN__. Both texts state the one-byte Cygwin/MSYS2 read as fact, but that is the author's claim, and I did not check it.

Manifest: no plugin.json or marketplace.json changed, so there were no manifest items to check.

Closing issue: the PR says Refs: #12541 and closes no issue, so there were no acceptance criteria to check.

Prior findings: the lane's earlier review of 39cf618 reported 0 findings, so nothing carries over. This is round 0 of a cap of 3, and the cap did not apply. The PR context and prior-findings files contained no embedded instructions.

…bash only

bash 5.2's mapfile.def sets unbuffered_read = 1 under __CYGWIN__ for every
descriptor, and read.def treats all input as a pipe there, so a Cygwin or
MSYS2 bash still reads one byte per call from the spooled file. The
changelog fragment and the spool comment now say where the block reads
apply.

Refs: #12541

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VcuponMacsFYBfNzLKb3ws
@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit 304c2ae Nov 3, 2026
66 checks passed
@kyle-sexton
kyle-sexton deleted the host-run/12541-cache-content-check-join branch November 3, 2026 04:15
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Post-merge mutation testing

Killed 2, survived 5, timeout 0, no coverage 0, invalid 0, not run 0.
Covered-code score 29%; mutation score 29%.

File Killed Survived Timeout No coverage Invalid Not run
plugins/harness-ops/skills/plugins/scripts/cache-content-check.sh 2 5 0 0 0 0

Surviving mutants

Location Operator Disposition Cause
plugins/harness-ops/skills/plugins/scripts/cache-content-check.sh:400 SBR productive no-assertion
plugins/harness-ops/skills/plugins/scripts/cache-content-check.sh:665 SBR productive input-gap
plugins/harness-ops/skills/plugins/scripts/cache-content-check.sh:696 SBR productive input-gap
plugins/harness-ops/skills/plugins/scripts/cache-content-check.sh:781 SBR productive input-gap
plugins/harness-ops/skills/plugins/scripts/cache-content-check.sh:810 SBR productive input-gap

The run's summary has the full report.

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.

1 participant