Skip to content

fix(examples): binary flow uses raw-byte I/O - #109

Merged
sfroment merged 1 commit into
mainfrom
fix/examples-binary-files-base64
Oct 28, 2026
Merged

sfroment merged 1 commit into
mainfrom
fix/examples-binary-files-base64

Conversation

@sfroment

@sfroment sfroment commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Summary

-        binary_data = b"Binary data: \x00\x01\x02\x03\xff\xfe\xfd"
-        fs.write_file("/tmp/binary.bin", binary_data, encoding="base64")
-        file_info = fs.read_file("/tmp/binary.bin", encoding="base64")
+        binary_data = b"Binary data: \x00\x01\x02\x03\xff\xfe\xfd"
+        fs.write_file("/tmp/binary.bin", binary_data)
+        file_info = fs.read_file("/tmp/binary.bin", encoding=None)
         assert binary_data == file_info.content

encoding="base64" means two different things across executor generations: the legacy JSON routes take raw bytes and encode them; the streamed /files routes (executor v0.0.24+) decode content that is base64 text. The example passed raw bytes, so against the streamed routes it hit base64.b64decode(raw) → Incorrect padding.

The example pins koyeb/sandbox:slim, which sandbox-container CI rebuilds from main on every merge — so it always runs the streamed routes (that's exactly what turned the reconciler sandbox-suite red on merge). So drop the base64 dance and showcase the binary-safe routes directly: raw bytes in, raw bytes out with encoding=None. Executor v0.0.24+ required, same as stat() and streamed writes.

Evidence

  • Before: reconciler e2e, staging pods ...-fra-ccqck/sbq67/zrnnt, Oct 28:
  File ".../koyeb/sandbox/filesystem.py", line 130, in _put_body
    return base64.b64decode(content)
binascii.Error: Incorrect padding
SandboxFilesystemError: Failed to write file: Incorrect padding
  • After: the example modules driven end-to-end through the real SandboxFilesystem/AsyncSandboxFilesystem against stateful fakes:
[streamed(v0.0.24+) sync] PASS   disk=b'Binary data: \x00\x01\x02\x03\xff\xfe\xfd'  (real bytes on disk)
[streamed(v0.0.24+) async] PASS   disk=b'Binary data: \x00\x01\x02\x03\xff\xfe\xfd'
[legacy(JSON)         sync] expected-raise  UnicodeDecodeError  ← v0.0.24+ by design
[legacy(JSON)         async] expected-raise  UnicodeDecodeError
  • pytest koyeb/sandbox → 372 passed

Merge Danger

Door: two-way

Blast Radius: examples only — no library code touched; revert is trivial. The reconciler sandbox-suite flow goes green on the next run after this lands. On pre-v0.0.24 executors the example now raises instead of round-tripping — unreachable in practice since the pinned :slim tag tracks main, but note the write failure there surfaces as a raw UnicodeDecodeError rather than the SDK's "requires v0.0.24+" error; a cleaner legacy guard for bytes writes might be worth a follow-up in the SDK itself.

The example used the legacy encoding="base64" convention (raw bytes
in, SDK encodes). On the streamed /files routes that parameter flips
meaning — content is base64 text decoded to disk — so raw bytes hit
b64decode and fail with "Incorrect padding" against
koyeb/sandbox:slim, which tracks executor main and turned the
reconciler sandbox-suite flow red on merge. The slim tag always runs
the streamed routes here, so drop base64 entirely: raw bytes in, raw
bytes out (encoding=None), executor v0.0.24+.
@sfroment
sfroment force-pushed the fix/examples-binary-files-base64 branch from e1b1306 to 5aed87a Compare October 28, 2026 16:44
@sfroment sfroment changed the title fix(examples): 09_binary_files sends base64 text, not raw bytes fix(examples): binary flow uses raw-byte I/O Oct 28, 2026
@sfroment
sfroment merged commit b94f60a into main Oct 28, 2026
10 checks passed
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