Repository navigation
Description
Bug type
Crash (process/app exits or hangs)
Beta release blocker
No
Summary
Doctor and gateway operations repeatedly stall while synchronous agent database maintenance transactions hold the main thread for 3.7–4.4 seconds.
Steps to reproduce
The reported runtime was a source-checkout installation running openclaw doctor --fix against existing state. Its trace repeatedly identifies agent.database.maintenance.admission with all measured hold time in sqlMs. The original database is not attached; a minimal shareable production-state reproducer is not available.
The accompanying source regression enters an existing-state SQLite write transaction under withAgentDatabaseMaintenanceLease, invokes maintenance.assertOwnedInTransaction(db), and asserts that it opens no separate read-only state readers. It uses the real SQLite and lease implementations; its spy observes the read-only entry point without replacing it.
Expected behavior
The transaction-aware ownership contract in OpenClawStateLeaseContext should check ownership using the supplied held transaction, retaining scope, ownership/expiry and heartbeat checks without redundant independent snapshot reads.
Actual behavior
The maintenance wrapper calls its no-argument ownership check before delegating to the transaction-aware owner. That no-argument path opens independent read-only state snapshots while the write transaction is held. The wrapper is present unchanged in upstream base f215c401e69a22547b31b9e1a2436944ab9528a7.
OpenClaw version
Source-checkout report; exact affected binary revision: NOT_ENOUGH_INFO. The PR regression candidate is based on upstream f215c401e69a22547b31b9e1a2436944ab9528a7 (package version 2026.9.8).
Operating system
macOS 26.6.2, ARM64 (captured process sample).
Install method
Source-checkout CLI.
Model
Not applicable to this SQLite maintenance operation.
Provider / routing chain
Not applicable; local SQLite maintenance.
Logs
User-reported runtime trace; database path redacted:
17:42:11 [sqlite/transaction] slow SQLite transaction hold async=false database=<state>/openclaw.sqlite operation=agent.database.maintenance.admission elapsedMs=3803 phases={"beginMs":0,"sqlMs":3803,"hostAdmissionWaitMs":0,"commitMs":0} isMainThread=true mode=immediate pid=23567 threadId=0 thresholdMs=1000
17:42:17 [sqlite/transaction] slow SQLite transaction hold async=false database=<state>/openclaw.sqlite operation=agent.database.maintenance.admission elapsedMs=4417 phases={"beginMs":0,"sqlMs":4417,"hostAdmissionWaitMs":0,"commitMs":0} isMainThread=true mode=immediate pid=23567 threadId=0 thresholdMs=1000
17:42:22 [sqlite/transaction] slow SQLite transaction hold async=false database=<state>/openclaw.sqlite operation=agent.database.maintenance.admission elapsedMs=3706 phases={"beginMs":0,"sqlMs":3706,"hostAdmissionWaitMs":0,"commitMs":0} isMainThread=true mode=immediate pid=23567 threadId=0 thresholdMs=1000
Impact and severity
The reporter describes repeated doctor/gateway lockups. Three captured warnings show synchronous main-thread holds of 3803, 4417 and 3706 milliseconds. This blocks the diagnostic workflow while each transaction runs. No data-loss claim is made.
Screenshots, recordings, and evidence
52 focused tests passed (17 unit, 35 infra) on Node 24.16.0. Wall time: 37.49 seconds. Candidate: 91861fd6289c48a66e8c9ad07a1f8f71c2a2147f, based on public upstream f215c401e69a22547b31b9e1a2436944ab9528a7. The test run preceded the commit; both committed files match the tested checkout bytes. No hosted CI result is available yet.
pnpm test src/state/openclaw-agent-db-maintenance.test.ts src/state/openclaw-state-lease-existing.test.ts src/state/openclaw-state-db-existing-write.test.ts --maxWorkers=1Saved regression execution trace (checkout path redacted; compiler preparation warnings omitted)
[test] starting test/vitest/vitest.unit.config.ts
RUN v5.0.1 <checkout>
✓ |unit| src/state/openclaw-state-db-existing-write.test.ts > retained existing-state writer > refuses invalid and restricted repair admission before acquiring schema maintenance 50ms
✓ |unit| src/state/openclaw-state-db-existing-write.test.ts > retained existing-state writer > preserves a replacement appearing during schema lease acquisition 166ms
✓ |unit| src/state/openclaw-state-db-existing-write.test.ts > retained existing-state writer > retains WAL files and one integrity admission through ordinary local and foreign writes 16ms
✓ |unit| src/state/openclaw-state-db-existing-write.test.ts > retained existing-state writer > readmits canonical same-version lazy DDL once before resuming warm subset writes 162ms
✓ |unit| src/state/openclaw-state-db-existing-write.test.ts > retained existing-state writer > retains a failed close for cleanup while refusing further writes 5ms
✓ |unit| src/state/openclaw-state-db-existing-write.test.ts > retained existing-state writer > rejects replacement before a retained write callback 5ms
✓ |unit| src/state/openclaw-state-db-existing-write.test.ts > retained existing-state writer > rejects foreign schema before a retained write 5ms
✓ |unit| src/state/openclaw-state-db-existing-write.test.ts > retained existing-state writer > rejects foreign version before a retained write 5ms
✓ |unit| src/state/openclaw-state-db-existing-write.test.ts > retained existing-state writer > rejects deferred content marker removed before a retained write 91ms
✓ |unit| src/state/openclaw-state-db-existing-write.test.ts > retained existing-state writer > rejects role changed before a retained write 6ms
✓ |unit| src/state/openclaw-state-db-existing-write.test.ts > retained existing-state writer > rejects metadata version changed before a retained write 4ms
✓ |unit| src/state/openclaw-state-db-existing-write.test.ts > retained existing-state writer > rejects primary row deleted before a retained write 4ms
✓ |unit| src/state/openclaw-state-db-existing-write.test.ts > retained existing-state writer > rejects content version newer than supported before a retained write 4ms
✓ |unit| src/state/openclaw-state-db-existing-write.test.ts > retained existing-state writer > rejects content version malformed before a retained write 4ms
✓ |unit| src/state/openclaw-state-db-existing-write.test.ts > retained existing-state writer > rolls back rows and forbidden schema mutation: CREATE TABLE forbidden (id INTEGER) 4ms
✓ |unit| src/state/openclaw-state-db-existing-write.test.ts > retained existing-state writer > rolls back rows and forbidden schema mutation: PRAGMA user_version = 1 4ms
stderr | retireSqliteTestSingleton (<checkout>/test/sqlite-test-lifecycle.ts:221:13)
[sqlite-test-lifecycle] src/state/openclaw-state-db-existing-write.test.ts: retiring openclaw.stateDatabaseLifecycle
[sqlite-test-lifecycle] src/state/openclaw-state-db-existing-write.test.ts: retiring openclaw.stateSnapshotOwners
✓ |unit| src/state/openclaw-state-db-existing-write.test.ts > retained existing-state writer > rechecks current environment and schema scope for each retained write 98ms
Test Files 1 passed (1)
Tests 17 passed (17)
Start at 18:54:05
Duration 3.68s (transform 59%, tests 18%, worker 13%, setup 5%, import 5%)
[test] starting test/vitest/vitest.infra.config.ts
RUN v5.0.1 <checkout>
✓ |infra| src/state/openclaw-agent-db-maintenance.test.ts > asynchronous agent database maintenance admission > checks maintenance authority on the held transaction without opening separate readers 535ms
✓ |infra| src/state/openclaw-agent-db-maintenance.test.ts > asynchronous agent database maintenance admission > reuses one integrity process across agent maintenance while checking each file afresh 1049ms
✓ |infra| src/state/openclaw-agent-db-maintenance.test.ts > asynchronous agent database maintenance admission > yields during real integrity admission while retaining the maintenance fence 630ms
✓ |infra| src/state/openclaw-agent-db-maintenance.test.ts > asynchronous agent database maintenance admission > refuses a prepared Worker claim during plain maintenance 493ms
✓ |infra| src/state/openclaw-agent-db-maintenance.test.ts > asynchronous agent database maintenance admission > refuses a delegated prepared open before publishing a native handle during maintenance 443ms
✓ |infra| src/state/openclaw-agent-db-maintenance.test.ts > asynchronous agent database maintenance admission > fences Worker resume after expiry (integrity failure=false) 597ms
✓ |infra| src/state/openclaw-agent-db-maintenance.test.ts > asynchronous agent database maintenance admission > fences Worker resume after replacement (integrity failure=false) 560ms
✓ |infra| src/state/openclaw-agent-db-maintenance.test.ts > asynchronous agent database maintenance admission > fences Worker resume after abort (integrity failure=false) 554ms
✓ |infra| src/state/openclaw-agent-db-maintenance.test.ts > asynchronous agent database maintenance admission > fences Worker resume after expiry (integrity failure=true) 546ms
✓ |infra| src/state/openclaw-agent-db-maintenance.test.ts > asynchronous agent database maintenance admission > fences Worker resume after replacement (integrity failure=true) 585ms
✓ |infra| src/state/openclaw-agent-db-maintenance.test.ts > asynchronous agent database maintenance admission > fences Worker resume after abort (integrity failure=true) 582ms
✓ |infra| src/state/openclaw-agent-db-maintenance.test.ts > asynchronous agent database maintenance admission > refuses changed database owner before Worker resume repairs indexes (integrity failure=false) 603ms
✓ |infra| src/state/openclaw-agent-db-maintenance.test.ts > asynchronous agent database maintenance admission > refuses changed database version before Worker resume repairs indexes (integrity failure=false) 594ms
✓ |infra| src/state/openclaw-agent-db-maintenance.test.ts > asynchronous agent database maintenance admission > refuses changed database owner before Worker resume repairs indexes (integrity failure=true) 560ms
✓ |infra| src/state/openclaw-agent-db-maintenance.test.ts > asynchronous agent database maintenance admission > refuses changed database version before Worker resume repairs indexes (integrity failure=true) 549ms
✓ |infra| src/state/openclaw-agent-db-maintenance.test.ts > asynchronous agent database maintenance admission > joins a cancelled real Worker before closing its database or releasing the fence 450ms
✓ |infra| src/state/openclaw-agent-db-maintenance.test.ts > asynchronous agent database maintenance admission > rejects a retained closed maintenance context before opening or scanning 468ms
✓ |infra| src/state/openclaw-agent-db-maintenance.test.ts > asynchronous agent database maintenance admission > requires the exact active maintenance scope when its context is outside 448ms
✓ |infra| src/state/openclaw-agent-db-maintenance.test.ts > asynchronous agent database maintenance admission > requires the exact active maintenance scope when its context is copied 453ms
✓ |infra| src/state/openclaw-state-lease-existing.test.ts > acquires, verifies, renews and releases an actual timer lease without migrating 338ms
✓ |infra| src/state/openclaw-state-lease-existing.test.ts > acquires, verifies, renews and releases an actual worker lease without migrating 384ms
✓ |infra| src/state/openclaw-state-lease-existing.test.ts > takes plugin and agent writer ownership before candidate migration (provenance=true) 245ms
✓ |infra| src/state/openclaw-state-lease-existing.test.ts > takes plugin and agent writer ownership before candidate migration (provenance=false) 253ms
✓ |infra| src/state/openclaw-state-lease-existing.test.ts > refuses a competing owner and preserves a replacement lease on cleanup 93ms
✓ |infra| src/state/openclaw-state-lease-existing.test.ts > does not create missing existing-only lease state 2ms
✓ |infra| src/state/openclaw-state-lease-existing.test.ts > keeps the maintenance lease live across an explicitly owned migration 133ms
✓ |infra| src/state/openclaw-state-lease-existing.test.ts > waits through transient state contention before admitting existing-schema maintenance 595ms
✓ |infra| src/state/openclaw-state-lease-existing.test.ts > drains cached agent handles from another profile using their own lease database 388ms
✓ |infra| src/state/openclaw-state-lease-existing.test.ts > does not recreate state displaced before the existing-schema heartbeat opens 62ms
✓ |infra| src/state/openclaw-state-lease-existing.test.ts > reenters the same real maintenance owner without acquiring or migrating state 258ms
✓ |infra| src/state/openclaw-state-lease-existing.test.ts > refuses nested maintenance redirection before creating another database 247ms
✓ |infra| src/state/openclaw-state-lease-existing.test.ts > joins nested maintenance work before releasing the actual durable lease 278ms
✓ |infra| src/state/openclaw-state-lease-existing.test.ts > reports a failed detached maintenance child before releasing its real owner 237ms
✓ |infra| src/state/openclaw-state-lease-existing.test.ts > retains the first actual ownership failure through nested maintenance drainage 219ms
✓ |infra| src/state/openclaw-state-lease-existing.test.ts > shares a child-first lease loss with its parent and sibling scopes 226ms
Test Files 2 passed (2)
Tests 35 passed (35)
Start at 18:54:09
Duration 17.85s (tests 84%, transform 11%, setup 3%, import 2%)
[vitest-workers] verifying completed generation before cleanup
[vitest-workers] retained completed compiler outputs for reuse
[test] passed 2 Vitest shards in 37.49s
Additional information
The source fix passes the held connection through maintenance authority validation, preserving the active-scope and shared failure-latching checks. Last known-good release: NOT_ENOUGH_INFO.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
clawsweeper commentedon Oct 6, 2026
Codex review: this still needs some work. Reviewed October 6, 2026, 7:01 PM ET / 23:01 UTC.
Summary
Current main still contains the redundant ownership-read path. The reporter’s open fix PR owns this bounded defect, so the issue should remain open until that work is resolved.
Reproducibility: yes. for the redundant-read defect: existing-schema maintenance calls the ordinary reader from inside a held write transaction. The reported production stall durations were not reproduced in this read-only review.
Next step
Review and resolve the linked implementation PR; another repair PR would duplicate active contributor work.
Review details
Best possible solution:
Use the held transaction for durable ownership verification while preserving scope validity, expiry, heartbeat responsiveness, and shared failure latching.
Do we have a high-confidence way to reproduce the issue?
Yes for the redundant-read defect: existing-schema maintenance calls the ordinary reader from inside a held write transaction. The reported production stall durations were not reproduced in this read-only review.
Is this the best way to solve the issue?
Yes: forwarding the held connection through the existing ownership wrapper is the narrow repair, provided all existing authority and lifecycle checks remain intact.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
Codex review notes: model internal, reasoning medium; reviewed against 15bdb49009fc.
Label changes
Label changes:
P2: A bounded maintenance-path defect causes avoidable synchronous work; sustained core unavailability is not established.impact:crash-loop: The report concerns repeated main-thread stalls and process responsiveness during maintenance.issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.clawsweeper:source-repro: Current issue advisory state selects this label.clawsweeper:linked-pr-open: Current issue advisory state selects this label.clawsweeper:no-new-fix-pr: Current issue advisory state selects this label.Label justifications:
P2: A bounded maintenance-path defect causes avoidable synchronous work; sustained core unavailability is not established.impact:crash-loop: The report concerns repeated main-thread stalls and process responsiveness during maintenance.Evidence reviewed
What I checked:
src/state/openclaw-agent-db-maintenance-lease.ts:66, 15bdb49009fc)src/state/openclaw-state-lease-storage.ts:63, 15bdb49009fc)src/state/openclaw-agent-db-existing-write.ts:24, 15bdb49009fc)src/state/openclaw-state-lease-context.ts:16, 15bdb49009fc)src/state/openclaw-agent-db-maintenance-lease.ts:66, fc23bc864e45)Likely related people:
How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.