Skip to content

fix(agent): allow octet stream text reads - #2110

Merged
yyhhyyyyyy merged 2 commits into
devfrom
codex/fix-octet-stream-read
Aug 9, 2026
Merged

fix(agent): allow octet stream text reads#2110
yyhhyyyyyy merged 2 commits into
devfrom
codex/fix-octet-stream-read

Conversation

@zerob13

@zerob13 zerob13 commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • allow application/octet-stream files to fall through to plain-text reads instead of binary sniffing
  • decode UTF-8 BOM and UTF-16 BOM text correctly in Agent filesystem reads
  • keep known archives, WebAssembly, audio, and video blocked while preserving image vision routing
  • add regression coverage for UTF-16 diff files detected as octet streams

Tests

  • pnpm exec vitest run --config vitest.config.ts test/main/lib/binaryReadGuard.test.ts test/main/tool/agentTools/agentToolManagerRead.test.ts
  • pnpm run typecheck
  • pnpm run i18n
  • pnpm run lint
  • pnpm exec oxfmt --check src/main/lib/binaryReadGuard.ts src/main/tool/agentTools/agentFileSystemHandler.ts src/main/tool/agentTools/agentToolManager.ts test/main/lib/binaryReadGuard.test.ts test/main/tool/agentTools/agentToolManagerRead.test.ts

Summary by CodeRabbit

  • New Features

    • Improved text-file reading with automatic UTF-8, UTF-16LE, and UTF-16BE detection.
    • Added support for reading code and diff files labeled as application/octet-stream.
    • UTF-16 content is decoded cleanly without unwanted null characters or byte-order marks.
  • Bug Fixes

    • Binary, audio, and video files remain blocked from text reads.
    • Image files remain available for vision-based reading.
    • Text and document files are handled more reliably.

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0853fb75-fe09-4d67-9a17-9a4c783a678e

📥 Commits

Reviewing files that changed from the base of the PR and between 5ca2c50 and db4eaba.

📒 Files selected for processing (1)
  • test/main/tool/agentTools/agentToolManagerRead.test.ts

📝 Walkthrough

Walkthrough

The binary read guard now classifies files by MIME type only. Agent file reads support BOM-aware UTF-16LE, UTF-16BE, and UTF-8 decoding. Octet-stream code and diff files are handled as raw text.

Changes

Agent file reading

Layer / File(s) Summary
MIME guard contract
src/main/lib/binaryReadGuard.ts, test/main/lib/binaryReadGuard.test.ts
shouldRejectAgentBinaryRead now accepts a MIME type synchronously. Tests cover allowed octet-stream and image types and rejected binary, audio, and video types.
Read path integration
src/main/tool/agentTools/agentToolManager.ts, src/main/tool/agentTools/agentFileSystemHandler.ts, test/main/tool/agentTools/agentToolManagerRead.test.ts
The manager passes only the MIME type to the guard and treats octet-stream content as raw text. readFile decodes BOM-marked UTF-16LE, UTF-16BE, and UTF-8 files. Regression tests cover all three encodings and verify that file preparation is bypassed.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • ThinkInAIXYZ/deepchat#1584: Modifies UTF-8 handling for agent file and command output through different functions and execution paths.

Suggested reviewers: yyhhyyyyyy

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: allowing application/octet-stream files to be read as text by the agent.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-octet-stream-read

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

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

@zerob13
zerob13 marked this pull request as ready for review August 9, 2026 08:25
@zerob13
zerob13 requested a review from yyhhyyyyyy August 9, 2026 08:25

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/main/tool/agentTools/agentToolManagerRead.test.ts`:
- Around line 224-240: Add focused regression tests alongside the existing
UTF-16LE case for AgentFileSystemHandler.readFile behavior with UTF-16BE and
UTF-8 BOM inputs reported as application/octet-stream. Verify returned content
contains the expected text without a leading BOM or NUL characters, and keep
each case minimal and consistent with the existing manager.callTool setup.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6865541d-c736-424f-84fd-54d3e8477023

📥 Commits

Reviewing files that changed from the base of the PR and between 443d3b8 and 5ca2c50.

📒 Files selected for processing (5)
  • src/main/lib/binaryReadGuard.ts
  • src/main/tool/agentTools/agentFileSystemHandler.ts
  • src/main/tool/agentTools/agentToolManager.ts
  • test/main/lib/binaryReadGuard.test.ts
  • test/main/tool/agentTools/agentToolManagerRead.test.ts

Comment thread test/main/tool/agentTools/agentToolManagerRead.test.ts Outdated

@yyhhyyyyyy yyhhyyyyyy 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.

LGTM

@yyhhyyyyyy
yyhhyyyyyy merged commit b235bfa into dev Aug 9, 2026
12 checks passed
@yyhhyyyyyy
yyhhyyyyyy deleted the codex/fix-octet-stream-read branch August 9, 2026 16:13
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