Skip to content

improve: prepare dirty session-list facts off the Gateway thread - #155388

Merged
steipete merged 6 commits into
mainfrom
codex/session-row-facts-worker
Sep 22, 2026
Merged

steipete merged 6 commits into
mainfrom
codex/session-row-facts-worker

Conversation

@steipete

@steipete steipete commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

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.

@clawsweeper

clawsweeper Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: L maintainer Maintainer-authored PR labels Sep 22, 2026
@steipete
steipete marked this pull request as ready for review September 22, 2026 03:20
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 22, 2026
@clawsweeper

clawsweeper Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 22, 2026, 2:58 AM ET / 06:58 UTC (Revision 3).

ClawSweeper review

What this changes

Moves 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
Reviewed head: ab5bdeb39ab79fa357beb8106b7a4324c0c10af8

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused implementation with meaningful snapshot and race coverage, bounded performance claims, and no identified blocking defect.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The maintainer-authored change is exempt from ordinary contributor proof. Supplied evidence and inspected regressions exercise worker replies, real SQLite snapshots, and session-list preparation; no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored change is exempt from ordinary contributor proof. Supplied evidence and inspected regressions exercise worker replies, real SQLite snapshots, and session-list preparation; no stored-data contract changes.
Evidence reviewed 8 items Current main still needs the cutover: Fetched main retains refreshBatch calling synchronous refresh, which reads each dirty row before materializing it; the proposed worker preparation is absent.
Latest release also uses synchronous refresh: The v2026.9.5 source calls readSessionRowEntry and materialize directly inside its refresh loop. The release does not supply this worker cutover.
Snapshot and failure semantics: The new reader bounds requests to 64 keys and reads entry, membership, board, and summary-watermark facts within one deferred transaction under canonical admission. Missing databases return empty results; unavailable metadata throws.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +360, Tests +364, Docs +9. Total +733 across 26 files.

View PR surface stats
Area Files Added Removed Net
Source 11 428 68 +360
Tests 14 433 69 +364
Docs 1 13 4 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 26 874 141 +733

Review metrics

Metric Value Why it matters
Production versus test growth Production net +360 lines; tests and test support net +364 lines Production growth implements the bounded worker handoff and lifecycle fencing, with corresponding snapshot and race coverage.

Technical review

Best 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.

Labels

Label justifications:

  • P2: This is a bounded Gateway responsiveness improvement without evidence of an urgent user-facing outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer-authored change is exempt from ordinary contributor proof. Supplied evidence and inspected regressions exercise worker replies, real SQLite snapshots, and session-list preparation; no stored-data contract changes.

Evidence

What I checked:

  • Current main still needs the cutover: Fetched main retains refreshBatch calling synchronous refresh, which reads each dirty row before materializing it; the proposed worker preparation is absent. (src/gateway/session-row-projection.ts:461, 2d84bb11af03)
  • Latest release also uses synchronous refresh: The v2026.9.5 source calls readSessionRowEntry and materialize directly inside its refresh loop. The release does not supply this worker cutover. (src/gateway/session-row-projection.ts, ec9c1a13db89)
  • Snapshot and failure semantics: The new reader bounds requests to 64 keys and reads entry, membership, board, and summary-watermark facts within one deferred transaction under canonical admission. Missing databases return empty results; unavailable metadata throws. (src/config/sessions/session-entry-read.worker.ts:106, ab5bdeb39ab7)
  • Delayed-result fencing: Database owners and canonical continuations remain retained through consumption. Replies require matching projection revision, registry snapshot, dirty membership, and row generation; newer direct reads are preserved. (src/gateway/session-row-projection-read.ts:126, ab5bdeb39ab7)
  • Current authorization remains at disclosure: Session listing rechecks readiness after awaits and prepares current viewer policy in the synchronous response frame. Membership writers publish committed invalidations, and existing async-read tests cover membership removal, visibility, identity, and config changes before response. (src/gateway/server-methods/sessions-read-async.test.ts:43, ab5bdeb39ab7)
  • Validation evidence and inspection limits: The captured PR body reports foreground reads falling from 3 to 0, snapshot consistency under a peer commit, delayed-worker replacement protection, and passing owner/event/chat regressions. GitHub confirms the cited large-fixture CI job succeeded. The later Testbox lease run is cancelled as disclosed in the body; its redirected log host was blocked, so the wrapper receipt was not independently inspected. No tests were executed during this read-only review. (src/gateway/session-row-projection.worker-read.test.ts:13, ab5bdeb39ab7)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • jalehman: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-22T03:34:05.704Z sha fbacc31 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-22T04:55:08.241Z sha 4ed2517 :: needs maintainer review before merge. :: none

@steipete
steipete enabled auto-merge (squash) September 22, 2026 07:03
@steipete
steipete merged commit 42263f8 into main Sep 22, 2026
190 checks passed
@steipete
steipete deleted the codex/session-row-facts-worker branch September 22, 2026 07:09
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash auto-merge.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 23, 2026
…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
steipete added a commit that referenced this pull request Oct 4, 2026
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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 5, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant