> ## Documentation Index
> Fetch the complete documentation index at: https://prescale.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# prescale investigate

> prescale investigate runs a load ramp, finds the culprit route, then probes it to classify the bottleneck and give you a concrete fix to try.

`prescale investigate` does everything `prescale run` does — ramp virtual users, find what breaks first, and report the break point — then goes further. Once the ramp identifies the culprit route, `investigate` runs an active second-pass probe: baseline vs loaded latency, a static-vs-dynamic comparison, and error/header forensics. The result is a classified bottleneck type, a confidence level, and a concrete list of things to try. The whole process is fully local and deterministic — no LLM, no external service.

## Basic usage

```bash theme={"system"}
# Local app
prescale investigate http://localhost:8000

# Staging target — confirm you own it
prescale investigate https://staging.myapp.com --i-own-this

# Re-investigate the most recent saved run (no URL needed)
prescale investigate

# Machine-readable JSON output
prescale investigate http://localhost:8000 --json
```

## Example output

After the ramp, PreScale prints a standard verdict followed by the `🔬 Diagnosis` block:

```text theme={"system"}
 Users   Req/s    p50    p95   vs 2s wall          p99   Errors
    10     520   18ms   31ms   █            ┆       44ms      0%
    50     610   46ms  120ms   █            ┆      210ms      0%
    90     590   80ms  240ms   ██           ┆      900ms      0%
   150     410  180ms   2.1s   ░░░░░░░░▒▒▒██┆        3.4s      7%

Scale readiness: ⚠️  Survives ~90 (75–110) concurrent users
Traffic         ≈ 590 req/s, roughly 5,900 real visitors (one request per visitor every 10s)

🔬 Diagnosis
Likely cause: 5xx under load while static assets held — the app/backend is the wall.
Bottleneck  connection_pool (high confidence)  ·  culprit /api/search
Evidence
  • culprit p95 28ms at 1 user vs 2100ms at 150 users
  • static /assets/app.js held at 150 users
  • errors under load: 5xx (180)
Try this
  → Increase the DB/upstream connection-pool size.
  → Add a pooler (e.g. pgbouncer) and check the pool checkout timeout.
```

> Numbers are illustrative — your results depend on your app and infrastructure.

## How it works

`investigate` runs in two phases:

**1. Load ramp**

Identical to `prescale run`: virtual users ramp from 1 to `--max-users`, holding each level for `--stage-seconds`. PreScale records throughput, latency percentiles, and error rates at every step and identifies the first level that crosses the latency wall or error threshold.

**2. Active diagnosis probe**

Once the culprit route is known, PreScale fires a series of targeted probes against it:

* **Baseline vs loaded latency** — a single request at 1 user is compared to the culprit's p95 at peak load. A large delta (e.g. 28 ms vs 2 100 ms) points to a resource that saturates under concurrency.
* **Static vs dynamic comparison** — a static asset (CSS, JS, an image) is tested at the same load level. If the static file responds fine while the dynamic route degrades, the problem is inside the application layer, not the network or web server.
* **Error and header forensics** — response status codes, `Retry-After`, `X-RateLimit-*`, `CF-Cache-Status`, and similar headers are inspected to narrow down the category (connection pool exhaustion, rate limiting, CDN misconfiguration, etc.).

The evidence is combined into a bottleneck classification with a confidence level, and PreScale emits a prioritised "Try this" list of concrete remediation steps.

## Fix prompt

After the diagnosis, `investigate` prints a **fix prompt**: plain text to paste into Claude Code, Cursor or any coding agent. It says where it broke, at how many users, the likely cause, the evidence and the fixes, and asks the agent for the smallest change that fixes the cause and to re-run `prescale investigate` to confirm. It's built from the run itself, with no model, and never includes response bodies, secrets or credentials from the URL. It's also in `--json` and saved runs as `fix_prompt`, in the HTML report (`prescale show <id> --html`), and in the PR comment from the GitHub Action.

```bash theme={"system"}
prescale investigate http://localhost:3000 --json | jq -r .fix_prompt
```

## Journeys

When your repo has journeys in `prescale/journeys/`, `investigate` ramps them the way `prescale run` does, then diagnoses **the journey step that breaks first**. The step is probed with the journey's own state: its 1-user latency comes from replaying the journey from the start (log in, add to cart, then place the order), so a step that needs a token or a cart id is measured the way a real user reaches it. The journey's other steps play the part static assets play for URLs: if they held while this step failed, the limit is something this step uses, such as a database pool.

```text theme={"system"}
🔬 Diagnosis
Likely cause: 5xx under load while the journey's other steps held — the app/backend is the wall (often a DB or upstream pool).
Bottleneck  connection_pool (high confidence)  ·  culprit checkout, step 3 place order (POST /api/carts/{{cart_id}}/order)
Evidence
  • culprit p95 123ms at 1 user vs 178ms at 50 users
  • the journey's other steps (log in, add to cart) held at 50 users
  • errors under load: 5xx (25)
```

If the journeys ramped together starved the culprit journey (it broke with fewer of its own users than it held alone), the evidence says so too. If every journey held on its own but they broke ramped together, `investigate` diagnoses the step that broke in the combined run: that's journeys competing for something they share. A step that answers an unexpected 4xx under load (a 409, a 401) is classified as [`unexpected_answer`](https://prescale.dev/docs/reference/bottleneck-types), not as a pool or a queue. The 1-user baseline replays the journey for about 2 seconds after a 1-second pause, within `--max-rps`; if too few replays reach the step, the evidence says there's no baseline. `--urls` investigates URLs instead.

## Options

**url** `string`

The URL to investigate. Optional — if you omit it, PreScale re-investigates the most recent saved run's target URL. See [Re-investigating a saved run](#re-investigating-a-saved-run) below.

**--max-users / -u** `integer` (default: 200)

Peak virtual users to ramp to during the load phase. PreScale steps through load levels from 1 up to this number, holding each level for `--stage-seconds`.

**--stage-seconds / -s** `float` (default: 5.0)

How many seconds to hold each load level before stepping up. Increase this for a more thorough measurement; decrease it for a faster iteration cycle.

**--path** `string`

An extra route to include in the ramp, relative to the base URL (e.g. `--path /api/search`). Repeatable. The culprit is chosen from all routes tested, and the diagnosis probe focuses on whichever one breaks first.

**--max-rps** `float`

Cap aggregate requests per second across all virtual users. A safety ceiling for shared staging environments. By default there is no cap.

**--i-own-this** `boolean` (default: false)

Skip the interactive confirmation prompt for non-local targets. Required in CI and when using `--json`. See the [Safety](#safety) note below.

**--app COMMAND** `string`

Replica mode: start your app with COMMAND (for example `"npm run build && npm start"`), test it on the local URL, then stop it and everything it started. No host is involved. The URL must be local, and the command is never saved or uploaded. See [Replica mode](https://prescale.dev/docs/guides/replica-mode.md).

**--app-timeout** `float` (default: 600)

Seconds to wait for the app started by `--app` to answer. Production builds can take minutes.

**--host-permission** `boolean` (default: false)

Confirm you have the host's permission to load-test the target. Vercel, Netlify and Cloudflare restrict load testing; without this, PreScale asks first, or stops in `--json` mode. Also set by `PRESCALE_HOST_PERMISSION=1`. See [Host rules](https://prescale.dev/docs/reference/host-rules.md).

**--json** `boolean` (default: false)

Emit the full Result document — including the `investigation` block — as JSON to stdout instead of the human-readable terminal output.

```bash theme={"system"}
prescale investigate https://staging.myapp.com --i-own-this --json | jq .investigation
```

**--store DIR** `string`

Directory where PreScale reads and writes saved run JSON files. Defaults to `./.prescale`. Pass the same value you used with `prescale run` if you changed the default.

**--fail-under N** `integer`

Exit with a non-zero status code if the app survives fewer than N concurrent users. Use this as a CI gate alongside `--i-own-this` and `--json`.

**--journey NAME** `string`

Investigate only this journey (repeatable). Default: every journey in `prescale/journeys/`.

**--no-combined** `boolean` (default: false)

Skip ramping the journeys together, so there's no interference check.

**--urls** `boolean` (default: false)

Investigate URLs even when `prescale/journeys/` has journeys.

**--allow-writes HOST** `string`

Let journeys that change data (POST, PUT, PATCH, DELETE) run against this non-local host, e.g. a staging host. Repeatable. Without it, such journeys only run against local hosts.

**--dir DIR** `string` (default: prescale/journeys)

Where the journey files are.

## Safety

`investigate` sends real traffic — a full ramp plus a handful of diagnostic probes — to your target. The same safety rules that apply to `prescale run` apply here:

* **Local hosts** are tested without any prompt.
* **All other hosts** show a confirmation panel before the ramp starts.
* **Hosts that restrict load testing** (Vercel, Netlify, Cloudflare) get no load until you confirm you have the host's permission. See [Host rules](https://prescale.dev/docs/reference/host-rules.md).

Pass `--i-own-this` to skip the prompt in CI or `--json` mode, and `--host-permission` for a restricted host you have permission for. Or test your app's own build locally with [Replica mode](https://prescale.dev/docs/guides/replica-mode.md) and skip all three.

> [!WARNING]
>
> Always point `prescale investigate` at a **staging or preview** URL, not production, unless you fully understand the traffic volume it will generate.

## Re-investigating a saved run

Run `prescale investigate` with **no URL** and it looks up the most recent saved run in `.prescale/runs/`, reads its target URL, and re-investigates it:

```bash theme={"system"}
prescale investigate   # re-uses the URL from the latest saved run
```

This is useful when you've already run `prescale run` and want a deeper diagnosis without typing the URL again, or when you want to check whether a fix you deployed has changed the bottleneck classification.

If you store runs in a non-default directory, pass `--store DIR` so PreScale knows where to look:

```bash theme={"system"}
prescale investigate --store /tmp/prescale-ci
```

> [!NOTE]
>
> The **Bottleneck Types** reference page at [`reference/bottleneck-types`](https://prescale.dev/docs/reference/bottleneck-types) describes every classification PreScale can emit — what each bottleneck means, how it is detected, and what "high / medium / low confidence" signifies.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.