Repository navigation
fix(infra): guard delivery queue inflate against corrupted entry_json - #98354
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 1, 2026, 12:02 AM ET / 04:02 UTC. Summary PR surface: Source +6, Tests +162. Total +168 across 2 files. Reproducibility: yes. Current main and v2026.6.11 have an unguarded JSON.parse in the shared SQLite queue inflater, and the PR body includes a negative-control run showing the same corrupt row crashes on main; I did not execute tests in this read-only review. Review metrics: 1 noteworthy metric.
Stored data model Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Next step before merge
Security Review detailsBest possible solution: Land the shared inflate-boundary guard and regression tests through normal maintainer merge gating. Do we have a high-confidence way to reproduce the issue? Yes. Current main and v2026.6.11 have an unguarded JSON.parse in the shared SQLite queue inflater, and the PR body includes a negative-control run showing the same corrupt row crashes on main; I did not execute tests in this read-only review. Is this the best way to solve the issue? Yes. Guarding the shared SQLite inflate chokepoint is the narrowest maintainable fix; catching this separately in session and outbound recovery callers would duplicate policy and leave single-load/update paths exposed. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 63dc9201c6b6. Label changesLabel justifications:
Evidence reviewedPR surface: Source +6, Tests +162. Total +168 across 2 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
…openclaw#98354) * fix(infra): guard delivery queue inflate against corrupted entry_json * fix(infra): use toSorted in delivery queue test
…openclaw#98354) * fix(infra): guard delivery queue inflate against corrupted entry_json * fix(infra): use toSorted in delivery queue test
…openclaw#98354) * fix(infra): guard delivery queue inflate against corrupted entry_json * fix(infra): use toSorted in delivery queue test (cherry picked from commit 302524b)
…openclaw#98354) * fix(infra): guard delivery queue inflate against corrupted entry_json * fix(infra): use toSorted in delivery queue test (cherry picked from commit 302524b)
…openclaw#98354) * fix(infra): guard delivery queue inflate against corrupted entry_json * fix(infra): use toSorted in delivery queue test (cherry picked from commit 302524b)
What Problem This Solves
Fixes an issue where a single corrupted
entry_jsonrow in the SQLite delivery queue (session or outbound) crashes the entire pending-entry load, preventing delivery recovery from making progress. Theinflate()helper callsJSON.parse(row.entry_json)without a try-catch — a corrupt row throws an uncaughtSyntaxErrorthat propagates throughloadDeliveryQueueEntry(single load),loadDeliveryQueueEntries(batch load — one bad row kills all pending entries),updateDeliveryQueueEntry, andmoveDeliveryQueueEntryToFailed. Callers in session-delivery recovery, outbound recovery, and the gateway restart sentinel do not catch this error, so a single corrupt SQLite row can block all queued delivery retries.Why This Change Was Made
Guard
inflate()itself — the shared chokepoint through which all queue reads flow. On parse failure it returnsnull.loadDeliveryQueueEntryalready returnsnullfor a missing row, so corrupt rows are treated the same way (unrecoverable → not found).loadDeliveryQueueEntriesfilters outnullinflate results, so one corrupt row no longer discards every other pending entry in the same queue.updateDeliveryQueueEntryandmoveDeliveryQueueEntryToFailednow throw a cleanENOENT(vialoadDeliveryQueueEntry) instead of a rawSyntaxError, consistent with how they behave when an entry is genuinely absent. No API surface changes.User Impact
No user-visible impact under normal operation. When
entry_jsonis somehow corrupted (disk error, manual edit, partial write), delivery recovery now skips the bad entry instead of crashing. Recovery and gateway restart sentinel paths remain operational for the remaining valid entries.Real behavior proof
entry_jsonrow in the SQLitedelivery_queue_entriestable must not crash delivery queue loads; the corrupt row should be treated as unrecoverable (null/skipped) while valid rows continue to load.fix/delivery-queue-inflate-json-parse, driving the real exportedloadDeliveryQueueEntry,loadDeliveryQueueEntries,updateDeliveryQueueEntry, andmoveDeliveryQueueEntryToFailedfromsrc/infra/delivery-queue-sqlite.tsagainst a real on-disk SQLite database (OPENCLAW_STATE_DIR). Corrupt rows are inserted directly via raw SQL (same write path asupsertDeliveryQueueEntryuses internally) and read back through the real exported loaders across the SQLite disk boundary. 18 assertions covering 6 scenarios.src/infra/delivery-queue-sqlite.tsto main (4ac5cf8636) and re-running the same proof harness crashes on case 1 with the uncaughtSyntaxError— the corrupt row that returnsnullafter the fix instead throws and aborts the entire batch:The negative control is load-bearing: the same proof harness, same corrupt rows, same disk boundary crashes on main and passes 18/18 after the fix. Restoring the fix from the branch (
git checkout HEAD -- src/infra/delivery-queue-sqlite.ts) and re-running returns to 18/18 green.loadDeliveryQueueEntry←loadPendingDelivery,loadDeliveryQueueEntries←loadPendingDeliveries/loadPendingSessionDeliveries), against a real SQLite database across the disk boundary, which exercises the shared chokepoint.Evidence
Regression tests (11 tests, all pass):
Covers: corrupt single-row → null, corrupt-in-batch → skipped, all-corrupt-batch → empty array, update-with-corrupt → clean ENOENT, move-to-failed-with-corrupt → clean ENOENT, plus valid-entry round-trips (upsert/load, update, delete).
Existing tests — no regressions:
Lint:
oxlintclean on both changed files.AI-assisted.