Skip to content

fix(frontend): Support V1 conversations in MetricsModal#12678

Merged
tofarr merged 6 commits intomainfrom
fix-display-cost-panel
Jan 29, 2026
Merged

fix(frontend): Support V1 conversations in MetricsModal#12678
tofarr merged 6 commits intomainfrom
fix-display-cost-panel

Conversation

@tofarr
Copy link
Copy Markdown
Collaborator

@tofarr tofarr commented Jan 29, 2026

Summary of PR

The MetricsModal was not working for V1 conversations because the contract has changed - we no longer get events that update stats on the fly. This PR fixes the issue by:

  • Adding proper TypeScript types for V1 metrics (V1TokenUsage, V1MetricsSnapshot)
  • Updating V1AppConversation.metrics from unknown to the properly typed V1MetricsSnapshot
  • Modifying MetricsModal to detect V1 conversations via useActiveConversation hook
  • For V1 conversations, fetching metrics using useBatchAppConversations instead of the metrics store
  • For non-V1 conversations, continuing to use the existing metrics store

Demo Screenshots/Videos

image

Change Type

  • Bug fix
  • New feature
  • Breaking change
  • Refactor
  • Other (dependency update, docs, typo fixes, etc.)

Checklist

  • I have read and reviewed the code and I understand what the code is doing.
  • I have tested the code to the best of my ability and ensured it works as expected.

Fixes

Resolves #(issue)

Release Notes

  • Include this change in the Release Notes.

@tofarr can click here to continue refining the PR


To run this PR locally, use the following command:

GUI with Docker:

docker run -it --rm   -p 3000:3000   -v /var/run/docker.sock:/var/run/docker.sock   --add-host host.docker.internal:host-gateway   -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.openhands.dev/openhands/runtime:978b277-nikolaik   --name openhands-app-978b277   docker.openhands.dev/openhands/openhands:978b277

tofarr and others added 2 commits January 29, 2026 12:47
The MetricsModal was not working for V1 conversations because the
contract has changed - we no longer get events that update stats on
the fly. This change:

- Adds proper TypeScript types for V1 metrics (V1TokenUsage,
  V1MetricsSnapshot)
- Updates V1AppConversation.metrics from 'unknown' to typed
  V1MetricsSnapshot
- Modifies MetricsModal to detect V1 conversations via
  useActiveConversation hook
- For V1 conversations, fetches metrics using useBatchAppConversations
  instead of the metrics store
- For non-V1 conversations, continues to use the existing metrics store

Co-authored-by: openhands <openhands@all-hands.dev>
@tofarr tofarr marked this pull request as ready for review January 29, 2026 20:34
Comment thread openhands/app_server/sandbox/remote_sandbox_service.py Outdated
usage: v1Metrics.accumulated_token_usage
? {
prompt_tokens:
v1Metrics.accumulated_token_usage.prompt_tokens ?? 0,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
v1Metrics.accumulated_token_usage.prompt_tokens ?? 0,
v1Metrics.accumulated_token_usage.prompt_tokens,

NIT: do we need the conditional checks for the token values?

Copy link
Copy Markdown
Collaborator

@malhotra5 malhotra5 left a comment

Choose a reason for hiding this comment

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

LGTM!

@hieptl
Copy link
Copy Markdown
Collaborator

hieptl commented Jan 29, 2026

Hello @tofarr, I noticed an issue while running the code locally.

The cost appears as $0.00 on my end. Please see the image below for additional details. Thank you! 🙏

image

@github-actions
Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  openhands/app_server/sandbox
  remote_sandbox_service.py 712-728
Project Total  

This report was generated by python-coverage-comment-action

Copy link
Copy Markdown
Collaborator

@hieptl hieptl left a comment

Choose a reason for hiding this comment

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

Thank you! 🙏

…versations

- Replace useBatchAppConversations with direct runtime conversation endpoint
- Add getRuntimeConversation method to V1ConversationService
- Implement getCombinedMetrics utility (TypeScript equivalent of Python SDK)
- Create useSandboxMetrics hook for real-time metrics from sandbox
- Add new types for runtime conversation info and metrics
- Maintain backward compatibility with existing metrics modal UI
- Enable real-time metrics updates every 30 seconds for V1 conversations

Co-authored-by: openhands <openhands@all-hands.dev>
- Update useSandboxMetrics to only fetch when modal is actually open
- Prevents unnecessary API calls every 30 seconds when modal is closed
- Improves performance by reducing background network requests
- Maintains real-time updates when modal is open

Co-authored-by: openhands <openhands@all-hands.dev>
@tofarr tofarr merged commit 3d4cb89 into main Jan 29, 2026
17 checks passed
@tofarr tofarr deleted the fix-display-cost-panel branch January 29, 2026 22:03
tofarr added a commit that referenced this pull request Jan 29, 2026
Co-authored-by: openhands <openhands@all-hands.dev>
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.

4 participants