Skip to content

fix: stop run_diagnostic_code from crashing every investigation dispatch#988

Merged
VaibhavUpreti merged 1 commit intoTracer-Cloud:mainfrom
AarushSharmaa:fix/956-run-diagnostic-code-is-available
Apr 27, 2026
Merged

fix: stop run_diagnostic_code from crashing every investigation dispatch#988
VaibhavUpreti merged 1 commit intoTracer-Cloud:mainfrom
AarushSharmaa:fix/956-run-diagnostic-code-is-available

Conversation

@AarushSharmaa
Copy link
Copy Markdown
Contributor

@AarushSharmaa AarushSharmaa commented Apr 27, 2026

Fixes #956

Describe the changes you have made in this PR -

run_diagnostic_code was registered with @tool but without is_available or extract_params. The dispatcher's defaults are: always select the tool (is_available returns True) and call it with empty kwargs (extract_params returns {}). Since run_diagnostic_code requires a code argument, this caused a TypeError on every investigation - even ones completely unrelated to code execution.

The fix is one line: is_available=lambda _: False in the @tool decorator. This matches the pattern used in #732, #703, and #704 which fixed the same class of bug for other tools. The tool still works perfectly when called directly with a code argument - it just won't be auto-selected by the dispatcher anymore.

Also updated the existing test that was asserting the wrong behaviour (is_available returning True) and made the intent explicit with a second assertion.


Code Understanding and AI Usage

Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?

  • No, I wrote all the code myself
  • Yes, I used AI assistance (continue below)

If you used AI assistance:

  • I have reviewed every single line of the AI-generated code
  • I can explain the purpose and logic of each function/component I added
  • I have tested edge cases and understand how the code handles them
  • I have modified the AI output to follow this project's coding standards and conventions

Explain your implementation approach:

I traced the crash by reading execute_actions.py (the dispatcher) and saw it calls action.extract_params(sources) then action.run(**kwargs). For tools without a custom extract_params, kwargs is always {}. run_diagnostic_code requires code as a positional argument, so the call always raises TypeError.

I looked at how prior fixes (#732, #703, #704) handled the same problem: they all used is_available=lambda _: False to tell the dispatcher "skip me, I can't be auto-called". That's the right fix here too, because there's no way to pull a meaningful code string out of an alert's source dict.

The one-line change to the decorator is the entire fix. I also flipped the test that was asserting the wrong thing and added a second assertion that documents why this matters.


Checklist before requesting a review

  • I have added proper PR title and linked to the issue
  • I have performed a self-review of my code
  • I can explain the purpose of every function, class, and logic block I added
  • I understand why my changes work and have tested them thoroughly
  • I have considered potential edge cases and how my code handles them
  • If it is a core feature, I have added thorough tests
  • My code follows the project's style guidelines and conventions

Note: Please check Allow edits from maintainers if you would like us to assist in the PR.

The dispatcher calls every tool whose is_available() returns True, then
passes whatever extract_params() pulls from the alert sources. This tool
had neither callback, so it always got selected and always got called with
no arguments — causing a TypeError on every single investigation run.

Added is_available=lambda _: False so the dispatcher skips it. The tool
still works fine when called directly with a code argument; it just
shouldn't be auto-selected when the agent has no code to give it.

Also updated the existing test that was asserting the wrong behaviour
(is_available returning True) and added a second assertion to make the
intent explicit.

Fixes Tracer-Cloud#956
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 27, 2026

Greptile Summary

This PR fixes a crash where run_diagnostic_code was being auto-selected by the investigation dispatcher on every dispatch because its @tool registration was missing is_available. Without the guard, the dispatcher would call action.run(**{}), omitting the required code positional argument and raising a TypeError. The fix adds is_available=lambda _: False, which is the established pattern used in PRs #732, #703, and #704 for the same class of bug, and the accompanying test is corrected to assert the new behaviour.

Confidence Score: 5/5

Safe to merge — one-line fix with updated tests, follows the established pattern for this class of bug.

The change is minimal and consistent with prior fixes (#732, #703, #704). The dispatcher logic in execute_actions.py confirms that returning False from is_available correctly gates auto-invocation. The tool remains callable via direct invocation. The test now accurately documents the intended behaviour with two complementary assertions. No regressions or edge-case concerns identified.

No files require special attention.

Important Files Changed

Filename Overview
app/tools/run_diagnostic_code.py Adds is_available=lambda _: False to the @tool decorator — minimal, correct fix that prevents the dispatcher from auto-invoking the tool without a code argument.
tests/tools/test_run_diagnostic_code_tool.py Renames and updates the is_available test to assert False for both empty sources and sources containing a knowledge/code entry, correctly covering the fixed behaviour.

Sequence Diagram

sequenceDiagram
    participant Dispatcher as Investigation Dispatcher
    participant Tool as run_diagnostic_code

    Note over Dispatcher,Tool: Before fix — every dispatch
    Dispatcher->>Tool: is_available(sources) → True (default)
    Dispatcher->>Tool: extract_params(sources) → {}
    Dispatcher->>Tool: run(**{})
    Tool-->>Dispatcher: TypeError: missing required arg 'code'

    Note over Dispatcher,Tool: After fix — every dispatch
    Dispatcher->>Tool: is_available(sources) → False
    Dispatcher-->>Dispatcher: skip — Action not available

    Note over Dispatcher,Tool: Direct / explicit call (unaffected)
    Dispatcher->>Tool: run(code="print(1)")
    Tool-->>Dispatcher: {success: True, stdout: "1\n", ...}
Loading

Reviews (1): Last reviewed commit: "fix: stop run_diagnostic_code from crash..." | Re-trigger Greptile

Copy link
Copy Markdown
Member

@VaibhavUpreti VaibhavUpreti left a comment

Choose a reason for hiding this comment

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

Awesome @AarushSharmaa , thanks a lot for fixing this!

@VaibhavUpreti VaibhavUpreti merged commit 286740d into Tracer-Cloud:main Apr 27, 2026
7 checks passed
@VaibhavUpreti
Copy link
Copy Markdown
Member

Welcome to the OpenSRE community :)

@AarushSharmaa
Copy link
Copy Markdown
Contributor Author

Thanks for the quick merge! Been reading through the codebase to understand how everything fits together and really enjoying it. Looking forward to picking up more issues as I go deeper. And honestly, cheers to what you all are building here, this kind of infrastructure is going to matter a lot as agents start taking over more of the ecosystem.

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.

run_diagnostic_code is registered without is_available/extract_params, crashes on every dispatch

2 participants