Repository navigation
jobs: keep the CPU window baseline when sampling drifts past 5 minutes - #471
Merged
Merged
Conversation
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.
What and why
In
JobSupervisor.sample(), the sliding-window cleanup droppedlive.cpu[0]wheneverat - live.cpu[0][0] > CPU_WINDOW_MS, right before checkingat - firstAt >= CPU_WINDOW_MS.Because
setInterval(..., SAMPLE_MS)and the asyncusage()lookup always add at least a few milliseconds of drift, the 11th sample arrives slightly pastCPU_WINDOW_MS(for example 300,010 ms), evicts the oldest sample, and leavesat - firstAtaround 270 s on every tick, so the 5-minute CPU limit never triggers in practice.This changes the loop to drop
live.cpu[0]only whilelive.cpu[1]is still at leastCPU_WINDOW_MSold (at - live.cpu[1]![0] >= CPU_WINDOW_MS), keeping the tightest baseline that covers a full 5-minute window.How it was checked
corepack pnpm vitest run server/jobs/supervisor.test.ts server/jobs/prompt.test.ts(2 files passed; 2 tests passed including the new CPU limit test on Windows, 9 existingsh-based tests skipped onwin32)corepack pnpm typecheck(exited 0)corepack pnpm lint(oxlint --deny-warnings ., 0 warnings, 0 errors across 8092 files)pnpm typecheck,pnpm lintandpnpm testpass (typecheck, lint, and targetedserver/jobs/tests passed; full repo-widepnpm testwas not run locally)New behaviour has a test
No secrets, personal data or local paths in the diff or screenshots