Repository navigation
fix(sdk): fall back when the output directory cannot be created - #6634
Conversation
…ir-fallback # Conflicts: # tests/sdk/utils/test_truncate.py
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Scope
This is an SDK-side bug fix in openhands-sdk/openhands/sdk/utils/truncate.py — squarely within this repository's ownership (Python SDK behavior). No product or architecture decision is needed, so the technical review proceeds.
Assessment
The fix correctly moves save_dir_path.mkdir(parents=True, exist_ok=True) inside the existing try/except in _save_full_content, so a failed directory creation now falls back to plain truncation instead of raising. This matches the pre-existing fallback contract for write failures and resolves #6219.
Verified on the current head dbcce7f4:
- Bug reproduced on base
origin/main(03f461a8):maybe_truncate(content, truncate_after=500, save_dir=<path of an existing file>)raisesFileExistsError. - Fixed on this head: the same call (file at the save path, and file blocking the save path's parent) returns clipped 500-char output with no persist notice and no change to the blocking file; the happy path still saves and references the file. Both parametrized variants of the new test cover these cases.
uv run pytest tests/sdk/utils/ -q→ 274 passed, 2 xfailed (includes all 22 tests intests/sdk/utils/test_truncate.py).tests/tools/terminal/test_observation_truncation.py(5 passed) andtests/tools/file_editor(78 passed) — the mainsave_dirconsumers (terminal, browser, file editor tools) are unaffected.
The analogous _save_screenshot in openhands-tools/.../browser_use/definition.py already wraps its own mkdir in try/except, so no sibling call site is left broken.
Side effects vs. base: previously failing mkdir and write_text now share one handler; on mkdir failure the function returns None before touching any file, so there is no path where deduplication returns a stale path for content that was never written. The dedup happy path behavior is unchanged.
Current CI on this head is green for all test/validate checks (only Docker image Build & Push jobs are pending, which are not test gates).
No material correctness, security, or compatibility findings.
✅ APPROVED
HUMAN:
just fixing a bug
AGENT:
Why
maybe_truncate(..., save_dir=...)raises when the save directory cannot be created, for example when an existing file sits at that path._save_full_contentonly guardedwrite_text; themkdirran outside the error handler.This carries over #6220 by Suyash Bhattarai unchanged. That branch conflicts with
main's parametrizedtest_truncate.pyand does not allow pushes from maintainers, so this branch adds one merge commit that keepsmain's tests and re-adds the new one.Summary
Issue Number
Fixes #6219. Part of #6348.
How to Test
22 passed. The pinned
test_maybe_truncate_unusable_save_dir_falls_back_to_plain_noticefrom the edge-case branch reports XPASS(strict) on this head.Type
🐳 Agent Server images for this PR — GHCR package, pull/run commands, and all pushed tags (click to expand)
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdkpython-node-runtimepython-node-runtimepython-node-runtimegolang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:dbcce7f-pythonRun
All tags pushed for this build
About Multi-Architecture Support
dbcce7f-python) is a multi-arch manifest supporting both amd64 and arm64dbcce7f-python-amd64) are also available if needed