Timeout then tool errors with Devstral-Medium #1883

Closed
opened 2026-02-16 17:33:04 -05:00 by yindo · 5 comments
Owner

Originally created by @agileandy on GitHub (Sep 29, 2025).

Originally assigned to: @rekram1-node on GitHub.

Keep getting an ongoing error using Devstral-Medium.

Here is the relevent snipper of the conversation.

Read src/phase3_vulnerability_assessment.py

"""
Phase 3: Vulnerability Assessment and PR Simulation
Analyzes scan results and generates simulated pull request remediation proposals
"""

import logging

Now I understand how the simulated PRs are generated. The issue is that the current implementation is using generic fixes that just add comments instead of actual code fixes. Let
me modify the generate_fix_for_vulnerability method to use the fix templates properly.

Let me check the current fix templates to understand what we have available:
Build devstral-medium-2507 (07:54 AM)

Read src/phase3_vulnerability_assessment.py (limit=100, offset=40)

        self.fix_templates = {
            "insecure_random_python": {
                "patterns": [r"random\.random\(\)", r"random\.randint\(", r"random\.choice\("],
                "fixes": {
                    r"random\.random\(\)": "secrets.token_hex(16)",
                    r"random\.randint\(([^)]+)\)": r"secrets.randbelow(\1)",

Now let me check the generate_fix_for_vulnerability method to understand how it's currently working:
Build devstral-medium-2507 (07:54 AM)

Read src/phase3_vulnerability_assessment.py (limit=240, offset=180)

            elif "command" in vulnerability_type:
                return "command_injection"
            else:
                return "generic_vulnerability"

    def generate_fix_for_vulnerability(self, scan_result: Dict, vuln_type: str) -> Optional[Tuple[str, List[str], str, str]]:

I can see the issue now. The problem is in the generate_fix_for_vulnerability method. It's trying to use the fix templates, but it's only applying the first matching pattern and
then breaking the loop. Also, the generic fixes are just adding comments instead of actual fixes.

Let me modify the code to properly apply all the fix patterns and ensure we're using the actual code fixes from the templates.
Build devstral-medium-2507 (07:55 AM)

Edit src/phase3_vulnerability_assessment.py

 209   fix_template = self.fix_templates[template_key]                                      209   fix_template = self.fix_templates[template_key]
 210                                                                                        210
 211   # Apply fix patterns                                                                 211   # Apply fix patterns
 212   fixed_code = code_snippet                                                            212   fixed_code = code_snippet
                                                                                            213 + pattern_matched = False
 213   for pattern, replacement in fix_template["fixes"].items():                           214   for pattern, replacement in fix_template["fixes"].items():
 214       if re.search(pattern, code_snippet):                                             215       if re.search(pattern, code_snippet):
 215           fixed_code = re.sub(pattern, replacement, code_snippet)                      216           fixed_code = re.sub(pattern, replacement, code_snippet)
 216 -         break                                                                        217 +         pattern_matched = True
                                                                                            218 +         break  # Apply only the first matching pattern
 217                                                                                        219
 218 - if fixed_code == code_snippet:                                                       220 + if not pattern_matched:
 219       # No pattern matched, try generic replacement                                    221       # No pattern matched, try generic replacement
 220       return self.generate_generic_fix(code_snippet, vuln_type)                        222       return self.generate_generic_fix(code_snippet, vuln_type)
 221                                                                                        223

edit
Build devstral-medium-2507 (07:59 AM)

TimeoutError: The operation timed out.

the change got a timeout - try again

AI_APICallError: Unexpected role 'user' after role 'tool'

This is occurring every time Opencode tries to make a code edit using Devstral.

Originally created by @agileandy on GitHub (Sep 29, 2025). Originally assigned to: @rekram1-node on GitHub. Keep getting an ongoing error using Devstral-Medium. Here is the relevent snipper of the conversation. ``` Read src/phase3_vulnerability_assessment.py """ Phase 3: Vulnerability Assessment and PR Simulation Analyzes scan results and generates simulated pull request remediation proposals """ import logging Now I understand how the simulated PRs are generated. The issue is that the current implementation is using generic fixes that just add comments instead of actual code fixes. Let me modify the generate_fix_for_vulnerability method to use the fix templates properly. Let me check the current fix templates to understand what we have available: Build devstral-medium-2507 (07:54 AM) Read src/phase3_vulnerability_assessment.py (limit=100, offset=40) self.fix_templates = { "insecure_random_python": { "patterns": [r"random\.random\(\)", r"random\.randint\(", r"random\.choice\("], "fixes": { r"random\.random\(\)": "secrets.token_hex(16)", r"random\.randint\(([^)]+)\)": r"secrets.randbelow(\1)", Now let me check the generate_fix_for_vulnerability method to understand how it's currently working: Build devstral-medium-2507 (07:54 AM) Read src/phase3_vulnerability_assessment.py (limit=240, offset=180) elif "command" in vulnerability_type: return "command_injection" else: return "generic_vulnerability" def generate_fix_for_vulnerability(self, scan_result: Dict, vuln_type: str) -> Optional[Tuple[str, List[str], str, str]]: I can see the issue now. The problem is in the generate_fix_for_vulnerability method. It's trying to use the fix templates, but it's only applying the first matching pattern and then breaking the loop. Also, the generic fixes are just adding comments instead of actual fixes. Let me modify the code to properly apply all the fix patterns and ensure we're using the actual code fixes from the templates. Build devstral-medium-2507 (07:55 AM) Edit src/phase3_vulnerability_assessment.py 209 fix_template = self.fix_templates[template_key] 209 fix_template = self.fix_templates[template_key] 210 210 211 # Apply fix patterns 211 # Apply fix patterns 212 fixed_code = code_snippet 212 fixed_code = code_snippet 213 + pattern_matched = False 213 for pattern, replacement in fix_template["fixes"].items(): 214 for pattern, replacement in fix_template["fixes"].items(): 214 if re.search(pattern, code_snippet): 215 if re.search(pattern, code_snippet): 215 fixed_code = re.sub(pattern, replacement, code_snippet) 216 fixed_code = re.sub(pattern, replacement, code_snippet) 216 - break 217 + pattern_matched = True 218 + break # Apply only the first matching pattern 217 219 218 - if fixed_code == code_snippet: 220 + if not pattern_matched: 219 # No pattern matched, try generic replacement 221 # No pattern matched, try generic replacement 220 return self.generate_generic_fix(code_snippet, vuln_type) 222 return self.generate_generic_fix(code_snippet, vuln_type) 221 223 edit Build devstral-medium-2507 (07:59 AM) TimeoutError: The operation timed out. the change got a timeout - try again AI_APICallError: Unexpected role 'user' after role 'tool' ``` This is occurring every time Opencode tries to make a code edit using Devstral.
yindo closed this issue 2026-02-16 17:33:04 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Sep 29, 2025):

This issue might be a duplicate of existing issues. Please check:

  • #526: Persistent tool call errors with Deepseek v3 and Devstral - reports similar tool errors specifically with Devstral model
  • #2720: AI_APICallError about tool_use blocks found without corresponding tool_result blocks - describes the exact same "AI_APICallError" and tool role sequence issues you're experiencing

The "AI_APICallError: Unexpected role 'user' after role 'tool'" error you're seeing appears to be related to the same underlying tool calling and message formatting issues reported in these other tickets.

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Sep 29, 2025): This issue might be a duplicate of existing issues. Please check: - #526: Persistent tool call errors with Deepseek v3 and Devstral - reports similar tool errors specifically with Devstral model - #2720: AI_APICallError about tool_use blocks found without corresponding tool_result blocks - describes the exact same "AI_APICallError" and tool role sequence issues you're experiencing The "AI_APICallError: Unexpected role 'user' after role 'tool'" error you're seeing appears to be related to the same underlying tool calling and message formatting issues reported in these other tickets. Feel free to ignore if none of these address your specific case.
Author
Owner

@rekram1-node commented on GitHub (Sep 29, 2025):

@agileandy if it is timing out frequently are you running it locally? Have you tried increasing timeout? If u share your opencode.json I can show u how

@rekram1-node commented on GitHub (Sep 29, 2025): @agileandy if it is timing out frequently are you running it locally? Have you tried increasing timeout? If u share your opencode.json I can show u how
Author
Owner

@agileandy commented on GitHub (Oct 1, 2025):

I'm running this through the Mistral API. I'll try and find the timeout settings and play around.

@agileandy commented on GitHub (Oct 1, 2025): I'm running this through the Mistral API. I'll try and find the timeout settings and play around.
Author
Owner

@rekram1-node commented on GitHub (Oct 2, 2025):

@agileandy this is how you can override timeout (it is in ms):

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "mistral": {
      "options": {
        "timeout": 600000 // 10 minutes
      }
    }
  }
}
@rekram1-node commented on GitHub (Oct 2, 2025): @agileandy this is how you can override timeout (it is in ms): ``` { "$schema": "https://opencode.ai/config.json", "provider": { "mistral": { "options": { "timeout": 600000 // 10 minutes } } } } ```
Author
Owner

@ErwanLegrand commented on GitHub (Nov 1, 2025):

This should be fixed by #2440 .

@ErwanLegrand commented on GitHub (Nov 1, 2025): This should be fixed by #2440 .
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#1883