Skip to content

Conversation

@dobrac
Copy link
Contributor

@dobrac dobrac commented Nov 11, 2025

Ensure error logs are always included in build failure responses, even with pagination offsets or log limits.

Previously, error logs for a failed step might be omitted from the reason.logEntries field if the client's polling offset had moved past them or if the log limit truncated them. This PR introduces a fallback: if error logs for a failed step are not found within the currently paginated log batch, a fresh query is made from offset 0 specifically for that step to guarantee their inclusion in the API response.


Slack Thread

Open in Cursor Open in Web

Co-authored-by: jakub.dobry <jakub.dobry@e2b.dev>
@cursor
Copy link

cursor bot commented Nov 11, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

// fetch logs from the beginning specifically for the error step
if len(errorLogs) == 0 && result.Status == api.TemplateBuildStatusError {
// Fetch all logs from the beginning to capture error context
allLogs := cli.GetLogs(ctx, templateID, buildID, 0, nil)
Copy link

Choose a reason for hiding this comment

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

Performance Issue: Unbounded log fetch on every error response

On line 136, when error logs are not found in the current paginated batch, cli.GetLogs(ctx, templateID, buildID, 0, nil) is called with no level filter and offset 0. This fetches ALL logs from Loki (up to the templateBuildLogsLimit of 1,000 entries) for every error build status request where the client has paginated past the error logs.

Problem: This doubles the log fetching cost for the common polling pattern:

  1. Client polls with increasing offset
  2. Offset eventually exceeds error log position
  3. Every subsequent poll triggers two full log fetches: the paginated one (line 116) AND the fallback from offset 0

Impact:

  • Increased Loki query load during active polling
  • Higher latency for error responses
  • Memory allocation for potentially 2,000 log entries per request

Suggested mitigation: Pass a warn-level filter to only fetch warn/error logs:

warnLevel := logs.WarnLevel
allLogs := cli.GetLogs(ctx, templateID, buildID, 0, &warnLevel)

This reduces the fetch to only warning/error logs needed for result.Reason.LogEntries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants