Repository navigation
Conversation
|
🦞👀 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. |
3825145 to
275fb92
Compare
|
Codex review: needs real behavior proof before merge. What this changesAdds a five-minute watchdog for deadline-less host callbacks and rotates worker pools after sustained SQLite WAL checkpoint blocking. Example: A transcript export's first asynchronous chunk consumer never returns.
Review scores
ProductKind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Complete Merge readiness⛔ Blocked before merge - 4 items remain This PR addresses a concrete unbounded worker callback path that remains on current main, but the automatic recovery introduces availability defects and the SDK-wide timeout policy needs an owner decision. Priority: P2 Decision needed
Before merge
Findings
Tests
Agent review detailsHow this fits togetherSQLite streaming readers exchange chunks with host consumers through the worker scheduler; checkpoint observations feed the proposed recovery registry, which invokes pool rotation. flowchart TD
A[Transcript export] --> B[Worker task pool]
B --> C[SQLite streaming reader]
C --> D[Host chunk consumer]
D --> B
E[WAL checkpoint observations] --> F[Recovery registry]
F --> B
Technical reviewBest possible solution: Bound the stranded callback through the existing deadline owner and keep WAL recovery scoped to reader resources without pausing unrelated pool dispatch. Do we have a high-confidence way to reproduce the issue? Source establishes that an unresolved first asynchronous chunk callback can retain a streaming reader without a task deadline; identifying that callback as the reported production blocker remains unproven. Is this the best way to solve the issue? A bounded callback is useful, but process-wide rotation is broader than the demonstrated failure and conflicts with the existing scheduler's pause-and-drain semantics. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f28188b078ce. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +114, Tests +326, Other +1. Total +441 across 8 files. Added test files: 2. View PR surface stats
Review metrics
LabelsLabel 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 21, 2026, 5:54 PM ET / 21:54 UTC. |
|
Follow-up commit The pool-side recovery from this PR could not fire for the shared-state store's second block episode. Root cause is a thread-scope mismatch:
This commit arms a thread-local recovery at every worker-thread state-DB open that has a real maintenance owner: on a sustained block the thread recycles its own cached state handles ( Also verified in the running dist bundle (gateway import graph, Regression coverage: |
…er threads The shared-state WAL maintenance chains live on worker threads (state worker, agent execution workers), while the blocked-reader recovery registry and checkpoint listeners are per-thread global singletons. Pool-side recovery was only ever armed on the pool-owning main thread, so a sustained block observed on a worker thread reached no hook at all, and pool rotation could not close worker-thread handles anyway. Arm a thread-local recovery at every worker-thread state-DB open that recycles that thread's cached handles, and release the long-lived retains held by the state/agent-execution workers so the reference- counted close can retire the pinned connection.
9019711 to
f664f03
Compare
|
Closing per owner directive 2026-10-24: upstream PR work retired; the full fix stack now lives on the local fork main (merge 31bc2929b92 + 90197113124), CI-proven in the consolidation worktree. Local-only delivery going forward. |
fix(worker-runtime,infra): bound host callbacks and recover WAL-blocked readers
What Problem This Solves
On production gateways, WAL checkpoint maintenance can become permanently stuck
(
PASSIVE blocked by a reader,consecutiveBlockedclimbing for hours, externalTRUNCATE busy=1, restart-only recovery). The stuck reader is invisible to currentdiagnostics (
blockingOwner:"unknown",trackedReaders:0,transactionOpen:false).The mechanism: a pooled worker parked in an interactive task exchange holds an
unexhausted native
node:sqlitecursor; the task has no deadline, so a host requesthandler that never settles can never be cancelled, the worker is never retired, and its
connection pins the WAL read mark forever. This PR bounds the host-callback phase for
deadline-less interactive tasks (so the existing cancel → retire → unwind path finally
fires) and adds a WAL-blocked-reader safety net that rotates idle pooled connections
when a checkpoint stays blocked for ~2 minutes. The live incident this fixes: gateway
2026.10.4 on host EVOMACH-PETROS,
state/openclaw.sqlitepinned at frame 129 with2133+ consecutive blocked observations and a 181 MB journal.
Evidence
Live symptom (host EVOMACH-PETROS, gateway 2026.10.4). WAL checkpoints on
state/openclaw.sqliteandagents/main/agent/openclaw-agent.sqlitestayedPASSIVE blocked by a readerpermanently:consecutiveBlockedreached 2133+, only129/44081 frames folded (WAL grew to 181 MB), external
TRUNCATEreturnedbusy=1, andonly a gateway restart folded the journals. Diagnostics reported
blockingOwner:"unknown",trackedReaders:0,transactionOpen:false— the pin wasinvisible to wrapper tracking.
Root cause (proven, file:line). Long-lived pooled read workers park inside
interactive task exchanges:
src/transcripts/store-export.worker.ts:106,111andsrc/agents/subagents/registry/subagent-registry.store.worker.ts:103runawait channel.request(batch)afterBEGINwith a suspendediterate(); theircleanup (ROLLBACK + close) only runs if the await settles.
src/state/openclaw-state-read-worker.tsstartRunpasses notimeoutMsin taskoptions.
packages/worker-runtime/src/worker-task-pool-core.tsarms a task timer onlywhen
options.timeoutMsis set (and re-arms after each host response). An async hosthandler that never settles — e.g.
src/transcripts/store-worker-client.ts:47awaitinga consumer that never returns — leaves the task with no deadline forever: no
timeout, no cancel, no retire, and the parked worker (with its native cursor) pins the
WAL read mark indefinitely.
node:sqlite, Node 24.18, two threads) reproduces the livefingerprint exactly: after a parked reader plus WAL growth,
PASSIVE busy=0 log=1326 checkpointed=664andTRUNCATE busy=1, and the wal-index header keeps anaReadMarkpinned at the abandoned frame — with
transactionOpen=falseand zero tracked readers,matching the live diagnostics. Abandoning an unexhausted
iterate()(with or withoutan open transaction) is sufficient to pin the mark; it survives
COMMIT/ROLLBACKonthe same connection and releases only when the statement is re-stepped to exhaustion
or the connection closes.
7.5 h / 55 min / 23 min), consistent with suspended async consumers being abandoned at
yield boundaries. Cancel → retire → unwind demonstrably works (the repro's
pool.rotate()folded the WAL in milliseconds), so the bug is purely that nothing evertriggers cancellation for deadline-less interactive tasks.
iterateSqliteQuerySyncgenerator wrapper insrc/infra/kysely-sync.tsis itselfsound (try/finally disposes the statement on every close path); a sustained pin
requires the generator to be held by a suspended async frame — the same class the
watchdog below bounds.
This fix.
packages/worker-runtime: a bounded host-callback watchdog. When an interactive(
onRequest) exchange arrives on a task that currently has no deadline, the poolarms a watchdog (
hostCallbackTimeoutMs, default 300 s) so a never-settling hosthandler times the task out, which cancels and retires the parked worker — letting its
native cleanup unwind and release the pinned read mark. Tasks with an explicit deadline
keep their existing authority (watchdog stays disarmed);
hostTimeout:"owner"(CodeMode) keeps its unbounded owner-managed wait; a healthy multi-chunk stream is unaffected
because each host response re-arms the normal timeout.
src/infra/sqlite-wal-blocked-reader-recovery.ts(new, registered inscripts/pr-lib/wrapper-components.txt): safety net. If any WAL stays blocked for 12consecutive checkpoint observations (~2 min), registered recovery hooks rotate idle
pooled worker connections, so pinned read marks are released even for leak vectors this
fix does not yet cover. A 10-minute cooldown bounds the fan-out.
src/infra/worker-task-pool.ts: both pool entry points (WorkerTaskPool,createOwnedWorkerTaskPool) register a rotate hook for their lifetime; rotation neverinterrupts running tasks (it defers until they settle).
Tests (green).
packages/worker-runtime/src/worker-task-pool.host-callback-timeout.test.ts(4 new):never-settling handler times out and the parked worker is terminated; a healthy 6-chunk
stream is not capped;
hostTimeout:"owner"stays unbounded; an explicit task deadlineremains the authority. Full
packages/worker-runtimeshard passes 30/30 undervitest.unit-support.config.ts.src/infra/sqlite-wal-blocked-reader-recovery.test.ts(4 new): threshold trigger, cooldown throttle, unregister, failing-hook containment —
green under
vitest.infra.config.ts.check:wrapper-shadowingpasses;check:import-cyclesreports 0 runtime cycles. (worker-task-pool.owned.test.tsand onesqlite-wal/sqlite-wal-checkpointcase fail identically without this diff on thisWindows host:
workerScriptNameERR_INVALID_FILE_URL_PATHand APFS-evidence tests;unrelated to the change.)
Honesty note. The exact per-call-site culprit (which consumer abandoned which
iterator) cannot be named from existing gateway diagnostics without instrumented replay;
this PR fixes the mechanism (an unbounded host-callback phase strands a parked worker)
and adds recovery for any residual pin, rather than patching one call site. The
WORKER_HOST_CALLBACK_TIMEOUTprocess warning added by the timeout path names thepending exchange (or the worker file behind it), which will localize each real offender
as it fires.
What to watch after this ships
consecutiveBlockedshould reset within ~14 ticks (~2 min) instead ofclimbing for hours;
walBytesshould fall back to MB scale.WORKER_HOST_CALLBACK_TIMEOUTwarnings: a non-zero rate identifies the exact strandedconsumers (the message names the pending exchange or the worker file behind it) — the
signal for follow-up per-site fixes.
held outside worker-task pools (e.g. a long-lived
hostTimeout:"owner"task); thewarning stream plus wal-index
aReadMarkslots would localize it.