Skip to content

fix(google): guard null parts in planGoogleHistory user-turn scan - #259

Open
dex0shubham wants to merge 1 commit into
teamchong:mainfrom
dex0shubham:fix/google-null-part-guard
Open

fix(google): guard null parts in planGoogleHistory user-turn scan#259
dex0shubham wants to merge 1 commit into
teamchong:mainfrom
dex0shubham:fix/google-null-part-guard

Conversation

@dex0shubham

@dex0shubham dex0shubham commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Problem

planGoogleHistory (src/core/google.ts) scans contents for user turns:

c.parts.some((p) => typeof p.text === 'string' && p.text.trim())

p.text is dereferenced without guarding p. A null element inside a contents turn's parts throws TypeError: Cannot read properties of null (reading 'text'). The proxy catches it and returns a 502 "pxpipe transform failed", so the whole Gemini request fails instead of being forwarded.

This violates the module's own contract: every other part-iterating function guards null (googleHistoryUnit: if (!part) { … continue }), and malformed request shapes are supposed to pass through unchanged. The existing test already pins systemInstruction: { parts: [null] } as pass-through, but the contents path — the one that reaches this scan — was untested.

Fix

Add the missing p && guard, matching the module's existing null-tolerance:

c.parts.some((p) => p && typeof p.text === 'string' && p.text.trim())

Extended the existing malformed-passthrough test with { contents: [{ role: 'user', parts: [null] }] }. Verified it fails on the old code (TypeError) and passes with the fix.

Full suite green (1204/1204); typecheck clean.

planGoogleHistory scans contents for user turns with
c.parts.some((p) => typeof p.text === 'string' && ...), dereferencing p.text
without guarding p. A null element inside a contents turn's parts throws
TypeError, which the proxy catches and returns as a 502 "pxpipe transform
failed" - failing the whole Gemini request instead of forwarding it.

Every other part-iterating function in the module guards null parts
(googleHistoryUnit: `if (!part) continue`) and the module's contract is
"malformed shape passes through unchanged" (tested). This one scan was the
gap. Add the missing `p &&` guard and cover the contents null-part case in
the existing malformed-passthrough test.
@dex0shubham
dex0shubham force-pushed the fix/google-null-part-guard branch from 77cf40d to 887c36f Compare September 2, 2026 07:14
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