Skip to content

fix(sdk): fall back when the output directory cannot be created - #6634

Merged
VascoSch92 merged 2 commits into
mainfrom
vasco/truncate-save-dir-fallback
Nov 9, 2026
Merged

VascoSch92 merged 2 commits into
mainfrom
vasco/truncate-save-dir-fallback

Conversation

@VascoSch92

@VascoSch92 VascoSch92 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

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_content only guarded write_text; the mkdir ran outside the error handler.

This carries over #6220 by Suyash Bhattarai unchanged. That branch conflicts with main's parametrized test_truncate.py and does not allow pushes from maintainers, so this branch adds one merge commit that keeps main's tests and re-adds the new one.

Summary

  • Move the directory creation into the existing error handler, so a failed save falls back to plain truncation.
  • Test an existing file at the save path and in its parent path.

Issue Number

Fixes #6219. Part of #6348.

How to Test

uv run pytest tests/sdk/utils/test_truncate.py -q

22 passed. The pinned test_maybe_truncate_unusable_save_dir_falls_back_to_plain_notice from the edge-case branch reports XPASS(strict) on this head.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

🐳 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

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python-slim amd64, arm64 python-node-runtime Link
python-minimal amd64, arm64 python-node-runtime Link
python amd64, arm64 python-node-runtime Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:dbcce7f-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-dbcce7f-python \
  ghcr.io/openhands/agent-server:dbcce7f-python

All tags pushed for this build

ghcr.io/openhands/agent-server:dbcce7f-golang-amd64
ghcr.io/openhands/agent-server:dbcce7f47ee14ca2622f481f1daf38c53ddb8162-golang-amd64
ghcr.io/openhands/agent-server:vasco-truncate-save-dir-fallback-golang-amd64
ghcr.io/openhands/agent-server:dbcce7f-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:dbcce7f-golang-arm64
ghcr.io/openhands/agent-server:dbcce7f47ee14ca2622f481f1daf38c53ddb8162-golang-arm64
ghcr.io/openhands/agent-server:vasco-truncate-save-dir-fallback-golang-arm64
ghcr.io/openhands/agent-server:dbcce7f-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:dbcce7f-java-amd64
ghcr.io/openhands/agent-server:dbcce7f47ee14ca2622f481f1daf38c53ddb8162-java-amd64
ghcr.io/openhands/agent-server:vasco-truncate-save-dir-fallback-java-amd64
ghcr.io/openhands/agent-server:dbcce7f-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:dbcce7f-java-arm64
ghcr.io/openhands/agent-server:dbcce7f47ee14ca2622f481f1daf38c53ddb8162-java-arm64
ghcr.io/openhands/agent-server:vasco-truncate-save-dir-fallback-java-arm64
ghcr.io/openhands/agent-server:dbcce7f-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:dbcce7f-python-amd64
ghcr.io/openhands/agent-server:dbcce7f47ee14ca2622f481f1daf38c53ddb8162-python-amd64
ghcr.io/openhands/agent-server:vasco-truncate-save-dir-fallback-python-amd64
ghcr.io/openhands/agent-server:dbcce7f-python-node-runtime-amd64
ghcr.io/openhands/agent-server:dbcce7f-python-arm64
ghcr.io/openhands/agent-server:dbcce7f47ee14ca2622f481f1daf38c53ddb8162-python-arm64
ghcr.io/openhands/agent-server:vasco-truncate-save-dir-fallback-python-arm64
ghcr.io/openhands/agent-server:dbcce7f-python-node-runtime-arm64
ghcr.io/openhands/agent-server:dbcce7f-python-minimal-amd64
ghcr.io/openhands/agent-server:dbcce7f47ee14ca2622f481f1daf38c53ddb8162-python-minimal-amd64
ghcr.io/openhands/agent-server:vasco-truncate-save-dir-fallback-python-minimal-amd64
ghcr.io/openhands/agent-server:dbcce7f-python-node-runtime-minimal-amd64
ghcr.io/openhands/agent-server:dbcce7f-python-minimal-arm64
ghcr.io/openhands/agent-server:dbcce7f47ee14ca2622f481f1daf38c53ddb8162-python-minimal-arm64
ghcr.io/openhands/agent-server:vasco-truncate-save-dir-fallback-python-minimal-arm64
ghcr.io/openhands/agent-server:dbcce7f-python-node-runtime-minimal-arm64
ghcr.io/openhands/agent-server:dbcce7f-python-slim-amd64
ghcr.io/openhands/agent-server:dbcce7f47ee14ca2622f481f1daf38c53ddb8162-python-slim-amd64
ghcr.io/openhands/agent-server:vasco-truncate-save-dir-fallback-python-slim-amd64
ghcr.io/openhands/agent-server:dbcce7f-python-node-runtime-slim-amd64
ghcr.io/openhands/agent-server:dbcce7f-python-slim-arm64
ghcr.io/openhands/agent-server:dbcce7f47ee14ca2622f481f1daf38c53ddb8162-python-slim-arm64
ghcr.io/openhands/agent-server:vasco-truncate-save-dir-fallback-python-slim-arm64
ghcr.io/openhands/agent-server:dbcce7f-python-node-runtime-slim-arm64
ghcr.io/openhands/agent-server:dbcce7f-golang
ghcr.io/openhands/agent-server:dbcce7f47ee14ca2622f481f1daf38c53ddb8162-golang
ghcr.io/openhands/agent-server:vasco-truncate-save-dir-fallback-golang
ghcr.io/openhands/agent-server:dbcce7f-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:dbcce7f-java
ghcr.io/openhands/agent-server:dbcce7f47ee14ca2622f481f1daf38c53ddb8162-java
ghcr.io/openhands/agent-server:vasco-truncate-save-dir-fallback-java
ghcr.io/openhands/agent-server:dbcce7f-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:dbcce7f-python-minimal
ghcr.io/openhands/agent-server:dbcce7f47ee14ca2622f481f1daf38c53ddb8162-python-minimal
ghcr.io/openhands/agent-server:vasco-truncate-save-dir-fallback-python-minimal
ghcr.io/openhands/agent-server:dbcce7f-python-node-runtime-minimal
ghcr.io/openhands/agent-server:dbcce7f-python-slim
ghcr.io/openhands/agent-server:dbcce7f47ee14ca2622f481f1daf38c53ddb8162-python-slim
ghcr.io/openhands/agent-server:vasco-truncate-save-dir-fallback-python-slim
ghcr.io/openhands/agent-server:dbcce7f-python-node-runtime-slim
ghcr.io/openhands/agent-server:dbcce7f-python
ghcr.io/openhands/agent-server:dbcce7f47ee14ca2622f481f1daf38c53ddb8162-python
ghcr.io/openhands/agent-server:vasco-truncate-save-dir-fallback-python
ghcr.io/openhands/agent-server:dbcce7f-python-node-runtime

About Multi-Architecture Support

  • Each variant tag (e.g., dbcce7f-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., dbcce7f-python-amd64) are also available if needed

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
TOTAL54583849984% 
report-only-changed-files is enabled. No changed files were found in the coverage report :)

@all-hands-bot all-hands-bot 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.

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>) raises FileExistsError.
  • 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 in tests/sdk/utils/test_truncate.py).
  • tests/tools/terminal/test_observation_truncation.py (5 passed) and tests/tools/file_editor (78 passed) — the main save_dir consumers (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

@VascoSch92
VascoSch92 merged commit 41d849f into main Nov 9, 2026
51 checks passed
@VascoSch92
VascoSch92 deleted the vasco/truncate-save-dir-fallback branch November 9, 2026 07:57
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.

Output truncation raises when the save directory cannot be created

3 participants