# Kade Persistent Runtime — Status Report

**From:** Riv
**To:** Kade
**Date:** 2026-05-24
**Status:** ✅ Built and registered, ⚠️ cutover requires one elevated step from Jimmie

---

## What shipped

1. **Scheduled task `KadeBot` registered** on `MINAS_TIRITH` under user `Minas_Tirith`.
   - Trigger: `AtLogOn` (current user)
   - Action: `C:\Python314\python.exe bot.py`
   - Working dir: `C:\PKA\Team\Riv\kade_slack` (so `.env` loads correctly)
   - Restart on failure: 1-minute delay, up to 999 attempts
   - MultipleInstances: `IgnoreNew` (prevents the scheduled task from spawning a second bot if one is already running under it)
   - Execution time limit: none (long-running bot)
   - RunLevel: Limited (no admin needed)

2. **`/api/kade/health` endpoint added** at `C:\PKA\Atlas\app\app\api\kade\health\route.ts` — GET with bearer auth, returns `{ ok, server_time, tz, db_reachable }`. Coordinated with Forge (we are wearing both hats this build).

3. **Bot startup ping wired** — `atlas_client.get_health()` added; `bot.py` calls it once at startup and logs the result. Non-fatal on failure.

## Verification

Started the scheduled task. Bot came up cleanly and produced this log sequence:

```
2026-05-24 17:38:00,342 [INFO] scheduler: Scheduler started in tz=America/Chicago
2026-05-24 17:38:00,343 [INFO] kade.bot: Jimmie's Slack user ID already pinned: U018CQPG4F5
2026-05-24 17:38:33,168 [INFO] httpx: GET /api/kade/meds/today "HTTP/1.1 200 OK"
2026-05-24 17:38:33,170 [INFO] scheduler: Scheduled fire Adderall:11:45am:2026-05-24
2026-05-24 17:38:33,170 [INFO] scheduler: Scheduled fire Adderall:afternoon:2026-05-24
2026-05-24 17:38:33,170 [INFO] scheduler: Scheduled fire Metformin:5:30pm:2026-05-24
2026-05-24 17:38:33,513 [INFO] slack_bolt.AsyncApp: A new session established
2026-05-24 17:38:33,514 [INFO] slack_bolt.AsyncApp: Bolt app is running!
```

✅ Meds loaded, fires scheduled, Slack connected. Persistent runtime works.

## ⚠️ Two follow-ups for Jimmie

### 1. Old foreground bot still alive (PID 24840) — needs one cutover step

When Jimmie launched the bot manually 2 days ago, it inherited an elevated/different security token. From this session I can't stop it (Access denied even with `Stop-Process -Force` and `taskkill /F`). To avoid double-fire I **immediately stopped the scheduled-task bot** after verification, so right now you're back to the original foreground bot until the cutover.

**Cutover options for Jimmie (pick one):**

- **Easy:** Reboot Minas_Tirith. AtLogon trigger fires KadeBot automatically once you log back in.
- **No reboot:** Open an **elevated** PowerShell on Minas_Tirith and run:
  ```powershell
  Stop-Process -Id 24840 -Force
  Start-ScheduledTask -TaskName "KadeBot"
  Get-Content "C:\PKA\Team\Riv\kade_slack\bot.log" -Tail 20
  ```
  Last command should show a fresh "Bolt app is running!" line.

### 2. Health endpoint returns 404 until Atlas is rebuilt

The `route.ts` file is in place, but PM2 is serving the previous build. Bot logs will show `Atlas health check FAILED on startup` until you do:

```powershell
# In an elevated PowerShell (PM2 daemon requires elevation per memory):
cd C:\PKA\Atlas\app
npm run build
pm2 restart atlas
```

The health-check failure is **non-fatal** — the bot still loads meds via `/api/kade/meds/today` (which IS live) and operates normally. It's just a noisy startup warning until Atlas is rebuilt.

## Manual stop/start one-liners

For future reference:

```powershell
# Status
Get-ScheduledTask -TaskName "KadeBot" | Select-Object TaskName, State
Get-ScheduledTaskInfo -TaskName "KadeBot" | Select-Object LastRunTime, LastTaskResult

# Start (manual run; ignored if already running due to MultipleInstances=IgnoreNew)
Start-ScheduledTask -TaskName "KadeBot"

# Stop (graceful — sends terminate to the python process)
Stop-ScheduledTask -TaskName "KadeBot"

# Tail log
Get-Content "C:\PKA\Team\Riv\kade_slack\bot.log" -Tail 30

# Disable temporarily (won't fire on logon)
Disable-ScheduledTask -TaskName "KadeBot"
Enable-ScheduledTask  -TaskName "KadeBot"

# Remove entirely
Unregister-ScheduledTask -TaskName "KadeBot" -Confirm:$false
```

## What's next from me

- **v0.2 bot handlers** — waiting on Forge's `kade-v02-tasks-api-contract.md`. Will ack on receipt.
- **v0.4 calendar bot commands** — waiting on Forge's calendar approach memo + contract.

— Riv
