Repository navigation
perf(sessions): reuse prepared create-target identity on first chat - #165360
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 October 5, 2026, 4:26 AM ET / 08:26 UTC (Revision 7). ClawSweeper reviewWhat this changesSession creation reuses its selected store and canonical keys to read current metadata through the existing database worker, with mutation checks and focused lifecycle regressions. Merge readiness✅ Ready for maintainer review This remains useful work: current main still performs the synchronous target reread. The pinned patch has convincing scoped evidence and no actionable correctness, security, or compatibility finding. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway creates sessions for chat, agents, and plugins. Its creation owner selects storage, validates current metadata and caller authority, then prepares resources and commits the session. flowchart TD
A[Chat or plugin request] --> B[Select session store and keys]
B --> C[Hold creation lifecycle custody]
C --> D[Ordered database worker read]
D --> E[Validate metadata and live authority]
E --> F[Prepare resources and commit session]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +75, Tests +151, Docs +8. Total +234 across 8 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep durable target preparation with the existing ordered reader while creation retains lifecycle custody and current authorization. Do we have a high-confidence way to reproduce the issue? Not applicable as a correctness bug report; current-main source confirms the synchronous reread, and the captured production workload provides matched execution counts. Is this the best way to solve the issue? Yes. Reusing the existing reader and selected target preserves one storage owner without adding a cache, configuration option, or parallel API. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a9f4080f9749. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (6 earlier review cycles)
|
Resolve adjacent worker-access documentation additions while preserving the reviewed create-target implementation and main reader/test-routing changes.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
Merge main c2e6410 and keep the ordered reader plus its stronger revocation and cleanup tests from #165360. This removes duplicate guard hunks from the header cutover without changing the lifecycle reader or released SDK surface. The three affected reader/freshness suites pass 37 cases. Fresh P2 review is clean; the prior SDK report remains scoped to unchanged header declarations and compatibility metadata.
Reuse the ordered-reader native mutation fence and cleanup-close regression already landed in #165360. Preserve the incognito domain facades, retained expiry settlement, and synchronous compute target capture.
What Problem This Solves
First-chat session creation repeated target discovery and metadata reads on the Gateway thread after selecting the target. The measured create-target caller executed 31 successful MAIN SQLite statements on first use.
Why This Change Was Made
Read the selected store and canonical keys through the existing ordered session reader, preserving full metadata and exact-row validation. Creation keeps lifecycle custody and rechecks its live caller guard after preparation. The reader also checks the native connection's mutation witness, so synchronous SDK rewrites cannot silently invalidate a pending read.
Route the creation collision/display-name fixtures through the existing host-owned worker project. Their raw-edit regression now checks the exact contender row instead of triggering broad admission on its deliberately uncertified sibling. The shared reader regression proves that database retirement during cleanup rejects the result and joins closure.
User Impact
Schemas, stored bytes, retention, durability, configuration, update behavior, and public APIs are unchanged. Process-held incognito reads retain their existing owner. No new service, persistent cache, or
OPENCLAW_*name.Production: +92 / −17 / net +75, 109 changed lines, across
session-create-target.ts,session-create-service.ts, andsession-entry-read-ordered.ts.Evidence
Three unchanged synthetic SQL workloads per version, independently based on
3b60dc8ba2c34d9de93e7385e169d92801f5c3a2, using sqlmeasure4's native execution observer and source-map caller attribution. Node 24.21.0 / SQLite 3.53.4; all RPC, child, cron, compaction, and graceful-shutdown checks passed. Calibration remained 8 native calls / 2 prepares / 7 successful statements on both threads; zero unattributed MAIN statements.retainSessionEntryKeyAbsencefirst-opener callerThis is not a 31-statement net first-turn saving. Twenty-four cold-admission statements, including the 17 canonical comparisons, move to the next existing host opener:
session-accessor.sqlite-exact-read.ts:269→session-accessor.entry.ts:460→chat-send-session.ts:418. The targeted caller is off-thread; that remaining admission debt stays visible. Aggregate totals show no reliable overall reduction under loaded-host scheduling. Remote capacity was unavailable, so these are local execution-count measurements, not latency claims.Validation used
--maxWorkers=1:node scripts/check-changed.mjs: passed, 3,154.30s. Follow-up fixture/reader lint and type graphs passed after test-only changes. Database-worker ratchet: no T1 growth; madge: 0 cycles; runtime import check: 0 cycles;git diff --check: passed.The cold worker/compiler startup dominates these loaded-Mac wall times. CI timing will be available on the first pushed-head run; no CI result is claimed here.
Related ownership work: #165028, #165193, and #162433. The same small ordered-reader witness is shared with the independent trajectory-preparation PR #165410; whichever lands second should retain one copy when rebasing.
Landing validation
Integrated current main through merge commit
24f0b0e3414a05c35afedaee99aa830f39327946(no rebase). The only conflict was adjacent additions in the worker-access documentation; both were retained. The three production-file diffs are byte-identical to the coordinator-reviewed incoming patch. Fresh isolated Codex autoreview is clean through P2; the maintainer also inspected the reader, creation owner, and live-authority boundary.On this integrated candidate,
node scripts/run-vitest.mjs src/gateway/session-create-target.test.ts src/gateway/session-create-collision.test.ts src/gateway/session-create-display-name.test.ts src/gateway/session-create-preparation.test.ts src/gateway/session-create-atomic-initialization.test.ts src/config/sessions/session-entry-read.worker.test.ts src/agents/harness/native-session/binding-authority.test.ts src/plugins/runtime/runtime-agent.test.ts --maxWorkers=1passed 94 tests across 8 files, 2,252.50s command wall time. Formatting of the conflict resolution andgit diff --checkpassed. The prior changed-check and import/build-graph results above remain historical evidence for the unchanged implementation; current-head CI is green at https://github.com/openclaw/openclaw/actions/runs/37280865941, without reruns or an inherited-failure exception.The indirect-caller audit found no additional host-owner routing changes: creation callers already use the Gateway, Gateway-method, plugin, or agent-support fork projects. The existing native-binding caller received focused sibling coverage. The released surface check against
v2026.9.8found thatreadSessionCreateTargetis internal, its only production caller is already asynchronous, andapi.runtime.agent.session.createSessionEntryretains its released Promise-based signature. No compatibility shim or public type-test change is needed. The full SDK comparison against v2026.9.8 completed for this exact head (checked receipt; digest5bbbc8efdb2126cbc37b1eacc6069578bd033e28befc64a73227b78e7895eb55). It reports the broad release-to-main API delta; neither changed internal helper appears in that declaration diff. The original PR-to-base report above and source reachability audit establish the unchanged public signature for this lane.Published-driver update proof is not applicable: this changes a runtime session reread, not update, Doctor, service startup, migration, plugin loading, schema, durability, retention, or recovery contracts. The 24 cold-admission statements still relocate to the next host opener; this PR does not claim to remove that separate admission debt.
ClawSweeper completed the integrated-head review at 2026-10-05T08:04:36Z with no actionable findings and no remaining before-merge item: #165360 (comment).