Repository navigation
Description
This issue was created by an AI agent (OpenHands) on behalf of @neubig.
Summary
GET /api/v1/app-conversations/{conversation_id}/git/diff returns 502 whenever the agent-server answers with a 4xx for a client-caused condition. That converts ordinary "file not found / file too big" responses into gateway errors, which land in the logs.traefik.prod.core_app.requests 5xx metric and have now tripped the prod 5xx monitor.
Impact
- Monitor 23656065 "SaaS Prod Core App HTTP 5xx Error Rate > 0.15% over 1 Hour" went OK→Alert at 2026-11-22 03:34:45Z. Trailing hour: 585 5xx / ~24.6k requests ≈ 2.4% (threshold 0.15%).
- 523 of those 585 5xx (~89%) were this one endpoint. The remainder was smaller: repo-search 500s (15), sandbox status polls (11), automation 502s (8), GitHub webhook 502s (5).
- Blast radius was narrow but real: 3 orgs accounted for ~90% of the errors, ~5 users materially affected, 7 conversations.
- Not a new regression. This endpoint has produced 973–3,726 502s/day every day since at least 2026-11-08. Only 1 of the last 300 hours crossed 0.15% (today 03:00 at 0.167%).
Root cause
openhands/app_server/app_conversation/app_conversation_router.py → _proxy_git_runtime_call():
except httpx.HTTPStatusError as e:
logger.exception(
'Agent server returned error during %s: %s - %s',
runtime_path, e.response.status_code, e.response.text, stack_info=True,
)
raise HTTPException(
status_code=status.HTTP_502_BAD_GATEWAY,
detail=f'Agent server error: {e.response.status_code}',
) from eThe upstream status is logged and then discarded — every non-2xx becomes 502.
The agent-server 4xx responses are expected, client-caused conditions:
400 {"detail":"File does not exist: /workspace/project/..."}— untracked or already-deleted file (115 occurrences in the alert hour)400 {"detail":"File too large for git diff: N bytes (max: 1048576 bytes)"}— the 1 MiB cap inopenhands-sdk/openhands/sdk/git/git_diff.py(12 occurrences)
Notably, the same file already implements the correct policy for LLM/ACP switching (_switch_agent_endpoint): it surfaces the agent-server's 400/504 and only returns 502 for anything else. The git proxy should follow the same rule.
Secondary contributors
- The agent-server uses a single 400 for both "untracked/missing file" and "file over 1 MiB", with no machine-readable distinction. This was reported in #16215 and closed without a fix ("the bug investigation turned out to be a 1 MB git-diff limit + untracked-file handling ... the canvas-side workaround ... is being rolled back").
- The runtime logs empty-tree diff failures as errors:
git show 4b825dc…(empty tree):<path>→ exit 128 "exists on disk, but not in empty tree", andgit rev-parse --git-dir→ exit 128 "not a git repository" (openhands.sdk.git.utils). - The canvas requests
/git/diffper file, so a single conversation with many missing or oversized files produces hundreds of 5xx.
Expected behavior
- agent-server
400→ surface400(ideally mapped to404for missing files,413for oversized files) - agent-server
404→404 - only transport failures and agent-server
5xx→502
Suggested fix
- Mirror
_switch_agent_endpoint's status policy inside_proxy_git_runtime_call(pass 4xx through; 502 only for 5xx/transport errors). - Have the agent-server return a structured error (
code: "file_not_found" | "file_too_large") so the UI can show "untracked file" / "diff too large" instead of retrying. - Frontend: skip files > 1 MiB and debounce/dedupe the per-file diff polling.
- Optionally exclude proxy-generated 502s from the monitor numerator until this is fixed; at 0.15% on a ~7 req/s denominator there is only ~4 errors/min of headroom.
Verification / reproduction data
Datadog, prod, 2026-11-22 02:34:45–03:34:45Z:
- traefik 5xx grouped by path → 523 on
/api/v1/app-conversations/{id}/git/diff service:deploy "Agent server returned error during /api/git/diff"→ 115 ×File does not exist, 12 ×File too large for git diff, 6 ×Bad Gateway, 2 ×503 no available server
Related
- #16215 — agent-server
/api/git/diff400 for untracked and >1 MiB files (closed, not fixed) - #19214 — diff stats are O(n²) and stall the UI on large diffs
Activity