Skip to content

Admin - Add v2 session support to session traces viewer#535

Merged
eshurakov merged 1 commit intomainfrom
eshurakov/admin-session-traces-viewer-v2
Feb 25, 2026
Merged

Admin - Add v2 session support to session traces viewer#535
eshurakov merged 1 commit intomainfrom
eshurakov/admin-session-traces-viewer-v2

Conversation

@eshurakov
Copy link
Contributor

Summary

  • Add support for ses_-prefixed v2 sessions alongside existing UUID v1 sessions in the admin session traces viewer
  • V2 messages are fetched via fetchSessionSnapshot and rendered with the cloud-agent-next MessageBubble component
  • Returns a format: 'v1' | 'v2' discriminator from getMessages so the frontend knows which renderer to use

Backend (admin-router.ts)

  • Relax session ID validation to accept both UUID and ses_ formats via a refined Zod schema
  • Dispatch to cli_sessions_v2 table when isNewSession() returns true
  • Fetch v2 messages via fetchSessionSnapshot using the session owner's kilo_user_id
  • Return { history: null } for v2 getApiConversationHistory (no equivalent in v2)
  • Null out missing fields (last_mode, last_model for v2; git_branch for v1) for a consistent UI shape

Frontend (SessionTraceViewer.tsx)

  • Accept ses_ IDs in URL params and search input validation
  • Render v2 messages with V2MessageBubble, v1 messages with V1MessageBubble
  • Display git_branch when available (v2 sessions)
  • Update placeholder text and error messages to reflect dual-format support

Support ses_-prefixed v2 sessions alongside existing UUID v1 sessions in
the admin trace viewer. V2 messages are fetched via fetchSessionSnapshot
and rendered with the cloud-agent-next MessageBubble component.

Backend changes (admin-router.ts):
- Relax session ID validation to accept both UUID and ses_ formats
- Dispatch to cli_sessions_v2 table for v2 sessions
- Fetch v2 messages via fetchSessionSnapshot using session owner's token
- Return format discriminator ('v1' | 'v2') from getMessages
- Return { history: null } for v2 getApiConversationHistory (no equivalent)
- Null out missing fields for consistent shape across v1/v2

Frontend changes (SessionTraceViewer.tsx):
- Accept ses_ IDs in URL param and search input validation
- Render v2 messages with V2MessageBubble, v1 with V1MessageBubble
- Display git_branch when available (v2 sessions)
- Update placeholder text and error messages for dual-format support
if (!messagesQuery.data?.messages || messagesQuery.data.format !== 'v2') return [];
// Server-side Zod validates minimal shape; full StoredMessage structure is
// guaranteed by the session-ingest worker that originally created the data.
return messagesQuery.data.messages as unknown as StoredMessage[];
Copy link
Contributor

Choose a reason for hiding this comment

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

[WARNING]: as unknown as StoredMessage[] bypasses type safety.

The project coding style strongly discourages as casts since they can't be statically checked. The server-side Zod schema (SessionSnapshotSchema) validates a minimal shape ({ info: { id }, parts: [{ id }] }), but StoredMessage expects info: OpenCodeMessage and parts: Part[] which are much richer types — a mismatch at runtime would silently produce incorrect data rather than a type error.

Consider defining a Zod schema on the client side that validates the full StoredMessage shape (or at least the fields MessageBubble actually accesses), and use .parse() / .safeParse() so mismatches surface as runtime errors rather than silent corruption.

@kilo-code-bot
Copy link
Contributor

kilo-code-bot bot commented Feb 24, 2026

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
src/app/admin/components/SessionTraceViewer.tsx 142 as unknown as StoredMessage[] bypasses type safety — server-side Zod validates a minimal shape but the cast assumes the full StoredMessage type without runtime verification
Other Observations (not in diff)

No issues found outside the diff.

Files Reviewed (2 files)
  • src/app/admin/components/SessionTraceViewer.tsx - 1 issue
  • src/routers/admin-router.ts - 0 issues

Fix these issues in Kilo Cloud

@eshurakov eshurakov requested a review from a team February 24, 2026 20:35
@eshurakov eshurakov merged commit 2403ba5 into main Feb 25, 2026
12 checks passed
@eshurakov eshurakov deleted the eshurakov/admin-session-traces-viewer-v2 branch February 25, 2026 08:47
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