Skip to content

feat(app-conversations): serve workspace files as bytes with MIME type and typed errors - #1233

Open
openhands-agent wants to merge 2 commits into
mainfrom
dev-coordinator/852-file-bytes-transport
Open

openhands-agent wants to merge 2 commits into
mainfrom
dev-coordinator/852-file-bytes-transport

Conversation

@openhands-agent

@openhands-agent openhands-agent commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

In plain words

OSS: The file viewer opens any file, including images and PDFs, and shows an error when one fails to load.
OHE: Files that are not plain text can arrive garbled, and a file that fails to load shows up empty.

HUMAN:

  • [ x] A human, I Juan, has tested these changes manually.

AGENT:


Why

Canvas reads cloud workspace files through GET /api/v1/app-conversations/{id}/file. That route decodes the bytes as UTF-8 and returns '' for every failure. So PNG and PDF previews break, and "file missing", "sandbox paused" and "runtime down" all look like an empty file. Canvas currently has to sniff NUL bytes as a workaround (use-workspace-file-content.ts). The gap inventory on saas-deploy#1847 (gap:canvas-cloud/file-transport) names the boundary: a /file response that keeps the bytes and the MIME type.

Summary

  • GET /app-conversations/{id}/file/download?file_path=&repository=: takes the same parameters as /file and returns the file bytes unchanged, with a Content-Type guessed from the file name (Python's built-in table) and Content-Disposition: attachment (RFC 5987 encoded). An empty file returns 200 with an empty body. Failures return {"code", "error"}, and each one has its own code: conversation_not_found / sandbox_not_found / repository_not_found / file_not_found (404), invalid_path (400), sandbox_paused (409), sandbox_not_ready / sandbox_unreachable (503), upstream_error (502). The response never echoes upstream bodies or exception text, so runtime keys cannot leak.
  • GET /app-conversations/{id}/raw/{path}: the stable asset base for rich previews. path is relative to the sandbox working dir, so the repository is part of the path (raw/<repo-folder>/site/index.html). A relative style.css link then resolves to the same route and uses the same cookie session, with no runtime key in the URL. The response is inline, with Content-Security-Policy: sandbox allow-same-origin; frame-ancestors 'self' and nosniff. Scripts, forms and plugins never run, even when the file is opened in a new window. ., .. or empty segments, backslashes and NUL are rejected before the runtime is called.
  • /file is marked deprecated in OpenAPI and its docstring points to /file/download. Its behavior is unchanged so the pinned Canvas keeps working until it migrates.
  • Two middleware fixes the new routes need:
    • SecurityHeadersMiddleware used to overwrite any route CSP. That would have dropped the sandbox, and HTML from a repository would have run inline scripts on the app origin. It now adds the default policy as a second header, and the browser enforces both.
    • CacheControlMiddleware treated any path containing assets/ as a public, immutable fingerprinted asset, and that included /api/.../raw/repo/assets/logo.png. /api/ paths are now excluded.
  • Unblocks preview verification (fix for a main regression): server/rate_limit.py now builds the limits Redis storage with implementation='redispy'. Since the coredis 4.24 → 6.9 bump (chore(deps): bump coredis from 4.24.0 to 6.9.0 #1040), the limits 5.8 coredis bridge never enters the coredis pool's async context. Every auth_uid hit raised Connection pool is not initialized, the error was swallowed, and a pool slot leaked. After 64 authenticated requests per pod, every request with a valid session blocked forever. This is why the previews for this PR (and for fix(conversation-card): open VS Code URL with noopener and http(s) only #1165 and feat(app-conversations): add managed conversation forks (Branch from here) #1232) hung after the first smoke run. redis-py is the client the rest of the app already uses. A new test in tests/unit/server/test_rate_limit.py runs 100 hits against a real password-protected Redis container and checks that the window is enforced. Without the fix it times out on hit 65.
  • Refactor: _get_agent_server_context now wraps a new _resolve_agent_server_context that raises a typed _AgentServerUnavailable(code). The status codes of the existing callers do not change.
Canvas ──GET /file/download?file_path=docs/logo.png──▶ app server ──GET /api/file/download?path=/workspace/<repo>/docs/logo.png (X-Session-API-Key)──▶ runtime
       ◀── 200 image/png <bytes> | 4xx/5xx {"code": ..., "error": ...} ──

Issue Number

Closes #852

How to Test

Unit tests (real FastAPI app + real httpx.AsyncClient with a MockTransport fake runtime; only conversation/sandbox services are mocked):

uv run pytest tests/unit/app_server/test_app_conversation_file_transport.py \
  tests/unit/server/test_rate_limit.py \
  tests/unit/app_server/test_security_headers_middleware.py \
  tests/unit/app_server/test_cache_control_middleware.py \
  tests/unit/app_server/test_rate_limit_middleware.py \
  tests/unit/app_server/test_app_conversation_router.py \
  tests/unit/app_server/test_app_conversation_skills_endpoint.py \
  tests/unit/app_server/test_app_conversation_hooks_endpoint.py \
  tests/unit/app_server/test_app_conversation_repository_selector.py \
  tests/unit/app_server/test_send_message_endpoint.py \
  tests/unit/server/routes/test_service_account_guard.py

All of these pass locally (211 router-related tests and 66 middleware/transport tests), and the pre-commit hooks (ruff, ruff format, mypy) pass too. The coverage includes PNG/PDF/arbitrary-binary sha256 round trips, a zero-byte file, a non-ASCII and quoted file name, every error code, a conversation from another tenant (it returns 404 and never reaches the runtime), upstream 401/403/500 bodies with the key in them (redacted to 502), a connection error (503), path-escape attempts, and resolution of the relative asset base.

How to verify on a preview

Use an authorized test user. Steps 2–6 can run in the browser devtools console on the app origin, where the session cookie authenticates, or with curl -H "Authorization: Bearer $OPENHANDS_API_KEY".

  1. Start a conversation on a repository (e.g. OpenHands/enterprise, folder enterprise) and wait for it to be running. Ask the agent: "Run: mkdir -p site && printf 'body{color:red}' > site/style.css && printf '<link rel=stylesheet href=style.css><h1>hi</h1><script>document.title=\"PWNED\"</script>' > site/index.html && python3 -c \"import zlib,struct;r=b'\\x00\\xff\\x00\\x00';d=zlib.compress(r);c=lambda t,b:struct.pack('>I',len(b))+t+b+struct.pack('>I',zlib.crc32(t+b));open('site/dot.png','wb').write(b'\\x89PNG\\r\\n\\x1a\\n'+c(b'IHDR',struct.pack('>IIBBBBB',1,1,8,2,0,0,0))+c(b'IDAT',d)+c(b'IEND',b''))\" && : > site/empty.txt && sha256sum site/dot.png". Note the sha256 and the conversation id $ID.
  2. Bytes + MIME: GET /api/v1/app-conversations/$ID/file/download?file_path=site/dot.png → 200, content-type: image/png, content-disposition: attachment; filename="dot.png"; .... The sha256 of the body (sha256sum on the curl output, or crypto.subtle.digest('SHA-256', await r.arrayBuffer())) equals the one from step 1.
  3. Empty file: GET .../file/download?file_path=site/empty.txt → 200, body length 0.
  4. Errors: GET .../file/download?file_path=site/nope.png → 404 {"code":"file_not_found",...}. GET /api/v1/app-conversations/<random-uuid>/file/download?file_path=x → 404 {"code":"conversation_not_found",...}. Pause the conversation's sandbox (POST /api/v1/sandboxes/<sandbox_id>/pause), then repeat step 2 → 409 {"code":"sandbox_paused",...}. Resume it afterwards. No error body contains a session key.
  5. Asset base, no scripts: open https://<preview-host>/api/v1/app-conversations/$ID/raw/enterprise/site/index.html in a new tab. The heading "hi" shows in red, which means style.css loaded through /raw/ with the same cookie. The tab title is not PWNED, and the console shows the script blocked by CSP sandbox. The response headers include content-security-policy: sandbox allow-same-origin; frame-ancestors 'self' (plus the default policy as a second header) and x-content-type-options: nosniff.
  6. Path escape: GET .../raw/enterprise/%2E%2E/%2E%2E/etc/passwd → 400 {"code":"invalid_path",...}.
  7. Legacy: GET .../file?file_path=site/style.css still returns the JSON string "body{color:red}", so the current Canvas Files tab keeps working.

Expected verdict: all seven pass.

Video/Screenshots

home
reply
raw preview

details

Type

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

Notes

  • Follow-ups outside this repo (from [OSS→OHE parity] Preserve file bytes, MIME and errors through tenant file transport #852's acceptance list): publish typed download/raw helpers in the SDK CloudClient (software-agent-sdk#6079), then migrate Canvas use-workspace-file-content.ts off /file and its NUL-sniff to /file/download for bytes and /raw/<folder>/<path> for staticUrl previews (OpenHands#15752). /file can be removed after that.
  • Symlinks: containment is lexical (no ..). The runtime follows symlinks inside the conversation's own sandbox, and the owning user already has shell access there. Tenant isolation comes from get_app_conversation being scoped to the caller's user and org, so another org's conversation id returns 404 before the runtime is contacted.
  • Session expiry and revocation for /raw/ assets follow the normal app session cookie or API key. No new token type is added.
  • Responses are buffered, not streamed, like the existing /file endpoint.

This PR was created by an AI agent (OpenHands dev-coordinator) on behalf of the user.


Enterprise server image for this PR:

ghcr.io/openhands/enterprise-server:sha-514c651

Add GET /app-conversations/{id}/file/download (attachment) and
GET /app-conversations/{id}/raw/{path} (inline, stable asset base for
previews). Both keep bytes intact, guess Content-Type from the name, send
nosniff and a sandbox CSP that blocks scripts, and return {code, error}
with distinct statuses instead of an empty string. Deprecate /file.

SecurityHeadersMiddleware now keeps a route's own CSP next to the default,
and CacheControlMiddleware no longer treats /api/ paths with an assets/
folder as public fingerprinted assets.

Closes #852

Co-authored-by: openhands <openhands@all-hands.dev>
@openhands-agent openhands-agent added the verify-this Triggers Preview Verification on https://app.beta.staging.all-hands-testing.dev/canvas/automations/ label Nov 6, 2026
@all-hands-bot

all-hands-bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Review posted for 514c65134554

Verdict: ✅ APPROVED. See the review.

This is an automated status.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  openhands/app_server
  middleware.py 176-186, 239
  openhands/app_server/app_conversation
  app_conversation_router.py 266, 276, 283, 1312, 1464, 1472-1476, 1489-1525, 1567-1580, 1606-1627
  server
  rate_limit.py
Project Total  

This report was generated by python-coverage-comment-action

@openhands-agent openhands-agent changed the title Serve conversation workspace files as bytes with MIME type and typed errors feat(app-conversations): serve workspace files as bytes with MIME type and typed errors Nov 6, 2026
@github-actions github-actions Bot added the type: feat A new feature label Nov 6, 2026
@openhands-agent
openhands-agent requested review from all-hands-bot and removed request for all-hands-bot November 6, 2026 04:30
@openhands-agent openhands-agent added verify-this Triggers Preview Verification on https://app.beta.staging.all-hands-testing.dev/canvas/automations/ and removed verify-this Triggers Preview Verification on https://app.beta.staging.all-hands-testing.dev/canvas/automations/ labels Nov 6, 2026
@openhands-agent

Copy link
Copy Markdown
Contributor Author

Fixed the failing pr-title / Lint PR title (conventional) check. I renamed the PR to a Conventional Commits title: feat(app-conversations): serve workspace files as bytes with MIME type and typed errors. I made no code changes, so the head stays at 92f3af7. All CI checks pass now. I requested a new review from all-hands-bot and re-applied verify-this to start a preview verification. There were no review threads and no earlier verification evidence on this head, so there was nothing else to address.

This comment was posted by an AI agent (OpenHands dev-coordinator) on behalf of the user.

@all-hands-bot all-hands-bot left a comment •

Copy link
Copy Markdown
Contributor

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).

This PR implements byte-preserving file transport with proper MIME types and typed error handling for workspace files. The implementation is well-designed and thoroughly tested.

Technical Review

Architecture:

  • Two new endpoints cleanly separate download (/file/download) and preview (/raw/{path}) concerns
  • Typed error handling with distinct codes for each failure case prevents silent failures
  • Legacy /file endpoint properly deprecated with clear migration path

Security:

  • ✅ CSP headers correctly applied (sandbox allow-same-origin) to prevent script execution
  • ✅ Path validation rejects directory traversal attempts (., .., backslashes, NUL bytes)
  • ✅ Error responses never echo upstream bodies or exception text, preventing session key leakage
  • ✅ X-Content-Type-Options: nosniff prevents MIME sniffing attacks

Middleware Fixes:

  • ✅ Critical fix: SecurityHeadersMiddleware now appends CSP policies instead of overwriting them (lines 178-183). This ensures route-specific CSP policies survive alongside the default policy.
  • ✅ Cache fix: CacheControlMiddleware excludes /api/ paths via negative lookahead regex ^(?!/api/), correctly preventing workspace files in assets/ folders from being cached as public assets.

Testing:

  • Comprehensive unit tests cover binary files (PNG, PDF, arbitrary bytes), empty files, error codes, path escapes, non-ASCII filenames, and both middleware fixes
  • Tests use real FastAPI app with mock runtime transport, exercising actual routing and header handling

Code Quality:

  • Well-documented with clear docstrings
  • Proper error handling with typed exceptions
  • RFC 5987-compliant Content-Disposition encoding for non-ASCII filenames
  • MIME type detection uses Python's built-in table (deterministic across hosts)

All CI checks pass. The implementation meets the acceptance criteria from issue #852.

✅ APPROVED

LLM profile: sonnet-4-5 · Model: openhands/claude-sonnet-4-5-20250929

@juanmichelini

Copy link
Copy Markdown
Contributor

Preview verification finished: FAIL. Evidence: https://github.com/OpenHands/saas-deploy/pull/2032#issuecomment-6677210617

This comment was posted by an AI agent (OpenHands) on behalf of the user.

@juanmichelini juanmichelini removed the verify-this Triggers Preview Verification on https://app.beta.staging.all-hands-testing.dev/canvas/automations/ label Nov 6, 2026
limits 5.8's coredis bridge never enters the coredis>=5 connection-pool
context, so after the coredis 6.9 bump every auth_uid hit raised
'Connection pool is not initialized', was swallowed, and leaked a pool
slot. After 64 failures every request with a valid session blocked
forever, which hung the preview used to verify this PR.

Co-authored-by: openhands <openhands@all-hands.dev>
@openhands-agent
openhands-agent marked this pull request as ready for review November 6, 2026 06:25
@openhands-agent openhands-agent added the verify-this Triggers Preview Verification on https://app.beta.staging.all-hands-testing.dev/canvas/automations/ label Nov 6, 2026
@openhands-agent

Copy link
Copy Markdown
Contributor Author

The latest preview verification failed because every request with a valid session hung after the first smoke run. The hang was not in the file-transport code. Its cause is a regression on main, so I fixed it on this branch in 514c651.

Root cause. Datadog logs for the preview namespace showed exactly 64 Rate limit check could not complete, redis issue? errors from saas_user_auth.py (rate_limiter.hit('auth_uid', …)). Each error was RuntimeError: Connection pool is not initialized, raised from limits' coredis bridge. After those 64 errors, authenticated requests stopped completing. #1040 bumped coredis from 4.24 to 6.9. Since then, limits 5.8 never enters the coredis pool context, so every hit fails open and leaks a pool slot. On the 65th hit the pool is exhausted and the call blocks forever. I reproduced this locally against a real Redis. The previews for #1165 and #1232, which are built on the same main, hung the same way.

Fix. create_redis_rate_limiter now passes implementation='redispy' to limits, so the limiter uses the redis-py async client that the rest of the app already uses. A new test in tests/unit/server/test_rate_limit.py makes 100 hits against a real password-protected Redis container and checks that the limit is enforced. Without the fix, the test times out on hit 65.

I did not change the file-transport code. CI is green. I marked the PR ready for review, asked all-hands-bot for a new review and re-applied verify-this. The PR description now describes this extra change. A maintainer may want to cherry-pick 514c651 to main on its own, because the hang affects every deployment built from current main that has Redis rate limiting turned on.

This comment was posted by an AI agent (OpenHands dev-coordinator) on behalf of the user.

@all-hands-bot all-hands-bot left a comment •

Copy link
Copy Markdown
Contributor

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).

Changes Since Previous Review

My earlier approval of the file transport implementation (commit 92f3af7c) remains valid. This review covers only the new rate limiter fix added in commit 514c651.

Rate Limiter Fix (server/rate_limit.py)

Problem Identified:
The coredis 6.9 upgrade (#1040) broke the limits library's coredis bridge. The bridge never enters the pool's async context, causing:

  • Every rate limit check to fail open (leaking a connection)
  • After 64 leaked connections, all authenticated requests hang forever
  • Preview deployments became unusable after the first smoke test

Solution:
✅ Switched to implementation='redispy' - uses the redis-py async client that the rest of the application already depends on
✅ Backward compatible - same interface, just a different underlying implementation
✅ Well-documented with inline comment explaining the root cause

Testing:
✅ Comprehensive regression test (test_redis_rate_limiter_counts_hits_against_real_redis):

  • Uses a real Redis container with password authentication
  • Makes 100 hits (exceeds connection pool size) to verify no hanging
  • Uses asyncio.wait_for(..., 5) timeout - test fails fast if requests hang
  • Verifies rate limiting actually works (101st request is rejected)
  • Verifies per-key isolation (different user can still make requests)

Impact:
This fixes a critical production regression on main that affects all deployments with Redis rate limiting enabled. The fix is minimal, well-tested, and restores the intended behavior.

All CI checks pass. The file transport implementation remains unchanged and approved.

✅ APPROVED

LLM profile: sonnet-4-5 · Model: openhands/claude-sonnet-4-5-20250929

@juanmichelini

Copy link
Copy Markdown
Contributor

Preview verification finished: PASS. Evidence: https://github.com/OpenHands/saas-deploy/pull/2041#issuecomment-6678966115

This comment was posted by an AI agent (OpenHands) on behalf of the user.

@juanmichelini juanmichelini removed the verify-this Triggers Preview Verification on https://app.beta.staging.all-hands-testing.dev/canvas/automations/ label Nov 6, 2026
@openhands-agent

Copy link
Copy Markdown
Contributor Author

Ready for human review, @juanmichelini: reviewed by all-hands-bot (APPROVED) and verified PASS on the head commit. Evidence: https://github.com/OpenHands/saas-deploy/pull/2041#issuecomment-6678966115. Assigned by dev-coordinator.

This comment was posted by an AI agent (OpenHands dev-coordinator) on behalf of the user.

@juanmichelini

Copy link
Copy Markdown
Contributor

Preview verification evidence (copied from https://github.com/OpenHands/saas-deploy/pull/2041#issuecomment-6678966115):


🔍 Preview Verification — PASS

PR: #2041 App: https://pr-2041.staging.all-hands.dev
Validates: #1233 (head 514c651) — /app-conversations/{id}/file/download returns file bytes + MIME type + typed errors; new sandboxed /raw/{path} asset route; CSP/cache middleware fixes; redis rate-limit fix
Timestamp: 2026-11-06T06:44:52Z
Run ID: 9d104b58-0627-4f40-9b6f-3375a75fb360

Result: PASS

Baseline smoke

Step Status Detail
preflight ✅ app reachable, 200
positive:login ✅ Keycloak login accepted
positive:home ✅ home screen + chat launcher visible
positive:backend ✅ /me 200, role=member
positive:reload ✅ login survived reload
positive:conversation ✅ conversation created (task-c492b3ac… → conversation cd1f3eac…)
positive:reply ✅ polled /api/v1/app-conversations?ids=…: sandbox RUNNING, execution_status finished after ~91s of polling; agent reply visible in conversation
negative:rejected ✅ wrong password rejected by Keycloak

Feature test — workspace file transport (bytes + MIME + typed errors)

Files were created in the sandbox by the agent following the PR's "How to verify" prompt (conversation had no repo connected, so files were in /tmp/site and copied to the sandbox working dir /workspace/project/site for the /raw checks). All API calls used the logged-in member browser session.

Step Status Intended effect Observed effect (how verified) Screenshot
Create fixtures (PNG, CSS, HTML, empty file) via agent ✅ files exist in sandbox agent ran command, finished; later downloads return the files setup
GET /file/download PNG bytes + MIME ✅ bytes unchanged, image/png, attachment 200, content-type: image/png, content-disposition: attachment; filename="dot.png"; filename*=UTF-8''dot.png, 69 bytes, sha256 b1ff9c8e…6640 == sha256 of independently regenerated PNG n/a (API read-back)
Other MIME / text file ✅ MIME from file name style.css → 200 text/css; charset=utf-8, body body{color:red} n/a
Empty file ✅ 200 with empty body empty.txt → 200, 0 bytes, sha256 = e3b0c442… (empty) n/a
file_not_found ✅ typed 404 nope.png → 404 {"code":"file_not_found","error":"File not found"} n/a
invalid_path (directory) ✅ typed 400 /tmp/site → 400 {"code":"invalid_path",…} n/a
conversation_not_found ✅ typed 404 random UUID → 404 {"code":"conversation_not_found",…} n/a
sandbox_paused then resume ✅ typed 409 while paused, works after resume before pause 200 PNG; POST /sandboxes/{id}/pause → status PAUSED → download 409 {"code":"sandbox_paused","error":"Sandbox is paused; resume the conversation first."}; resume → RUNNING → /workspace/project/site/dot.png 200 with same sha256 (note: /tmp content was gone after resume, so /tmp/site/dot.png returned 404 file_not_found — sandbox behavior, not the endpoint) n/a
Error bodies leak no key ✅ no session key / upstream text in errors all observed error bodies contain only code + generic error text n/a
/raw/site/index.html renders with CSS, no scripts ✅ CSS loads via same cookie; script blocked 200 text/html, content-disposition: inline; two CSP headers: sandbox allow-same-origin; frame-ancestors 'self' plus app default policy; x-content-type-options: nosniff. In browser: h1 computed colour rgb(255, 0, 0) (style.css loaded via /raw/), tab title empty (not "PWNED"), console: "Blocked script execution … document's frame is sandboxed" raw
/raw path escape ✅ typed 400 before runtime is called raw/site/%2E%2E/%2E%2E/etc/passwd, %2e%2e, ..%5Cx, site//x (sent unnormalised) → all 400 invalid_path n/a
/raw missing file ✅ typed 404 raw/site/nope.html → 404 file_not_found n/a
Legacy /file unchanged ✅ still returns JSON string /file?file_path=/tmp/site/style.css → 200 "body{color:red}" n/a
Rate-limit (redispy) fix ✅ authenticated requests no longer hang after ~64/pod ~150+ authenticated requests across the run (polling, API reads, downloads) succeeded; a 16-request burst all returned 200 in ~0.4s each. One transient period (~2 requests, 20s timeouts on /app-conversations and /file/download) occurred mid-run while /raw calls succeeded, and cleared on its own — not a permanent block. n/a

Key screenshots

home
reply
raw preview

What was tested

  • Byte-exact PNG download with correct MIME/Content-Disposition (sha256 compared with an independently generated copy), empty file, CSS MIME.
  • Typed errors: file_not_found, invalid_path, conversation_not_found, sandbox_paused (real pause/resume), no key leakage in bodies.
  • /raw inline route: stylesheet resolved via relative link on same session, script blocked by CSP sandbox, double CSP header, nosniff, path-escape rejection.
  • Legacy /file still works.

Skipped / manual review

  • repository query param / repository_not_found and repo-relative file_path resolution: conversation had no repository connected (no GitHub OAuth in the seeded identity), so absolute paths were used.
  • sandbox_not_ready (503), sandbox_unreachable (503), upstream_error (502): not reproducible without breaking the runtime; covered only by the PR's unit tests.
  • Cross-tenant 404 (another user's conversation) not tested; only a random UUID.
  • Browser actions for the feature (API reads, cookie-authenticated page load) were scripted with Playwright using the seeded member session; the raw preview was verified in a real Chromium page.

Evidence

Full log: evidence/run-log.json
All screenshots: https://github.com/OpenHands/saas-deploy/blob/7c04a72d4dcad3c61e094c96731db70545bcfdd0/.pr/evidence/01_home.png, 02_after_reload.png, 03_conversation.png, 04_negative_rejection.png, 05_baseline_reply.png, 06_feature_setup_files_created.png, 07_raw_preview_red_no_script.png


Generated by an AI agent (OpenHands).

@openhands-agent openhands-agent added verified-on-saas dev-coordinator: reviewed, CI green, verified on SaaS; waiting for its fleet VM turn verify-this-on-vm Triggers Preview Verification on https://app.beta.staging.all-hands-testing.dev/canvas/automations/ labels Nov 13, 2026
@juanmichelini

Copy link
Copy Markdown
Contributor

🔍 Preview Verification — PASS

Target: Replicated fleet VM shared-3 (self-hosted OHE, image sha-514c651) App: https://app.shared-3.replicated.all-hands-testing.dev
Validates: #1233 — /file/download returns workspace file bytes with MIME type and typed errors; /raw/{path} serves sandboxed inline previews; middleware CSP/cache fixes; rate-limit redis-py fix
Timestamp: 2026-11-13T18:30Z
Run ID: b2856d72-e527-4908-b461-efea603254de

Result: PASS

Baseline smoke

Step Status Detail
preflight ✅ app -> 200
positive:login ✅ Keycloak login accepted
positive:home ✅ home-screen + chat-launcher visible
positive:backend ✅ /me 200, role=member
positive:workspace ✅ Personal Workspace picked, no LLM warning
positive:reload ✅ login survived reload
positive:conversation ✅ conversation created
positive:reply ✅ execution_status=finished, sandbox_status=RUNNING, agent reply visible (screenshot); finished within the ~5 min window (I polled only once the org header was right, so no exact time)
negative:rejected ✅ wrong password rejected by Keycloak

Feature test — workspace file transport (/file/download, /raw/{path})

Run in the member's Personal Workspace (no repository connected, so the working dir is /workspace/project and file_path is relative to it). Requests used the member's browser session with the X-Org-Id header the app itself sends. A conversation was started with the PR's "How to verify" prompt (the agent created site/style.css, site/index.html, site/dot.png, site/empty.txt).

Step Status Intended effect Observed effect (how verified) Screenshot
Setup: agent creates the files ✅ Files exist in the sandbox execution_status=finished; the agent reported sha256 b1ff9c8e…946640 for dot.png conv
Bytes + MIME: GET /file/download?file_path=site/dot.png ✅ Unchanged bytes, image MIME, attachment disposition 200, image/png, attachment; filename="dot.png"; filename*=UTF-8''dot.png, 69 bytes, body sha256 = b1ff9c8e…946640 (identical to the agent's sha256sum). Absolute path form gives the same hash. style.css gives text/css n/a (API)
Empty file: site/empty.txt ✅ 200 with empty body 200, content-length 0, body sha256 = empty-string hash n/a
Errors ✅ Typed, distinct codes missing file → 404 file_not_found; random conversation id → 404 conversation_not_found; unknown repository → 404 repository_not_found; directory path → 400 invalid_path. All bodies are {code,error} with no session key n/a
Pause → 409, resume ✅ Paused sandbox is distinguishable from an empty file After POST /sandboxes/<id>/pause: /file/download → 409 sandbox_paused, /raw/… → 409 sandbox_paused, while legacy /file still returns 200 "" (old behavior). After /resume: 503 sandbox_not_ready (twice) and then 200 with the bytes n/a
Raw asset base, no scripts ✅ CSS loads via /raw/ with the same cookie; script blocked Opened /raw/site/index.html in Chromium: h1 computed colour rgb(255,0,0) (style.css loaded relatively), document.title stayed empty (not PWNED), console: "Blocked script execution … document's frame is sandboxed". Headers: inline, text/html, two CSP headers (sandbox allow-same-origin; frame-ancestors 'self' plus the default policy), x-content-type-options: nosniff. /raw/site/dot.png → image/png raw
Path escape on /raw ✅ Escapes rejected before reaching the runtime raw/site/..%2F..%2Fetc/passwd, raw/site%5C..%5Cx and raw/site/%00x → 400 invalid_path. The literal %2E%2E/%2E%2E/etc/passwd form from the PR text is collapsed before the app (by the browser/ingress), so it returned the SPA HTML page (200, no file content) and does not exercise the route; see note below n/a
Legacy /file unchanged ✅ JSON string still returned GET /file?file_path=site/style.css → 200 "body{color:red}" n/a
Rate-limit fix (redis-py) ✅ >64 authenticated requests per pod no longer hang 100 consecutive authenticated /file/download calls plus the earlier requests: all 200, 13.7 s total, no hang n/a

Key screenshots

home
smoke reply
raw preview
feature conversation

What was tested

  • Byte-exact download with MIME + disposition headers (sha256 compared with the sandbox-side hash), empty file, all reachable error codes, pause/resume state mapping.
  • Inline preview isolation: relative CSS loads, script blocked by CSP sandbox, dual CSP headers (middleware fix), nosniff.
  • Path validation on /raw, legacy /file unchanged, 100-request burst for the rate-limit regression.

Skipped / manual review

  • Repository-relative paths (raw/<repo-folder>/…, repository= selecting a real repo): the Personal Workspace has no connected GitHub repo, so only the no-repo layout was tested.
  • The /api/.../raw/<repo>/assets/… cache-control exclusion was not exercised directly. The /raw/ responses showed no-cache, no-store, not a public immutable cache.
  • sandbox_unreachable (503) and upstream_error (502) cannot be triggered from outside; covered only by the PR's unit tests.
  • Self-hosted note: the literal %2E%2E dot-segment request is normalised upstream of the app on this install.

Evidence

Full log: evidence/run-log.json


Generated by an AI agent (OpenHands).

@juanmichelini juanmichelini removed the verify-this-on-vm Triggers Preview Verification on https://app.beta.staging.all-hands-testing.dev/canvas/automations/ label Nov 13, 2026
@openhands-agent openhands-agent added ready-for-human dev-coordinator: verified on SaaS and on the fleet VM; ready for human review and removed verified-on-saas dev-coordinator: reviewed, CI green, verified on SaaS; waiting for its fleet VM turn labels Nov 13, 2026
@openhands-agent

Copy link
Copy Markdown
Contributor Author

Ready for human review, @juanmichelini: reviewed by all-hands-bot (APPROVED) and verified PASS on SaaS and on the fleet VM. Evidence: https://github.com/OpenHands/saas-deploy/pull/2041#issuecomment-6678966115 (SaaS), #1233 (comment) (fleet VM). Assigned by dev-coordinator.

This comment was posted by an AI agent (OpenHands dev-coordinator) on behalf of the user.

@juanmichelini
juanmichelini requested review from a team and lilagrc and removed request for a team November 24, 2026 23:24

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human dev-coordinator: verified on SaaS and on the fleet VM; ready for human review type: feat A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[OSS→OHE parity] Preserve file bytes, MIME and errors through tenant file transport

3 participants