From 5fcfda5645600f1f67e956c898bcd06572adacb2 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 14 May 2026 15:40:05 +0000 Subject: [PATCH 1/2] fix: use last resumed event timestamp for 'running for' calculation When a sandbox has been paused and resumed, the 'running for' field now uses the last 'resumed' event timestamp instead of the creation timestamp, so the displayed duration reflects time since the most recent resume rather than total time since creation. Co-Authored-By: ben@e2b.dev --- .../dashboard/sandbox/header/ran-for.tsx | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/features/dashboard/sandbox/header/ran-for.tsx b/src/features/dashboard/sandbox/header/ran-for.tsx index 52ed9fa90..86225350a 100644 --- a/src/features/dashboard/sandbox/header/ran-for.tsx +++ b/src/features/dashboard/sandbox/header/ran-for.tsx @@ -2,6 +2,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react' import { useSandboxContext } from '../context' +import { SANDBOX_LIFECYCLE_EVENT_RESUMED } from '../monitoring/utils/constants' export default function RanFor() { const { sandboxInfo, sandboxLifecycle, isRunning } = useSandboxContext() @@ -10,11 +11,22 @@ export default function RanFor() { const startedAt = sandboxLifecycle?.createdAt const pausedAt = sandboxLifecycle?.pausedAt const endedAt = sandboxLifecycle?.endedAt + const events = sandboxLifecycle?.events + + const lastResumedAt = useMemo(() => { + if (!events) return null + for (let i = events.length - 1; i >= 0; i--) { + if (events[i].type === SANDBOX_LIFECYCLE_EVENT_RESUMED) { + return events[i].timestamp + } + } + return null + }, [events]) - const startDate = useMemo( - () => (startedAt ? new Date(startedAt) : null), - [startedAt] - ) + const startDate = useMemo(() => { + const effectiveStart = lastResumedAt ?? startedAt + return effectiveStart ? new Date(effectiveStart) : null + }, [lastResumedAt, startedAt]) const pausedDate = useMemo( () => (pausedAt ? new Date(pausedAt) : null), [pausedAt] From 03c480ffbbb766ed46c71a1f72aabaa67a665fd8 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 14 May 2026 15:46:48 +0000 Subject: [PATCH 2/2] fix: handle possibly undefined event in loop to satisfy strict TS checks Co-Authored-By: ben@e2b.dev --- src/features/dashboard/sandbox/header/ran-for.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/features/dashboard/sandbox/header/ran-for.tsx b/src/features/dashboard/sandbox/header/ran-for.tsx index 86225350a..a587034ef 100644 --- a/src/features/dashboard/sandbox/header/ran-for.tsx +++ b/src/features/dashboard/sandbox/header/ran-for.tsx @@ -16,8 +16,9 @@ export default function RanFor() { const lastResumedAt = useMemo(() => { if (!events) return null for (let i = events.length - 1; i >= 0; i--) { - if (events[i].type === SANDBOX_LIFECYCLE_EVENT_RESUMED) { - return events[i].timestamp + const event = events[i] + if (event && event.type === SANDBOX_LIFECYCLE_EVENT_RESUMED) { + return event.timestamp } } return null