Skip to content

fix(api): stop logging expected sandbox 404s as errors (timeout handler + access log) - #3318

Open
AdaAibaby wants to merge 1 commit into
e2b-dev:mainfrom
AdaAibaby:fix/sandbox-404-log-noise
Open

AdaAibaby wants to merge 1 commit into
e2b-dev:mainfrom
AdaAibaby:fix/sandbox-404-log-noise

Conversation

@AdaAibaby

@AdaAibaby AdaAibaby commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A timeout/pause call can race the sandbox's own expiry — the SDK cannot always know a sandbox is already gone before issuing the request, so a 404 from KeepAliveFor is an expected outcome, not a failure. The handler previously reported every KeepAliveFor error through telemetry.ReportError, which logs at WARN and records a span error. For the 404 case that is pure noise that buries real failures.

Changes

  • sandbox_timeout.go — on a 404, log at INFO (no stack trace, no span error) instead of telemetry.ReportError. Every other status still flows through ReportError, so real 5xx failures stay visible. The handler now calls KeepAliveFor through a small timeoutOrchestrator interface (timeoutBackendOverride), matching the existing pause/fork/connect backend-override pattern, so the branch is testable without a real orchestrator.
  • middleware/logging.go — HTTP 404 responses log at INFO instead of WARN in the request access log. A 404 is a normal "already gone / never existed" outcome, not a client error.

Note (scope reduced from the original PR)

The original PR also edited logger/logger.go to cap automatic stack-trace capture at ErrorLevel, on the premise that stack traces were attached to every WARN. That premise does not hold on current main: the logger config already sets Development: false, and zap captures stack traces at ErrorLevel (not WarnLevel) in non-development mode (zap.Config.buildOptions → stackLevel := ErrorLevel). The logger.go change was therefore a no-op and has been dropped.

Test plan

  • go test ./internal/handlers/ -short passes (DB-gated integration tests skipped).
  • New sandbox_timeout_notfound_test.go: a 404 from KeepAliveFor returns 404 to the client and records no span error; a 5xx still records a span error (real failures stay visible).
  • Build + vet clean for packages/api and packages/shared/pkg/middleware.

/cc @ryan-sana @jakubno @dobrac @ValentaTomas @arkamar @tvi Looking forward to your code review.

@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 logging behavior for 404 Not Found errors. It updates the sandbox timeout handler to log an info message instead of reporting a telemetry error when a sandbox is not found, configures the logger to include stack traces for error-level logs, and adjusts the logging middleware to log 404 StatusNotFound responses at the Info level rather than the Warn level. 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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f9009ffbab

ℹ️ 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".

Comment thread packages/shared/pkg/logger/logger.go Resolved
@ValentaTomas
ValentaTomas force-pushed the main branch 2 times, most recently from 5aad415 to d71980e Compare July 25, 2026 22:53
A timeout/pause call can race the sandbox's own expiry: the SDK cannot always
know a sandbox is already gone before issuing the request, so KeepAliveFor
returning 404 is an expected outcome, not a failure.

PostSandboxesSandboxIDTimeout reported every KeepAliveFor error through
telemetry.ReportError, which logs at WARN and records a span error. For the
404 case that is pure noise that buries real failures. Log the 404 at INFO
(no stack trace, no span error) and keep ReportError for every other code.

Also lower the access-log level for HTTP 404 responses from WARN to INFO in
the shared logging middleware — a 404 is a normal "already gone / never
existed" outcome, not a client error worth a WARN.

To make the 404 branch testable without a real orchestrator, the handler now
goes through a small timeoutOrchestrator interface (timeoutBackendOverride),
matching the existing pause/fork/connect backend-override pattern. Added a
test asserting a 404 records no span error while a 5xx still does.
@AdaAibaby
AdaAibaby force-pushed the fix/sandbox-404-log-noise branch from 20daeec to 8299ea2 Compare November 10, 2026 09:08
@AdaAibaby AdaAibaby changed the title fix(api): downgrade sandbox 404 log noise from WARN to INFO fix(api): stop logging expected sandbox 404s as errors (timeout handler + access log) Nov 10, 2026
@AdaAibaby
AdaAibaby force-pushed the fix/sandbox-404-log-noise branch from 8299ea2 to ac81f60 Compare November 25, 2026 14:03

This branch has not been deployed

No deployments
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