Repository navigation
fix (A2A): fetch public diff for PR URLs and report failed state to Langfuse - #2459
Conversation
When a PR URL is provided, fetch the public unified diff via `.diff` endpoint and route through mosaico_diff provider instead of using the host provider. This enables token-free operation for public repos while failing honestly for private repos or unsupported hosts. - Add `_fetch_public_diff()` to retrieve public diffs with size/timeout limits - Return `RouteResult(text, ok)` from routing to distinguish success/failure - Mark tasks as failed (not completed) when diff fetch or routing fails - Switch Langfuse callback from `langfuse` to `langfuse_otel` for OTEL support - Update all tests to mock diff fetching and validate failed state handling
PR Summary by QodoFetch public PR .diff for URL inputs and fail tasks on routing errors Description
Diagram
High-Level Assessment
Files changed (7)
|
Code Review by Qodo
1. PR URL non-diff completes
|
…allback registration - Add SSRF guards to _fetch_public_diff: enforce HTTPS-only, validate all resolved IPs are public, and check redirect targets - Implement _url_is_safe and _host_resolves_public helpers to block private/loopback/link-local/metadata IPs - Add redirect following with safety checks (max 5 hops) to prevent redirect-based SSRF attacks - Remove legacy 'langfuse' callback entries and ensure exactly one 'langfuse_otel' callback is registered - Add comprehensive unit tests for SSRF protection scenarios and legacy callback cleanup
| async def _run_on_diff(diff_body: str, verb: str, text: str, title: str) -> "RouteResult": | ||
| """Parse a unified diff, install it as MOSAICO.INPUT under the mosaico_diff provider, | ||
| and run the verb (token-free). Empty parse -> empty fallback (ok=True).""" | ||
| parsed = parse_unified_diff(diff_body) | ||
| if not parsed: | ||
| return RouteResult(_empty_fallback(verb), ok=True) |
There was a problem hiding this comment.
1. Pr url non-diff completes 🐞 Bug ≡ Correctness
When a PR URL’s .diff endpoint returns non-diff text (e.g., HTML), parse_unified_diff() returns an empty list and _run_on_diff() returns ok=True, so the executor marks the task completed even though routing effectively failed. This contradicts the PR’s intent to “fail honestly” for private repos/unsupported hosts because many such cases return a non-empty non-diff body with HTTP 200.
Agent Prompt
## Issue description
PR-URL routing treats any non-empty response body from `pr_url + ".diff"` as a diff. If the response is HTML/text (common for private repos/login pages or unexpected server responses), `parse_unified_diff()` returns `[]`, and `_run_on_diff()` returns an empty fallback with `ok=True`, causing `PRAgentExecutor` to complete the task instead of failing it.
## Issue Context
- `parse_unified_diff()` explicitly degrades to `[]` when there is no `diff --git` header.
- `PRAgentExecutor.execute()` uses `RouteResult.ok` to decide `complete()` vs `failed()`.
## Fix Focus Areas
- pr_agent/mosaico/dispatch.py[264-305]
- pr_agent/mosaico/diff_provider.py[29-45]
- pr_agent/mosaico/executor.py[37-46]
## Suggested fix
- Distinguish “empty diff parse” from success for the PR-URL flow.
- Option A (minimal behavioral change): add a flag to `_run_on_diff(..., empty_ok: bool)` and call it with `empty_ok=False` from the PR-URL path; when `parsed` is empty and `empty_ok=False`, return `RouteResult(_pr_fetch_failed_fallback(pr_url), ok=False)` (or a more specific message) instead of `ok=True`.
- Option B: validate the fetched body before calling `_run_on_diff` (e.g., `if not _looks_like_diff(diff_body): treat as fetch failure`).
- Add/adjust unit tests to cover a 200 response with a non-diff body and assert `ok=False` for PR URL routing.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
Code review by qodo was updated up to the latest commit 93dc779 |
When fetching a public diff from a PR URL, if the response is HTTP 200 but contains non-diff content (e.g., HTML login page), the parser returns an empty result. Previously this was treated as success with an empty fallback. Now correctly reports ok=False with pr-fetch-failed fallback by adding empty_ok parameter to _run_on_diff.
|
Code review by qodo was updated up to the latest commit 67b1552 |
When a PR URL is provided, fetch the public unified diff via
.diffendpoint and route through mosaico_diff provider instead of using the host provider. This enables token-free operation for public repos while failing honestly for private repos or unsupported hosts._fetch_public_diff()to retrieve public diffs with size/timeout limitsRouteResult(text, ok)from routing to distinguish success/failurelangfusetolangfuse_otelfor OTEL support