|
81 | 81 | - SSRF check in createDefaultNetworkAdapter blocks 127.0.0.1 — test network adapters need directFetch bypass for mock servers |
82 | 82 | - crypto polyfill (node-stdlib-browser) lacks randomUUID — augment with bridge _cryptoRandomUUID |
83 | 83 | - process.stdout.write(data, callback) callback must be invoked — Pi's flush Promise depends on it |
| 84 | +- V8_POLYFILLS TextDecoder.decode() must handle Uint8Array subarrays — `new Uint8Array(buf.buffer)` ignores byteOffset/byteLength; use `buf instanceof Uint8Array ? ... : new Uint8Array(buf.buffer || buf)` |
| 85 | +- Bridge fetch must normalize Headers instances to plain objects before JSON.stringify — SDK passes Headers, JSON.stringify(Headers) = {} |
| 86 | +- Response body needs Symbol.asyncIterator with Promise.resolve-based reader for SDK SSE parsing — async generators create extra microtask overhead |
| 87 | +- V8 event loop needs post-loop microtask drain (session.rs) for async generator chains across loaded ESM modules |
| 88 | +- SDK uses .mjs files in V8 sandbox — patches to .js files won't be loaded; the _loadFile handler traces must check .mjs paths |
84 | 89 |
|
85 | 90 | # Ralph Progress Log |
86 | 91 | Started: Sat Mar 21 02:49:43 AM PDT 2026 |
@@ -938,3 +943,26 @@ Started: Sat Mar 21 02:49:43 AM PDT 2026 |
938 | 943 | - SSRF check in createDefaultNetworkAdapter blocks 127.0.0.1 — test needs directFetch bypass |
939 | 944 | - Anthropic SDK uses ANTHROPIC_BASE_URL env var for API endpoint override |
940 | 945 | --- |
| 946 | + |
| 947 | +## 2026-03-22 00:00 - US-027 (PASSING) |
| 948 | +- Fixed 4 bridge compatibility issues that prevented Pi from running in-VM: |
| 949 | + 1. TextDecoder subarray bug: V8_POLYFILLS TextDecoder.decode() used `new Uint8Array(buf.buffer)` which ignores byteOffset/byteLength of typed array views — SDK's LineDecoder returned corrupted SSE lines |
| 950 | + 2. Fetch Headers serialization: SDK passes `Headers` instances to fetch, `JSON.stringify(Headers)` produces `{}` — normalize to plain Record via `.entries()` |
| 951 | + 3. Response body async iterator: added `Symbol.asyncIterator` with explicit `Promise.resolve()` (not async generator) for SDK's ReadableStreamToAsyncIterable |
| 952 | + 4. V8 event loop microtask drain: added post-event-loop checkpoint loop in session.rs for nested async generator yield chains across loaded ESM modules |
| 953 | +- Pi boots, loads Anthropic SDK, processes SSE streaming response, outputs LLM response |
| 954 | +- Tests use output-settle detection (500ms no new output → kill process) because process.exit() in TLA doesn't cleanly terminate V8 session |
| 955 | +- Bash tool test skipped when WASM binaries unavailable |
| 956 | +- Files changed: |
| 957 | + - native/v8-runtime/src/session.rs (microtask drain loop after event loop) |
| 958 | + - packages/nodejs/src/execution-driver.ts (TextDecoder subarray fix) |
| 959 | + - packages/nodejs/src/bridge/network.ts (Headers normalization, body async iterator) |
| 960 | + - packages/nodejs/src/bridge/polyfills.ts (TextDecoder subarray fix for polyfill) |
| 961 | + - packages/secure-exec/tests/cli-tools/pi-headless.test.ts (output-settle spawn helper, bash skip) |
| 962 | +- **Learnings for future iterations:** |
| 963 | + - V8_POLYFILLS TextDecoder runs BEFORE bridge IIFE — fixes must go in execution-driver.ts, not polyfills.ts |
| 964 | + - SDK uses `.mjs` files (ESM), not `.js` (CJS) — module tracing must check the right variant |
| 965 | + - `text-encoding-utf-8` polyfill has the same subarray bug — both polyfills need fixing |
| 966 | + - Async generator `yield` across V8-loaded ESM modules needs extra microtask checkpoints after event loop |
| 967 | + - process.exit() inside TLA doesn't cleanly terminate the V8 session — test needs output-settle detection |
| 968 | +--- |
0 commit comments