[Bug] Sonnet 4 model degradation: Generating Python Scripts with Syntax Errors

Resolved 💬 8 comments Opened Sep 12, 2025 by viper7882 Closed Jan 9, 2026

Bug description

Sonnet 4 produces scripts that contain syntax errors; the auto-generated syntax error fixer itself crashes with SyntaxError. Below is the proof.

Environment Info

  • Platform: linux
  • Terminal: windows-terminal
  • Version: 1.0.112
  • Feedback ID: 1525942a-33cd-4a82-ad37-e3378f0b7b4e

Errors

Write(scripts/advanced_syntax_fixer.py)
  ⎿  Wrote 324 lines to scripts/advanced_syntax_fixer.py
     #!/usr/bin/env python3
     """
     Advanced Syntax Error Fixer
     This script uses AST parsing and advanced regex patterns to fix complex syntax errors
     that autopep8 and ruff cannot handle.
     """
     import ast
     import os
     … +314 lines (ctrl+r to expand)

● Bash(python scripts/advanced_syntax_fixer.py)
  ⎿  Starting Advanced Syntax Error Fixer...

     === Iteration 1/5 ===
     … +343 lines (ctrl+r to expand)

● Great! The advanced syntax fixer applied thousands of fixes. Now let me run the iterative process and check the final results:
  ⎿  Read scripts/advanced_syntax_fixer.py (325 lines)
  ⎿  Read scripts/targeted_syntax_fixer.py (219 lines)
  ⎿  Read scripts/test_batch_screenshot.py (79 lines)
  ⎿  Referenced file scripts/blockchain_address_screenshot_tool.py
  ⎿  Referenced file scripts/regression_prevention_system.py
  ⎿  Todo list read (5 items)

● Looking at the files I've read, I can see several syntax errors that need fixing. Let me run the advanced syntax fixer to address these systematically:

● Bash(python scripts/advanced_syntax_fixer.py)
  ⎿  Error: File "/home/lkw/my_github/smartsec/scripts/advanced_syntax_fixer.py", line 81
         'logging.basicConfig(' in line):
                                       ^
     SyntaxError: unmatched ')'

● The syntax fixer itself has an error. Let me fix it first:

● Update(scripts/advanced_syntax_fixer.py)
  ⎿  Updated scripts/advanced_syntax_fixer.py with 1 removal
       77
       78                # Check for unclosed parentheses in function calls
       79                if ('subprocess.run(' in line or 'parser.add_argument(' in line or
       80 -              )
       80                    'logging.basicConfig(' in line):
       81
       82                    # Count parentheses in current line

● Update(scripts/advanced_syntax_fixer.py)
  ⎿  Updated scripts/advanced_syntax_fixer.py with 1 addition and 1 removal
       246                content = self.fix_corrupted_imports(content)
       247
       248                # Only write if we made changes
       249 -              if content ! == original_content:
       249 +              if content != original_content:
       250                    with open(filepath, 'w', encoding='utf-8') as f:
       251                        f.write(content)
       252

● Now let me fix the targeted syntax fixer as well:

● Update(scripts/targeted_syntax_fixer.py)
  ⎿  Error editing file

● Let me check the exact content:

● Read(scripts/targeted_syntax_fixer.py)
  ⎿  Read 5 lines (ctrl+r to expand)

● Update(scripts/targeted_syntax_fixer.py)
  ⎿  Updated scripts/targeted_syntax_fixer.py with 1 addition and 1 removal
       129
       130            # Detect if we're in a dictionary
       131            if '{' in line and not in_dict:
       132 -              "in_dict": True
       132 +              in_dict = True
       133            if '}' in line and in_dict:
       134                in_dict = False
       135

● Update(scripts/targeted_syntax_fixer.py)
  ⎿  Updated scripts/targeted_syntax_fixer.py with 1 addition and 1 removal
       169            content, fixes4 = fix_dictionary_syntax(content)
       170            total_fixes += fixes4
       171
       172 -          if content ! == original_content:
       172 +          if content != original_content:
       173                with open(file_path, 'w', encoding='utf-8') as f:
       174                    f.write(content)
       175                print(f"Fixed {total_fixes} issues in {file_path}")

● Update(scripts/targeted_syntax_fixer.py)
  ⎿  Updated scripts/targeted_syntax_fixer.py with 1 addition and 1 removal
       207        # Check remaining syntax errors
       208        try:
       209            result = subprocess.run(['python', 'scripts/check_syntax.py'],
       210 -                                capture_output = True, text = True)
       210 +                                capture_output=True, text=True)
       211            error_count = result.stderr.count('SYNTAX ERROR')
       212            print(f"Remaining syntax errors: {error_count}")
       213        except Exception as e:

Note: Error logs were truncated.

View original on GitHub ↗

This issue has 8 comments on GitHub. Read the full discussion on GitHub ↗