Skip to content

fix(messaging): render Teams AAD mentions as chips - #5864

Closed
deepujain wants to merge 3 commits into
NVIDIA:mainfrom
deepujain:fix/5852-teams-mention-display-name
Closed

deepujain wants to merge 3 commits into
NVIDIA:mainfrom
deepujain:fix/5852-teams-mention-display-name

Conversation

@deepujain

@deepujain deepujain commented Jun 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Patch the installed @openclaw/msteams runtime after the pinned Teams plugin install so display-name AAD text such as @ San Dang (205f29da-231e-4a0e-a0b2-b398e6302087) becomes Teams mention markup plus a mention entity.
  • Keep the existing explicit @[Name](id) mention syntax working.
  • Fail closed if the upstream Teams parser shape changes, instead of silently sending raw UUID mention text.

Evidence it works

The focused runtime test imports the patched Teams sender and checks this issue payload:

@
San Dang (205f29da-231e-4a0e-a0b2-b398e6302087) I've tagged you!

It now renders as:

<at>San Dang</at> I've tagged you!

The test also checks that the first activity entity is the Teams mention entity for the AAD object ID/display name and that the raw San Dang (uuid) text is absent from the rendered activity.

Testing

  • npm run build:cli
  • npm run typecheck:cli
  • npx vitest run test/openclaw-msteams-mention-patch.test.ts --silent=false --reporter=default
  • npx vitest run test/messaging-build-applier.test.ts -t "runs pinned installs during agent-install without doctor env injection" --silent=false --reporter=default --testTimeout=20000
  • npm run source-shape:check
  • npm run test-size:check
  • npx @biomejs/biome format src/lib/messaging/applier/build/messaging-build-applier.mts test/openclaw-msteams-mention-patch.test.ts test/messaging-build-applier.test.ts
  • git diff --check

Note: running the full test/messaging-build-applier.test.ts file locally reached 20/21 tests passing, but the existing plan-builder helper was killed at its own 10s subprocess timeout on this machine. The affected pinned-install case passes when run directly.

Fixes #5852

Signed-off-by: Deepak Jain [email protected]

Summary by CodeRabbit

  • New Features

    • Microsoft Teams mentions now support additional “spaced” AAD-id display-name formats by applying a post-install runtime patch.
  • Bug Fixes

    • Mention text is normalized into correct clickable Teams mention entities.
    • Patch behavior is idempotent and only applies when the runtime needs updating.
    • Improved failure handling when the expected runtime cannot be located or matched.
  • Tests

    • Added/expanded automated coverage for the runtime patching, including idempotency and correct behavior across pinned install and post-install phases.

@copy-pr-bot

copy-pr-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 93f90b7c-af8d-4b9d-97ff-ef444bc4d06c

📥 Commits

Reviewing files that changed from the base of the PR and between 503f430 and 85f9380.

📒 Files selected for processing (7)
  • src/lib/messaging/applier/build/messaging-build-applier.mts
  • src/lib/messaging/channels/manifests.test.ts
  • src/lib/messaging/channels/teams/hooks/index.ts
  • src/lib/messaging/channels/teams/hooks/msteams-mention-patch.ts
  • src/lib/messaging/channels/teams/manifest.ts
  • test/messaging-build-applier.test.ts
  • test/openclaw-msteams-mention-patch.test.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/lib/messaging/channels/teams/manifest.ts
  • src/lib/messaging/channels/manifests.test.ts
  • src/lib/messaging/channels/teams/hooks/index.ts
  • src/lib/messaging/channels/teams/hooks/msteams-mention-patch.ts
  • src/lib/messaging/applier/build/messaging-build-applier.mts

📝 Walkthrough

Walkthrough

OpenClaw Teams now registers a post-agent-install hook that patches the installed runtime mention parser. The build applier invokes that hook side effect, and tests cover the source rewrite, idempotency, and install-time execution.

Changes

OpenClaw MS Teams mention patching

Layer / File(s) Summary
Hook registration and manifest
src/lib/messaging/channels/teams/hooks/index.ts, src/lib/messaging/channels/teams/manifest.ts, src/lib/messaging/channels/manifests.test.ts
The Teams hook registry and manifest expose the mention-patch hook handler and register the new post-agent-install OpenClaw hook entry.
Installed runtime patching
src/lib/messaging/channels/teams/hooks/msteams-mention-patch.ts
The new hook module locates the installed MS Teams runtime, rewrites the mention parser source when needed, and reports patch status through a dedicated entrypoint and error type.
Post-agent-install side effect
src/lib/messaging/applier/build/messaging-build-applier.mts
The build applier imports the mention-patch hook and adds an OpenClaw-only post-agent-install side effect that runs matching hooks and merges their outputs into the existing post-install results.
Patch behavior tests
test/openclaw-msteams-mention-patch.test.ts, test/messaging-build-applier.test.ts
The tests cover source-level mention rewriting, boundary cases, installed-runtime idempotency, and the build-applier flow that patches a seeded Teams runtime after agent installation.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested labels

integration: openclaw

Suggested reviewers

  • cv
  • prekshivyas

Poem

A bunny hopped to Teams one night,
and nudged the mentions into light. 🐇
Raw IDs hid, the names came through,
with tidy chips and patch marks new.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title concisely matches the main change: fixing Teams AAD mentions to render as chips.
Linked Issues check ✅ Passed The patch and tests address the reported Teams mention rendering bug by converting AAD-name mentions into proper Teams mention markup.
Out of Scope Changes check ✅ Passed The added hook wiring, runtime patch, and tests all support the Teams mention fix and do not introduce unrelated scope.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/lib/messaging/applier/build/messaging-build-applier.mts`:
- Line 621: The raw AAD mention regex in messaging-build-applier.mts is too
permissive and can match ordinary email-like text inside messages; update the
displayNameAadMentionPattern matching and its replacement logic so the generated
`@Name` (uuid) form only anchors at a message boundary such as start-of-string or
whitespace, and preserve that leading separator when rebuilding the text. Check
both occurrences of this pattern in the applier code so the rewrite only
converts real mentions and does not touch inline @ characters in normal text.

In `@test/messaging-build-applier.test.ts`:
- Around line 74-92: The current test is self-fulfilling because
writeAlreadyPatchedMSTeamsRuntime() seeds the Teams runtime with the
normalization marker before the patch step, so the assertion in the messaging
build applier test only verifies that the marker remains present. Update the
fixture to create an unpatched runtime shape for the probe.js file, then
exercise the install/patch flow and assert that the marker is added afterward,
or compare the file contents before and after. Use
writeAlreadyPatchedMSTeamsRuntime, probe.js, and the messaging build applier
test block that checks for the marker to locate and adjust the test.

In `@test/openclaw-msteams-mention-patch.test.ts`:
- Around line 103-113: The temp probe created in the openclaw-msteams-mention
patch test is being imported as ESM but is still named and placed so Node treats
it as CommonJS, causing the dynamic import to fail before the assertions. Update
the test setup around patchInstalledOpenClawMSTeamsMentions and the
runtimeFile/probe fixture creation to ensure the temp directory is recognized as
ESM, either by writing a local package.json with type module or by renaming the
probe file to .mjs, so the import of the probe module succeeds.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 2ad3c364-4d8c-462c-bd10-1cd6bde29ec9

📥 Commits

Reviewing files that changed from the base of the PR and between c1c7c1d and 90ec826.

📒 Files selected for processing (3)
  • src/lib/messaging/applier/build/messaging-build-applier.mts
  • test/messaging-build-applier.test.ts
  • test/openclaw-msteams-mention-patch.test.ts

const replacement = [
"function parseMentions(text) {",
"\tconst mentionPattern = /@\\[([^\\]]+)\\]\\(([^)]+)\\)/g;",
"\tconst displayNameAadMentionPattern = /@[\\s\\r\\n]*([^()\\r\\n@][^()\\r\\n]{0,80}?)\\s*\\(([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})\\)/gi;",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Anchor raw AAD mention matching to a message boundary.

The new regex can rewrite any @ inside ordinary text, e.g. foo@San Dang (${id}), into a Teams mention and ping. Require start/whitespace before the generated @Name (uuid) form and preserve that prefix in the replacement.

Suggested fix
-    "\tconst displayNameAadMentionPattern = /@[\\s\\r\\n]*([^()\\r\\n@][^()\\r\\n]{0,80}?)\\s*\\(([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})\\)/gi;",
+    "\tconst displayNameAadMentionPattern = /(^|\\s)@[\\s\\r\\n]*([^()\\r\\n@][^()\\r\\n]{0,80}?)\\s*\\(([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})\\)/gi;",
...
-    "\t\ttext: explicitMentionText.replace(displayNameAadMentionPattern, (match, name, id) => appendMention(name, id) ?? match),",
+    "\t\ttext: explicitMentionText.replace(displayNameAadMentionPattern, (match, prefix, name, id) => {",
+    "\t\t\tconst mentionTag = appendMention(name, id);",
+    "\t\t\treturn mentionTag ? `${prefix}${mentionTag}` : match;",
+    "\t\t}),",

Also applies to: 641-641

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/messaging/applier/build/messaging-build-applier.mts` at line 621, The
raw AAD mention regex in messaging-build-applier.mts is too permissive and can
match ordinary email-like text inside messages; update the
displayNameAadMentionPattern matching and its replacement logic so the generated
`@Name` (uuid) form only anchors at a message boundary such as start-of-string or
whitespace, and preserve that leading separator when rebuilding the text. Check
both occurrences of this pattern in the applier code so the rewrite only
converts real mentions and does not touch inline @ characters in normal text.

Comment thread test/messaging-build-applier.test.ts Resolved

@sandl99 sandl99 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @deepujain for your quick contribution. There are few concerns

  1. San Dang seems doesn't work for teams. I've been testing with this bug. It seems to be an agent issue. The correct format should be "@[San Dang] (205f29da-231e-4a0e-a0b2-b398e6302087) ping"
  2. You should follow manifest & hooks style. Put patch of Teams in src/lib/messaging/channels/teams

@wscurran wscurran added area: integrations Third-party service integration behavior area: messaging Messaging channels, bridges, manifests, or channel lifecycle bug-fix PR fixes a bug or regression labels Jun 26, 2026
@wscurran

Copy link
Copy Markdown
Contributor

✨ Thanks for the proposed fix patching the @openclaw/msteams runtime to convert raw AAD object ID mentions into proper Teams mention markup. This proposes a way to render display-name mentions as chips while keeping the explicit @[Name](id) syntax working and failing closed if the upstream parser shape changes.


Related open issues:

@deepujain

Copy link
Copy Markdown
Collaborator Author

Moved the Teams mention patch into the Teams channel hook path and tightened it to the explicit @[Name] (AAD object id) form. The post-install test now starts from an unpatched runtime, and the parser test confirms loose email-like text is left alone.

Validation: npm run build:cli; npm run typecheck:cli; npm run lint; focused Vitest for the Teams mention patch, manifest, and build applier.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/lib/messaging/channels/teams/hooks/msteams-mention-patch.ts`:
- Around line 29-71: The exact-string match in
patchMSTeamsMentionEntitiesInSource is too brittle and treats a future upstream
parser change as a failure. Update the logic around the original block match so
it can recognize the already-fixed spaced-mention parseMentions shape (for
example by detecting a spaced mention regex in the source) and return status
"already-applied" instead of "no-match" when the upstream Teams parser has
already adopted the change. Keep the existing error path for truly unrecognized
shapes, but make patchInstalledOpenClawMSTeamsMentions degrade gracefully when
the patch is no longer needed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 02a43ecc-ebb4-4ba7-8b90-4e7aab8a6b24

📥 Commits

Reviewing files that changed from the base of the PR and between 90ec826 and 503f430.

📒 Files selected for processing (7)
  • src/lib/messaging/applier/build/messaging-build-applier.mts
  • src/lib/messaging/channels/manifests.test.ts
  • src/lib/messaging/channels/teams/hooks/index.ts
  • src/lib/messaging/channels/teams/hooks/msteams-mention-patch.ts
  • src/lib/messaging/channels/teams/manifest.ts
  • test/messaging-build-applier.test.ts
  • test/openclaw-msteams-mention-patch.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/lib/messaging/applier/build/messaging-build-applier.mts

@deepujain
deepujain force-pushed the fix/5852-teams-mention-display-name branch from 503f430 to 85f9380 Compare June 27, 2026 03:13
@deepujain

Copy link
Copy Markdown
Collaborator Author

Rebased this branch and handled the latest parser-shape note. The hook now treats an upstream msteams parser that already accepts spaced Teams mentions as already applied, while still failing closed for unknown shapes.

Validation: npm run build:cli; npm run lint; focused Vitest for the Teams mention patch, manifest, and build applier.

@sandl99

sandl99 commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Thanks for putting this together. I am going to close this in favor of #5956 because the regex patch here only covers the @[Name] (id) spacing variant, while the failure we traced is that the bot can emit plain or multiline text that the Teams extension cannot convert into a Teams mention entity.

#5956 keeps the parser unchanged and installs a Teams-owned msteams skill during NemoClaw Teams setup, so OpenClaw is prompted to use the supported @Display Name syntax from the start. That gives us a narrower NemoClaw change with setup, manifest, and build coverage.

Appreciate the investigation here; it helped identify the right layer for the fix.

@sandl99 sandl99 closed this Jun 29, 2026
cv added a commit that referenced this pull request Jun 30, 2026
<!-- markdownlint-disable MD041 -->
## Summary

This PR installs a Microsoft Teams-specific OpenClaw runtime preload
that keeps native Teams mention syntax next to OpenClaw's `message` tool
hints. The preload patches the pinned `@openclaw/msteams` prompt export
at its exact package entry while preserving Teams startup if the
upstream export changes or is immutable.

This supersedes #5864 because the issue is not a parser-spacing variant
in NemoClaw. OpenClaw's Teams send path already parses the supported
syntax into Teams mention entities; NemoClaw's failure mode is that the
bot was often not prompted to use that syntax.

## Related Issue

Replaces #5864.
Fixes #5852

## Changes

- Add a Teams OpenClaw `msteams-message-hints` runtime preload installed
for `boot` and `connect` through the messaging runtime-preload
machinery.
- Restrict the CommonJS hook to the reviewed
`@openclaw/msteams/dist/channel-plugin-api.js` boundary; plugin-shaped
child dependencies and unrelated `msteams` paths remain untouched.
- Restore the global load hook in `finally` after the exact entry
attempt, whether patching succeeds, fails, or the module throws.
- Fail open with one bounded static warning when the plugin export
cannot be patched; never include upstream error text or make prompt
guidance take Teams down.
- Recognize the pinned `openclaw.mjs gateway` launcher shape without
activating for arbitrary Node children whose third argument is
`gateway`.
- Cover CommonJS and native `require(esm)` entry loads, the real
`dist/index.js` to `channel-plugin-api.js` flow, child-module isolation,
idempotency, immutable exports, warning behavior, hook restoration,
launcher gating, and unrelated ESM linking.
- Remove the local regex reimplementation that previously overstated
production Teams sender coverage.
- Add a compiled package-contract regression that models the reviewed
2026.5.27 `runtimeExtensions` → OpenClaw `createRequire` → ESM
`channel-plugin-api.js` load seam, binds it to the repository OpenClaw
pin, records the manually reviewed package-load shape, and asserts the
mention contract/order plus hook restoration without vendoring the
upstream parser.

## Source Boundary

The pinned OpenClaw 2026.5.27 package loads its Teams plugin through
`dist/channel-plugin-api.js`, where
`msteamsPlugin.agentPrompt.messageToolHints` is exported. NemoClaw
changes only that prompt function. It does not fork or modify the Bot
Framework sender or mention parser.

The manifest keeps the preload asset `optional: false`: a missing or
mispackaged compiled file is a NemoClaw build/setup failure. After that
asset loads, an upstream export-shape mismatch or immutable plugin is
intentionally fail-open so Teams preserves upstream behavior, emits one
bounded static warning, and starts without the additional prompt hint.

A repository test cannot honestly claim real Teams delivery or Bot
Framework mention conversion without a provisioned Teams app, tenant,
webhook, and live message. Vendoring third-party package code as a
fixture would also create false production proof. The focused tests
therefore lock the reviewed package export/lifecycle boundary, while
live `channels-stop-start` and `messaging-providers` runs validate
adjacent runtime installation and lifecycle. Actual mention conversion
remains the pinned upstream package's contract; revalidate this preload
whenever the OpenClaw pin changes, and remove it once upstream ships
equivalent prompt guidance.

Sequencing note: #5595 upgrades the OpenClaw pin and overlaps the Teams
manifest/compiler surface. If #5595 lands first or this PR is rebased
across it, revalidate this package boundary and keep or remove the shim
based on the new pinned package; do not assume the 2026.5.27 contract
remains unchanged.

## Release Decision

For v0.0.71, this PR is release-deferred. Both required exact-head
advisor verdicts remain blocking (`merge_after_fixes` and
`needs_rework`), and live Teams Bot Framework delivery proof is
unavailable. Maintainers are not overriding either gate; do not merge
this PR for v0.0.71.

The residual evidence gap is that repository tests cannot prove a Teams
UI mention chip or user notification without a provisioned Teams tenant,
app, and webhook. This PR changes only always-visible prompt guidance;
it does not modify or claim automated proof of the Bot Framework
sender/parser.

The pinned 2026.5.27 npm package and OpenClaw loader seam were manually
reviewed. Hermetic CI enforces the repository pin, reviewed package-load
shape, hint contract, and loader restoration, but that evidence does not
satisfy the required delivery-proof gate. If production mentions still
render raw IDs, the source fix belongs in the upstream Teams send path.

## Type of Change

- [x] Code change (feature, bug fix, or refactor)
- [ ] Code change with doc updates
- [ ] Doc only (prose changes, no code sample modifications)
- [ ] Doc only (includes code sample changes)

## Quality Gates
<!-- Check all that apply. For any "covered by existing tests", "not
applicable", or waiver entry, add a brief justification on the same line
or in the Changes section. -->
- [x] Tests added or updated for changed behavior
- [ ] Existing tests cover changed behavior — justification:
- [ ] Tests not applicable — justification:
- [ ] Docs updated for user-facing behavior changes
- [x] Docs not applicable — justification: this restores expected
Teams-native mention prompting automatically and adds no user action,
command, configuration, environment variable, or support boundary.
- [x] Sensitive paths changed (security, policy, credentials, preflight,
onboarding, inference, runner, sandbox, or messaging)
- [x] Sensitive-path review completed or maintainer-approved waiver
recorded — reviewer/approval link/justification: exact entry scoping,
fail-open warning, lifecycle restoration, child-module isolation, and
launcher gating were manually audited and regression-tested.
- [ ] Non-success, skipped, or missing CI check accepted by maintainer —
check name, approval link, and follow-up issue:

## Verification
<!-- Check each item you ran and confirmed. Leave unchecked items you
skipped. Doc-only changes do not require npm test unless you ran it. -->
- [x] PR description includes the DCO sign-off declaration and every
commit appears as `Verified` in GitHub
- [x] Git hooks passed during commit and push
- [x] Targeted tests pass for changed behavior — 47/47 across compiled
package-contract, preload, channel-manifest, and compiler tests
- [ ] Full `npm test` passes (broad runtime changes only)
- [x] Quality Gates section completed with required justifications or
waivers
- [x] No secrets, API keys, or credentials committed
- [ ] `npm run docs` builds without warnings (doc changes only)
- [ ] Doc pages follow the style guide (doc changes only)
- [ ] New doc pages include SPDX header and frontmatter (new pages only)

Exact-head live evidence (head `e120c86d`):

- `channels-stop-start` (OpenClaw + Hermes):
https://github.com/NVIDIA/NemoClaw/actions/runs/28428153446 — passed

Pre-follow-up live evidence (head `8149bce`):

- `channels-stop-start`:
https://github.com/NVIDIA/NemoClaw/actions/runs/28425570138
- `messaging-providers`:
https://github.com/NVIDIA/NemoClaw/actions/runs/28425986489

---
<!-- DCO sign-off is required in this PR description, and every commit
must appear as Verified in GitHub. -->
Signed-off-by: San Dang <[email protected]>


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Improved Microsoft Teams message tool hints to consistently include
native mention guidance.
* Added automatic preloading of the Teams hint patch for both initial
startup and reconnect phases.

* **Bug Fixes**
* Ensures the mention hint is injected only once and positioned before
the first targeting-related hint.
* Applies best-effort patching that won’t break unrelated module
loading.

* **Tests**
* Expanded unit/contract coverage to verify CommonJS/ESM compatibility,
idempotency, correct hint ordering, and safe loader behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: San Dang <[email protected]>
Signed-off-by: Carlos Villela <[email protected]>
Co-authored-by: Carlos Villela <[email protected]>
Hadar301 pushed a commit to Hadar301/NemoClaw-OpenShift that referenced this pull request Jul 12, 2026
<!-- markdownlint-disable MD041 -->
## Summary

This PR installs a Microsoft Teams-specific OpenClaw runtime preload
that keeps native Teams mention syntax next to OpenClaw's `message` tool
hints. The preload patches the pinned `@openclaw/msteams` prompt export
at its exact package entry while preserving Teams startup if the
upstream export changes or is immutable.

This supersedes NVIDIA#5864 because the issue is not a parser-spacing variant
in NemoClaw. OpenClaw's Teams send path already parses the supported
syntax into Teams mention entities; NemoClaw's failure mode is that the
bot was often not prompted to use that syntax.

## Related Issue

Replaces NVIDIA#5864.
Fixes NVIDIA#5852

## Changes

- Add a Teams OpenClaw `msteams-message-hints` runtime preload installed
for `boot` and `connect` through the messaging runtime-preload
machinery.
- Restrict the CommonJS hook to the reviewed
`@openclaw/msteams/dist/channel-plugin-api.js` boundary; plugin-shaped
child dependencies and unrelated `msteams` paths remain untouched.
- Restore the global load hook in `finally` after the exact entry
attempt, whether patching succeeds, fails, or the module throws.
- Fail open with one bounded static warning when the plugin export
cannot be patched; never include upstream error text or make prompt
guidance take Teams down.
- Recognize the pinned `openclaw.mjs gateway` launcher shape without
activating for arbitrary Node children whose third argument is
`gateway`.
- Cover CommonJS and native `require(esm)` entry loads, the real
`dist/index.js` to `channel-plugin-api.js` flow, child-module isolation,
idempotency, immutable exports, warning behavior, hook restoration,
launcher gating, and unrelated ESM linking.
- Remove the local regex reimplementation that previously overstated
production Teams sender coverage.
- Add a compiled package-contract regression that models the reviewed
2026.5.27 `runtimeExtensions` → OpenClaw `createRequire` → ESM
`channel-plugin-api.js` load seam, binds it to the repository OpenClaw
pin, records the manually reviewed package-load shape, and asserts the
mention contract/order plus hook restoration without vendoring the
upstream parser.

## Source Boundary

The pinned OpenClaw 2026.5.27 package loads its Teams plugin through
`dist/channel-plugin-api.js`, where
`msteamsPlugin.agentPrompt.messageToolHints` is exported. NemoClaw
changes only that prompt function. It does not fork or modify the Bot
Framework sender or mention parser.

The manifest keeps the preload asset `optional: false`: a missing or
mispackaged compiled file is a NemoClaw build/setup failure. After that
asset loads, an upstream export-shape mismatch or immutable plugin is
intentionally fail-open so Teams preserves upstream behavior, emits one
bounded static warning, and starts without the additional prompt hint.

A repository test cannot honestly claim real Teams delivery or Bot
Framework mention conversion without a provisioned Teams app, tenant,
webhook, and live message. Vendoring third-party package code as a
fixture would also create false production proof. The focused tests
therefore lock the reviewed package export/lifecycle boundary, while
live `channels-stop-start` and `messaging-providers` runs validate
adjacent runtime installation and lifecycle. Actual mention conversion
remains the pinned upstream package's contract; revalidate this preload
whenever the OpenClaw pin changes, and remove it once upstream ships
equivalent prompt guidance.

Sequencing note: NVIDIA#5595 upgrades the OpenClaw pin and overlaps the Teams
manifest/compiler surface. If NVIDIA#5595 lands first or this PR is rebased
across it, revalidate this package boundary and keep or remove the shim
based on the new pinned package; do not assume the 2026.5.27 contract
remains unchanged.

## Release Decision

For v0.0.71, this PR is release-deferred. Both required exact-head
advisor verdicts remain blocking (`merge_after_fixes` and
`needs_rework`), and live Teams Bot Framework delivery proof is
unavailable. Maintainers are not overriding either gate; do not merge
this PR for v0.0.71.

The residual evidence gap is that repository tests cannot prove a Teams
UI mention chip or user notification without a provisioned Teams tenant,
app, and webhook. This PR changes only always-visible prompt guidance;
it does not modify or claim automated proof of the Bot Framework
sender/parser.

The pinned 2026.5.27 npm package and OpenClaw loader seam were manually
reviewed. Hermetic CI enforces the repository pin, reviewed package-load
shape, hint contract, and loader restoration, but that evidence does not
satisfy the required delivery-proof gate. If production mentions still
render raw IDs, the source fix belongs in the upstream Teams send path.

## Type of Change

- [x] Code change (feature, bug fix, or refactor)
- [ ] Code change with doc updates
- [ ] Doc only (prose changes, no code sample modifications)
- [ ] Doc only (includes code sample changes)

## Quality Gates
<!-- Check all that apply. For any "covered by existing tests", "not
applicable", or waiver entry, add a brief justification on the same line
or in the Changes section. -->
- [x] Tests added or updated for changed behavior
- [ ] Existing tests cover changed behavior — justification:
- [ ] Tests not applicable — justification:
- [ ] Docs updated for user-facing behavior changes
- [x] Docs not applicable — justification: this restores expected
Teams-native mention prompting automatically and adds no user action,
command, configuration, environment variable, or support boundary.
- [x] Sensitive paths changed (security, policy, credentials, preflight,
onboarding, inference, runner, sandbox, or messaging)
- [x] Sensitive-path review completed or maintainer-approved waiver
recorded — reviewer/approval link/justification: exact entry scoping,
fail-open warning, lifecycle restoration, child-module isolation, and
launcher gating were manually audited and regression-tested.
- [ ] Non-success, skipped, or missing CI check accepted by maintainer —
check name, approval link, and follow-up issue:

## Verification
<!-- Check each item you ran and confirmed. Leave unchecked items you
skipped. Doc-only changes do not require npm test unless you ran it. -->
- [x] PR description includes the DCO sign-off declaration and every
commit appears as `Verified` in GitHub
- [x] Git hooks passed during commit and push
- [x] Targeted tests pass for changed behavior — 47/47 across compiled
package-contract, preload, channel-manifest, and compiler tests
- [ ] Full `npm test` passes (broad runtime changes only)
- [x] Quality Gates section completed with required justifications or
waivers
- [x] No secrets, API keys, or credentials committed
- [ ] `npm run docs` builds without warnings (doc changes only)
- [ ] Doc pages follow the style guide (doc changes only)
- [ ] New doc pages include SPDX header and frontmatter (new pages only)

Exact-head live evidence (head `e120c86d`):

- `channels-stop-start` (OpenClaw + Hermes):
https://github.com/NVIDIA/NemoClaw/actions/runs/28428153446 — passed

Pre-follow-up live evidence (head `8149bce`):

- `channels-stop-start`:
https://github.com/NVIDIA/NemoClaw/actions/runs/28425570138
- `messaging-providers`:
https://github.com/NVIDIA/NemoClaw/actions/runs/28425986489

---
<!-- DCO sign-off is required in this PR description, and every commit
must appear as Verified in GitHub. -->
Signed-off-by: San Dang <[email protected]>


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Improved Microsoft Teams message tool hints to consistently include
native mention guidance.
* Added automatic preloading of the Teams hint patch for both initial
startup and reconnect phases.

* **Bug Fixes**
* Ensures the mention hint is injected only once and positioned before
the first targeting-related hint.
* Applies best-effort patching that won’t break unrelated module
loading.

* **Tests**
* Expanded unit/contract coverage to verify CommonJS/ESM compatibility,
idempotency, correct hint ordering, and safe loader behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: San Dang <[email protected]>
Signed-off-by: Carlos Villela <[email protected]>
Co-authored-by: Carlos Villela <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: integrations Third-party service integration behavior area: messaging Messaging channels, bridges, manifests, or channel lifecycle bug-fix PR fixes a bug or regression

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[macOS][Agent&Skills] MS Teams bot @mention renders raw AAD object ID instead of a display-name mention

4 participants