Repository navigation
fix(ai-gateway): detect cache-breakpoint markers consistently across request bodies - #8380
Conversation
…request bodies Rework cache-breakpoint marker detection in the shared OpenRouter request transform into a single traversal over array and object nodes. Breakpoint placement for chat-completions, responses and messages bodies is unchanged, and tests cover marker detection in chat-completions content blocks and in responses input.
Read the last message content into a local and assert it is an array before indexing, so the nested marker case does not rely on a non-null assertion.
Code Review SummaryStatus: 1 Issue Found | Recommendation: Address before merge Executive SummaryThe new pre-push budget check bounds the Overview
Issue Details (click to expand)WARNING
Files Reviewed (2 files)
Fix these issues in Kilo Cloud Previous Review Summary (commit 203fb90)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 203fb90)Status: 2 Issues Found | Recommendation: Address before merge Executive SummaryThe iterative marker scan avoids the deep-recursion stack overflow, but exhausting its new node budget is silently treated as "markers already present", disabling cache breakpoints for the largest requests. Overview
Issue Details (click to expand)WARNING
SUGGESTION
Files Reviewed (2 files)
Reviewed by deepseek-v4.1-flash-1017 · Input: 32.8K · Output: 6.5K · Cached: 360.7K Review guidance: REVIEW.md from base branch |
Account for queued nodes in one place while walking the body, and keep the new test bodies typed as their request kinds so each case narrows correctly.
|
What size (MBs) would the request have to be to trigger a stack overflow? |
|
bot: Depth, not size, is the limiting dimension here: in a maximally nested body each level costs two bytes, so the 4.5 MB request-body ceiling (Vercel returns Measured on this branch by calling
The scan keeps its own work list, so call-stack use does not grow with nesting depth, and it stops after 100,000 visited nodes, which is why the large rows finish in single-digit milliseconds. So no request size within the body limit reaches a stack overflow in this transform. |
Change
Rework cache-breakpoint marker detection in the shared OpenRouter request transform into a single pass over array and object nodes, returning as soon as a node owns a
cache_controlorprompt_cache_breakpointkey.addCacheBreakpointskeeps today's breakpoint placement and logging for chat-completions, responses and messages bodies; only the marker scan changes.Tests
apps/web/src/tests/openrouter-request-helpers.test.tsgains three cases in the existingaddCacheBreakpointsgroup:cache_controlkeeps its placement;prompt_cache_breakpointkeeps its placement;End-to-end evidence
Ran the ai-gateway app on the work VM in development mode against local PostgreSQL and a local stub inference upstream, with an owned fake account and a custom LLM definition whose base URL points at the stub. Over
POST /api/v1/chat/completions:cache_controlUnit and type checks on this VM: the request-helpers suite passes (53 tests),
@kilocode/web-sharedtypecheck passes, and oxlint reports no findings for the changed files.Proxy answers
The owner's proxy gave these answers in the owner's place.