Skip to content

fix(agent-server): report the uploaded file_size in the upload response - #5856

Merged
enyst merged 2 commits into
mainfrom
claude/umbrella-bug-fixes-tgz9ai-upload-file-size
Oct 17, 2026
Merged

enyst merged 2 commits into
mainfrom
claude/umbrella-bug-fixes-tgz9ai-upload-file-size

Conversation

@enyst

@enyst enyst commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

HUMAN:
This PR proposes a fix for a bug uncovered during the first full agentic run of verify-agent-server.


AGENT:

I'm an AI agent (Claude Code) helping Engel Nyst (@enyst) with project maintenance.

Requested by Engel · project thread

Decision

Engel chose server-reported size: the upload routes answer {"success": true, "file_size": N} with the bytes the server actually wrote (new FileUploadResult(Success) response model). The change is additive; clients that read only success keep working, and the SDK and TypeScript remote workspaces already read file_size.

Why

POST /api/file/upload (global and conversation-scoped) answered only {"success": true}, but the SDK's RemoteWorkspace.file_upload and the TypeScript RemoteWorkspace.fileUpload copy a file_size from that response. The SDK therefore reported file_size=None, the TypeScript client undefined, and the TypeScript write_file tool told the model Successfully wrote undefined bytes. LocalWorkspace.file_upload reports the real size.

Summary

  • _upload_file counts the bytes it streams to disk and returns them as file_size; both upload routes share it.
  • tests/agent_server/test_file_router.py asserts the size for a small upload, a chunked (>8 KiB) upload, and an overwrite.
  • The F14.upload-size map bullet drops its # bug marker and "known bug" label, now also checks file_size on the raw REST response, and its prose and Gotchas line describe the fixed behaviour.

REST API contract changes

Compared with base OpenAPI 5fa4dea24c52 for public /api/** paths.

--- base public OpenAPI
+++ head public OpenAPI
@@ -731 +731 @@
-response POST /api/conversations/{runtime_conversation_id}/file/upload 200 application/json schema=Success
+response POST /api/conversations/{runtime_conversation_id}/file/upload 200 application/json schema=FileUploadResult
@@ -735 +735 @@
-response POST /api/file/upload 200 application/json schema=Success
+response POST /api/file/upload 200 application/json schema=FileUploadResult
@@ -1685,0 +1686,3 @@
+schema FileUploadResult property file_size required schema=type="integer"
+schema FileUploadResult property success optional schema=type="boolean" default=true
+schema FileUploadResult type="object"

Issue Number

Fixes #5836

How to Test

  • uv run pytest -q tests/agent_server/test_file_router.py tests/sdk/workspace/remote: 238 passed, 1 skipped. The three updated upload tests fail on main and pass here.
  • Map proof (AGENT_SERVER_VERIFY_HOME private, clients/typescript built with npm ci && npm run build in both checkouts; the TypeScript source is unchanged):
    • control-agent-server map run --file F14 --only F14.upload-size --fresh --repeat 2 --checkout <main at 6e7a853>: xfail in both attempts.
    • The same command from this branch (without --checkout): xpass in both attempts.
    • With the marker removed: control-agent-server map check has no problems, and map run --file F14 --only F14.upload-size --fresh reports pass.
  • uv run pre-commit run --files <changed files>: all passed.

Video/Screenshots

n/a

Type

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

Notes

  • The TypeScript generated schema (clients/typescript/src/generated/agent-server-schema.ts) is pinned to the released 1.54.0 contract, so it picks up file_size on its next regeneration; it is not hand-edited here.
  • Two follow-ups from the same umbrella (Agent Server bugs found by the verify-agent-server feature map (umbrella) #5653) also touch _upload_file: atomic replace via a temp file, and a 4xx instead of a masked 500 for uploads onto a directory. This change only counts the bytes written so both can follow cleanly.

🤖 Generated with Claude Code

https://claude.ai/code/session_014MKndVj7XWvRQmvW9w2bDg


Generated by Claude Code


🐳 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:a30648c-python

Run

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

All tags pushed for this build

ghcr.io/openhands/agent-server:a30648c-golang-amd64
ghcr.io/openhands/agent-server:a30648c2e7e2afc4d820f863dadf2243d4f9d295-golang-amd64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-upload-file-size-golang-amd64
ghcr.io/openhands/agent-server:a30648c-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:a30648c-golang-arm64
ghcr.io/openhands/agent-server:a30648c2e7e2afc4d820f863dadf2243d4f9d295-golang-arm64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-upload-file-size-golang-arm64
ghcr.io/openhands/agent-server:a30648c-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:a30648c-java-amd64
ghcr.io/openhands/agent-server:a30648c2e7e2afc4d820f863dadf2243d4f9d295-java-amd64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-upload-file-size-java-amd64
ghcr.io/openhands/agent-server:a30648c-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:a30648c-java-arm64
ghcr.io/openhands/agent-server:a30648c2e7e2afc4d820f863dadf2243d4f9d295-java-arm64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-upload-file-size-java-arm64
ghcr.io/openhands/agent-server:a30648c-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:a30648c-python-amd64
ghcr.io/openhands/agent-server:a30648c2e7e2afc4d820f863dadf2243d4f9d295-python-amd64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-upload-file-size-python-amd64
ghcr.io/openhands/agent-server:a30648c-python-node-runtime-amd64
ghcr.io/openhands/agent-server:a30648c-python-arm64
ghcr.io/openhands/agent-server:a30648c2e7e2afc4d820f863dadf2243d4f9d295-python-arm64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-upload-file-size-python-arm64
ghcr.io/openhands/agent-server:a30648c-python-node-runtime-arm64
ghcr.io/openhands/agent-server:a30648c-python-minimal-amd64
ghcr.io/openhands/agent-server:a30648c2e7e2afc4d820f863dadf2243d4f9d295-python-minimal-amd64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-upload-file-size-python-minimal-amd64
ghcr.io/openhands/agent-server:a30648c-python-node-runtime-minimal-amd64
ghcr.io/openhands/agent-server:a30648c-python-minimal-arm64
ghcr.io/openhands/agent-server:a30648c2e7e2afc4d820f863dadf2243d4f9d295-python-minimal-arm64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-upload-file-size-python-minimal-arm64
ghcr.io/openhands/agent-server:a30648c-python-node-runtime-minimal-arm64
ghcr.io/openhands/agent-server:a30648c-python-slim-amd64
ghcr.io/openhands/agent-server:a30648c2e7e2afc4d820f863dadf2243d4f9d295-python-slim-amd64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-upload-file-size-python-slim-amd64
ghcr.io/openhands/agent-server:a30648c-python-node-runtime-slim-amd64
ghcr.io/openhands/agent-server:a30648c-python-slim-arm64
ghcr.io/openhands/agent-server:a30648c2e7e2afc4d820f863dadf2243d4f9d295-python-slim-arm64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-upload-file-size-python-slim-arm64
ghcr.io/openhands/agent-server:a30648c-python-node-runtime-slim-arm64
ghcr.io/openhands/agent-server:a30648c-golang
ghcr.io/openhands/agent-server:a30648c2e7e2afc4d820f863dadf2243d4f9d295-golang
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-upload-file-size-golang
ghcr.io/openhands/agent-server:a30648c-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:a30648c-java
ghcr.io/openhands/agent-server:a30648c2e7e2afc4d820f863dadf2243d4f9d295-java
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-upload-file-size-java
ghcr.io/openhands/agent-server:a30648c-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:a30648c-python-minimal
ghcr.io/openhands/agent-server:a30648c2e7e2afc4d820f863dadf2243d4f9d295-python-minimal
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-upload-file-size-python-minimal
ghcr.io/openhands/agent-server:a30648c-python-node-runtime-minimal
ghcr.io/openhands/agent-server:a30648c-python-slim
ghcr.io/openhands/agent-server:a30648c2e7e2afc4d820f863dadf2243d4f9d295-python-slim
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-upload-file-size-python-slim
ghcr.io/openhands/agent-server:a30648c-python-node-runtime-slim
ghcr.io/openhands/agent-server:a30648c-python
ghcr.io/openhands/agent-server:a30648c2e7e2afc4d820f863dadf2243d4f9d295-python
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-upload-file-size-python
ghcr.io/openhands/agent-server:a30648c-python-node-runtime

About Multi-Architecture Support

  • Each variant tag (e.g., a30648c-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., a30648c-python-amd64) are also available if needed

POST /api/file/upload (global and conversation-scoped) answered only
{"success": true}, while the SDK's RemoteWorkspace.file_upload and the
TypeScript RemoteWorkspace.fileUpload copy a file_size from it, so they
reported None / undefined (the TypeScript write_file tool said
"wrote undefined bytes"). The handler now counts the bytes it writes and
returns {"success": true, "file_size": N}, an additive response change.
The F14.upload-size map bullet drops its known-bug marker.

Fixes #5836

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014MKndVj7XWvRQmvW9w2bDg
@enyst enyst self-assigned this Oct 14, 2026
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-agent-server/openhands/agent_server
   file_router.py4527484%130–132, 168–170, 220–222, 327, 330–331, 338–339, 377, 379–381, 430, 474–477, 483–485, 491–493, 505–506, 543, 611–613, 618, 622–624, 666–667, 676, 683, 704–706, 763–765, 792–793, 797–798, 806, 808–813, 816–818, 902–903, 907–908, 1093–1095, 1099–1102
TOTAL502642004060% 

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@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

In scope for this repository: the change is confined to the Python Agent Server (file_router.py, models.py), its canonical OpenAPI response contract, its regression tests, and the repo-owned verify-agent-server feature map. It is an additive, backward-compatible REST response change (Success to FileUploadResult(Success) with an added file_size), so no product/architecture decision is needed.

Assessment

The fix is correct and minimal. _upload_file now accumulates len(chunk) over the same chunks it writes and returns FileUploadResult(file_size=...); the byte count therefore reflects exactly what the server wrote. Both upload entry points share this helper: the global POST /api/file/upload and the conversation-scoped POST /api/conversations/{runtime_conversation_id}/file/upload (the latter mounts the same file_router via create_runtime_router), so both routes report the size as the PR claims. FileUploadResult subclasses Success, keeping success: true and remaining additive for clients that read only success.

Consumers already read the field they were promised: RemoteWorkspace._file_upload_generator / AsyncRemoteWorkspace.file_upload (remote_workspace_mixin.py:336, result_data.get("file_size")) and the TypeScript RemoteWorkspace.fileUpload (remote-workspace.ts:177), whose write_file tool reports the byte count. No other path drops or renames the field.

Verified on this head:

  • uv run pytest -q tests/agent_server/test_file_router.py — 92 passed (the three updated assertions cover a small upload, a chunked >8 KiB upload, and an overwrite).
  • uv run pytest -q tests/sdk/workspace/remote — 147 passed.
  • uv run pytest -q tests/agent_server/test_openapi_contract.py tests/agent_server/test_openapi_discriminator.py — 13 passed.
  • Exported OpenAPI and ran the weak-schema ratchet: Agent Server OpenAPI type-quality check passed; control-agent-server map check reports no problems.
  • Current-head GitHub Actions: all check runs completed successfully on b8ef70a.

The linked issue #5836 is bug / priority:low / ready-for-dev and remains open; this PR is the corresponding fix. The production-facing evidence checkpoint is satisfied: the PR reports the F14.upload-size map recipe failing (xfail) twice on the base and passing (xpass) twice on this head through the real REST, SDK, and TypeScript entry points.

Non-blocking note

The PR updates F14-files.md, but the same skill still carries a now-stale statement in .agents/skills/verify-agent-server/references/feature-map/F33-sdk-remote-client.md:1988 ("file_upload reports file_size: null (the server answers only {"success": true})"). That sentence is no longer true on this head and the F33 map gotcha will mislead the next verifier. It is a doc-consistency item, not a code defect, so it does not block merge — a short follow-up edit is enough.

No material correctness, security, or compatibility findings.

✅ APPROVED

…-size

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S978x74H7Drsnw7bzoGWc8
@enyst
enyst merged commit af05c8b into main Oct 17, 2026
51 checks passed
@enyst
enyst deleted the claude/umbrella-bug-fixes-tgz9ai-upload-file-size branch October 17, 2026 03:26
@neubig
neubig requested a review from all-hands-bot October 19, 2026 09:36

@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

In scope for this repository: the change touches only the Python Agent Server (file_router.py, models.py), its canonical OpenAPI response contract, its regression tests, and the repo-owned verify-agent-server feature map. It is an additive, backward-compatible REST response change (Success to FileUploadResult(Success) with an added file_size), so no product/architecture decision is required.

Assessment

Re-reviewed at the current head a30648c, which merged main (base moved to 5fa4dea) since my prior review at b8ef70a. The fix is intact and correct on this head.

_upload_file accumulates len(chunk) over the same chunks it writes and returns FileUploadResult(file_size=file_size) (file_router.py:112). Both upload entry points share this helper, so the global POST /api/file/upload and the conversation-scoped POST /api/conversations/{runtime_conversation_id}/file/upload report the bytes the server actually wrote. FileUploadResult subclasses Success (models.py:447), keeping success: true and remaining additive for clients that read only success.

Consumers already read the field they were promised: RemoteWorkspace._file_upload_generator / AsyncRemoteWorkspace.file_upload (remote_workspace_mixin.py:336, result_data.get("file_size")) and the TypeScript RemoteWorkspace.fileUpload (remote-workspace.ts:177). No path drops or renames the field.

Verified on this head:

  • uv run pytest -q tests/agent_server/test_file_router.py tests/sdk/workspace/remote — 243 passed, 1 failed. The single failure, test_deferred_init_trajectory_downloads_follow_init_conversations_path, is not part of this PR's diff (it exercises /api/init auth and trajectory download paths). I reproduced it on the base commit 5fa4dea in a clean worktree, so it is pre-existing and unrelated to this change. The three updated upload assertions (small upload, chunked >8 KiB, overwrite) pass.
  • Current-head GitHub Actions on a30648c: all check runs completed successfully.
  • The merged main already carries the follow-up 4xx handling for uploads onto a directory (#5931); the byte-count logic here is unaffected and the two compose cleanly.

The linked issue #5836 (bug, priority:low) is closed, and this PR is merged; the change matches its acceptance criterion (server-reported file_size).

Non-blocking note

The PR updates F14-files.md, but the same skill still carries a now-stale statement in .agents/skills/verify-agent-server/references/feature-map/F33-sdk-remote-client.md:1988 ("file_upload reports file_size: null (the server answers only {"success": true})"). That line is pre-existing (present on base 5fa4dea) and not part of this PR's diff, so it is out of scope here, but it is now factually wrong and will mislead the next verifier — worth a short follow-up edit.

No material correctness, security, or compatibility findings.

✅ APPROVED

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.

[Bug]: File upload responds only {"success": true}, so the SDK and TypeScript remote workspaces report no file_size

3 participants