Skip to content

CLIInstaller: write the downloaded CLI in binary mode on every platform - #179

Merged
ya-luotao merged 1 commit into
mainfrom
fix/install-cli-binmode
Oct 27, 2026
Merged

ya-luotao merged 1 commit into
mainfrom
fix/install-cli-binmode

Conversation

@ya-luotao

@ya-luotao ya-luotao commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #177

bin/rails claude_agent_sdk:install_cli failed in every Rails app with Encoding::UndefinedConversionError. Http.download_to opened the download with File::BINARY, which is 0 outside Windows, so the file was in text mode. Rails sets Encoding.default_internal to UTF-8, and every write then transcoded the binary chunks, raising on the first byte that is not valid UTF-8. The same thing happens outside Rails whenever default_internal is set.

The file is now opened with binmode: true, which also covers what File::BINARY did on Windows.

The two other installer IO paths don't need changing: Metadata.write writes ASCII only, and Metadata.read uses File.read(path, limit), which returns a binary string. Checked with external US-ASCII / internal UTF-8 (a common Docker locale), including a VERSION file containing non-UTF-8 bytes, which still gets a clean reinstall.

Tests

  • New example in spec/unit/cli_installer_spec.rb: with default_internal set to UTF-8, download_to writes non-UTF-8 bytes unchanged. It fails on main and passes here.
  • spec/unit/cli_installer*_spec.rb: 138 examples, 0 failures. RuboCop: no offenses.

🤖 Generated with Claude Code

https://claude.ai/code/session_016wuLhHzFb7oEoM5Qw39CBj


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

File::BINARY is 0 outside Windows, so the download was opened in text
mode. With Encoding.default_internal set (Rails sets it to UTF-8), each
write transcoded the binary chunks and raised
Encoding::UndefinedConversionError on the first byte that is not valid
UTF-8, so `bin/rails claude_agent_sdk:install_cli` always failed.
Open the file with binmode: true instead.

Fixes #177

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016wuLhHzFb7oEoM5Qw39CBj
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T08:08:39.975364Z d9af541 Manual request
🔒 Security Review ✅ Completed 2026-10-27T08:09:05.092464Z d9af541 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ya-luotao

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: d9af541b0f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: d9af541b0f

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ya-luotao
ya-luotao merged commit 3bed891 into main Oct 27, 2026
15 checks passed
@ya-luotao
ya-luotao deleted the fix/install-cli-binmode branch October 27, 2026 08:10
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.

install_cli fails under Rails: the CLI is written in text mode, as File::BINARY is a no-op outside Windows

1 participant