Skip to content

feat(activity): use process CPU metrics to prevent premature idle transitions#4560

Merged
gregpriday merged 2 commits intodevelopfrom
feature/issue-4151-use-process-cpu-metrics
Mar 29, 2026
Merged

feat(activity): use process CPU metrics to prevent premature idle transitions#4560
gregpriday merged 2 commits intodevelopfrom
feature/issue-4151-use-process-cpu-metrics

Conversation

@gregpriday
Copy link
Copy Markdown
Collaborator

Summary

  • Extends ProcessStateValidator interface with isCpuBusy() to expose process-level CPU activity alongside the existing hasActiveChildren() check
  • ActivityMonitor now uses CPU busyness to prevent the CompletionTimer from firing idle transitions when the process tree is still consuming CPU, reducing false "idle" calls during silent processing phases
  • Adds a HIGH_CPU_THRESHOLD_PERCENT constant (10%) and a CpuBusyTracker helper that integrates with the existing WorkingSignalDebouncer pattern

Resolves #4151

Changes

  • electron/services/ActivityMonitor.ts — added isCpuBusy() to ProcessStateValidator, CpuBusyTracker class, CPU-aware guard in CompletionTimer, and wired CPU signal into confidence scoring
  • electron/services/pty/terminalActivityPatterns.ts — exported HIGH_CPU_THRESHOLD_PERCENT constant
  • electron/services/__tests__/ActivityMonitor.test.ts — comprehensive test coverage for CPU signal integration: silent high-CPU suppression, near-zero CPU acceleration, graceful degradation when data is unavailable

Testing

Full unit test suite passes. CPU signal tests cover all four quadrants (high/low CPU × with/without output), threshold boundary cases, and graceful degradation when isCpuBusy is not provided by the validator.

Greg Priday added 2 commits March 29, 2026 14:18
…nsitions

- Extend ProcessStateValidator interface with getDescendantsCpuUsage()
- Add CPU hysteresis tracking (10% enter, 3% exit) to ActivityMonitor
- Guard isWorkingSilenceTimeout, prompt fast-path, lexeme fallback, isQuietForIdle, and debounce idle paths
- Implement getDescendantsCpuUsage in createProcessStateValidator
- Add 10 new tests covering CPU idle prevention, hysteresis, completion passthrough, and error handling
- Add verbose logging to getCpuUsageSafe() for consistency with hasActiveChildrenSafe()
- Fix vacuous assertion in cpu-10 dispose test
@gregpriday gregpriday force-pushed the feature/issue-4151-use-process-cpu-metrics branch from 58487a7 to 0920623 Compare March 29, 2026 12:18
@gregpriday gregpriday merged commit 449f4de into develop Mar 29, 2026
@gregpriday gregpriday deleted the feature/issue-4151-use-process-cpu-metrics branch March 29, 2026 12:18
gregpriday added a commit that referenced this pull request Apr 8, 2026
…s-cpu-metrics

feat(activity): use process CPU metrics to prevent premature idle transitions
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.

Use process CPU metrics to improve agent activity detection

1 participant