fix(msteams): prevent path-to-regexp crash with express 5 (#55161)#55440
fix(msteams): prevent path-to-regexp crash with express 5 (#55161)#55440BradGroux merged 1 commit intoopenclaw:mainfrom
Conversation
72beea0 to
faa2461
Compare
Greptile SummaryThis PR fixes a startup crash in the MS Teams channel ( Confidence Score: 4/5Safe to merge — fixes a real startup crash with a targeted workaround and a passing regression test; the only risk is future SDK updates breaking the internal dist/ imports. The root cause is well-understood, the fix is minimal and correctly scoped, and the regression test uses the real SDK against Express 5. One non-blocking fragility remains (deep private imports from the SDK's dist/ tree), but it does not affect current correctness. extensions/msteams/src/sdk.ts lines 77–82 — the three internal @microsoft/teams.apps/dist/… imports.
|
| Filename | Overview |
|---|---|
| extensions/msteams/src/sdk.ts | Adds async createNoOpHttpPlugin that stubs the SDK's default HttpPlugin (which uses an Express 5-incompatible route pattern), and threads the stub through createMSTeamsApp and loadMSTeamsSdkWithAuth. Fix is logically sound and well-commented; main fragility is the three deep dist/ imports used to obtain reflect-metadata keys. |
| extensions/msteams/src/sdk.test.ts | Adds a regression test that instantiates the real Teams SDK against Express 5, confirming the startup crash no longer occurs. Existing adapter test is unchanged. |
Prompt To Fix All With AI
This is a comment left during a code review.
Path: extensions/msteams/src/sdk.ts
Line: 77-82
Comment:
**Fragile deep-private SDK imports**
These three import paths reach directly into the SDK's compiled `dist/` tree rather than its public API surface:
```
@microsoft/teams.apps/dist/types/plugin/decorators/plugin.js
@microsoft/teams.apps/dist/types/plugin/decorators/dependency.js
@microsoft/teams.apps/dist/types/plugin/decorators/event.js
```
Any internal refactor inside `@microsoft/teams.apps` — even a patch release — will silently break MS Teams channel startup, likely with an opaque `MODULE_NOT_FOUND` error rather than a clear message.
Consider whether the three metadata keys could instead be hard-coded as local string constants (snapshotted from the current SDK source), removing the runtime dependency on these internal paths entirely. The values are unlikely to collide with other plugin registry entries, and a snapshot is more stable than a live import of a private file.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix(msteams): prevent path-to-regexp cra..." | Re-trigger Greptile
| // FRAGILE: these are internal SDK paths (not public API). If | ||
| // @microsoft/teams.apps changes its dist layout, these imports will break. | ||
| // Pin the SDK version and re-verify after any upgrade. | ||
| await import("reflect-metadata"); | ||
| const { PLUGIN_METADATA_KEY } = | ||
| await import("@microsoft/teams.apps/dist/types/plugin/decorators/plugin.js"); |
There was a problem hiding this comment.
Fragile deep-private SDK imports
These three import paths reach directly into the SDK's compiled dist/ tree rather than its public API surface:
@microsoft/teams.apps/dist/types/plugin/decorators/plugin.js
@microsoft/teams.apps/dist/types/plugin/decorators/dependency.js
@microsoft/teams.apps/dist/types/plugin/decorators/event.js
Any internal refactor inside @microsoft/teams.apps — even a patch release — will silently break MS Teams channel startup, likely with an opaque MODULE_NOT_FOUND error rather than a clear message.
Consider whether the three metadata keys could instead be hard-coded as local string constants (snapshotted from the current SDK source), removing the runtime dependency on these internal paths entirely. The values are unlikely to collide with other plugin registry entries, and a snapshot is more stable than a live import of a private file.
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/msteams/src/sdk.ts
Line: 77-82
Comment:
**Fragile deep-private SDK imports**
These three import paths reach directly into the SDK's compiled `dist/` tree rather than its public API surface:
```
@microsoft/teams.apps/dist/types/plugin/decorators/plugin.js
@microsoft/teams.apps/dist/types/plugin/decorators/dependency.js
@microsoft/teams.apps/dist/types/plugin/decorators/event.js
```
Any internal refactor inside `@microsoft/teams.apps` — even a patch release — will silently break MS Teams channel startup, likely with an opaque `MODULE_NOT_FOUND` error rather than a clear message.
Consider whether the three metadata keys could instead be hard-coded as local string constants (snapshotted from the current SDK source), removing the runtime dependency on these internal paths entirely. The values are unlikely to collide with other plugin registry entries, and a snapshot is more stable than a live import of a private file.
How can I resolve this? If you propose a fix, please make it concise.faa2461 to
e9be2a1
Compare
…5161) The Teams SDK (@microsoft/teams.apps) default HttpPlugin registers an Express middleware with the pattern `/api*`. When the host application uses Express 5 (which depends on path-to-regexp v8+), that pattern is invalid and throws: Missing parameter name at index 5: /api* OpenClaw manages its own Express server for the Teams webhook endpoint and does not use the SDK's built-in HTTP server. This commit injects a no-op HTTP plugin stub into the Teams SDK App constructor to prevent the default HttpPlugin from being created, avoiding the crash entirely. Changes: - sdk.ts: Add createNoOpHttpPlugin() that creates a properly decorated stub plugin named 'http', and pass it to App constructor - sdk.ts: Make createMSTeamsApp async (was sync) to support lazy import of reflect-metadata and decorator constants - sdk.test.ts: Add regression test verifying App creation succeeds with the real Teams SDK under express 5 Closes openclaw#55161
e9be2a1 to
84efae9
Compare
Problem
The MS Teams channel crashes immediately on startup in 2026.3.24 with:
Fixes #55161
Root Cause
The Teams SDK (
@microsoft/teams.apps@2.0.5) has a built-inHttpPluginthat registers an Express middleware with the pattern/api*in its constructor. This pattern was valid in Express 4, but is invalid in Express 5 which usespath-to-regexp@8.x.When installed in OpenClaw's monorepo, pnpm hoisting resolves the SDK's
expressimport to the project's top-levelexpress@5.2.1instead of Express 4, causing the crash.Fix
Inject a no-op HTTP plugin stub into the Teams SDK's
Appconstructor to prevent the defaultHttpPluginfrom being created. OpenClaw manages its own Express routing, so the SDK's built-in HTTP handling is not needed.Testing
attachments.test.tsare SSRF/DNS environment issues unrelated to this change (confirmed on main branch too)