Skip to content

fix(hermes): preserve strip think method binding#4731

Merged
cv merged 1 commit into
mainfrom
fix/hermes-strip-think-instance
Jun 3, 2026
Merged

fix(hermes): preserve strip think method binding#4731
cv merged 1 commit into
mainfrom
fix/hermes-strip-think-instance

Conversation

@cv

@cv cv commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Preserves the descriptor binding for Hermes' patched AIAgent._strip_think_blocks method. This prevents the messaging response normalizer from turning an instance method into a staticmethod and breaking Hermes chat completions with a missing content argument.

Changes

  • Detect whether _strip_think_blocks is a staticmethod, classmethod, or instance method before patching it.
  • Wrap each method shape with the matching descriptor so the original call signature is preserved.
  • Add regression coverage for the real instance-method binding shape that failed in the Bedrock-compatible Hermes E2E job.

Type of Change

  • 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)

Verification

  • npx prek run --all-files passes
  • npm test passes
  • Tests added or updated for new or changed behavior
  • No secrets, API keys, or credentials committed
  • Docs updated for user-facing behavior changes
  • 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)

Signed-off-by: Carlos Villela cvillela@nvidia.com

Summary by CodeRabbit

  • Bug Fixes

    • Fixed method binding in the Hermes plugin's messaging response handling to ensure correct execution semantics.
    • Improved normalization of messaging responses across different platforms.
  • Tests

    • Added test coverage for messaging response patch behavior and instance method binding verification.

Signed-off-by: Carlos Villela <cvillela@nvidia.com>
@cv cv self-assigned this Jun 3, 2026
@coderabbitai

coderabbitai Bot commented Jun 3, 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: 5b674b55-77f7-4e96-8930-a879c25bbe8b

📥 Commits

Reviewing files that changed from the base of the PR and between 19a17ea and b8e9668.

📒 Files selected for processing (2)
  • agents/hermes/plugin/__init__.py
  • test/hermes-plugin-handlers.test.ts

📝 Walkthrough

Walkthrough

The Hermes plugin patch for AIAgent._strip_think_blocks now correctly preserves the original method's descriptor type and binding semantics while normalizing messaging outputs through the tracked platform. A test verifies instance-method binding is maintained after patching.

Changes

Hermes messaging patch descriptor preservation

Layer / File(s) Summary
Descriptor-aware patch and response normalization
agents/hermes/plugin/__init__.py
inspect is imported to detect method descriptor types. _install_messaging_response_patch() uses inspect.getattr_static to identify whether _strip_think_blocks is a staticmethod, classmethod, or instance method, wraps the patched implementation accordingly to preserve binding semantics, and normalizes raw messaging pseudo-tool output through _normalize_raw_messaging_tool_response using the current platform.
Instance-method binding test verification
test/hermes-plugin-handlers.test.ts
New test case installs the messaging patch, sets platform to "telegram", stubs _strip_think_blocks as an instance method with a call counter, and verifies the patch preserves instance binding by checking both normalized output and call counter increments while plain responses are unaffected.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • NVIDIA/NemoClaw#4175: Both PRs modify agents/hermes/plugin/__init__.py to patch AIAgent._strip_think_blocks for Hermes messaging and normalize raw send_message pseudo-tool outputs, with this PR additionally fixing descriptor/binding semantics and extending test coverage for instance-method correctness.

Suggested labels

integration: hermes, area: messaging, bug-fix

Poem

🐰 A patch that binds so true,
Each method knows what it must do—
Static, class, or instance-bound,
The descriptor dance goes round and round!
Telegram whispers flow just right,
Now _strip_think_blocks works right. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.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 directly addresses the main change: preserving method binding for the _strip_think_blocks patch in Hermes, which is the core fix preventing descriptor type loss.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/hermes-strip-think-instance

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

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

PR Review Advisor

Findings: 0 needs attention, 0 worth checking, 0 nice ideas
Top item: No actionable code findings

Workflow run details

This is an automated advisory review. A human maintainer must make the final merge decision.

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

E2E Advisor Recommendation

Required E2E: hermes-e2e, hermes-discord-e2e, hermes-slack-e2e
Optional E2E: None

Dispatch hint: hermes-e2e,hermes-discord-e2e,hermes-slack-e2e

Auto-dispatched E2E: hermes-e2e, hermes-discord-e2e, hermes-slack-e2e via nightly-e2e.yaml at b8e9668c2e77145ed51ce0c9ac87a04dd66efa1dnightly run

Workflow run

Full advisor summary

E2E Recommendation Advisor

Base: origin/main
Head: HEAD
Confidence: high

Required E2E

  • hermes-e2e (high; up to 60 minutes and requires NVIDIA_API_KEY): Validates the core Hermes install/onboard/sandbox/live inference path after changing the Hermes plugin loaded in real Hermes runtime sessions.
  • hermes-discord-e2e (high; up to 60 minutes and requires NVIDIA_API_KEY plus fake Discord E2E configuration): Exercises Hermes with a real Discord gateway-style messaging configuration; this is directly relevant to platform-anchored send_message response normalization and cross-platform misdelivery prevention.
  • hermes-slack-e2e (high; up to 60 minutes and requires NVIDIA_API_KEY plus fake Slack E2E configuration): Exercises Hermes with Slack messaging enabled, covering another supported platform affected by the platform-aware response patch and ensuring the runtime plugin still works in a messaging sandbox.

Optional E2E

  • None.

New E2E recommendations

  • Hermes Telegram first-message messaging response (high): The changed code explicitly handles Telegram-targeted send_message pseudo-calls and first-turn platform anchoring, but no existing dedicated hermes-telegram-e2e job was found. Current coverage relies on unit tests plus generic Hermes and Discord/Slack E2Es.
    • Suggested test: Add a Hermes Telegram first-message E2E that drives the gateway/inbound message path with a fake Telegram API and asserts same-platform normalization while cross-platform pseudo-calls are not delivered.

Dispatch hint

  • Workflow: .github/workflows/nightly-e2e.yaml
  • jobs input: hermes-e2e,hermes-discord-e2e,hermes-slack-e2e

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

E2E Scenario Advisor Recommendation

Required scenario E2E: ubuntu-repo-cloud-hermes-discord
Optional scenario E2E: ubuntu-repo-cloud-hermes-slack, ubuntu-repo-cloud-hermes

Dispatch required scenario E2E:

  • gh workflow run e2e-scenarios.yaml --ref <pr-head-ref> --field scenarios=ubuntu-repo-cloud-hermes-discord

Workflow run

Full scenario advisor summary

E2E Scenario Advisor

Base: origin/main
Head: HEAD
Confidence: medium

Required scenario E2E

  • ubuntu-repo-cloud-hermes-discord: Hermes plugin messaging-response patch changed; this scenario exercises Hermes with a real Discord messaging onboarding path and the messaging-discord suite, covering the platform-aware gateway/message path most directly related to the modified _strip_think_blocks wrapper.
    • Dispatch: gh workflow run e2e-scenarios.yaml --ref <pr-head-ref> --field scenarios=ubuntu-repo-cloud-hermes-discord

Optional scenario E2E

  • ubuntu-repo-cloud-hermes-slack: Adjacent Hermes messaging scenario on a different platform; useful to confirm the same generic messaging-response patch and current-platform anchoring works outside Discord, but not the smallest primary target.
    • Dispatch: gh workflow run e2e-scenarios.yaml --ref <pr-head-ref> --field scenarios=ubuntu-repo-cloud-hermes-slack
  • ubuntu-repo-cloud-hermes: Optional baseline Hermes scenario to validate the plugin still loads in the non-messaging Hermes onboarding path after changing method binding behavior.
    • Dispatch: gh workflow run e2e-scenarios.yaml --ref <pr-head-ref> --field scenarios=ubuntu-repo-cloud-hermes

Relevant changed files

  • agents/hermes/plugin/__init__.py

@cv cv merged commit 11fcbf7 into main Jun 3, 2026
32 checks passed
@cv cv deleted the fix/hermes-strip-think-instance branch June 3, 2026 22:43
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Selective E2E Results — ✅ All requested jobs passed

Run: 26917582203
Target ref: b8e9668c2e77145ed51ce0c9ac87a04dd66efa1d
Workflow ref: main
Requested jobs: hermes-e2e,hermes-discord-e2e,hermes-slack-e2e
Summary: 3 passed, 0 failed, 0 skipped

Job Result
hermes-discord-e2e ✅ success
hermes-e2e ✅ success
hermes-slack-e2e ✅ success

@wscurran wscurran added the bug-fix PR fixes a bug or regression label Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix PR fixes a bug or regression

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants