Commit a57ea2

2026-03-14 18:57:49 Claude (MCP): [mcp] [mcp] Add E-5 (.pyc retention) and E-6 (warming ping) emergent tasks
Tasks/Emergent.md ..
@@ 156,3 156,54 @@
- [ ] All existing E2E tests pass
- [ ] First-request latency < 2,000ms (deferred init)
- [ ] Warm request latency unchanged
+
+ ---
+
+ ### E-5: Retain .pyc Files in Lambda Package
+
+ **Priority:** Low — estimated 200-400ms cold start reduction, low effort
+ **Discovered during:** Cold start mitigation discussion (2026-03-14)
+ **Relates to:** [[Dev/E-1_Cold_Start_Benchmarks]]
+
+ **Context:**
+ The Lambda build script (`app/otterwiki/build.sh`) strips all `.pyc` files and `__pycache__` directories to reduce package size. However, Lambda's package filesystem is read-only — Python cannot cache compiled bytecode at runtime. Every cold start recompiles every `.py` file it imports. Retaining pre-compiled `.pyc` files (or better, running `python -m compileall` during the build) skips the compilation step on cold start.
+
+ Estimated savings: 200-400ms. The bulk of import time is executing module-level code and loading C extensions, not bytecode compilation, so the improvement is modest. But the change is a one-liner with zero risk.
+
+ **Task:**
+ 1. Remove the `find "$PACKAGE_DIR" -name "*.pyc" -delete` line from `build.sh`
+ 2. Remove the `find "$PACKAGE_DIR" -type d -name "__pycache__" -exec rm -rf {} +` line
+ 3. Add `python -m compileall -q "$PACKAGE_DIR"` after stripping to pre-compile all `.py` files
+ 4. Measure package size delta
+ 5. Re-run cold start benchmark to measure actual improvement
+
+ **Acceptance criteria:**
+ - [ ] `.pyc` files retained in Lambda package
+ - [ ] Cold start improvement measured and documented
+ - [ ] Package size increase documented (expected: ~10-20MB)
+
+ ---
+
+ ### E-6: Lambda Warming Ping
+
+ **Priority:** Low — stopgap measure, not a long-term solution
+ **Discovered during:** Cold start mitigation discussion (2026-03-14)
+ **Relates to:** [[Dev/E-1_Cold_Start_Benchmarks]], [[Design/CDN_Read_Path]]
+
+ **Context:**
+ An EventBridge rule invoking the otterwiki Lambda every 5 minutes keeps one execution environment warm, eliminating cold starts for the common case (single user browsing). Cost is effectively $0/month (8,760 invocations/month at 500ms × 512MB = 2,190 GB-seconds, well within the 400K GB-s free tier).
+
+ Limitations: only keeps 1 instance warm. Concurrent requests beyond 1 still cold-start. Does not solve the problem at scale — just masks it for low-traffic scenarios.
+
+ This is a band-aid, not a solution. The CDN read path ([[Tasks/E-2_CDN_Read_Path_ClientSide]]) is the proper fix. This task exists as a fallback if the CDN work is delayed.
+
+ **Task:**
+ 1. Add EventBridge rule in `infra/__main__.py`: invoke otterwiki Lambda every 5 minutes
+ 2. Add Lambda permission for EventBridge to invoke
+ 3. The Lambda handler already handles non-API-Gateway events gracefully (returns early)
+ 4. Verify warm state with benchmark
+
+ **Acceptance criteria:**
+ - [ ] EventBridge rule triggers Lambda every 5 minutes
+ - [ ] Lambda stays warm between invocations (no cold start on next real request)
+ - [ ] Cost: $0/month additional
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9