Skip to content

perf(gateway): skip empty session recovery stores - #117498

Merged
vincentkoc merged 2 commits into
mainfrom
perf/session-recovery-empty-store-skip
Aug 1, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
perf/session-recovery-empty-store-skip

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Aug 1, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Gateways with many configured agents can have per-agent SQLite databases before any durable session exists because unrelated auth or model-catalog state uses the same database. Restart recovery was opening the session writer path for every such store even when it had no interrupted run.

Kova exposed this on the 12-agent prepared-runtime fixture: sidecars.main-session-recovery took about 1.3 seconds on a fresh fixture.

Why This Change Was Made

The first implementation only checked whether the database file existed. Exact-head Kova disproved that approach: the databases already existed, so startup time was unchanged.

The corrected implementation adds a generic read-only indexed status probe and enters the recovery writer lane only for stores proven to contain running session rows. Missing databases return false without being created. Existing databases with an unknown or unreadable schema remain eligible for the writer path so diagnostics and compatibility behavior stay visible.

User Impact

Fresh multi-agent gateways avoid unnecessary recovery writer initialization for databases that contain only unrelated state. Interrupted durable sessions continue to recover normally, and unknown or corrupt durable stores retain the existing diagnostic path.

Evidence

@vincentkoc vincentkoc self-assigned this Aug 1, 2026
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS maintainer Maintainer-authored PR labels Aug 1, 2026
@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. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. 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, 1:21 PM ET / 17:21 UTC.

ClawSweeper review

What this changes

The PR adds a read-only session-status probe so gateway restart recovery skips agent databases that contain no running durable session.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

This focused optimization appears correct: it avoids writable recovery work for agent SQLite stores with no running durable session while preserving the existing writer path for missing, unknown, or unreadable stores. Keep it open for the assigned human maintainer review because it intentionally changes restart-recovery eligibility for persisted session state.

Priority: P2
Reviewed head: 140dae6bb03df2f8290c7126d33bfa256e04b50e
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, well-covered recovery optimization with credible runtime evidence; the remaining requirement is owner acceptance of the session-state boundary.
Proof confidence 🦞 diamond lobster (5/6) Not applicable: This member-authored PR is not subject to the external-contributor proof gate; its body nevertheless supplies Kova runtime measurements and focused recovery-test evidence.
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 Kova runtime measurements and focused recovery-test evidence.
Evidence reviewed 6 items Current main behavior: Current main collects each discovered/configured store path and sends every path to the recovery writer path; the PR narrows only that eligibility step.
Read-only predicate preserves diagnostic fallback: The proposed accessor returns false only for a missing database; schema-missing and table-missing outcomes remain eligible for the existing writable path, preserving diagnostics and repair behavior.
Read-only database contract: The underlying read-only helper does not create, register, migrate, or join the writable database lifecycle; absent stores report database-missing without opening a database.
Findings None None.
Security None None.

How this fits together

Gateway startup scans configured and discovered agent session stores, then marks interrupted running sessions for recovery. This change inserts a read-only status check before the session writer path so unrelated agent-database state does not trigger recovery initialization.

flowchart LR
  A[Gateway restart] --> B[Discover agent session stores]
  B --> C[Read-only session status probe]
  C -->|running row found| D[Recovery writer path]
  C -->|database missing or no running row| E[Skip store]
  C -->|unknown or unreadable schema| D
  D --> F[Mark interrupted session for recovery]
Loading

Decision needed

Question Recommendation
Should gateway restart recovery enter the writer lane only when the read-only session store proves a running row exists, while retaining the current writer path for unknown or unreadable stores? Accept the focused eligibility gate: Merge the read-only status probe because it preserves active-session recovery and routes missing or unknown stores safely.

Why: The implementation is mechanically sound and covered, but it deliberately changes the recovery boundary for durable session state; accepting that behavioral contract is an owner decision.

Before merge

  • Resolve merge risk (P1) - This changes which persisted stores enter restart recovery: a false-negative status probe could leave an interrupted durable session unmarked, so a human owner should explicitly accept the new eligibility boundary before merge.
Agent review details

Security

None.

PR surface

Source +40, Tests +96. Total +136 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 5 43 3 +40
Tests 2 96 0 +96
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 139 3 +136

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: src/config/sessions/session-accessor.readonly.test.ts, serialized state: src/config/sessions/session-accessor.sqlite-entry.ts, unknown-data-model-change: src/config/sessions/session-accessor.readonly.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Accept the conservative recovery gate (recommended)
    Merge with the existing status tests and runtime evidence, accepting that only stores with a running row enter writer recovery while unknown stores retain the old path.
  2. Pause for a different recovery contract
    Keep the PR open if maintainers require writer-side inspection of valid empty stores despite the measured startup cost.

Technical review

Best possible solution:

Keep the single read-only probe and its conservative unknown-schema fallback, then land it once the recovery-path owner accepts the stored-session eligibility change.

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

Yes, at source level: current main sends every discovered/configured store into startup recovery, while the branch's focused tests exercise missing stores, inactive stores, and stores with running rows. I did not execute the tests because this review checkout is read-only.

Is this the best way to solve the issue?

Yes: reusing the existing read-only agent-database contract at the recovery eligibility boundary is narrower and safer than opening every store writable or adding a second discovery mechanism.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 8b994fc9e170.

Labels

Label justifications:

  • P2: This is a bounded gateway startup-performance improvement with a persisted-session correctness boundary, not an active outage.
  • merge-risk: 🚨 session-state: The patch changes which session stores are eligible for restart recovery, so an incorrect predicate could miss recovery of an interrupted durable session.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster 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 Kova runtime measurements and focused recovery-test evidence.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Introduced the pure-read agent-database access refactor that supplies the non-creating inspection contract used by this PR. (role: read-only database abstraction introducer; confidence: high; commits: d8846a1dcb88; files: src/state/openclaw-agent-db-readonly.ts, src/config/sessions/session-accessor.sqlite-entry.ts)
  • Miorbnli: Git history attributes the current restart-recovery shared path surrounding the new eligibility gate to this contributor. (role: recent recovery-path contributor; confidence: medium; commits: 0d8b70f39e44; files: src/agents/main-session-restart-recovery-shared.ts, src/agents/main-session-restart-recovery-marking.ts)
  • Vincent Koc: Recent history shows related configuration/session work, and the PR implementation is attributable to this contributor. (role: recent session/config contributor; confidence: medium; commits: 0e4fa090e2cf, c1623140f6d5; files: src/config/sessions/session-accessor.sqlite-entry.ts, src/agents/main-session-restart-recovery-shared.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 (4 earlier review cycles)
  • reviewed 2026-08-01T16:23:19.405Z sha dfb7f85b6e6cf959769017ccee55e5af8230e833 :: found issues before merge. :: [P1] Preserve non-ENOENT store-inspection failures
  • reviewed 2026-08-01T16:38:03.379Z sha 3890fea5705ca20538600ed9205b7f11d7ae3338 :: found issues before merge. :: [P3] Remove the release-owned changelog entry
  • reviewed 2026-08-01T16:59:04.773Z sha 3361c7550266396befd56d551aad052d479e622f :: needs maintainer review before merge. :: none
  • reviewed 2026-08-01T17:09:31.622Z sha 3361c7550266396befd56d551aad052d479e622f :: needs maintainer review before merge. :: none

@vincentkoc
vincentkoc force-pushed the perf/session-recovery-empty-store-skip branch from dfb7f85 to 3890fea Compare August 1, 2026 16:33
@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
vincentkoc marked this pull request as ready for review August 1, 2026 16:51
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 1, 2026
@vincentkoc
vincentkoc force-pushed the perf/session-recovery-empty-store-skip branch from 3361c75 to 140dae6 Compare August 1, 2026 17:16
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Aug 1, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

Maintainer decision:

  • Accept the conservative recovery eligibility boundary: only stores that prove a running session row enter writer recovery.
  • Valid stores with no running rows may skip writable recovery initialization.
  • Missing, schema-unknown, table-unknown, unreadable, and corrupt existing stores retain the current writer/diagnostic path.
  • Approve landing only after the refreshed exact-head CI and Kova runs complete successfully.

This resolves the remaining ClawSweeper owner-decision item on head 140dae6bb03df2f8290c7126d33bfa256e04b50e.

@vincentkoc

Copy link
Copy Markdown
Member Author

Land-ready verification for head 140dae6bb03df2f8290c7126d33bfa256e04b50e:

This satisfies the remaining exact-head ClawSweeper Before merge owner-decision item. No ClawSweeper findings or security items remain.

@vincentkoc
vincentkoc merged commit 5118b0b into main Aug 1, 2026
133 of 135 checks passed
@vincentkoc
vincentkoc deleted the perf/session-recovery-empty-store-skip branch August 1, 2026 17:29
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 1, 2026
* origin/main: (26 commits)
  fix(update): return failure when dirty checkout blocks update (#117452)
  fix(auto-reply): apply mixed chat directives in one session transaction (#117542)
  refactor(ui): unify channel status and setup controls (#117499)
  fix(doctor): preserve surviving lint selections (#117543)
  fix(media): keep an unquoted MEDIA path with spaces as one media item (#112464)
  refactor(channels): consolidate lightweight plugin discovery (#117541)
  fix(imessage): prevent duplicate messages after delayed sends (#110853)
  refactor(memory): unify authoritative dreaming state and presentation (#117538)
  refactor(agents): consolidate main-session recovery ownership (#117383)
  fix(proxy-capture): make path-based session cleanup atomic (#98852)
  refactor(agents): consolidate compaction and context-engine ownership (#117482)
  fix(gateway): preserve Responses usage details (#117533)
  perf(gateway): skip empty session recovery stores (#117498)
  fix(ci): update canonical Kova performance pin (#117508)
  fix(system-agent): emit the wizard cancel hint once per message (#113731)
  refactor: dedupe secrets runtime snapshot fixtures (#117502)
  test(google): cover ready callback close precedence
  test(openai): dedupe realtime voice fixtures (#117503)
  fix(google): flush lazy prompts on provider readiness
  fix(gateway): keep canonical hooks on pristine startup path (#117493)
  ...
abdulrahman305 pushed a commit to qenex-ai/openclaw that referenced this pull request Aug 1, 2026
* origin/main: (35 commits)
  fix(update): return failure when dirty checkout blocks update (openclaw#117452)
  fix(auto-reply): apply mixed chat directives in one session transaction (openclaw#117542)
  refactor(ui): unify channel status and setup controls (openclaw#117499)
  fix(doctor): preserve surviving lint selections (openclaw#117543)
  fix(media): keep an unquoted MEDIA path with spaces as one media item (openclaw#112464)
  refactor(channels): consolidate lightweight plugin discovery (openclaw#117541)
  fix(imessage): prevent duplicate messages after delayed sends (openclaw#110853)
  refactor(memory): unify authoritative dreaming state and presentation (openclaw#117538)
  refactor(agents): consolidate main-session recovery ownership (openclaw#117383)
  fix(proxy-capture): make path-based session cleanup atomic (openclaw#98852)
  refactor(agents): consolidate compaction and context-engine ownership (openclaw#117482)
  fix(gateway): preserve Responses usage details (openclaw#117533)
  perf(gateway): skip empty session recovery stores (openclaw#117498)
  fix(ci): update canonical Kova performance pin (openclaw#117508)
  fix(system-agent): emit the wizard cancel hint once per message (openclaw#113731)
  refactor: dedupe secrets runtime snapshot fixtures (openclaw#117502)
  test(google): cover ready callback close precedence
  test(openai): dedupe realtime voice fixtures (openclaw#117503)
  fix(google): flush lazy prompts on provider readiness
  fix(gateway): keep canonical hooks on pristine startup path (openclaw#117493)
  ...
vincentkoc added a commit that referenced this pull request Aug 1, 2026
* origin/main: (491 commits)
  feat(gateway): advertise chat attachment limits on hello-ok (#116188)
  fix(ui): preserve full graphemes in session owner initials (#117350)
  refactor(tui): consolidate runtime ownership (#117368)
  fix(update): return failure when dirty checkout blocks update (#117452)
  fix(auto-reply): apply mixed chat directives in one session transaction (#117542)
  refactor(ui): unify channel status and setup controls (#117499)
  fix(doctor): preserve surviving lint selections (#117543)
  fix(media): keep an unquoted MEDIA path with spaces as one media item (#112464)
  refactor(channels): consolidate lightweight plugin discovery (#117541)
  fix(imessage): prevent duplicate messages after delayed sends (#110853)
  refactor(memory): unify authoritative dreaming state and presentation (#117538)
  refactor(agents): consolidate main-session recovery ownership (#117383)
  fix(proxy-capture): make path-based session cleanup atomic (#98852)
  refactor(agents): consolidate compaction and context-engine ownership (#117482)
  fix(gateway): preserve Responses usage details (#117533)
  perf(gateway): skip empty session recovery stores (#117498)
  fix(ci): update canonical Kova performance pin (#117508)
  fix(system-agent): emit the wizard cancel hint once per message (#113731)
  refactor: dedupe secrets runtime snapshot fixtures (#117502)
  test(google): cover ready callback close precedence
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 2, 2026
* perf(gateway): skip inactive session recovery stores

* chore: leave release notes to release workflow
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 2, 2026
* origin/main: (26 commits)
  fix(update): return failure when dirty checkout blocks update (openclaw#117452)
  fix(auto-reply): apply mixed chat directives in one session transaction (openclaw#117542)
  refactor(ui): unify channel status and setup controls (openclaw#117499)
  fix(doctor): preserve surviving lint selections (openclaw#117543)
  fix(media): keep an unquoted MEDIA path with spaces as one media item (openclaw#112464)
  refactor(channels): consolidate lightweight plugin discovery (openclaw#117541)
  fix(imessage): prevent duplicate messages after delayed sends (openclaw#110853)
  refactor(memory): unify authoritative dreaming state and presentation (openclaw#117538)
  refactor(agents): consolidate main-session recovery ownership (openclaw#117383)
  fix(proxy-capture): make path-based session cleanup atomic (openclaw#98852)
  refactor(agents): consolidate compaction and context-engine ownership (openclaw#117482)
  fix(gateway): preserve Responses usage details (openclaw#117533)
  perf(gateway): skip empty session recovery stores (openclaw#117498)
  fix(ci): update canonical Kova performance pin (openclaw#117508)
  fix(system-agent): emit the wizard cancel hint once per message (openclaw#113731)
  refactor: dedupe secrets runtime snapshot fixtures (openclaw#117502)
  test(google): cover ready callback close precedence
  test(openai): dedupe realtime voice fixtures (openclaw#117503)
  fix(google): flush lazy prompts on provider readiness
  fix(gateway): keep canonical hooks on pristine startup path (openclaw#117493)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 2, 2026
* origin/main: (35 commits)
  fix(update): return failure when dirty checkout blocks update (openclaw#117452)
  fix(auto-reply): apply mixed chat directives in one session transaction (openclaw#117542)
  refactor(ui): unify channel status and setup controls (openclaw#117499)
  fix(doctor): preserve surviving lint selections (openclaw#117543)
  fix(media): keep an unquoted MEDIA path with spaces as one media item (openclaw#112464)
  refactor(channels): consolidate lightweight plugin discovery (openclaw#117541)
  fix(imessage): prevent duplicate messages after delayed sends (openclaw#110853)
  refactor(memory): unify authoritative dreaming state and presentation (openclaw#117538)
  refactor(agents): consolidate main-session recovery ownership (openclaw#117383)
  fix(proxy-capture): make path-based session cleanup atomic (openclaw#98852)
  refactor(agents): consolidate compaction and context-engine ownership (openclaw#117482)
  fix(gateway): preserve Responses usage details (openclaw#117533)
  perf(gateway): skip empty session recovery stores (openclaw#117498)
  fix(ci): update canonical Kova performance pin (openclaw#117508)
  fix(system-agent): emit the wizard cancel hint once per message (openclaw#113731)
  refactor: dedupe secrets runtime snapshot fixtures (openclaw#117502)
  test(google): cover ready callback close precedence
  test(openai): dedupe realtime voice fixtures (openclaw#117503)
  fix(google): flush lazy prompts on provider readiness
  fix(gateway): keep canonical hooks on pristine startup path (openclaw#117493)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 2, 2026
* origin/main: (491 commits)
  feat(gateway): advertise chat attachment limits on hello-ok (openclaw#116188)
  fix(ui): preserve full graphemes in session owner initials (openclaw#117350)
  refactor(tui): consolidate runtime ownership (openclaw#117368)
  fix(update): return failure when dirty checkout blocks update (openclaw#117452)
  fix(auto-reply): apply mixed chat directives in one session transaction (openclaw#117542)
  refactor(ui): unify channel status and setup controls (openclaw#117499)
  fix(doctor): preserve surviving lint selections (openclaw#117543)
  fix(media): keep an unquoted MEDIA path with spaces as one media item (openclaw#112464)
  refactor(channels): consolidate lightweight plugin discovery (openclaw#117541)
  fix(imessage): prevent duplicate messages after delayed sends (openclaw#110853)
  refactor(memory): unify authoritative dreaming state and presentation (openclaw#117538)
  refactor(agents): consolidate main-session recovery ownership (openclaw#117383)
  fix(proxy-capture): make path-based session cleanup atomic (openclaw#98852)
  refactor(agents): consolidate compaction and context-engine ownership (openclaw#117482)
  fix(gateway): preserve Responses usage details (openclaw#117533)
  perf(gateway): skip empty session recovery stores (openclaw#117498)
  fix(ci): update canonical Kova performance pin (openclaw#117508)
  fix(system-agent): emit the wizard cancel hint once per message (openclaw#113731)
  refactor: dedupe secrets runtime snapshot fixtures (openclaw#117502)
  test(google): cover ready callback close precedence
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. 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