fix(aibtc-news): inherit process.env in signing subprocess + support signatureBase64#362
Conversation
arc0btc
left a comment
There was a problem hiding this comment.
Fixes two independent silent failures in the signing subprocess path — both clearly diagnosed and correctly addressed.
What works well:
- The
env: { ...process.env }fix is exactly right. Bun.spawn doesn't inherit parent env by default, soAIBTC_WALLET_PASSWORD(andAIBTC_MNEMONIC,NETWORK) were never reaching the signing process. The error would surface as an unlocked-wallet failure even when the parent had the wallet open — a classic invisible subprocess env issue. - The
signature ?? signatureBase64fallback is backward-compatible and safe. The??operator only falls back onnull/undefined, not empty strings, and the downstream!sigguard covers both. TypeScript narrowing after the throw means the return is correctly typed asstring. - Clean rebase of #256 — excluding the unrelated hodlmm-risk/paperboy additions was the right call.
[suggestion] Simplify the type cast (aibtc-news/aibtc-news.ts)
The double cast (result as Record<string, unknown>).signatureBase64 as string | undefined is a workaround for TypeScript not knowing the shape of JSON.parse() output. If result were typed at the parse site, this would be cleaner:
const sig = (result as { signature?: string; signatureBase64?: string; success: boolean; signer?: string; error?: string }).signature
?? (result as { signatureBase64?: string }).signatureBase64;
Or alternatively, define a SigningResult interface at the top of the function. Not blocking — the current cast is functionally correct, it's just a readability improvement.
Operational context: This hits our file-signal path every time we send a signed payload to the news API. We've had six consecutive days of SQ=1 and while the main root causes were different (ACTIVE_BEATS empty, missing beat tag, single source), silent signing failures on this path were a real possibility. This fix closes that gap.
Problem
The
signMessage()function inaibtc-news.tsspawnssigning.ts btc-signas a subprocess without inheritingprocess.env. This meansAIBTC_WALLET_PASSWORD(and other env vars) never reach the subprocess, causing signing to fail with an unlocked-wallet error even when the wallet is unlocked in the parent process.A second independent failure: even when signing succeeds, the response parser checked only for
signature— but the currentsigning.tsoutputssignatureBase64. Both bugs compound on the same call path, making authenticated news API calls silently fail.Changes
env: { ...process.env }added toBun.spawnoptions — ensuresAIBTC_WALLET_PASSWORD,AIBTC_MNEMONIC, andNETWORKare available in the signing subprocess.signatureBase64fallback — the result check now readsresult.signature ?? result.signatureBase64, maintaining backward compatibility while supporting current signing skill output.Testing
Before this fix,
aibtc-news file-signalwould fail with"btc-sign error: missing signature or signer in output"even with a valid unlocked wallet. After this fix, the subprocess receives the wallet credentials and the response is correctly parsed.Previous PR
This is a clean rebase of the fix originally in PR #256 (closed due to merge conflicts + no response). The hodlmm-risk and paperboy skill additions from that PR are excluded — those were already merged by other contributors.