Skip to content

πŸ™Œ OpenHands: AI-Driven Development

feat: display message timestamps on hover (#17123)

LosAveRoad0c194180ac67
diff --git a/__tests__/components/chat-message.test.tsx b/__tests__/components/chat-message.test.tsx
index 5bdb6fc59e..3b48686a0b 100644
--- a/__tests__/components/chat-message.test.tsx
+++ b/__tests__/components/chat-message.test.tsx
@@ -5,6 +5,37 @@ import util from "util";
import { ChatMessage } from "#/components/features/chat/chat-message";
describe("ChatMessage", () => {
+ it.each(["user", "agent"] as const)(
+ "shows the recorded timestamp when a %s message is hovered",
+ async (type) => {
+ const user = userEvent.setup();
+ const timestamp = "2026-04-16T19:32:29.828Z";
+ const expected = new Date(timestamp).toLocaleString("en", {
+ dateStyle: "medium",
+ timeStyle: "short",
+ });
+
+ render(<ChatMessage type={type} message="Hello" timestamp={timestamp} />);
+
+ const message = screen.getByTestId(`${type}-message`);
+ await user.hover(message);
+
+ const tooltip = await screen.findByRole("tooltip");
+ expect(tooltip).toHaveTextContent(expected);
+ expect(tooltip.querySelector("time")).toHaveAttribute(
+ "datetime",
+ timestamp,
+ );
+ },
+ );
+
+ it("does not fabricate a timestamp for an invalid value", () => {
+ render(<ChatMessage type="user" message="Hello" timestamp="not-a-date" />);
+
+ expect(screen.getByTestId("user-message")).not.toHaveAttribute("tabindex");
+ expect(screen.queryByRole("tooltip")).not.toBeInTheDocument();
+ });
+
it("does not update the parent while measuring user-message truncation", async () => {
// Regression test for the React warning:
// "Cannot update a component (`ChatMessage`) while rendering a different
diff --git a/__tests__/components/conversation-events/chat/event-message-acp-tool-call.test.tsx b/__tests__/components/conversation-events/chat/event-message-acp-tool-call.test.tsx
index 0163892acd..094adb0d65 100644
--- a/__tests__/components/conversation-events/chat/event-message-acp-tool-call.test.tsx
+++ b/__tests__/components/conversation-events/chat/event-message-acp-tool-call.test.tsx
@@ -60,6 +60,49 @@ describe("EventMessage - ACPToolCallEvent dispatch", () => {
expect(screen.getByText("ACTION_MESSAGE$ACP_RUN")).toBeInTheDocument();
});
+ it("shows the command event's recorded timestamp on hover", async () => {
+ const user = userEvent.setup();
+ const event = makeEvent();
+
+ renderWithProviders(
+ <EventMessage
+ event={event}
+ messages={[]}
+ isLastMessage={false}
+ isInLast10Actions={false}
+ />,
+ );
+
+ const title = screen.getByTestId("generic-event-message-title");
+ await user.hover(title);
+
+ const tooltip = await screen.findByRole("tooltip");
+ expect(tooltip.querySelector("time")).toHaveAttribute(
+ "datetime",
+ event.timestamp,
+ );
+ });
+
+ it("shows the timestamp when the existing expand control receives focus", async () => {
+ const user = userEvent.setup();
+ const event = makeEvent();
+
+ renderWithProviders(
+ <EventMessage
+ event={event}
+ messages={[]}
+ isLastMessage={false}
+ isInLast10Actions={false}
+ />,
+ );
+
+ await user.tab();
+ expect(screen.getByRole("button", { name: "BUTTON$EXPAND" })).toHaveFocus();
+ expect(
+ (await screen.findByRole("tooltip")).querySelector("time"),
+ ).toHaveAttribute("datetime", event.timestamp);
+ });
+
it("does not show a success icon for completed tool calls", () => {
renderWithProviders(
<EventMessage
@@ -105,4 +148,26 @@ describe("EventMessage - ACPToolCallEvent dispatch", () => {
expect(screen.getByText(/gh pr diff 490/)).toBeInTheDocument();
expect(screen.getByText(/diff output here/)).toBeInTheDocument();
});
+
+ it("dismisses the timestamp when details are expanded with a pointer", async () => {
+ const user = userEvent.setup();
+ renderWithProviders(
+ <EventMessage
+ event={makeEvent()}
+ messages={[]}
+ isLastMessage={false}
+ isInLast10Actions={false}
+ />,
+ );
+
+ const title = screen.getByTestId("generic-event-message-title");
+ await user.hover(title);
+ expect(await screen.findByRole("tooltip")).toBeInTheDocument();
+
+ await user.click(screen.getByRole("button", { name: "BUTTON$EXPAND" }));
+ expect(screen.queryByRole("tooltip")).not.toBeInTheDocument();
+
+ await user.hover(screen.getByText(/diff output here/));
+ expect(screen.queryByRole("tooltip")).not.toBeInTheDocument();
+ });
});
diff --git a/__tests__/utils/format-event-timestamp.test.ts b/__tests__/utils/format-event-timestamp.test.ts
new file mode 100644
index 0000000000..8780d12c35
--- /dev/null
+++ b/__tests__/utils/format-event-timestamp.test.ts
@@ -0,0 +1,20 @@
+import { describe, expect, it } from "vitest";
+import { formatEventTimestamp } from "#/utils/format-event-timestamp";
+
+describe("formatEventTimestamp", () => {
+ it.each(["en", "zh-CN"])("uses the supplied %s locale", (locale) => {
+ const timestamp = "2026-04-16T19:32:29.828Z";
+
+ expect(formatEventTimestamp(timestamp, locale)).toBe(
+ new Date(timestamp).toLocaleString(locale, {
+ dateStyle: "medium",
+ timeStyle: "short",
+ }),
+ );
+ });
+ it("reads an offset-less agent-server timestamp as UTC", () => {
+ expect(formatEventTimestamp("2026-04-16T19:32:29.828069", "en")).toBe(
+ formatEventTimestamp("2026-04-16T19:32:29.828069Z", "en"),
+ );
+ });
+});
diff --git a/src/components/conversation-events/chat/event-message-components/finish-event-message.tsx b/src/components/conversation-events/chat/event-message-components/finish-event-message.tsx
index 6cfee059d0..244086262c 100644
--- a/src/components/conversation-events/chat/event-message-components/finish-event-message.tsx
+++ b/src/components/conversation-events/chat/event-message-components/finish-event-message.tsx
@@ -25,6 +25,7 @@ export function FinishEventMessage({
type="agent"
message={message}
isFromPlanningAgent={isFromPlanningAgent}
+ timestamp={event.timestamp}
/>
{event.critic_result != null && (
<CriticResultDisplay criticResult={event.critic_result} />
diff --git a/src/components/conversation-events/chat/event-message-components/generic-event-message-wrapper.tsx b/src/components/conversation-events/chat/event-message-components/generic-event-message-wrapper.tsx
index 6142b27b4c..ad684c1d6f 100644
--- a/src/components/conversation-events/chat/event-message-components/generic-event-message-wrapper.tsx
+++ b/src/components/conversation-events/chat/event-message-components/generic-event-message-wrapper.tsx
@@ -117,6 +117,7 @@ export function GenericEventMessageWrapper({
details={bodyDetails}
success={success}
initiallyExpanded={initiallyExpanded}
+ timestamp={event.timestamp}
titleIcon={
skillKnowledge ? (
<SkillsIcon className="h-4 w-4 stroke-[var(--oh-muted)] flex-shrink-0 mr-2" />
diff --git a/src/components/conversation-events/chat/event-message-components/thought-event-message.tsx b/src/components/conversation-events/chat/event-message-components/thought-event-message.tsx
index 25c6110a7a..19ce187ece 100644
--- a/src/components/conversation-events/chat/event-message-components/thought-event-message.tsx
+++ b/src/components/conversation-events/chat/event-message-components/thought-event-message.tsx
@@ -34,6 +34,7 @@ export function ThoughtEventMessage({
message={thoughtContent}
actions={actions}
isFromPlanningAgent={isFromPlanningAgent}
+ timestamp={event.timestamp}
/>
);
}
diff --git a/src/components/conversation-events/chat/event-message-components/user-assistant-event-message.tsx b/src/components/conversation-events/chat/event-message-components/user-assistant-event-message.tsx
index f165deee5f..9d73e9d244 100644
--- a/src/components/conversation-events/chat/event-message-components/user-assistant-event-message.tsx
+++ b/src/components/conversation-events/chat/event-message-components/user-assistant-event-message.tsx
@@ -120,6 +120,7 @@ export function UserAssistantEventMessage({
message={message}
isFromPlanningAgent={isFromPlanningAgent}
actions={actions}
+ timestamp={event.timestamp}
>
{imageUrls.length > 0 && (
<ImageCarousel size="small" images={imageUrls} />
diff --git a/src/components/conversation-events/chat/event-message.tsx b/src/components/conversation-events/chat/event-message.tsx
index 49ce591080..e35a4df71c 100644
--- a/src/components/conversation-events/chat/event-message.tsx
+++ b/src/components/conversation-events/chat/event-message.tsx
@@ -238,6 +238,7 @@ export function EventMessage({
type="agent"
message={message}
isFromPlanningAgent={isFromPlanningAgent}
+ timestamp={event.timestamp}
/>
)}
</>
diff --git a/src/components/features/chat/chat-message.tsx b/src/components/features/chat/chat-message.tsx
index 35119274a8..e6a1b4a707 100644
--- a/src/components/features/chat/chat-message.tsx
+++ b/src/components/features/chat/chat-message.tsx
@@ -6,6 +6,7 @@ import type { SourceType } from "#/types/agent-server/core/base/common";
import { StyledTooltip } from "#/components/shared/buttons/styled-tooltip";
import { I18nKey } from "#/i18n/declaration";
import { TextShimmer } from "#/components/shared/text-shimmer";
+import { formatEventTimestamp } from "#/utils/format-event-timestamp";
import { MarkdownRenderer } from "../markdown/markdown-renderer";
import { PendingStopIcon } from "./pending-stop-icon";
import {
@@ -29,6 +30,7 @@ interface ChatMessageProps {
onRetry?: () => void;
onDismiss?: () => void;
onStop?: () => void;
+ timestamp?: string;
}
export function ChatMessage({
@@ -41,8 +43,9 @@ export function ChatMessage({
onRetry,
onDismiss,
onStop,
+ timestamp,
}: React.PropsWithChildren<ChatMessageProps>) {
- const { t } = useTranslation("openhands");
+ const { t, i18n } = useTranslation("openhands");
const [isHovering, setIsHovering] = React.useState(false);
const [isCopy, setIsCopy] = React.useState(false);
const [isExpanded, setIsExpanded] = React.useState(false);
@@ -50,6 +53,7 @@ export function ChatMessage({
const [isSingleLinePendingMessage, setIsSingleLinePendingMessage] =
React.useState(true);
const pendingMessageContentRef = React.useRef<HTMLDivElement>(null);
+ const timestampLabel = formatEventTimestamp(timestamp, i18n?.language);
React.useEffect(() => {
setIsExpanded(false);
@@ -238,10 +242,22 @@ export function ChatMessage({
</article>
);
+ const messageBubbleWithTimestamp = timestampLabel ? (
+ <StyledTooltip
+ content={<time dateTime={timestamp}>{timestampLabel}</time>}
+ placement="top"
+ isOpen={isHovering}
+ >
+ {messageBubble}
+ </StyledTooltip>
+ ) : (
+ messageBubble
+ );
+
if (type === "user" && pendingStatus === "error") {
return (
<div className="flex w-fit max-w-full flex-col items-end gap-1.5 self-end last:mb-4">
- {messageBubble}
+ {messageBubbleWithTimestamp}
<div
role="alert"
data-testid="chat-message-error"
@@ -276,7 +292,7 @@ export function ChatMessage({
if (type === "user" && pendingStatus === "sending") {
return (
<div className="flex w-full max-w-full flex-col last:mb-4">
- {messageBubble}
+ {messageBubbleWithTimestamp}
<div className="my-1 w-full py-1 text-sm">
<TextShimmer
as="p"
@@ -294,5 +310,5 @@ export function ChatMessage({
);
}
- return messageBubble;
+ return messageBubbleWithTimestamp;
}
diff --git a/src/components/features/chat/generic-event-message.tsx b/src/components/features/chat/generic-event-message.tsx
index f3a9f98347..3c93f79904 100644
--- a/src/components/features/chat/generic-event-message.tsx
+++ b/src/components/features/chat/generic-event-message.tsx
@@ -7,6 +7,8 @@ import { ObservationResultStatus } from "#/components/conversation-events/chat/e
import { MarkdownRenderer } from "../markdown/markdown-renderer";
import { cn } from "#/utils/utils";
import { I18nKey } from "#/i18n/declaration";
+import { StyledTooltip } from "#/components/shared/buttons/styled-tooltip";
+import { formatEventTimestamp } from "#/utils/format-event-timestamp";
interface GenericEventMessageProps {
title: React.ReactNode;
@@ -19,6 +21,7 @@ interface GenericEventMessageProps {
titleTrailing?: React.ReactNode;
/** Optional icon rendered before the title text. */
titleIcon?: React.ReactNode;
+ timestamp?: string;
}
export function GenericEventMessage({
@@ -29,14 +32,24 @@ export function GenericEventMessage({
chevronPosition = "after",
titleTrailing,
titleIcon,
+ timestamp,
}: GenericEventMessageProps) {
- const { t } = useTranslation("openhands");
+ const { t, i18n } = useTranslation("openhands");
const [showDetails, setShowDetails] = React.useState(initiallyExpanded);
+ const [isHovered, setIsHovered] = React.useState(false);
+ const [hasFocusWithin, setHasFocusWithin] = React.useState(false);
+ const timestampLabel = formatEventTimestamp(timestamp, i18n?.language);
const chevron = details ? (
<button
type="button"
- onClick={() => setShowDetails((prev) => !prev)}
+ onClick={(event) => {
+ setShowDetails((prev) => !prev);
+ if (event.detail > 0) {
+ setIsHovered(false);
+ event.currentTarget.blur();
+ }
+ }}
className="cursor-pointer text-left"
aria-label={
showDetails ? t(I18nKey.BUTTON$COLLAPSE) : t(I18nKey.BUTTON$EXPAND)
@@ -60,26 +73,55 @@ export function GenericEventMessage({
</button>
) : null;
- return (
- <div className="flex flex-col gap-1.5 my-1 py-1 text-sm w-full">
- <div className="flex items-center justify-between font-normal text-[var(--oh-muted)]">
- <div className="flex items-center">
- {chevronPosition === "before" && chevron}
- {titleIcon}
- {/* Wrap the title in a span so any whitespace inside Trans-rendered
- fragments (e.g. "Editing <path>...</path>") is preserved by
- normal inline flow instead of being collapsed between
- anonymous flex items. */}
- <span>{title}</span>
- {chevronPosition === "after" && chevron}
- </div>
+ const titleContent = (
+ <div
+ data-testid="generic-event-message-title"
+ className="flex items-center"
+ onMouseEnter={() => setIsHovered(true)}
+ onMouseLeave={() => setIsHovered(false)}
+ onFocusCapture={() => setHasFocusWithin(true)}
+ onBlurCapture={(event) => {
+ if (!event.currentTarget.contains(event.relatedTarget)) {
+ setHasFocusWithin(false);
+ }
+ }}
+ >
+ {chevronPosition === "before" && chevron}
+ {titleIcon}
+ {/* Wrap the title in a span so any whitespace inside Trans-rendered
+ fragments (e.g. "Editing <path>...</path>") is preserved by
+ normal inline flow instead of being collapsed between
+ anonymous flex items. */}
+ <span>{title}</span>
+ {chevronPosition === "after" && chevron}
+ </div>
+ );
+
+ const titleContentWithTimestamp = timestampLabel ? (
+ <StyledTooltip
+ content={<time dateTime={timestamp}>{timestampLabel}</time>}
+ placement="top"
+ isOpen={isHovered || hasFocusWithin}
+ >
+ {titleContent}
+ </StyledTooltip>
+ ) : (
+ titleContent
+ );
- <div className="flex items-center">
- {titleTrailing}
- {success && <SuccessIndicator status={success} />}
- </div>
+ const titleRow = (
+ <div className="flex items-center justify-between font-normal text-[var(--oh-muted)]">
+ {titleContentWithTimestamp}
+ <div className="flex items-center">
+ {titleTrailing}
+ {success && <SuccessIndicator status={success} />}
</div>
+ </div>
+ );
+ return (
+ <div className="flex flex-col gap-1.5 my-1 py-1 text-sm w-full">
+ {titleRow}
{showDetails &&
(typeof details === "string" ? (
<MarkdownRenderer>{details}</MarkdownRenderer>
diff --git a/src/components/shared/buttons/styled-tooltip.tsx b/src/components/shared/buttons/styled-tooltip.tsx
index a99f451fcb..6b8a37fe6a 100644
--- a/src/components/shared/buttons/styled-tooltip.tsx
+++ b/src/components/shared/buttons/styled-tooltip.tsx
@@ -11,6 +11,7 @@ export interface StyledTooltipProps {
closeDelay?: number;
offset?: number;
shouldFlip?: boolean;
+ isOpen?: TooltipProps["isOpen"];
}
function getTooltipTriggerChild(children: ReactNode) {
@@ -29,6 +30,7 @@ export function StyledTooltip({
closeDelay = 100,
shouldFlip,
offset = 7,
+ isOpen,
}: StyledTooltipProps) {
const disableAnimation = import.meta.env.MODE === "test";
@@ -39,6 +41,7 @@ export function StyledTooltip({
placement={placement}
offset={offset}
shouldFlip={shouldFlip}
+ isOpen={isOpen}
className={cn("bg-white text-black", tooltipClassName)}
showArrow={showArrow}
disableAnimation={disableAnimation}
diff --git a/src/utils/format-event-timestamp.ts b/src/utils/format-event-timestamp.ts
new file mode 100644
index 0000000000..65b9f164af
--- /dev/null
+++ b/src/utils/format-event-timestamp.ts
@@ -0,0 +1,20 @@
+export function formatEventTimestamp(
+ timestamp?: string,
+ locale?: string,
+): string | null {
+ if (!timestamp) return null;
+
+ // Agent-server events carry datetime.now().isoformat(), which has no offset.
+ // Left alone the browser reads that wall-clock as its own local time, so an
+ // event recorded in a UTC sandbox renders hours off for anyone outside UTC.
+ const utc = /(?:Z|[+-]\d{2}:?\d{2})$/i.test(timestamp)
+ ? timestamp
+ : `${timestamp}Z`;
+ const date = new Date(utc);
+ if (Number.isNaN(date.getTime())) return null;
+
+ return date.toLocaleString(locale, {
+ dateStyle: "medium",
+ timeStyle: "short",
+ });
+}