Skip to content

fix(invoke): restore tolerant JSON parsing for Invoke headers - #19184

Closed
auyua9 wants to merge 2 commits into
infiniflow:mainfrom
auyua9:codex/invoke-headers-json-guard-huyua9
Closed

auyua9 wants to merge 2 commits into
infiniflow:mainfrom
auyua9:codex/invoke-headers-json-guard-huyua9

Conversation

@auyua9

@auyua9 auyua9 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

The d053317 Invoke refactor (Fix: variable in doc generator, #14180) silently changed how malformed or non-object JSON in the headers parameter is handled. Before that commit, Invoke would log a warning and fall back to an empty header dict; afterwards, both cases raise ValueError, which propagates out of _invoke and breaks the whole agent run whenever a user mistypes the headers field.

This PR restores the previous tolerant behavior:

  • json.JSONDecodeError -> warning + {}
  • non-object JSON payload (array, string, number, etc.) -> warning + {}

A parametrized regression test covers both branches.

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • Test

How to test

Run the unit test file directly (no live services needed):

.venv/bin/python -m pytest -q \
  test/testcases/test_web_api/test_canvas_app/test_invoke_component_unit.py \
  --confcutdir=test/testcases/test_web_api/test_canvas_app

17 tests pass (15 existing + 2 new).

The d053317 Invoke refactor switched malformed-JSON headers from a
warning+empty-dict fallback to raising ValueError, and a non-object
JSON payload (e.g. an array) from being ignored to also raising. This
turns user-config mistakes into uncaught component errors that break
the whole agent run.

This commit restores the pre-d053317 behavior:
- Log a warning and return an empty header dict when self._param.headers
  fails to parse as JSON.
- Log a warning and return an empty header dict when the parsed payload
  is not a JSON object (e.g. a list, number, or string).
- Add a parametrized regression test covering both malformed JSON and a
  non-object JSON payload.
@coderabbitai

coderabbitai Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 31ddd442-a83c-4d01-ac3e-6760e98d895b

📥 Commits

Reviewing files that changed from the base of the PR and between 48f6cbf and 4988532.

📒 Files selected for processing (2)
  • agent/component/invoke.py
  • test/testcases/test_web_api/test_canvas_app/test_invoke_component_unit.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • agent/component/invoke.py

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


📝 Walkthrough

Walkthrough

The Invoke component now ignores invalid or non-object header payloads, logs warnings, and sends requests with empty headers. Parametrized tests cover malformed JSON and JSON arrays.

Changes

Invoke header handling

Layer / File(s) Summary
Header fallback and validation
agent/component/invoke.py, test/testcases/test_web_api/test_canvas_app/test_invoke_component_unit.py
_build_headers returns empty headers and logs warnings for invalid JSON or non-object values. Tests verify both payload types.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 49885

Invoke now ignores malformed or non-object header JSON, logs a warning, and continues requests with empty headers. No current merge-blocking risk is identified.

Suggested reviewers: 6ba3i

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 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 identifies the Invoke header parsing fix and matches the main change.
Description check ✅ Passed The description explains the problem, intended behavior, change type, regression coverage, and test command. It uses a different heading from the template, but it provides the required summary informa…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI

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

I’m a rabbit with headers held light,
Bad JSON hops out of sight.
Empty maps guide the request,
Warning logs mark the test.
Two small cases pass the gate,
No broken burrow, all is straight.

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

@6ba3i 6ba3i left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few points still look worth addressing before merge:

  1. The Go implementation should be updated too.
    Python now ignores malformed/non-object header JSON and continues without custom headers, but internal/agent/component/invoke.go still returns an error for the same inputs. Since both implementations serve the same Invoke component, they should follow the same behavior.

  2. Avoid logging the raw header value.
    The new warning includes raw=%r, which can expose bearer tokens, API keys, cookies, or other secrets if the JSON is malformed. Logging the parse error alone should be enough.

  3. Python should also handle non-string header values.
    json.loads() can raise TypeError if headers arrive as an already-decoded dict or another non-string type. The backend does not strictly guarantee a string here. Accepting dicts directly and safely ignoring unsupported types would make the fallback complete.

@6ba3i

6ba3i commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

could you please fix the issues raised in my comment ?

@coderabbitai

coderabbitai Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@6ba3i

6ba3i commented Sep 10, 2026 •

Copy link
Copy Markdown
Collaborator

now overlaps #19481

@6ba3i 6ba3i closed this Sep 10, 2026
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