Repository navigation
improve: prepare dirty session-list facts off the Gateway thread - #155388
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. |
|
Codex review: needs maintainer review before merge. Reviewed September 22, 2026, 2:58 AM ET / 06:58 UTC (Revision 3). ClawSweeper reviewWhat this changesMoves dirty session-list database reads into the existing history worker and strengthens handling of delayed replies, replaced databases, and coalesced session-change events. Merge readiness✅ Ready for maintainer review The PR remains useful: current main still prepares dirty session rows synchronously. No blocking introduced correctness or security defect was found, and the maintainer-protected work should remain open. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway maintains an in-memory session list from committed database changes. Worker-prepared metadata feeds that projection, which applies current viewer permissions before returning session lists and events. flowchart TD
A[Committed session changes] --> B[Dirty session rows]
B --> C[History worker]
C --> D[SQLite snapshot facts]
D --> E[Revision and generation checks]
E --> F[Resident session projection]
F --> G[Current viewer checks and responses]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +360, Tests +364, Docs +9. Total +733 across 26 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Use the existing history worker for bounded dirty-row preparation while retaining the projection’s invalidation, lifecycle, and current-viewer authorization owners. Do we have a high-confidence way to reproduce the issue? Yes at source level: dirty session-list refreshes on current main synchronously read and materialize database facts. Runtime latency was not independently reproduced in this read-only review. Is this the best way to solve the issue? Yes. Extending the existing history worker preserves one database lifecycle owner and one projection, without adding configuration, persistent state, or a parallel cache. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2d84bb11af03. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
Merged via squash auto-merge.
|
…nclaw#155388) * fix(sessions): prepare dirty row facts in history workers * style(sessions): satisfy row fact lint guards * fix(sessions): retain row reader admission across worker refreshes * fix(gateway): recapture coalesced session change identities * fix(sessions): distinguish recreated stores after inode reuse
Startup admission and the catalog-triggered background drain could acquire the same session facts concurrently. The asynchronous acquisition introduced in 42263f8 (#155388) left that overlap possible; selected-page readiness in 1b896e6 (#162280) no longer joins the entire background drain. Keep one pending batch in the refresh owner so both callers share its work. Preserve exact-read priority, retained facts, invalidation and failure cleanup. Extend the registered list regression to hold admission against the background drain and assert one acquisition per row, while keeping the zero-read catalog refresh and concurrent committed-update assertions. Validation: original production acquires both fixture rows twice; the fixed producer acquires each once. All 169 tests across 17 owner and sibling files pass. Both cycle checks report zero cycles; core plus Gateway root, server and method test types, strict targeted lint and formatting pass.
Startup admission and the catalog-triggered background drain could acquire the same session facts concurrently. The asynchronous acquisition introduced in 64e58bb (openclaw#155388) left that overlap possible; selected-page readiness in d13db6a (openclaw#162280) no longer joins the entire background drain. Keep one pending batch in the refresh owner so both callers share its work. Preserve exact-read priority, retained facts, invalidation and failure cleanup. Extend the registered list regression to hold admission against the background drain and assert one acquisition per row, while keeping the zero-read catalog refresh and concurrent committed-update assertions. Validation: original production acquires both fixture rows twice; the fixed producer acquires each once. All 169 tests across 17 owner and sibling files pass. Both cycle checks report zero cycles; core plus Gateway root, server and method test types, strict targeted lint and formatting pass.
What Problem This Solves
Dirty session-list refreshes perform per-row SQLite reads on the Gateway thread, delaying other work while reading membership, boards, and activity-summary validity.
User Impact
Persistent dirty-row preparation now runs in the existing history worker. Session-list contents and sharing behavior remain the same. There is no schema/version bump, migration, config change, retention change, or operator action.
Why This Change Was Made
Each batch selects at most 64 rows and reads entry metadata, membership, board presence, and summary watermarks from one snapshot per physical store. The projection retains database ownership through consumption and rejects replies after its revision, registry snapshot, or selected row generation changes. Direct reads that already refreshed a row keep their newer facts.
The existing timed materialization loop serves both direct and prepared reads. Physical store reuse also compares the owner’s recorded birth time, so a newly created database cannot inherit stale rows when the filesystem reuses an inode. Coalesced session-change notices refresh their captured generation and capture-failure status with their newest payload. Startup/topology hydration, direct keyed/archive reads, incognito stores, and optional transcript backfill remain separate migration work. Existing worker startup and transfer costs still apply.
Related: #153683.
Evidence
The foreground regression observes 3 → 0 targeted Gateway-thread data reads. Restoring the original caller makes the final fixture fail on watermark, board, and membership SQL.
A real peer commit between entry decoding and further reads proves entry/member/board/hot-generation/cold-sequence facts share one SQLite snapshot. Missing stores remain empty; unavailable metadata refuses the read.
A pending real worker reply reproduced replacement of a newer keyed session. The generation fence preserves the newer row and passes that regression.
62 existing projection cases passed, covering aliases, cross-agent inheritance, archive behavior, registry invalidation, disposal, and committed writes. The physical-replacement fixture now awaits the existing resource-drain owner before renaming its database. The snapshot fixture reuses the session window created by the normal writer.
Final focused rerun: 9 passed, including those two corrected fixtures, the new race, foreground SQL, and cross-batch child moves/deletion. Gateway test bodies: 7.36 s foreground, 5.75 s cross-batch relations, 4.62 s replacement, 8.71 s pending-reply race. Snapshot test body: 0.30 s. The complete final focused command took 224.58 s wall time; worker compilation dominates the wrapper cost.
The source-matched CI fixture passed on PR merge e59eda457beda5d7d909ea57eb48860530dd9c10: 2,048 rows with 32 writes during drain, 2.382 s elapsed / 1.126 s calling-thread CPU, +46.887 MiB heap and +77.930 MiB RSS snapshots. Test duration was 5.395 s. CPU is inclusive, not isolated transfer/deserialization; memory deltas are not peaks. CI evidence.
Core and all core-test type graphs passed. Selected local source guards passed; the initial lint run found two shadowed names and a conditional map spread, corrected and verified with targeted lint. The final mechanical delta has its own clean P2 review. CI run 35683118612 failed in seven shards. Retained logs exposed fixture request-lifetime, teardown, historical-clock and optional-preview assumptions, plus a retained-reader admission compatibility gap. Those repairs passed 67 selected cases, formatting, and type-aware lint on the exact 4ed2517 tree in an isolated Blacksmith run. The next exact-head CI passed all type, lint, dependency, and import-cycle checks; it exposed the already-fixed main reload fixture issue and order-dependent chat failures. Full original-file replay reproduced the chat failures; temporary diagnostics distinguished missing projected metadata from changed database metadata. The original inode-reuse and event-capture implementations each failed their new regression assertion. With the repairs, 2 owner regressions and 193 event/chat cases passed, including full original chat-file order; formatting and targeted type-aware lint passed. The owner group took21.28s wall and the event/chat group103.48s; changed test bodies were1.395s for replacement and0.788s for recipient coalescing. Linux proof uses the delegated wrapper’s successful receipt (the backing lease job can be cancelled during cleanup). Its persistent-store identity encoding predates the final equivalent separate-field comparison, which preserves symbol identity and has a clean P2 review. Required exact-head GitHub CI remains enforced.
A synthetic transfer probe measured 4,661 UTF-8 JSON bytes for 8 rows × 4 members and an 88,903-byte first reply for 64 rows × 32 members. The larger drain split across 64/38/7-row requests under the unchanged materialization budget and took 51.17 ms wall / 37.94 ms caller CPU. Synchronous consumer slices reached 12.25 ms wall. These are single synthetic observations: JSON size is not IPC wire size, await CPU is inclusive, and memory snapshots are not peaks. No production speedup or memory ceiling is claimed.