### 2026‑03‑11 · Performance & Workflow Optimizations

**Summary:** Addressed timeout and token‑consumption bottlenecks in morning‑report generation.

#### Key Learnings
1. **Timeout root causes:**
   - **Browser automation stuck in ad‑tech frames** (AAStocks, investing.com) – pages load dozens of iframes; `act/evaluate` hangs.
   - **Tavily‑search variable latency** – some queries >30s, no client‑side timeout control.
   - **Sequential workflow** – calendar → indices → ADRs → rates → FX → news; any slow step blocks everything.

2. **Token‑burn culprits:**
   - **Verbose prompts** – template + instructions + Tavily results added ~10‑15k tokens before real work.
   - **Browser snapshots** – ad‑tech frames alone contributed ~70k tokens in one timed‑out subagent.

#### Improvements Implemented (21:48 HKT)
- **Browser timeouts:** Added `timeoutMs: 15000` to all `browser act` calls.
- **Batched Tavily queries:** Combined related searches (calendar, indices, rates/FX, news).
- **Cron‑job payload rewritten:** Concise instructions, explicit timeout guidance.
- **Fallback strategy:** If AAStocks times out, use Tavily for ADR data.
- **Token reduction:** Removed verbose instructional text from payload.

#### Data‑Source Decisions
- **ADR excess moves:** Use AAStocks ADR page (`/en/usq/quote/adr.aspx`) with formula:
  ```
  Excess = (ADR_Price_HKD – HK_Price) / HK_Price × 100%
  ```
- **Ex‑dividend dates:** Use AAStocks Corporate Events Dividend (`calendar.aspx?type=5`).
  - **Rule:** Show ex‑div within 1 week ahead (exclude yesterday/before) + next upcoming (even if >1 month).
  - **Note:** AAStocks page may be incomplete (HSBC ex‑div not listed); consider supplemental search.

#### Morning‑Report Template Updates
- **Indices table:** `4pm Close (Mark)`, `T‑1 (Day‑on‑Day)`, `T0 (Close‑to‑Present)`.
- **ADR table:** 4‑digit HK symbols, excess calculated via raw prices.
- **Calendar section:** Prioritize AAStocks Corporate Events, fallback to Tavily for missing dividends.

#### Next Steps
- **Test optimized workflow** with timeouts and batched queries.
- **Consider parallel subagents** for independent sections (calendar/rates, indices/ADRs, FX/news).
- **Cache static data** (ex‑div dates, rebalancing) to reduce daily search load.

---
*Memories logged at 22:17 HKT.*