Repository navigation
fix: session maintenance delays other Gateway requests - #148351
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. |
adc2961 to
3eda198
Compare
|
Codex review: needs maintainer review before merge. Reviewed September 14, 2026, 12:16 PM ET / 16:16 UTC. ClawSweeper reviewWhat this changesThe PR defers session-maintenance protection scans until cleanup candidates exist, adds regression coverage, and routes a wizard integration test through the existing database-capable test runner. Merge readiness✅ Ready for maintainer review This remains a useful, focused performance fix: current main still performs the unnecessary inventory scan. No blocking correctness findings were identified, and the supplied measurements support the improvement. Priority: P2 Review scores
Verification
How this fits togetherSession writes trigger background maintenance of OpenClaw’s per-agent SQLite stores. Maintenance identifies cleanup candidates, protects active conversations, and archives or removes eligible entries while sharing execution time with Gateway requests. flowchart TD
A[Session writes] --> B[Maintenance writer transaction]
B --> C{Cleanup candidates exist?}
C -->|No| D[Finish without protection scan]
C -->|Yes| E[Read protection inventory once]
E --> F[Apply existing retention rules]
F --> G[Archive or remove eligible entries]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +5, Tests +100, Docs +4. Total +109 across 8 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep candidate-driven protection reads within the existing maintenance transaction, preserving retention semantics and avoiding a separate cache or scheduler. Do we have a high-confidence way to reproduce the issue? Yes: current main unconditionally projects the protection inventory before candidate selection, making repeated no-work maintenance scans source-reproducible. The PR supplies baseline/candidate measurements; this review did not execute code. Is this the best way to solve the issue? Yes: deferring the existing read within the same synchronous transaction removes unnecessary work without duplicating policy, changing storage contracts, or introducing cache invalidation. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 50090f5df4e9. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
* perf(sessions): skip idle maintenance protection scans * test: run wizard recovery with the host broker
What Problem This Solves
Fixes: automatic session maintenance delays other Gateway requests when a large session inventory has no entries eligible for cleanup.
User Impact
Routine session writes avoid repeatedly reading the entire protection-key inventory when maintenance has no age or cap candidates. Active work, parent sessions, lifecycle operations, retention rules, and writer ordering keep their existing behavior. No configuration change, migration, or schema change is required.
Why This Change Was Made
The shared planner now obtains its protection set once, immediately before its first phase with candidates. This includes cap-only cleanup after an empty age scan. SQLite retains the same synchronous transaction and ownership checks; legacy, preview, and file-backed callers retain their prepared protection sets.
Evidence
The new no-work regression fails on the original code with 96 unnecessary projected rows across three ordinary writes and passes with zero. Both cap-only and age-plus-cap cases retain active-admission, lifecycle, provider, active-key, and parent protection. All 107 focused tests passed, covering maintenance, legacy read/write parity, cleanup previews, pruning, cap archives, stale handles, and write-triggered maintenance. The full build and all changed-source checks passed for the profiled maintenance commit. Fresh independent Codex review through P2 found no actionable issues in the final combined diff.
A serial baseline/candidate/candidate/baseline measurement used byte-identical closed databases with 3,550 rich session entries, eight active admissions, eight warmups, and 60 measured maintenance transactions per cell. Mean transaction wall time fell from 10.65 to 1.53 ms, and CPU from 10.94 to 1.60 ms (85.4% less). Every canonical database row remained unchanged.
A separate paired Gateway run used the same synthetic fixture and fixed workload: 16 turns, 64 history reads, 64 updates, and 16 rounds of list, readiness, Control UI, and subscription probes. Both runs completed all requests without failures and exited cleanly.
Maintenance writer execution fell from 1,269 ms across 60 admissions to 251 ms across 66 admissions. Foreground request counts match; asynchronous background work can vary. Other results were mixed: readiness p50 rose from 9 to 16 ms, and entry-patch summed queue wait rose from 4,199 to 4,391 ms with 151 versus 147 patches. This single paired run is a point measurement, not a claim that all queueing or latency is fixed.
Baseline source:
7cf2696575cb604a8afa02af5187a65834f5b63e; candidate:adc29616e0816039ab4a9ece0ba65ceb049bdad4. These are isolated synthetic measurements, not deployed latency claims. The raw readiness delay can retain profiler-start overhead, and the mock request total includes setup; neither is used as an in-load CPU measurement.CI Repair
The first CI run exposed an unrelated failure introduced on main by #148195: the new wizard recovery integration test ran in a worker thread, but its pending-install migration requires the host-owned SQLite broker. It reproduces unchanged on main with the same assertion failure. This PR adds that test to the existing forked database-consumer routing list, preserving production code, authority checks, and assertions. The exact test, setup-flow and install-rollback siblings, and routing checks pass: 170 focused cases, plus the tooling changed-source checks.
The branch was refreshed onto
bfaac101391ec82d66aa443c589f580cc82bf656for this CI repair. All seven maintenance files remain byte-identical to the profiled candidate above; the final head is3eda1981dceb08ad7cd09263d36c010930d3884c.