Skip to content

fix(routing): honor the Handled flag so a before-hook can refuse a function call - #1425

Merged
Oceania2018 merged 1 commit into
SciSharp:masterfrom
ywang1110:fix/honor-handled-flag-in-invoke-function
Sep 5, 2026
Merged

fix(routing): honor the Handled flag so a before-hook can refuse a function call#1425
Oceania2018 merged 1 commit into
SciSharp:masterfrom
ywang1110:fix/honor-handled-flag-in-invoke-function

Conversation

@ywang1110

Copy link
Copy Markdown
Contributor

…nction call

@ywang1110 ywang1110 changed the title fix(routing): honor the Handled flag so a before-hook can refuse a fu… fix(routing): honor the Handled flag so a before-hook can refuse a function call Sep 5, 2026
@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Honor Handled Flag When Invoking Routed Functions

🐞 Bug fix 🕐 Less than 10 minutes

Grey Divider

AI Description

• Skips function execution when a before-hook marks the cloned message as handled.
• Suppresses after-hooks for refused calls while preserving the hook-provided response.
Diagram

sequenceDiagram
    participant C as Routing Caller
    participant R as Routing Service
    participant H as Conversation Hooks
    participant E as Function Executor
    C->>R: Invoke function
    R->>H: Run before-hooks
    H-->>R: Update cloned message
    alt Handled is false
        R->>E: Execute function
        E-->>R: Return result
        R->>H: Run after-hooks
    else Handled is true
        R->>R: Skip execution
    end
    R-->>C: Copy response and return
Loading
High-Level Assessment

The PR's approach is optimal because it enforces the existing documented Handled contract at the execution boundary without changing hook interfaces. Returning early or introducing a separate hook decision type would add broader control-flow or API changes without improving this targeted fix.

Files changed (1) +16 / -5

Bug fix (1) +16 / -5
RoutingService.InvokeFunction.csSkip handled function calls and their after-hooks +16/-5

Skip handled function calls and their after-hooks

• Checks the cloned message's Handled flag after all before-hooks run. When handled, it bypasses the function executor and OnFunctionExecuted hooks while still copying the hook-provided response back to the original message.

src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeFunction.cs

@qodo-code-review

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can keep summaries lean with Finding overflow, which tucks the rest behind 'View more'

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@Oceania2018
Oceania2018 merged commit db8f053 into SciSharp:master Sep 5, 2026
4 checks passed
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.

3 participants