Repository navigation
fix(agent-server): report the uploaded file_size in the upload response - #5856
Conversation
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
Coverage Report •
|
||||||||||||||||||||
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
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 checkreports 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
all-hands-bot
left a comment
There was a problem hiding this comment.
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/initauth and trajectory download paths). I reproduced it on the base commit5fa4deain 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
mainalready 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
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 (newFileUploadResult(Success)response model). The change is additive; clients that read onlysuccesskeep working, and the SDK and TypeScript remote workspaces already readfile_size.Why
POST /api/file/upload(global and conversation-scoped) answered only{"success": true}, but the SDK'sRemoteWorkspace.file_uploadand the TypeScriptRemoteWorkspace.fileUploadcopy afile_sizefrom that response. The SDK therefore reportedfile_size=None, the TypeScript clientundefined, and the TypeScriptwrite_filetool told the modelSuccessfully wrote undefined bytes.LocalWorkspace.file_uploadreports the real size.Summary
_upload_filecounts the bytes it streams to disk and returns them asfile_size; both upload routes share it.tests/agent_server/test_file_router.pyasserts the size for a small upload, a chunked (>8 KiB) upload, and an overwrite.F14.upload-sizemap bullet drops its# bugmarker and "known bug" label, now also checksfile_sizeon the raw REST response, and its prose and Gotchas line describe the fixed behaviour.REST API contract changes
Compared with base OpenAPI
5fa4dea24c52for public/api/**paths.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 onmainand pass here.AGENT_SERVER_VERIFY_HOMEprivate,clients/typescriptbuilt withnpm ci && npm run buildin 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>:xfailin both attempts.--checkout):xpassin both attempts.control-agent-server map checkhas no problems, andmap run --file F14 --only F14.upload-size --freshreportspass.uv run pre-commit run --files <changed files>: all passed.Video/Screenshots
n/a
Type
Notes
clients/typescript/src/generated/agent-server-schema.ts) is pinned to the released 1.54.0 contract, so it picks upfile_sizeon its next regeneration; it is not hand-edited here._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
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:a30648c-pythonRun
All tags pushed for this build
About Multi-Architecture Support
a30648c-python) is a multi-arch manifest supporting both amd64 and arm64a30648c-python-amd64) are also available if needed