Repository navigation
Conversation
vishu-bh
left a comment
There was a problem hiding this comment.
Recording reachability from actual calls makes sense, and the new timestamp gives clients useful context. There are four gaps to address before merging: MCP tool calls bypass the observation writes, the Admin UI treats unknown status as a failure, local serialization errors mark agents unreachable, and downgrade leaves the column nullable.
The focused service tests pass. Please also add a live gateway regression covering observations through both the A2A API and MCP tool calls, as required by AGENTS.md.
| db_agent = get_for_update(ts_db, DbA2AAgent, agent_id) | ||
| if db_agent and getattr(db_agent, "enabled", False): | ||
| db_agent.last_interaction = end_time | ||
| if reachable_observation is not None: |
There was a problem hiding this comment.
[P1] Please record observations for A2A tool calls as well.
This write only runs through invoke_agent(). The MCP A2A branch in ToolService.invoke_tool() sends HTTP requests directly at tool_service.py:7276, and _call_a2a_agent() does the same at line 8952. Neither path updates these fields. A successful tool call can therefore leave a new agent unobserved or preserve an old unreachable status.
The helper reproduction returned HTTP 200 after one outbound call, while reachable and last_seen stayed None. Please share the observation writer across these paths and cover tool-call success and transport failure.
There was a problem hiding this comment.
Fixed! The A2A branch of ToolService.invoke_tool() and _call_a2a_agent() now use the same writer as invoke_agent(). The writer is record_a2a_reachability() in a2a_reachability.py.
Any HTTP response marks the agent reachable. A connection failure or a timeout marks it unreachable.
Tests: test_a2a_tool_call_records_reachability covers success, HTTP 500, connect failure, and both timeout types. A live test calls the agent through tools/call and checks reachable and lastSeen. The live test fails when I disable the writes in tool_service.py.
| config: Dict[str, Any] | ||
| enabled: bool | ||
| reachable: bool | ||
| reachable: Optional[bool] = Field(default=None, description="Last observed reachability. None means the gateway has made no observation.") |
There was a problem hiding this comment.
[P2] Please give the new null state an explicit display in the Admin UI.
agents_partial.html:146 currently renders it as "Unreachable", while a2aAgents.js:145 renders it as "Offline". Since the migration resets every existing agent to null, users will see a failure before the gateway makes any observation. Rendering the table with reachable=None confirms this behavior.
Please show an "Unknown" or "Not checked" state in both views and add a regression test.
There was a problem hiding this comment.
Fixed! agents_partial.html and a2aAgents.js now show null as "Not checked". The table no longer shows "Unreachable", and the detail view no longer shows "Offline".
Tests: test_agents_partial_reachability_label renders None, True, and False. A new JS test checks that reachable: null shows "Not checked" and not "Offline".
| try: | ||
| async with get_isolated_http_client(follow_redirects=False) as client: | ||
| http_response = await client.post(pinned.endpoint_url, json=prepared.request_data, headers=pinned.headers, extensions=pinned.extensions) | ||
| except Exception: |
There was a problem hiding this comment.
[P2] Please limit this handler to transport failures.
HTTPX can also fail locally before it sends a request. Passing a NaN parameter raises a serialization ValueError; the reproduction sends zero requests but still changes reachable to False and advances last_seen. That records an observation about an agent the gateway never contacted.
Please preserve the previous observation when local request construction or serialization fails, and add coverage for that case.
There was a problem hiding this comment.
Fixed! is_transport_failure() accepts only httpx.TransportError and timeouts. A request that fails before the gateway sends it, such as the NaN serialization error, now keeps the previous reachable and last_seen.
Tests: test_invoke_records_reachability has a local-serialization-error case. It checks that neither field changes. The same rule applies to the tool-call paths.
| if "last_seen" not in [column["name"] for column in inspector.get_columns("a2a_agents")]: | ||
| return | ||
| op.execute(sa.text("UPDATE a2a_agents SET reachable = :value WHERE reachable IS NULL").bindparams(value=True)) | ||
| with op.batch_alter_table("a2a_agents") as batch_op: |
There was a problem hiding this comment.
[P2] Please restore the original NOT NULL constraint during downgrade.
The upgrade makes reachable nullable, but the downgrade only replaces existing null values and removes last_seen. After a SQLite upgrade/downgrade round trip, the column remains nullable and accepts a new NULL value. The original schema rejects that value.
Please set nullable=False in this batch after clearing the nulls, and assert the restored constraint in the round-trip test.
There was a problem hiding this comment.
Fixed! The downgrade now sets nullable=False on reachable after it replaces the null values.
Tests: test_downgrade_restores_the_not_null_constraint runs upgrade then downgrade on SQLite. It asserts that the column is NOT NULL and that inserting NULL raises IntegrityError.
vishu-bh
left a comment
There was a problem hiding this comment.
The MCP observations, unknown UI state, and downgrade constraint now have fixes and regression coverage. The new live gateway tests also pass. Two items remain: local protocol errors still change reachability, and the migration needs to follow the current main branch head. Details are inline.
| >>> is_transport_failure(ValueError("Out of range float values are not JSON compliant")) | ||
| False | ||
| """ | ||
| return isinstance(error, (httpx.TransportError, asyncio.TimeoutError)) |
There was a problem hiding this comment.
[P2] Local protocol errors still change reachability
The NaN case is fixed, but this check still includes httpx.LocalProtocolError because it inherits from TransportError. HTTPX raises it when a configured header contains CRLF, before sending any HTTP request bytes. I reproduced that with the actual invocation: zero request bytes were written, but reachable changed from True to False and last_seen advanced.
Please exclude local protocol errors from these observations and add a regression test. The direct httpx.TransportError catch in tool_service.py:7332 needs the same treatment.
There was a problem hiding this comment.
Fixed!
is_transport_failure() now returns false for httpx.LocalProtocolError, so a malformed header no longer changes reachable or last_seen. It also returns false for httpx.UnsupportedProtocol, because HTTPX raises that error before it sends a request.
The direct httpx.TransportError catch in tool_service.py now calls is_transport_failure() before it records an observation. All three paths follow the same rule: the A2A API, the MCP tool call, and _call_a2a_agent().
Tests:
test_is_transport_failurecoversLocalProtocolErrorandUnsupportedProtocol.test_invoke_records_reachabilityhas alocal-protocol-errorcase. It checks that neither field changes.test_a2a_tool_call_records_reachabilityhas the same case for the tool-call path. It checks that no observation is recorded.
| import sqlalchemy as sa | ||
|
|
||
| revision: str = "c3e5a7b9d1f2" # pragma: allowlist secret | ||
| down_revision: Union[str, Sequence[str], None] = "b9d2f4a6c8e1" # pragma: allowlist secret |
There was a problem hiding this comment.
[P1] Update the migration parent after syncing with main
Main now includes c4e8a1d7f2b9, which also follows b9d2f4a6c8e1. Combining the two migration sets produces two Alembic heads, so resolving the code conflicts alone will not make the combined branch ready.
Please make this migration follow the current main head and update the expected parent in its test. After resolving the merge conflicts, verify that alembic heads reports one head and that the upgrade still passes.
There was a problem hiding this comment.
I rebased on main and resolved the conflicts in CHANGELOG.md, db.py, and schemas.py. The migration c3e5a7b9d1f2 now follows c4e8a1d7f2b9, and the expected parent in test_a2a_agents_last_seen_migration.py matches. alembic reports one head. The migration tests pass, including the upgrade, the idempotent second run, and the downgrade round trip.
The model and the read schema now carry reachable and last_seen next to drifted and unverified from #7663.
The reachable field of an A2A agent was True by default and no code
changed it, so clients showed every agent as reachable.
Record an observation each time the gateway calls an agent:
- Any HTTP response marks the agent reachable, including a non-200
and a JSON-RPC error. The success flag is not used.
- A transport failure marks the agent unreachable.
- A request that the outbound URL policy blocks changes nothing.
Add a nullable last_seen field so clients can tell how old the
observation is. Make reachable nullable. Null means no observation.
Disabling an agent sets both fields to null.
Migration c3e5a7b9d1f2 adds last_seen and sets reachable to null for
existing agents, because the old default was never an observation.
Signed-off-by: Marek Dano <mk.dano@gmail.com>
Address review feedback on the reachability change. Record observations for MCP tool calls. The A2A branch of ToolService.invoke_tool() and _call_a2a_agent() now use the same writer as invoke_agent(). The writer is in a2a_reachability.py. Mark an agent unreachable only for a connection failure or a timeout. A request that fails before the gateway sends it, such as a serialization error, keeps the previous observation. Show a null reachable value as "Not checked" in the Admin UI table and the agent detail view. The table and the detail view showed it as a failure. Restore the NOT NULL constraint on reachable in the downgrade. Add a live gateway test for observations through the A2A API and MCP tool calls. Signed-off-by: Marek Dano <mk.dano@gmail.com>
httpx raises LocalProtocolError, for example for a header with CRLF, before it sends any request bytes. Recording it marked the agent unreachable although the gateway never contacted the agent. Treat LocalProtocolError and UnsupportedProtocol as local failures in is_transport_failure(). Apply the same check at the direct httpx.TransportError catch in the MCP tool-call path. Make the last_seen migration follow c4e8a1d7f2b9, the current head on main, so Alembic reports one head. Closes #7603 Signed-off-by: Marek Dano <mk.dano@gmail.com>
4358a64 to
1c64117
Compare
Closes #7603
Summary
reachableon an A2A agent wastrueby default and no code changed it. Clients showed every agent as reachable.The gateway now records an observation each time it calls an agent:
reachabletruefalsereachableis now nullable.nullmeans no observation. A disabled agent and an agent nobody has called both reportnull.A new nullable
last_seenfield records when the gateway made the observation. It is ona2a_agentsandA2AAgentRead.Changes
db.py,schemas.py: nullablereachable, newlast_seen.a2a_service.py:invoke_agentwrites both fields in the existing post-call write.set_agent_stateclears both fields on deactivation.c3e5a7b9d1f2addslast_seenand setsreachabletonullfor existing agents. The old value came from a column default, not from an observation.CHANGELOG.mdentry.Notes for reviewers
reachableas a boolean must handlenull.Testing