Skip to content

Conversation

@matdev83
Copy link
Owner

@matdev83 matdev83 commented Oct 12, 2025

Summary

  • ensure the tool call reactor middleware accepts empty replacement payloads when swallowing
  • add a regression test confirming an empty steering message still swallows the tool call

Testing

  • python -m pytest tests/unit/core/services/test_tool_call_reactor_middleware.py -q -o addopts=
  • python -m pytest -o addopts=

https://chatgpt.com/codex/tasks/task_e_68ec25355ce08333b87d0889ca85b9a5

Summary by CodeRabbit

  • Bug Fixes

    • Corrected response handling so tool-call outputs can be intentionally replaced with empty content while preserving associated metadata. This prevents unintended text from appearing when an empty result is desired and ensures consistent behavior across responses.
  • Tests

    • Added unit coverage for empty replacement scenarios to validate that content is cleared correctly and metadata is retained, helping prevent regressions.

@coderabbitai
Copy link

coderabbitai bot commented Oct 12, 2025

Walkthrough

Updated middleware logic to consider any non-None replacement payload as valid when swallowing tool calls. Added a unit test to verify swallowing with an empty string replacement results in empty content and correct metadata recording. No public interfaces changed.

Changes

Cohort / File(s) Summary of Changes
Middleware logic adjustment
src/core/services/tool_call_reactor_middleware.py
Changed condition from truthy check to is not None for replacement responses during tool-call swallowing; other logic unchanged.
Unit tests
tests/unit/core/services/test_tool_call_reactor_middleware.py
Added test to assert swallowing with empty string replacement yields empty content and preserves swallowing metadata and handler attribution.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Caller
  participant M as ToolCallReactorMiddleware
  participant H as Swallow Handler

  C->>M: process(message with tool_calls)
  M->>H: evaluate swallow & produce replacement_response
  alt replacement_response is not None
    Note over M: New behavior: empty string is valid replacement
    M->>C: return message with content = replacement_response<br/>+ swallowing metadata
  else replacement_response is None
    M->>C: return original message (unmodified)
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nudge the wires with gentle might,
Swap truthy checks for clearer sight.
An empty whisper now has voice,
In swallowed calls, we honor choice.
Thump-thump—my paws approve the string,
Even when it’s nothing—it's still a thing. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title accurately and concisely describes the primary change to allow empty replacement responses in the tool call reactor middleware, aligning with the code adjustments and new test.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/fix-a-bug-in-reactor-tool-7sr2mp

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dd216cf and d4e3523.

📒 Files selected for processing (2)
  • src/core/services/tool_call_reactor_middleware.py (1 hunks)
  • tests/unit/core/services/test_tool_call_reactor_middleware.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*.py: Avoid using emojis in Python code comments or docstrings
Follow PEP 8 and use type hints for all functions
Import order must be: standard library, third-party, then local imports, separated by blank lines
Naming conventions: snake_case for variables and functions; PascalCase for classes
Error handling: use specific exceptions and include meaningful error messages
Prefer f-strings for string formatting

Files:

  • src/core/services/tool_call_reactor_middleware.py
  • tests/unit/core/services/test_tool_call_reactor_middleware.py
src/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

src/**/*.py: Catch specific exceptions; avoid broad except Exception blocks
If a broad exception must be caught, log with exc_info=True and re-raise a specific custom exception
Use the most specific exception class from src.core.common.exceptions that accurately describes the error
Provide clear, helpful error messages and include relevant details in the details dictionary of custom exceptions

Files:

  • src/core/services/tool_call_reactor_middleware.py
🧬 Code graph analysis (1)
tests/unit/core/services/test_tool_call_reactor_middleware.py (3)
src/core/interfaces/response_processor_interface.py (1)
  • ProcessedResponse (8-30)
src/core/interfaces/tool_call_reactor_interface.py (1)
  • ToolCallReactionResult (47-57)
src/core/services/tool_call_reactor_middleware.py (1)
  • process (57-220)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: test (3.10)
  • GitHub Check: Analyze (python)
🔇 Additional comments (2)
tests/unit/core/services/test_tool_call_reactor_middleware.py (1)

406-451: LGTM! Well-structured regression test.

The test correctly verifies that handlers can swallow tool calls with empty string replacements. It properly asserts that:

  • Content is empty
  • Swallowing metadata is preserved
  • Handler metadata is recorded

The test structure mirrors the existing non-empty replacement test, maintaining consistency.

src/core/services/tool_call_reactor_middleware.py (1)

198-198: LGTM! Correctly fixes the empty replacement bug.

Changing from a truthy check to an explicit is not None check allows handlers to swallow tool calls with empty string replacements. This aligns with the str | None type hint and is backward compatible.


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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant