Skip to content

fix(api): handle corrupted data in sandbox stop time#3203

Merged
jakubno merged 2 commits into
mainfrom
chore/clamp-sandbox-end-time-edge-case
Jul 3, 2026
Merged

fix(api): handle corrupted data in sandbox stop time#3203
jakubno merged 2 commits into
mainfrom
chore/clamp-sandbox-end-time-edge-case

Conversation

@jakubno

@jakubno jakubno commented Jul 3, 2026

Copy link
Copy Markdown
Member

Handle a case where EndTime < StartTime < now

@cla-bot cla-bot Bot added the cla-signed label Jul 3, 2026
@cursor

cursor Bot commented Jul 3, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Analytics reporting only; no auth, billing logic changes, or user-facing API behavior beyond more accurate stop timestamps and durations for bad records.

Overview
Fixes analytics duration when sandbox records have invalid or missing EndTime (before start, equal to start, or zero). sbxStopTime now treats any EndTime that is not strictly after StartTime as corrupt and returns StartTime, so reported duration is zero instead of falling through to now and producing incorrect or negative-looking usage. Normal paths (future end, past end, clock skew with future start) are unchanged. Tests were reorganized to cover corrupt cases separately with the new expectations.

Reviewed by Cursor Bugbot for commit c119758. Bugbot is set up for automated code reviews on this repo. Configure here.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the sbxStopTime function to return the start time when the end time is not after the start time, and updates the unit tests to include a new test suite for corrupt end times. I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM — small, well-tested fix that collapses corrupt records to a zero-duration analytics event.

Extended reasoning...

Overview

This PR modifies sbxStopTime in packages/api/internal/orchestrator/analytics.go so that any corrupt sandbox record (EndTime not strictly after StartTime, including the zero value) now returns StartTime, producing a zero duration for analytics. Previously such records could fall through to return now, yielding an inflated duration. The test file is reorganized: normal cases stay in TestSbxStopTime, and a new TestSbxStopTime_CorruptEndTime covers the three corrupt shapes (end < start, end == start, zero end).

Security risks

None. This is a pure-function refactor on analytics reporting math; no auth, crypto, input parsing, or external I/O is touched.

Level of scrutiny

Low. The affected function is ~10 lines, has direct unit tests exercising each branch, and only influences PostHog/analytics payloads — not sandbox lifecycle, billing enforcement, or user-visible responses. The behavior change is well-scoped to the corrupt-data path, which is what the PR title and tests both describe.

Other factors

The only reported issue is a typo (bZbe) in a test comment, already flagged as an inline nit with no runtime impact. No outstanding reviewer comments to address.

Comment thread packages/api/internal/orchestrator/analytics_test.go Outdated
Comment thread packages/api/internal/orchestrator/analytics_test.go Outdated
@jakubno jakubno merged commit a98a178 into main Jul 3, 2026
42 checks passed
@jakubno jakubno deleted the chore/clamp-sandbox-end-time-edge-case branch July 3, 2026 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants