Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix: show local time on Pending run rows instead of Jan 1, 1970 (#812)

Hiep Le376569eb0141
diff --git a/__tests__/components/automations/detail/activity-log-item.test.tsx b/__tests__/components/automations/detail/activity-log-item.test.tsx
index 7bfcf17609..663f983211 100644
--- a/__tests__/components/automations/detail/activity-log-item.test.tsx
+++ b/__tests__/components/automations/detail/activity-log-item.test.tsx
@@ -134,3 +134,51 @@ describe("ActivityLogItem β€” logs button", () => {
).toBe(true);
});
});
+
+describe("ActivityLogItem β€” timestamp fallback", () => {
+ beforeEach(() => {
+ __resetActiveStoreForTests();
+ setRegisteredBackends([localBackend]);
+ setActiveSelection({ backendId: localBackend.id });
+ });
+
+ afterEach(() => {
+ __resetActiveStoreForTests();
+ vi.useRealTimers();
+ });
+
+ it("renders the user's local time instead of the Unix epoch when started_at is unset on a Pending run", () => {
+ // Arrange: the backend reports started_at as epoch-zero while a run is
+ // still Pending. Pin "now" so the assertion is deterministic.
+ vi.useFakeTimers();
+ vi.setSystemTime(new Date("2026-05-27T13:00:00Z"));
+ const run = makeRun({
+ status: AutomationRunStatus.PENDING,
+ started_at: "1970-01-01T00:00:00Z",
+ conversation_id: null,
+ bash_command_id: null,
+ });
+
+ // Act
+ const { container } = renderItem(run);
+
+ // Assert: the row reflects the current clock, not 1970.
+ expect(container.textContent).toContain("2026");
+ expect(container.textContent).not.toContain("1970");
+ });
+
+ it("renders the backend-provided started_at unchanged when it is a valid timestamp", () => {
+ // Arrange: pin "now" to a different year so we can prove the row uses
+ // started_at rather than the fallback substitution.
+ vi.useFakeTimers();
+ vi.setSystemTime(new Date("2030-01-01T00:00:00Z"));
+ const run = makeRun({ started_at: "2027-03-15T09:00:00Z" });
+
+ // Act
+ const { container } = renderItem(run);
+
+ // Assert
+ expect(container.textContent).toContain("2027");
+ expect(container.textContent).not.toContain("2030");
+ });
+});
diff --git a/src/components/features/automations/detail/activity-log-item.tsx b/src/components/features/automations/detail/activity-log-item.tsx
index 48a42802ff..73d30438c4 100644
--- a/src/components/features/automations/detail/activity-log-item.tsx
+++ b/src/components/features/automations/detail/activity-log-item.tsx
@@ -22,6 +22,12 @@ function formatRunTimestamp(dateStr: string, locale: string): string {
});
}
+function isInvalidTimestamp(dateStr: string | null | undefined): boolean {
+ if (!dateStr) return true;
+ const t = new Date(dateStr).getTime();
+ return Number.isNaN(t) || t === 0;
+}
+
function getConversationUrl(conversationId: string): string {
// In agent-canvas, conversations are at /conversations/:id
return `/conversations/${conversationId}`;
@@ -32,8 +38,18 @@ export function ActivityLogItem({ run }: ActivityLogItemProps) {
const hasConversation = !!run.conversation_id;
const hasBashCommand = !!run.bash_command_id;
const [logsOpen, setLogsOpen] = useState(false);
+ // The backend leaves started_at unset (epoch/zero) while a run is Pending
+ // and only populates it once execution begins. Show the user's local time
+ // at first render in that window so the row doesn't read "Jan 1, 1970".
+ const [fallbackStartedAt] = useState(() => new Date().toISOString());
+ const effectiveStartedAt = isInvalidTimestamp(run.started_at)
+ ? fallbackStartedAt
+ : run.started_at;
- const formattedTimestamp = formatRunTimestamp(run.started_at, i18n.language);
+ const formattedTimestamp = formatRunTimestamp(
+ effectiveStartedAt,
+ i18n.language,
+ );
const handleLogsClick = (
e: