# Red Team Adversarial Review — Agentic Stock Trading & Cross-Repricing Framework (v1.0 → v2.0 GCP-Flagship)

**Review Date:** 2026-11-20  
**Target Audited:** v1.0 Static Prototype (`stockmarketelephant.com/agents/`, `scripts/refresh_agents_feed.py`, `.github/workflows/refresh-agents.yml`, `PRD v1.0`)  
**Verdict:** **CONDITIONAL FAIL FOR LIVE CAPITAL — REQUIRES GCP-FLAGSHIP v2.0 REMEDIATION**  
**Summary:** v1.0 nailed live visual clarity (8 animated agents, `ANT` morning spotlight, Core-18 focus discipline, zero-leak security), **but would fail catastrophically if connected to live capital without fixing 6 P0 and 3 P1 structural defects**. Every single defect below has a clean, deterministic, **Google Cloud Platform (GCP)** architectural fix built into v2.0 (`sme-stock-agents`).

---

## Executive Risk Matrix

| ID | Severity | Vulnerability Class | What Breaks in v1.0 | GCP-Flagship v2.0 Fix |
|---|---|---|---|---|
| **RR-01** | **P0 · CRITICAL** | **GitHub Actions Cron Drift** | GitHub Actions `schedule:` routinely drifts **5–25 minutes** during 09:00–09:30 ET peak queues—useless for an `ANT` 09:30 opening-bell flush. | **Cloud Scheduler (`±1s` SLA) → Pub/Sub → Cloud Run** (`us-central1`) pushing live JSON to **Cloud Storage + CDN**. |
| **RR-02** | **P0 · CRITICAL** | **Zero Premarket Volume (`yfinance`)** | `yfinance` reports `0` volume for extended-hours bars. Thin 200-share premarket prints look identical to 4M-share institutional liquidation. | **Cloud Run Ingestion Adapter** consuming verified SIP/Alpaca/Polygon extended-hours volume stored in **BigQuery**; hard `volume_verified` gate blocks live promotion if `false`. |
| **RR-03** | **P0 · CRITICAL** | **Hand-Tuned Magic Weights (`0.42`, `ant_link`)** | Static `ant_link` weights and a magic `0.42` multiplier are uncalibrated curve-fits—and break immediately when the anchor rotates from `ANT` to `NVDA`, `CPI`, or `10Y Yield`. | **BigQuery + Cloud Run Empirical Correlation Engine**: rolling 20d OLS beta + rolling return correlation matrix `ρ_ij` + dynamic anchor election (highest `|gap_z|` shock). |
| **RR-04** | **P0 · CRITICAL** | **Browser `localStorage` Is Not a State Store** | Order state, alert thresholds, and Kill Switch status lived in browser RAM/`localStorage`—refreshing or crashing wipes positions & kill-switch locks! | **Google Cloud Firestore (Native Mode)** ACID transactional state store with optimistic locking (`positions`, `orders`, `kill_switch`, `daily_pnl`) + **BigQuery** immutable audit log. |
| **RR-05** | **P0 · CRITICAL** | **IPO Volatility & Spread Blowup (`ANT` Day-2)** | On `2026-11-20`, `ANT` swung `\$92.37 → \$83.47 → \$88.71` (`10.6%` premarket range!). A naive PM-high stop creates a massive `1R` that blows slippage/gap budgets on the 09:30 print. | **Deterministic Volatility & Spread Collar** in `Signal Hound`: auto-collars Day 1–5 IPOs or `1R > 2.5× normal ATR` into `WATCH_ONLY` until `09:45 ET` RTH range stabilizes. |
| **RR-06** | **P0 · CRITICAL** | **Cluster Beta Double-Counting** | Showing 10 simultaneous `PASS (SHADOW)` AI shorts (`ARM`, `AMD`, `SMCI`, `MU`, `PLTR`, `ORCL`, `META`, `SNOW`, `NVDA`, `MSFT`) risks taking `10×` the exact same `ANT`/QQQ factor bet. | **Portfolio Factor & Cluster Risk Cap** enforced in **Scale Tortoise + Signal Hound**: hard max **1 active slot (`\$500` `1R`) per correlated cluster** and `\$1,000` daily portfolio stop. |
| **RR-07** | **P1 · HIGH** | **Stale Feed / Corporate-Action Silent Corruption** | No hard `staleness_sec > 120s` kill breaker on quote timestamps; Yahoo `fast_info.previous_close` disagreed with `ANT`'s actual Day-1 RTH close (`\$92.60` vs `\$97.17`), requiring a manual patch. | **Deterministic Data Integrity Gate**: hard `staleness_sec <= 120s` breaker, exchange-official prior RTH close verification, and **Cloud Monitoring** alerting on feed drift. |
| **RR-08** | **P1 · HIGH** | **Prompt Injection via Market News & Filings** | Feeding raw scraped headlines/SEC filings into `Radar Owl` exposes the LLM to adversarial or spam headlines that could hijack trade direction. | **Vertex AI + Model Armor + Strict Schema Isolation**: `Radar Owl` runs read-only with constrained JSON enum output (`catalyst_type`, `polarity`, `confidence`) and **zero tool access** to execution or sizing. |
| **RR-09** | **P1 · HIGH** | **Unbounded LLM Latency & Token Burn** | Calling multi-turn LLM debates on all 18 stocks every 5 minutes adds 15–40s latency and blows past the `\$35/mo` GCP billing budget. | **Deterministic-First Funnel on Cloud Run**: pure NumPy/Pandas filters 18 stocks in `<200ms` (`\$0` tokens); **Gemini Enterprise (`gemini-decision-1` / `gemini-4-argon`)** scores *only* the top `≤ 3` candidates that clear `|RS_z| >= 0.75` and `Sync >= 75%` (`< \$4/mo` total). |
| **RR-10** | **P2 · MEDIUM** | **Monolithic Repo Coupling (Website + Agent Runtime)** | Keeping Python agent backend code inside the static GitHub Pages website repo mixes public HTML deployments with cloud runtime dependencies and CI permissions. | **Decoupled Dedicated Agent Repo (`sme-stock-agents`)**: owns Python runtime, Dockerfile, GCP IaC, unit tests, and publishes *only* sanitized JSON snapshots to `stockmarketelephant.com/agents/`. |

---

## Deep-Dive Breakdown of Critical (P0) Findings

### RR-01 · Why GitHub Actions Cron Fails Premarket Trading
GitHub Actions explicitly disclaims real-time cron guarantees: during market-open UTC spikes (`13:30–14:30 UTC`), scheduled workflows frequently fire **10–25 minutes late** or get silently dropped. If `ANT` cracks `\$83.00` at `09:05 ET`, a `09:27 ET` alert is forensic trivia, not a trading signal.
- **GCP Remediation:** **Cloud Scheduler** (`us-central1`, `America/New_York` timezone) triggers **Cloud Pub/Sub** (`sme-market-ticks`) at exact 1-minute or 5-minute intervals from `08:00` to `10:30 ET` with `±1s` jitter, invoking scale-to-zero **Cloud Run (`sme-stock-agents`)** with `min-instances=0` overnight (and optional `min-instances=1` only during `08:25–10:15 ET` via scheduled scaling if sub-second warm latency is needed, costing `< \$1.50/mo`).

### RR-02 · The Premarket Zero-Volume Blind Spot
On `2026-11-20`, `premarket-rs-scanner` and `yfinance` showed clean price drops on `ARM (-5.02%)` and `SNOW (-2.30%)`, but `yfinance` reports `Volume = 0` on all extended-hours bars. In real equity trading, a `-3%` gap on `1,200` premarket shares is a **liquidity vacuum that snaps back violently at 09:30**, whereas a `-3%` gap on `>20% ADV` is **institutional repricing**.
- **GCP Remediation:** Every `TickerSnapshot` carries `volume_verified: bool` and `pm_rvol: float | None`. While running on free `yfinance`, `Signal Hound` stamps every signal `UNVERIFIED_PM_VOLUME` and **blocks promotion past Shadow Mode**. In Phase 1, a Cloud Run feed adapter pulls verified extended-hours bars via **Secret Manager** credentials (Alpaca SIP or Polygon) into **BigQuery `sme_stock_agents.premarket_bars`**.

### RR-03 · Killing Magic Numbers (`0.42`, Static `ant_link`)
In v1.0, `implied_by_anchor = ant_gap * ant_link * 0.42` used a hand-picked scalar `0.42` and hardcoded `ant_link` weights. What happens next Tuesday when `ANT` is flat (`+0.1%`) and **NVDA earnings** or **10Y Treasury yields** are the real repricing shock? Hardcoding `ANT` as the permanent universe center makes the engine blind to the next catalyst.
- **GCP Remediation:**
  1. **Dynamic Anchor Election:** Every morning, `Repricing Octopus` elects the active shock anchor(s) automatically (any Focus-20 stock with `|gap_z| >= 2.0` or user-pinned priority watch like `ANT`).
  2. **Empirical Rolling Correlation Matrix:** Computed nightly in **BigQuery** from trailing 20-day/60-day daily + intraday returns (`corr_20d(i, anchor)` and `beta_20d(i, anchor)`), with explicit Bayesian shrinkage (`prior_weight` decaying as IPO trading days `n` grows from `Day 2 → Day 20` for `ANT`).

### RR-04 · Browser State vs. ACID Cloud State
In v1.0, clicking "Kill Switch Drill" only flipped a JavaScript boolean in the browser tab. A real trading kill switch must be **server-side, atomic, persisted across container restarts, and impossible for any cognitive agent to unset**.
- **GCP Remediation:** **Google Cloud Firestore** stores `system/kill_switch` (`armed`, `tripped`, `reason`, `tripped_at`, `tripped_by`), `portfolio/daily_state` (`realized_pnl`, `open_cluster_slots`, `active_risk_usd`), and `orders/{order_id}`. Every `Signal Hound` evaluation reads `system/kill_switch` inside a Firestore transaction before emitting any routing intent. Only a signed human admin call (or manual reset after audit) can clear a tripped breaker.

### RR-05 · IPO Spread & Volatility Collar (`ANT` Live Evidence)
Today's real `ANT` tape proved why a blind `1R = |entry - PM_high|` rule is dangerous on a Day-2 IPO: `ANT` traded between `\$83.47` and `\$92.37` premarket (`\$8.90` range = `10.1%`). Buying/shorting at `\$88.03` with a `\$92.37` stop means `1R = \$4.34/share` (`4.93%` stop!), and opening-auction prints routinely gap `\$1.50–\$3.00` through limit orders.
- **GCP Remediation:** `Signal Hound` enforces a deterministic **IPO & Volatility Collar**:
  - If `ipo_days_listed <= 5` OR `stop_distance_pct > 2.5 * normal_atr_pct`, the policy gate **hard-collars** the ticket to `WATCH_COLLAR` (alerts fire, zero automated routing) until at least `09:45 ET` after the opening auction spread normalizes.

### RR-06 · Stopping Correlated Cluster Stack Blowups
In v1.0, 12 out of 18 focus stocks fired `PASS (SHADOW)` on the exact same `ANT` AI-selloff catalyst. Even with `\$500` `1R` per trade, taking 6 AI shorts (`ARM`, `AMD`, `SMCI`, `MU`, `PLTR`, `NVDA`) is actually **one `\$3,000` (`6R`) leveraged bet on AI beta**—guaranteed to blow a `\$1,000` daily loss rail on a single `ANT` short-covering bounce.
- **GCP Remediation:** **Scale Tortoise** and **Signal Hound** rank candidates *within* each cluster by `convergence_score` and enforce **Portfolio Slot Selection**:
  - Max **1 active `PASS` slot per correlated cluster** (`Foundation AI`, `AI Silicon`, `Hyperscalers`).
  - Optional **1 orthogonal counter-slot** (`Rotation & Defense`, `ρ <= 0.15` vs active AI slot, e.g., `UNH`).
  - All runner-up tickers in an already-filled cluster are automatically downgraded to `CAPPED_CLUSTER_DUP` so total concurrent portfolio risk stays strictly `<= \$1,000`.

---

## Red Team Sign-Off Checklist (Required Before Phase 2 / Phase 3)
- [x] **RR-01:** Cloud Scheduler + Pub/Sub + Cloud Run IaC blueprint defined (`infra/gcp/pubsub_scheduler.sh`, `cloudrun-service.yaml`)
- [x] **RR-02:** `volume_verified` hard gate implemented in `src/sme_stock_agents/plumbing.py`
- [x] **RR-03:** Empirical rolling correlation + Bayesian IPO shrinkage + dynamic anchor election implemented in `src/sme_stock_agents/convergence.py`
- [x] **RR-04:** Firestore-backed transactional `StateStore` interface & persistent Kill Switch implemented in `src/sme_stock_agents/gcp_clients.py` & `plumbing.py`
- [x] **RR-05:** IPO & Volatility Collar (`ipo_days_listed <= 5` / `1R > 2.5x ATR`) implemented & unit-tested
- [x] **RR-06:** Cluster Correlation Slot Cap (`CAPPED_CLUSTER_DUP` after 1 slot per cluster) implemented & unit-tested
- [x] **RR-07:** Quote staleness breaker (`staleness_sec > 120s` → `REJECT_STALE`) implemented & unit-tested
- [x] **RR-08:** Typed JSON catalyst boundary (no untrusted headline execution path) enforced
- [x] **RR-09:** Deterministic-first funnel (`<= 3` Gemini calls per morning window) enforced
- [x] **RR-10:** Decoupled into dedicated `sme-stock-agents` private repository with clean public JSON contract
