cmux-tui: read the registry identity without the registry lock

Merged
AU
4d ago
+27-2

Summary

Part of the cmux NEXT lag audit (https://github.com/manaflow-ai/cmux/issues/27698 has the connection-limit side).

On a loaded nightly-next Mac, server-stats over 3.7 hours showed the workspace registry lock as the daemon's bottleneck:

  • waits: p50 14 ms, p90 5.2 s, p99 16.8 s, max 144 s;
  • holds: p99 655 ms, max 94 s;
  • 67,948 stalls across 155,310 acquisitions.

The app's 2 s requests timed out behind it: put-frontend-projection (629 times), close-workspace (537), list-workspaces resyncs (181, with a 10 s budget), identify (281).

Mux::registry_identity() took that lock only to read the registry's id and generation, two values fixed when the registry opens. Generation changes only on a reopen, which builds a new Mux. About twenty request paths read them, including:

  • every resource mutation's reply (resource_router::mutation_result);
  • list-workspaces;
  • identify (cmd_server);
  • attach generation checks (cmd_attach);
  • terminal commands (cmd_terminals).

So each of those requests queued behind a durable commit a second time, just for two constants. The pair is now read once in Mux construction, the same way session_public_id is, and returned without the lock.

Testing

Regression test: registry_identity_does_not_wait_on_the_registry_lock in cmux-tui-core/src/mux/tests/workspaces.rs. It holds the registry lock on one thread and reads the identity from another, with a 5 s bound.

  • Red: ./scripts/verify-cmux-tui-hosted.sh --filter registry_identity_does_not_wait_on_the_registry_lock at af7d305c9ce042e5553922aae28fe582f1ae2348 (test only): RESULT_RED
  • Green: the same command at the head: RESULT_GREEN

Observed / Not run

  • Observed: the server-stats and app error-journal numbers above, on the nightly-next app's session daemon.
  • Not run: no before/after latency measurement on a loaded daemon. This removes one lock acquisition per affected request. The registry lock's other holders (durable commits with a synced WAL write each, personal_snapshot) still contend, and are listed in the audit as follow-ups.

Performance

No perf numbers: this removes one registry-lock acquisition per identity read; no before/after harness was run on a loaded daemon. The server-stats lock wait and hold numbers in the Summary are the observed baseline that motivated it.

Changelog

Fixed: cmux NEXT requests that only read the session's identity no longer wait behind saves on a busy Mac.

šŸ¤– Generated with Claude Code