Skip to content

perf(distribution): replace grep control-char check with Bash cntrl class - #358

Merged
kyle-sexton merged 2 commits into
mainfrom
cursor/sync-manifest-control-char-bash-f19e
Aug 12, 2026
Merged

kyle-sexton merged 2 commits into
mainfrom
cursor/sync-manifest-control-char-bash-f19e

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Aug 11, 2026 •

Copy link
Copy Markdown
Member

Summary

Replace the printf | grep control-character probe in is_safe_repo_path with an in-shell Bash [[:cntrl:]] pattern test, eliminating ~109 grep process spawns per validate run.

Includes a 256-byte equivalence fixture proving grep and Bash agree for embeddable bytes (documented intentional delta at LF).

This is part 2 of #316. The issue stays open until Part 1 (Git index batching) lands.

Test plan

  • bash distribution/sync-manifest.test.sh
  • Equivalence suite passes
  • CI green on merge

Related

No linked issue

Open in Web Open in Cursor 

@cursor

cursor Bot commented Aug 11, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@claude

claude Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

Claude finished @kyle-sexton's task in 5m 15s —— View job


Claude's review of #358

Todo list

  • Gather context (CLAUDE.md/REVIEW.md, PR diff)
  • Review distribution/sync-manifest.sh change
  • Review distribution/control-char-equivalence.test.sh
  • Review distribution/fixtures/control-char-equivalence.tsv
  • Review distribution/sync-manifest.test.sh change
  • Post inline findings and summary

Summary

The core change (distribution/sync-manifest.sh:56) swaps a printf | grep control-character probe for an in-shell [[ "$path" == *[[:cntrl:]]* ]] test in is_safe_repo_path. This is a correct, low-risk perf change:

  • CONTROL_RE is still exported and used elsewhere (jq/yq strenv(CONTROL_RE) calls at lines 214–267, 425, 429), so nothing is left orphaned.
  • The [[ ... ]] && return 1 construct is safe under set -euo pipefail — a failing first command in an && list (when it isn't the list's final command) doesn't trigger -e, so this won't prematurely abort the function. This is a legitimate, well-known bash idiom.
  • The one behavioral delta between grep and the new glob test — embedded LF (byte 10) — is real (grep operates line-by-line and never sees a newline as "inside" a line) and is explicitly documented and asserted in the new equivalence test. It's a strictly stricter check (rejects a byte the old grep-based check silently let through), so it can only newly reject paths that were already questionable — not a regression.
  • I independently verified the fixture data (distribution/fixtures/control-char-equivalence.tsv): 256 data rows (bytes 0–255) + header = 257 lines, matching the PR's stated diff size, and spot-checked several rows (byte 0 NUL, byte 32 space, byte 127 DEL) against POSIX cntrl class semantics — all correct, including the byte-0 case where the value can't actually be embedded in a bash string at all (both columns correctly read "no").
  • The behavior-preserving refactor to the dest-paths command lines that showed up when diffing against my local origin/main ref turned out to be a stale-ref artifact (this branch predates commit 3288035/feat(sync-manifest): add dest-paths machine-readable output #354 on main); diffing against the actual GitHub-computed merge ref (pull/358/merge) confirms the real diff is exactly what the PR description states — just the one-line swap plus the two new test files and the 3-line hook in sync-manifest.test.sh. No actual conflict with #354.

One finding posted inline on distribution/sync-manifest.test.sh:808:

  • 🟡 Nit — control-char-equivalence.test.sh matches the *.test.sh glob that harness/shell/run-tests.sh auto-discovers for a whole-suite run (the pattern harness/README.md documents as the standard way to run everything locally). Since it's also explicitly invoked from sync-manifest.test.sh:808, a bare bash harness/shell/run-tests.sh run executes the 256-row equivalence suite twice. CI itself dodges this only because the distribution job happens to invoke sync-manifest.test.sh directly rather than through bare discovery. This is also the only place in the repo where one *.test.sh file invokes another. Given the PR's stated goal is cutting redundant subprocess overhead, worth tightening — either drop the explicit nested call and let discovery handle it, or rename the file off the *.test.sh glob.

Verification note

I read and traced the logic by hand and ran git diff/git show against the actual merge ref to confirm the true diff. I was not able to execute the test scripts myself (bash distribution/sync-manifest.test.sh, bash distribution/control-char-equivalence.test.sh) — script execution required approval that wasn't available in this environment. The PR's Test plan checkboxes (sync-manifest.test.sh, equivalence suite) are author-claimed and unverified by me.
· Branch

Comment thread distribution/sync-manifest.test.sh Resolved
@github-actions

Copy link
Copy Markdown

Claude has reviewed this PR 1 time. The lane skips further automatic reviews after 5; deleting this comment resets the count.

@cursor
cursor Bot force-pushed the cursor/sync-manifest-control-char-bash-f19e branch from 29154df to 890ff0f Compare August 12, 2026 00:14
…l:]]

Replace the printf|grep spawn in is_safe_repo_path with a Bash pattern
test ([[ $path == *[[:cntrl:]]* ]]), removing ~109 grep process spawns
per validate run (issue #316 part 2).

Add distribution/fixtures/control-char-equivalence.tsv and
control-char-equivalence.test.sh proving grep [[:cntrl:]] regex and Bash
glob agree for all 256 single-byte embeddings under LC_ALL=C, except byte
10 (LF): grep line mode misses embedded newlines while Bash correctly
rejects them.

Part 1 (Git index batching in tracked_regular_mode) remains for a follow-up.

Co-authored-by: Kyle Sexton <[email protected]>
@cursor
cursor Bot force-pushed the cursor/sync-manifest-control-char-bash-f19e branch from 890ff0f to 18e3cd4 Compare August 12, 2026 00:14
- Rename control-char-equivalence.test.sh to control-char-equivalence.sh
- Keeps helper out of harness *.test.sh auto-discovery glob

Co-authored-by: Kyle Sexton <[email protected]>
@kyle-sexton

Copy link
Copy Markdown
Member Author

Resolved Claude nit in 0f4ceb9: renamed control-char-equivalence.test.sh → control-char-equivalence.sh to avoid harness *.test.sh auto-discovery double-run while keeping explicit invocation from sync-manifest.test.sh.

Commit signature verified (verified: true). Review thread resolved.

@kyle-sexton
kyle-sexton merged commit 28ef6eb into main Aug 12, 2026
1 check passed
@kyle-sexton
kyle-sexton deleted the cursor/sync-manifest-control-char-bash-f19e branch August 12, 2026 00:38
kyle-sexton added a commit that referenced this pull request Aug 12, 2026
<!-- CURSOR_AGENT_PR_BODY_BEGIN -->
## Summary

Closes #316 (Part 1). Part 2 (grep → Bash `[[:cntrl:]]` control-char
check) already landed in #358.

Batches `git ls-files --stage` and `git hash-object` so production
`validate` uses one of each instead of per-path spawns. Exact
recorded-path attribution is preserved.

## Test plan

- [x] `bash distribution/sync-manifest.test.sh`
- [x] Nested-prefix fixture + spawn-counting shim
- [ ] CI green on merge

## Related

Closes #316

<!-- CURSOR_AGENT_PR_BODY_END -->

<div><a
href="https://cursor.com/agents/bc-e95c74ba-a1a6-4270-b3db-3938d8c4f19e?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-web-light.png"><img
alt="Open in Web" width="114" height="28"
src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a
href="https://cursor.com/background-agent?bcId=bc-e95c74ba-a1a6-4270-b3db-3938d8c4f19e&cursor_ref=pr_footer&cursor_cta=open_in_cursor"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img
alt="Open in Cursor" width="131" height="28"
src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a>&nbsp;</div>

---------

Co-authored-by: Cursor Agent <[email protected]>
Co-authored-by: Kyle Sexton <[email protected]>
kyle-sexton added a commit that referenced this pull request Sep 7, 2026
<!-- CURSOR_AGENT_PR_BODY_BEGIN -->
No related issue: remaining Bash spawn N+1 after #316/#361, ranked by
spawn census rather than file size.

## Summary

Measurement-first Bash performance pass, following the fleet
`performance@melodic-software` plugin (spawn count over wall clock,
stable PATH shim, interleaved repeats) and the patterns already landed
in #320/#358/#361.

`distribution/sync-manifest.sh` is already a Node wrapper; this change
does not touch it.

Highest-impact remaining subjects on this repo, in order:

1. `check-exec-bit.sh`: **133 → 4** process spawns (**git 131 → 2**)
against 65 shebang-looking blobs.
2. `scan-comment-hygiene.sh`: **81 → 3** (**awk 77 → 0**) — one awk per
git-grep hit.
3. `check-machine-specific-paths.sh`: **10 → 1** (**git 5 → 1**, **head
5 → 0**).
4. `scan-workflow-files.sh`: **yq 11 → 1** on the success path (CI glob
is 11 workflow files).
5. `check-plugin-baseline.sh --compare`: **jq 5 → 3**.
6. cloud-bootstrap warm path: **5 Claude list CLIs → 2**.
7. `setup.sh` plugin stage (fleet+repo, warm): **4 Claude list CLIs + N
grep → 2** (same list-once shape as cloud-bootstrap).
8. `check-claude-settings-targets.sh --file`: **jq 3 → 2** on the
success path.
9. `check-heading-cites.sh`: drop the identity `cat` when `EXCLUDE` is
empty.

Host qualification (`bash -c true`, n=20): spread 1.66× (measurable).
Headline metric is still the drift-immune spawn counter.

## Fix

- **exec-bit**: one `git grep --cached -z -nIE '^#!'` (line 1 ≡ byte-0
shebang) plus one `git ls-files --stage -z` with exact-recorded-path
mode lookup. POSIX awk join (bash 3.2: no `declare -A`). Combined `-z
-n` emits `path NUL lineno NUL text LF` (git 2.43 byte dump; git-grep(1)
only mentions pathname delimiting). The 100644 shebang case fails
closed; a contract test pins that record via `tr '\0' '|'`.
- **comment-hygiene**: `chp::scan_text` matches the comment-start
pattern in-process for newline-free content (the local-lane git-grep hit
shape). Multi-line callers still use one awk.
- **machine-specific-paths**: one combined `git grep -E` over the five
OS/repo bodies; classify hits in-process so per-OS labels and the
20-line cap stay without a second grep or `head`.
- **heading-cites**: split the corpus pipeline so an empty `EXCLUDE`
does not spawn `cat`.
- **check-plugin-baseline `compare_settings`**: one tagged jq pass,
matching `compare_catalog` and the #320 yq consolidation.
- **cloud-bootstrap**: list marketplaces and plugins once; record
installs locally; re-list marketplaces only when this session registered
a new one. Materialized `.claude/cloud-bootstrap.sh` stays
byte-identical to the component.
- **setup.sh plugin stage**: share one `marketplace list` and one
`plugin list` across fleet+repo; in-process membership instead of `grep
-qxF` per entry; record new installs so the second source does not
re-query. Toolchain tracks (apt/dotnet/nvm) are unchanged.
- **settings-targets**: one jq policy pass on the success path; `jq
empty` on the candidate runs only when that pass fails, so parse errors
stay exit 2 and policy misses stay exit 1.
- **pin-comment**: one `yq eval --no-doc` over every existing workflow
argument on the success path (`filename` operator; without `--no-doc`,
`---` document separators are misread as records). Mike Farah yq 4.53.3
multi-file `eval` still stops at the first parse error and has no
`try`/`catch`, so a failed batch falls back to per-file `pcc::scan_text`
and still reports every file.

Left unchanged after census (already at floor, tiny corpus, or
I/O-dominated): `sync-manifest` Node engine, setup.sh apt/dotnet/nvm,
private-repo-inventory (tiny TOML), `repin::ahead_of` (release-time,
small N).

## Verification

- `bash harness/shell/run-tests.sh` — previously 19 passed, 0 failed, 16
skipped on the earlier commits; this revision adds spawn-census coverage
in `pin-comment-convention.test.sh`.
- `comment-hygiene.test.sh`: 8 single-line scans awk=0; multi-line
fixture awk=1
- `local-lane-guards.test.sh`: exec-bit 8-file git shim (grep=1,
ls-files=1, cat-file=0); 100644 shebang fails closed; `git grep -z -n`
layout `bad.sh|1|#!/usr/bin/env bash`; machine-paths git=1 head=0;
comment-hygiene driver awk=0; start-of-line Linux home still labeled
- `check-plugin-baseline.test.sh`: `--compare` jq=3
- `cloud-bootstrap.test.sh`: warm path marketplace-list=1,
plugin-list=1; copies identical
- `setup.test.sh`: fleet+repo warm path marketplace-list=1,
plugin-list=1, marketplace-add=0, plugin-install=2 (beta+gamma); `bash
-n` and stamp-after-wait contracts unchanged
- `check-claude-settings-targets.test.sh`: `--file` success-path jq=2;
malformed candidate still exits 2
- `pin-comment-convention.test.sh`: 8 conforming files yq=1; parse-error
fallback still reports a later missing-comment (batch + per-file yq=4)

| subject | before | after |
| --- | --- | --- |
| `check-exec-bit.sh` | 133 (`git=131`) | **4** (`git=2`) |
| `scan-comment-hygiene.sh` | 81 (`awk=77`) | **3** (`awk=0`) |
| `check-machine-specific-paths.sh` | 10 (`git=5` `head=5`) | **1**
(`git=1`) |
| `scan-workflow-files.sh` (CI glob, success) | 11 yq | **1** yq |
| `--compare` identical fleet list | 10 (`jq=5`) | **6** (`jq=3`) |
| `check-heading-cites.sh` | 8 (incl. `cat=1`) | **7** (`cat=0`) |
| `setup.sh` plugin stage (fleet+repo, warm) | 4 Claude list CLIs + N
grep | **2** (`grep=0`) |
| `check-claude-settings-targets.sh --file` | 3 jq | **2** jq |

Grounding: GNU/Git `cat-file --batch` / `ls-files --stage` / `grep`
(batch vs per-object); Google Shell Style Guide “builtin vs external”
and no UUOC; this repo’s #320/#361 spawn-census method; performance
plugin harness-integrity (stable PATH, fail closed, commit before
verify); [yq file
operators](https://mikefarah.gitbook.io/yq/operators/file-operators).

## Related

- Follows #320, #358, #361 and closed #316 (sync-manifest remaining
spawns; engine now Node).
- Sources: [Git cat-file batch](https://git-scm.com/docs/git-cat-file),
[Git ls-files](https://git-scm.com/docs/git-ls-files), [Git
grep](https://git-scm.com/docs/git-grep), [Google Shell Style
Guide](https://google.github.io/styleguide/shellguide.html), [BashFAQ
001](https://mywiki.wooledge.org/BashFAQ/001), [performance
plugin](https://github.com/melodic-software/claude-code-plugins/tree/main/plugins/performance),
[yq file
operators](https://mikefarah.gitbook.io/yq/operators/file-operators).
<!-- CURSOR_AGENT_PR_BODY_END -->

<div><a
href="https://cursor.com/agents/bc-c3a723a2-54d9-4964-854f-cda78e9fcba6?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-web-light.png"><img
alt="Open in Web" width="114" height="28"
src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a
href="https://cursor.com/background-agent?bcId=bc-c3a723a2-54d9-4964-854f-cda78e9fcba6&cursor_ref=pr_footer&cursor_cta=open_in_cursor"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img
alt="Open in Cursor" width="131" height="28"
src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a>&nbsp;</div>

---------

Co-authored-by: Cursor Agent <[email protected]>
Co-authored-by: ksextonmelodic <[email protected]>
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