Windows: bundled keytar.node is a Linux ELF binary -> "Bad Image" 0xc000012f, vault never persists (login stuck Anonymous)
Summary
On Windows, the keytar native module shipped in the VSIX
(dist/node_modules/keytar/build/Release/keytar.node) is a Linux ELF binary,
not a Windows PE. Neither VS Code (Electron) nor the daemon can load it, so the
vault can never be sealed/unsealed and every login stays Anonymous.
Environment
- OS: Windows 11 x64
- Extension:
nskha.perplexity-vscode0.8.53 - Runtimes affected: VS Code Electron (
ELECTRON_RUN_AS_NODE) and standalone Node v22 - Bundled keytar version: 7.9.0
Symptoms
Code.exe - Bad Imagedialog:...\dist\node_modules\keytar\build\Release\keytar.node is either not designed to run on Windows or it contains an error ... Error status 0xc000012f.daemon.log:[vault] getSavedCookies failed ... Vault locked: no keychain, no env var, no TTYdaemon-status.json:authenticated: false, tier: AnonymousPerplexity: Loginruns but the vault is never persisted (or cannot be unsealed), soperplexity_reason/perplexity_researchetc. return "requires an authenticated Pro account".
Root cause (verified by binary header inspection)
keytar.nodestarts with7F 45 4C 46(\x7FELF, Linux). A Windows binary must start with4D 5A(MZ, PE).0xc000012f= STATUS_IMAGE_CHECKSUM_MISMATCH, i.e. the OS loader rejects the wrong-platform image.- For contrast, the bundled ngrok native module IS packaged per-platform
correctly (a valid
ngrok.win32-x64-msvc.nodewith anMZheader exists in the same VSIX). Onlykeytaris Linux-only.
Workaround that fully resolves it
Swapping in the official Windows prebuild of the same keytar version fixes everything:
- Download
keytar-v7.9.0-napi-v3-win32-x64.tar.gzfrom the atom/node-keytar releases and extractbuild/Release/keytar.node(valid Windows PE, N-API v3). - Replace the ELF
keytar.nodein the extension with it. - Restart the daemon and run
Perplexity: Login.
After this, keytar loads under both standalone Node v22 and VS Code's Electron
runtime, the vault seals via Windows Credential Manager, and the daemon reports
tier: Pro. All tools work.
(The PERPLEXITY_DISABLE_KEYCHAIN + PERPLEXITY_VAULT_PASSPHRASE fallback is also a
valid workaround, but the packaging fix is the clean solution.)
Suggested fix
Bundle the correct per-platform keytar prebuild(s) in the VSIX (win32-x64 at minimum; ideally win32-arm64 + darwin + linux), the same way ngrok is already bundled. The current Windows package appears to contain only the Linux keytar build.
Confirmed on every load-bearing point, and fixed in main — thank you. Inspecting the binary header and noting that ngrok was packaged correctly while keytar wasn't is what made this a 20-minute fix instead of a week.
What was actually happening
Three facts composed into a total auth outage for every Windows and macOS Marketplace user:
- keytar 7.9.0 uses
prebuild-install, not optionalDependencies-per-platform like@ngrok/ngrok— sonpm cimaterializes exactly onebuild/Release/keytar.node, for the build machine's platform. prepare-package-deps.mjslisted keytar in its genericrootPackagesarray, which blind-cpSyncs whatever the builder has.release.ymlpacks a universal VSIX (novsce --target) onubuntu-latest.
So the Ubuntu runner's Linux ELF went to everyone. Your ngrok observation was the key: ngrok isn't fine by luck — it got exactly this fix in 0.8.5 (it can ship side-by-side variants because it dispatches on process.platform at runtime). keytar never got the same treatment, and when packaging moved to an Ubuntu runner its exposure simply flipped from Linux users to Windows/macOS users.
Two footnotes on your report
Your NT status name is off, in a way that strengthens your case. 0xC000012F is STATUS_INVALID_IMAGE_NOT_MZ — literally "did not have an initial MZ" — not STATUS_IMAGE_CHECKSUM_MISMATCH (that's 0xC0000221). The loader was stating your ELF-instead-of-PE diagnosis outright.
We did not touch the vault's error handling. vault.js already wraps import("keytar") in try/catch and caches the failure — that's precisely why you got the clean Vault locked: no keychain, no env var, no TTY message instead of a crash. The "Bad Image" dialog is an OS hard-error raised by the loader inside process.dlopen(); JS can't intercept it. The fallback isn't broken — the fallback state (vault permanently locked) is just fatal to auth. Fixing the binary was the only real fix.
The fix
Your suggested approach, with one wrinkle you'd have hit immediately: keytar's lib/keytar.js hardcodes require('../build/Release/keytar.node') with no platform dispatch, so dropping prebuilds side-by-side does nothing on its own. Packaging now:
- fetches the 4 smoke-matrix prebuilds (
linux-x64,darwin-x64,darwin-arm64,win32-x64) from keytar's GitHub Releases — they're not on npm, so thenpm packpath used for ngrok doesn't apply; - verifies each by magic bytes (
MZ/\x7FELF/ Mach-O) and refuses to package on a mismatch; - stages them under
build/Release/<platform>-<arch>/; - deletes the build machine's own binary, so a Linux-built VSIX can't keep loading the ELF with correct binaries sitting right beside it;
- applies a surgical one-line loader patch for per-platform resolution, asserted against the stock line so an upstream change fails the build loudly.
~300 KB on a ~12.7 MB VSIX. Verified end-to-end on Windows 11: the patched loader resolves win32-x64, loads a real PE, and round-trips a secret through the actual Credential Manager. The new CI test asserts on bytes, not paths — negative-tested by planting the Linux ELF at win32-x64/ and confirming the suite fails.
Why this escaped us
The bug is only observable in CI-built artifacts. npm run package:vsix on a Windows dev box ships a Windows keytar — so local smoke-testing could never reproduce it, in either direction. CI ran vsce ls on both Ubuntu and Windows but only grepped for leaked .ts files; it never looked inside a native binary. That's the real gap, and the magic-byte gate closes it.
Your PERPLEXITY_DISABLE_KEYCHAIN + PERPLEXITY_VAULT_PASSPHRASE workaround stays valid for anyone on 0.8.54 or earlier until the next release ships. Thanks again — this was a genuinely excellent report.
Fixed and released in extension v0.8.60. Your diagnosis was correct on every load-bearing point — thank you.
Verified against the actual shipped artifact, not just the source. The published perplexity-vscode-0.8.60.vsix (built by CI on ubuntu-latest, i.e. the exact condition that produced the bug) now contains:
dist/node_modules/keytar/build/Release/win32-x64/keytar.node 4d5a9000 (MZ — PE)
dist/node_modules/keytar/build/Release/darwin-x64/keytar.node cffaedfe (Mach-O)
dist/node_modules/keytar/build/Release/darwin-arm64/keytar.node cffaedfe (Mach-O)
dist/node_modules/keytar/build/Release/linux-x64/keytar.node 7f454c46 (ELF)
The build machine's own binary is gone from the stock build/Release/keytar.node path, and the loader is patched to require(\../build/Release/${process.platform}-${process.arch}/keytar.node`)`. This mattered: verifying a locally packed VSIX would have proven nothing — on a Windows dev box it ships a Windows keytar and cannot reproduce the bug in either direction. Only the CI artifact is meaningful evidence.
Two footnotes on your report, neither of which weakens it:
- Your NT status name is off in a way that strengthens the diagnosis:
0xC000012FisSTATUS_INVALID_IMAGE_NOT_MZ— literally "did not have an initial MZ" — notSTATUS_IMAGE_CHECKSUM_MISMATCH(0xC0000221). The loader was stating your ELF-instead-of-PE conclusion outright. - We did not touch the vault's error handling.
vault.jsalready try/catches the keytar import correctly — that's precisely why you got the cleanVault locked: no keychain, no env var, no TTYmessage instead of a crash. The "Bad Image" dialog is an OS hard-error raised insideprocess.dlopen(); JS cannot intercept it. The fallback wasn't broken — the fallback state (vault permanently locked) is just fatal to auth. Fixing the binary was the only real fix.
Why it escaped us: the bug was only ever observable in CI-built artifacts, and CI ran vsce ls on both Ubuntu and Windows but only grepped for leaked .ts files — it never looked inside a native binary. There's now a magic-byte gate at packaging time (fails the build loudly on a wrong-platform binary) plus a CI test that asserts on bytes, not paths — negative-tested by planting a Linux ELF at win32-x64/ and confirming the suite fails.
Please update to 0.8.60; your PERPLEXITY_DISABLE_KEYCHAIN + PERPLEXITY_VAULT_PASSPHRASE workaround is no longer needed. Reopen if the vault still won't persist.