fix(gateway): reuse subagent registry snapshot in session listing#75013
fix(gateway): reuse subagent registry snapshot in session listing#75013anyech wants to merge 0 commit intoopenclaw:mainfrom
Conversation
|
Codex review: needs maintainer review before merge. What this changes: This PR adds a request-scoped subagent registry read context and threads it through Gateway session listing and row construction, with focused agent and Gateway tests for parity and reduced registry reads. Maintainer follow-up before merge: This is an open implementation PR with no concrete repair finding from this review; the remaining action is maintainer review plus completed CI, not an automated replacement or fix PR. Security review: Security review cleared: The diff only changes TypeScript registry/session-list read paths and tests; it does not add dependencies, scripts, CI permissions, artifact downloads, or secret handling. Review detailsBest possible solution: Land a request-scoped registry read context if CI remains green and maintainers are comfortable with the snapshot boundary; keep it scoped to one sessions.list/read operation and avoid hoisting it into global cache state. Do we have a high-confidence way to reproduce the issue? Yes. The current-main reproduction path is code-level: sessions.list spawnedBy filtering and row enrichment call registry snapshot-backed helpers repeatedly, and the PR adds a focused fs.statSync-based regression test for the repeated disk snapshot case. Is this the best way to solve the issue? Yes, likely. A per-request context is the narrowest maintainable optimization because it avoids global caching or persistence changes while preserving the existing direct row fallback behavior. What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 099037cca6f5. |
2bf9f98 to
9cb71f7
Compare
|
Restored the patch in replacement draft PR #75019 after the fork branch was accidentally pushed to the current base during CI repair and GitHub auto-closed this PR. The replacement keeps the same change set and credits this PR as the source thread. |
Summary
This PR adds a request-scoped subagent registry read context for Gateway session listing.
It reduces repeated registry snapshot/stat/index/scan work during
sessions.listrow construction by building one per-request read context and reusing it for:spawnedByfilteringThe context is deliberately request-scoped and is not cached globally or persisted.
Relationship to #74970 / slice 1
#74970 adds regression coverage for the slice-1 behavior now present on
main: safesessions.listpaths filter/sort/limit entries before expensive row enrichment.This PR is slice 2. Slice 1 avoids enriching rows that will be dropped. Slice 2 reduces repeated subagent-registry snapshot/stat/scan work for rows that still need enrichment, including selected rows and legacy
spawnedBy/ subagent child-resolution paths.Future slice 3 work, if needed, should stay separate and focus on transcript fallback caching and/or session-store metadata dedupe.
Why
Before this change, session listing could recreate subagent registry read snapshots and scan registry state repeatedly while filtering and enriching rows. This is especially visible in
spawnedByand child-session enrichment paths.This PR keeps the same request-level behavior but shares one point-in-time registry read context through the relevant call chain.
Validation
All validation used isolated source checkout and synthetic/copied lab data only. No live Gateway, live config, installed dist, or live session store was modified or benchmarked.
Local checks:
OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway.config.ts src/gateway/session-utils.subagent.test.ts— 24 tests passedOPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs run --config test/vitest/vitest.unit-fast.config.ts src/agents/subagent-registry-read-context.test.ts src/agents/subagent-registry-queries.test.ts— 23 tests passednode scripts/run-oxlint.mjs --tsconfig tsconfig.oxlint.core.json src/agents/subagent-registry-read.ts src/agents/subagent-registry-read-context.test.ts src/gateway/session-utils.ts src/gateway/session-utils.subagent.test.ts— passedcorepack pnpm tsgo:core:test— passedcorepack pnpm build— passedSynthetic benchmark (
240entries,80selected rows):The primary claim is reduced registry snapshot/stat/index/scan work, not guaranteed cold physical disk-I/O reduction. File contents may already be served by OS/runtime caching depending on environment.
Notes / caveats
sessions.listrequest, that request sees the snapshot captured when the context was created. This avoids inconsistent repeated snapshots within one request and matches the intended read-boundary tradeoff.