Admin - Add v2 session support to session traces viewer#535
Conversation
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[]; |
There was a problem hiding this comment.
[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.
Code Review SummaryStatus: 1 Issue Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Other Observations (not in diff)No issues found outside the diff. Files Reviewed (2 files)
|
Summary
ses_-prefixed v2 sessions alongside existing UUID v1 sessions in the admin session traces viewerfetchSessionSnapshotand rendered with thecloud-agent-nextMessageBubblecomponentformat: 'v1' | 'v2'discriminator fromgetMessagesso the frontend knows which renderer to useBackend (
admin-router.ts)ses_formats via a refined Zod schemacli_sessions_v2table whenisNewSession()returns truefetchSessionSnapshotusing the session owner'skilo_user_id{ history: null }for v2getApiConversationHistory(no equivalent in v2)last_mode,last_modelfor v2;git_branchfor v1) for a consistent UI shapeFrontend (
SessionTraceViewer.tsx)ses_IDs in URL params and search input validationV2MessageBubble, v1 messages withV1MessageBubblegit_branchwhen available (v2 sessions)