Skip to content

perf(sessions): reduce database reads during session creation - #183156

Merged
steipete merged 1 commit into
mainfrom
dbasync/spawnsql
Oct 25, 2026
Merged

steipete merged 1 commit into
mainfrom
dbasync/spawnsql

Conversation

@steipete

@steipete steipete commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Creating a second session and its native child repeats a full creation read immediately after target discovery. The row-metadata reader also fetches participants separately despite already having an aggregate-capable entry query. The standard synthetic workload attributes six statements and one worker request per spawn to those two classes.

User Impact

Session creation and initial transcript reads perform less database work with the same stored result, permissions, and restart behavior. No user action is required.

Why This Change Was Made

Reuse the existing owner-published full entry facts for eligible unlabeled canonical creation, including known absence. Preserve separate existing/target entries, opaque alias resolution, labeled/cold fallback, physical source custody, replacement CAS, and final authority. Include participants in the existing aggregate when reading row transcript metadata. The jsonOrderedArray call and ordering are unchanged. No schema, new cache, generation, or cross-store transaction changes.

Acceptance rule (registered before candidate A/B)

Flow: real isolated Gateway, loopback transport and mock provider, frozen v3.1.5 standard synthetic workload including native child, compaction, shutdown and restart. All data is synthetic.

Three alternating same-platform baseline/candidate pairs on base b406c2b9c1aa310f933c66c3ff0867750af80c54 and this head. Count statements, worker requests and MAIN operations; report phase 04.second-session per-owner and execution/causal medians [min–max], plus cold and warm phases separately. Removed owner classes must strictly decrease; other touched-owner work must hold or improve. Runtime MAIN must not increase. Any adverse metric move of 20% stops for attribution. Profile all Gateway threads. No local latency claim on a loaded host; timing comparisons require the campaign timing lock, load <24, and at least five samples per arm with median/p95/spread.

Registered expected owner reduction: creation −3 SQL/−1 request; row-facts −3 SQL/0 requests; total −6 SQL/−1 request/0 MAIN per phase04.

Evidence

  • All four regression cases fail on unchanged base for the intended extra reads and pass with the change. Full touched suites: 36/36 pass. Covers absent/resident creation facts and post-write visibility; participant snapshot consistency and post-commit visibility with and without reader continuation.
  • Full two-file invocation: 119.51 seconds, mostly compiler work (81% transform); test execution 15%. No new test file, export, or test-only production seam.
  • Basic changed-file oxlint and formatting pass; git diff --check passes.
  • Local type-aware lint cannot pass declaration-custody preflight with the external virtual store. The exact-head CI run supplies the passing types and lint evidence; no local type-aware pass is claimed.
  • Both isolated code reviews found no actionable P0–P2 findings. Exact-head CI run 40154739914 passed, including all three PostgreSQL conformance shards, types, lint, source contracts, Madge and database ratchets. PostgreSQL semantic review is complete.
  • Canonical Knip export scans have identical baseline/candidate findings: production 42/42, full-tree 57/57, scripts 14/14; zero new findings or resolution errors.
  • One qualified same-platform baseline/candidate pair completed. The remaining four arms were not run: host load stayed above the count admission threshold through the extended wait. The coordinator closed the broad performance claim as unproven; no complete three-pair acceptance, timing improvement, or complete all-process profile coverage is claimed.

The production diff adds 26 net lines to consume existing facts while keeping the required cold/labeled path. Tests add 76 net lines for the two distinct removed read classes. This is a SQL/request reduction, not a net-negative-code claim. Registry recovery, Team leases and spawn admission are unchanged. Historical subagents.runs JSON scans did not reproduce in three attribution runs and are excluded; pending-input and payload-owner work belong to separate lanes.

Shared open-PR index overlap check: #183114 at c82c9413df6177cae1e4d2ed10f853ded83730f1 is clean against both base and candidate; #177242 retains the same 17 inherited conflict messages and unchanged conflict hunks; #146847 retains the same 25 inherited conflict messages and unchanged conflict hunks. This patch adds zero conflicts. Compared committed head d7492aebd58 against all three indexed heads with git merge-tree.

Post-merge measurement disposition

The retained pair confirms the intended owner reduction. Creation/exact-entry requests fell from 26 to 23 SQL and 10 to 9 worker requests; row-facts requests fell from 12 to 9 SQL with 3 requests in both arms. That is six fewer statements and one fewer request in these read classes.

Other work offsets the target reduction: the full second-session phase measured 498→496 SQL with 119 requests in both arms. Entry-patch work increased by three statements and one request; activity-summary work increased by one statement. The whole workload measured 2976→2975 SQL, 796→797 requests and 94→94 total MAIN operations; runtime MAIN remained zero. These are single-pair observations, not median/p95 estimates.

The ≥20% stop cells remain disclosed. Idle-settle requests measured 14→17 (+21.4%). Restart-first-turn measured 146→180 SQL (+23.3%) and 49→61 requests (+24.5%); its turn-owned portion was identical at 127 SQL/38 requests with the exact same SQL-shape multiset. Startup and maintenance work moved from connect/boot into that window. The entire restart measured 532→535 SQL with 191 requests in both arms. Additional plugin-state reads, passive checkpoints and idle request residuals remain unresolved; the broader performance claim is unproven.

Gateway-thread profiles were captured, but helper-process profiles are incomplete (five missing on baseline, one on candidate). No CPU or latency comparison is claimed. Two of six planned arms completed; the other four were explicitly closed without running after the sustained load wait. The landed owner-read improvement and its regression proof stand; this is not a claim that every whole-workload metric improved.

Use complete owner-published entry facts for unlabeled canonical creation
and include participants in the existing row-metadata aggregate. Keep cold,
labeled, alias-sensitive, source-custody, and replacement-conflict paths.

The synthetic second-session flow attributes six redundant SQL statements
and one worker request to these reads. Add regressions for known absence,
post-write visibility, and participant snapshot consistency.
@clawsweeper

clawsweeper Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review October 25, 2026 02:30
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-25T02:33:23.410007Z d7492ae Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 25, 2026
@clawsweeper

clawsweeper Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR reuses retained session-creation facts and includes participant identities in the existing row-metadata query.

Example: Create agent:main:target after discovery has retained its complete entry or confirmed absence.

  • Before: Creation dispatches another full creation-snapshot read.
  • After: Eligible unlabeled creation uses the retained facts while cold, labeled, and alias-sensitive requests retain the existing reader.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused implementation and boundary regressions are credible, but required performance proof is not yet supplied.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Creating sessions and reading their initial metadata repeats database work whose complete results are already available.
Reason: The maintainer-authored direction removes identified work through existing owners without adding configuration or changing intended session behavior.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it is a useful, maintainer-directed optimization, and source review found no concrete introduced correctness or security defect.

Priority: P2
Reviewed head: d7492aebd5844a542569bcdc697ae2d335f4d3ea

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Supply the registered baseline/head Gateway workload results covering second-session creation, native child, compaction, shutdown, and restart.
Agent review details

How this fits together

The session accessor prepares creation context from worker-owned database facts, invokes the creation callback, and commits through the existing replacement and publication owners.

flowchart TD
A[Session creation request] --> B[Session accessor]
B --> C[Retained actor facts]
B --> D[History worker fallback]
C --> E[Creation callback]
D --> E
E --> F[Replacement and commit guards]
F --> G[Database and published facts]
Loading

Technical review

Best possible solution:

Reuse complete facts through the existing creation owner and participant query while preserving the established fallback and commit checks.

Do we have a high-confidence way to reproduce the issue?

Current-main source exposes the unconditional creation-snapshot request and separate participant acquisition; the PR reports matching base-failing work-count regressions, but this read-only review ran no target code.

Is this the best way to solve the issue?

The patch follows the smallest complete approach: consume the existing receipt-maintained facts and aggregate owner rather than introduce another cache, worker, or state representation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against ec74daef033b.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit f19b09b adds src/config/sessions/session-accessor.sqlite-creation.ts:74 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f19b09b6b40f; files: src/config/sessions/session-accessor.sqlite-creation.ts)

PR surface

Source +26, Tests +76. Total +102 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 36 10 +26
Tests 2 79 3 +76
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 115 13 +102

Review metrics

Metric Value Why it matters
Production versus test growth Production +26 net lines; tests +76 net lines Production growth consumes an existing owner's facts while retaining necessary fallback behavior; tests cover two distinct redundant-read classes and their visibility boundaries.

Labels

Label changes:

  • add P2: Reduces redundant database work during session creation without evidence of an urgent user-facing outage.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Reduces redundant database work during session creation without evidence of an urgent user-facing outage.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 24, 2026, 10:47 PM ET / October 25, 2026, 02:47 UTC.

@steipete
steipete merged commit 8771a39 into main Oct 25, 2026
213 of 215 checks passed
@steipete
steipete deleted the dbasync/spawnsql branch October 25, 2026 03:01
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 25, 2026
…w#183156)

Reuse complete owner-published entry facts for unlabeled canonical creation and include participants in the existing row-metadata query. Keep cold, alias and labeled fallback, physical source custody, replacement CAS and final authority.

Four regression cases fail on the unchanged base; all 36 touched tests pass. No schema or transaction change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant