Skip to content

[Bug]: git/diff proxy turns agent-server 4xx into 502, driving prod 5xx alert #1503

Open

Description

@neubig

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 e

The 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 in openhands-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

  1. 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").
  2. 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", and git rev-parse --git-dir → exit 128 "not a git repository" (openhands.sdk.git.utils).
  3. The canvas requests /git/diff per file, so a single conversation with many missing or oversized files produces hundreds of 5xx.

Expected behavior

  • agent-server 400 → surface 400 (ideally mapped to 404 for missing files, 413 for oversized files)
  • agent-server 404 → 404
  • only transport failures and agent-server 5xx → 502

Suggested fix

  1. Mirror _switch_agent_endpoint's status policy inside _proxy_git_runtime_call (pass 4xx through; 502 only for 5xx/transport errors).
  2. 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.
  3. Frontend: skip files > 1 MiB and debounce/dedupe the per-file diff polling.
  4. 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/diff 400 for untracked and >1 MiB files (closed, not fixed)
  • #19214 — diff stats are O(n²) and stall the UI on large diffs

Activity

  1. added
    bug
    python
    on Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpython

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions