Synced from monorepo
Synced from monorepo Changes: - Workspace server: surface preview-proxy metrics through the hub metric pump - Shell: reclaim a session’s retained state in one entry - Shell: reclaim a session’s resident state in one entry - Pager: withhold key event types from Alacritty builds that double keys - Tools: cancel a session’s subagents when it closes - Pager: keep the whole plan in scrollback and separate reasoning from output in minimal mode - Pager: probe terminal version over DA2 and include it with feedback - SuperGrok Plus: identity, CLI, and analytics tier surfaces - Shell: inherit the session process scope into subagents - Pager: build @-file-search matcher lazily on first use - Tools: fix description and output contradictions in tool definitions - Workspace: degrade @-file-search instead of aborting on thread exhaustion - Tools: reap a session’s LSP servers when it closes - Tools: fix contradictions and defects in tool descriptions, schemas, and harness pools - MCP: reap stdio MCP children on session close - Shell: reuse spawn-time skill discovery for session telemetry - Tools: stop leaking shell-wrapper positional params into sourced scripts (fixes activate_conda under persistent/static shell) - Shell: self-heal corrupt session-search SQLite cache - Workspace: cap workspace-server tokio workers on many-core hosts - Shell: reap a session’s child processes when it closes - Crash handler: capture SIGABRT so panic-aborts leave crash reports - CLI chat proxy: team-scoped Grok Code managed-config admin routes - MCP: add CLI enable/disable for MCP servers - Shell: cap tokio worker threads for startup thread demand - Workspace: harden git_commit and add git_sync_base operation - Circuit breaker: add feature-gated gRPC retry policy Source-Revision: 2a818575225183d8ca915f5632a09b8067b5156a
This commit is contained in:
parent
02d9359435
commit
5da6962e4a
192 changed files with 10337 additions and 3421 deletions
55
crates/codegen/xai-tty-utils/src/runtime.rs
Normal file
55
crates/codegen/xai-tty-utils/src/runtime.rs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
//! Worker-thread policy for multi-thread tokio runtimes.
|
||||
//!
|
||||
//! Tokio defaults to one worker per core. On many-core shared hosts (100+-core
|
||||
//! HPC login nodes) that pins 100+ thread slots per grok process against
|
||||
//! per-user ceilings — systemd user-slice `pids.max` (commonly 1000) or
|
||||
//! `RLIMIT_NPROC` — and later thread spawns die with EAGAIN. Grok's runtimes
|
||||
//! are I/O-bound, so throughput does not scale with workers past a small
|
||||
//! count.
|
||||
//!
|
||||
//! This is the single home for the cap policy; every multi-thread runtime in
|
||||
//! the workspace (the `grok` binary, the `workspace_server` daemon) derives
|
||||
//! its worker count from here so the policy cannot drift across crates.
|
||||
|
||||
use std::num::NonZeroUsize;
|
||||
|
||||
/// Maximum runtime worker threads for any grok process.
|
||||
pub const MAX_WORKER_THREADS: NonZeroUsize = NonZeroUsize::new(8).unwrap();
|
||||
|
||||
/// Pure, testable: `min(cores, MAX_WORKER_THREADS)`.
|
||||
pub fn cap_worker_threads(cores: NonZeroUsize) -> NonZeroUsize {
|
||||
cores.min(MAX_WORKER_THREADS)
|
||||
}
|
||||
|
||||
/// Reads the host: `min(available_parallelism, MAX_WORKER_THREADS)`.
|
||||
pub fn capped_worker_threads() -> NonZeroUsize {
|
||||
cap_worker_threads(std::thread::available_parallelism().unwrap_or(NonZeroUsize::MIN))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn nz(n: usize) -> NonZeroUsize {
|
||||
NonZeroUsize::new(n).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cap_is_identity_at_or_below_max() {
|
||||
assert_eq!(cap_worker_threads(nz(1)), nz(1));
|
||||
assert_eq!(cap_worker_threads(nz(4)), nz(4));
|
||||
assert_eq!(cap_worker_threads(nz(8)), nz(8));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cap_clamps_many_core_hosts() {
|
||||
assert_eq!(cap_worker_threads(nz(9)), nz(8));
|
||||
assert_eq!(cap_worker_threads(nz(360)), nz(8));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn capped_worker_threads_stays_in_bounds() {
|
||||
let n = capped_worker_threads();
|
||||
assert!(n <= MAX_WORKER_THREADS, "got {n}");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue