Skip to content

fix(sessions): avoid startup stalls with many empty agent stores - #126685

Merged
steipete merged 1 commit into
openclaw:mainfrom
goutamadwant:fix/session-migration-empty-store-scaling
Aug 25, 2026
Merged

steipete merged 1 commit into
openclaw:mainfrom
goutamadwant:fix/session-migration-empty-store-scaling

Conversation

@goutamadwant

@goutamadwant goutamadwant commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #126676.

What Problem This Solves

Gateway session migration performs quadratic filesystem alias detection when many configured agents have no existing session stores. A 500-agent state previously performed 124,750 filesystem probes and stalled the migration owner for approximately 5.5 seconds; larger deployments scale significantly worse.

Why This Change Was Made

Check whether each candidate session-store path actually exists before adding it to physical-path alias grouping. Definitely absent paths are skipped immediately, while existing files and inaccessible paths preserve the original conservative, fail-closed alias ownership and warning behavior. Reuse the existing owner map to keep the production change net-neutral.

Production LOC: +9/-9 (net 0). Regression tests: +23.

User Impact

Session-store migration now scales linearly with absent per-agent stores. Existing aliases, shared stores, symlinks, hardlinks, inaccessible paths, and migration idempotence retain their previous behavior.

Evidence

  • Before repair: the real production migration owner performs 4,950 probes for 100 agents, 31,125 for 250 agents, and 124,750 for 500 agents; the focused 100-agent linear-bound regression fails.
  • After repair: the same actual production migration owner performs exactly one filesystem probe per configured agent, including a 10,000-agent isolated run; the complete inspectable command and actual stdout appear below.
  • All 46 focused migration and startup sibling tests pass, including inaccessible-path fail-closed behavior, readable aliases, symlinks, hardlinks, shared-owner stores, and idempotence.
  • Full trusted production build passes.
  • Complete local changed gate passes all 27 guards without skips, including production/test typechecking, lint, formatting, dead-code checks, unchanged SQLite schema baseline, database-first rules, and import cycles.
  • Fresh structured autoreview: clean; independent reviewer approved the exact owner repair and failure semantics.
  • Whole-Gateway 10,000-agent before/after timing is not claimed: unrelated configuration/bootstrap overhead occurs before the migration owner, so the measured results below invoke the actual production migration owner with actual configured agent lists and isolated missing state.
  • Exact reviewed head: 509eb2c53f055f75eb1fdeb6cff92de374b4f60d.
  • Original contributor attribution is preserved as Co-authored-by: goutamadwant <[email protected]>.

Inspectable real production-owner terminal proof

node --import tsx --input-type=module -e 'import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import { performance } from "node:perf_hooks"; import { migrateOrphanedSessionKeys } from "./src/infra/state-migrations.session-store.ts"; import { EMPTY_LEGACY_SESSION_SURFACES } from "./src/plugins/legacy-session-surfaces.types.ts"; for (const agents of [100,250,500,10000]) { const state=fs.mkdtempSync(path.join(os.tmpdir(),"openclaw-session-proof-")); const stat=fs.statSync; let probes=0; fs.statSync=function(candidate,...args){ if(String(candidate).endsWith("sessions.json"))probes++; return stat.call(fs,candidate,...args) }; const started=performance.now(); try { const result=await migrateOrphanedSessionKeys({cfg:{session:{store:path.join(state,"stores","{agentId}","sessions.json")},agents:{list:Array.from({length:agents},(_,index)=>({id:`agent-${index}`}))}},env:{OPENCLAW_STATE_DIR:state},additionalAgentIds:[],legacySessionSurfaces:EMPTY_LEGACY_SESSION_SURFACES}); console.log(JSON.stringify({agents,sessionStoreStatProbes:probes,durationMs:Math.round(performance.now()-started),changes:result.changes.length,warnings:result.warnings.length})); } finally {fs.statSync=stat;fs.rmSync(state,{recursive:true,force:true})} }'
{"agents":100,"sessionStoreStatProbes":100,"durationMs":1,"changes":0,"warnings":0}
{"agents":250,"sessionStoreStatProbes":250,"durationMs":1,"changes":0,"warnings":0}
{"agents":500,"sessionStoreStatProbes":500,"durationMs":1,"changes":0,"warnings":0}
{"agents":10000,"sessionStoreStatProbes":10000,"durationMs":26,"changes":0,"warnings":0}

This is real production migration-owner execution against genuine configured agent lists and isolated temporary filesystem state. It is not a full Gateway startup measurement and does not require or expose provider credentials.

Disclosure: AI was used to understand the codebase and review the fix.

@clawsweeper

clawsweeper Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@goutamadwant
goutamadwant marked this pull request as ready for review August 20, 2026 13:54
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 20, 2026
@clawsweeper

clawsweeper Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 25, 2026, 2:56 PM ET / 18:56 UTC.

ClawSweeper review

What this changes

The PR skips definitely absent configured session-store files before alias grouping and adds a regression test that bounds the resulting filesystem probes.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

No blocking patch finding: the owner-level prefilter removes the absent-store quadratic path while retaining existing and inaccessible-path handling. The PR is still necessary because current main lacks this repair; it awaits normal exact-head integration validation.

Priority: P1
Reviewed head: 509eb2c53f055f75eb1fdeb6cff92de374b4f60d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Strong owner-level terminal proof and a focused net-neutral repair support a normal mergeable-quality rating, pending ordinary exact-head integration checks.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body includes exact-head terminal output from the real migration owner, showing linear probe counts and unchanged migration results for isolated absent-store states.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body includes exact-head terminal output from the real migration owner, showing linear probe counts and unchanged migration results for isolated absent-store states.
Evidence reviewed 6 items Current-main gap: The current-main-to-PR diff shows main still enters each configured path into the alias scan; the PR adds the regular-file prefilter before that scan.
Owner-boundary repair: The changed migration owner skips missing or non-file paths, preserves caught inaccessible paths for conservative alias handling, and otherwise retains the existing alias logic.
Regression coverage: The added test uses 100 configured per-agent paths, observes the real filesystem probe boundary, and requires one probe per missing store; the previous scan would probe every earlier candidate.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/infra/state-migrations.orphan-keys.test.ts

Result: FAIL (partial) — step 2 expect_output checks missing agent stores without comparing every earlier path: expected terminal output was not visible within 30 seconds: "checks missing agent stores without comparing every earlier path"

[test] starting test/vitest/vitest.infra.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-126685-TvOj2J/target

 ✓  infra  src/infra/state-migrations.orphan-keys.test.ts (43 tests) 179ms

 Test Files  1 passed (1)
      Tests  43 passed (43)
   Start at  18:57:27
   Duration  7.09s (transform 5.40s, setup 1.11s, import 5.68s, tests 179ms, environment 0ms)

[test] passed 1 Vitest shard in 13.09s
[test] starting test/vitest/vitest.infra.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-126685-TvOj2J/target

 ✓  infra  src/infra/state-migrations.orphan-keys.test.ts (43 tests) 166ms

 Test Files  1 passed (1)
      Tests  43 passed (43)
   Start at  18:57:41
   Duration  3.37s (transform 1.74s, setup 499ms, import 2.59s, tests 166ms, environment 0ms)

[test] passed 1 Vitest shard in 9.38s

Assertions:

  • FAIL expect_output: checks missing agent stores without comparing every earlier path

How this fits together

Gateway startup runs a legacy session-store migration before the HTTP listener is available. The migration derives store ownership from configured and discovered agents, then reads and canonicalizes real session-store files.

flowchart LR
  A[Gateway startup] --> B[Session migration]
  C[Configured agent stores] --> D[Store ownership mapping]
  D --> E{Regular file exists?}
  E -->|No| F[Skip absent path]
  E -->|Yes or inaccessible| G[Alias safety checks]
  G --> H[Session migration results]
Loading

Before merge

  • Resolve merge risk (P1) - The branch is behind main and the recorded exact-head ci-gate is failing, so merge should wait for a current integration result despite the focused proof.
  • Complete next step (P2) - No discrete repair remains on the submitted branch; the next action is ordinary exact-head integration validation and maintainer merge review.
Agent review details

Security

None.

PR surface

Source 0, Tests +23. Total +23 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 9 9 0
Tests 1 23 0 +23
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 32 9 +23

Review metrics

Metric Value Why it matters
Production versus regression LOC production +9/-9 (net 0); tests +23/-0 The repair absorbs the performance fix into the existing migration owner while adding focused coverage for the missing-store invariant.

Stored data model

Persistent data-model change detected: serialized state: src/infra/state-migrations.orphan-keys.test.ts, serialized state: src/infra/state-migrations.session-store.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #126676
Summary: This PR is the explicit candidate repair for the linked Gateway startup-stall report.

Members:

  • canonical: [Bug]: #126676 - The PR explicitly connects its migration-owner repair to the reported large-agent startup stall.

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land the owner-boundary prefilter after current-head checks confirm it integrates cleanly, retaining the existing alias and inaccessible-path safeguards.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land the owner-boundary prefilter after current-head checks confirm it integrates cleanly, retaining the existing alias and inaccessible-path safeguards.

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

Yes—source establishes the quadratic scan over absent configured paths, and the PR’s exact-head terminal run exercises the real migration owner with up to 10,000 such paths.

Is this the best way to solve the issue?

Yes—the prefilter is at the migration owner that creates the unnecessary alias groups; an inode-index redesign would be broader and would need to preserve unknown-identity fail-closed behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 858d95fa4dcf.

Labels

Label justifications:

  • P1: The change addresses a startup path that can prevent Gateway availability for deployments with many configured agents.
  • 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. Sufficient (terminal): The PR body includes exact-head terminal output from the real migration owner, showing linear probe counts and unchanged migration results for isolated absent-store states.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes exact-head terminal output from the real migration owner, showing linear probe counts and unchanged migration results for isolated absent-store states.

Evidence

What I checked:

Likely related people:

  • steipete: Peter Steinberger authored the current PR head and prior recent session-migration maintenance commits. (role: recent session-migration contributor; confidence: high; commits: 509eb2c53f05, c43166a9208c; files: src/infra/state-migrations.session-store.ts)
  • Colin Johnson: Authored the recent fixed-store owner preservation repair in this migration owner. (role: fixed-store ownership contributor; confidence: medium; commits: f66a2c6a2944; files: src/infra/state-migrations.session-store.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Refresh the branch’s exact-head integration result before merge.

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 (12 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-22T03:18:44.612Z sha c6e4ad1fdf6e59d2a49bbb48c1c0a14251be247b :: needs maintainer review before merge. :: none
  • reviewed 2026-08-22T03:31:18.803Z sha c6e4ad1fdf6e59d2a49bbb48c1c0a14251be247b :: needs maintainer review before merge. :: none
  • reviewed 2026-08-22T04:47:55.644Z sha c6e4ad1fdf6e59d2a49bbb48c1c0a14251be247b :: needs maintainer review before merge. :: none
  • reviewed 2026-08-22T06:07:00.619Z sha c6e4ad1fdf6e59d2a49bbb48c1c0a14251be247b :: needs maintainer review before merge. :: none
  • reviewed 2026-08-23T07:46:41.868Z sha c6e4ad1fdf6e59d2a49bbb48c1c0a14251be247b :: needs real behavior proof before merge. :: [P2] Measure the actual quadratic path in the regression test
  • reviewed 2026-08-23T08:28:38.686Z sha c6e4ad1fdf6e59d2a49bbb48c1c0a14251be247b :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-24T15:04:31.414Z sha 10f5eb341209b18620ab0462e1c36f43535932a4 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-25T18:03:17.351Z sha 509eb2c53f055f75eb1fdeb6cff92de374b4f60d :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 20, 2026
@goutamadwant
goutamadwant force-pushed the fix/session-migration-empty-store-scaling branch from caf039b to c6e4ad1 Compare August 20, 2026 16:40
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 20, 2026
@clawsweeper clawsweeper Bot mentioned this pull request Aug 21, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. proof: sufficient ClawSweeper judged the real behavior proof convincing. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 22, 2026
@steipete
steipete force-pushed the fix/session-migration-empty-store-scaling branch from 10f5eb3 to 509eb2c Compare August 25, 2026 17:53
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 25, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 25, 2026
@steipete
steipete force-pushed the fix/session-migration-empty-store-scaling branch from 509eb2c to faaceab Compare August 25, 2026 20:58
@steipete
steipete merged commit 46e4520 into openclaw:main Aug 25, 2026
250 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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.

[Bug]:

2 participants