Session Memory / Runtime

Kraken-only broker lock, live status, and deployment rules.
MEMORY.md
# MEMORY

Last updated: 2026-07-30 (regime v1.1 + promote bypass, bot 5.2.19)

**Read this first in new sessions.** Also read `ARCHITECTURE.md`, `STRATEGY.md`, `ISSUES.md`, `OVERHAUL_PLAN.md` (Selective PnL standing law), `config/overhaul_board.json`, and `config/strategy_watchboard.json`.

## What this repo does
Kraken Futures trading bot (`PF_XBTUSD`) — hourly adaptive long/short scoring, risk controls, IOC/taker live entry (maker optional), shadow testing, dashboard, public reviewer exports. Strategy 2.0 paper desk **retired 2026-07-28** (engine/DB kept for autopsy).

## Production server
| Item | Value |
|------|-------|
| Droplet | `165.227.175.240` |
| Service | `cryptobot-kraken` |
| Strategy 2.0 | `cryptobot-strategy2` **disabled** (`STRATEGY2_ENABLED=false`; never re-enable on deploy) |
| Maintenance | `cryptobot-maintenance.timer` (30 min) |
| Review export | `cryptobot-review-export.timer` (30 min) |
| Push | `cryptobot-push` |
| DB | `/var/lib/crypto-bot/kraken_futures_state.db` |
| Strategy 2.0 DB | `/var/lib/crypto-bot/strategy2_state.db` (retained; service off) |
| Status | `/var/www/crypto-bot/kraken/status.json` |
| Dashboard | http://165.227.175.240/kraken/ (nav → **Watchboard** + **Overhaul**; slim Overview) |
| Watchboard | `config/strategy_watchboard.json` → status.json `watchboard` → `watchboard.html` |
| Deploy | `./deploy_to_do.sh 165.227.175.240 update` from **`main` only** (branch guard enforced; writes `deploy/deploy.json`) |
| Strategy env | `tools/apply_kraken_strategy_phase_env.sh` → `/etc/crypto-bot-kraken.env` |
| Risk env | `tools/apply_kraken_selective_risk_env.sh crypto-bot-do` (legacy 5/day blocked) |
| Overhaul | `config/overhaul_board.json` → `overhaul.html` (Selective PnL standing law) |
| Health | `python3 tools/check_droplet_health.py --host 165.227.175.240` |
| SSH | `~/.ssh/config` Host `crypto-bot-do` + `165.227.175.240` → `~/.ssh/cursor_cloud_droplet_ed25519`; deploy scripts use `tools/resolve_droplet_ssh.sh` |


## Current runtime (2026-07-30 ~19:22 UTC — regime stability v1.1 + promote bypass)
- Live: `health=ok`; provider `kraken_futures` / `PF_XBTUSD`; version `5.2.19`; strategy `adaptive_long_short_score_v1.1`; `cryptobot-kraken` active; ready=true
- **Deploy:** `main` @ `00df958` (2026-07-30 ~19:22 UTC)
- **Regime v1.1 live:** ADX momentum (soft 18 + rising), structure demotion (weak 1h ADX alone no longer demotes SU), 12h breakout override (4h-aligned), 2-bar hysteresis, **B13 promote hysteresis bypass** (SU/SD promote commits immediately)
- **Live gates unchanged:** hourly ADX min **20**, anti-chase **1.5 ATR**; `SCORING_RECOVERY_RELIEF_ENABLED=false`
- **Shadow:** `recovery_relief` — recovery-only ADX floor **13**, anti-chase **2.0 ATR** (paper only)
- **Reclaim gates:** uptrend hourly promote on; conviction **68/4/12**; post-SU anti-chase grace **2.0 ATR × 2h**
- **Phase 0 levers live:** `MAX_TRADES_PER_DAY=1`, `COOLDOWN_MINUTES=360`, `SCORING_RANGE_THRESHOLD=999`, short-only-SD
- **Risk (~$100):** `MAX_POSITION_USD=40`, `MAX_RISK_USD_PER_TRADE=2`, `MAX_DAILY_LOSS_USD=5`
- **Watchboard:** seasoning regime v1.1 + reclaim gates; `recovery_relief` parked watching; candidates empty; `promote_anything=false`
- **Local suite:** **544 OK**; server deploy suites **544 OK** (157+170+89+109+19); health PASS

## Operator 24–48h checklist (dashboard Watchboard — 7 items)
1. Health ok + ready
2. Selective density (≤1–2/day, CD≥180)
3. Flat in range (thr 999)
4. Reclaim gates (uptrend promote + conviction 68/4/12 + SU grace)
5. Phase 0 safety (ATR stops, short-only-SD, ~$40/$2 sizing)
6. Do not promote shadows
7. Regime v1.1 — earlier SU/SD on real trends; fewer SD↔recovery flips (watch `regime_raw` vs committed)

## Strategy 2.0 (retired 2026-07-28)
| Item | Value |
|------|-------|
| Status | Failed promote — do not revive |
| Evidence | 2 trades, 0 wins, PF 0, equity $100→$98.07; Settings contamination via live Phase 0 range=999; funding veto 0 |
| Rule | Future paper desks use **isolated Settings**; never inherit live Phase levers |
| Artifacts | `strategy2/` code + `strategy2_state.db` kept for autopsy |

## Code architecture (quick map)
```
cryptobot-kraken.service → bot.py::run_async() → run_once()
  timing_guards.py                   candle boundary + stamp policy
  strategies/adaptive_long_short.py  production signals + tip-cache + VWAP pullback relief
  risk/risk_manager.py               equity-first sizing + daily limit + flip reentry
  broker/kraken_futures_client.py    monotonic nonce + min-lot close sizing + market_context fetch
  config/strategy_watchboard.json    Watchboard + check_next_48h checklist
  web/watchboard.py + status_writer  Overview + Watchboard + Overhaul (slim nav)

cryptobot-strategy2.service → DISABLED (strategy2/ retained for autopsy)
```

## Tests
- Deploy suites run via `deploy_to_do.sh` on server after sync
- Deploy traceability: `tests/test_deploy_info.py`, `tests/test_deployment_hardening.py`

## Git
- **Production branch: `main`** (trunk-based; see `.cursor/rules/08-trunk-git-workflow.mdc`)
- **Latest:** `0a0b23f` (handoff docs) · deploy on server `00df958` (code) · bot **5.2.19**
- Backup tags: `backup/main-pre-trunk-merge-20260723`, `backup/cursor-*-20260723`

## Shadow vs live (active)
Season regime v1.1 + reclaim gates + Selective PnL. Review shadows: funding, faster_time, **recovery_relief**, transition. **Watchboard candidates empty.** **`promote_anything=false`**. Live recovery relief **off** until shadow evidence.

## Open issues (priority)
1. Season regime v1.1 24–48h — watch false SU/SD from breakout override; whipsaw rate vs Jul 26–30 baseline
2. Season reclaim gates — watch false SU promote in chop + overnight long fills
3. Phase 1 observe continues — density/flat-range/kill PF
4. Phase 2 shadow/harness queue parked until OOS fidelity
5. Phase 3 one-lever promote (operator gate only)
6. **Real net PnL is negative** — expect recovery only after selective law seasons
7. Fix 2 (incremental IIR append) held

## Session handoff log
- **2026-07-30 ~19:30 UTC:** Docs/dashboard refresh — Watchboard + Overhaul banners, STRATEGY at-a-glance, OVERHAUL_PLAN Phase 0/1, MEMORY/ARCHITECTURE. Production still `00df958` / **5.2.19**.
- **2026-07-30 ~19:22 UTC:** Deployed **regime v1.1 follow-up** (`00df958`) — promote hysteresis bypass (`SCORING_REGIME_PROMOTE_HYSTERESIS_BYPASS_ENABLED`), Kraken OHLC replay + Jul 26–30 edge-case tests. Bot `5.2.19`. Local/server **544 OK**; health PASS; `status.deploy.git_commit=00df958`.
- **2026-07-30 ~19:01 UTC:** Deployed **regime stability v1.1** (`67b70b0`) — ADX momentum, structure demotion, breakout override, 2-bar hysteresis. Strategy `adaptive_long_short_score_v1.1`, bot `5.2.18`. Local/server **526 OK**; health PASS; `status.deploy.git_commit=67b70b0`.
- **2026-07-30 ~16:19 UTC:** Deployed **recovery relief shadow** (`6ece303`) — per-regime ADX 13 + anti-chase 2.0 ATR in recovery only; live unchanged. Local/server **523 OK**; health PASS; Watchboard parked `recovery_relief` watching.
- **2026-07-29 ~14:58 UTC:** Deployed **simplified Watchboard + Overhaul dashboard docs** (`42d0f65`) — plain summaries, last-edited timestamps, backtest notes, 6-item checklist. Server **515 OK**; health PASS; `status.deploy.git_commit=42d0f65`.
- **2026-07-29 ~14:34 UTC:** Deployed **compensating cancel** (`b1f69d2`) — ambiguous Kraken submit → best-effort cancel + status lookup before reconcile. Local **515 OK**; server suites OK; health PASS.
- **2026-07-29 ~14:09 UTC:** Deployed **reclaim gates** (`007d226` / `2851deb`). Uptrend promote + conviction 68/4/12 + SU grace 2.0×2h + equity-first $40/$2/$5. Local **509 OK**; health PASS; Watchboard candidates empty. `promote_anything=false`.
- **2026-07-28 ~12:48 UTC:** Deployed **S2 retirement + shadow prune** (`3a47078`).
- **2026-07-28 ~12:26 UTC:** Deployed **B13-mirror downtrend promote** (`40b68d2`).
- **2026-07-27 ~10:53 UTC:** Selective PnL Phase 0 **deployed** `801e2dd`.

## Rules for agents
- `.cursor/rules/04-memory-handoff.mdc` — update this file after deploy / runtime / strategy reviews
- `.cursor/rules/05-post-deploy-handoff.mdc` — after successful tested deploy: notes, commit, push
- `.cursor/rules/07-strategy-watchboard.mdc` — Watchboard + `check_next_48h` on live lever changes
- `.cursor/rules/09-selective-pnl-overhaul.mdc` — Selective PnL standing law; update `OVERHAUL_PLAN.md` + `config/overhaul_board.json`