fix(mcp): break the ci-health-check-tool ↔ ci-health-log circular import (#3756)#3811
Merged
Merged
Conversation
) Importing the MCP tools barrel (or ci-health-check-tool / ci-health-log) under tsx ESM evaluation threw 'ReferenceError: Cannot access CiHealthStatusSchema before initialization': the tool DEFINED the shared schema/types and imported the log's appenders, while the log used the schema at module-eval time — the cyclic init order left CiHealthStatusSchema in the TDZ. (Forced a static-parse workaround in the #3687 tool-reference generator.) Fix: extract CiHealthStatusSchema/CiHealthStatus/CiHealthSignal into a leaf ci-health-types.ts (imports only zod); both modules import the leaf, breaking the cycle (check-tool -> log -> types, check-tool -> types — a DAG). The tool re-exports the symbols for API compat. Verified all three imports load OK under tsx. Guard: a structural test asserts ci-health-log no longer imports from ci-health-check-tool + a smoke test loads the tool/barrel. 37 ci-health tests pass; typecheck, lint, governance, producer-consumer clean. Closes #3756. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This was referenced Jun 9, 2026
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.
Closes #3756.
Observable bug
Importing the MCP tools barrel (or either ci-health module) under tsx ESM evaluation threw:
Repro (now fixed):
npx tsx -e "import('./packages/nexus-agents/src/mcp/tools/index.js')". This forced a static-parse workaround in the #3687 tool-reference generator.Cause
A circular dependency with a TDZ trap:
ci-health-check-tool.tsdefinedCiHealthStatusSchema/CiHealthSignaland importedci-health-log's appenders.ci-health-log.tsimportedCiHealthStatusSchemafrom the tool and used it at module-eval time (insideCiHealthEventSchema).Fix (standard leaf-extraction)
New
ci-health-types.ts(imports onlyzod) hostsCiHealthStatusSchema/CiHealthStatus/CiHealthSignal. Both modules import the leaf →check-tool → log → types,check-tool → types(a DAG, no cycle). The tool re-exports the symbols for API compatibility. Verified all three imports load OK under tsx.Guard + verification
A structural test asserts
ci-health-logno longer imports fromci-health-check-tool(cycle stays broken) + a smoke test loads the tool/barrel. 37 ci-health tests pass; typecheck, lint, governance (46 tools), description-drift, docs:tools (47), producer-consumer all green.🤖 Generated with Claude Code