Skip to content

fix(gateway): keep sessions.list responsive with many configured agents - #124453

Merged
steipete merged 1 commit into
mainfrom
fix/session-path-projection
Aug 16, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/session-path-projection

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Related: #124384

What Problem This Solves

Fixes an issue where operators listing sessions across many configured agents could still see the Gateway saturate CPU and memory and time out, even after #124384 removed broad directory enumeration. On Molty, the exact #124384 merge remained at 149.6% CPU and 2.95 GB RSS, timed out over HTTP, and made 16,023 failed readlink calls in 8 seconds because every configured sessions.list cache miss rebuilt physical target identities.

This PR intentionally excludes #124372. That change addresses a separate path, is not bundled here, and is not a replacement for this cache-ownership repair.

Why This Change Was Made

Configured Gateway listings now reuse one bounded prepared target snapshot keyed by the exact config identity, a durable-registry generation token, and the incognito membership generation. The completed list-cache fence carries both lifecycle generations, so registry or incognito membership changes rebuild the snapshot and invalidate completed results without restoring request-time filesystem discovery.

The prepared physical target set is also the authoritative sharing lookup set. This collapses requested-agent symlink aliases to one row, avoids redundant requested-agent prewarm dedupe when no incognito database is open, and keeps path identity internally consistent by resolving the real path before reading its stat identity. Generic CLI and Doctor dedupe remains fresh per call.

User Impact

Operators with many configured agents should get responsive session listings without repeated matcher, stat, or symlink-resolution work on each distinct list request. Registry and incognito topology changes remain visible immediately through explicit generation fences, while fixed/shared stores, lineage, startup prewarm, and incognito behavior are retained.

Live Molty validation of this exact PR head is still pending and is required before merge.

Evidence

  • 29-target scaling regression: the first request performs matcher/stat/realpath work 1/29/29; a second distinct request performs 0/0/0/0/0 matcher/stat/lstat/readlink/realpath work.
  • Registry and incognito membership mutations rebuild prepared targets and fence previously completed list results.
  • Requested-agent symlink aliases produce one authoritative row; fault-injected symlink retarget tests prove realpath/stat identity consistency.
  • 227 focused tests passed, 4 skipped. Follow-up verification after independent findings passed alias/scaling 5/5, 3 targeted identity/token tests, and 124 lifecycle/ownership tests across 8 files.
  • Trusted local pnpm check:changed passed every selected core and coreTests lane. Crabbox/Blacksmith CLI was unavailable, so the repository-authorized trusted-source fallback ran locally; this is not presented as remote proof.
  • Formatting, lint, import-cycle, and git diff --check gates are clean. Fresh structured autoreview reported no accepted/actionable findings at 0.97 confidence.
  • Production LOC: +200/-76 (net +124). Tests: +383/-2 (net +381). The production growth owns the required registry/incognito lifecycle generations, single-slot prepared target snapshot, and completed-list fencing that replace request-time filesystem work.
  • Pending gates: exact-head pull_request CI attachment/completion and Molty live validation of this exact head. Do not merge until both are green.

@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 16, 2026 06:28
@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Aug 16, 2026
@steipete steipete self-assigned this Aug 16, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: L maintainer Maintainer-authored PR labels Aug 16, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready evidence for exact head 523d8e545ae4b8513ad34f1507c88bae7f606db8:

  • Native review artifacts validate with READY FOR /prepare-pr, issueValidation.status=valid, and no findings.
  • Exact-head CI run 31931501122 completed successfully.
  • Fresh autoreview is clean at 0.98 confidence. The full local changed gate for core/coreTests is green.
  • Focused proof is green: 227 passed / 4 skipped, post-review alias/scaling 5/5, identity/token targeted 3, and lifecycle/ownership 124 tests.
  • Live exact-head Molty proof after 7m39 passed the intended identity-owner fix: a 2-second path sample recorded 0 readlink calls, HTTP recovered from the initial 1.16s response to 14-20ms, and the exact CLI/source root was confirmed. The fix(gateway): avoid repeated session root scans in configured lists #124384 baseline recorded 16,023 failed readlink calls in 8 seconds and HTTP timeout.

The root cause is repeated physical target identity construction on configured-only misses. The fix is the owner-boundary design: one bounded prepared snapshot keyed by config identity, registry Symbol token, and incognito generation; registry/incognito lifecycle fences cover the completed list cache; sharing receives the authoritative prepared targets; the requested alias row is retained; redundant prewarm dedupe is removed; and existing target identity uses realpath before stat. Generic CLI/Doctor discovery remains fresh.

Production LOC is +200/-76 (net +124); tests are +383/-2 (net +381). The production growth is the explicit lifecycle token/generation/fence and bounded snapshot. There is no config, schema, protocol, TTL, polling, or fallback surface.

Scope is intentionally narrow: this proves the repeated target identity/readlink preparation and associated HTTP-starvation repair, not full Molty recovery. The overall incident remains DEGRADED from a separate stat-heavy workload: CPU 148.3%, RSS 2.77GB, RPC/health/channels/cron handshakes timing out, and an 8-second sample with 1,388 readlink calls (1,352 errors) plus 22,300 statx calls. That placement/session sweep remains a named follow-up and open proof gap.

@steipete
steipete merged commit 063ce57 into main Aug 16, 2026
248 checks passed
@steipete
steipete deleted the fix/session-path-projection branch August 16, 2026 06:59
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

SemonCat pushed a commit to SemonCat/openclaw that referenced this pull request Aug 16, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 17, 2026
steipete added a commit that referenced this pull request Oct 12, 2026
## What Problem This Solves

The configured-only 29-store projection test changes the process state-directory override while its suite retains a live Gateway projection. Both contexts compete for the process-held store registry memo, making filesystem-probe assertions depend on unrelated background work.

## User Impact

This is a test-fixture correction with no production behavior change. It preserves all 29 seeded stores, the warm preparation request, filesystem assertions and cleanup. No production checks, SQL, security, schema, service-lifecycle or SDK behavior changes; no numeric T1 or SQL statement/request improvement is claimed.

## Why This Change Was Made

Move the case into the existing handler-only projection suite, which exercises the same list handlers without a live Gateway. Preserve the independently landed runtime-config setup from #169714. After setting both multi-store overrides, explicitly publish the completed fixture configuration: `createSessionStoreDir` has already installed an earlier snapshot, so merely reading it does not publish the new store template and agent entries. The two-file diff is +72/−75 and contains the reviewed fixture move plus its snapshot-publication correction.

The test originated in #124453; the first commit exposing the retained-projection interaction remains unestablished. Two Codex review rounds completed with no actionable findings, covering the fixture move and snapshot adaptation.

## Evidence

Exact head `443698a6a37b0e425c4bf305100140522c5a3843` passed [CI run 38313773328](https://github.com/openclaw/openclaw/actions/runs/38313773328): 20 successful jobs and 29 skipped jobs, including a successful CI gate. Both projection cases passed: 56.56 s Vitest duration and 58.73 s test-runner wall time; the conventional-state-directory case took 4.984 s and the configured-only case 2.919 s. Local runtime was not repeated.

The other changed file, `src/gateway/server.sessions.store-paths.test.ts`, was not selected by that PR run. Its six cases passed in [run 38311910220, job 115019808666](https://github.com/openclaw/openclaw/actions/runs/38311910220/job/115019808666) on `0c4b38b77adfcd32fc25a18f5d0ed7fb97c2faae`, using the exact same fixture blob `b3cdb024f1f3affcf1a811d8e341d8002942d97f`. That includes both disposal outcomes and configured-only lineage coverage. Summed case times were 14.531 s; no file wall time is available. This is reused composition evidence, not an exact-PR-head sibling run; the broader job failed in three other files.

The exact-head baseline ratchets, source contracts, additional boundaries, selected test types and lint jobs passed. Normal commit hooks and diff checks passed. Build artifacts and the published-driver update cell were not selected for this test-only change.

Knip evidence is reused narrowly from [run 38311910220](https://github.com/openclaw/openclaw/actions/runs/38311910220/job/115019807997): both changed test blobs, package/lock/workspace, all-exports configuration and runner match; the primary Knip configuration differs only in a comment. That actual scan reported only three unrelated team-scale exports, all already removed on this branch. This is scoped evidence for this diff, not a claim that the earlier whole-tree scan passed. The same composition's actual Madge check reported zero cycles; this change adds no production import edge. This green PR run does not establish green scheduled CI on main.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
…#170284)

## What Problem This Solves

The configured-only 29-store projection test changes the process state-directory override while its suite retains a live Gateway projection. Both contexts compete for the process-held store registry memo, making filesystem-probe assertions depend on unrelated background work.

## User Impact

This is a test-fixture correction with no production behavior change. It preserves all 29 seeded stores, the warm preparation request, filesystem assertions and cleanup. No production checks, SQL, security, schema, service-lifecycle or SDK behavior changes; no numeric T1 or SQL statement/request improvement is claimed.

## Why This Change Was Made

Move the case into the existing handler-only projection suite, which exercises the same list handlers without a live Gateway. Preserve the independently landed runtime-config setup from openclaw#169714. After setting both multi-store overrides, explicitly publish the completed fixture configuration: `createSessionStoreDir` has already installed an earlier snapshot, so merely reading it does not publish the new store template and agent entries. The two-file diff is +72/−75 and contains the reviewed fixture move plus its snapshot-publication correction.

The test originated in openclaw#124453; the first commit exposing the retained-projection interaction remains unestablished. Two Codex review rounds completed with no actionable findings, covering the fixture move and snapshot adaptation.

## Evidence

Exact head `443698a6a37b0e425c4bf305100140522c5a3843` passed [CI run 38313773328](https://github.com/openclaw/openclaw/actions/runs/38313773328): 20 successful jobs and 29 skipped jobs, including a successful CI gate. Both projection cases passed: 56.56 s Vitest duration and 58.73 s test-runner wall time; the conventional-state-directory case took 4.984 s and the configured-only case 2.919 s. Local runtime was not repeated.

The other changed file, `src/gateway/server.sessions.store-paths.test.ts`, was not selected by that PR run. Its six cases passed in [run 38311910220, job 115019808666](https://github.com/openclaw/openclaw/actions/runs/38311910220/job/115019808666) on `0c4b38b77adfcd32fc25a18f5d0ed7fb97c2faae`, using the exact same fixture blob `b3cdb024f1f3affcf1a811d8e341d8002942d97f`. That includes both disposal outcomes and configured-only lineage coverage. Summed case times were 14.531 s; no file wall time is available. This is reused composition evidence, not an exact-PR-head sibling run; the broader job failed in three other files.

The exact-head baseline ratchets, source contracts, additional boundaries, selected test types and lint jobs passed. Normal commit hooks and diff checks passed. Build artifacts and the published-driver update cell were not selected for this test-only change.

Knip evidence is reused narrowly from [run 38311910220](https://github.com/openclaw/openclaw/actions/runs/38311910220/job/115019807997): both changed test blobs, package/lock/workspace, all-exports configuration and runner match; the primary Knip configuration differs only in a comment. That actual scan reported only three unrelated team-scale exports, all already removed on this branch. This is scoped evidence for this diff, not a claim that the earlier whole-tree scan passed. The same composition's actual Madge check reported zero cycles; this change adds no production import edge. This green PR run does not establish green scheduled CI on main.
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 size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant