Skip to content

improve(gateway): reduce work when loading sessions from fixed stores - #148985

Merged
steipete merged 6 commits into
mainfrom
codex/perf-fixed-store-discovery-7006
Sep 15, 2026
Merged

steipete merged 6 commits into
mainfrom
codex/perf-fixed-store-discovery-7006

Conversation

@steipete

@steipete steipete commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

History and startup requests can traverse many unrelated sessions when agents share a configured fixed session store.

Why This Change Was Made

The Gateway previously discovered a store that its caller already selected, then discarded that duplicate target. The existing discovery owner now excludes that target after validating ownership. This applies only to uncached configured fixed-store lookups; request-scoped caches retain complete targets for deleted-session and worker-placement lookups.

User Impact

History and startup reads avoid redundant session-store discovery. Store selection, registry errors, collision warnings, missing-store behavior, and cached discovery remain unchanged. No configuration or storage migration is required.

Evidence

  • Original/candidate comparison on base 45e944b51584: nine cases and 25 lookup calls per arm. Complete results, warnings, errors, and stored rows match after validating and normalizing only synthetic temporary-directory identities. Error stacks have no differences.
  • With 1,024 foreign session keys preceding the selected agent, redundant inventory keys visited fall from 1,025 to zero, native read calls from eight to six, and rows returned to JavaScript from 1,032 to six. Default/template and unreadable-registry controls retain their original behavior and work counts. These measurements do not establish an end-to-end latency improvement.
  • All 110 tests across six full Gateway and session-store suites pass without failures or skips, including cursor responses, collision warnings, registry failures, cached discovery, deleted-main handling, and worker placement.
  • Formatting, type-aware lint, production types, and the two affected Gateway test type graphs pass. The canonical changed-check plan was inspected; this is targeted local proof, not a claim that every broad check ran. An initial memory-admission stop was preserved, and only the unrun type checks resumed after capacity recovered.
  • Independent review found no actionable P0-P2 findings.

Hosted CI 34954726529, merge revision f6c944691d41, exposed a missing export in the session-spawn test harness caused by this PR's classifier import. The harness now forwards the real classifier from its canonical leaf module. All eight lifecycle cases reproduce the same missing-export error with the published harness and pass with the repair; assertions, case order, and deadlines are unchanged. Targeted formatting, lint, and the canonical agents-root test type graph pass. Fresh independent review of the repair found no actionable P0-P2 findings.

Hosted CI 34959628169 on repaired head ee3ef5d23f3d remains a recorded failure. Its runtime-auth fixture failures are covered by merged #149004; the UI setup expectations by merged #149023; and the Copilot fixture cleanup and canonical credential metadata by merged #149016 and #149038. Main 80936b0933a1 contains these repairs. Complete retained logs attribute the failures to the historical CI base, outside this five-file diff. The fresh hosted review resolves the harness finding and reports no actionable findings. Head fb3658ce8995 now integrates repaired main 80936b0933a1. Its complete five-file binary diff and all original/candidate file snapshots are unchanged. Fresh CI 34965682831 then exposed six thinking-route tests whose runtime auth-store fixture was incomplete (2,034 passed and six failed in that shard). The failing test and runtime/model owners are unchanged by this PR. Merged #149049 supplies the existing fixture store through its runtime reader without changing the cases or assertions. Head ee1012b5dd3d now integrates main ed264cc3ca59; all five changed files and the complete patch remain unchanged. The subsequent exact-head failure is recorded below; that historical run did not satisfy native gates. Historical failures remain recorded; no test retry or timeout adjustment was used.

A source comparison with main 140ae96507a confirmed the four original files were unchanged and found no conflict with its newer committed-read lifecycle. Local tests and work counts remain evidence from the recorded base; they do not assert identical counts or latency on later main revisions.

Exact-head CI 34969565592 failed one plugin-inspection case (1,384 passed, one failed, six skipped in that shard). Existing diagnostics show that the written config matched the fixture and the initial snapshot was valid, then config observation rejected with STATE_DATABASE_READ_ADMISSION_INVALIDATED and returned a read-failed fallback. The test, command, and named observation owners are unchanged by this PR. Canonical repair #148839 landed as 1bbc39f1b988. Previous head 59d706b95a30 normally integrates repaired main 22a07e0abe7f, which also includes the child-evidence fixture repair #149243. The complete PR patch remains equivalent. Four complete original/candidate file pairs are unchanged; the cursor suite also incorporates the existing asynchronous database teardown from #148972. Fresh CI 34995632936 failed in native PR-tooling and Codex fixtures, detailed below. Historical failures remain failed evidence; no duplicate repair, CI rerun, or timeout adjustment was used.
That run failed 34 cases across the native main-refresh, cross-checkout, hosted-merge and Crabbox-authorization fixture suites because their GitHub mocks reject the repository metadata request introduced by #149230. A separate Codex model-attribution case failed background-terminal cleanup with TypeError: data is not iterable. The exact CI merge tree matches this PR, and all those owners/tests are unchanged by the fixed-store patch. The canonical repair owners investigated these failures; no duplicate fix, retry or deadline change was made here. That historical run did not satisfy native gates; the repairs and current-head check result are recorded below.

Current head b047bd1deebd integrates main 273b6c5e11462, containing the merged native fixture repair #149294 and Codex model-attribution fixture repair #149301. Every complete original/candidate file pair and the complete binary PR patch are byte-identical to the preceding reviewed integration. Existing source review remains applicable; prior runtime evidence retains its recorded base. Exact-head CI35006860947 passed on b047bd1deebd; native gates remain required before landing. Historical failures remain recorded; no CI retry or deadline/assertion change was made in this PR.

@clawsweeper

clawsweeper Bot commented Sep 15, 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 15, 2026
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Sep 15, 2026
@steipete
steipete marked this pull request as ready for review September 15, 2026 09:47
@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 15, 2026
@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 15, 2026, 3:29 PM ET / 19:29 UTC (Revision 12).

ClawSweeper review

What this changes

The PR skips redundant fixed-store inventory scans during Gateway session lookups while preserving ownership validation, cached discovery, and regression coverage.

Merge readiness

✅ Ready for maintainer review

Keep open: this remains a useful performance improvement absent from current main. No actionable introduced defect remains, and the earlier session-spawn harness finding is resolved.

Priority: P2
Reviewed head: b047bd1deebd47de821deea8ecfab8579ce7696c

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with relevant regression coverage, a resolved prior finding, and no remaining actionable defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The external-contributor proof gate does not apply to this maintainer PR, and no material authority change triggers additional proof. Recorded fixed-store comparisons support the changed discovery path on their stated base; this review does not recast them as current-head live execution.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The external-contributor proof gate does not apply to this maintainer PR, and no material authority change triggers additional proof. Recorded fixed-store comparisons support the changed discovery path on their stated base; this review does not recast them as current-head live execution.
Evidence reviewed 8 items Introduced optimization preserves validation: The fixed-store exclusion follows SQLite target resolution and collision-owner validation. It skips only the inventory probe whose result the configured caller previously discarded.
Cache and fallback semantics remain intact: Exclusion requires an uncached lookup, a configured agent, and a fixed store. Configured lookups still read the same fallback; deleted-main lookups and request-scoped discovery caches retain complete existing targets.
Production entrypoint: History requests use the read-only session loader, which reaches the changed lookup with exact-row reads. The optimization concerns OpenClaw store discovery; the unrelated Codex fixture repairs mentioned in the discussion do not establish a Codex dependency for this patch.
Findings None None.
Security None None.

How this fits together

The Gateway resolves session keys to agent-owned SQLite stores before serving history and startup requests. Store discovery selects candidate locations, and the session accessor reads the requested rows.

flowchart TD
  A[History or startup request] --> B[Resolve session and agent]
  B --> C[Validate store ownership]
  C --> D{Uncached configured fixed store?}
  D -->|Yes| E[Skip duplicate inventory scan]
  D -->|No| F[Keep complete discovery]
  E --> G[Read selected session rows]
  F --> G
  G --> H[Return session history]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +15, Tests +53. Total +68 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 27 12 +15
Tests 3 78 25 +53
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 105 37 +68

Review metrics

None.

Technical review

Best possible solution:

Keep the existing discovery owner and eliminate its discarded inventory work while retaining complete cached discovery and unchanged store-admission behavior.

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

Yes, from source: an uncached configured fixed-store lookup scans inventory before discarding the duplicate target; foreign rows can increase that work. This review did not execute the workload.

Is this the best way to solve the issue?

Yes. The patch removes discarded work through the existing discovery owner without adding another cache, changing selected stores, or altering persisted formats.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded Gateway performance improvement for fixed-store session reads, with no demonstrated urgent outage.
  • 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 external-contributor proof gate does not apply to this maintainer PR, and no material authority change triggers additional proof. Recorded fixed-store comparisons support the changed discovery path on their stated base; this review does not recast them as current-head live execution.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: 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.

History

Review history (11 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-15T10:53:20.215Z sha ee3ef5d :: needs maintainer review before merge. :: none
  • reviewed 2026-09-15T11:23:49.633Z sha ee3ef5d :: needs maintainer review before merge. :: none
  • reviewed 2026-09-15T12:17:50.556Z sha fb3658c :: needs maintainer review before merge. :: none
  • reviewed 2026-09-15T12:54:05.848Z sha ee1012b :: needs maintainer review before merge. :: none
  • reviewed 2026-09-15T14:07:41.297Z sha ee1012b :: needs changes before merge. :: none
  • reviewed 2026-09-15T16:46:34.492Z sha 59d706b :: blocked before merge. :: none
  • reviewed 2026-09-15T17:00:26.061Z sha 59d706b :: blocked before merge. :: none
  • reviewed 2026-09-15T18:38:39.134Z sha b047bd1 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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 15, 2026
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Sep 15, 2026
@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 15, 2026
@steipete
steipete merged commit 1fee2d3 into main Sep 15, 2026
200 checks passed
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@steipete
steipete deleted the codex/perf-fixed-store-discovery-7006 branch September 15, 2026 19:33
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 16, 2026
…openclaw#148985)

* improve(gateway): avoid redundant fixed-store discovery

* test(agents): preserve session store classifier in spawn harness
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling 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: 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