Skip to content

Conversation

@crystalin
Copy link
Contributor

@crystalin crystalin commented Nov 25, 2025

Summary

  • Add check in MetricsService.storeRequest() to skip storage when messageCount === 0
  • Add check to skip storage when response has zero tokens AND empty content (catches empty streaming responses)
  • Add unit tests to verify both fixes

Context

Even after recent fixes for empty Bedrock responses and internal operations, two types of "empty" requests were still being stored:

  1. Requests with no messages - Requests where the messages array is empty
  2. Empty streaming responses - Streaming responses that complete with zero tokens and no content (common with failed connections or edge cases)

Both of these pollute the database with non-meaningful request data.

Changes

  1. Skip storage when messageCount === 0
  2. Skip storage when inputTokens === 0 AND outputTokens === 0 AND content.length === 0

Test plan

  • Unit test added for empty messages filtering
  • Unit test added for empty response filtering
  • All existing tests pass (135 tests)
  • TypeScript type checking passes

🤖 Generated with Claude Code

crystalin and others added 2 commits November 25, 2025 15:20
Requests with an empty messages array were still being stored in the
database despite recent fixes for other edge cases. This commit adds
a check in MetricsService.storeRequest() to skip storage when
messageCount === 0.

Changes:
- Add empty messages check after calculating messageCount
- Skip storage and log debug message when messages array is empty
- Add unit test to verify empty message requests are not stored

This complements existing filters for non-storable request types
(query_evaluation, quota, internal_operation) and empty Bedrock responses.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
The previous fix only handled requests with empty messages. This commit
adds a second check to filter out empty responses (zero tokens AND empty
content array), which commonly occurs with streaming responses that fail
or return no meaningful data.

Detection criteria for empty responses:
- inputTokens === 0 AND
- outputTokens === 0 AND
- content array is empty or missing

This catches:
- Empty streaming responses from any provider
- Failed streaming connections that produced no content
- Edge cases where response reconstruction yields empty data

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[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