
# Investigating a reported problem

When someone reports a problem, investigate it from production's records yourself. `agc capsule` shows what production did around an entity, incident or window, as shapes and counts, `agc logs` reads its scrubbed lines, and `agc up --at` reproduces it on masked data. Success is a fix shipped with `--fixes`.

```bash
agc capsule booking:123
```

## Execution contract

- **Before starting:** Get an entity or incident ID from the report, or a time window. Check the app's target before asking for history.
- **Do:** Read `agc capsule` and `agc logs`, reproduce with `agc up --at <time>` where supported, fix, add a regression check, then `agc check` and `agc ship --fixes "<what was reported>"`.
- **Success:** The regression check passes and the fix release returns exit 0 with `"outcome": "live"`.
- **If blocked:** For `target.private_data`, reproduce on a normal mirror with seed data; don't ask for production exports in chat.
- **Human handoff:** Relay any release decision and wait for the person; report unresolved failures.

## Ask your agent

```text
A parent says booking 123 never showed up in their account. Find out why and fix it.
Don't ask me for logs.
```

```text
The confirmation emails stopped going out. Check the worker's logs and tell me what's wrong.
```

The agent reads production itself. The person sees a fix release, and approves it if it changes the database.

## Steps

```bash
agc capsule booking:123
agc up --at 2026-10-20T13:45:00Z
agc replay booking:123
agc check
agc ship --fixes "booking 123 never showed up"
```

1. **Capsule.** Pass an entity id from the report (`type:id`), an incident id from the console (`inc_…`), or a window: `agc capsule --from 2026-10-20T13:30:00Z --to 2026-10-20T14:00:00Z`. Read the [logs](#logs) around it.
2. **Reproduce.** Start a mirror of production from just before the failure. It gets its own name (`at-20261020t1345`), so your working mirror is untouched.
3. **Replay** the entity's workflow steps on that mirror, then repeat what the person did.
4. **Fix and prove.** Add an invariant or smoke flow that fails without your fix and passes with it. Run `agc check`.
5. **Ship with `--fixes`.** Checks this release adds become held once it's live: a later ship that removes or changes them goes to a person.

## How it works

The capsule reads production's observability data and returns only what can't identify anyone:

| Field | What's in it |
|---|---|
| `workflow` | The entity's workflow events (name, entity, related, status, release, time), from the last 30 days |
| `requests` | Requests by route, status and release, with counts and p95 |
| `failed_requests` | 5xx requests in order, up to 30: route, status, duration, release |
| `errors` | Error log lines grouped by class (`…Error`, `…Exception`), code location (`file.ts:42`), message shape and release |
| `cluster` | Kubernetes warnings (restarts, OOM) by reason and release |
| `platform` | Agent Cloud's own events in the window: releases, approvals |
| `window` | The `from` and `to` it used |

Routes are reduced to segments the app's own source contains, and numbers become `<n>`. An error's `shape` keeps only lowercase words found in that release's source. You see the template a developer wrote ("booking not found for <x>"), never an email or a name. Request bodies and full messages never appear. Rehearsals ran on unmasked data, so their events are left out.

| Without a window you give | The capsule uses |
|---|---|
| An entity | Its first and last event, plus 10 minutes on each side |
| An incident | Its open time minus 15 minutes, to its resolution plus 5 |
| Any window | Capped at 24 hours, counted back from its end |

| The capsule shows | `next` suggests |
|---|---|
| Errors with a code location | `agc up` |
| A failed workflow step | `agc replay <entity>` |
| Failed requests | `agc check` |

`agc up --at` forks production as it was then (an ISO time, or relative like `90m`), masked like any mirror. History goes back about a day.

## Logs

`agc logs` returns your app's web and worker output in production, plus the platform's lines about them (started, restarted, out of memory), newest first. By default it reads the live release over the last 15 minutes, at most 200 lines. Success is `"ok": true` with the lines in `data.lines`.

```bash runnable
agc logs
agc logs --process worker
agc logs --level error --since 2h
agc logs --grep "payment"
```

```bash
agc logs --release v11
agc logs --release op_8c2e…
agc logs --follow
```

```json
{ "ok": true, "product": "agent.cloud", "command": "logs",
  "data": { "app": "camp-bookings", "release": "v12", "next": "lc_…",
    "lines": [{ "ts": "2026-10-20T14:03:11.204Z", "process": "worker", "release": "v12", "level": "error", "message": "send failed: provider answered 401" }] },
  "next": [{ "cmd": "agc logs --process worker --level error --before lc_…", "why": "the page before this one (data.next)" }] }
```

`next` fetches the page before through a sealed cursor that reveals nothing about any line. Don't build one. `--follow` prints one envelope per new line (NDJSON) until interrupted. It polls every 2 seconds and re-reads the five minutes before its newest line, so late lines still print and none prints twice.

Observability keeps each line's app, release, process, level and message for 30 days. Control scrubs every line before it leaves, replacing tokens, keys, URL credentials, cookies, JWTs and long opaque strings. It cuts each at 2,000 characters. The person sees lines unscrubbed in the console (Observability, Logs). `--grep` searches the scrubbed lines in control, so a match can't reveal a hidden value. It scans up to 10,000 lines per call. If it stops early, the `note` says so and `next` continues.

**Rehearsal lines** are open to you, scrubbed, so you can check a release before a person approves it. Use `--release rehearsal` for every rehearsal, or `--release <op>` for one ship's. They come from a branch of production with real data, so treat them as production output.

**Who may read.** A connected Builder or Read-only agent, or a Builder deploy key on its own app, at every autonomy level. Ship-only keys and task tokens get `agent.purpose`. Mirror-only and unclaimed agents get `logs.not_allowed`. Another person's app answers `app.unavailable`, so it never learns whether the app exists.

An empty window, or a target that sends Agent Cloud no logs, isn't an error: `"ok": true`, `lines: []` and a `note`, such as "No release is live yet. A rehearsal's lines are under --release rehearsal."

## Reference

| Command | Takes |
|---|---|
| `agc capsule <type:id>` | Entity: type 1–32 of `A-Za-z0-9_-`, id 1–64 of `A-Za-z0-9_.-` |
| `agc capsule inc_…` | Incident id, `inc_` or `obs_` plus 8–40 hex |
| `agc capsule --from <t> --to <t>` | Any two parseable times |
| `agc up --at <t>` | ISO 8601, or `<n>m` / `<n>h` ago; between 1 minute and 23 hours ago |
| `agc ship --fixes "<text>"` | Up to 200 characters |

| `agc logs` flag | Values | Default |
|---|---|---|
| `--process` | `web`, `worker` | both |
| `--release` | `v<N>`, `rehearsal`, a ship's `op_…`, a [PR preview's](/docs/ship/pr-previews.md) `pv_…` | the live release |
| `--level` | `error`, `warn`, `info` (`warn` includes errors) | all |
| `--since` | `15m`, `2h`, `7d` (1–4 digits plus `m`, `h` or `d`), or an ISO time within 30 days | `15m` |
| `--grep` | text, up to 200 characters, case-insensitive | none |
| `--limit` | 1 to 1000 | 200 |
| `--before` | the cursor from `data.next` | none |
| `--follow` | no value | off |

## Errors

Every code, its exit and fix: [Error code catalog](/docs/reference/error-code-catalog.md). On a private target, `agc up --at` answers `target.private_data`, as does `agc logs` unless the organization enabled customer log export. Reproduce on your normal mirror, which starts from seed data. An entity with no events in 30 days isn't an error: `"found": false` with a note to ask with a window.

```json
{ "ok": false, "product": "agent.cloud", "command": "capsule",
  "error": { "code": "capsule.about", "message": "\"pat@example.test\" is neither an entity (booking:123) nor an incident (inc_…).",
             "fix": "Use the id from the report you are investigating, or a window: agc capsule --from <time> --to <time>.", "retryable": false },
  "next": [{ "cmd": "agc help capsule", "why": "what you can ask about" }] }
```

## Where do my app's users' reports show up?

On the app's Work, once a person turns on **Users' reports file Work** in the app's settings. The app posts `{title, body, key}` to `AGC_WORK_URL` with `AGC_WORK_TOKEN`; while it's off the answer is `work.reports_off`.

## Agent notes

- An email or name isn't an entity id: ask for the booking number, or search by time.
- The capsule is evidence, not a diagnosis: reproduce before you fix.
- A fix with no new check isn't held. Add the check, even for a one-line fix.
- `logs.unavailable` means retry, never "no lines".
- Mirror logs aren't in `agc logs`; on a laptop, `agc up` shows them.
- Incident ids (`inc_…`) come from the console's app overview, not `agc status`.

## Related

- [Workflow events and replay](/docs/build/workflow-events-and-replay.md)
- [Held checks and fixes](/docs/checks/invariants.md#held-checks-and-fixes)
- [Incidents](/docs/ship/after-release-watch-and-rollback.md#incidents)
- [Reading production safely](/docs/data/reading-production-safely.md)

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