fix(code): Workers 實部署修正 —— wasmfile+Module 載入 + tick-budget timeout(CF 實測)

leo21c 實部署發現兩個 CF 限制並修正:
1. CF 禁 runtime 從 bytes 編譯 wasm(WebAssembly.instantiate(bytes) 被 embedder 擋)
   → singlefile(base64) 內嵌不可用。改 wasmfile variant + `import wasm from './vendor/quickjs.wasm'`
   (wrangler CompiledWasm rule 綁成預編 WebAssembly.Module),newVariant({wasmModule}) 注入。
   sandbox 改 variant 注入制(setVariant):Worker 注 wrangler Module、Node 由 bytes 建 Module,
   同一 production 路徑受測。vendor/quickjs.wasm 由 postinstall 自 node_modules 複製(gitignored)。
2. CF 凍結同步執行期 Date.now → wall-clock deadline 對純同步迴圈失效(撞 CF CPU 回 1102)。
   改指令計數 interrupt(max_ticks,CF-safe),wall-clock 留 Node 保護。校準:cadence≈5000
   指令/tick、真實 card 解析≈4 ticks、CF 門檻≈1000+ ticks → 預設 max_ticks=500。
   有 body 的迴圈(含 100M 迴圈)皆乾淨回 TimeoutError;空體 while(true){} 仍由 CF CPU guard 容納。

Worker live: arcrun-code.leo21c.workers.dev(cypher-executor 以此 workers.dev 慣例位址呼叫)。
Node 單測 12/12 綠(wasmfile variant + 注入 Module,同 production 路徑)。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HJiLCRUU2o3aSpPEzVCt2o
This commit is contained in:
Leo
2026-07-06 05:15:50 +00:00
parent 1a7b4639c3
commit 08a79229a5
6 changed files with 1057 additions and 70 deletions
+7 -3
View File
@@ -6,12 +6,16 @@
"description": "arcrun code 零件 —— sandbox inline JSQuickJS-wasm, Workers-ready",
"main": "index.ts",
"scripts": {
"test": "vitest run --config vitest.config.mjs"
"postinstall": "node scripts/vendor-wasm.mjs",
"vendor": "node scripts/vendor-wasm.mjs",
"test": "vitest run --config vitest.config.mjs",
"predeploy": "node scripts/vendor-wasm.mjs",
"deploy": "wrangler deploy"
},
"dependencies": {
"@jitl/quickjs-wasmfile-release-sync": "^0.32.0",
"hono": "^4.7.0",
"quickjs-emscripten-core": "^0.31.0",
"@jitl/quickjs-singlefile-mjs-release-sync": "^0.32.0"
"quickjs-emscripten-core": "^0.31.0"
},
"devDependencies": {
"vitest": "^3.1.0",