Skip to content

perf(gateway): skip empty session reconciliation - #117589

Merged
vincentkoc merged 2 commits into
mainfrom
perf/startup-skip-empty-agent-db
Aug 1, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
perf/startup-skip-empty-agent-db

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

Related: #117577

What Problem This Solves

Fixes an issue where gateways with configured agents that had no session state would create and schema-register an empty SQLite database for every agent during startup transcript reconciliation.

Why This Change Was Made

Startup now checks each configured agent's canonical SQLite path after the legacy import step and reconciles transcript projections only when that database exists. Request-time reconciliation and reconciliation for existing or newly imported databases remain unchanged.

User Impact

Gateways with many configured but unused agents start faster and no longer create empty per-agent databases solely because the gateway started.

Evidence

  • Safe temp-state probe on Node 24.15.0:
    • current main, 1 agent: 123-139 ms, 1 reconcile call, 1 database created
    • this branch, 1 agent: 1.5-1.6 ms, 0 reconcile calls, 0 databases created
    • current main, 12 agents: 424-433 ms, 12 reconcile calls, 12 databases created
    • this branch, 12 agents: 45.1-48.8 ms, 0 reconcile calls, 0 databases created
  • node scripts/run-vitest.mjs src/gateway/server-startup-session-migration.test.ts
    • 15/15 tests passed
  • Targeted oxfmt, oxlint, and git diff --check passed.
  • Structured autoreview completed with no accepted or actionable findings.
  • The broader oxlint wrapper was attempted but stopped on an unrelated current-main declaration error in packages/terminal-core/src/ansi.ts; the touched files pass direct targeted lint.

@vincentkoc vincentkoc self-assigned this Aug 1, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review August 1, 2026 19:21
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Aug 1, 2026
@vincentkoc
vincentkoc force-pushed the perf/startup-skip-empty-agent-db branch from 0dd5a53 to 937393e Compare August 1, 2026 19:25
@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. P2 Normal backlog priority with limited blast radius. labels Aug 1, 2026
@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 3:45 PM ET / 19:45 UTC.

ClawSweeper review

What this changes

The branch adds a post-import filesystem check so gateway startup reconciles transcript projections only for configured agents whose canonical SQLite session database exists, with regression coverage for absent, existing, and import-created databases.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open for normal maintainer landing. Current main still reconciles every configured agent at startup, and that reconciliation opens, schema-validates, and registers the per-agent SQLite database; this focused branch filters out absent databases only after legacy import. The prior release-owned changelog finding is resolved, the latest head has no actionable correctness finding, and the maintainer label plus MEMBER authorship require an explicit human landing decision rather than automated cleanup.

Priority: P2
Reviewed head: 25002874795eaff6904247c738ed372492393c87
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused source-level repair with coherent owner-boundary tests and supplied exact-head validation; no blocking defect was found.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: This MEMBER-authored PR is not subject to the external-contributor proof gate; its body nevertheless supplies after-fix temp-state measurements and the provided exact-head CI includes a successful real-behavior-proof check.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This MEMBER-authored PR is not subject to the external-contributor proof gate; its body nevertheless supplies after-fix temp-state measurements and the provided exact-head CI includes a successful real-behavior-proof check.
Evidence reviewed 7 items Current-main behavior creates the unwanted work: Current main enumerates every configured agent and invokes transcript reconciliation without checking for an existing SQLite database.
Reconciliation is the database-creating owner path: Transcript reconciliation resolves the canonical agent SQLite path and begins a projection write; that writer opens the agent database, whose open path ensures schema and registers the database.
Branch changes the correct lifecycle boundary: The branch runs the existence filter after runStartupSessionSqliteImport, then retains reconciliation for each existing or newly imported database; it does not alter the schema, import contract, or request-time reconciliation owner.
Findings None None.
Security None None.

How this fits together

Gateway startup performs session maintenance before serving requests: it imports any legacy session store, then repairs SQLite transcript projections. The projection repair currently opens each configured agent database, so filtering absent databases prevents unused agents from gaining empty persistent state during startup.

flowchart LR
  A[Configured agents] --> B[Legacy session import]
  B --> C[Canonical agent SQLite path]
  C --> D{Database exists?}
  D -- Yes --> E[Reconcile transcript projections]
  D -- No --> F[Skip empty database creation]
  E --> G[Gateway begins serving]
  F --> G
Loading

Decision needed

Question Recommendation
Does the owner of gateway session persistence approve landing this focused startup filter, which stops empty per-agent SQLite creation while retaining reconciliation for existing and import-created databases? Land the focused filter: Accept the post-import existence check because it preserves all durable-session reconciliation paths and removes startup-created empty databases.

Why: The patch is source-consistent and the author is a repository MEMBER, but the protected maintainer label requires an explicit human landing decision rather than an automated close or repair route.

Before merge

None.

Agent review details

Security

None.

PR surface

Source +23, Tests +111. Total +134 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 24 1 +23
Tests 1 111 0 +111
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 135 1 +134

Review metrics

None.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/gateway/server-startup-session-migration.test.ts, migration/backfill/repair: src/gateway/server-startup-session-migration.ts, unknown-data-model-change: src/gateway/server-startup-session-migration.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Technical review

Best possible solution:

Keep the post-import existence filter as the canonical startup behavior and land it after the session-persistence owner confirms the exact merge result; existing and import-created databases must continue through projection reconciliation.

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

Yes — source establishes that current main reconciles every configured agent, and reconciliation opens and schema-registers its SQLite database. The branch's focused tests and supplied temp-state measurements cover the absent, existing, and import-created database cases, although this read-only review did not execute them.

Is this the best way to solve the issue?

Yes — the filter sits after the legacy-import owner and before the database-opening reconciliation owner, so it removes the unnecessary producer-side work without adding runtime fallback behavior or changing schema/config contracts.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 26aa884c6914.

Labels

Label justifications:

  • P2: This is a bounded gateway startup persistence/performance repair that prevents unwanted empty state creation without evidence of an urgent user-facing outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This MEMBER-authored PR is not subject to the external-contributor proof gate; its body nevertheless supplies after-fix temp-state measurements and the provided exact-head CI includes a successful real-behavior-proof check.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Introduced the startup session migration module and its original unconditional reconciliation loop in the current-main history. (role: feature introducer and current-path owner; confidence: high; commits: aa2a5c96f69a; files: src/gateway/server-startup-session-migration.ts, src/gateway/server-startup-session-migration.test.ts)

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 (2 earlier review cycles)
  • reviewed 2026-08-01T19:30:26.065Z sha 937393e :: found issues before merge. :: [P2] Remove the release-owned changelog entry
  • reviewed 2026-08-01T19:37:57.113Z sha 2500287 :: needs maintainer review before merge. :: none

@vincentkoc

Copy link
Copy Markdown
Member Author

Resolved the exact-head ClawSweeper finding on 25002874795eaff6904247c738ed372492393c87.

  • Removed the branch-local CHANGELOG.md entry.
  • Kept the release-note context in the PR body.
  • The runtime and regression-test diff is unchanged.
  • Repository-native review artifacts validate as READY FOR /prepare-pr with zero findings.

This resolves the P2 changelog finding, its derived merge risk, and the matching rank-up move.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@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 Aug 1, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

Final exact-head landing proof is complete for 25002874795eaff6904247c738ed372492393c87.

  • Exact-head GitHub CI has no pending or failing checks: 62 passed, 32 intentional skips; cancelled entries are superseded duplicate proof jobs.
  • OPENCLAW_TESTBOX=1 scripts/pr prepare-run 117589 completed successfully against current origin/main at 2f92c17db6e.
  • Hosted exact-or-recent-parent gates passed.
  • Repository-native review artifacts remain READY FOR /prepare-pr with zero findings.
  • The release-owned changelog finding and its rank-up move are resolved; release-note context remains in the PR body.
  • Maintainer decision: land the focused startup-owner repair. It changes no SQLite schema or migration contract and preserves reconciliation for existing and import-created databases.

This resolves the durable review's current-main merge-risk and maintainer-decision items.

@clawsweeper re-review

@vincentkoc
vincentkoc merged commit 27b1d04 into main Aug 1, 2026
126 of 132 checks passed
@vincentkoc
vincentkoc deleted the perf/startup-skip-empty-agent-db branch August 1, 2026 19:47
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 1, 2026
* commit '81e392b7ff43bcdb7a3be50a99adf65c3b0141b5':
  fix(channels): preserve filters in offline status diagnostics (#117570)
  perf(gateway): separate startup maintenance timing (#117577)
  refactor(tests): deduplicate database-first guard fixtures (#117594)
  fix(cli): align sessions cleanup label summary by visible width (#117459)
  perf(gateway): skip empty session reconciliation (#117589)
vincentkoc added a commit that referenced this pull request Aug 1, 2026
* commit '81e392b7ff43bcdb7a3be50a99adf65c3b0141b5':
  fix(channels): preserve filters in offline status diagnostics (#117570)
  perf(gateway): separate startup maintenance timing (#117577)
  refactor(tests): deduplicate database-first guard fixtures (#117594)
  fix(cli): align sessions cleanup label summary by visible width (#117459)
  perf(gateway): skip empty session reconciliation (#117589)
  refactor(ui): consolidate cron form control rendering (#117576)
  fix(memory): recover restored session freshness (#117548)
  fix(ui): preserve Talk transcript surrogate bounds
  fix(ui): harden Talk transcript marker bounds
  test(ui): cover bounded realtime Talk entries
  fix(ui): bound realtime Talk conversation text
vincentkoc added a commit that referenced this pull request Aug 1, 2026
* origin/main:
  perf(gateway): separate startup maintenance timing (#117577)
  refactor(tests): deduplicate database-first guard fixtures (#117594)
  fix(cli): align sessions cleanup label summary by visible width (#117459)
  perf(gateway): skip empty session reconciliation (#117589)
vincentkoc added a commit that referenced this pull request Aug 1, 2026
* commit '81e392b7ff43bcdb7a3be50a99adf65c3b0141b5':
  fix(channels): preserve filters in offline status diagnostics (#117570)
  perf(gateway): separate startup maintenance timing (#117577)
  refactor(tests): deduplicate database-first guard fixtures (#117594)
  fix(cli): align sessions cleanup label summary by visible width (#117459)
  perf(gateway): skip empty session reconciliation (#117589)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 2, 2026
* perf(gateway): skip empty session reconciliation

* chore(release): remove branch-local changelog entry
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 2, 2026
* commit '58213dd5389737ff100c6286d110921defeb76e8':
  fix(channels): preserve filters in offline status diagnostics (openclaw#117570)
  perf(gateway): separate startup maintenance timing (openclaw#117577)
  refactor(tests): deduplicate database-first guard fixtures (openclaw#117594)
  fix(cli): align sessions cleanup label summary by visible width (openclaw#117459)
  perf(gateway): skip empty session reconciliation (openclaw#117589)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 2, 2026
* origin/main:
  perf(gateway): separate startup maintenance timing (openclaw#117577)
  refactor(tests): deduplicate database-first guard fixtures (openclaw#117594)
  fix(cli): align sessions cleanup label summary by visible width (openclaw#117459)
  perf(gateway): skip empty session reconciliation (openclaw#117589)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 2, 2026
* commit '58213dd5389737ff100c6286d110921defeb76e8':
  fix(channels): preserve filters in offline status diagnostics (openclaw#117570)
  perf(gateway): separate startup maintenance timing (openclaw#117577)
  refactor(tests): deduplicate database-first guard fixtures (openclaw#117594)
  fix(cli): align sessions cleanup label summary by visible width (openclaw#117459)
  perf(gateway): skip empty session reconciliation (openclaw#117589)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 2, 2026
* commit '58213dd5389737ff100c6286d110921defeb76e8':
  fix(channels): preserve filters in offline status diagnostics (openclaw#117570)
  perf(gateway): separate startup maintenance timing (openclaw#117577)
  refactor(tests): deduplicate database-first guard fixtures (openclaw#117594)
  fix(cli): align sessions cleanup label summary by visible width (openclaw#117459)
  perf(gateway): skip empty session reconciliation (openclaw#117589)
  refactor(ui): consolidate cron form control rendering (openclaw#117576)
  fix(memory): recover restored session freshness (openclaw#117548)
  fix(ui): preserve Talk transcript surrogate bounds
  fix(ui): harden Talk transcript marker bounds
  test(ui): cover bounded realtime Talk entries
  fix(ui): bound realtime Talk conversation text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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