Skip to content

fix(rpc): action with file#307

Open
arnaud-moncel wants to merge 2 commits into
fix/rpc/action-formfrom
fix/rpc/action-file
Open

fix(rpc): action with file#307
arnaud-moncel wants to merge 2 commits into
fix/rpc/action-formfrom
fix/rpc/action-file

Conversation

@arnaud-moncel
Copy link
Copy Markdown
Member

@arnaud-moncel arnaud-moncel commented May 20, 2026

Definition of Done

General

  • Write an explicit title for the Pull Request, following Conventional Commits specification
  • Test manually the implemented changes
  • Validate the code quality (indentation, syntax, style, simplicity, readability)

Security

  • Consider the security impact of the changes made

Note

Add file action response support to RPC collection and agent route

  • Updates Collection#execute in collection.rb to request the raw Faraday::Response (via with_response: true) and detect X-Forest-Action-Type: File headers, returning a structured File result hash with mime type, filename, optional response headers, and stream.
  • Adds RpcClient#call_rpc with_response keyword argument so callers can receive the raw response object instead of the parsed body.
  • Updates ActionExecute#handle_request in action_execute.rb to detect File results and build a response with Content-Disposition, X-Forest-Action-Type, and related headers before streaming the file content.
  • Behavioral Change: execute now returns response.body (instead of the parsed hash) for non-file actions, since call_rpc is called with with_response: true.

Macroscope summarized 74c7031.

@qltysh
Copy link
Copy Markdown

qltysh Bot commented May 20, 2026

1 new issue

Tool Category Rule Count
qlty Structure Function with many parameters (count = 7): call_rpc 1


# rubocop:disable Metrics/ParameterLists
def call_rpc(endpoint, caller: nil, method: :get, payload: nil, symbolize_keys: false, if_none_match: nil)
def call_rpc(endpoint, caller: nil, method: :get, payload: nil, symbolize_keys: false,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Function with many parameters (count = 7): call_rpc [qlty:function-parameters]

name: CGI.unescape(file_name_header.to_s),
stream: response.body.to_s
}
result[:response_headers] = JSON.parse(response_headers_header) if response_headers_header
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Low forest_admin_datasource_rpc/collection.rb:198

When response_headers_header is an empty string or invalid JSON, JSON.parse raises JSON::ParserError and crashes action execution. The condition if response_headers_header is truthy for empty strings, so an absent or malformed header causes a hard failure rather than graceful fallback.

-      result[:response_headers] = JSON.parse(response_headers_header) if response_headers_header
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file packages/forest_admin_datasource_rpc/lib/forest_admin_datasource_rpc/collection.rb around line 198:

When `response_headers_header` is an empty string or invalid JSON, `JSON.parse` raises `JSON::ParserError` and crashes action execution. The condition `if response_headers_header` is truthy for empty strings, so an absent or malformed header causes a hard failure rather than graceful fallback.

Evidence trail:
packages/forest_admin_datasource_rpc/lib/forest_admin_datasource_rpc/collection.rb lines 188-201 at REVIEWED_COMMIT: `response_headers_header` set from `response.headers['x-forest-action-response-headers']` (line 189), guard on line 198 `if response_headers_header` is truthy for empty strings in Ruby, `JSON.parse("")` raises `JSON::ParserError`. Ruby semantics: only `nil` and `false` are falsy; empty string is truthy.

Base automatically changed from fix/rpc/action-response to main May 21, 2026 08:28
@arnaud-moncel arnaud-moncel force-pushed the fix/rpc/action-file branch 2 times, most recently from 682b89a to 48a1cdd Compare May 21, 2026 13:55
@arnaud-moncel arnaud-moncel changed the base branch from main to fix/rpc/action-form May 21, 2026 13:55
Comment thread packages/forest_admin_rpc_agent/lib/forest_admin_rpc_agent/agent.rb
@arnaud-moncel arnaud-moncel force-pushed the fix/rpc/action-file branch from 0fc8d1a to 78f0eaa Compare May 21, 2026 14:08
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