From b9882dab9ffd6a69264327bc3b936fc99147203b Mon Sep 17 00:00:00 2001 From: chakravartyharish Date: Sat, 25 Jul 2026 15:27:20 +0530 Subject: [PATCH] Guard the Owl feature-binding lookup so it fails safe on Linux MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bundled main-app chunk calls process._linkedBinding("electron_common_owl_features") during startup to read OpenAI's internal feature-flag state. That binding only exists in OpenAI's custom-patched Electron fork used for the official macOS/Windows builds; the stock open-source Electron used here never has it, so the call throws and bootstrap-import-main aborts on every single launch before the window ever appears. Guard the lookup so a missing binding degrades to "no Owl features enabled" instead of crashing. The lookup lives in a content-hashed chunk file (not a fixed path), so it's located by content rather than filename. Verified: rebuilt the app, extracted the packed asar to confirm the guarded fallback landed, then launched codex-app/start.sh directly — it now boots past bootstrap, loads the webview UI, and connects to the app-server backend (thread/list succeeds), instead of failing every time as before. --- scripts/patches/bootstrap.js | 65 +++++++++++++++++++ .../extracted-app/owl-feature-guard/patch.js | 13 ++++ 2 files changed, 78 insertions(+) create mode 100644 scripts/patches/core/all-linux/extracted-app/owl-feature-guard/patch.js diff --git a/scripts/patches/bootstrap.js b/scripts/patches/bootstrap.js index c82ef5d19..b6c8d7763 100644 --- a/scripts/patches/bootstrap.js +++ b/scripts/patches/bootstrap.js @@ -43,7 +43,72 @@ function patchLinuxMultiInstanceBootstrap(extractedDir) { return { changed: true }; } +const unguardedOwlFeatureLookup = + "function Qe(){let e=process._linkedBinding;if(typeof e!=`function`)throw Error(`Owl feature binding is unavailable`);return Ge.parse(e.call(process,`electron_common_owl_features`))}"; +const guardedOwlFeatureLookup = + "function Qe(){let e=process._linkedBinding;if(typeof e!=`function`)return{isOwlFeatureEnabled:()=>false};try{return Ge.parse(e.call(process,`electron_common_owl_features`))}catch(t){return{isOwlFeatureEnabled:()=>false}}}"; + +function applyLinuxOwlFeatureGuardPatch(currentSource) { + if (currentSource.includes(guardedOwlFeatureLookup)) { + return currentSource; + } + if (currentSource.includes(unguardedOwlFeatureLookup)) { + return currentSource.replace(unguardedOwlFeatureLookup, guardedOwlFeatureLookup); + } + + if (currentSource.includes("electron_common_owl_features")) { + console.warn( + "WARN: Could not find bootstrap Owl feature binding lookup in expected shape — skipping Linux Owl feature guard patch", + ); + } + return currentSource; +} + +function findFileContaining(dir, needle) { + if (!fs.existsSync(dir)) { + return null; + } + for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { + const entryPath = path.join(dir, entry.name); + if (entry.isDirectory()) { + const found = findFileContaining(entryPath, needle); + if (found != null) { + return found; + } + } else if (entry.isFile() && entry.name.endsWith(".js")) { + if (fs.readFileSync(entryPath, "utf8").includes(needle)) { + return entryPath; + } + } + } + return null; +} + +function patchLinuxOwlFeatureGuard(extractedDir) { + // The Owl feature-binding lookup lives in whichever chunk the main bundle + // pulls it into (content-hashed filename, not a fixed path), so locate it + // by content instead of assuming it's in bootstrap.js. + const target = findFileContaining( + path.join(extractedDir, ".vite", "build"), + "electron_common_owl_features", + ); + if (target == null) { + return { changed: false, reason: "owl feature binding lookup not found" }; + } + + const source = fs.readFileSync(target, "utf8"); + const patched = applyLinuxOwlFeatureGuardPatch(source); + if (patched === source) { + return { changed: false }; + } + + fs.writeFileSync(target, patched, "utf8"); + return { changed: true, target }; +} + module.exports = { applyLinuxMultiInstanceBootstrapPatch, patchLinuxMultiInstanceBootstrap, + applyLinuxOwlFeatureGuardPatch, + patchLinuxOwlFeatureGuard, }; diff --git a/scripts/patches/core/all-linux/extracted-app/owl-feature-guard/patch.js b/scripts/patches/core/all-linux/extracted-app/owl-feature-guard/patch.js new file mode 100644 index 000000000..b9919f5ef --- /dev/null +++ b/scripts/patches/core/all-linux/extracted-app/owl-feature-guard/patch.js @@ -0,0 +1,13 @@ +"use strict"; + +const { + patchLinuxOwlFeatureGuard, +} = require("../../../../bootstrap.js"); + +module.exports = { + id: "linux-owl-feature-guard", + phase: "extracted-app", + order: 130, + ciPolicy: "optional", + apply: patchLinuxOwlFeatureGuard, +};