# ISS-0104 Plan: Slow query / TopSQL data proxy not supported for Azure clusters — agent should detect and warn

## Background

GitHub issue #634: workspace ws-1780454500112-2b3ee0a48 (prod, astran customer, lingtao.li@pingcap.com)

User feedback: "Slow query Synapse drill-down fails on schema/type handling"

"Synapse" refers to Azure Synapse Analytics — the query engine used by the Clinic data proxy
for Azure-hosted TiDB Cloud Dedicated clusters. According to the clinic-api data-proxy
SUBSKILL.md, Azure is explicitly not supported:

> | Azure | No | - | Not yet supported |

When collect_evidence.py A3 (slow_query) or A4 (topsql) is executed for an Azure cluster,
the data proxy query will fail. The failure mode is "schema/type handling" error, indicating
the data proxy returns an error or unexpected schema when the Azure backend is attempted.

## What Went Wrong

1. **collect_evidence.py does not check the cloud vendor before querying data proxy.**
   For Azure clusters, A3 (slow_query) and A4 (topsql) are executed despite the backend
   not supporting Azure. This results in errors that are silently recorded in
   `evidence_summary.errors` but don't surface clearly to the user.

2. **The agent proceeds to diagnose without slow query / TopSQL data**, potentially giving
   a low-quality diagnosis while the user believes the analysis included all data sources.

3. **"schema/type handling" error** suggests that when the Synapse/Azure backend returns
   an unsupported response (e.g., different column types, missing schema, or HTTP error),
   the Python code in collect_evidence.py fails to parse the response, raising a type error.

## Relevant Code

- `agentkit/skills/builtin/tidb-clinic-diagnosis/scripts/collect_evidence.py`
  - A3 segment: slow_query_logs query via data proxy
  - A4 segment: topsql query via data proxy
  - Provider detection: uses `cluster_meta["provider"]` (populated from `clusterProviderName`)

- `agentkit/skills/nutshell-skills/platform/clinic-api/data-proxy/SUBSKILL.md`
  - Documents Azure as not supported

## Fix Plan

### Step 1: Detect Azure clusters early in collect_evidence.py

In the A0 (cluster metadata) segment, after fetching cluster_meta:

```python
cloud_provider = cluster_meta.get("provider", "").lower()
if cloud_provider in ("azure",):
    print("WARNING: Azure clusters are not supported by Clinic data proxy.")
    print("TopSQL and SlowQuery data will not be available.")
    # Write to evidence_summary errors
    summary["errors"].append({
        "segment": "data_proxy",
        "error": f"Azure cluster detected: data proxy does not support Azure (vendor={cloud_provider}). TopSQL and SlowQuery data unavailable."
    })
```

### Step 2: Skip A3/A4 for Azure clusters

Add a guard at the start of A3 and A4 segments:

```python
# A3: SlowQuery
if cloud_provider in ("azure",):
    summary["slow_queries"] = {"error": "Skipped: Azure clusters not supported by data proxy"}
else:
    # existing A3 logic
    ...

# A4: TopSQL
if cloud_provider in ("azure",):
    summary["topsql_tidb"] = {"error": "Skipped: Azure clusters not supported by data proxy"}
    summary["topsql_tikv"] = {"error": "Skipped: Azure clusters not supported by data proxy"}
else:
    # existing A4 logic
    ...
```

### Step 3: Add explicit warning to SKILL.md

In tidb-clinic-diagnosis SKILL.md, add a note under the "Data Sources" section:

> **Azure clusters**: Clinic data proxy does not support Azure clusters. TopSQL and SlowQuery
> data will not be available. Diagnosis will rely on metrics, Loki logs, and Activity Hub events only.
> Inform the user of this limitation at the start of diagnosis.

### Step 4: Surface limitation clearly in diagnosis output

When Azure is detected, the agent should output:

```
⚠️ Note: This cluster is hosted on Azure. Clinic's data proxy does not currently support
Azure clusters, so TopSQL CPU attribution and SlowQuery drill-down are unavailable.
The diagnosis will use metrics, error logs, and cluster events as the primary data sources.
```

## Verification

1. Run collect_evidence.py on an Azure cluster ID — should skip A3/A4 with clear warning
2. Check evidence_summary.errors for the Azure limitation notice
3. Verify the agent mentions the limitation in the diagnosis output
4. No "schema/type handling" errors should appear during the run
