Skip to content

fix: Altimate Base 413 HTML body and missing header timeout - #1256

Open
anandgupta42 wants to merge 1 commit into
mainfrom
fix/altimate-base-413-and-timeout
Open

fix: Altimate Base 413 HTML body and missing header timeout#1256
anandgupta42 wants to merge 1 commit into
mainfrom
fix/altimate-base-413-and-timeout

Conversation

@anandgupta42

@anandgupta42 anandgupta42 commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #1255

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Fixes two client-side Altimate Base bugs found by live-prod E2E of the v0.11.0-beta.2 release.

Bug 1 — 413 oversize error showed a generic message instead of the friendly one.

FreeTier.describeRequestTooLarge in packages/opencode/src/altimate/free/client.ts did JSON.parse(body) in a try/catch that returned undefined on a parse failure. In production, oversized requests are rejected by the gateway's edge proxy with a raw HTML error page (not a JSON body), so the parse always throws for that case, the function always returned undefined, and the user saw a generic fallback error instead of the friendly "your request is too large — start a new session or shorten it" message.

Fix: describeRequestTooLarge now takes { status, body } instead of a bare body string. Its logic is now:

  • If the body parses as JSON and matches the known request_too_large shape, keep the existing specific message (with the KB byte-count detail when present).
  • If the body parses as JSON but is a different shape (e.g. another provider's 413, or an unrelated gateway error), still return undefined — unchanged behavior, no false positives even though the status is 413.
  • If the body does not parse as JSON (or is empty) and the status is 413, return the same friendly fallback message the JSON path produces.
  • Any non-413 status still returns undefined for an unparseable body — unchanged.

The sole caller in packages/opencode/src/provider/error.ts already knew the status was 413 before calling (it gates on input.error.statusCode === 413); it now threads input.error.statusCode through explicitly so the function itself can make the same decision without relying on caller-side control flow alone. All existing test call sites were updated to the new object signature.

Bug 2 — Altimate Base provider had no client-side header timeout.

The "altimate-free" loader in packages/opencode/src/provider/provider.ts returned options: { baseURL, apiKey, fetch } with no headerTimeout, unlike the openai loader in the same file, which sets headerTimeout: OPENAI_HEADER_TIMEOUT_DEFAULT. If the gateway hung before sending response headers, a request through Altimate Base had no client-side timeout and could hang the CLI indefinitely.

Fix: added headerTimeout: OPENAI_HEADER_TIMEOUT_DEFAULT to the altimate-free loader's options, matching the openai loader's existing default.

How did you verify your code works?

  • bun run typecheck (root, via turbo) — passes across all 15 packages.
  • Added/extended unit tests:
    • New cases in test/altimate/altimate-base-rate-limit-messages.test.ts: a raw-HTML 413 body returns the friendly fallback; an empty/absent-body 413 returns the same fallback; a 413 with the known JSON shape still returns the specific byte-count message (not the fallback); a non-413 status with an HTML body still returns undefined; a 413 with valid-but-unrelated JSON still returns undefined.
    • New integration test in test/provider/error.test.ts exercising the full ProviderError.parseAPICallError path with a 413 + raw HTML body, asserting the friendly message comes out end-to-end.
    • Extended the existing Altimate Base provider-shape test in test/provider/provider.test.ts to assert options.headerTimeout is set to the same default the openai loader uses.
    • Updated every existing describeRequestTooLarge call site (production and test) to the new { status, body } signature.
  • Ran the full affected suites locally: test/altimate/altimate-base-rate-limit-messages.test.ts, test/altimate/altimate-base-error-surfacing.test.ts, test/provider/error.test.ts, test/provider/provider.test.ts, test/provider/header-timeout.test.ts, and the full test/altimate/ directory — all green (5104 pass / 0 fail across the altimate suite; 150 pass / 0 fail for the four directly-targeted files).
  • Ran bun run script/upstream/analyze.ts --markers --base origin/main --strict — reports no upstream-shared files were touched (client.ts and provider.ts are altimate-owned, not upstream-shared), so no marker violations; new hunks are still wrapped in altimate_change comments for consistency with the surrounding code.

Not verified: the 413 fix is verified by unit test (a synthetic raw-HTML body) and by the parseAPICallError integration test, but has not been re-run against a live oversized request through the real production nginx edge — that would require reproducing a >1MiB request against the live gateway, which wasn't done as part of this fix.

Screenshots / recordings

N/A — no UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Note

Low Risk
Localized Altimate Base error mapping and provider timeout defaults; behavior is well covered by unit/integration tests with no auth or data-model changes.

Overview
Fixes two Altimate Base client bugs: oversized-request errors and hung gateway calls.

413 / request too large: describeRequestTooLarge now takes { status, body } instead of a raw body string. When the response is 413 with HTML or empty/unparseable bodies (production nginx edge rejection), it returns the same friendly Altimate Base message instead of undefined, so parseAPICallError no longer falls through to generic context_overflow. JSON request_too_large responses still get byte-count detail when available; unrelated 413 JSON shapes are left unchanged.

Header timeout: The altimate-free provider loader sets headerTimeout: OPENAI_HEADER_TIMEOUT_DEFAULT (10s), matching OpenAI so a stalled gateway cannot hang the CLI indefinitely.

Tests cover nginx HTML 413 end-to-end, edge cases for the new signature, and provider headerTimeout assertion.

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


Summary by cubic

Fixes two Altimate Base client-side bugs found in live-prod E2E: oversized requests now show the friendly "request too large" message even when the gateway rejects with raw HTML, and a hung gateway response no longer hangs the CLI. Closes #1255.

Bug Fixes

  • describeRequestTooLarge now takes { status, body } and returns the friendly message on any 413, even when the body doesn't parse as JSON.
  • A 413 with valid JSON that isn't the known request_too_large shape still returns undefined, as does any non-413 status.
  • The altimate-free provider loader now sets headerTimeout, matching the openai loader's default.

Written for commit eeccaa9. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of oversized request errors, including gateway responses with empty or unparseable bodies.
    • Displays a friendly “request too large” message for HTTP 413 responses instead of a generic error.
    • Prevents stalled gateway responses by applying a 10-second response-header timeout.
  • Tests

    • Added coverage for malformed, empty, and oversized response scenarios.

- `describeRequestTooLarge` now takes `{ status, body }` instead of a bare
  body string, and returns the friendly "request too large" message on any
  HTTP `413` even when the body is unparseable (nginx's raw HTML edge
  rejection in production, not LiteLLM's JSON shape). A 413 whose body still
  parses to the known `request_too_large` JSON shape keeps the more specific
  byte-count message; any other 413 shape or non-413 status is unchanged
  (`undefined`).
- Updated the sole caller in `provider/error.ts` to thread `statusCode`
  through, and updated every test call site to the new object signature.
- Added `headerTimeout: OPENAI_HEADER_TIMEOUT_DEFAULT` to the `altimate-free`
  provider loader's options in `provider/provider.ts`, matching the existing
  `openai` loader default, so a hung gateway response can no longer hang the
  CLI forever.
- Added unit tests covering the HTML/empty-body 413 fallback, the
  still-specific JSON-shape 413 case, a non-413 HTML body (no fallback), and
  the `altimate-free` provider's `headerTimeout`.

Closes #1255

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@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.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@cursor

cursor Bot commented Sep 7, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_ab8b4145-ae26-44eb-8057-a4fca3a83b1f)

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 7, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-07T19:41:36.209884Z eeccaa9 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
- - - - - - - - - - - - - - - - - - - - - - - - -
                    AIRECEIPTS                    
             1 session behind this PR             

claude-sonnet-5..........................≥ $1.9037
  session slice: turns 1–48 of 50
--------------------------------------------------
TOTAL priced.............................≥ $1.9037
  standard API-equivalent floor; not an invoice
  counted: 1 session
  cache served 98% of input tokens
  full receipts + session ids: section below
- - - - - - - - - - - - - - - - - - - - - - - - -
                npx aireceipts-cli                
         github.com/anandgupta42/receipts         
- - - - - - - - - - - - - - - - - - - - - - - - -
full receipts (1 session)
session id scope turns time tokens in / out cached
builder a1a1caab turns 1–48 of 50 48 11m 96 / 4k 98%

builder · a1a1caab

- - - - - - - - - - - - - - - - - - - - - - - - -
                    AIRECEIPTS                    
 “Fix two client-side bugs in the PUBLIC repo A…” 
 Claude Code · Sep 07 2026 19:25:19 UTC · 11m 04s 
               claude-sonnet-5 100%               
         cache served 98% of input tokens         

pre-edit: 26% of priced floor (12/48 turns)
  (share before the first named edit tool)

Bash.........................≥ $1.1848  (29 calls)
Read.........................≥ $0.3966  (11 calls)
Edit..........................≥ $0.2828  (7 calls)
Write..........................≥ $0.0393  (1 call)
--------------------------------------------------
TOTAL....................................≥ $1.9035
standard API-equivalent floor; not an invoice
same tokens on claude-haiku-4-5..........≥ $0.6345
  (67% lower observable floor)
  (arithmetic, not a prediction)
- - - - - - - - - - - - - - - - - - - - - - - - -
                npx aireceipts-cli                
         github.com/anandgupta42/receipts         
- - - - - - - - - - - - - - - - - - - - - - - - -

Generated by aireceipts

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

👋 This PR was automatically closed by our quality checks.

Common reasons:

  • New GitHub account with limited contribution history
  • PR description doesn't meet our guidelines
  • Contribution appears to be AI-generated without meaningful review

If you believe this was a mistake, please open an issue explaining your intended contribution and a maintainer will help you.

2 similar comments
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

👋 This PR was automatically closed by our quality checks.

Common reasons:

  • New GitHub account with limited contribution history
  • PR description doesn't meet our guidelines
  • Contribution appears to be AI-generated without meaningful review

If you believe this was a mistake, please open an issue explaining your intended contribution and a maintainer will help you.

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

👋 This PR was automatically closed by our quality checks.

Common reasons:

  • New GitHub account with limited contribution history
  • PR description doesn't meet our guidelines
  • Contribution appears to be AI-generated without meaningful review

If you believe this was a mistake, please open an issue explaining your intended contribution and a maintainer will help you.

@coderabbitai

coderabbitai Bot commented Sep 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 8e94d56a-5bf2-4a78-863b-d193edaeb272

📥 Commits

Reviewing files that changed from the base of the PR and between ec475f4 and eeccaa9.

📒 Files selected for processing (7)
  • packages/opencode/src/altimate/free/client.ts
  • packages/opencode/src/provider/error.ts
  • packages/opencode/src/provider/provider.ts
  • packages/opencode/test/altimate/altimate-base-error-surfacing.test.ts
  • packages/opencode/test/altimate/altimate-base-rate-limit-messages.test.ts
  • packages/opencode/test/provider/error.test.ts
  • packages/opencode/test/provider/provider.test.ts

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

Altimate Base now returns a friendly request-size message for HTTP 413 responses with JSON, HTML, empty, or malformed bodies. The provider also applies a 10-second header timeout.

Changes

Altimate Base provider behavior

Layer / File(s) Summary
Request-size error handling
packages/opencode/src/altimate/free/client.ts, packages/opencode/src/provider/error.ts, packages/opencode/test/altimate/*, packages/opencode/test/provider/error.test.ts
describeRequestTooLarge accepts status and body data. HTTP 413 responses use the friendly fallback when the body is malformed, empty, or HTML. Provider error translation and tests use the updated behavior.
Provider header timeout
packages/opencode/src/provider/provider.ts, packages/opencode/test/provider/provider.test.ts
The altimate-free provider sets a 10-second header timeout. The provider test verifies the value.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to eecca

Altimate Base users now receive clear request-size guidance for all 413 response formats, and stalled gateway header responses time out after 10 seconds. Focused error-handling and provider configuration coverage supports merge readiness.

Poem

A rabbit reads each line,
The patch grows clear beneath the moon,
Small changes hop in place,
Tests guard the garden path,
Reviews bloom before the dawn.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies both fixes: Altimate Base 413 HTML handling and the missing header timeout.
Description check ✅ Passed The description follows the required template. It identifies issue #1255, marks the change as a bug fix, explains both fixes, documents verification, notes the lack of live production testing, and com…
Linked Issues check ✅ Passed The changes address both objectives in issue #1255. They add friendly handling for unparseable or empty 413 responses, preserve known JSON-specific handling, add the Altimate Base header timeout, and …
Out of Scope Changes check ✅ Passed All production and test changes relate directly to the two Altimate Base bugs described in issue #1255. No unrelated code changes are identified.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/altimate-base-413-and-timeout

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

👋 This PR was automatically closed by our quality checks.

Common reasons:

  • New GitHub account with limited contribution history
  • PR description doesn't meet our guidelines
  • Contribution appears to be AI-generated without meaningful review

If you believe this was a mistake, please open an issue explaining your intended contribution and a maintainer will help you.

@kilo-code-bot

kilo-code-bot Bot commented Sep 7, 2026

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (7 files)
  • packages/opencode/src/altimate/free/client.ts
  • packages/opencode/src/provider/error.ts
  • packages/opencode/src/provider/provider.ts
  • packages/opencode/test/altimate/altimate-base-error-surfacing.test.ts
  • packages/opencode/test/altimate/altimate-base-rate-limit-messages.test.ts
  • packages/opencode/test/provider/error.test.ts
  • packages/opencode/test/provider/provider.test.ts

Reviewed by deepseek-v4-pro · Input: 40.8K · Output: 13.1K · Cached: 397.4K

Review guidance: REVIEW.md from base branch main

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

No issues found across 7 files

Re-trigger cubic

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.

Altimate Base: 413 HTML error body shows generic message; no client-side header timeout

1 participant