Pi Optimize
Security-first, file-by-file audit of a Node.js codebase for performance on constrained ARM64 hardware (Raspberry Pi 5, 8GB RAM, microSD storage, Debian Bookworm).
Philosophy
Performance on constrained hardware is a security concern, not just a convenience issue.
When the event loop blocks on a sync filesystem call, the gateway stops processing auth checks, tool confirmations, and rate limiting. When memory pressure triggers aggressive GC, latency spikes can cause timeouts that bypass intended control flows. When I/O saturates a microSD card, credential writes can fail silently.
Every optimization submitted upstream should be evaluated through this lens: does this make the system more predictable and harder to disrupt under resource constraints?
Audit Approach
Work through the codebase one file at a time. Use lightweight shell commands (grep, find, wc) to identify the highest-value target, then deep-dive that one file. Do not bulk-scan the entire repo. Each file gets a focused read.
Prioritize files in this order:
- Security-critical paths: auth, session isolation, tool gating, input validation
- Gateway hot paths: HTTP handlers, message processing, WebSocket handling
- Resource management: connection pools, caches, rate limiters
- Session and state: file I/O for credentials, config, memory
- CLI and setup code (lowest priority)
Track progress in memory/openclaw-audit.md.
Target Specs
- CPU: 4x Cortex-A76 @ 2.4GHz, aarch64
- RAM: 8GB
- Storage: microSD (slow random I/O, limited write endurance)
- OS: Debian 12 Bookworm, kernel 6.12.x
- Node: v22.x
Audit Checklist
1. Security-Relevant Performance
- Flag synchronous operations in auth/session/tool-gating paths (event loop block = security pause)
- Check rate limiter implementations for timer precision on slow hardware
- Look for unbounded allocations that could enable resource exhaustion (DoS vector)
- Verify credential/token operations are async (blocking on microSD could cause auth timeout)
- Check for error paths that leak timing information
- Flag any path where slow I/O could cause a security check to be skipped or time out
2. I/O Patterns
- microSD has ~25MB/s sequential, terrible random I/O
- Flag synchronous file operations in hot paths
- Look for excessive temp file creation or logging that hammers the SD card
- Check for missing
fsync where data integrity matters (credentials, config)
- Identify opportunities for in-memory caching vs repeated disk reads
- Check that file permission operations are atomic where security-relevant
3. Memory and Resource Management
- Run with
--max-old-space-size at realistic Pi limits (512MB-1GB)
- Watch for: large string buffers, unbounded caches, event listener leaks
- Check for V8 flags that help on constrained memory
- Look for operations that allocate proportional to untrusted input size (DoS vector)
- Verify connection/pool limits are bounded
4. CPU and Compute
- Identify hot functions: JSON parsing of large payloads, regex on big strings, crypto operations
- Check if any code assumes x86 (SIMD intrinsics, specific buffer alignments)
- Look for synchronous crypto or compression blocking the event loop
- Flag any
child_process.execSync in request paths
- Check regex patterns for ReDoS vulnerability on constrained hardware (slower CPU amplifies the issue)
5. Network and Concurrency
- Check connection pool sizes for Pi-appropriate defaults
- Flag hardcoded timeouts that assume fast hardware
- Look for concurrent operations that could overwhelm 4 cores + limited RAM
- Identify backpressure handling in streams
- Check WebSocket handling for memory pressure under many connections
6. Build and Startup
- Measure cold start time
- Check for eager loading of large modules that could be lazy-loaded
- Flag any postinstall scripts that compile native code without ARM64 support
7. Configuration Defaults
- Find hardcoded buffer sizes, cache limits, pool sizes, batch sizes
- Recommend Pi-appropriate defaults or environment-based scaling
- Check for config that should scale with
os.totalmem() or os.cpus().length
Logging Findings
Every finding goes into the project doc at memory/openclaw-audit.md with:
### [category] Short description
- **File:** path/to/file.js:line
- **Severity:** low / medium / high / critical
- **Security relevance:** how this impacts security posture
- **Issue:** What's wrong
- **Fix:** What to do
- **PR:** link (once submitted)
- **Status:** found / fix-written / pr-submitted / merged / wontfix
PR Workflow
When a fix is ready:
- Create a branch named
pi/short-description
- Keep commits atomic and focused
- PR title format:
perf: short description of optimization or security: ... if primarily security-relevant
- PR body: explain the problem, the Pi-specific context, security implications, benchmarks if available
- Reference the audit doc finding
- Reference relevant OpenClaw security docs (SECURITY.md, trust.openclaw.ai) when applicable
Posting Findings to X
Follow VOICE.md. Tag @openclaw on findings. Tag @steipete on PRs that align with VISION.md priorities (performance, security, test infrastructure).
References
1---2name: pi-optimize3description: Security-first performance audit of a Node.js codebase for Raspberry Pi and ARM64 constrained hardware. Use when: (1) finding security-relevant performance issues (event loop blocking, resource exhaustion, DoS vectors), (2) profiling memory, I/O, or CPU on constrained devices, (3) identifying sync filesystem calls that could stall security-critical paths, (4) recommending Pi-appropriate config defaults. NOT for: general code review, non-Node.js projects, or cloud-only deployments.4---56# Pi Optimize78Security-first, file-by-file audit of a Node.js codebase for performance on constrained ARM64 hardware (Raspberry Pi 5, 8GB RAM, microSD storage, Debian Bookworm).910## Philosophy1112Performance on constrained hardware is a security concern, not just a convenience issue.1314When the event loop blocks on a sync filesystem call, the gateway stops processing auth checks, tool confirmations, and rate limiting. When memory pressure triggers aggressive GC, latency spikes can cause timeouts that bypass intended control flows. When I/O saturates a microSD card, credential writes can fail silently.1516Every optimization submitted upstream should be evaluated through this lens: does this make the system more predictable and harder to disrupt under resource constraints?1718## Audit Approach1920Work through the codebase one file at a time. Use lightweight shell commands (grep, find, wc) to identify the highest-value target, then deep-dive that one file. Do not bulk-scan the entire repo. Each file gets a focused read.2122Prioritize files in this order:231. Security-critical paths: auth, session isolation, tool gating, input validation242. Gateway hot paths: HTTP handlers, message processing, WebSocket handling253. Resource management: connection pools, caches, rate limiters264. Session and state: file I/O for credentials, config, memory275. CLI and setup code (lowest priority)2829Track progress in `memory/openclaw-audit.md`.3031## Target Specs3233- CPU: 4x Cortex-A76 @ 2.4GHz, aarch6434- RAM: 8GB35- Storage: microSD (slow random I/O, limited write endurance)36- OS: Debian 12 Bookworm, kernel 6.12.x37- Node: v22.x3839## Audit Checklist4041### 1. Security-Relevant Performance4243- Flag synchronous operations in auth/session/tool-gating paths (event loop block = security pause)44- Check rate limiter implementations for timer precision on slow hardware45- Look for unbounded allocations that could enable resource exhaustion (DoS vector)46- Verify credential/token operations are async (blocking on microSD could cause auth timeout)47- Check for error paths that leak timing information48- Flag any path where slow I/O could cause a security check to be skipped or time out4950### 2. I/O Patterns5152- microSD has ~25MB/s sequential, terrible random I/O53- Flag synchronous file operations in hot paths54- Look for excessive temp file creation or logging that hammers the SD card55- Check for missing `fsync` where data integrity matters (credentials, config)56- Identify opportunities for in-memory caching vs repeated disk reads57- Check that file permission operations are atomic where security-relevant5859### 3. Memory and Resource Management6061- Run with `--max-old-space-size` at realistic Pi limits (512MB-1GB)62- Watch for: large string buffers, unbounded caches, event listener leaks63- Check for V8 flags that help on constrained memory64- Look for operations that allocate proportional to untrusted input size (DoS vector)65- Verify connection/pool limits are bounded6667### 4. CPU and Compute6869- Identify hot functions: JSON parsing of large payloads, regex on big strings, crypto operations70- Check if any code assumes x86 (SIMD intrinsics, specific buffer alignments)71- Look for synchronous crypto or compression blocking the event loop72- Flag any `child_process.execSync` in request paths73- Check regex patterns for ReDoS vulnerability on constrained hardware (slower CPU amplifies the issue)7475### 5. Network and Concurrency7677- Check connection pool sizes for Pi-appropriate defaults78- Flag hardcoded timeouts that assume fast hardware79- Look for concurrent operations that could overwhelm 4 cores + limited RAM80- Identify backpressure handling in streams81- Check WebSocket handling for memory pressure under many connections8283### 6. Build and Startup8485- Measure cold start time86- Check for eager loading of large modules that could be lazy-loaded87- Flag any postinstall scripts that compile native code without ARM64 support8889### 7. Configuration Defaults9091- Find hardcoded buffer sizes, cache limits, pool sizes, batch sizes92- Recommend Pi-appropriate defaults or environment-based scaling93- Check for config that should scale with `os.totalmem()` or `os.cpus().length`9495## Logging Findings9697Every finding goes into the project doc at `memory/openclaw-audit.md` with:9899```100### [category] Short description101- **File:** path/to/file.js:line102- **Severity:** low / medium / high / critical103- **Security relevance:** how this impacts security posture104- **Issue:** What's wrong105- **Fix:** What to do106- **PR:** link (once submitted)107- **Status:** found / fix-written / pr-submitted / merged / wontfix108```109110## PR Workflow111112When a fix is ready:1131141. Create a branch named `pi/short-description`1152. Keep commits atomic and focused1163. PR title format: `perf: short description of optimization` or `security: ...` if primarily security-relevant1174. PR body: explain the problem, the Pi-specific context, security implications, benchmarks if available1185. Reference the audit doc finding1196. Reference relevant OpenClaw security docs (SECURITY.md, trust.openclaw.ai) when applicable120121## Posting Findings to X122123Follow VOICE.md. Tag @openclaw on findings. Tag @steipete on PRs that align with VISION.md priorities (performance, security, test infrastructure).124125## References126127- See `references/v8-arm64-flags.md` for V8 flags relevant to ARM64/constrained environments128- See `references/pi-benchmarks.md` for baseline performance numbers129- OpenClaw SECURITY.md: https://github.com/openclaw/openclaw/blob/main/SECURITY.md130- OpenClaw security docs: https://docs.openclaw.ai/gateway/security131- OpenClaw trust model: https://trust.openclaw.ai