Skip to content

Use shared inference-result constants instead of raw strings in responses.py #1700

@coderabbitai

Description

@coderabbitai

Summary

In src/app/endpoints/responses.py, the raw string literals "success" and "failure" are passed to _record_response_inference_result in multiple places. Since src/metrics/recording.py already exports LLM_INFERENCE_RESULT_SUCCESS and LLM_INFERENCE_RESULT_FAILURE constants for exactly this purpose, the raw literals should be replaced with these constants to reduce typo risk and prevent silent metric skew.

Affected locations

  • Around line 1045–1052 (streaming path — terminal event handling in response_generator)
  • Around lines 1188–1193 (non-streaming path — success recording in handle_non_streaming_response)
  • Around lines 1222–1225 (non-streaming path — failure recording in handle_non_streaming_response)

Suggested fix

-                result = "failure" if chunk.type == "response.failed" else "success"
+                result = (
+                    recording.LLM_INFERENCE_RESULT_FAILURE
+                    if chunk.type == "response.failed"
+                    else recording.LLM_INFERENCE_RESULT_SUCCESS
+                )

Apply the same substitution to the other two occurrences where "success" and "failure" are passed directly.

References

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions