Skip to content

fix(health-check): resolve Jest worker process leak [TD-6]#35

Merged
Pedrovaleriolopez merged 2 commits intomainfrom
fix/td-6-jest-worker-leak
Jan 4, 2026
Merged

fix(health-check): resolve Jest worker process leak [TD-6]#35
Pedrovaleriolopez merged 2 commits intomainfrom
fix/td-6-jest-worker-leak

Conversation

@Pedrovaleriolopez
Copy link
Contributor

@Pedrovaleriolopez Pedrovaleriolopez commented Jan 4, 2026

Summary

  • Root Cause: setTimeout in engine.js:runSingleCheck() was never cleared after Promise.race resolved
  • Impact: 7 open handles per test run, causing Jest exit code 1 with "worker process failed to exit gracefully"
  • Fix: Store timeoutId and call clearTimeout() on both success and error paths

Changes

File Change
.aios-core/core/health-check/engine.js Added clearTimeout(timeoutId) after Promise.race resolves
.aios-core/development/scripts/dev-context-loader.js Handle null coreConfig gracefully

Validation

Before: 7 open handles (Timeout) → Exit code 1
After:  0 open handles → Jest exits cleanly

Tests: 17 health-check tests passing, 0 open handles detected with --detectOpenHandles

Test plan

  • Run npm test -- tests/health-check/health-check.test.js --detectOpenHandles
  • Verify 0 open handles in output
  • Run npm test to confirm all tests pass
  • CI passes without worker leak warning

Related

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Fixed health-check timeout cleanup to prevent worker memory leaks.
    • Made development configuration access safer to avoid runtime errors.
  • Refactor

    • Improved style and null-safety consistency across development scripts.

✏️ Tip: You can customize this high-level summary in your review settings.

Root Cause: setTimeout in engine.js runSingleCheck() was never cleared
after Promise.race resolved, leaving 7 open handles per test run.

Changes:
- engine.js: Store timeoutId and call clearTimeout() on success/error
- dev-context-loader.js: Handle null coreConfig gracefully

Before: 7 open handles, Jest exit code 1, "worker process failed to exit"
After: 0 open handles, Jest exits cleanly

Closes #34

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions github-actions bot added type: docs Documentation improvements core area: agents Agent system related area: workflows Workflow system related squad squad: etl squad: creator mcp docker-mcp type: test Test coverage and quality labels Jan 4, 2026
@coderabbitai
Copy link

coderabbitai bot commented Jan 4, 2026

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key(s) in object: 'tools', 'abort_on_close'
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Walkthrough

Adds explicit per-check timeout tracking and cleanup in the health-check engine to prevent dangling timers; applies null-safety and minor stylistic changes to the development context loader; updates install manifest metadata/hashes.

Changes

Cohort / File(s) Summary
Core timeout cleanup
.aios-core/core/health-check/engine.js
Adds per-check timeoutId storage, ensures clearTimeout(timeoutId) on both success and error paths (including in runSingleCheck()), and adjusts timeout promise handling to avoid lingering timers that can leak Jest workers.
Development tooling updates
.aios-core/development/scripts/dev-context-loader.js
Adds safe access for coreConfig.devLoadAlwaysFiles (fallback to []) and standardizes arrow-function parameter parentheses and minor formatting; no behavioral changes.
Install manifest
.aios-core/install-manifest.yaml
Updates generated_at timestamp and sha256/size entries for the modified files.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

core, ci/cd, bug-fix, tests

Pre-merge checks

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: resolving a Jest worker process leak in the health-check engine by clearing timeouts, directly addressing the PR's primary objective.
Linked Issues check ✅ Passed The PR directly addresses the acceptance criteria in issue #34: identifies the timeout leak source, implements proper cleanup with clearTimeout calls, and the validation confirms 0 open handles post-fix.
Out of Scope Changes check ✅ Passed The dev-context-loader.js changes (null-safety and formatting) are minor and complementary to the primary fix; manifest updates are expected regeneration artifacts. All changes align with addressing the Jest worker leak issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 33ed1bd and d588ce2.

📒 Files selected for processing (1)
  • .aios-core/install-manifest.yaml
🔇 Additional comments (1)
.aios-core/install-manifest.yaml (1)

11-11: LGTM! Manifest correctly regenerated.

The manifest has been properly regenerated to reflect the timeout cleanup fix in engine.js and the null-safety improvements in dev-context-loader.js. The updated hashes and sizes for these two files are consistent with the TD-6 changes described in the PR objectives.

Also applies to: 364-366, 664-666


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 4, 2026

📊 Coverage Report

Coverage report not available

📈 Full coverage report available in Codecov


Generated by PR Automation (Story 6.1)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
.aios-core/core/health-check/engine.js (1)

1-1: Pipeline failure: Regenerate the manifest.

The CI pipeline is failing because the manifest file is outdated. Please run npm run generate:manifest to update the manifest with the new file hashes.

.aios-core/development/scripts/dev-context-loader.js (1)

1-1: Pipeline failure: Regenerate the manifest.

The CI pipeline is failing because the manifest file is outdated. Please run npm run generate:manifest to update the manifest with the new file hashes.

🧹 Nitpick comments (1)
.aios-core/development/scripts/dev-context-loader.js (1)

64-64: Formatting consistency: Arrow function parentheses.

The added parentheses around single arrow function parameters improve stylistic consistency across the file. This aligns with common linting rules that enforce uniform parameter syntax.

Also applies to: 167-167, 176-176, 261-261, 290-290

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1c7b14c and 33ed1bd.

📒 Files selected for processing (2)
  • .aios-core/core/health-check/engine.js
  • .aios-core/development/scripts/dev-context-loader.js
🧰 Additional context used
🪛 GitHub Actions: CI
.aios-core/development/scripts/dev-context-loader.js

[error] 1-1: Manifest is OUTDATED. Modified file hash mismatch detected. To fix, run 'npm run generate:manifest'.

.aios-core/core/health-check/engine.js

[error] 1-1: Manifest is OUTDATED. Modified file hash mismatch detected. To fix, run 'npm run generate:manifest'.

🔇 Additional comments (5)
.aios-core/core/health-check/engine.js (4)

249-249: LGTM: Timeout ID initialization.

The timeout ID is correctly initialized before the try block, allowing it to be accessed in both success and error paths for cleanup.


252-259: LGTM: Timeout promise correctly captures timeoutId.

The timeout promise properly stores the timeout ID, enabling cleanup in both resolution paths. The timeout duration calculation correctly respects both the check-specific timeout and the overall timeout.


264-268: LGTM: Success path cleanup correctly implemented.

The timeout is properly cleared after the check completes successfully. The guard check is defensive programming, and clearing the timeout ensures Jest doesn't detect an open handle.


293-297: LGTM: Error path cleanup ensures no leaks.

The timeout is properly cleared in the error handler, ensuring cleanup occurs even when checks fail or time out. This completes the fix for the Jest worker leak, as the timeout is now cleared in all possible code paths.

.aios-core/development/scripts/dev-context-loader.js (1)

40-42: LGTM: Null-safety improvement for coreConfig.

The defensive null check is appropriate. While loadCoreConfig() returns an empty object on error, the YAML parser could potentially return null or undefined for empty/invalid YAML content, making this guard necessary.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 4, 2026
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@Pedrovaleriolopez Pedrovaleriolopez merged commit 0959918 into main Jan 4, 2026
18 of 19 checks passed
@Pedrovaleriolopez Pedrovaleriolopez deleted the fix/td-6-jest-worker-leak branch January 4, 2026 19:36
Experiasolutions pushed a commit to Experiasolutions/aios-core that referenced this pull request Mar 13, 2026
* fix(health-check): resolve Jest worker process leak [TD-6]

Root Cause: setTimeout in engine.js runSingleCheck() was never cleared
after Promise.race resolved, leaving 7 open handles per test run.

Changes:
- engine.js: Store timeoutId and call clearTimeout() on success/error
- dev-context-loader.js: Handle null coreConfig gracefully

Before: 7 open handles, Jest exit code 1, "worker process failed to exit"
After: 0 open handles, Jest exits cleanly

Closes SynkraAI#34

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* chore: regenerate install manifest after engine.js fix

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Pedro Valerio <pedro@allfluence.ai>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: agents Agent system related area: workflows Workflow system related docker-mcp mcp squad: creator squad: etl squad type: docs Documentation improvements type: test Test coverage and quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(ci): Investigate Jest worker process leak causing CI failures

1 participant