fix(worker): discard impossible cgroup v2 cpu samples - #2436
Open
rosetta-livekit-bot[bot] wants to merge 2 commits into
Open
fix(worker): discard impossible cgroup v2 cpu samples#2436rosetta-livekit-bot[bot] wants to merge 2 commits into
rosetta-livekit-bot[bot] wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: 42c4fe0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 38 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Ports livekit/agents#7113.
Measures elapsed time around cgroup v2 CPU reads and discards deltas that are negative or exceed the physical host CPU ceiling. Discarded reads retain the last valid load so torn hypervisor counters cannot make an idle worker appear full or a busy worker appear idle.
Adds the source regression coverage for measured elapsed time, negative and over-ceiling deltas, first-sample behavior, the reported torn-read sequence, ceiling behavior, and quota bursts. Includes a patch changeset for
@livekit/agents.Source diff coverage
Source diff coverage
livekit-agents/livekit/agents/utils/hw/cpu.py->agents/src/cpu.ts. The existing TypeScript cgroup v2 monitor now uses Node’s monotonicperformance.now(),os.cpus().lengthfor the physical host ceiling, and the target Pino logger. The source behavior is otherwise preserved: impossible deltas warn and return the last valid sample, while accepted quota bursts clamp to full load.tests/test_cpu_monitor.py->agents/src/cpu.test.ts. All source-added tests are ported with Vitest fake timers and mocked monotonic time in milliseconds. The target worker reports samples directly and has no productionMovingAveragecounterpart, so the reporter-pattern test computes the same five-sample average locally without introducing unrelated runtime averaging behavior.Validation
pnpm test agents(151 files passed; 2,498 tests passed, 5 skipped)pnpm build(39/39 workspace tasks passed)pnpm lint(39/39 workspace tasks passed; existing warning-only findings remain outside changed files)pnpm --filter @livekit/agents typecheckpnpm exec prettier --check agents/src/cpu.ts agents/src/cpu.test.ts .changeset/tidy-cpus-rest.mdPorted from livekit/agents#7113
Original PR description
Problem: On some hypervisors the root cgroup
usage_useccounter returns a torn per-cpu sum, andCGroupV2CPUMonitor.cpu_percentturns that one read into a 1.0 or a large negative sample. Four such samples in the five-slot load average mark an idle worker FULL for 2.5 s, and a call that lands in that window gets no server.Fix: The monitor measures elapsed time around the two reads and discards a delta that is negative or above
elapsed x host cpus, since no host can produce either. A discarded sample returns the last good value instead of a fresh number, so the average is unchanged on idle and busy hosts alike.Fixes #7102. Supersedes #7103.
Context for reviewing and coding agents