Repository navigation
Conversation
Node 24 before 24.18.1 restarts a finished StatementSync iterator on next() and keeps a WAL read snapshot, so checkpoints stay blocked and the -wal file grows until restart. Adds a known-issues row to the Node compatibility page and a troubleshooting entry keyed to the symptoms reported in openclaw#143524.
…e native sqlite iterator Node 24.16.0 through 24.18.0 (fixed in 24.18.1 by nodejs/node@af9ff0490c, CVE-2026-58041) restart a finished StatementSync iterator on next() and leave it stepped, holding a WAL read snapshot that blocks every checkpoint. The observed iterator wrapper now answers next() and return() itself once it has seen done, so the native iterator is never stepped again or finalized twice, whatever the runtime probe reports. Refs openclaw#143524
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs real behavior proof before merge. What this changesThis PR prevents completed SQLite iterators from reaching native next() or return() again and documents the associated WAL checkpoint problem. Example: An observed SELECT iterator on Node 24.18.0 is exhausted, then next() is called again.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Partial Merge readiness⛔ Blocked before merge - 2 items remain Keep this PR: it contributes a focused iterator safeguard and useful recovery guidance, but leaves superseded runtime probing in place. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe SQLite observer wraps statements opened through OpenClaw's database owner, translating native execution and iterator completion into custody and schema-observation updates. flowchart TD
A[Database caller] --> B[OpenClaw database owner]
B --> C[Native operation observer]
C --> D[Statement iterator]
D --> E[Node SQLite binding]
E --> F[SQLite WAL]
C --> G[Execution custody]
Technical reviewBest possible solution: Keep terminal handling in the existing observer and retire unused iterator-capability probing and transport while preserving SQLite library admission. Do we have a high-confidence way to reproduce the issue? The current observer source and upstream Node patch establish the restart mechanism on affected bindings, corroborated by the linked standalone output; no target code was executed during this review, and current Gateway runtime floors exclude those standard Node versions. Is this the best way to solve the issue? Enforcing terminal completion at the existing iterator owner addresses the demonstrated mechanism, but the obsolete capability machinery should be removed in the same cutover. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 7e15500187cd. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +4, Tests +39, Docs +38. Total +81 across 5 files. Added test files: 0. View PR surface stats
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 25, 2026, 10:09 PM ET / October 26, 2026, 02:09 UTC. |
|
Thanks @ava-perry for the investigation and fix! Landed the credited replacement in #190242 (2c0ab86), with real WAL checkpoint regressions and the obsolete probe removed. |
Summary
On Node 24.16.0 through 24.18.0 (fixed in 24.18.1), calling
next()on anode:sqliteStatementSynciterator that already returneddonerestarts the statement and leaves it stepped. The connection then holds a WAL read snapshot whileisTransactionisfalse, so every WAL checkpoint stays blocked and the-walfile grows until the Gateway restarts. The upstream fix is nodejs/node@af9ff0490c (CVE-2026-58041, "sqlite: invalidate tag store iterators on statement reset"), which also marks the iterator done onSQLITE_DONE. Root cause, bisect and production before/after: #143524.This PR:
done(fromnext()or from an earlierreturn()), laternext()andreturn()calls are answered by the wrapper with a fresh copy of the terminal result and never reach the native iterator. The native iterator is not stepped afterdoneand is not finalized twice. On main the engines field already excludes the affected releases; the guard removes the dependency on the probe and on the Node version./install/node-compatibility(the Fixed-in cell names nodejs/node@af9ff0490c and CVE-2026-58041) and a "SQLite WAL grows and checkpoints stay blocked" runbook on/gateway/troubleshooting/gateway-service-and-process, linked from the troubleshooting index.Why main's existing iterator check does not cover 24.18.0
Line numbers are on main
c96f35d5d60.assertSafeSqliteRuntime()(src/infra/sqlite-native-runtime.ts:124-184) runs fromopenNodeSqliteDatabase()(src/infra/node-sqlite.ts:112), once per process: the result is cached atsqlite-native-runtime.ts:127-129, and worker isolates reuse the parent's result through environment data (:130-140). It callsprobeSqliteIteratorBehavior()(src/infra/sqlite-native-observer.ts:25-45) on a one-row:memory:statement (sqlite-native-runtime.ts:149-154).doneonce more and recordsnextAfterDoneIsTerminal = previous.next().done === true(sqlite-native-observer.ts:29). On 24.18.0 that extranext()restarts the statement and returns the row again, so the probe correctly reportsfalse. The probe does not reject the runtime: the only hard gate in that function is the SQLite WAL-reset version check (assertSqliteWalResetSafeVersion,sqlite-native-runtime.ts:26-36, called at:135and:157), and SQLite 3.53.1 on 24.18.0 passes it. The probe result is stored asiteratorBehaviorand handed to the observer (node-sqlite.ts:107-115,sqlite-native-runtime.ts:168-183).next()still reaches the native iterator. The only consumer is the observed iterator wrapper. When nativenext()returnsdone, it setsdone = native.iteratorBehavior.nextAfterDoneIsTerminal(sqlite-native-observer.ts:346-347). On 24.18.0 that isfalse, so the wrapper only callslifetime.stopObservation(true)(:351) and leavesdonefalse. The next call passes the early-out at:336(doneis false), re-activates the lifetime (:339-342) and callsnativeNext.apply(this, args)(:345), which is exactly the restart. In other words the check makes the observer account for a restartable cursor (custody tracking); it does not prevent the restart, and nothing later steps the restarted statement todoneor resets it, so the snapshot stays held. On runtimes where the probe returnstrue, the post-done call is still forwarded (:336,done || ...), it is just harmless there.return()afterdoneis forwarded to native as well (:360-366).v2026.10.5,v2026.10.6andv2026.10.7tags do not containnextAfterDoneIsTerminal; their wrapper re-arms a finished lifetime and forwards post-donenext()unconditionally. 2026.10.5's engines field (>=24.16.0 <25 || >=26.1.0) admits 24.16.0 through 24.18.0; 2026.10.6 and 2026.10.7 require>=24.22.1 <25 || >=26.12.1.With this PR the wrapper answers from
terminalbefore any of that (sqlite-native-observer.ts:340-342and:363-365on this branch), so the outcome no longer depends on the probe or on the Node version.Scope
statement.iterate()on databases opened throughopenNodeSqliteDatabase(), wheretrackSqliteSchema()installs the observer (sqlite-schema-facts.ts:223). That is every OpenClaw state and agent database.node:sqliteuse outside it (non-test code undersrc,extensions,packages):new DatabaseSync(appears insrc/gateway/worker-environments/bootstrap.ts(:memory:), the workspace-quiescence worker scripts,src/infra/update-managed-service-handoff-sqlite-source.ts,src/infra/bun-sqlite-close-probe.worker.ts,src/infra/sqlite-native-runtime.ts(the probe itself,:memory:) and the knowledge-source-ingest skill scripts. Of these, two calliterate(): the close-capability probe worker (bun-sqlite-close-probe.worker.ts:28, onenext()on a temp database that it then closes, never pastdone) and the knowledge-source-ingest skill scripts (extensions/knowledge/skills/knowledge-source-ingest/scripts/source-manifest.mjs,discrawl-normalize.mjs), which usefor...ofloops in short-lived CLI processes on their own files. Afor...ofloop stops atdoneand never callsnext()again. So neither is exposed, and no Gateway state or agent database iterates outside the observer.iteratorBehavior.nextAfterDoneIsTerminalanditeratorBehavior.returnAfterDoneIsInertlose their only consumer in this diff. Grep finds no other reader: the remaining references are the probe (sqlite-native-observer.ts:16-45), admission parsing/transport (sqlite-native-runtime.ts:59-96) and one test (node-sqlite.test.ts:266-268). I left them in place to keep this PR small and can remove the probe and the transport field in a follow-up if you want.Tests
Run on a temporary Linux VM (Debian 12, n2-standard-16), not on the reporting Windows host. Branch head
4ddc356d618on basec96f35d5d60.node scripts/run-vitest.mjs run src/infra/sqlite-native-observer.test.ts src/infra/node-sqlite.test.tson Node 24.22.1: 2 files, 80 tests passed.sqlite-native-observer.test.ts:79) spies on the native iterator prototype'snextandreturn, finishes an iterator once by exhaustion and once byreturn(), then callsnext(),return(),next(),return(). It asserts all four results equal the terminal result, nativenextis not called again, nativereturnis called 0 times (exhausted) or exactly once (returned), and no native execution stays pending.expected "return" to be called +0 times, but got 2 times.next()forwarded as on main): fails withexpected "next" to be called 3 times, but got 5 times.sqlite-native-observer.tswith the new test: fails.next()once more, thenwal_checkpoint(PASSIVE)from a second connection): restarts and holds the snapshot on 24.16.0, 24.17.0, 24.18.0 and 26.4.0; returnsdoneand checkpoints fully on 24.18.1, 24.22.1 and 26.5.1. 26.5.1 carries the same CVE fix (nodejs/node@d08fde8a16).pnpm tsgo:core,pnpm tsgo:test:src,pnpm tsgo:all: all exit 0.pnpm format:docs:check: clean (1400 files). markdownlint (lint:docsconfig): 0 issues.pnpm docs:check-links: 16006 internal links, 0 broken.pnpm docs:check-mdx: passed.pnpm docs:check-links:anchorsreports 7 findings, none from this diff (all present on main, e.g.docs/gateway/troubleshooting.md:87, an unchanged line). The new links resolve:/install/node-compatibility#supported-versions(## Supported versions),#known-node-24-issues,/gateway/troubleshooting/gateway-service-and-process#sqlite-wal-grows-and-checkpoints-stay-blocked, and/cli/doctor/sqlite-maintenance(docs/cli/doctor/sqlite-maintenance.md).openclaw logs --followis documented indocs/cli/logs.mdand listed byopenclaw logs --help.Tested Node range for the bug: leaks on 24.16.0, 24.17.0 and 24.18.0, fixed in 24.18.1 (also clean on 24.19.0 through 24.22.1 in the Gateway bisect on #143524). Gateway-level reproduction and bisect were on Windows; the standalone repro and this test run were on Linux, so the bug is not OS-specific.
Related: #143524 (root cause), #164294 (same fingerprint, most reports list Node 24.18.0).