Skip to content

fix(logs): return 503 instead of 500 when a v2 logs read is cancelled - #9558

Closed
waleedlatif1 wants to merge 2 commits into
stagingfrom
fix/v2-logs-transient-read-503
Closed

waleedlatif1 wants to merge 2 commits into
stagingfrom
fix/v2-logs-transient-read-503

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • GET /api/v2/logs/stats (and the other v2 logs reads) returned an unhandled 500 when Postgres cancelled the read: a read-replica recovery conflict (40001) on a long handled-error count, with valid input
  • The v2 logs error policies now answer temporary read failures with the documented 503 SERVICE_UNAVAILABLE + Retry-After; permanent errors and user-requested cancels still fall through to 500
  • isDatabaseReadUnavailable moves the existing billing-read predicate (transient driver error, read deadline, statement/transaction timeout) into lib/db/read-retry.ts, so the internal billing policy and the v2 logs policy share it
  • No in-process retry: re-running a cancelled scan only repeats its cost
  • Scoped to read routes on purpose — a builder-wide default would advise retrying writes whose outcome is unknown

Type of Change

  • Bug fix

Testing

  • route-policies.test.ts adds a case per v2 logs policy: a 40001 recovery conflict and a 57014 statement timeout return 503 with Retry-After; an undefined-table error and a user-requested cancel stay unhandled. The 503 cases fail with the fix reverted
  • route-policies, read-retry, and lib/api/server/routes suites pass locally (360 tests); check:boundaries passes
  • Lint, type-check, and audits run in CI

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Nov 2, 2026 4:49am UTC

Request Review

@greptile-apps

greptile-apps Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

V2 logs reads now return 503 with SERVICE_UNAVAILABLE and Retry-After for temporary database failures.

  • V2 log reads return a retryable response for temporary database failures.

No actionable issues found. Tests were not run during this review.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Logs read fails] --> B{Detail access must be concealed?}
  B -->|Yes| C[404 Log not found]
  B -->|No| D{Temporary database failure?}
  D -->|Yes| E[503 with Retry-After]
  D -->|No| F[Existing error response]
Loading

Reviews (3) · Last reviewed commit: "docs(db): describe how the unavailable-r..." · Reviewed by Greptile

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 4 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/db/read-retry.ts Resolved
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 force-pushed the fix/v2-logs-transient-read-503 branch from 209c79f to 080877b Compare November 2, 2026 04:49
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

This branch was previously deployed

1 inactive deployment
Preview — 080877bb Deployed Nov 2, 2026 by vercel[bot]
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.

1 participant