Skip to content

perf(harness-ops): drop per-id jq spawns from plugins sync and time each CLI call - #12540

Merged
kyle-sexton merged 2 commits into
mainfrom
fix/harness-ops-sync-perf
Nov 2, 2026
Merged

kyle-sexton merged 2 commits into
mainfrom
fix/harness-ops-sync-perf

Conversation

@kyle-sexton

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

Copy link
Copy Markdown
Member

Summary

Refs #12532.

This removes the per-plugin process spawns that made /harness-ops:plugins sync scale with the number of updated plugins, and records each claude call's time, so later runs can separate CLI time from script time.

  • Baseline. run_cli appends # elapsed <s>s, exit <rc> to journal.log after each call's output. Each digest block carries cli: {calls, seconds}, and timings.total - cli.seconds is the script's own time. cli.seconds includes the journaling tee pipeline, about 50 ms per call on Git Bash.
  • Sweep. Each update result is read with one jq (cli_update_result). cli_json reads every candidate line in one jq. Every id's installed version comes from one read of mid.<mp>.json.
  • Finalize.
    • finalize_moves joins the move ledger to post.<mp>.json in one read.
    • Rows are built with json_string_to, in the same key order and escaping as jq -c.
    • version_direction_to gives the comparison without a subshell.
    • monitor_rows reads every install path in one pass, and monitor_count_at skips jq for a manifest whose text never mentions monitors when there is no default monitors/monitors.json.
  • Step 3a. The settings check reads .claude/settings*.json with a builtin instead of cksum, and asks rev-parse once per path. path_row is built without jq.
  • --only-install re-entry. It still rebuilds the whole digest from the move ledger, as before, rather than only the installed ids. That rebuild now costs about 1 s for 91 rows, so storing the first pass's rows was not needed.

Measurements

The bench is this host's install records with all 92 melodic-software user records set below the catalog. It reads the real catalog clone and uses a stub CLI and a stub cache checker, so it measures the script's own overhead. Each step was measured on its own.

Step Total user_sweep finalize
main 113.2 s / 134.1 s 68.0 s / 80.5 s 34.7 s / 43.4 s
+ call timing 98.8 s 57.0 s 31.4 s
+ sweep parse 75.2 s 39.0 s 27.8 s
+ finalize/monitors 41.9 s 31.5 s 1.8 s
  • Re-entry, one install: 28.4 s to 4.4 s (finalize 23.5 s to 1.1 s).
  • Near-no-change run (24 updates, 49 other-path calls): 30.1 s to 18.3 s.
  • Report unchanged: the digest blocks match main apart from the run directory path.

On a real host the re-entry still pays the CLI install and enable calls, three fleet-state reads (about 1.5 s each) and the real cache-content check. #12532 records the remaining floor and the owner decisions this PR does not take.

Test plan

  • sync-run.test.sh: 630 pass, 4 fail locally on Windows Git Bash; the same 4 fail on unmodified main (628 pass): --only-install: and only INSPECTED the project-scope map and three render goldens (divergence by path, no project root, divergence split, no project root, divergence split, project root) whose diffs show only line endings. The 2 extra passes are the new cli and journal # elapsed assertions.
  • shellcheck -x and shfmt -i 2 -d clean on sync-run.sh
  • Bench digests compared field by field against main (first pass and re-entry)

🤖 Generated with Claude Code

https://claude.ai/code/session_01QBsfckuVYk2asB2jFSTNjE

kyle-sexton and others added 2 commits November 2, 2026 17:30
…ach CLI call

The user sweep parsed every update result with four or more jq calls, and
finalize spent several jq calls and a subshell on each moved row, so a run
with 87 updates paid about 40 s in finalize and an --only-install re-entry
paid it again for one install.

- run_cli journals each call's wall time and each block carries
  cli: {calls, seconds}, so CLI time and script time can be told apart.
- The sweep reads each result line with one jq and takes every id's
  installed version from one read of the snapshot.
- finalize_moves joins the ledger to the post snapshot in one read and
  builds rows with builtins; version_direction has a no-subshell form.
- monitor_rows reads every install path in one pass and skips jq for a
  manifest that never mentions monitors.
- Step 3a's settings check reads the files with a builtin instead of cksum
  and asks rev-parse once per path; path_row is built without jq.

Bench with a stub CLI, 92 updates: 113 s to 42 s first pass, 28 s to
4.4 s re-entry, identical digest blocks.

Refs #12532

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QBsfckuVYk2asB2jFSTNjE
…ns sync

jq 1.7's last() of nothing yields null, which cli_json and
cli_update_result would read as a found result line; `values` drops it.

Refs #12532

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QBsfckuVYk2asB2jFSTNjE
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

PR body contract — issue linkage

This PR body does not yet satisfy the issue-linkage contract:

  • Missing a "## Fix" section. State the concrete change and how it addresses the problem.
  • Missing a "## Verification" section. Record concrete evidence the change works (commands, gates, output).
  • Missing a "## Related" section. List related PRs, ADRs, or decision-log entries this PR does not close.
  • Missing a native closing keyword (Closes/Fixes/Resolves #N). If this PR references an issue it must not close, put "Refs: #N" (or "Relates to: #N") on its own line. If it relates to no GitHub issue at all, state "No linked issue" (or "No related issue:") in the body instead.

Edit the body and this comment updates itself on the next run.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 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-02T23:14:19.948054Z df479e8 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 2, 2026

Copy link
Copy Markdown
Contributor

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

Security review: PR #12540 (perf(harness-ops): fewer jq spawns in plugins sync, a timer on each CLI call)

I found no security issues.

The scope was all 4 changed files, every hunk read: the .changes entry, context/sync.md, sync-run.sh and sync-run.test.sh. None of them match a trusted path. The PR touches no workflow, plugin manifest, trust control, merge hold or standing instruction.

What I checked

  • Settings content in settings_state. It now keeps the raw bytes of .claude/settings*.json instead of a cksum. Those files can hold secrets, so I checked where the value goes. It is only compared before and after a call (sync-run.sh lines 1363–1373 and 1764–1791). It is never written to the journal, the digest or a report row, so nothing leaks.
  • JSON rows built in the shell. move_row_to, downgrade_row_to, path_row and the monitor rows now build JSON without jq. Every string field goes through json_string_to in jq-capture.sh, which escapes \, ", the short control escapes and every other C0 byte. The fields left unquoted are safe: stopped is a literal true/false from inside the script, monitors is an integer from monitor_count_at, and cli_calls/cli_ms are integers from shell arithmetic. Ids or versions taken from marketplace or CLI data cannot inject JSON.
  • printf -v "$1" targets. Every variable name passed in is a hard-coded name inside the script. None comes from input.
  • The monitor_count_at shortcut. It reports 0 monitors without running jq when a manifest never contains the text monitors or any \u escape and there is no default monitors/monitors.json. A JSON key can only spell monitors with those characters or with \u escapes, so a manifest cannot hide a declared monitor from the report this way. A manifest that does not parse already counted as 0 before this change.
  • Fields joined with \x1f. In finalize_moves, the user sweep and monitor_rows, the joined fields come from the same local snapshot files the old per-id version_at calls read. Splitting a value on a newline or \x1f could only distort a report row. It gains no access, credential or charge, and the move ledger already wrote those values raw before this change.
  • Instruction-surface lens. The sync.md change only adds text documenting the new cli field and the journal line. It removes or softens no rule.

Spend

None. This is a local operator script and changes no CI, billing, model or effort settings.

critical-findings: 0

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

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

Code review: no findings

I read every hunk of all 4 changed files: the changelog fragment, context/sync.md, sync-run.sh and sync-run.test.sh. None of them matches a trusted-path glob. This is round 1 of 3, with no earlier findings and no settled threads.

What I checked against the code at head

  • version_direction_to. The reordered branches give the same results as before for both unparseable versions and tied versions. The caller's variable names (dir, __vd) don't clash with the function's locals.
  • cli_json and cli_update_result. I compared the single jq call (-R -n, last(inputs | try fromjson catch null | select(...)) | values) with the old per-line jq -e loop:
    • A line that isn't JSON becomes null, and the short-circuiting and keeps has off non-objects, so one bad line can't abort the whole program.
    • values keeps jq 1.7's last(empty) == null from reading as a result line.
    • updated / noop / other and the newVersion read match cli_move_result and cli_reported_version for a result line. With no result line, the function still falls back to the text forms.
  • finalize_moves join. post_v, ncat and nlabel follow the same rules as version_at (currentProject unless user scope), .catalog_versions[$id] // "" and the old nlabel query. A missing or unreadable post.<mp>.json drops back to the raw ledger lines with empty fields, which is what version_at returned before. Every later use of ncur, post_v and cur reads the same value as before.
  • Row builders. move_row_to, downgrade_row_to and path_row produce the same key order as the jq -c objects they replace, including the optional kind and concurrent. So the "kind": / "direction":"backward" match in monitor_rows still finds the rows it should.
  • monitor_count_at shortcut. It only skips jq when there is no default monitors/monitors.json. In that case both the false and the unreadable paths already gave a count of 0, so the result can't change.
  • settings_state. It now compares the files' bytes instead of their cksum, which is at least as strict. The cached rev-parse is keyed on the directory.
  • stamp_us and run_cli timing. The arithmetic holds at all three clock resolutions, a negative time is clamped to 0, and both calls in the --json fallback retry are counted. CLI_CALLS / CLI_MS reset per marketplace in reset_marketplace_state. Block-level cli covers only the current pass, the same as block timings on an --only-install re-entry, so the doc text in sync.md (lines 104–107) is accurate.
  • The script runs set -uo pipefail without set -e. So [[ -f x ]] && IFS= read -r -d '' …, which returns non-zero at end of file, doesn't stop the script.
  • Changelog fragment. bump: minor fits a new digest field (cli) plus a fix.

Rules: .claude/rules/skill-bodies-state-current-rules.md and .claude/rules/cost-claims.md cover context/sync.md. The added paragraph describes this repository's own journal format, which is neither a volatile upstream fact nor a price, so neither rule is broken.

Author-claimed, not verified by me: the test-suite counts (630 pass / 4 fail on Windows Git Bash, the same 4 failing on main), shellcheck and shfmt being clean, the bench timings, and digests matching main field by field. I had no shell in this run, so I ran nothing.

The pull request text contains no instructions aimed at this review.

@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 2, 2026
Merged via the queue into main with commit eafe9b5 Nov 2, 2026
95 of 96 checks passed
@kyle-sexton
kyle-sexton deleted the fix/harness-ops-sync-perf branch November 2, 2026 23:27
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Post-merge mutation testing

Killed 4, survived 3, timeout 0, no coverage 0, invalid 0, not run 0.
Covered-code score 57%; mutation score 57%.

File Killed Survived Timeout No coverage Invalid Not run
plugins/harness-ops/skills/plugins/scripts/sync-run.sh 4 3 0 0 0 0

Surviving mutants

Location Operator Disposition Cause
plugins/harness-ops/skills/plugins/scripts/sync-run.sh:692 AOR productive no-assertion
plugins/harness-ops/skills/plugins/scripts/sync-run.sh:1291 ROR productive input-gap
plugins/harness-ops/skills/plugins/scripts/sync-run.sh:1325 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

needs-issue-linkage Pull request body has no issue linkage line; set by the check-contract step, advisory.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant