Skip to content

improve(codex): reduce database reads when listing sessions - #151979

Merged
steipete merged 1 commit into
mainfrom
codex/sqlite-codex-adoption-refresh-0918
Sep 18, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/sqlite-codex-adoption-refresh-0918

Conversation

@steipete

@steipete steipete commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Listing Codex sessions repeats the same SQLite freshness, schema, and binding-authority reads for each adopted session.

User Impact

Catalog listing performs fewer database reads while preserving current binding checks and returned session results. No migration or operator action is required.

Why This Change Was Made

Read eligible adoption bindings together through the existing bounded plugin-state store, and carry that capability through the registered lazy adapter. Decode rows in traversal order, retain scalar fallbacks, and keep registration free of state access. The binding scope helper and read tests move into focused sibling modules to keep their owners within the existing file-growth limits.

A terminal bulk database error can surface before an earlier per-row domain error; successful acquisition still preserves traversal-order validation. The change adds no schema, cache, transaction, or retention policy.

Evidence

  • The registered Gateway catalog fixture with 3,000 native sessions, 3,000 local sessions, and 3 adoptions measured 18 → 6 SQLite reads per request, including 3 → 1 binding-authority reads, across all 100 lists. Worker facade operations remain zero.
  • Final functional proof passed 228 tests across 11 files, including registration laziness, binding freshness and generation fences, adoption/recovery/listing, run preparation, native-subagent receipts, and the composed catalog budget with its existing CPU bound.
  • Complete responses match the warmed response for each query variant within each run. These counters cover main-process SQL and worker facade operations; separate remote runs do not establish a latency improvement or cross-run whole-store equality.
  • Full changed checks passed, including core/extension/test type checks, lint, formatting, dead-export analysis, and repository guards. Independent P0–P2 review completed across all three evidence passes with no actionable findings. Hosted CI passed on the published commit 73a7705d8841a3c6ed26e06988119fbfd8085d40.

@clawsweeper

clawsweeper Bot commented Sep 18, 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 self-assigned this Sep 18, 2026
@steipete
steipete marked this pull request as ready for review September 18, 2026 17:09
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime extensions: codex size: L maintainer Maintainer-authored PR labels Sep 18, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 18, 2026
@clawsweeper

clawsweeper Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 18, 2026, 1:19 PM ET / 17:19 UTC.

ClawSweeper review

What this changes

The Codex plugin batches session-binding reads during catalog listing, preserves sequential fallbacks, and adds freshness, ordering, and query-budget coverage.

Merge readiness

✅ Ready for maintainer review

This remains a useful optimization: current main still reads adoption bindings individually. No actionable introduced correctness or security defect was found, and the maintainer-protected PR should remain open.

Priority: P2
Reviewed head: 73a7705d8841a3c6ed26e06988119fbfd8085d40

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with meaningful regression coverage and no identified blocking defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied Repository State identifies this as maintainer-authored, so the external-contributor proof gate does not apply. The inspected Gateway fixture exercises registered catalog listing and real SQLite with a synthetic Codex peer; its reported query reduction is scoped performance evidence, not live native-session proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied Repository State identifies this as maintainer-authored, so the external-contributor proof gate does not apply. The inspected Gateway fixture exercises registered catalog listing and real SQLite with a synthetic Codex peer; its reported query reduction is scoped performance evidence, not live native-session proof.
Evidence reviewed 9 items Optimization remains absent from current main: The fetched main implementation still calls bindingStore.read once for each eligible adoption. The introduced change was reviewed against the pinned merge base, not endpoint drift.
Shared validation and bounded acquisition: Bulk reads reuse the scalar decoder and stored-generation check. Unsupported hosts and cohorts above 10,000 use scalar reads; acquisition failures are not retried. The catalog consumes the generator synchronously and closes it after collection.
Existing public storage contract: lookupMany is already an optional positional API with bounded input and per-key results. This PR consumes that API through a private plugin adapter; it changes neither the public SDK nor stored schemas.
Findings None None.
Security None None.

How this fits together

OpenClaw’s Codex session catalog combines native thread listings with local session metadata. Binding checks identify which native threads already have an adopted OpenClaw chat.

flowchart TD
  A[Session catalog request] --> B[Eligible local sessions]
  B --> C[Bulk read or scalar fallback]
  D[Plugin state SQLite] --> C
  C --> E[Validate binding and session generation]
  E --> F[Adopted session map]
  G[Native thread listing] --> H[Catalog response]
  F --> H
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +113, Tests +266. Total +379 across 13 files.

View PR surface stats
Area Files Added Removed Net
Source 7 213 100 +113
Tests 6 391 125 +266
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 13 604 225 +379

Review metrics

Metric Value Why it matters
Reported database work 18 → 6 SQLite reads per list The registered Gateway fixture reports a two-thirds reduction across 100 lists without weakening its existing CPU bound.
Production versus test growth Production +113 net lines; tests +266 net lines Production growth supports bounded acquisition and ordered fallback behavior; test growth covers freshness and the composed query budget.

Technical review

Best possible solution:

Keep batching within the existing plugin-state owner while preserving fresh per-list generation checks, ordered decoding, and scalar compatibility.

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

Not applicable to a functional bug: this is a performance optimization. Current source confirms repeated scalar acquisition, and the composed benchmark supplies a concrete query-count comparison.

Is this the best way to solve the issue?

Yes. Reusing the existing bounded storage API and canonical decoder avoids a new cache or competing state owner while retaining existing compatibility behavior.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded session-catalog efficiency improvement with no established urgent user-facing regression.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied Repository State identifies this as maintainer-authored, so the external-contributor proof gate does not apply. The inspected Gateway fixture exercises registered catalog listing and real SQLite with a synthetic Codex peer; its reported query reduction is scoped performance evidence, not live native-session proof.

Label justifications:

  • P2: This is a bounded session-catalog efficiency improvement with no established urgent user-facing regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied Repository State identifies this as maintainer-authored, so the external-contributor proof gate does not apply. The inspected Gateway fixture exercises registered catalog listing and real SQLite with a synthetic Codex peer; its reported query reduction is scoped performance evidence, not live native-session proof.

Evidence

What I checked:

  • Optimization remains absent from current main: The fetched main implementation still calls bindingStore.read once for each eligible adoption. The introduced change was reviewed against the pinned merge base, not endpoint drift. (extensions/codex/src/session-catalog-adoption.ts:128, 31044b634cdd)
  • Shared validation and bounded acquisition: Bulk reads reuse the scalar decoder and stored-generation check. Unsupported hosts and cohorts above 10,000 use scalar reads; acquisition failures are not retried. The catalog consumes the generator synchronously and closes it after collection. (extensions/codex/src/app-server/session-binding-record.ts:425, 73a7705d8841)
  • Existing public storage contract: lookupMany is already an optional positional API with bounded input and per-key results. This PR consumes that API through a private plugin adapter; it changes neither the public SDK nor stored schemas. (src/plugin-state/plugin-state-store.types.ts:86, 73a7705d8841)
  • Behavioral regression coverage: Added cases cover generation changes, deleted bindings, duplicate-adoption error ordering, failed bulk acquisition, unsupported adapters, and oversized cohorts. Existing generation-fence tests were moved rather than discarded. (extensions/codex/src/session-catalog-adoption.test.ts:45, 73a7705d8841)
  • Performance evidence and its scope: The captured PR body reports 18 to 6 SQLite reads and 3 to 1 binding-authority reads per request across 100 lists. The inspected fixture enters sessions.catalog.list through Gateway admission and the registered plugin, using real SQLite and a synthetic Codex WebSocket peer. Response comparisons cover repeated query variants within each run, not cross-run equivalence or demonstrated latency improvement. Tests were not executed during this read-only review. (src/gateway/server-methods/session-catalog.performance.test.ts:233, 73a7705d8841)
  • Dependency-contract inspection signal: The performance fixture initializes a synthetic Codex peer and implements thread/list responses. That protocol-backed evidence justified inspecting the sibling Codex contract; the production optimization itself changes OpenClaw-owned binding reads. (src/gateway/server-methods/session-catalog.performance.test-support.ts:113, 73a7705d8841)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit cc4e89a into main Sep 18, 2026
184 checks passed
@steipete
steipete deleted the codex/sqlite-codex-adoption-refresh-0918 branch September 18, 2026 17:36
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 18, 2026
* origin/main:
  test(gateway): isolate session resolution channel fixtures (#151945)
  fix(clickclack): drain discussion opens before shutdown (#151978)
  fix(test): restore trusted packaging harness startup (#151967)
  improve(codex): batch session adoption binding reads (#151979)
  improve(cron): reduce allocations for busy stream sources (#151956)
  fix(file-transfer): avoid repeated directory record encoding (#151987)
  fix: avoid session-list rebuilds when authentication availability changes (#151920)
  fix(updates): explain externally managed update refusals (#151942)
  improve(heartbeat): avoid unused config work in membership checks (#151867)
  fix(android): keep status text readable and label accessibility actions (#151342)
  improve(ui): show OS and size in the environment selector (#151947)
  fix(android): keep tool errors visible in collapsed chat activity (#151332)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: codex gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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