Skip to content

[AgentOps][Code Quality] Better organization for enum [1/n]#442

Merged
XinweiHe merged 6 commits intopivot/agentopsfrom
xinwei_enum_cleanup_v1
Feb 9, 2026
Merged

[AgentOps][Code Quality] Better organization for enum [1/n]#442
XinweiHe merged 6 commits intopivot/agentopsfrom
xinwei_enum_cleanup_v1

Conversation

@XinweiHe
Copy link
Collaborator

@XinweiHe XinweiHe commented Feb 9, 2026

Summary

as titled.

Type of Change

  • feat - A new feature
  • fix - A bug fix
  • docs - Documentation only changes
  • style - Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  • refactor - A code change that neither fixes a bug nor adds a feature
  • perf - A code change that improves performance
  • test - Adding missing tests or correcting existing tests
  • build - Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
  • ci - Changes to our Cl configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
  • chore - Other changes that don't modify sc or test files
  • revert - Reverts a previous commit
  • security - A security fix or improvement
  • github - Changes to our GitHub configuration files and scripts
  • other (please describe):

Details

Screenshots / Recordings (if applicable)

Checklist

  • I have read the CONTRIBUTING.md
  • I have added/updated tests where applicable
  • I have added screenshots or recordings for UI changes (if applicable)
  • I have updated documentation where necessary

@XinweiHe XinweiHe requested a review from a team as a code owner February 9, 2026 05:32
@greptile-apps
Copy link

greptile-apps bot commented Feb 9, 2026

Greptile Overview

Greptile Summary

This PR centralizes enum definitions across the backend, frontend, and Python SDK to improve code organization and type safety. The refactoring replaces hardcoded string literals with proper enum constants for SpanKind, SpanStatus, TraceStatus, and MemberRole.

Key Changes:

  • Backend: Created backend/shared/enums.py with Python StrEnum classes, updated transformer.py and deps.py to use enum constants
  • Frontend Core: Added constants.ts with TypeScript const objects and Prisma enum re-exports, created schemas.ts with Zod validators
  • Python SDK: Renamed StepType to SpanKind with improved documentation
  • Prisma: Added MemberRole enum to database schema
  • UI: Updated 20+ files to import and use centralized enum constants instead of string literals

Critical Issue:
The Zod schema definitions in frontend/packages/core/src/schemas.ts use incorrect syntax - z.enum() expects tuple arrays but receives TypeScript enums and const objects, which will cause runtime validation errors.

Confidence Score: 1/5

  • This PR cannot be safely merged due to a critical syntax error in the Zod schema definitions that will cause runtime validation failures
  • The refactoring approach is sound and most changes are correct, but the incorrect z.enum() usage in schemas.ts is a blocking issue. This file defines validation schemas used throughout the application for API requests. The syntax error will cause immediate failures when these schemas are used for validation, breaking workspace member management, trace status filtering, and span validation across the application.
  • Pay close attention to frontend/packages/core/src/schemas.ts - requires immediate fix before merge

Important Files Changed

Filename Overview
backend/shared/enums.py Created centralized enum definitions for SpanKind, SpanStatus, TraceStatus, and MemberRole using Python StrEnum
frontend/packages/core/src/constants.ts Created centralized TypeScript constants for SpanKind, SpanStatus, TraceStatus, and re-exported Prisma Role enum
frontend/packages/core/src/schemas.ts CRITICAL: Incorrect z.enum() usage with TypeScript enums and const objects - will cause runtime errors
frontend/packages/core/prisma/schema.prisma Added MemberRole enum to schema and updated Invite and WorkspaceMember models to use typed enum
traceroot-py/traceroot/constants.py Renamed StepType to SpanKind with improved documentation explaining lowercase-to-uppercase transformation

Sequence Diagram

sequenceDiagram
    participant SDK as Python SDK<br/>(traceroot-py)
    participant Backend as Backend Worker<br/>(transformer.py)
    participant Enums as Backend Enums<br/>(shared/enums.py)
    participant DB as PostgreSQL<br/>(Prisma)
    participant CorePkg as Core Package<br/>(constants.ts)
    participant UI as Frontend UI<br/>(React Components)

    Note over SDK: Decorator uses lowercase<br/>SpanKind ("llm", "agent", etc)
    SDK->>Backend: Send OTEL span with<br/>traceroot.span.type attribute
    
    Backend->>Enums: Import SpanKind, SpanStatus enums
    Backend->>Backend: Transform lowercase to uppercase<br/>using enum constants
    Backend->>Backend: Set status using SpanStatus.OK/ERROR
    
    Note over DB: MemberRole enum defined<br/>in Prisma schema
    DB->>CorePkg: Generate MemberRole enum<br/>via Prisma Client
    
    CorePkg->>CorePkg: Re-export as Role<br/>Define SpanKind, SpanStatus,<br/>TraceStatus constants
    
    CorePkg->>UI: Import Role, SpanKind,<br/>SpanStatus, TraceStatus
    UI->>UI: Use enum constants for<br/>comparisons and displays
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

5 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@XinweiHe XinweiHe merged commit 7961b04 into pivot/agentops Feb 9, 2026
4 checks passed
@XinweiHe XinweiHe deleted the xinwei_enum_cleanup_v1 branch February 9, 2026 06:00
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.

1 participant