Skip to content

Commit 067bc66

Browse files
ekinneeErick Kinneesteipete
authored
fix(sqlite): distinguish shared system SQLite in WAL safety error (#107771)
* fix(sqlite): distinguish shared system SQLite from embedded in WAL safety error * test(sqlite): cover shared build diagnostics Co-authored-by: Erick Kinnee <[email protected]> * style(sqlite): format shared build check Co-authored-by: Erick Kinnee <[email protected]> --------- Co-authored-by: Erick Kinnee <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
1 parent ef110e9 commit 067bc66

2 files changed

Lines changed: 65 additions & 3 deletions

File tree

‎src/infra/node-sqlite.test.ts‎

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,40 @@ async function loadNodeSqliteWithVersion(version: string) {
1818
return await import("./node-sqlite.js");
1919
}
2020

21+
async function withNodeSharedSqliteValue(value: unknown, run: () => Promise<void>): Promise<void> {
22+
const originalDescriptor = Object.getOwnPropertyDescriptor(process, "config");
23+
if (!originalDescriptor) {
24+
throw new Error("process.config descriptor is unavailable");
25+
}
26+
try {
27+
// Node freezes process.config.variables, so replace and then restore its exact descriptor.
28+
Object.defineProperty(process, "config", {
29+
value: {
30+
...process.config,
31+
variables: { ...process.config.variables, node_shared_sqlite: value },
32+
},
33+
writable: false,
34+
configurable: true,
35+
});
36+
await run();
37+
} finally {
38+
Object.defineProperty(process, "config", originalDescriptor);
39+
}
40+
}
41+
42+
function expectedUnsafeSqliteError(version: string, shared: boolean): string {
43+
const wording = shared ? "uses shared system" : "embeds";
44+
const remediation = shared
45+
? "Upgrade the system SQLite library to 3.51.3+ (or patched 3.50.7+/3.44.6+), or use a Node build embedding a safe version."
46+
: "Upgrade to Node 22.22.3+, 24.15.0+, or 25.9.0+ before retrying.";
47+
return (
48+
"SQLite support is unavailable or unsafe in this Node runtime. " +
49+
"OpenClaw requires SQLite 3.51.3+ (or patched 3.50.7+/3.44.6+) for WAL safety; " +
50+
`Node ${process.versions.node} ${wording} SQLite ${version}, which is affected by the upstream WAL-reset ` +
51+
`database corruption bug. ${remediation}`
52+
);
53+
}
54+
2155
describe("node SQLite safety", () => {
2256
beforeEach(() => {
2357
vi.resetModules();
@@ -39,7 +73,27 @@ describe("node SQLite safety", () => {
3973
"rejects vulnerable or unknown SQLite %s",
4074
async (version) => {
4175
const { requireNodeSqlite } = await loadNodeSqliteWithVersion(version);
42-
expect(() => requireNodeSqlite()).toThrow(`embeds SQLite ${version}, which is affected`);
76+
expect(() => requireNodeSqlite()).toThrow(`SQLite ${version}, which is affected`);
77+
},
78+
);
79+
80+
it.each([true, "true"])(
81+
"rejects vulnerable shared SQLite with system-library remediation (%j)",
82+
async (nodeSharedSqlite) => {
83+
await withNodeSharedSqliteValue(nodeSharedSqlite, async () => {
84+
const { requireNodeSqlite } = await loadNodeSqliteWithVersion("3.51.2");
85+
expect(() => requireNodeSqlite()).toThrow(expectedUnsafeSqliteError("3.51.2", true));
86+
});
87+
},
88+
);
89+
90+
it.each([false, "false"])(
91+
"rejects vulnerable embedded SQLite with Node-upgrade remediation (%j)",
92+
async (nodeSharedSqlite) => {
93+
await withNodeSharedSqliteValue(nodeSharedSqlite, async () => {
94+
const { requireNodeSqlite } = await loadNodeSqliteWithVersion("3.51.2");
95+
expect(() => requireNodeSqlite()).toThrow(expectedUnsafeSqliteError("3.51.2", false));
96+
});
4397
},
4498
);
4599

‎src/infra/node-sqlite.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,18 @@ function assertSqliteWalResetSafeVersion(version: string, nodeVersion: string):
1111
if (isSqliteWalResetSafeVersion(version)) {
1212
return;
1313
}
14+
const variables = (process.config as { variables?: Record<string, unknown> } | undefined)
15+
?.variables;
16+
const isShared =
17+
variables?.node_shared_sqlite === true || variables?.node_shared_sqlite === "true";
18+
const wording = isShared ? "uses shared system" : "embeds";
19+
const remediation = isShared
20+
? "Upgrade the system SQLite library to 3.51.3+ (or patched 3.50.7+/3.44.6+), or use a Node build embedding a safe version."
21+
: "Upgrade to Node 22.22.3+, 24.15.0+, or 25.9.0+ before retrying.";
1422
throw new Error(
1523
`OpenClaw requires SQLite 3.51.3+ (or patched 3.50.7+/3.44.6+) for WAL safety; ` +
16-
`Node ${nodeVersion} embeds SQLite ${version}, which is affected by the upstream WAL-reset ` +
17-
"database corruption bug. Upgrade to Node 22.22.3+, 24.15.0+, or 25.9.0+ before retrying.",
24+
`Node ${nodeVersion} ${wording} SQLite ${version}, which is affected by the upstream WAL-reset ` +
25+
`database corruption bug. ${remediation}`,
1826
);
1927
}
2028

0 commit comments

Comments
 (0)