File size: 14,879 Bytes
983e562 c8c30b4 983e562 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | <!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SOPs β Admin</title>
<link rel="stylesheet" href="/css/nav.css?v=4">
<link rel="icon" type="image/svg+xml" href="/static/favicon.svg">
<style>
* { box-sizing: border-box; }
body { background: #0d1117; color: #e6edf3; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; margin: 0; }
.page-content { max-width: 900px; margin: 0 auto; padding: 32px 20px; }
h1 { font-size: 24px; margin: 0 0 4px; }
.sub { color: #8b949e; font-size: 14px; margin-bottom: 24px; }
h2 { font-size: 14px; color: #f0b90b; margin: 0 0 16px; letter-spacing: 1px; text-transform: uppercase; }
.card { background: #1e2329; border: 2px solid #30363d; border-radius: 12px; padding: 20px; margin-bottom: 20px; }
.sop-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.sop-num { font-size: 13px; font-weight: 700; color: #0b0e11; background: #f0b90b; border-radius: 6px; padding: 4px 10px; white-space: nowrap; }
.sop-title { font-size: 18px; font-weight: 700; }
.sop-meta { color: #8b949e; font-size: 12px; margin-bottom: 16px; }
details { border: 1px solid #30363d; border-radius: 10px; margin-bottom: 12px; background: #161b22; }
details summary { cursor: pointer; padding: 12px 16px; font-size: 14px; font-weight: 700; color: #e6edf3; list-style: none; display: flex; align-items: center; gap: 8px; }
details summary::-webkit-details-marker { display: none; }
details summary::before { content: 'βΈ'; color: #f0b90b; font-size: 12px; transition: transform .15s ease; }
details[open] summary::before { transform: rotate(90deg); }
details .body { padding: 4px 16px 16px; font-size: 13.5px; line-height: 1.65; color: #c9d1d9; }
.cmd { font-family: 'SF Mono', Monaco, monospace; font-size: 12px; background: #0d1117; border: 1px solid #30363d; border-radius: 8px; padding: 10px 12px; margin: 8px 0; overflow-x: auto; white-space: pre; color: #7ee787; }
.note { background: #1a2333; border-left: 3px solid #58a6ff; border-radius: 0 8px 8px 0; padding: 10px 14px; margin: 10px 0; font-size: 13px; color: #c9d1d9; }
.warn { background: #33261a; border-left: 3px solid #f0b90b; border-radius: 0 8px 8px 0; padding: 10px 14px; margin: 10px 0; font-size: 13px; color: #e3b341; }
.danger { background: #3a1a1a; border-left: 3px solid #f87171; border-radius: 0 8px 8px 0; padding: 10px 14px; margin: 10px 0; font-size: 13px; color: #f87171; }
ol { padding-left: 22px; margin: 8px 0; }
ul { padding-left: 22px; margin: 8px 0; }
li { margin-bottom: 6px; }
.ok { color: #4ade80; }
.bad { color: #f87171; }
b, strong { color: #e6edf3; }
</style>
</head>
<body>
<nav class="nav-bar">
<div class="nav-brand">π Blind Monkeys</div>
<div class="nav-links">
<a href="/admin" class="nav-link">π οΈ Admin</a>
<a href="/" class="nav-link">\ud83c\udfe0 Home</a>
</div>
</nav>
<div class="page-content">
<div class="breadcrumbs"><a href="/">Home</a><span class="bc-sep">βΊ</span><a href="/admin">Admin</a><span class="bc-sep">βΊ</span><span class="bc-current">SOPs</span></div>
<h1>π Standard Operating Procedures</h1>
<p class="sub">Runbooks for operating and recovering the Blind Monkeys platform.</p>
<div class="card">
<h2>Architecture Quick Map</h2>
<div style="font-size:13.5px;line-height:1.7;color:#c9d1d9;">
<b>blindmonkeys.org</b> (main Flask site) β Cloudflare DNS β Cloud Run service
<b>portfolio-agent-public</b>, project <span class="cmd" style="display:inline;padding:2px 6px;">project-46559977-eb74-48c3-a1e</span>, region us-central1.<br>
<b>Dynamic data</b> β GCS bucket <span class="cmd" style="display:inline;padding:2px 6px;">portfolio-agent-data-388170800364</span>
(users, scans, P/L, settings; written by the 15-min crons).<br>
<b>Scanner + trader</b> β Cloud Run <span class="cmd" style="display:inline;padding:2px 6px;">blind-monkeys-scanner</span> /
<span class="cmd" style="display:inline;padding:2px 6px;">blind-monkeys-trader</span>, project
<span class="cmd" style="display:inline;padding:2px 6px;">gen-lang-client-0223878158</span>, region europe-west1;
trader state in bucket <span class="cmd" style="display:inline;padding:2px 6px;">blind-monkeys-trader-state</span>.<br>
<b>Source of truth</b> β git.sr.ht/~deanpowers/blind-monkeys (public repo, mirrors production).
</div>
</div>
<!-- ================= SOP 1 ================= -->
<div class="card">
<div class="sop-head">
<span class="sop-title">Restore blindmonkeys.org from Google Cloud</span>
<span class="sop-num">SOP #1</span>
</div>
<div class="sop-meta">Applies when the site is down, serves the wrong content, or its data is missing. Authored 2026-11-04 after the domain-hijack incident of 2026-11-02 β 2026-11-04 (full history: CHANGELOG.md, 2026-11-04 entry).</div>
<details open>
<summary>Step 1 β Diagnose: find out WHAT is broken</summary>
<div class="body">
<p>Run these checks in order and compare with the expected results:</p>
<div class="cmd">curl -s https://blindmonkeys.org/ | grep -o '<title>.*</title>'
# expect: <title>Blind Monkeys</title> (anything else = wrong content is being served)
curl -s -o /dev/null -w '%{http_code}\n' https://blindmonkeys.org/performance
# expect: 200
dig +short blindmonkeys.org
# expect: Google IPs (172.217.x.x β¦) when grey-cloud, or Cloudflare IPs
# (104.21.x / 172.67.x) when orange β but title check above is the real test
gcloud run services list --project project-46559977-eb74-48c3-a1e --region us-central1
# portfolio-agent-public must be present and serving
gcloud beta run domain-mappings list --project project-46559977-eb74-48c3-a1e --region us-central1
# blindmonkeys.org -> portfolio-agent-public must show status True (healthy cert)</div>
<p>Then pick the matching scenario below:</p>
<ul>
<li>Title is <b>not</b> "Blind Monkeys" β <b>Scenario A</b> (domain is serving something else)</li>
<li>Cloud Run service missing, erroring, or a bad revision is live β <b>Scenario B</b> (redeploy / rollback)</li>
<li>Site loads but data is gone (users, history, scans) β <b>Scenario C</b> (data bucket restore)</li>
</ul>
</div>
</details>
<details>
<summary>Scenario A β Domain serves the wrong content (hijack or bad DNS)</summary>
<div class="body">
<p><b>What happened 2026-11-02:</b> a Next.js deployment on Cloudflare claimed
<b>blindmonkeys.org</b> as a Worker custom domain and replaced the Flask site with a
blank scaffold. The Flask app and data were untouched β only routing was wrong.</p>
<ol>
<li>In Cloudflare β <b>Workers & Pages</b> β open the offending site β
<b>Settings β Domains & Routes</b> β remove the
<b>blindmonkeys.org</b> custom domain. This releases the hostname.</li>
<li>In <b>DNS β Records</b>, set the apex records for <b>blindmonkeys.org</b> to Google
Cloud Run, proxy <b>OFF (grey cloud)</b>:
<div class="cmd">AAAA @ 2001:4860:4802:32::15 (grey)
AAAA @ 2001:4860:4802:34::1 (grey)
AAAA @ 2001:4860:4802:36::15 (grey)
AAAA @ 2001:4860:4802:38::15 (grey)
A @ 216.239.32.21 (grey)
A @ 216.239.34.21 (grey)
A @ 216.239.36.21 (grey)
A @ 216.239.38.21 (grey)</div></li>
<li>Leave the TXT records (DMARC, google-site-verification) and the subdomain
CNAMEs (scan / charts / positions / thumbnails β ghs.googlehosted.com, grey) as they are.</li>
<li>Wait for DNS to propagate (usually minutes), then re-run the Step 1 checks.</li>
</ol>
<div class="note"><b>Note:</b> orange-cloud (proxied) apex records pointing at Google IPs also
work β Cloudflare proxies to Cloud Run β but grey-cloud with Google's managed cert is the
pre-incident baseline. If Cloudflare reports "A DNS record managed by Workers already exists
on that host", remove the Worker custom domain first (step 1), then edit DNS.</div>
</div>
</details>
<details>
<summary>Scenario B β App is down, broken, or a bad revision is live</summary>
<div class="body">
<ol>
<li>Check service health on its direct URL:
<div class="cmd">curl -s -o /dev/null -w '%{http_code}\n' https://portfolio-agent-public-388170800364.us-central1.run.app/
gcloud run revisions list --project project-46559977-eb74-48c3-a1e --region us-central1 --service portfolio-agent-public</div></li>
<li><b>Fastest fix β roll back</b> to the last known-good revision:
<div class="cmd">gcloud run services update-traffic portfolio-agent-public \
--to-revisions PREVIOUS_REVISION=100 \
--region us-central1 --project project-46559977-eb74-48c3-a1e</div></li>
<li><b>Or redeploy from source</b> (run from the repo / workspace root β this is what runs in production):
<div class="cmd">gcloud run deploy portfolio-agent-public --source . \
--region us-central1 --project project-46559977-eb74-48c3-a1e</div>
Environment variables and Secret Manager bindings persist across deploys β no extra flags needed.</li>
<li>Verify with the Step 1 checks, plus key APIs:
<div class="cmd">curl -s https://blindmonkeys.org/api/ai-visibility | head -c 200
curl -s https://blindmonkeys.org/api/bot-pnl | head -c 200</div></li>
</ol>
<div class="note">The canonical source lives at git.sr.ht/~deanpowers/blind-monkeys and
must mirror production. Deploy from a checkout of that repo.</div>
</div>
</details>
<details>
<summary>Scenario C β Data bucket was wiped (restore from GCS soft delete)</summary>
<div class="body">
<p>All buckets have <b>soft delete enabled with 7-day retention</b> β objects deleted
(or overwritten) stay recoverable for a week.</p>
<ol>
<li>Inventory what was deleted (recursive β subdirectory objects are easy to miss):
<div class="cmd">gcloud storage ls -l --soft-deleted --recursive gs://portfolio-agent-data-388170800364/
# trader state:
gcloud storage ls -l --soft-deleted --recursive gs://blind-monkeys-trader-state/</div></li>
<li><b>Read the output carefully.</b> Each line ends with
<span class="cmd" style="display:inline;padding:1px 6px;">objectname#GENERATION</span>.
The <b>highest generation number per object name is the newest pre-incident version</b> β restore that one.</li>
<li>Restore each object via the REST API (gcloud 589 has no
<span class="cmd" style="display:inline;padding:1px 6px;">objects restore</span> command yet):
<div class="cmd">TOKEN=$(gcloud auth print-access-token)
curl -X POST \
-H "Authorization: Bearer $TOKEN" \
"https://storage.googleapis.com/storage/v1/b/portfolio-agent-data-388170800364/o/OBJECT_NAME/restore?generation=GENERATION"</div>
URL-encode the object name (slashes become %2F). Restore fails if a live object with
the same name exists β back up and delete the live one first if needed.</li>
<li>Restore the trader-state bucket the same way (same command, bucket
<span class="cmd" style="display:inline;padding:2px 6px;">blind-monkeys-trader-state</span>).</li>
<li>If an entire <b>bucket</b> was deleted (not just its contents):
<div class="cmd">gcloud storage buckets restore gs://BUCKET_NAME</div></li>
</ol>
<div class="warn"><b>Beware false alarms:</b> files rewritten every 15 minutes by the crons
(admin_stats.jsonl, latest_scan_*.json, alerts.json, β¦) accumulate thousands of soft-deleted
generations from normal overwrite churn. A real wipe shows every object soft-deleted at the
<b>same moment</b>. Check the describe output before panicking:
<div class="cmd">gcloud storage objects describe --soft-deleted \
gs://portfolio-agent-data-388170800364/FILE.json#GENERATION \
--format="value(name, generation, softDeleteTime)"</div></div>
<div class="danger">Soft-deleted objects older than 7 days expire permanently, and objects
deleted while soft delete was disabled on the bucket are not recoverable. Act quickly.</div>
</div>
</details>
<details>
<summary>Step 2 β Final verification checklist</summary>
<div class="body">
<ul>
<li><span class="ok">β</span> <b>curl -s https://blindmonkeys.org/</b> β 200, title "Blind Monkeys"</li>
<li><span class="ok">β</span> /performance, /scan, /financials β 200 and tables render</li>
<li><span class="ok">β</span> /api/ai-visibility and /api/bot-pnl return real JSON data</li>
<li><span class="ok">β</span> scan.blindmonkeys.org/summary β 200</li>
<li><span class="ok">β</span> Telegram: grid/futures alerts still arriving (check the newest message age)</li>
<li><span class="ok">β</span> Bybit: positions and bots intact, balance unchanged</li>
<li><span class="ok">β</span> gcloud run services list in <b>both</b> projects β all revisions serving</li>
<li><span class="ok">β</span> gcloud scheduler jobs list β jobs enabled, last run OK</li>
<li><span class="ok">β</span> Log the incident and fix in CHANGELOG.md, and update CONTINUITY.md if architecture changed</li>
<li><span class="ok">β</span> Push the docs + any code changes to git.sr.ht/~deanpowers/blind-monkeys</li>
</ul>
</div>
</details>
</div>
<div class="card">
<h2>Upcoming SOPs</h2>
<div style="font-size:13.5px;color:#8b949e;line-height:1.7;">
Planned: SOP #2 β Full platform wind-down (pause Cloud Scheduler in both projects,
DRY_RUN=true on the trader, liquidate via Bybit β see CONTINUITY.md Β§8).
To add a new SOP, edit <span class="cmd" style="display:inline;padding:2px 6px;">templates/admin_sops.html</span>
and give it the next number.
</div>
</div>
</div>
<script src="/css/nav.js?v=16"></script>
</body>
</html>
|