
# The doctor

The doctor, `/opt/agent-cloud/doctor.sh` on a private target's node, prints one JSON report on k3s, reachability, metadata isolation, manifests, pods and the runner's recent log. Run it whenever an install step, update or release on the target fails, and send the whole report.

A healthy node reads `"node_ready": "True"`, `"agent_cloud": "200"`, `"relay": "200"`, `"internet_blocked": true`, `"pod_metadata_denied": true` and `"manifests_behind": false`. In `runner_log`, credentials in URLs, `Bearer` values and `agc…_` tokens are redacted on the node before they're printed. It isn't `agc doctor`, which checks the `agc` install on a laptop.

## Ask your infra agent

```text
Run the Agent Cloud doctor on our target's node over SSM (on_node "/opt/agent-cloud/doctor.sh" from
infra-agent.md). Show me the JSON, and for every field that isn't the healthy value, say what it means.
Don't change anything on the node.
```

You'll get the report and a short reading of anything that's off.

## Steps

```bash
on_node "/opt/agent-cloud/doctor.sh"
```

`on_node` is infra-agent.md's SSM helper; the doctor runs as root on the node. After a [manifests update](/docs/targets/manifests-and-updates.md), `manifests_behind` is Agent Cloud's view as of the runner's last report (`reported` in `manifests_current`), so it can read `true` just after an apply. Run the doctor again; don't re-apply.

## How it works

The script ships twice: in the install bundle, for steps before the manifests exist, and in the ConfigMap `agent-cloud/agc-doctor` (key `doctor.sh`), which install step 5 and every manifests update write over `/opt/agent-cloud/doctor.sh`. So one hash and one `kubectl diff` cover the script that runs as root, and an update refreshes it.

Each check is built so that a broken check can't read as a pass:

| Check | How | Verdict |
|---|---|---|
| Reachability | `curl`'s own status for `https://agent.cloud/v1/health` and `https://relay.agent.cloud/healthz` (10 seconds each) and `https://example.com` (5 seconds) | `internet_blocked` is `true` only when the last couldn't connect at all (`000`) |
| Host IMDS | An IMDSv2 token from the node itself (2 seconds) | Reported as `imds_from_host`; `"200"` when it succeeds |
| Pod IMDS | `kubectl exec` in a running pod in any `app-*` namespace, with `python3` or `node`, ignoring the app's own `HTTP_PROXY` (60 seconds) | `true` only for `blocked`, `false` only when the metadata service answered with an HTTP status, otherwise `null` with `pod_probe_error`; null is never a verdict |
| Manifests | The stamp on `agc-runner` against `GET /runner/v1/manifests/version`, asked with the runner's own token | The answer goes through one JSON parser, so the report stays valid JSON even for an error page |

## Reference

| Field | Healthy value | Meaning |
|---|---|---|
| `node_ready` | `"True"` | The node's Ready condition; `unknown` if k3s doesn't answer |
| `agent_cloud` | `"200"` | HTTP status from `/v1/health`; `"000"` means no connection |
| `relay` | `"200"` | HTTP status from the relay's `/healthz` |
| `internet_blocked` | `true` | `false` means the node reached `example.com`; expected in a shared VPC with `InternetEgress=true` |
| `imds_from_host` | `"200"` | The node's own IMDSv2 token request |
| `pod_metadata_denied` | `true` | An app pod can't reach `169.254.169.254` |
| `pod_probe_error` | `null` | Why the pod probe had no verdict, such as `no running app pod to probe from` |
| `disk_used` | a low percentage | Root filesystem use |
| `manifests_version` | the current version | The stamp on the node's `agc-runner`; `"0"` if unstamped |
| `manifests_current` | object | Agent Cloud's answer: `version`, `reported`, `behind`, `why`, `missing` |
| `manifests_behind` | `false` | Whether the objects need an update |
| `storage_isolated` | `true` | From manifests version 7: the storage isolation proof. Agent Cloud offers app storage only while a passing run on current manifests stands; `null` when there's none to prove |
| `storage_checks` | | The canary's checks, or why it gave none, such as `no app storage on this target` |
| `storage_binding` | | The storage configuration the proof ran against; `null` without app storage |
| `storage_recorded` | `true` | Agent Cloud recorded this run's storage verdict |
| `pods` | | `kubectl get pods -A -o wide`, first 60 lines |
| `runner_log` | | Last 40 lines of the runner's log, with URL credentials, `Bearer` values and `agc…_` tokens redacted |

## Errors

| Value | Cause | Fix |
|---|---|---|
| `"agent_cloud": "000"` or `"relay": "000"` | The node can't reach Agent Cloud or the relay on 443 | Check the security group's `/32` rules and any TLS-inspecting proxy; the relay connection can't be inspected |
| `"pod_metadata_denied": false` | An app pod reached the metadata service | Treat as a security incident: check the instance's hop limit is 1 and the `tenant-isolation` NetworkPolicy ([Tenant isolation](/docs/security/tenant-isolation.md#isolation-on-private-targets)), and tell Agent Cloud |
| `"pod_metadata_denied": null` | No verdict; the reason is in `pod_probe_error` | Expected before the first app runs; otherwise read the reason |
| `"manifests_current": null` | The version route didn't answer with JSON (no token, no route out) | Check `agent_cloud` and the runner's registration |
| `doctor.sh is empty` | The install or update line's jsonpath lost its quoting | Run that line again exactly as written |

A node whose security group lost the relay's rule:

```json
{"node_ready": "True", "agent_cloud": "200", "relay": "000", "internet_blocked": true,
 "imds_from_host": "200", "pod_metadata_denied": true, "pod_probe_error": null, "disk_used": "31%", "manifests_version": "9", "manifests_current": {"version": 9, "reported": 9, "behind": false, "why": null, "missing": []}, "manifests_behind": false,
 "storage_isolated": null, "storage_checks": "no app storage on this target", "storage_binding": null, "storage_recorded": true,
 "pods": "…", "runner_log": "…"}
```

The console shows the same target Unhealthy with "The relay tunnel to relay.agent.cloud is down".

## Agent notes

- Send the whole report, not a summary; `runner_log` is often the answer.
- `internet_blocked: false` in a shared VPC is the honest value, not a fault.
- `manifests_behind` can lag an apply; run the doctor again rather than re-applying.

## Related

- [Installing with infra-agent.md](/docs/targets/installing-with-infra-agent-md.md)
- [Manifests and updates](/docs/targets/manifests-and-updates.md)
- [Architecture of a private target](/docs/targets/architecture-of-a-private-target.md)
- [Network and egress](/docs/targets/network-and-egress.md)
- [Tenant isolation](/docs/security/tenant-isolation.md#isolation-on-private-targets)

<!-- feedback:start -->
---
Wrong, outdated or unclear? Run `agc feedback docs "targets/the-doctor: <what is wrong>" --body <file>` with the sentence quoted in the file. No code or app data is sent.
<!-- feedback:end -->
