fix(orchestrator): drop stale pre-init logs#3297
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to correct stale log timestamps emitted by a sandbox guest before its clock is synchronized upon resume or creation. It adds a LifecycleStartedAt field to the Sandbox struct, initialized during sandbox creation and resumption, and uses it to clamp stale log timestamps to the host's start time while preserving the original timestamp. The review feedback suggests ensuring timezone consistency by explicitly converting and storing these timestamps in UTC, preventing issues with local timezone offsets in downstream log aggregation systems.
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.
| LifecycleID: lifecycleID, | ||
| LifecycleStartedAt: time.Now(), |
There was a problem hiding this comment.
It is safer to initialize LifecycleStartedAt using time.Now().UTC() to ensure that the anchor timestamp is always stored in UTC, avoiding any local timezone dependencies or discrepancies when comparing or formatting it later.
| LifecycleID: lifecycleID, | |
| LifecycleStartedAt: time.Now(), | |
| LifecycleID: lifecycleID, | |
| LifecycleStartedAt: time.Now().UTC(), |
There was a problem hiding this comment.
Good catch, fixed - forced UTC on both the write side (time.Now().UTC() in CreateSandbox/ResumeSandbox) and the format call in correctStaleTimestamp.
9f99e1b to
308c608
Compare
❌ 1 Tests Failed:
View the top 3 failed test(s) by shortest run time
View the full list of 1 ❄️ flaky test(s)
To view more test analytics, go to the Test Analytics Dashboard |
734eb85 to
9cdcd74
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9cdcd7489b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
9cdcd74 to
9a50790
Compare
matthewlouisbrockman
left a comment
There was a problem hiding this comment.
good enough for now - can we yeet some of the excessive verboseness from the comments please?
one improvement might want to consider later: comparison's happening forever. not sure if there's a way to only do these checks while we're resuming the sandbox? also i think we're dropping logs from before we fix clock while resuming but tradeoff seems fine.
A sandbox resumed from a memory snapshot boots with its clock still set to the snapshot's time, so envd's log exporter (also restored from the snapshot) can emit startup logs stamped with that old time before /init corrects the clock. Record a fresh per-lifecycle timestamp on the host before the sandbox is reachable, and reject any log timestamped more than a minute before it. envd's exporter doesn't retry on rejection, so these stale records are simply dropped instead of forwarded.
9a50790 to
b9d2947
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9ceb20d55b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| return | ||
| } | ||
|
|
||
| if hasStaleLogTimestamp(payload, sbx.LifecycleStartedAt) { |
There was a problem hiding this comment.
Preserve queued pre-pause logs
When the same sandbox is paused with envd log entries still buffered in HTTPExporter.logs, that queue is captured in the memory snapshot and is sent after resume with its original pre-pause timestamp. If the pause lasted more than a minute, this new check returns 400 for those valid same-sandbox entries, and the exporter drops non-2xx sends, so logs produced immediately before pause disappear; the filter needs to distinguish restored pre-init records from buffered pre-pause records.
Useful? React with 👍 / 👎.
A sandbox resumed from a memory snapshot boots with its clock still set to the snapshot's time. envd's log exporter is restored along with the rest of the VM, so it can send startup logs stamped with that old time before
/initcorrects the clock.Each sandbox now records a fresh host timestamp when its lifecycle is created, before it's reachable. The
/logshandler rejects any envd log timestamped more than a minute before that anchor. envd's exporter doesn't retry on a rejected request, so those stale records are simply dropped instead of being forwarded to the collector. Logs with a reasonable timestamp go through unchanged.