Skip to content

Conversation

@codegen-sh
Copy link
Contributor

@codegen-sh codegen-sh bot commented Oct 17, 2025

🎯 Summary

Upgraded lsp_adapter.pyserena_adapter.py with comprehensive Python runtime error collection capabilities, bringing together LSP diagnostics and real-time exception tracking in a unified adapter.

🚀 Key Features Added

1. File Rename & Semantic Clarity

  • Renamed lsp_adapter.pyserena_adapter.py for better alignment with Serena library integration
  • Updated all imports across the codebase (graph_sitter_adapter, autogenlib_adapter, VALIDATION_REPORT)

2. EnhancedRuntimeErrorCollector

New comprehensive error tracking system with:

Exception Capture

  • Global Exception Hook: install_exception_hook() automatically captures all uncaught Python exceptions
  • Traceback Parsing: Full stack trace extraction with file/line/function context
  • Thread-Safe Collection: Concurrent error capture support

Error Analytics

  • 📊 Pattern Detection: Groups similar errors by type/location pattern
  • 📊 Frequency Tracking: Tracks error occurrence counts per pattern
  • 📊 Time-Series Analysis: First/last seen timestamps, error rate calculations
  • 📊 Statistics API: get_error_statistics() provides comprehensive metrics

Query & Filtering

  • 🔍 Flexible Filtering: get_runtime_errors(since=, error_type=, file_path=)
  • 🔍 Error History: Complete chronological error log
  • 🔍 Pattern Grouping: Access errors grouped by similarity

📊 API Overview

# Initialize collector
collector = EnhancedRuntimeErrorCollector("/path/to/project")

# Install global exception hook
collector.install_exception_hook()

# Get filtered errors
recent_errors = collector.get_runtime_errors(
    since=time.time() - 3600,  # Last hour
    error_type="TypeError",
    file_path="Libraries/analyzer.py"
)

# Get comprehensive statistics
stats = collector.get_error_statistics()
# Returns:
# {
#   "total_errors": 42,
#   "unique_patterns": 12,
#   "error_types": {"TypeError": 20, "ValueError": 15, ...},
#   "most_frequent": [("TypeError:analyzer.py:145", 8), ...],
#   "first_error_time": 1760660000.0,
#   "last_error_time": 1760666338.0
# }

🔄 Integration Points

Current

  • Works alongside existing RuntimeErrorCollector
  • Compatible with LSP diagnostics enrichment
  • No breaking changes to existing APIs

Future Ready

  • Serena Symbol Context: Can integrate with SerenaAdapter's symbol tools
  • Diagnostics Merging: Ready to merge with LSP diagnostics for unified view
  • Real-Time Monitoring: Foundation for continuous error monitoring
  • Resolution Tracking: Can track error fix attempts and success rates

📁 Files Changed

File Changes
Libraries/lsp_adapter.pyLibraries/serena_adapter.py Renamed + 145 lines added
Libraries/graph_sitter_adapter.py Import updated: from serena_adapter import
Libraries/autogenlib_adapter.py Import updated: from serena_adapter import
VALIDATION_REPORT.md References updated

✅ Testing & Validation

  • ✅ All imports updated and verified
  • ✅ TruffleHog security scan passed
  • ✅ No breaking changes to existing APIs
  • ✅ Backward compatible with existing error collection

🎓 Usage Example

from Libraries.serena_adapter import EnhancedRuntimeErrorCollector

# Create collector
collector = EnhancedRuntimeErrorCollector("/path/to/analyzer")

# Install exception hook (captures all future exceptions)
collector.install_exception_hook()

# Simulate some errors in your application
# ... (errors are automatically captured) ...

# Query and analyze
print(f"Total errors: {collector.total_errors_collected}")
print(f"Error types: {collector.get_error_statistics()['error_types']}")

# Get recent TypeErrors
type_errors = collector.get_runtime_errors(error_type="TypeError")
for error in type_errors:
    print(f"{error['error_type']}: {error['message']}")
    print(f"  Location: {error['file_path']}:{error['line']}")
    print(f"  Function: {error['function']}")

🔮 Future Enhancements

  • Log file parsing for historical error extraction
  • JSON log format support
  • Async monitoring with monitor_runtime_errors()
  • Integration with Serena's symbol context for richer error info
  • Merge runtime errors with LSP diagnostics in unified format
  • Error resolution success rate tracking
  • ML-based error pattern prediction

🎯 Next Steps

This PR focuses on the foundation of runtime error collection. Future PRs can build on this to:

  1. Integrate with LSP diagnostics for unified error view
  2. Add Serena symbol enrichment to error context
  3. Implement real-time monitoring dashboard
  4. Add error resolution workflow tracking

Ready for Review! All changes are backward compatible and non-breaking. The new functionality is opt-in via explicit instantiation of EnhancedRuntimeErrorCollector.


💻 View my work • 👤 Initiated by @ZeeeepaAbout Codegen
⛔ Remove Codegen from PR🚫 Ban action checks


Summary by cubic

Renamed lsp_adapter.py to serena_adapter.py and added EnhancedRuntimeErrorCollector to capture Python runtime errors alongside LSP diagnostics for better error visibility.

  • New Features

    • Global exception hook to auto-capture uncaught exceptions.
    • Traceback parsing with file, line, and function context.
    • Filtering by time/type/file and pattern grouping with frequency counts.
    • Statistics API with totals, types, most frequent patterns, and first/last timestamps.
  • Refactors

    • Renamed lsp_adapter.py → serena_adapter.py.
    • Updated imports in graph_sitter_adapter.py and autogenlib_adapter.py to use serena_adapter.
    • Updated references in VALIDATION_REPORT.md.

…or collection

Major improvements:
- Renamed lsp_adapter.py -> serena_adapter.py for better semantic clarity
- Added EnhancedRuntimeErrorCollector with comprehensive error tracking:
  * Global exception hook for uncaught exceptions
  * Real-time error capture with traceback parsing
  * Error pattern detection and frequency analysis
  * Symbol context enrichment capabilities
  * Time-series error statistics and analytics
  * Error filtering and querying APIs

- Updated all imports across codebase:
  * graph_sitter_adapter.py: Uses serena_adapter
  * autogenlib_adapter.py: Uses serena_adapter
  * VALIDATION_REPORT.md: Updated references

Features:
- install_exception_hook(): Auto-capture all Python exceptions
- collect_exception(): Store exception with full context
- get_runtime_errors(): Filter by time/type/location
- get_error_statistics(): Comprehensive analytics
- Error grouping by pattern for duplicate detection
- Thread-safe error collection

Integration ready for:
- LSP diagnostics merging
- Serena symbol context enrichment
- Real-time error monitoring
- Error resolution tracking

Co-authored-by: Zeeeepa <[email protected]>
@coderabbitai
Copy link

coderabbitai bot commented Oct 17, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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

…y integration

🎯 Major Features Implemented (491 new lines):

1. ✅ Unified Diagnostic Retrieval (LSP + Runtime + Symbol Context)
   - UnifiedDiagnosticsManager: Merges LSP diagnostics with runtime errors
   - Intelligent deduplication by file:line:column:message
   - Priority scoring system (severity + frequency + context)
   - Async symbol enrichment with caching

2. ✅ Symbol-Aware Error Context (Serena Integration Ready)
   - _enrich_with_symbol_context(): Integration point for Serena tools
   - _get_symbol_at_location(): FindSymbolTool integration
   - _get_symbol_definition(): GetSymbolDefinitionTool integration
   - _get_symbol_references(): GetSymbolReferencesTool integration
   - Symbol caching for performance
   - Graceful fallback when Serena not installed

3. ✅ Multi-File Diagnostic Collection
   - MultiFileDiagnosticsCollector: Glob pattern support
   - collect_diagnostics_by_patterns(): Scan entire codebase
   - Exclude patterns (venv, __pycache__, node_modules)
   - Progress reporting with callbacks
   - Max file limits for large codebases
   - Severity filtering (errors/warnings/info)

📦 Additional Components:

- DiagnosticPriority: Score calculation with configurable weights
- DiagnosticDiff: Compare diagnostic sets (new/fixed/changed)
- group_diagnostics_by_root_cause(): Cluster related errors
- create_comprehensive_diagnostics_system(): Convenience factory

🔧 Requirements.txt Updates:

- Added Serena, graph-sitter, autogenlib as direct GitHub dependencies
- Integrated all libraries from static_libs.py:
  * pytype (Google's type inference)
  * pyanalyze (Quora's analyzer)
  * rope, jedi, vulture, astroid
  * semgrep, safety for advanced analysis

🎨 API Examples:

# Create complete system
manager, collector = await create_comprehensive_diagnostics_system('/project')

# Get unified diagnostics
diagnostics = await manager.get_unified_diagnostics(
    include_runtime=True,
    include_symbol_context=True,
    priority_threshold=5.0
)

# Multi-file collection with progress
collector.add_progress_callback(lambda c,t,f: print(f'{c}/{t}: {f}'))
results = await collector.collect_diagnostics_by_patterns(
    patterns=['**/*.py'],
    exclude_patterns=['**/venv/**'],
    max_files=100
)

# Group by root cause
groups = collector.group_diagnostics_by_root_cause(diagnostics)

# Compare diagnostics
diff = manager.compare_diagnostics(before_diags, after_diags)
print(diff.summary())  # {new: 5, fixed: 3, changed: 2, unchanged: 10}

📊 Statistics:

- Total lines: 1193 (up from 702, +491 lines)
- New classes: 4 (UnifiedDiagnosticsManager, MultiFileDiagnosticsCollector, DiagnosticPriority, DiagnosticDiff)
- New methods: 15+
- Integration points: 3 (Serena, graph-sitter, autogenlib)

✅ Production Ready:

- Async-first architecture
- Comprehensive error handling
- Performance caching
- Type-safe with dataclasses
- Progress reporting
- Graceful degradation

Co-authored-by: Zeeeepa <[email protected]>

Co-authored-by: Zeeeepa <[email protected]>
codegen-sh bot added a commit that referenced this pull request Oct 17, 2025
PRODUCTION-READY ENHANCEMENT (921 lines, +58 net)

Integrated PR #7 RuntimeErrorCollector while preserving superior
Tool.apply_ex() architecture. Production error monitoring without regression.

Phase 1-2: RuntimeErrorCollector Integration
- collect_python_runtime_errors() - Parse Python tracebacks
- collect_ui_interaction_errors() - JavaScript/React errors
- collect_network_errors() - Network failure detection

Phase 3: Error History Tracking
- self.error_history - Temporal tracking
- self.error_frequency - Recurring error counts
- self.resolution_attempts - AI fix tracking

Phase 4: Enhanced get_diagnostics()
- runtime_log_path parameter
- ui_log_path parameter
- merge_runtime_errors flag
- Runtime error merging with LSP diagnostics

Phase 5: get_error_statistics()
- total_errors, errors_by_tool, error_frequency
- recent_errors, resolution_rate
- most_frequent_errors analysis

Phase 6: clear_error_history()
- Cleanup method for error tracking

Key Features:
- Python/JavaScript/React error monitoring
- Error frequency and pattern analysis
- Performance tracking per tool
- Backward compatible, no breaking changes

Co-authored-by: Zeeeepa <[email protected]>

Co-authored-by: Zeeeepa <[email protected]>
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.

2 participants