Dashboard › sentry › Session 0f6iSiGPhiWE
0f6iSiGPhiWEQErfjYou are reviewing PR #609 on behalf of the author before merging. Be critical and thorough. Check for:
Here's the context:
Title: fix(gateway): use fossilize programmatic API instead of impl-* glob dance
Body:
Closes https://github.com/BYK/fossilize/issues/23
Updates build-binary-sea.ts to use fossilize v0.9.0's public API (`import { fossilize } from 'fossilize'`) instead of the fragile impl-* glob dance that broke when fossilize v0.9.0 shipped a proper exports field.
**Changes:**
- Replace 20-line glob+dynamic-import block with direct `import { fossilize } from 'fossilize'`
- Remove `.call(fossilizeContext, ...)` wrapper — v0.9.0's API constructs Stricli context internally
- Remove unused `readdirSync` import
fix(gateway): use fossilize programmatic API instead of impl-* glob dancefix(gateway): bump fossilize to ^0.9.0 for programmatic APIrefactor(gateway): use static import for fossilize at module levelRead the file and compare it against git diff from main.
Steps:
/home/byk/.local/share/opencode/worktree/51d1015fd1f616acf9a5ffaad9331ec6b304586b/swift-harbor/packages/gateway/script/build-binary-sea.ts lines 27-50 (imports section)/home/byk/.local/share/opencode/worktree/51d1015fd1f616acf9a5ffaad9331ec6b304586b/swift-harbor/packages/gateway/package.json (full file, check fossilize version)git diff origin/main...HEAD to see the full PR diffI'll systematically gather all the context needed for this review.
<path>/home/byk/.local/share/opencode/worktree/51d1015fd1f616acf9a5ffaad9331ec6b304586b/swift-harbor/packages/gateway/script/build-binary-sea.ts</path> <type>file</type> <content> 1: /** 2: * Build @loreai/gateway standalone binary via Node SEA + fossilize. 3: * 4: * This replaces the legacy `bun build --compile` pipeline. The new 5: * pipeline uses: 6: * 7: * 1. esbuild → single CJS bundle (target: Node 22) 8: * 2. esbuild → worker CJS bundle 9: * 3. fossilize → Node SEA per target, with WASM files + model 10: * files + worker CJS embedded as SEA assets 11: * 12: * At runtime, the binary uses the WASM backend of 13: * `@huggingface/transformers` (i.e. `onnxruntime-web`'s Node entry). 14: * This is the path of least resistance: WASM runs correctly under 15: * Node's V8 engine (the bugs that forced this migration were 16: * specific to Bun's WASM engine — see `oven-sh/bun#18145`, `#25677`, 17: * `#31158`). ...
<path>/home/byk/.local/share/opencode/worktree/51d1015fd1f616acf9a5ffaad9331ec6b304586b/swift-harbor/packages/gateway/script/build-binary-sea.ts</path>
<type>file</type>
<content>
560: },
561: "worker.cjs": { file: "worker.cjs", src: "worker.cjs" },
562: };
563: if (vendorModelDir) {
564: for (const rel of MODEL_FILES) {
565: const key = `model/${rel}`;
566: manifest[key] = { file: key, src: key };
567: }
568: }
569:
570: const manifestPath = join(stagingDir, "asset-manifest.json");
571: writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
572:
573: // -------------------------------------------------------------------------
574: // Step 4: Run fossilize
575: // -------------------------------------------------------------------------
576: // fossilize uses Node.js archive naming which differs from our
577: // VALID_TARGETS on some platforms:
578: // our "windows-x64" → fossilize "win-x64"
579: // our "darwin-arm64" ...
<path>/home/byk/.local/share/opencode/worktree/51d1015fd1f616acf9a5ffaad9331ec6b304586b/swift-harbor/packages/gateway/package.json</path>
<type>file</type>
<content>
1: {
2: "name": "@loreai/gateway",
3: "version": "0.24.1",
4: "type": "module",
5: "license": "FSL-1.1-Apache-2.0",
6: "description": "Lore as a transparent LLM proxy — context management for any AI coding client",
7: "main": "./dist/index.cjs",
8: "types": "./dist/index.d.cts",
9: "exports": {
10: ".": {
11: "types": "./dist/index.d.cts",
12: "require": "./dist/index.cjs",
13: "default": "./dist/index.cjs"
14: }
15: },
16: "bin": {
17: "lore": "./dist/bin.cjs",
18: "lore-gateway": "./dist/bin.cjs"
19: },
20: "scripts": {
21: "typecheck": "tsc --noEmit",
22: "build": "tsx script/build.ts",
23: "bundle": "tsx script/bundle.ts",
24: "build:binary": "tsx script/build.ts --binary",
25: "build:binary:sea": "tsx script/build-binary-sea.ts",
26: ...
...output truncated...
Full output saved to: /home/byk/.local/share/opencode/tool-output/tool_ea3fc5d31001FoucmDT5GacbZc
+
+ "magic-string": ["magic-string@0.30.21", "", { "dependencies": { "@jridgewell/sourcemap-codec": "1.5.5" } }, "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ=="],
+
+ "marked": ["marked@15.0.12", "", { "bin": { "marked": "bin/marked.js" } }, "sha512-8dD6FusOQSrpv9Z1rdNMdlSgQOIP880DHqnohobOmYLElGEqAL/JvxvuxZO16r4HtjTlfPRDC1hbvxC9dPN2nA=="],
+
+ "matcher": ["matcher@3.0.0", "", { "dependencies": { "escape-string-regexp": "4.0.0" } }, "sha512-OkeDaAZ/bQCxeFAozM55PKcKU0yJMPGifLwV4Qgjitu+5MoAfSQN4lsLJeXZ1b8w0x+/Emda6MZgXS1jvsapng=="],
+
+ "mdast-util-from-markdown": ["mdast-util-from-markdown@2.0.3", "", { "dependencies": { "@types/mdast": "4.0.4", "@types/unist": "3.0.3", "decode-named-character-reference": "1.3.0", "devlop": "1.1.0", "mdast-util-to-string": "4.0.0", "micromark": "4.0.2", ...
Now let me check if createRequire and pathToFileURL are still used elsewhere in the file:
Found 14 matches
/home/byk/.local/share/opencode/worktree/51d1015fd1f616acf9a5ffaad9331ec6b304586b/swift-harbor/packages/gateway/script/build-binary-sea.ts:
Line 40: import { createRequire } from "node:module";
Line 41: import { fileURLToPath, pathToFileURL } from "node:url";
Line 48: const require = createRequire(import.meta.url);
Line 185: const coreRequire = createRequire(`${coreDir}/`);
Line 193: const tfRequire = createRequire(`${tfDir}/`);
Line 411: // Post-process: patch createRequire in both bundles
Line 414: // createRequire(import.meta.url) → createRequire(shim.url) where
Line 419: // We replace the call with createRequire(pathToFileURL(__filename).href)
Line 429: const createRequirePattern =
Line 430: /\(0,\s*([a-zA-Z_$][a-zA-Z0-9_$]*)\.createRequire\)\(([a-zA-Z_$][a-zA-Z0-9_$]*)\.url\)/g;
Line 431: const createRequireReplacement =
Line 432: '(0,$1.createRequire)(require("url").pathToFileURL(__filename).href)';
...
8556db8 refactor(gateway): use static import for fossilize at module level df19b01 fix(gateway): bump fossilize to ^0.9.0 for programmatic API 8ac9c21 fix(ci): remove empty `with:` from pnpm/action-setup in eval.yml (#610) 7ccc536 test(ci): quiet test harness noise + pretest hook for bundle (#608) 0613c6b fix(gateway): use fossilize programmatic API instead of impl-* glob dance b79acad fix(gateway): polyfill getSystemErrorMap for Bun to prevent Sentry SDK crash (#602) 48770f2 fix(core): recognize WASM fatal error wrapper prefix in isWasmFatalError() (#604) f610388 fix(gateway): guard resp.usage accesses against undefined for vLLM/partial responses (#600) 122690b fix(gateway): handle SSE response from upstream when stream: false was sent (#605) 57893c5 fix(core): guard against postMessage on terminated embedding worker (#603) 932b1b9 fix(site): grain z-index, blog footer, CWD-relative fs read fd05371 fix(entities): filter dismissed pairs from dashboard dedup suggestions (#598) 6ba34e5 ...
Now let me verify the full usage of pathToFileURL to see if it's only used in the createRequire patching context (which is still needed) or also in the removed fossilize import:
Found 3 matches
/home/byk/.local/share/opencode/worktree/51d1015fd1f616acf9a5ffaad9331ec6b304586b/swift-harbor/packages/gateway/script/build-binary-sea.ts:
Line 41: import { fileURLToPath, pathToFileURL } from "node:url";
Line 419: // We replace the call with createRequire(pathToFileURL(__filename).href)
Line 432: '(0,$1.createRequire)(require("url").pathToFileURL(__filename).href)';
<path>/home/byk/.local/share/opencode/worktree/51d1015fd1f616acf9a5ffaad9331ec6b304586b/swift-harbor/packages/gateway/script/build-binary-sea.ts</path>
<type>file</type>
<content>
410: // -------------------------------------------------------------------------
411: // Post-process: patch createRequire in both bundles
412: // -------------------------------------------------------------------------
413: // In CJS output, esbuild shims import.meta to {}, making
414: // createRequire(import.meta.url) → createRequire(shim.url) where
415: // shim is {} and .url is undefined. This throws "The argument
416: // 'filename' must be a file URL object..." when transformers.js's
417: // bundled ONNX runtime initializes.
418: //
419: // We replace the call with createRequire(pathToFileURL(__filename).href)
420: // which always resolves to a valid file URL from the script's path. ...
Good — pathToFileURL is referenced in lines 419 and 432, but line 419 is just a comment, and line 432 is a string literal ('..pathToFileURL...'), not an actual call to the imported pathToFileURL. Let me verify that pathToFileURL is never actually called as a function anywhere in the file:
419: // We replace the call with createRequire(pathToFileURL(__filename).href)
432: '(0,$1.createRequire)(require("url").pathToFileURL(__filename).href)';
41:import { fileURLToPath, pathToFileURL } from "node:url";
50:const here = dirname(fileURLToPath(import.meta.url));
Now I have the full picture. Let me also check the commits that are actually in the PR (not the other unrelated ones):
8556db8 refactor(gateway): use static import for fossilize at module level df19b01 fix(gateway): bump fossilize to ^0.9.0 for programmatic API 8ac9c21 fix(ci): remove empty `with:` from pnpm/action-setup in eval.yml (#610) 7ccc536 test(ci): quiet test harness noise + pretest hook for bundle (#608) 0613c6b fix(gateway): use fossilize programmatic API instead of impl-* glob dance b79acad fix(gateway): polyfill getSystemErrorMap for Bun to prevent Sentry SDK crash (#602) 48770f2 fix(core): recognize WASM fatal error wrapper prefix in isWasmFatalError() (#604) f610388 fix(gateway): guard resp.usage accesses against undefined for vLLM/partial responses (#600) 122690b fix(gateway): handle SSE response from upstream when stream: false was sent (#605) 57893c5 fix(core): guard against postMessage on terminated embedding worker (#603) 932b1b9 fix(site): grain z-index, blog footer, CWD-relative fs read fd05371 fix(entities): filter dismissed pairs from dashboard dedup suggestions (#598) 6ba34e5 ...
8556db8 refactor(gateway): use static import for fossilize at module level df19b01 fix(gateway): bump fossilize to ^0.9.0 for programmatic API 0613c6b fix(gateway): use fossilize programmatic API instead of impl-* glob dance 8291bbf fix(core,gateway): restore bun export conditions for OpenCode plugin (#597) 87105bc fix(core,gateway): restore bun export conditions for OpenCode plugin 7fe80db feat(website): Migrate website to Astro (#559)
Now let me verify the diff for just the 3 PR commits to understand what each one does:
commit 0613c6b9dd98e2455075c974abca9f2166476897
Author: Burak Yigit Kaya <ben@byk.im>
Date: Sun Jun 7 21:03:25 2026 +0000
fix(gateway): use fossilize programmatic API instead of impl-* glob dance
packages/gateway/script/build-binary-sea.ts | 31 +++--------------------------
1 file changed, 3 insertions(+), 28 deletions(-)
---
commit df19b0104714b68bea7a2c09856c840349c0a769
Author: Burak Yigit Kaya <ben@byk.im>
Date: Sun Jun 7 21:12:09 2026 +0000
fix(gateway): bump fossilize to ^0.9.0 for programmatic API
packages/gateway/package.json | 2 +-
pnpm-lock.yaml | 10 +++++-----
2 files changed, 6 insertions(+), 6 deletions(-)
---
commit 8556db80b977d42adaa5725018717fb4b523ec32
Author: Burak Yigit Kaya <ben@byk.im>
Date: Sun Jun 7 21:17:53 2026 +0000
refactor(gateway): use static import for fossilize at module level
packages/gateway/script/build-binary-sea.ts | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
Now I have everything I need for a thorough review. Here's my analysis:
pathToFileURL — Severity: Minor (but real)The import on line 41 is:
import { fileURLToPath, pathToFileURL } from "node:url";
After the refactor, pathToFileURL is no longer called anywhere as an actual function:
// We replace the call with createRequire(pathToFileURL(...))'(0,$1.createRequire)(require("url").pathToFileURL(__filename).href)')fileURLToPath is still used (line 50), so the import statement should stay but pathToFileURL should be removed from it:
import { fileURLToPath } from "node:url";
This is a real unused import left over from the old await import(pathToFileURL(fossilizeImplPath).href) call that was removed. The PR description even says "Remove unused readdirSync import" — it should also mention pathToFileURL.
.call() claim — Severity: MinorThe PR description says:
Remove
.call(fossilizeContext, ...)wrapper — v0.9.0's API constructs Stricli context internally
This is accurate for the code change. ✅
The PR description says:
Remove unused
readdirSyncimport
It should also list pathToFileURL as a newly-unused import that should be removed. readdirSync was correctly removed, but pathToFileURL was missed.
The commit order is:
fix(gateway): use fossilize programmatic API instead of impl-* glob dance — rewrites the call site but leaves import { fossilize } as a dynamic import inside the functionfix(gateway): bump fossilize to ^0.9.0 for programmatic API — bumps the version