Repository navigation
Conversation
…try patch Every session-entry patch hydrated the same session row four times (preparation, in-transaction revalidation, writeSessionEntry canonical re-read, and post-write identity snapshot) and deep-compared two decoded copies via JSON.stringify, so ~11 patches per streamed turn burned roughly a third of a saturated gateway's main thread. Decode once at preparation and revalidate cheaply at the commit edge by comparing the raw persisted row fingerprint (session_key, current_session_id, entry_json, updated_at), preserving the SqliteSessionMutationConflictError contract. The write reuses the commit-validated previous entry instead of re-reading it, and identity publication reuses the row the transaction just persisted. Fixes openclaw#136338
Contributor
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Contributor
Author
|
Closing as a duplicate of #136361, the issue reporter's own fix PR (the issue body announced "Fix PR follows"). Same defect owner and same goal: decode the session row once at preparation and revalidate cheaply at the commit edge. Deferring to the earlier, author-owned PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #136338
What Problem This Solves
Resolves a problem where gateways running the SQLite session store lose roughly a third of saturated throughput compared to 2026.7.1-2: every session-entry patch decodes (JSON.parse + participants projection) the same session row four times and deep-compares two decoded copies via
JSON.stringify, all synchronously on the gateway event loop. A normal streamed reply turn issues about eleven such patches, so with a production-shaped ~17 KBentry_jsonthe session store consumed ~29% of a saturated gateway main thread.Why This Change Was Made
The patch path now decodes the session row exactly once at preparation and revalidates cheaply at the commit edge: instead of re-hydrating the row and
JSON.stringify-comparing decoded entries, the transaction compares a raw persisted-row fingerprint (session_key,current_session_id,entry_json,updated_at) and keeps the sameSqliteSessionMutationConflictErrorrejection contract when another writer changed the source row.writeSessionEntryreuses the commit-validated previous entry via an explicit opt-in (trustedCanonicalPreviousEntry) instead of re-reading the row, and post-write identity publication reuses the exact row the transaction just persisted instead of a fourth hydrated read. No schema or session-semantics changes; other write paths (lifecycle, recovery, transcript writes) are untouched.User Impact
Session-entry patches stop paying four full row decodes plus two decoded-entry stringifications per patch, restoring gateway main-thread capacity for multi-agent deployments. Behavior is unchanged: commit-edge conflict detection, creation-stamp preservation, and identity mutation events work exactly as before.
Evidence
Regression test first (RED) — the prepared row was decoded 3 times during one successful patch (preparation, in-transaction revalidation,
writeSessionEntrycanonical re-read; the 4th decode reads the post-write row):After the fix, the same test asserts exactly one decode of the prepared row, and the issue's conformance contract ("rejects a prepared SQLite entry patch when its source row changes") still passes:
Stability:
session-accessor.conformance.test.tsre-run 3 consecutive times after the final refactor, 47/47 each run.validate.sh(oxfmt + oxlint + same-directory tests +pnpm tsgo:core) passes on all changed files. CI lanes (test-projects --changed, fullcheck:test-types) are pending on Actions.Real environment tested: Node 26.7.0 on the repository worktree (Linux), vitest unit/conformance suites against a real
node:sqlitedatabase — not the 16-agent production gateway profile from the issue.Exact steps or commands run after this patch:
Evidence after fix: 175/175 tests pass across both suites; the decode-once regression test asserts
JSON.parseof the persistedentry_jsonhappens exactly once per successful patch; 3 consecutive conformance re-runs (47/47) confirm the commit-edge conflict contract is stable.Observed result after fix: one decode at preparation, cheap raw-column fingerprint comparison at the commit edge, no row re-read inside
writeSessionEntry, no post-write identity re-read — while a concurrentreplaceSessionEntrySyncbetween preparation and commit still rejects withSqliteSessionMutationConflictError.What was not tested: the issue's full 16-concurrent-agent gateway throughput/profile scenario (requires containerized gateway images and a mock provider); only source-level decode counts and behavioral conformance were measured.