Skip to content

fix(functions): treat invoke 2xx as success regardless of body shape (VOL-766) - #154

Open
connorckong wants to merge 1 commit into
Kong:mainfrom
connorckong:connorckong/vol-766-fix
Open

fix(functions): treat invoke 2xx as success regardless of body shape (VOL-766)#154
connorckong wants to merge 1 commit into
Kong:mainfrom
connorckong:connorckong/vol-766-fix

Conversation

@connorckong

@connorckong connorckong commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Fixes VOL-766: volcano functions invoke reported a false error on genuine 2xx responses whenever the function handler returned a non-object body (plain text, HTML, empty, or non-object JSON).
  • Root cause (validated): InvokeFunction used the OpenAPI-generated InvokeFunctionWithResponse client and only treated the call as success when JSONDefault/JSON200 were populated. Those fields are only filled for JSON object bodies. For plain text / empty / non-JSON content-types, the typed fields stay nil and the caller fell through to error classification — producing messages like HTTP 200: plain text from function or HTTP 204: No Content. For application/json arrays (and other non-object JSON), the failure is even earlier: ParseInvokeFunctionClientResponse fails during json.Unmarshal into FunctionInvocationResponse (map[string]interface{}), so InvokeFunctionWithResponse returns a parse error before status-based success handling runs.
  • Fix: InvokeFunction calls the raw (non-WithResponse) client method, classifies success purely by HTTP status (2xx = success), and decodes the body leniently (JSON object as-is; other JSON/plain text under a "body" key; empty body as {}). Non-2xx responses still go through apiError normalization. No API request/response contract or endpoint changes; only internal/api/functions.go and its tests.

Validation (independent review)

  • Reproduced the pre-fix bug against main for plain-text 200, JSON-array 200 (unmarshal/parse failure), and empty 204; confirmed the CLI path surfaces Error: failed to invoke function "...": HTTP 200: ....
  • Confirmed the fix returns success on those same cases (including via the functions invoke command harness).
  • Ran full suite: go build ./..., go vet ./..., go test ./... -count=1 — all passed.
  • Regression hunt: non-2xx paths still error with status preserved for structured error / error_description / message, 400/401/403/404/429/503, plain-text and HTML error bodies, non-error JSON objects/arrays, empty bodies, malformed JSON, and 302 redirects. No case found where a real failure is reported as success.

Test plan

  • Unit: TestInvokeFunctionSuccessWithNonObjectBody (plain text, no content-type object JSON, JSON array, empty 204)
  • Unit: existing TestInvokeFunctionErrorsNormalize (429) still passes
  • Full go test ./... -count=1
  • Optional smoke: deploy/invoke a function that returns plain text or a JSON array and confirm volcano functions invoke prints success JSON

Made with Cursor

Invoke responses can be plain text, non-object JSON, or empty; classifying
success only via the generated typed JSON fields falsely errored on genuine
2xx. Classify by HTTP status and decode the body leniently instead.

Co-authored-by: Cursor <cursoragent@cursor.com>
@connorckong
connorckong requested a review from a team as a code owner August 6, 2026 22:05
@CLAassistant

CLAassistant commented Aug 6, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.

2 participants