Repository navigation
perf(sessions): remove redundant owner-state database rechecks - #169339
Conversation
Reuse cohort entry snapshots, actor transcript identities, and published subagent protection. Fold workspace lease exclusion into the claim write.
|
🦞👀 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. What this changesThis PR reuses Gateway-owned session facts and folds workspace reservation checks into claim writes to reduce repeated SQLite reads. Example: An ordinary warmed chat turn claims its session workspace and appends an assistant response.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it provides a focused, owner-backed performance simplification, with no actionable correctness or security findings from the pinned diff. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherGateway session operations use registry publications, session actors, and worker snapshots to prepare maintenance and transcript mutations, then commit through existing SQLite owners. flowchart TD
A[Gateway session operation] --> B[Registry publications]
A --> C[Session actor and cohort]
B --> D[Maintenance preparation]
C --> E[Transcript validation]
A --> F[Conditional workspace claim]
D --> G[SQLite worker commit]
E --> G
F --> G
Technical reviewBest possible solution: Retain the existing owner-based implementation and complete the normal checks for the reviewed head before merging. Do we have a high-confidence way to reproduce the issue? This is a performance refactor rather than a defect report; source inspection confirms the repeated reads, and the author supplies a pinned before/after benchmark. Is this the best way to solve the issue? Reusing facts at their existing owners is appropriate here: the cohort keeps its snapshot, actor facts remain transaction-scoped, and workspace exclusion moves into the conditional write. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 6fbc2daf53d0. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource -149, Tests -400, Docs +3, Other +4. Total -542 across 36 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 Reviewed October 11, 2026, 4:29 PM ET / 20:29 UTC. |
|
Merged via squash.
|
… inventory #169339 deleted src/auto-reply/reply/get-reply.maintenance-conflict.test.ts but left it in the hand-maintained database-worker inventory, so the ci-node-test-plan host-owned consumer guard failed on main.
…law#169339) * perf(storage): consume owned facts instead of repeating SQL checks Reuse cohort entry snapshots, actor transcript identities, and published subagent protection. Fold workspace lease exclusion into the claim write. * test(storage): cover owner updates and retire bypass-read expectations * test(storage): initialize registry mutation owner in fixture * fix(storage): remove retired replacement checks and restore test admission * test(storage): remove unused replacement fixture import
… inventory openclaw#169339 deleted src/auto-reply/reply/get-reply.maintenance-conflict.test.ts but left it in the hand-maintained database-worker inventory, so the ci-node-test-plan host-owned consumer guard failed on main.
First-parent upstream e63e209..0b0c2f2 (93 commits, including openclaw#169144 subagent work across gateway restarts, openclaw#169251 worker write transaction overhead, openclaw#169306 question-answer custody, openclaw#169305 fallback ordering, openclaw#169339 owner-state rechecks, openclaw#169235/openclaw#168887 Solid UI ports). Stops before openclaw#169315 (fp#248, agent schema), which is step 59 on its own. Conflicts: - embedded-agent-runner/run/payloads.ts: upstream gates the assistant-texts branch on !assistantForPayload (an empty canonical terminal stays authoritative); kept our per-hop raw-answer split for earlier continuation signals ahead of it. - session-reset-cleanup.test.ts: upstream's retainEmbeddedSessionPromptState disposable; kept our async clearSessionResetRuntimeState call. - plugin-sdk-surface-report.mts: upstream 3674/2135, ours +11/+4. - config-baseline counts/sha256 and worker-access inventory regenerated on the merged tree (core +17 fork config entries, as before). Auto-merged files that carry continuation overlay (19, incl. attempt-execution, agent-runner-fallback-candidate, session.ts, status-message, stream/update handlers) keep the overlay byte-for-byte. Refs #1475 Co-Authored-By: Claude Opus 5.5 <[email protected]>
What Problem This Solves
Ordinary session maintenance, workspace claims, and prepared assistant appends repeat SQLite checks for facts already held by their Gateway owner.
User Impact
No intended user-visible change. Reduces database work without changing schemas, stored data, permissions, or update behavior.
Why This Change Was Made
Registry maintenance now consumes the owner-published projection; its digest scans, victim rereads, and duplicate identity captures are removed. Workspace claims check active publication-lease expiry inside the existing conditional write. Prepared assistant appends reuse actor identity facts when there are no newer messages. Entry cohorts reuse the entry already selected in their snapshot. The retired lifecycle snapshot reread was already absent on the base.
Accepted edges and retained boundaries:
Evidence
Base:
af288ea70b81e0e8c3d933c8338dd5a12a3f6a85. Candidate:c3ee9698746f85e5e6f3b721bce30f8897690354.Base
af288ea70b81e0e8c3d933c8338dd5a12a3f6a85; candidatec3ee9698746f85e5e6f3b721bce30f8897690354. Three alternating pairs, same AWS lease.placementTurns.claim(src/gateway/worker-environments/placement-turn-claims-store.ts:334)session.actor.appendTranscriptEvent(src/config/sessions/session-actor-durable.ts:63)session.actor.read(src/config/sessions/session-actor-durable.ts:63)session.lifecycle.project(src/config/sessions/session-lifecycle-projection.ts:118)acpSessions.metadata(src/state/openclaw-state-read-worker.ts:411)session-exact-entries(src/config/sessions/session-transcript-worker-runtime.ts:154)readSessionTranscriptAnchorFactsInDatabasereadUnchangedLifecycleTargetSnapshotsubagentMaintenanceDurableBasisMatchesassertSessionWorkspaceUnreservedcanRebasePreparedAssistantInTransactionAll duration ratios are below 1.5. The connection increase is cold memory admission moving earlier: in the first pair,
database.domain.publish(schema.admit)shifts +133/−133 statements between connection/first-turn,database.prepareWrite+31/−31, and main-thread admission +9/−9. The combined boot+connect+first-turn median falls from 4046 to 4019 statements; no new preparation request is introduced.The warmed request median changes +0.34%, within the 0.5% noise floor. Across 30 turns the net is +7 requests, fully attributed below to unchanged memory sync, row-projection drains, and queued actor/entry reads. Regular actor reads stay at 40 per run; the extra actor reads come from the byte-identical queued replacement-worker read path. Changed claim, append, and lifecycle command counts are identical. Whole-workload requests fall by three. All warm requests completed, with no duplicate sends or missing context rows.
All nonzero warmed request-count variances (requests/turn):
T1: native inventory global 612 → 611; changed-file scope 12 → 11; registry-maintenance reader 1 → 0 (the registry module is 3 → 2). The ratchet comparison using the candidate inventory is 611 → 611, so classification did not increase the baseline. No new main-thread database path. The warmed workload performs zero main-thread statements on both revisions.
The shared kernels retain these existing synchronous contracts; moving them requires their owning API/transaction cutover, so this PR stops at those calls:
loadSubagentRunsForSessionsInDatabasecommitProjectedLifecycleMutationcommittranscriptEntryIsAncestor,readTranscriptVisibleTailEntryIdInTransaction,readActiveTranscriptAppendParentId,readTranscriptIdentityInTransactionclearLocalTurnClaimsInDatabasereadWorkspaceReservationAuthorityValidation: all changed test files and consumers mocking changed exports were exercised. The original remote 15-file run passed 91 cases and exposed eight cases with a removed test-only import; restoring the import made the two affected files pass 28/28 (73.89 s). The registry owner regression passed 4/4 locally (19.82 s). The regressions cover owner-published maintenance after writes, actor identity updates, cohort entry reuse, and active/expired workspace claims.
Remote
check:changed --base af288ea70b81e0e8c3d933c8338dd5a12a3f6a85passed production types, all 28 test type graphs, formatting, source contracts/export collisions, Knip and four core lint stripes. The remaining whole-core lint stripe was killed by the 16 GiB runner without a diagnostic; the supported scoped recovery passed the same type-aware lint over all 32 changed TypeScript files (33.37 s). Changed-script lint, Madge, Knip, T1 and dialect ratchets pass. Dialect groups are unchanged (mechanical 1 → 1; design 11 → 11).Two independent Codex reviews completed with no actionable findings. Initial validation caught and fixed a registry fixture missing its owned row versions, a deleted import still needed by retained tests, and replacement-worker calls to a retired guard. No SDK, schema, migration, update, Doctor, plugin-loading, or service-lifecycle change; the SDK API diff and published-driver update cell do not apply.
LOC: production/tooling +104/−249; tests +204/−604; docs +48/−45. Changelog remains release-owned.