Skip to content

perf(tui): migrate runtime_threads maps to parking_lot::Mutex (#4149)#4243

Merged
Hmbown merged 1 commit into
Hmbown:mainfrom
wuisabel-gif:fix/4149-parking-lot
Jul 8, 2026
Merged

perf(tui): migrate runtime_threads maps to parking_lot::Mutex (#4149)#4243
Hmbown merged 1 commit into
Hmbown:mainfrom
wuisabel-gif:fix/4149-parking-lot

Conversation

@wuisabel-gif

Copy link
Copy Markdown
Contributor

Closes #4149 (v0.8.68 §6.1 / B1.2 — finish parking_lot migration at hot lock sites).

I claimed this on the issue before starting — see my comment.

What

RuntimeThreadManager held four synchronous maps behind std::sync::Mutex:

  • task_manager
  • automations
  • pending_approvals
  • pending_dynamic_tools

All four are locked in short, non-async critical sections (attach / register / cancel / deliver / count / snapshot-clone), so they're safe parking_lot::Mutex sites. parking_lot guards are !Send and cannot cross .await; I verified none of these sites hold a guard across an await.

Because parking_lot::Mutex doesn't poison, lock() returns the guard directly — which removes the if let Ok(..) / match ... Err boilerplate at every call site (net −21 lines).

Behavior note

The one intentional behavior change: after a panic while holding one of these locks, callers now continue with the recovered map instead of silently skipping via the poisoned-Err branch. That's the standard, intended parking_lot tradeoff, and for these best-effort registries (pending sender maps, manager slots) continuing is the safer default.

Deliberately left as-is

  • state / activetokio::sync::Mutex, held across .await on purpose; not parking_lot candidates.
  • config — already parking_lot::RwLock.
  • app-server runtime locks (also named in the issue) — those are tokio::sync::{Mutex, RwLock} async locks held across .await; migrating them to parking_lot would be incorrect, so they're out of scope.

Acceptance

  • Hot sites use parking_lot where safe
  • No lock guards cross .await
  • Existing tests pass — cargo check -p codewhale-tui clean; 178 approval/pending tests pass, 0 failed

…#4149)

The RuntimeThreadManager held four synchronous maps behind std::sync::Mutex:
task_manager, automations, pending_approvals, and pending_dynamic_tools. All
are locked in short, non-async critical sections (attach/register/cancel/
deliver/count), so they are safe parking_lot::Mutex sites. parking_lot guards
are !Send and cannot cross .await, and none of these sites do.

parking_lot::Mutex does not poison, so lock() returns the guard directly. This
drops the Result-handling boilerplate (if-let-Ok / match-Err) at every call
site. The only behavior change: after a panic while holding one of these
locks, callers now continue with the recovered map instead of silently
skipping via the poisoned-Err branch, which is the intended parking_lot
tradeoff for these best-effort registries.

Left as-is (correctly): the async state/active locks (tokio::sync::Mutex,
held across .await) and config (already parking_lot::RwLock). The app-server
'runtime locks' named in the issue are tokio async locks, not parking_lot
candidates.

Verified: cargo check -p codewhale-tui clean; 178 approval/pending tests pass.
@wuisabel-gif wuisabel-gif requested a review from Hmbown as a code owner July 8, 2026 18:15
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

Thanks @wuisabel-gif for taking the time to contribute.

This repository is observing a maintainer-managed PR intake gate in dry-run mode, so this pull request is staying open. This note helps maintainers prepare the allowlist before any enforcement is considered.

Please read CONTRIBUTING.md for the expected contribution shape. A maintainer can grant recurring PR access by commenting /lgtm on a pull request.

@Hmbown Hmbown merged commit 6e08bfc into Hmbown:main Jul 8, 2026
14 checks passed

Hmbown commented Jul 9, 2026

Copy link
Copy Markdown
Owner

thank you so much for contributing!!

@wuisabel-gif

Copy link
Copy Markdown
Contributor Author

thank you so much for contributing!!

you're very welcome~

@wuisabel-gif wuisabel-gif deleted the fix/4149-parking-lot branch July 10, 2026 00:50
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.

v0.8.68 6.1: finish parking_lot migration at hot lock sites

2 participants