Skip to content

Commit d1c5552

Browse files
fix: use last resumed event timestamp for 'running for' calculation (#328)
## Summary When a sandbox has been paused and then resumed, the "running for" field in the sandbox details header was incorrectly calculating duration from the creation timestamp. This meant it included the paused time in the displayed duration. This fix looks up the last `sandbox.lifecycle.resumed` event from the lifecycle events array and uses its timestamp as the start for the "running for" calculation. If no resumed event exists (sandbox was never paused), it falls back to the original `createdAt` timestamp. ## Review & Testing Checklist for Human - [ ] Open a sandbox that has been paused and then resumed — verify the "running for" field shows time since last resume, not since creation - [ ] Open a sandbox that has never been paused — verify "running for" still shows time since creation (no regression) - [ ] Open a killed sandbox that was previously paused/resumed — verify "ran for" shows duration from last resume to kill time ### Notes The change is isolated to `src/features/dashboard/sandbox/header/ran-for.tsx`. The events array used is the same one already available in the sandbox lifecycle context and used by the monitoring charts. Link to Devin session: https://app.devin.ai/sessions/ff633b5c68c846719d63d51498cedc2d --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: ben@e2b.dev <ben@e2b.dev>
1 parent ab740ed commit d1c5552

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

src/features/dashboard/sandbox/header/ran-for.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { useCallback, useEffect, useMemo, useState } from 'react'
44
import { useSandboxContext } from '../context'
5+
import { SANDBOX_LIFECYCLE_EVENT_RESUMED } from '../monitoring/utils/constants'
56

67
export default function RanFor() {
78
const { sandboxInfo, sandboxLifecycle, isRunning } = useSandboxContext()
@@ -10,11 +11,23 @@ export default function RanFor() {
1011
const startedAt = sandboxLifecycle?.createdAt
1112
const pausedAt = sandboxLifecycle?.pausedAt
1213
const endedAt = sandboxLifecycle?.endedAt
14+
const events = sandboxLifecycle?.events
15+
16+
const lastResumedAt = useMemo(() => {
17+
if (!events) return null
18+
for (let i = events.length - 1; i >= 0; i--) {
19+
const event = events[i]
20+
if (event && event.type === SANDBOX_LIFECYCLE_EVENT_RESUMED) {
21+
return event.timestamp
22+
}
23+
}
24+
return null
25+
}, [events])
1326

14-
const startDate = useMemo(
15-
() => (startedAt ? new Date(startedAt) : null),
16-
[startedAt]
17-
)
27+
const startDate = useMemo(() => {
28+
const effectiveStart = lastResumedAt ?? startedAt
29+
return effectiveStart ? new Date(effectiveStart) : null
30+
}, [lastResumedAt, startedAt])
1831
const pausedDate = useMemo(
1932
() => (pausedAt ? new Date(pausedAt) : null),
2033
[pausedAt]

0 commit comments

Comments
 (0)