-
Notifications
You must be signed in to change notification settings - Fork 0
narrow WorkloadProfiler.profile classifier except to (AttributeError, TypeError, ValueError, KeyError) #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,7 +134,7 @@ def profile( | |
| value, confidence = classifier(request, headers) | ||
| values[axis_name] = value | ||
| axis_confidences[axis_name] = confidence | ||
| except Exception: | ||
| except (AttributeError, TypeError, ValueError, KeyError): | ||
| logger.exception("Axis classifier %s failed", axis_name) | ||
| values[axis_name] = "unknown" | ||
| axis_confidences[axis_name] = 0.0 | ||
|
Comment on lines
+137
to
140
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Description: Check error handling around profiler.profile() call in routing engine
# Search for the profile() call with surrounding context to see error handling
rg -nP -A 10 -B 5 'self\.profiler\.profile\(' --type=py -g 'engine.py'Repository: HrachShah/FreeRelay Length of output: 1278 🏁 Script executed: #!/bin/bash
# Check the full _prepare_request_context method to see broader error handling context
rg -n 'def _prepare_request_context' --type=py freerelay/core/routing/engine.py -A 25Repository: HrachShah/FreeRelay Length of output: 45 🏁 Script executed: #!/bin/bash
# Check for callers of _prepare_request_context to see if they handle exceptions
rg -n '_prepare_request_context' --type=py freerelay/core/routing/engine.py -B 2 -A 2 | head -30Repository: HrachShah/FreeRelay Length of output: 45 🏁 Script executed: #!/bin/bash
# Find axis classifier implementations to check what exceptions they can raise
fd -t f -e py freerelay/data_plane/profiler/ | xargs grep -l 'def classify_axis\|class.*Classifier' | head -5Repository: HrachShah/FreeRelay Length of output: 489 🏁 Script executed: #!/bin/bash
# Get the full _prepare_request_context method
rg -n 'def _prepare_request_context' --type=py -A 30 freerelay/core/routing/engine.pyRepository: HrachShah/FreeRelay Length of output: 45 🏁 Script executed: #!/bin/bash
# Find classifiers in the profiler directory
fd . freerelay/data_plane/profiler/ --type=f --extension=py | head -10Repository: HrachShah/FreeRelay Length of output: 589 🏁 Script executed: #!/bin/bash
# Check workload.py profile method to see the full try-except structure
rg -n 'def profile' freerelay/data_plane/profiler/workload.py -A 50 | head -80Repository: HrachShah/FreeRelay Length of output: 2484 🏁 Script executed: #!/bin/bash
# Look at one classifier implementation to see what exceptions it raises
cat -n freerelay/data_plane/profiler/axes/latency_class.pyRepository: HrachShah/FreeRelay Length of output: 2095 🏁 Script executed: #!/bin/bash
# Find what method contains the profile() call at line 210
rg -n 'def ' freerelay/core/routing/engine.py | grep -B1 -A1 '210'Repository: HrachShah/FreeRelay Length of output: 45 🏁 Script executed: #!/bin/bash
# Search for any method that calls _prepare_request_context or wraps it
rg -n '_prepare_request_context\|prepare_request_context' freerelay/core/routing/engine.py -B 3 -A 3Repository: HrachShah/FreeRelay Length of output: 45 🏁 Script executed: #!/bin/bash
# Get full engine.py to find the method containing line 210
wc -l freerelay/core/routing/engine.pyRepository: HrachShah/FreeRelay Length of output: 100 🏁 Script executed: #!/bin/bash
# Look at lines around 210 in engine.py
sed -n '200,230p' freerelay/core/routing/engine.pyRepository: HrachShah/FreeRelay Length of output: 1234 🏁 Script executed: #!/bin/bash
# Search for 'prepare_request_context' more broadly (without underscore)
rg 'prepare_request_context' freerelay/core/routing/engine.pyRepository: HrachShah/FreeRelay Length of output: 45 🏁 Script executed: #!/bin/bash
# Look for the method signature that contains line 210 by searching backwards
sed -n '180,220p' freerelay/core/routing/engine.pyRepository: HrachShah/FreeRelay Length of output: 1539 🏁 Script executed: #!/bin/bash
# Find all callers of _prepare_context
rg '_prepare_context' freerelay/core/routing/engine.py -B 2 -A 2Repository: HrachShah/FreeRelay Length of output: 601 🏁 Script executed: #!/bin/bash
# Check the full methods that call _prepare_context
rg -n 'def ' freerelay/core/routing/engine.py | head -20Repository: HrachShah/FreeRelay Length of output: 968 🏁 Script executed: #!/bin/bash
# Look at classifier implementations to see if they raise exceptions beyond the 4 caught types
# Check a few classifiers for exception patterns
rg 'raise\|assert\|\.get\(\)\[' freerelay/data_plane/profiler/axes/ --type=pyRepository: HrachShah/FreeRelay Length of output: 45 🏁 Script executed: #!/bin/bash
# Check the full route() method to see error handling context around _prepare_context call
sed -n '332,370p' freerelay/core/routing/engine.pyRepository: HrachShah/FreeRelay Length of output: 1512 🏁 Script executed: #!/bin/bash
# Check the full route_stream() method
sed -n '437,475p' freerelay/core/routing/engine.pyRepository: HrachShah/FreeRelay Length of output: 1665 🏁 Script executed: #!/bin/bash
# Look at all classifiers to see if any raise exceptions explicitly
fd . freerelay/data_plane/profiler/axes/ --type=f --extension=py -x grep -l 'raise ' {} \;Repository: HrachShah/FreeRelay Length of output: 45 🏁 Script executed: #!/bin/bash
# Check if route() methods are wrapped in any middleware or error handlers
# Look for FastAPI/async handlers or middleware patterns
rg -n 'async def' freerelay/core/routing/engine.py | grep -E 'route|execute'Repository: HrachShah/FreeRelay Length of output: 153 🏁 Script executed: #!/bin/bash
# Search for how route() is called from outside the engine class (likely in an API handler)
rg -n '\.route\(' freerelay/ --type=py | head -10Repository: HrachShah/FreeRelay Length of output: 1190 🏁 Script executed: #!/bin/bash
# Check if there's a higher-level error handler in the app or API layer
fd . freerelay -name 'main.py' -o -name 'app.py' -o -name 'api.py' | head -5Repository: HrachShah/FreeRelay Length of output: 294 🏁 Script executed: #!/bin/bash
# Look at main.py around line 242 to see error handling context
sed -n '235,260p' freerelay/main.pyRepository: HrachShah/FreeRelay Length of output: 875 🏁 Script executed: #!/bin/bash
# Check broader context in main.py for the endpoint handler
sed -n '220,280p' freerelay/main.pyRepository: HrachShah/FreeRelay Length of output: 2211 🏁 Script executed: #!/bin/bash
# Check one of the strategy implementations to see if they have error handling
sed -n '60,75p' freerelay/data_plane/execution/strategies/cheap_first_escalate.pyRepository: HrachShah/FreeRelay Length of output: 611 Add error handling around the With the narrowed exception handling at line 137, exceptions other than Either catch and log unexpected exceptions from classifiers (preserving fallback values), or add error handling at the call site in the routing engine to gracefully handle exceptions that escape 🤖 Prompt for AI Agents |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: HrachShah/FreeRelay
Length of output: 45
🏁 Script executed:
Repository: HrachShah/FreeRelay
Length of output: 2104
🏁 Script executed:
Repository: HrachShah/FreeRelay
Length of output: 207
🏁 Script executed:
Repository: HrachShah/FreeRelay
Length of output: 4159
🏁 Script executed:
Repository: HrachShah/FreeRelay
Length of output: 798
🏁 Script executed:
Repository: HrachShah/FreeRelay
Length of output: 799
🏁 Script executed:
Repository: HrachShah/FreeRelay
Length of output: 24575
Verify that classifier implementations don't raise other legitimate exception types.
The exception tuple
(AttributeError, TypeError, ValueError, KeyError)is too narrow. While the 10 axis classifiers don't explicitly raise exceptions, they perform operations that could legitimately raise unhandled exceptions for valid input failures:msg.content.typewhenmsg.contentis a string instead of a list, orrequest.response_format.typewhenresponse_formatis Nonemsg.tool_calls)When these exceptions occur, they will propagate instead of producing fallback "unknown"/0.0 values, potentially breaking the profiling pipeline.
🤖 Prompt for AI Agents