# Inbox / Bot / Voice / Memory — Full System Review

**What it is:** System audit — command-inbox engine, Telegram bot, voice pipeline, transcripts, memory.
**Generated:** Thursday, June 25 2026 · 2:19 AM EDT (NY) · 10 Tamuz 5786 · by 🧠 Brain (session 5948b2be)
**Working dir:** `C:\Users\ztrei\OneDrive\2. Hook Street\05. 2026 BH` · ops-api restored to `8523bfaf`
**Method:** 3 parallel read-only review agents (engine code · repo/docs/queue · GitHub/notify/memory).
**⚠️ NOT pushed** — committing to master re-clobbers ops-api. Local record only until the build is split.

---

## 1. How it's set up (architecture)

**One Google Sheet, 7 tabs, 3 surfaces, one brain.**

- **Tabs:** `Action_Queue` (cards) · `Action_Events` (immutable audit) · `Grocery_List` · `INBOX` (raw capture of every message) · `OUTBOX` (every notification fired) · `Transcript` (every Telegram turn IN+OUT) · `Context` (entity facts).
- **Surfaces (all hit the same engine):** PWA (`start-here.html`) · iOS Shortcut · Telegram bot (@HSInboxBot, via a Cloudflare proxy worker).
- **Flow:** message → `doPost` captures to INBOX → `routeCommand_` (first-word commands) OR `telegramBrainReply_` (free text → Claude) → actions run through tested engine fns → reply sent → logged to Transcript (+ OUTBOX if relay).
- **Brain:** `callClaude_` with `buildClaudeContext_` (date/Hebcal + open queue + 25 Profile facts + Brain_Feed) + `recentTranscriptTurns_(12)` for memory; `<<<ACTIONS>>>` protocol lets it create/done/defer/grocery, logged as actor `(Telegram-AI)`.
- **Memory (#042, SHIPPED):** D1 catalog `hookstreet-memory` (~249 facts) unified with Claude-Code memory; `/memory/search` retrieval; nightly "Dreaming" cron (03:00 ET) consolidates Profile→D1 + retires stale rows. **Working.**
- **Voice:** bot → ops-api `/voice/transcribe` (Cloudflare Whisper, free) in; `/voice/speak` (OpenAI TTS) out. **Restored tonight.**

---

## 2. The keystone problem (fix this first — everything hangs on it)

**ops-api build collision.** A Cloudflare Workers Build targets worker name `ops-api` but reads the repo-root `wrangler.toml`, which is the **portal** (`name=hookstreet-ops`, assets=`outputs/`). **Every push to master** deploys the portal *over* the API worker → all API routes 404 → voice/Plaid/calendar die. Tonight's outage + the recurring "strands 30 secrets" freeze are the SAME bug.

- **Tonight:** restored production to documented-good `8523bfaf` (verified: health green, secrets intact, voice working).
- **Permanent fix (Cloudflare dashboard, ~30 min, deliberate):** split into two builds — portal build → name `hookstreet-ops` (root dir `/`), API build → name `ops-api` (root dir `ops-api/`). Then ops-api un-freezes.
- **Do NOT merge** the `update_worker_name_to_ops-api` branch — it makes the collision permanent.
- **Standing rule until split:** nobody pushes master. (Memory: `feedback_ops_api_master_push_clobber`.)

---

## 3. Code defects (clasp-deployable — does NOT touch the frozen worker or master)

| # | Issue | Location | Sev | Fix |
|---|---|---|---|---|
| 1 | Voice transcribe `JSON.parse` crashes on empty/404 body → the "🎙️ Voice pipeline error" Sam saw | `Code.js:372` | **P0** | check response code + guard empty/non-JSON; clear user message |
| 2 | TTS `/voice/speak` response parsed without status check → voice-out fails silently | `start-here.gs:2573` | P1 | guard HTTP status before parse |
| 3 | **Relay actor misread** — "tell Mom X" logs Transcript sender as *Mom*, not Sam → bot later thinks Mom spoke (the "cross-person actor" bug) | `Code.js:143` | P1 | log original `sender` + `recipient` meta |
| 4 | `#405` "Your day now" block appends on every queue touch (even proof-only) → stale-card spam | `start-here.gs:3531` | P2 | skip proof-only / throttle once per session |
| 5 | Hebcal Shabbos parse unguarded → Shabbos mute skipped on Hebcal outage | `start-here.gs:2371` | P2 | check status before parse |
| 6 | No retry on Twilio SMS send; no `timeout` on `UrlFetchApp` calls | `start-here.gs:2752` + multiple | P2 | backoff loop + `timeout:25000` |

Idempotency (webhook `update_id` dedup) and the brain API parse (line 528 guards it) are **solid**.

---

## 4. GitHub issues (in `hookstreet-workspace`) — overlap with queue cards

| Issue | Title | Maps to |
|---|---|---|
| **#35** | Telegram voice mic-loop repeats last phrase ~40× | voice card #180/#246 (long-note Whisper) |
| **#34** | No timestamped transcript-audit path (`recentTranscriptTurns_` strips timestamps; no range query) | transcript audit gap |
| **#26** | Bot conversational write-back (act on a sentence, with confirm guard) | brain actions protocol |
| **#27** | Bot autonomous powers — scoped, one at a time | backlog |

---

## 5. Open queue cards by theme (already tracked — don't duplicate)

- **Voice/transcript:** #180 (loop + Shabbos gate, P1) · #246 (LevSMS voice reliability/speed, P1) · #250 (mirror tuning) · #297 (photo/image input, P1) · #308 (transcribe forwarded WhatsApp audio)
- **Memory/brain:** #42 (cross-device sync — SOLVED by Cloud Memory Layer) · #306 (Cloud Brain plan) · #215 (self-learning: distill Brain_Feed → Profile facts — UNBUILT) · #325 (email visibility scan)
- **Cadence:** #254 (close-loop daily/weekly review) · #202 (session-open auto stale-sweep) · #305 (MIS daily report restore)
- **Other:** #272 (Chanie kiosk dedup) · #405 (stale "Your day now" — see code defect #4)

---

## 6. The flagship: Cloud Memory Layer (`docs/CLOUD_MEMORY_LAYER.md`)

The brain reachable from every surface with the PC off. **#042 is the live foundation (titles/hooks in D1).** Phases: **0 = deploy-safety (HARD GATE — same as the build split above)** · 1 = push full file BODIES to D1 (depth gap; titles live, bodies don't) · 2 = scope wall + every surface reads · 3 = R2 bodies · 4 = semantic recall · 5 = self-sharpening loop (folds in #215).

---

## 7. Recommended order

1. **Permanent ops-api build split** (dashboard) → un-freeze. *Keystone.*
2. **Ship code defects #1–#3** via clasp (no master push needed) → robust voice + correct relay attribution.
3. **Cloud Memory Phase 1** (`brain-sync.ps1` push of bodies — no deploy) → brain depth on phone.
4. **#215 self-learning** (nightly Brain_Feed distill) → bot improves by design.
5. **#180/#35 voice loop + #297 photo input** → modality completeness.
6. Reconcile GitHub issues ↔ queue cards (#34/#35/#26 overlap #180/#215).

---

---

## 8. EXECUTED this session (2026-06-25 ~11 AM ET)

**Code fixes — LIVE via clasp deploy @126 (NOT git-committed; committing re-clobbers ops-api until the build is split):**
- Voice pipeline hardened (`Code.js`): `getFile` now mutes exceptions + detects "file is too big" (the long-note 400) → clear message; download + transcribe responses guarded against empty/404 bodies (no more `JSON.parse` crash). The raw Dutch-locale error is gone.
- Relay actor fixed (`Code.js`): relay transcript now logs `Sam → <name>` (was `<name>`) — fixes the bot misreading who-said-what.
- `#405` stripped (`start-here.gs`): the auto-appended "Your day now" stale-card block removed.
- (TTS + Hebcal parses left as-is — already inside their own try/catch, degrade safely.)

**ops-api:** rolled forward to `bbaba3ee` (full API incl relays + voice). `8523bfaf` was missing relay endpoints — corrected in memory.

**Capture (email → queue):** created 6 cards the email review found uncaptured — **#526 P0 HOA waivers DUE Jun 26**, #527 PSEG $1,974.55, #528 National Grid $843.13 (due Jun 27), #529 Honda past-due, #530 Mildred VA raise, #531 Nathali (dup of #462 → closed).

**Queue cleanup:** closed 10 — stale one-time (#304,#315,#452,#453,#482,#490), merges (#22,#298→#208; #50→#323), dup (#531→#462). Queue 330→320.

**Still needs Sam:** reverify #045/#278/#282/#280/#341 (dates/amounts); the big clusters (STR #378-427, cameras, family-page) recommended for epic-rollups not 1-by-1.

### Source trail
- File: `outputs/2026-06-25_02-19_audit_inbox-bot-voice-system-review.md` (local, not pushed)
- ops-api restored: version `8523bfaf-bdaf-4589-9357-39a10886331e`
- Working dir: `C:\Users\ztrei\OneDrive\2. Hook Street\05. 2026 BH`
