Repository navigation
fix: session deletion delays unrelated agent writes - #189287
Merged
steipete merged 2 commits intoOct 31, 2026
Merged
Conversation
Contributor
|
🦞👀 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. |
steipete
marked this pull request as ready for review
October 31, 2026 10:22
Contributor
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
steipete
enabled auto-merge (squash)
October 31, 2026 11:18
steipete
deleted the
steipete/perf-micro-session-lifecycle-delete-sql-20260919
branch
October 31, 2026 11:21
Contributor
Author
|
Merged via squash auto-merge.
|
This was referenced Oct 31, 2026
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Nov 1, 2026
* fix: session deletion delays unrelated agent writes * fix: preserve historical schemas during deletion index admission
RomneyDa
added a commit
that referenced
this pull request
Nov 17, 2026
Backport ce90837. Co-authored-by: RomneyDa <[email protected]>
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.
What Problem This Solves
Session deletion unnecessarily scans unrelated completion history and delivery rows while holding an agent database's only SQLite writer, delaying other session writes.
User Impact
Deletion releases the writer sooner. Slow
session.lifecycle.deletewarnings now distinguish statement execution from remaining callback time, without logging SQL text or bindings. This removes proven scan work; the reported multi-second production tail is not yet attributed or claimed fixed.Why This Change Was Made
Add nonunique indexes for the completion foreign-key cascade and delivery cleanup predicates. Existing admission and first-use schema owners install them once using published schema facts. This is a lead-approved same-version SQLite addition: schema 39, row contracts, atomic deletion, and retention remain unchanged. Older-schema readers and writers accept the extra indexes. PostgreSQL v39's exact sealed catalog stays byte-identical; its adoption waits for the next natural migration. All 23 historical SQLite catalogs also remain identical to base. Version-crossing migration witnesses permit only the two validated canonical additions; same-version witnesses and local indexes remain strict.
Reuse native statement observation for this operation only. The existing 1,000 ms slow-hold threshold controls output; at most 32 statement groups plus overflow carry counts, total/max elapsed time, and normalized-SQL fingerprints.
callbackOtherMsalso includes preparation, final guards, rollback, GC and scheduling; neither field is CPU time.Related: #184370. Its projection drain requires a nonempty transcript and does not run for the empty-transcript path labeled
session.lifecycle.delete; it also leaves canonical deletion unbounded. No code is adopted. A 480 MiB board-artifact probe held the writer for 60–115 ms, so this change preserves atomic deletion instead of introducing a speculative authoritative-data drain.Evidence
Synthetic fixture: 1,000,000 transcript rows, 10,001 sessions, 34.94 GiB, 12,497 synthetic completion outcomes and 14 deliveries. Five counterbalanced pairs, 20 deletions per arm per pair, separate allocation sampling, with A/A controls. The real native deletion owner runs inside the agent writer transaction; rollback restores identical input. Both index arms use the same diagnostic instrumentation. Samples include common assertions and rollback, and exclude worker transport, pre-BEGIN admission, and commit durability costs; the real worker flow is tested separately.
A/A writer medians were 11.437/13.793 ms and CPU 12.243/13.869 ms; this heavily loaded local host cannot establish production tail latency. The A/A maximum was already 427.591 ms, matching the indexed outlier; maximum latency is therefore explicitly unqualified, not claimed improved. Every paired median and CPU result improved. Exact row counts and retained-content digests passed. Completion index construction took 4.6–13.3 ms; delivery index construction took 0.3–0.9 ms on the seeded disk database. These are isolated DDL timings on an admitted connection; full cold/dirty admission and integrity checks are excluded, so they do not establish a sub-second deployment or database-open bound.
Diagnostic cost, separately measured over five pairs of 100,000 tiny 16-statement transactions: +1.75 µs CPU and +1.38 KiB sampled JS allocation per transaction. This explicitly requested attribution has a measurable collection cost; normalization/hashing happens only for slow warnings.
Reproduce with the committed
scripts/perf/session-lifecycle-delete-sql-measure.tsandscripts/perf/session-delete-diagnostics-measure.tscommands documented in their headers. The fixture uses incremental auto-vacuum on local APFS with an empty freelist, not a fragmented btrfs store; no production data was copied.Initial CI run 41192504394 found five attributable migration-test failures across four suites: historical-schema drift and rejected migration witnesses. These were reproduced locally and repaired at those owners, without changing frozen expectations; all 47 tests in the four affected suites now pass. Added assertions retain rejection of lost local indexes and incorrect definitions under canonical names.
Focused proof: 39 index/compatibility tests, 20 transaction/observation tests, and six real worker deletion tests pass (112 distinct tests including the 47 migration tests). The two affected generation checks were rerun after the repair, along with scoped lint, state type checking, formatting, and the test-line ratchet. Both new diagnostic regressions fail on the base. All three actual DELETE plans scan on the base and use indexes after the fix. The lazy-first-use test caught an extraction-boundary omission; its corrected path passes. The older-schema open/write test checks retained rows, foreign keys, and unchanged version markers.
Scoped lint, formatting, unused-file scans (zero entries), and the 243-line regression allocation pass.
pnpm check:changedidentified a test tuple typing error, now corrected with the affected state type check passing. Its export scan also reports four inherited exports:resolveFollowupReplyAnchor,captureRepositoryClientActor, the GatewayRepositoryOperationre-export, andRepositoryAuthorization. Their owners/consumers are unchanged from base; #189237 independently repairs the latter three and documents the first as inherited. No aggregate green claim is made for that baseline scan.Fresh independent Codex autoreview covered the complete staged candidate against
33facea809027bccac675f53701eea6344230da9through P2 in two passes. Its sole finding was rejected after source inspection: the older-schema test importssqlite-schema-contract.test-support, which explicitly builds a catalog from frozen/synthetic DDL before invoking the runtime validator. The finding assumed the runtime string-only path. No accepted or actionable findings remain; no production code changed after review.Handwritten production delta is +115 lines (+124 including generated TypeScript); the measurement scripts total 577 lines. Necessary production growth covers two derived indexes, existing observation/admission owners, and historical schema/witness compatibility; no config, cache, queue or deletion protocol is added. Regression growth covers scan plans, older-schema writes, lazy admission, PostgreSQL catalog compatibility, and bounded private diagnostics.