Skip to content

fix(harness-config): find why the audit engine ran 20 minutes with no output #6258

Closed

Description

@kyle-sexton

Problem

On one Windows 11 machine, /harness-config:audit's engine ran for about 20 minutes without
printing anything and was stopped. The root cause is not known. This issue is a diagnosis: measure
where the time goes, name the cause with a measurement, then fix it or file the fix.

What happened (2026-10-04 Windows performance audit, Claude Code 2.1.289, Git for Windows):

  • audit-engine.sh --table printed nothing in 280 s in the foreground, nor in about 15 more
    minutes in the background. It was stopped by hand. Whether it hung or was still working is not
    known.
  • The run was rooted in the home directory, not a repository. 84 plugins were enabled at user
    scope, with 254 to 256 hook registrations. The audit counted "507 permission deny rules (42 ask,
    137 allow)" in the settings file; the 507 may count the whole permissions block, so read it as
    roughly 500 to 700 rules. The melodic-software marketplace was a local directory source, and 77 plugins
    diverged between the loaded directory and the registry cache.
  • The engine's hook-inventory step, check-hook-coverage.sh --json, ran on its own and finished.
    Its timing was not recorded.

Paths are relative to plugins/harness-config/skills/audit/scripts/. Line numbers are on
origin/main 5779559.

Evidence

Verified this pass by reading code only. The engine was not run.

  • Silence does not tell a hang from a slow run. The engine prints nothing until it finishes.
    Rows collect in shell arrays (audit-engine.sh:340-377), and the --table text is printed only
    in the assemble step (:2104-2186). Only fatal errors go to stderr earlier. A run 1 second from
    done and a run stuck forever look the same.
  • The network calls are time-bounded, so the network is unlikely to be the cause.
    • The docs fetcher uses curl --connect-timeout 15 --max-time 120
      (plugins/harness-config/scripts/fetch-docs.sh:193).
    • The plugin drift check's curl uses --max-time 15 (check-plugin-drift.sh:237).
    • claude --version runs under timeout 30 when timeout exists (audit-engine.sh:645-650).
  • A home-rooted run audits one file twice. With no git toplevel, the project root falls back to
    CLAUDE_PROJECT_DIR or $PWD (plugins/harness-config/lib/resolve-scopes.sh:37-39). In the
    home directory, the project settings path $PROJECT_ROOT/.claude/settings.json
    (audit-engine.sh:310) is the same file as the user settings, so every per-rule and per-key
    check runs once per scope.

Code-level suspects. Each is a hypothesis; none was measured.

  1. Per-row process spawning.
    • Every finding row starts about 10 processes: anchor_for_excerpt runs sed and two
      sha256/cut pipelines (:130-137), finding_id runs sort, sha256 and cut (:139-156), and
      row runs two jq -cn calls (:364-370).
    • A non-finding row still starts one jq (:373-375). There are 102 row call sites, many
      inside loops over hooks (:1408-1484), permission patterns (:1245 onward) and plugins.
    • The audit measured process start cost on this host at bash 53 ms, node 95 ms and python
      85 ms (medium confidence). Thousands of spawns at that rate take minutes, more while other
      sessions load the machine.
  2. Per-key greps over the claude binary.
    • For each settings key not documented on settings-reference, the engine runs
      grep -aqE over the whole installed claude binary (:1043-1056). A miss reads the entire
      file.
    • For each hit, bin_describe runs grep -aoE with a [^;{}]{0,800} tail over the whole
      binary (:1029-1040). That bounded repetition can be slow in GNU grep. How many keys this
      machine sent down this path is not known.
  3. The plugin drift check (check-plugin-drift.sh, 653 lines, called at :1700-1710) over 84
    plugins with 77 divergent.
  4. The hook loop over about 256 hooks (:1408-1484). It runs path resolution and several
    rows per hook, on top of the inventory check-hook-coverage.sh already built.

What the item claimed and this pass did not confirm: nothing beyond the facts above. The item gave
no cause, and none is asserted here.

Proposed approach

Step 1, reproduce and measure. Do this before changing any engine code.

  1. Build a synthetic fixture the size of the observed config: a settings file with about 700
    permission rules, about 250 hook registrations across 80 or more plugin directories, some
    undocumented keys, and a home-rooted layout where project and user settings are the same file.
    Point the engine at it through its test seams (audit-engine.sh:61-75):
    • SETTINGS_AUDIT_ENGINE_FIXTURE_DIR
    • SETTINGS_AUDIT_ENGINE_USER_DIR
    • SETTINGS_AUDIT_ENGINE_INSTALLED_JSON
    • FETCH_DOCS_FIXTURE_DIR, for offline docs
  2. Time the phases without editing the script:
    PS4='+ $EPOCHREALTIME $LINENO ' BASH_XTRACEFD=3 bash -x audit-engine.sh --json 3>trace.log >/dev/null.
    The trace goes to its own descriptor, apart from the engine's stderr. Write trace.log to a
    scratch directory, then sum the elapsed time per section, using the # --- section headers as
    boundaries. Tracing adds its own overhead, so compare sections with each other rather than
    reading absolute times.
  3. Bisect with the existing switches:
    • SETTINGS_AUDIT_ENGINE_SKIP_DRIFT=1 removes the drift check.
    • SETTINGS_AUDIT_ENGINE_CLAUDE_BIN='' skips the binary greps (:637-641, :1043).
    • Compare a run where the claude binary is present against one where it is absent.
  4. If the fixture does not reproduce a run of several minutes, run step 2 once on a real
    home-rooted machine of that size. Record the per-section times, not the trace, because the
    trace holds settings values.

Step 2, fix by measured cause. The likely remedies, matched to the suspects above. Pick one only
after step 1 names the cause.

  • Suspect 1: build rows in one jq pass per category instead of per row, and hash identities in
    one batched pass.
  • Suspect 2: read the binary once (one grep -aoE over the alternation of all leaf names, or a
    strings pass cached per run) instead of once per key.
  • Suspect 3: cap or parallelize per-plugin work in the drift check.
  • Home-rooted runs: skip the project scope when it is the same file as the user scope. The
    engine already compares file identity for settings.local.json (:406).

Independent of the cause, recommended: write one progress line per category to stderr, for
example audit-engine: D hooks (256). A slow run then shows where it is, and an operator can
tell slow from stuck. The SKILL.md Phase 1 block (SKILL.md:112-121) should also say how long a
large config takes and that a long run belongs in the background.

Acceptance criteria

  • Per-section wall times are recorded on this issue for a home-rooted run with at least 700
    permission rules and 250 hooks (fixture or real), each with the configuration that produced
    it.
  • A named root cause is stated with the measurement that shows it, or the issue records that
    the run completes in under N minutes on that config and only the silence was the defect.
  • The engine writes at least one stderr progress line per category during a --table or
    --json run, and a test asserts it without changing stdout.
  • The fix for the named cause lands here, or is filed as its own issue and linked.
  • On the same fixture, the full --table run finishes within a budget recorded in SKILL.md,
    or SKILL.md tells the agent to run it in the background with a stated expected duration.

Constraints and gotchas

  • Do not run the real engine against a person's live settings to diagnose this without asking.
    The trace and the --json output hold settings values; keep them in a scratch directory and
    publish only timings.
  • The engine's contract is to never execute a hook (audit-engine.sh:49-54). Keep it.
  • Git Bash on Windows: jq appends CR to stdout lines (:83-86). Any batching change must keep the
    tr -d '\r' handling.
  • Row identities (finding_id) are a contract with /harness-config:audit-pass and with
    suppression records. A batched rewrite must produce byte-identical ids. Prove it against the
    existing tests in audit-engine.test.sh.
  • Bump the harness-config version and add a CHANGELOG line, per the repo's release convention.

Context

Part of the 2026-10-04 performance audit, parent #6244.

Source: local handoff item 20261004-152632-claude-perf-audit-tooling-bugs.md, bug 5 (retired into
this issue). Related history: #4206 (Windows defects in this engine), #3989 (engine made
script-first), #6090 (drift reads the marketplace renames map).

Activity

  1. github-actions commented on Oct 4, 2026

    @github-actions
    Contributor

    Thanks for this. I understand the problem as: on a home-rooted run with a large config (~84 plugins, ~255 hooks, ~500-700 permission rules), audit-engine.sh --table produced no output for well over 20 minutes and was stopped, with the root cause (slow vs. hung) unconfirmed. The report already lists concrete suspects (per-row process spawning, per-key greps over the claude binary, the plugin drift check, the hook loop, and double-auditing when project/user settings resolve to the same file), a reproduction plan using the engine's existing fixture env vars, and acceptance criteria requiring measured per-section timings, a named cause, and a stderr progress line per category.

    Nothing appears missing to start the work: the proposed approach already specifies how to build a synthetic fixture and bisect with existing switches (SETTINGS_AUDIT_ENGINE_SKIP_DRIFT, SETTINGS_AUDIT_ENGINE_CLAUDE_BIN). I didn't find an existing issue duplicating this specific diagnosis; it links its own related history (#6244 parent, #4206, #3989, #6090).

    Automated triage. A maintainer reviews it.

  2. kyle-sexton commented on Oct 4, 2026

    @kyle-sexton
    MemberAuthor

    Timed reproduction and cause

    Reproduced on a real configuration, Windows 11, Git for Windows bash 5.3.15, jq 1.8.2, Claude Code 2.1.289 (a 249 MB binary). The host was busy with other sessions. Only timings and counts are published here; every trace and output stayed in a scratch directory.

    Configuration. 83 enabled plugins at user scope (8 more at project scope in the repo-rooted run), 79 resolved for the hook inventory, 259 hook registrations, 72 plugins diverging between a directory marketplace and the registry cache. User settings hold 512 deny, 43 ask and 141 allow rules (696; the repo-rooted run adds 7 project denies, 703). A 56-entry user suppression record.

    It does not hang. Every phase finished. The silence was the engine printing nothing until assembly.

    Before: per-phase wall time, repo-rooted, bash -x trace

    Traced total 584 s (tracing adds overhead; compare phases with each other).

    Phase Seconds
    Hook inventory (check-hook-coverage.sh, child) 242.9
    D hook loop 121.5
    E plugin dependencies and E rows 76.6
    Suppression record load (56 entries) 44.6
    B permissions 29.9
    Docs fetch (network) 13.7
    settings-reference parse 11.7
    check_keys 7.4
    Plugin drift (check-plugin-drift.sh, child) 4.5
    Binary key search (1 undocumented key) 1.9
    Everything else under 30 combined

    The hook inventory alone, run standalone: 147 s (plugin loop 99 s for 79 plugins, JSON output 45 s for about 420 jq calls).

    Untraced, with docs read from disk (--docs-dir) and drift skipped: 400 s and 411 s repo-rooted, 344 s home-rooted (SETTINGS_AUDIT_ENGINE_FIXTURE_DIR=$HOME, so the project and user scopes are the same file).

    Cause: one or more processes per row, per hook and per plugin

    Process starts on this host: jq -cn 1 140 ms, printf | sha256sum 160 ms, a $( ) subshell 40 ms when idle; 545 ms, 525 ms and 130 ms while an engine run was in progress.

    Counted with PATH shims on the repo-rooted run (docs from disk, drift skipped): 4,247 external process starts: 1,435 jq, 1,163 tr, 545 cut, 310 base64, 292 grep, 274 sha256sum, 127 sort, 72 sed, the rest under 20. Subshell forks are on top of that.

    Where they came from: every row ran 1 to 3 jq calls, and every finding row about 10 more processes for its anchor and id; the hook inventory ran about 15 processes per plugin and one jq per hook, plugin and divergence node it printed; each category E row decoded 7 fields with 7 base64 calls; each plugin's plugin.json was read with its own tr | jq.

    Ruled out by the numbers: the network (docs 13.7 s, all bounded), the binary greps (1.9 s; one undocumented key here), the drift check (4.5 s repo-rooted, 13 s in the home-rooted default run).

    After: commit fe1d087 on perf/6258-audit-engine-timing

    • 810 external process starts on the same run (275 jq, 202 sha256sum, 278 tr).
    • Repo-rooted, docs from disk, drift skipped: 76 to 86 s (three runs). Home-rooted, same settings: 63 s.
    • Home-rooted full default --table run (network docs fetch and drift check included): 106 s.
    • --json documents and --out findings files are byte-identical to the old engine's, repo-rooted and home-rooted. The standalone hook inventory output is byte-identical too (147 s to 20 s).
    • The engine writes one audit-engine: <category> ... (<seconds>s) line per category to stderr. Home-rooted full run: docs 10 s, A 20 s, D inventory 25 s, B 58 s, D checks 61 s, E 75 s, E drift 79 s, F 92 s, assemble 101 s. SETTINGS_AUDIT_ENGINE_PROGRESS=0 turns the lines off.
    • Regression test (audit-engine.test.sh case 55): it counts jq starts through a PATH shim on configs with 5 and 60 hooks, deny rules and disabled plugins, and asserts the counts are equal. On the old engine it fails with 135 against 301; on the new one both are 87. It also asserts a progress line per category and stdout unchanged with progress on.

    Residual: each finding row still costs two sha256sum starts (about 200 on this config, roughly double for a home-rooted run with many findings). The home-rooted double audit of one file under two scope labels is unchanged; it now costs seconds, not minutes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions