Skip to content

jobs: keep the CPU window baseline when sampling drifts past 5 minutes - #471

Merged
SiddDevZ merged 1 commit into
DuskBotAI:devfrom
samyyy2311:fix-job-cpu-watchdog
Dec 3, 2026
Merged

SiddDevZ merged 1 commit into
DuskBotAI:devfrom
samyyy2311:fix-job-cpu-watchdog

Conversation

@samyyy2311

Copy link
Copy Markdown
Contributor

What and why

In JobSupervisor.sample(), the sliding-window cleanup dropped live.cpu[0] whenever at - live.cpu[0][0] > CPU_WINDOW_MS, right before checking at - firstAt >= CPU_WINDOW_MS.

Because setInterval(..., SAMPLE_MS) and the async usage() lookup always add at least a few milliseconds of drift, the 11th sample arrives slightly past CPU_WINDOW_MS (for example 300,010 ms), evicts the oldest sample, and leaves at - firstAt around 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 while live.cpu[1] is still at least CPU_WINDOW_MS old (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 existing sh-based tests skipped on win32)

  • corepack pnpm typecheck (exited 0)

  • corepack pnpm lint (oxlint --deny-warnings ., 0 warnings, 0 errors across 8092 files)

  • pnpm typecheck, pnpm lint and pnpm test pass (typecheck, lint, and targeted server/jobs/ tests passed; full repo-wide pnpm test was not run locally)

  • New behaviour has a test

  • No secrets, personal data or local paths in the diff or screenshots

@SiddDevZ
SiddDevZ merged commit e4510ed into DuskBotAI:dev Dec 3, 2026
20 of 21 checks passed
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.

2 participants