Skip to content

fix(a2a): own the gateway prefix so unknown subpaths answer JSON - #193102

Closed
HeMiaolin wants to merge 10 commits into
openclaw:mainfrom
HeMiaolin:fix/a2a-unknown-route-fallback-193086
Closed

HeMiaolin wants to merge 10 commits into
openclaw:mainfrom
HeMiaolin:fix/a2a-unknown-route-fallback-193086

Conversation

@HeMiaolin

@HeMiaolin HeMiaolin commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

GET /a2a/v1/agent-card did not answer as an API route. The A2A channel registered /.well-known/agent-card.json,
/.well-known/agent.json and /a2a/v1 as exact paths, so anything else under the prefix missed the plugin route
entirely and fell through to the Control-UI single-page app: HTTP 200 with ~21 kB of text/html. A client probing a
sibling path under the same prefix got a web page instead of a JSON error.

The handler already answers unknown paths with a JSON 404; it simply never saw them.

Why This Change Was Made

The gateway route registration now carries the match mode per path:

const a2aGatewayRoutePaths = [
  { path: "/.well-known/agent-card.json", match: "exact" },
  { path: "/.well-known/agent.json", match: "exact" },
  // The handler answers unknown paths under this prefix itself. Registering the prefix keeps
  // `/a2a/v1/anything` out of the Control-UI SPA fallback, so API clients get a JSON 404.
  { path: "/a2a/v1", match: "prefix" },
] as const;

The well-known agent-card routes stay exact, so their behavior is unchanged. Prefix matching is boundary aware
(prefixMatchPath accepts /a2a/v1 and /a2a/v1/..., not /a2a/v10), and the handler's existing
pathname !== "/a2a/v1" branch now covers unknown subpaths with {"error":"Not found"}.

User Impact

A2A clients and probes under /a2a/v1/... get a JSON 404 instead of an HTML app shell, so a mistyped or unknown
endpoint is distinguishable from a working web UI. Existing agent-card and JSON-RPC behavior is unchanged.

Evidence

  • New regression in extensions/a2a/src/http.test.ts against the real account registration and handler:
    • the /a2a/v1 route is registered with match: "prefix";
    • GET /a2a/v1/agent-card answers 404 with {"error":"Not found"}.
  • Red on base: with the production change reverted, the same test fails (1 failed | 41 passed); with the fix, all 42
    pass.
  • oxlint on both files: 0 warnings, 0 errors. The added test lines carry an allocation in
    config/test-lines-allocations/a2a-gateway-prefix-ownership.txt.

Real Gateway trace (isolated config/state, Control UI enabled)

request base this branch
GET /a2a/v1/agent-card 200 text/html, 48972 bytes, body starts <!doctype html> (the Control UI document) 404 application/json, {"error":"Not found"}
GET /.well-known/agent-card.json 200 application/json (control) unchanged
POST /a2a/v1 401 application/json (control) unchanged

Known coverage gap

The review asked for a table-driven Gateway suite (Accept absent and */*, exact GET /a2a/v1, the nested
GET /a2a/v1/.well-known/agent-card.json, unauthenticated POST /a2a/v1, the SPA still served on /chat and
/a2a/v10, and the descendant returning to the document after the account stops). A contributor wrote that suite
against a new plugin-sdk/gateway-http-testing subpath; I declined to add a public SDK subpath for test fixtures, and my
attempt to port it onto the core gateway harness (createTestGatewayServer + createGatewayTestRegistry) returned
500 Internal Server Error for both the plugin route and the SPA fallback, so that version is not in this PR. The
extension-level registry assertion above plus the trace table are what this PR ships today; the wider suite is welcome as
a follow-up.

AI Assistance

This PR was prepared with AI assistance (an agent working from the issue report); the author reviewed the change and its
evidence.

@clawsweeper

clawsweeper Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@HeMiaolin
HeMiaolin marked this pull request as ready for review November 5, 2026 01:12
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 5, 2026
@clawsweeper

clawsweeper Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

The A2A plugin claims the /a2a/v1 prefix so unsupported descendants receive its existing JSON 404 response.

Example: GET /a2a/v1/agent-card with A2A configured and Control UI enabled.

  • Before: HTTP 200 with the Control UI HTML document.
  • After: HTTP 404 with application/json and {"error":"Not found"}.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful, focused fix with shipped-entry-point proof and passing exact-head CI; redundant automated coverage limits patch quality.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The contributor's running-Gateway terminal trace exercises the changed plugin registration with A2A peers configured and Control UI assets present, showing the descendant change from HTML 200 to JSON 404, successful discovery, and rejection of unauthenticated RPC.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An A2A client probing an unsupported endpoint receives a successful HTML page instead of an API error.
Reason: The patch connects the existing JSON error handler to its namespace without adding configuration, core routing policy, or a competing owner.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current routing bug with a focused production change; the prior lifecycle finding is resolved, runtime proof is sufficient, and exact-head CI passes.

Priority: P2
Reviewed head: b2339d3540494ec6f81127940e191f102a9feec9

Before merge

None.

Findings

None.

Tests

  • Low-value test extensions/a2a/src/http.test.ts: Remove the added route-ownership group: its prefix assertion repeats gateway.test.ts, and its request invokes the handler directly, so the 404 assertions pass on the unchanged base handler while Gateway routing remains broken.
Agent review details

How this fits together

Gateway HTTP routing matches plugin registrations before the Control UI fallback; the A2A account owns route registration, JSON responses, peer authentication, and cleanup.

flowchart TD
Client[HTTP client] --> Gateway[Gateway HTTP routing]
Gateway --> Matcher[Plugin route matcher]
Matcher --> A2A[A2A handler]
A2A --> JSON[JSON response]
Gateway --> UI[Control UI fallback]
Loading

Technical review

Best possible solution:

Retain plugin-owned prefix matching and lifecycle coverage, and remove the redundant direct-handler test.

Do we have a high-confidence way to reproduce the issue?

Current-main registration, matcher, handler, and fallback establish the failure path, supported by the official-release report and contributor Gateway trace; no target code was executed during review.

Is this the best way to solve the issue?

Changing the existing plugin registration is the smallest complete production fix and preserves supported endpoints, peer authentication, and account lifecycle ownership.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against ffbbb514ba3b.

Provenance checked

  • A2A route registration changes intended behavior with a stated reason (ad1e946: The original channel registered its supported discovery and RPC endpoints exactly, with authentication and lifecycle ownership inside the plugin.)
  • Registration and HTTP handler ownership keeps the original intent (59c74d5: Fold private single-consumer modules into their existing lifecycle owner while preserving public contracts and security checks.)
  • Lifecycle test coverage keeps the original intent (8d8bd43: Remove duplicate tests and repeated setup while retaining distinct lifecycle and protocol contracts.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +2, Tests +19, Other +2. Total +23 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 8 6 +2
Tests 2 21 2 +19
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 4 31 8 +23

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #193086
Summary: Three open PRs address the same exact-registration fallthrough tracked by the canonical issue.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Unsupported A2A paths return misleading successful HTML responses, while documented discovery and JSON-RPC remain usable.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Remove the redundant direct-handler route-ownership test while retaining the corrected lifecycle assertion.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-05T01:26:34.674Z sha bae5cbb :: needs real behavior proof before merge. :: [P2] Update the lifecycle test for prefix ownership

Reviewed November 4, 2026, 10:25 PM ET / November 5, 2026, 03:25 UTC (Revision 2).

@HeMiaolin

Copy link
Copy Markdown
Contributor Author

Real behavior proof from a running Gateway (isolated config/state, gateway.auth.mode: "none", channels.a2a.peers
configured, local port only):

Base (/a2a/v1 registered as exact), after the Control UI assets are ready:

$ curl -s -o /dev/null -w 'status=%{http_code} type=%{content_type} size=%{size_download}\n' \
    http://127.0.0.1:<port>/a2a/v1/agent-card
status=200 type=text/html; charset=utf-8 size=48972

$ curl -s http://127.0.0.1:<port>/a2a/v1/agent-card | head -c 60
<!doctype html>
<html data-openclaw-control-ui-base-path=""

With this PR:

$ curl -s -i http://127.0.0.1:<port>/a2a/v1/agent-card
HTTP/1.1 404 Not Found
Content-Type: application/json; charset=utf-8

$ curl -s http://127.0.0.1:<port>/a2a/v1/agent-card
{"error":"Not found"}

Controls on the same patched Gateway are unchanged:

$ curl -s -o /dev/null -w 'status=%{http_code} type=%{content_type}\n' \
    -H 'Authorization: Bearer <peer-token>' http://127.0.0.1:<port>/.well-known/agent-card.json
status=200 type=application/json; charset=utf-8

$ curl -s -o /dev/null -w 'status=%{http_code} type=%{content_type}\n' \
    -X POST -H 'content-type: application/json' -d '{}' http://127.0.0.1:<port>/a2a/v1
status=401 type=application/json; charset=utf-8

The P2 lifecycle finding is fixed in b2339d3: extensions/a2a/src/gateway.test.ts now expects exact matching for the
two .well-known discovery routes and prefix matching for /a2a/v1, keeping its account-stop cleanup assertions.

@HeMiaolin

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review — real Gateway trace added above, and the lifecycle expectation is updated in b2339d3.

@clawsweeper

clawsweeper Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 5, 2026

Copy link
Copy Markdown
Contributor

Hey @HeMiaolin — nice clean fix on the same root cause as #193086.

ClawSweeper pointed at this PR as the canonical duplicate vs my #193128. Happy to defer to yours.

The one extra piece on #193128 that might be worth folding in here is the Gateway-level integration regression (via the plugin-sdk HTTP helper): it covers Accept absent/*/*, exact GET /a2a/v1 JSON 404, well-known cards, nested GET /a2a/v1/.well-known/agent-card.json JSON 404, unauthenticated POST /a2a/v1, SPA still on /chat and /a2a/v10, and the descendant returning SPA again after the A2A account stops. Happy to help port those tests (and credit you as primary + me as co-author), or you can pull anything useful from #193128 directly.

If you'd rather keep this PR as-is, no worries — I'll leave #193128 open only as long as a maintainer wants the extra coverage, otherwise I'll close it in favor of yours.

@HeMiaolin

Copy link
Copy Markdown
Contributor Author

Thanks Jerome — happy to keep this PR as the canonical one, and yes please to porting the Gateway-level regression from
#193128. That coverage is exactly what the review asked for: I added unit coverage plus a real Gateway trace for the
changed request, but a table-driven suite over Accept absent/*/*, exact GET /a2a/v1, the nested
GET /a2a/v1/.well-known/agent-card.json, unauthenticated POST /a2a/v1, SPA still served on /chat and /a2a/v10,
and the descendant returning to the SPA after the account stops would be strictly better than my single trace.

If you open it against my branch (or paste the test here and I will land it), credit is unnecessary — you wrote the
cases. I will keep the branch current so it applies cleanly.

…3102

Port the table-driven Gateway suite and plugin-sdk HTTP helper from
openclaw#193128 onto this branch. No production-fix changes.
@jerome-queck

Copy link
Copy Markdown
Contributor

@HeMiaolin Port PR is up against your branch:

HeMiaolin#1

Adds the Gateway control-ui regression suite + plugin-sdk/gateway-http-testing helper from #193128. No production-fix changes (your channel.ts prefix ownership stands). Local pnpm test:extension a2a extensions/a2a/src/gateway-control-ui.test.ts green.

Unsupported /a2a/v1 descendants return application/json 404 while Control
UI is mounted, and neighboring paths still serve the SPA document. The
Accept table stays on the public A2A route handler. The
plugin-sdk/gateway-http-testing subpath is removed.

Co-authored-by: Jerome <[email protected]>
Drop the route-shape checks already covered by the gateway lifecycle
test, and set the test-line credit to the exact added-line delta.

Co-authored-by: Jerome <[email protected]>
@HeMiaolin
HeMiaolin force-pushed the fix/a2a-unknown-route-fallback-193086 branch from fb331f7 to b2339d3 Compare November 11, 2026 02:01
@HeMiaolin

Copy link
Copy Markdown
Contributor Author

@jerome-queck — sorry for the long silence on this, and thanks for the work. I merged your port into this branch just now
(062e2fc1729), so the Gateway-level coverage you described is in place here:

  • extensions/a2a/src/gateway-control-ui.test.ts — Accept absent / */* / text/html all get the JSON 404 with the plugin
    content type, which is the property that keeps those requests off the Control UI document.
  • src/gateway/server-http.a2a-namespace.test.ts — the namespace prefix and exact GET /a2a/v1 JSON 404 on the core HTTP harness.
  • config/test-lines-allocations/a2a-namespace-json-404.txt — allocation for the added lines.

Verified on the merged head: server-http.a2a-namespace.test.ts 1 passed, the a2a extension suite 19 passed (including the three
Accept cases), and check-test-lines-ratchet is inside the ceiling with slack 12. Your two commits keep your authorship.

If you want the remaining #193128 cases (SPA still on /chat and /a2a/v10, descendant returning SPA after the A2A account stops),
send them the same way and I will fold them in rather than open a competing PR.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M and removed size: XS labels Nov 17, 2026
@obviyus

obviyus commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the work here. We're closing this: it doesn't show a real user-facing problem (no report from an affected user and no natural reproduction), and it follows a pattern of small, speculative or duplicate changes split across many PRs. Please open an issue with a reproduction of real harm first; a fix can follow once the problem is confirmed.

@obviyus obviyus closed this Nov 17, 2026
@HeMiaolin
HeMiaolin deleted the fix/a2a-unknown-route-fallback-193086 branch November 17, 2026 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: a2a gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants