# Next.js Live Debugging: Code Changes Not Taking Effect

Systematic diagnostic flow when the user says "nothing changed" after a deploy.

## Step 1: Is the right process running?

```bash
ss -tlnp | grep PORT   # Note PID and START TIME
stat .next/BUILD_ID     # Compare build timestamp
```

If process start time is older than build time → running old code.

## Step 2: Kill ALL processes on the port

`kill PID` often misses child processes (Next.js spawns `next-server` as a child):

```bash
fuser -k PORT/tcp
sleep 1
ss -tlnp | grep PORT   # Must be empty
```

## Step 3: Verify compiled code has changes

```bash
grep -c "unique_new_string" .next/server/chunks/*.js
```

## Step 4: Check server error logs FIRST

```bash
cat /tmp/next_err.log 2>/dev/null | tail -20
```

Common silent failures:
- `DeepSeek 400: Prompt must contain 'json'` → add JSON to system prompt
- `DeepSeek 401` → bad/expired API key
- `EADDRINUSE` → zombie process on port

## Step 5: Test API directly (200 vs 500 vs old behavior)

```bash
curl -s -X POST http://localhost:PORT/api/endpoint \
  -H "Content-Type: application/json" \
  -H "Cookie: icoach_auth=1" \
  -d '{"test":"data"}' | python3 -m json.tool
```

## Step 6: .env.local changes need RESTART

`.env.local` is read at startup only. `process.env.X ?? 'default'` — env overrides default.
Check `.env.local` isn't unexpectedly overriding code-level defaults.
