Skip to content

fix: guard against undefined extension.exports in MCP server init#1929

Closed
dev-punia-altimate wants to merge 1 commit into
masterfrom
qa-autopilot/fix-ext-mcp-ready-null-ref
Closed

fix: guard against undefined extension.exports in MCP server init#1929
dev-punia-altimate wants to merge 1 commit into
masterfrom
qa-autopilot/fix-ext-mcp-ready-null-ref

Conversation

@dev-punia-altimate
Copy link
Copy Markdown
Contributor

Evidence Matrix

Source Checked Data Extracted
App Insights Telemetry 2270 events in 24h, event: DbtPowerUserMcpServer:updateMcpExtensionApiError, message: "Cannot read properties of undefined (reading 'ready')"
Sentry N/A — extension telemetry via Azure App Insights
Code Search src/mcp/index.ts:55extension.exports.ready accessed without null check
Existing Tests No existing tests for DbtPowerUserMcpServer.updateMcpExtensionApi() — created new test suite

Discovery

Azure Application Insights telemetry shows 2270 occurrences of Cannot read properties of undefined (reading 'ready') in the last 24 hours across versions 0.51.2–0.60.7 and all modes (core, cloud, fusion). Top event: DbtPowerUserMcpServer:updateMcpExtensionApiError.

Root Cause Analysis

In src/mcp/index.ts, the updateMcpExtensionApi() method:

  1. Gets the altimateai.vscode-altimate-mcp-server extension via extensions.getExtension()
  2. Checks if the extension exists ✅
  3. Activates it if not active ✅
  4. Accesses extension.exports.ready without checking if exports is defined

VS Code's Extension.exports is typed as T | undefined. When the MCP extension is present but hasn't fully initialized its exports (e.g., during a race condition at activation), exports is undefined, and accessing .ready throws the TypeError.

The error is caught by the surrounding try/catch, so it doesn't crash the extension — but it generates 2270 telemetry noise events per day and prevents MCP tool registration.

Why This Fix Resolves It

Added an explicit !extension.exports guard (line 55–62) that:

  • Returns early if exports are undefined, matching the existing pattern for !extension at line 43
  • Logs the condition via dbtTerminal.error for debuggability
  • Is non-breaking: mcpExtensionApi stays undefined, which is already handled by the null check in registerToolsInMcpExtension() at line 87

Self-Critique

  1. Root cause confidence: HIGH — the stack trace message exactly matches accessing .ready on undefined, and extension.exports is the only object before .ready that can be undefined
  2. What could be wrong: The underlying cause of exports being undefined (MCP extension activation timing) is not fixed — this is a defensive guard. If the MCP extension consistently fails to export, tools won't register.
  3. Edge cases considered: Extension missing, exports undefined, exports.ready rejecting, normal happy path
  4. Test coverage: 5 new regression tests covering all branches of updateMcpExtensionApi()

Impact

  • Affects: 2270 events/day across all modes and multiple versions
  • User impact: MCP tools fail to register silently; extension still activates normally
  • Risk: Low — defensive null guard, no behavior change when exports are defined
  • Files changed: 1 source file (8 lines added), 1 test file (160 lines)

Generated by QA Autopilot | Extension Telemetry

…-autopilot)

Add null check for extension.exports before accessing .ready property
in updateMcpExtensionApi(). When the Altimate MCP Server extension is
present but hasn't fully initialized its exports, the previous code
threw 'Cannot read properties of undefined (reading ready)' — seen
2270 times in telemetry in 24h across versions 0.51.2–0.60.7.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 30, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 961e6fca-1b5c-4287-90a5-402b061f5104

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch qa-autopilot/fix-ext-mcp-ready-null-ref

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.

@dev-punia-altimate
Copy link
Copy Markdown
Contributor Author

Critic Review — BLOCK

❌ BLOCK — CI checks still pending

Rule-CI-PENDING: 7 required checks are still running. Cannot merge or approve until CI completes.

Check Status
build (macos-latest, darwin-arm64) 🔄 In Progress
build (ubuntu-latest, linux-x64) 🔄 In Progress
build (windows-latest, win32-x64) 🔄 In Progress
test (macos-latest) 🔄 In Progress
test (ubuntu-latest) 🔄 In Progress
test (windows-latest) 🔄 In Progress
Analyze (javascript-typescript) 🔄 In Progress

5 checks already passed: Analyze (actions), Analyze (python), CodeQL, GitGuardian Security Checks, security/snyk — no issues there.


Preliminary code-quality assessment (not blocking on its own):

The fix and tests look high quality:

  • src/mcp/index.ts: The !extension.exports guard at line 55 is well-placed, matches the existing defensive pattern for !extension at line 43, and addresses the root cause (VS Code types Extension.exports as T | undefined).
  • src/test/suite/mcpServer.test.ts: 5 new regression tests, all with falsifiable assertions. No type-only checks (Rule 22 clean), no tautologies (Rule 19 clean). The happy-path test (line 119) verifies addMcpIntegrationConfig is called with an object containing title: "Advanced Data Tools" — specific and mutation-sensitive. Branch coverage looks complete (extension missing, exports undefined, inactive extension, happy path, exports.ready rejection).

If CI passes, this PR is ready to PROCEED.


Re-run critic after CI completes. Agent blocks are reversible via critic: override comment on this PR.


Quality Critic • View run

@dev-punia-altimate
Copy link
Copy Markdown
Contributor Author

🔴 Critic Finding [CRITICAL] — Rule-CI-PENDING

7 required checks are still in progress: build (macos-latest, darwin-arm64), build (ubuntu-latest, linux-x64), build (windows-latest, win32-x64), test (macos-latest), test (ubuntu-latest), test (windows-latest), Analyze (javascript-typescript). Re-run critic after all CI checks complete.

Fix this finding and reply with "Fixed in <commit_sha>" to clear this comment.


Quality Critic • View run

@github-actions
Copy link
Copy Markdown

Bundle Size Report

darwin-arm64: 74.2 MB
Category Size Compressed Files
Webview JS bundles 36.3 MB 12.3 MB 346
Native: altimate-core 35.1 MB 14.0 MB 1
Media assets 29.6 MB 25.8 MB 91
Native: zeromq 20.5 MB 8.2 MB 15
Webview images 15.3 MB 12.2 MB 18
Extension backend (JS) 2.7 MB 0.6 MB 1
Python packages 2.0 MB 0.5 MB 95
Native: other node_modules 1.0 MB 0.2 MB 139
Webview CSS 0.8 MB 0.1 MB 2
Webview other 0.5 MB 0.1 MB 5
Other 0.1 MB 26 KB 15
Total 143.9 MB 74.0 MB 728
linux-x64: 75.9 MB
Category Size Compressed Files
Native: altimate-core 41.8 MB 15.1 MB 1
Webview JS bundles 36.3 MB 12.3 MB 346
Media assets 29.6 MB 25.8 MB 91
Native: zeromq 21.9 MB 8.7 MB 16
Webview images 15.3 MB 12.2 MB 18
Extension backend (JS) 2.7 MB 0.6 MB 1
Python packages 2.0 MB 0.5 MB 95
Native: other node_modules 1.0 MB 0.2 MB 139
Webview CSS 0.8 MB 0.1 MB 2
Webview other 0.5 MB 0.1 MB 5
Other 0.1 MB 26 KB 15
Total 152.0 MB 75.7 MB 729
win32-x64: 76.8 MB
Category Size Compressed Files
Native: altimate-core 50.3 MB 16.2 MB 1
Webview JS bundles 36.3 MB 12.3 MB 346
Media assets 29.6 MB 25.8 MB 91
Native: zeromq 20.0 MB 8.1 MB 15
Webview images 15.3 MB 12.2 MB 18
Extension backend (JS) 2.7 MB 0.6 MB 1
Native: other node_modules 2.3 MB 0.7 MB 147
Python packages 2.0 MB 0.5 MB 95
Webview CSS 0.8 MB 0.1 MB 2
Webview other 0.5 MB 0.1 MB 5
Other 0.1 MB 26 KB 15
Total 159.8 MB 76.6 MB 736

Copy link
Copy Markdown
Contributor

@ralphstodomingo ralphstodomingo left a comment

Choose a reason for hiding this comment

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

being addressed in #1926

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