Skip to content

fix(backend): use correct port fallback for in-cluster agent resolution - #1525

Merged
pdettori merged 1 commit into
mainfrom
fix/resolve-agent-url-port-fallback
May 9, 2026
Merged

pdettori merged 1 commit into
mainfrom
fix/resolve-agent-url-port-fallback

Conversation

@cwiklik

@cwiklik cwiklik commented May 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Fix resolve_agent_url to use DEFAULT_IN_CLUSTER_PORT (8000) as fallback when running in-cluster, instead of always using DEFAULT_OFF_CLUSTER_PORT (8080)
  • When the upstream Sandbox controller (kubernetes-sigs/agent-sandbox) creates a headless Service without port definitions, the backend now falls back to the correct agent port
  • If the Service has ports defined, the backend does nothing extra and respects the existing Service port configuration as before
  • Expanded unit tests to cover both in-cluster and off-cluster fallback scenarios

Root cause: The Sandbox controller creates headless Services with no spec.ports (kubernetes-sigs/agent-sandbox#154). The backend's lookup_service_port finds no ports on the Service and falls back to a default. Previously the default was always 8080 (off-cluster port), but in-cluster agents listen on 8000 — causing 503 errors when fetching the agent card.

Behavior:

  • Service has ports → use service.spec.ports[0].port (unchanged)
  • Service has no ports (Sandbox bug) or doesn't exist → fall back to 8000 in-cluster, 8080 off-cluster

Test plan

  • Unit tests pass (pytest tests/test_routes.py — 15 tests)
  • Deploy to Kind cluster with Sandbox workload and verify agent card is fetched successfully

Assisted-By: Claude Code

When a Service has no ports defined (e.g. Sandbox-created headless
services), resolve_agent_url fell back to DEFAULT_OFF_CLUSTER_PORT
(8080) regardless of context. In-cluster agents listen on port 8000,
so the fallback should match the deployment context.

Workaround for kubernetes-sigs/agent-sandbox#154 where the Sandbox
controller creates headless Services without port definitions.

Signed-off-by: cwiklik <[email protected]>

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: cwiklik <[email protected]>

@huang195 huang195 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dobra robota. Targeted one-line fix in resolve_agent_url plus symmetric test coverage (in-cluster / off-cluster × service-missing / ports-empty). Scope is right — other DEFAULT_OFF_CLUSTER_PORT sites (agents.py:3073,3612) are for HTTPRoute/external access and intentionally differ, and they skip Sandboxes anyway.

Verified against the live Kind cluster: weather-agent.team1.svc.cluster.local:8080 → 503, :8000 → 200. This patch routes to the right port.

Areas reviewed: Python (1 file, 1 change), tests (4 cases)
Commits: 1, signed-off
CI: all green (E2E HyperShift awaits /run-e2e)

@huang195

huang195 commented May 9, 2026

Copy link
Copy Markdown
Member

/run-e2e

@github-actions github-actions Bot added the safe-to-test Maintainer reviewed - safe to run E2E tests label May 9, 2026
@github-actions

github-actions Bot commented May 9, 2026

Copy link
Copy Markdown

E2E HyperShift Tests Started

Triggered by: @huang195
Commit: cd5ec7920d2be4195f40404f2c7a42b3b3182c24
Workflow Run: View logs

Tests are running on OpenShift 4.20.11. This typically takes 30-45 minutes.


To re-run tests after new commits, comment /run-e2e again.

@github-actions

github-actions Bot commented May 9, 2026

Copy link
Copy Markdown

E2E HyperShift Tests Passed

Commit: cd5ec7920d2be4195f40404f2c7a42b3b3182c24
Result: All tests passed
Workflow Run: View logs

The safe-to-test label indicates this commit has been approved for E2E testing.


If you push new commits, the label will be removed and you'll need to comment /run-e2e again.

@pdettori pdettori left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@pdettori
pdettori merged commit 70e512a into main May 9, 2026
22 checks passed
@huang195
huang195 deleted the fix/resolve-agent-url-port-fallback branch May 9, 2026 01:20
cwiklik pushed a commit that referenced this pull request May 9, 2026
…back

fix(backend): use correct port fallback for in-cluster agent resolution

Signed-off-by: cwiklik <[email protected]>
@xjacka xjacka mentioned this pull request May 11, 2026
huang195 added a commit that referenced this pull request May 12, 2026
…stant

PR #1525 made `resolve_agent_url` fall back to DEFAULT_IN_CLUSTER_PORT (8000)
for in-cluster callers when the Service has no ports (the Sandbox case).
That contradicts the sandbox-builder change in `_build_sandbox_manifest`,
which aligns the Sandbox pod's PORT and containerPort with service_port
(default DEFAULT_OFF_CLUSTER_PORT = 8080) so that AGENT_ENDPOINT, the
advertised agent card URL, and the actual listener all agree.

With both changes in effect, the backend knocks on :8000 while the agent
listens on :8080; envoy returns 503 and the UI shows "Agent card not
available."

Replace the hardcoded in-cluster fallback with a read of the owning
Sandbox's pod template (`spec.podTemplate.spec.containers[0]` —
containerPort first, then the PORT env var). Deployments are unaffected:
their Service exposes ports, so the first lookup still wins and the new
Sandbox lookup is skipped. A single DEFAULT_OFF_CLUSTER_PORT final fallback
covers the case where both lookups fail (matches the sandbox-builder
default and the external port used by Gateways/Ingresses).

As a side benefit, this also handles Sandboxes created with a custom
servicePorts[0].port — neither prior fix covered that case.

Tests:
- Replace the two :8000 assertions from #1525 with Sandbox-aware tests
  (containerPort path and PORT-env path) and a final-fallback test that
  asserts :8080 when neither Service nor Sandbox is found.

The long-term fix is upstream kubernetes-sigs/agent-sandbox#154 (Sandbox
controller populating its Service with ports); this is the in-tree
workaround until then.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe-to-test Maintainer reviewed - safe to run E2E tests

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants