chore(scripts): add concurrency_audit.sh — Phase 10a baseline tool#303
Merged
Conversation
Walks every workspace member and emits, per crate, the 7-dimension
async/concurrency inventory called out by playbook §1082-1146 and
Phase 10 plan §7:
1. tokio::spawn / detached tasks — every call-site for hand-audit.
2. Locks held across .await — literal .read/.write/.lock().await
sites for Phase-10b hand-audit.
3. Blocking IO inside async — files containing both async fn and
std::fs::* / std::thread::sleep (Phase-10f candidates).
4. Arc<Mutex<...>> patterns — flat + multi-layer nesting.
5. Missing timeouts — IO/network/IPC await sites that need a
tokio::time::timeout enclosure.
6. Missing cancellation handling — spawn sites whose closure body
(next 50 lines) lacks select! / CancellationToken / cancelled()
keywords.
7. Unbounded channels — every unbounded_channel() / broadcast::channel()
site for Phase-10d backpressure audit.
Mirrors the shape of scripts/dev/build_codegen_audit.sh (Phase 9a):
shebang + SPDX header, --with-cargo flag (runs cargo build --tests +
cargo clippy -W clippy::await_holding_lock), workspace-root detection,
RG_PROD_GLOBS filter, Markdown report to stdout.
Prod-only filter excludes test code (tests/, benches/, examples/,
tests.rs / *_tests.rs / *_test.rs / test_*.rs). Note: the **/
recursive prefix is required for directory excludes because UFFS has
in-tree test modules under src/.../tests/ (the canonical Rust pattern)
in addition to top-level crates/*/tests/. Without the prefix,
!tests/** would only match the top-level path.
Detection caveats are documented inline:
* Lock-across-await uses literal regex; multi-line guard-then-await
patterns require Phase-10b hand-audit.
* Cancellation-keyword regex uses word boundaries (e.g. requires
CancellationToken / cancelled() / abort_signal, NOT bare 'cancel'
which would match cancel_tx false-positively).
* Arc<Mutex<...>> output filters doc-comment / block-comment lines
so rustdoc prose doesn't inflate the count.
* Counter uses grep -c '^.' (not grep -c .) so echo '' doesn't
falsely count as 1.
Baseline at SHA ff8b897 (Phase 10 entry — prod-only counts):
* 278 async fn + blocks across 5 crates (daemon=132, mft=74,
mcp=46, client=25, core=1).
* 27 tokio::spawn( sites (daemon=23, mft=3, client=1).
* 53 spawn_blocking sites (daemon=36, mft=15, core=1, client=1).
* 22 std::sync::Mutex/RwLock + 6 tokio::sync::* + 1 Arc<Mutex<>>.
* 36 lock-across-await candidate sites (daemon=34, mcp=2) —
primary Phase-10b audit target.
* 5 bounded + 4 unbounded channels — Phase-10d target.
* 10 prod-code tokio::time::timeout sites — Phase-10e target.
* 24 of 27 spawn sites lack nearby cancellation keywords —
Phase-10c target.
* 14 blocking-IO-in-async candidate files — Phase-10f target.
Runs in ~6 s (pure rg + awk; no cargo invocation in default mode).
Refs #302.
This was referenced May 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 10a of the playbook Phase-10 effort (issue #302). Adds
scripts/dev/concurrency_audit.sh— the workspace concurrency / async / shared-state baseline tool. Mirrors the shape ofscripts/dev/build_codegen_audit.sh(Phase 9a).What it does
Walks every workspace member and emits, per crate, the 7-dimension async/concurrency inventory called out by playbook §1082-1146 and Phase 10 plan §7:
tokio::spawn/ detached tasks — every call-site for Phase-10c hand-audit..await— literal.read/.write/.lock().awaitsites for Phase-10b hand-audit.async fnANDstd::fs::*/std::thread::sleep(Phase-10f candidates).Arc<Mutex<…>>patterns — flat + multi-layer nesting (Arc<Mutex<Arc<…>>>separately flagged)..connect/.read_exact/.write_all/.recv/.accept/...) that need atokio::time::timeoutenclosure.select!/CancellationToken/.cancelled()keywords.unbounded_channel()/broadcast::channel(...)site for Phase-10d backpressure audit.Default mode runs in ~6 s (pure
rg+awk; nocargoinvocation).--with-cargomode also runscargo build --workspace --tests+cargo clippy --workspace --tests -- -W clippy::await_holding_lockas a Phase-10b enforcement-mode preview.Baseline at this SHA (prod-only)
async fn+ async blockstokio::spawn(call sitesspawn_blockingcall sitesstd::sync::Mutex/RwLocktokio::sync::*async locksArc<Mutex<…>>/Arc<RwLock<…>>tokio::time::timeout(sites#[tokio::test]sites (test code)The headline finding is 36 lock-across-await candidate sites in
uffs-daemon(34) +uffs-mcp(2) — significantly more than the initial 7-site estimate in the plan recon. Each will be hand-audited in Phase 10b for "guard held across an inner.await" (the hazard) vs "guard acquired with.awaitand dropped before the next.await" (legitimate).Detection caveats (documented in the script preamble + per-helper comments)
let g = lock(); g.foo(); other.await; drop(g);) require Phase-10b hand-audit to confirm.cancelwould matchcancel_txfalse-positively; we requireCancellationToken/cancellation_token/.cancelled()/is_cancelled/select!/abort_signal/recv_cancel.Arc<Mutex<…>>output filters doc-comment lines. Rustdoc prose referencing the pattern doesn't inflate the count.grep -c '^.'(notgrep -c .) soecho ''doesn't falsely count as 1 (this was caught + fixed during the script's own smoke-test).!**/tests/**(not bare!tests/**) — UFFS has in-tree test modules undersrc/.../tests/which the bare pattern would not exclude.Why this is Phase 10a (audit-tool first)
Mirroring the established Phase 6a / 7a / 8a / 9a cadence:
docs/dev/baseline/2026-05-19/phase_10_concurrency_baseline.md).concurrency_policy.md+ per-crate# Concurrencyrustdoc.Rule-1 adherence
Zero
#[allow]introductions. Script-levelset -uo pipefail(matches sibling audit scripts). One# shellcheck-info-level note (SC2016 —'single quotes don't expand') is intentional: the affected lines emit Markdown backticks literally, not shell variables.Cross-references
docs/dev/architecture/code_clean/phase_10_async_concurrency_shared_state_implementation_plan.mdscripts/dev/build_codegen_audit.sh(Phase 9a — same shape),scripts/dev/feature_dep_audit.sh(Phase 8a),scripts/dev/trait_generic_audit.sh(Phase 7a),scripts/dev/clone_alloc_audit.sh(Phase 6a).world_class_rust_workspace_refactor_playbook.md§1082-1146 (local-only).Verification
bash -n scripts/dev/concurrency_audit.sh→ SYNTAX OKshellcheck scripts/dev/concurrency_audit.sh→ only SC2016 info (intentional, see above)scripts/dev/concurrency_audit.sh > /tmp/baseline.md→ 316-line Markdown report in ~6 sNext steps (queued)
concurrency_policy.md+ per-crate# Concurrencyrustdoc.