Skip to content

feat(logs): map OTHER to UNKNOWN - #1343

Merged
steebchen merged 1 commit into
mainfrom
terragon/safte-filter-unified-reason-qns2xy
Dec 19, 2025
Merged

steebchen merged 1 commit into
mainfrom
terragon/safte-filter-unified-reason-qns2xy

Conversation

@steebchen

@steebchen steebchen commented Dec 19, 2025 •

Copy link
Copy Markdown
Member

Summary

  • Adds mapping for finishReason "OTHER" to UnifiedFinishReason.UNKNOWN in the unified finish reason logic.
  • Ensures non-standard finish reasons are categorized as unknown for safer filtering.

Changes

Core Logic

  • Update getUnifiedFinishReason in apps/gateway/src/lib/logs.ts to return UnifiedFinishReason.UNKNOWN when finishReason is "OTHER" (in addition to existing handling for content filter scenarios).
  • This hook now covers more edge cases and aligns with the new test coverage.

Tests

  • Extend logs.spec.ts to cover the new edge case:
    • When finishReason is "OTHER" for provider "google-ai-studio", the function should return UnifiedFinishReason.UNKNOWN.

Rationale

  • Provides consistent and safe mapping for non-standard finish reasons, improving downstream log categorization and analytics.

Test plan

  • Run unit tests:
    • Verify getUnifiedFinishReason("OTHER", "google-ai-studio") yields UnifiedFinishReason.UNKNOWN.
    • Ensure existing tests for other finish reasons remain unaffected.

Notes

  • No breaking changes introduced; this is an additive enhancement to finish reason handling.

🌿 Generated by Terry


ℹ️ Tag @terragon-labs to ask questions and address PR feedback

📎 Task: https://www.terragonlabs.com/task/55e97d7e-4f72-4978-be42-96f307c503fa

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of unexpected response types from Google AI Studio and Google Vertex providers by mapping them to a standard fallback state, ensuring more robust error handling.
  • Tests

    • Added test coverage for edge-case response type handling from Google AI Studio provider.

✏️ Tip: You can customize this high-level summary in your review settings.

…NKNOWN

Add handling for the finishReason value 'OTHER' in the getUnifiedFinishReason function to return UnifiedFinishReason.UNKNOWN. Also add corresponding test coverage to ensure proper behavior.

Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com>
Copilot AI review requested due to automatic review settings December 19, 2025 12:03
@coderabbitai

coderabbitai Bot commented Dec 19, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

This PR extends the finish reason mapping for Google-related providers (google-ai-studio and google-vertex) by adding a case that maps the "OTHER" finish reason to UnifiedFinishReason.UNKNOWN. A corresponding test is added to verify this mapping behavior.

Changes

Cohort / File(s) Summary
Google finish reason mapping
apps/gateway/src/lib/logs.ts
Adds handling for "OTHER" finish reason under Google-related providers, mapping it to UnifiedFinishReason.UNKNOWN
Test coverage for finish reason mapping
apps/gateway/src/lib/logs.spec.ts
Adds test expectation verifying that Google AI Studio's "OTHER" finish reason maps to UnifiedFinishReason.UNKNOWN

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Minor logic tweak with straightforward mapping addition
  • Consistent pattern applied to existing finish reason handlers
  • Test mirrors the implementation change without complex assertions

Possibly related PRs

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and concisely captures the main change: mapping the OTHER finish reason to UNKNOWN in the unified finish reason logic.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch terragon/safte-filter-unified-reason-qns2xy

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions github-actions Bot changed the title Map OTHER finishReason to UNKNOWN in unified finish reason feat(logs): map OTHER to UNKNOWN Dec 19, 2025

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds mapping for Google AI Studio's "OTHER" finish reason to UnifiedFinishReason.UNKNOWN, ensuring non-standard finish reasons are properly categorized for safer downstream handling.

Key Changes:

  • Add explicit handling for "OTHER" finish reason in Google AI Studio/Vertex cases
  • Extend test coverage to verify the new mapping behavior

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
apps/gateway/src/lib/logs.ts Adds "OTHER" finish reason mapping to UNKNOWN for google-ai-studio and google-vertex providers
apps/gateway/src/lib/logs.spec.ts Adds test case to verify "OTHER" finish reason is correctly mapped to UNKNOWN

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
apps/gateway/src/lib/logs.ts (1)

70-72: Explicit mapping for "OTHER" improves clarity but triggers error logging.

The mapping of "OTHER" to UNKNOWN is correct for Google finish reasons. Since "OTHER" is a documented, legitimate Google finish reason (not an error condition), mapping it to UNKNOWN will cause error logging at lines 139-149 whenever it occurs. Consider whether this is intended—if "OTHER" should not produce error logs, add it to the known reasons that bypass logging.

📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9083a95 and 4ccf9f3.

📒 Files selected for processing (2)
  • apps/gateway/src/lib/logs.spec.ts (1 hunks)
  • apps/gateway/src/lib/logs.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Never use any or as any unless absolutely necessary in TypeScript code
For database reads: Use db().query.<table>.findMany() or db().query.<table>.findFirst()

Files:

  • apps/gateway/src/lib/logs.ts
  • apps/gateway/src/lib/logs.spec.ts
**/*.{ts,tsx,js,jsx,json,md}

📄 CodeRabbit inference engine (CLAUDE.md)

Always use tabs for indentation

Files:

  • apps/gateway/src/lib/logs.ts
  • apps/gateway/src/lib/logs.spec.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx,js,jsx}: Always use top-level import, never use require or dynamic imports
No unnecessary code comments

Files:

  • apps/gateway/src/lib/logs.ts
  • apps/gateway/src/lib/logs.spec.ts
apps/{gateway,api}/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Use Hono framework with Zod validation and OpenAPI documentation for backend APIs

Files:

  • apps/gateway/src/lib/logs.ts
  • apps/gateway/src/lib/logs.spec.ts
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Always use top-level import, never use require or dynamic imports

Files:

  • apps/gateway/src/lib/logs.ts
  • apps/gateway/src/lib/logs.spec.ts
{apps/api,apps/gateway,packages/db}/**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

{apps/api,apps/gateway,packages/db}/**/*.ts: Use Drizzle ORM with latest object syntax for database operations
For database reads: Use db().query.<table>.findMany() or db().query.<table>.findFirst()

Files:

  • apps/gateway/src/lib/logs.ts
  • apps/gateway/src/lib/logs.spec.ts
apps/{gateway,api}/src/**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

apps/{gateway,api}/src/**/*.ts: Use Hono for backend framework in Gateway and API services
Use Zod schemas for validation in Hono services

Files:

  • apps/gateway/src/lib/logs.ts
  • apps/gateway/src/lib/logs.spec.ts
**/*.spec.ts

📄 CodeRabbit inference engine (CLAUDE.md)

Unit tests should use *.spec.ts file naming convention

Files:

  • apps/gateway/src/lib/logs.spec.ts
🧬 Code graph analysis (1)
apps/gateway/src/lib/logs.ts (1)
packages/db/src/schema.ts (2)
  • UnifiedFinishReason (20-30)
  • UnifiedFinishReason (32-33)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: Upload results
  • GitHub Check: e2e-shards (4)
  • GitHub Check: e2e-shards (5)
  • GitHub Check: e2e-shards (2)
  • GitHub Check: e2e-shards (1)
  • GitHub Check: e2e-shards (3)
  • GitHub Check: build / run
  • GitHub Check: test / run
  • GitHub Check: generate / run
  • GitHub Check: lint / run
  • GitHub Check: autofix
🔇 Additional comments (1)
apps/gateway/src/lib/logs.spec.ts (1)

66-68: Test correctly validates the new mapping.

The test appropriately verifies that "OTHER" maps to UNKNOWN for Google AI Studio. Testing only google-ai-studio (not google-vertex) is sufficient since they share the same case block in the implementation.

@steebchen
steebchen added this pull request to the merge queue Dec 19, 2025
Merged via the queue into main with commit 169b40a Dec 19, 2025
20 checks passed
@steebchen
steebchen deleted the terragon/safte-filter-unified-reason-qns2xy branch December 19, 2025 15:22
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