Repository navigation
perf(sessions): remove redundant entry lifecycle queries - #169043
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 changes before merge. What this changesThis PR removes redundant SQLite queries from session sharing, suggestion settlement, reactions, conversation linking, and deletion. Example: Remove Alice’s membership with addedBy=owner and addedAt=3.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 2 items remain Keep this maintainer-authored PR open: useful optimizations remain beyond current main, with one low-impact comparison defect and a confirmed merge conflict to resolve. Priority: P3 Before merge
Findings
Tests
Agent review detailsHow this fits togetherGateway session operations enter existing storage owners, which validate session facts, execute SQLite transactions, and return state with committed invalidation receipts. flowchart TD
A[Gateway session operations] --> B[Admission and authority checks]
B --> C[Session storage owners]
C --> D[SQLite transaction]
D --> E[Returned rows and committed receipts]
E --> F[Session projections and responses]
Technical reviewBest possible solution: Integrate the remaining optimizations with main’s existing implementations while preserving exact grant comparisons and the current storage owners. Do we have a high-confidence way to reproduce the issue? The base source establishes redundant queries, and the new expected-grant SQL predicate has a concrete Unicode normalization mismatch; neither was executed during this read-only review. Is this the best way to solve the issue? Existing transaction owners are the appropriate place for these reductions, provided the conditional membership mutation preserves the former decoded-string comparison. Full review comments:
Overall correctness: patch is correct AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ec5fe47d136b. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource -40, Tests +67. Total +27 across 10 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReviewed October 11, 2026, 6:25 AM ET / 10:25 UTC (Revision 3). |
# Conflicts: # src/config/sessions/session-reaction-store.kernel.ts # src/config/sessions/session-sharing-store.native.ts # src/config/sessions/session-suggestion-store.test.ts
|
Merged via squash auto-merge.
|
…9043) * perf(sessions): remove redundant entry lifecycle queries * fix(sessions): remove unused reclamation type import
First-parent upstream 069a5b8..75df19c (17 commits, including openclaw#169043 entry lifecycle queries, openclaw#169034, openclaw#169058 memory index facts, openclaw#168950, openclaw#169019 telegram queued history replies, openclaw#168790/openclaw#168756/ openclaw#168759/openclaw#168739 Solid UI ports, openclaw#168813 codex metadata/startup lifecycles, openclaw#168981, openclaw#168992 agent preparation SQLite work). Only conflict: worker-access inventory, regenerated (631 files, 2436 calls). Auto-merged files carrying our overlay, reviewed: snapshot.ts (upstream's block-reply reconcile reads through index-1; our per-part continuation-marker strip in extractAssistantStreamSnapshot unchanged), codex side-question.ts (upstream's request-scoped client lease; our disableContinuationTools and the extracted dynamic-tool-call helper unaffected), subagent-registry-restore.ts, session-sharing-store.native.ts. Refs #1475 Co-Authored-By: Claude Opus 5.5 <[email protected]>
What Problem This Solves
Session lifecycle operations issue redundant reads and deletes after the owning transaction already has the needed facts.
User Impact
No intended behavior change. Sharing membership, suggestion settlement, reaction summaries, explicit conversation routes, and session deletion use fewer SQLite statements. This does not claim to complete the remaining synchronous session-storage migration.
Why This Change Was Made
Use conditional
DELETE/UPDATE ... RETURNINGfor membership removal and suggestion settlement. Reuse the reaction rows already read by the transaction, preserving SQLite's UTF-8 byte ordering when timestamps tie. Skip the old association read when an explicit route replaces it, and remove Board cleanup already owned by node-artifact deletion and foreign-key cascades. No schema, SDK, dependency, migration, or service-lifecycle change.Removed reads/checks and accepted edge cases:
Remaining native calls require the existing synchronous SDK/callback contract or the process-held incognito owner. The actor's entry replica is not sharing authorization. Callback full-row patches retain their conflict check because another accepted write during an awaited callback can otherwise lose user edits. These calls were left in place under the data-safety/owner-redesign escape hatch, not relabeled as worker-only.
Evidence
Measured base:
e65bd3be4134f1453bb4ab26e68704c678086b58; measured candidate:f189d7d9855de13719e7d1f91bf0702077cf1a81. Final headf737f5cb0cf4ce3c2ef1317c84362c520ef59ee8merges4db95aa552f7with conflict-only integration. Main independently acquired the same suggestion finalization and membership deletion simplifications; those portions are no longer part of the final diff. The measurement remains the original patch proof, not a claim of incremental savings already present on current main. No repeated SQL campaign was run for this conflict-only integration under the landing proof-reuse rule.Three alternating pairs on one Hetzner host, unchanged shared harness. Warmed per-turn median [min–max]:
This workload is effectively neutral: its warmed path does not exercise the changed sharing/suggestion/reaction mutations. The initial first-turn median rose 1307→1319 statements, so the permitted extra alternating pair checked whole-workload redistribution: first turn 1325→1300 statements (200→203 requests); whole workload 10932→10893 statements (1753→1752 requests). Across four pairs, first-turn medians were 1312.5→1309.5 and warmed medians 406.1→406.3 (+0.05%). All workload and counter validation passed; warmed duration ratio 1.01. The extra pair is an ambiguity check, not a claim of 39 statements saved by this patch. The original whole-workload median was 10910→10968 statements and 1751→1749 requests; after four pairs it was 10917.5→10941.5 and 1751→1750. The required extra-pair comparison reduced both totals.
Positive warmed family deltas are in unchanged callers:
session.actor.completeTurn(+0.30,session-actor-durable.ts:62),session-exact-entries(+0.25,session-transcript-worker-runtime.ts:203),acpSessions.metadata(+0.20) andsessionRows.sharedFacts(+0.15, bothopenclaw-state-read-worker.ts:411).session-row-factsfell 0.50. Family medians are independently calculated and do not add to the whole-turn median.Three alternating supplemental owner probes isolate the changed operations:
Requests are unchanged in each owner flow. The lifecycle difference removes exactly the Board table inventory and two duplicate deletes; the one-statement baseline range is unrelated timing work.
Measured T1 inventory: changed owners 35→29 (conversation 8→8, reclamation 7→4, reaction 6→5, sharing 5→4, suggestion 9→8); all
src/config/sessions383→377; repository 706→700. After main independently absorbed sharing/suggestion changes, final-base T1 is 25→21 across the four remaining production owners, sessions 381→377, repository 692→688. Remaining native contracts are described above.Focused regression coverage checks stale membership/dispatch claims, persisted reaction ordering, explicit route publication, and deletion/rollback with Board rows and unaffected sibling sessions.
Remote focused suites passed on f189 (7 files, 123 tests; 190.30s). On final conflict head f737, all three affected suites passed (47 tests; 67.557s), changed-file type-aware oxlint passed (11.166s), export-name collisions passed (44.771s), and T1/dialect ratchets passed. Madge and production core typecheck passed on runtime-identical f189.
check:changedoriginally stopped on an inherited max-lines suppression insrc/web-search/runtime.test.ts; its remaining relevant plan was executed directly. The unrelated all-consumer test-graph sweep was stopped after completed graphs; changed tests were run directly. Final Knip reports one unused export,isCodeModeExecToolKindin untouchedsrc/agents/code-mode-control-tools.ts, with byte-identical output on main4db and f737. Initial check setup lackedcorepackandrg; those prerequisites were installed. The unused reclamation type import found by the first typecheck was removed and reviewed. No SDK/API surface or published-driver update cell applies.CI run 38129552324 fails the unrelated physical-parent selection case in
src/gateway/session-utils-store-lookup.test.ts; the exact case also fails on the final base (31 passing / 1 failing). This is an inherited CI exception under the authorized relaxed landing policy.Independent Codex autoreview: two rounds (runtime patch, then import-only cleanup), no actionable findings. Final LOC: production +43/-68 (net -25); tests +73/-9; total +116/-77 across nine files, after main independently absorbed two simplifications. Release-note context: reduce redundant session lifecycle SQLite queries while preserving existing sharing, suggestion, reaction, routing, and cleanup behavior.