Skip to content

fix: reduce Gateway stalls when opening session details - #149858

Merged
steipete merged 1 commit into
mainfrom
codex/perf-sessions-describe-async
Sep 16, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf-sessions-describe-async

Conversation

@steipete

@steipete steipete commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Related: #149466

What Problem This Solves

Opening session details after the subagent registry cache expires parses retained run metadata on the Gateway event loop, delaying unrelated work.

User Impact

Session detail reads leave more main-thread CPU available while preserving the same session, child, swarm, and visibility results. No configuration or migration is required. Cold requests incur worker handoff overhead; the shared worker also has startup and memory costs when it has not already been started.

Why This Change Was Made

Use the existing asynchronous full-registry cache owner already used by sessions.list, then resolve the current session and permissions after the metadata reads finish. This keeps one cache and lifecycle owner and preserves the full registry projection; it does not change SQL, schemas, cache expiry, or database repair behavior.

Evidence

The registered-handler regressions fail on the original implementation because it completes without dispatching the cold read to a worker. They pass after the change and verify replacement and draft visibility while that read is pending, canonical child links, and retained deleted-collector totals.

After incorporating the row-materialization refactor in #149771, all 72 focused Gateway, row-materialization and registry lifecycle tests pass. Fresh formatting and independent P0–P2 review pass. Exact-head CI passes for rebased commit 9e9d820ed629. The original head also passed the full selected check:changed gate, including production and core-test types, typed lint, and database/import guards.

A fresh synthetic Node 24.20.0 comparison on base d0f4dc76b10f used four A/B/B/A processes, 1,564 retained runs including 162 private-parent runs, current-source compiled workers, and 560 measured requests plus four separate first-request observations. Every complete response matched, with independent child/swarm/private-field assertions. Source and compiled inputs remained unchanged and all processes settled naturally. Ranges below are per-call means for each round, not a pooled estimate:

Cache condition Main-thread CPU before Main-thread CPU after
Cold 22.9–24.9 ms 4.8–7.7 ms
Warm 1.98–2.35 ms 2.03–2.52 ms
Five sequential calls, first cold 5.63–5.94 ms 1.94–2.67 ms

The tradeoff is explicit: cold request wall time increased from 23.0–25.0 ms to 27.1–32.0 ms, and whole-process CPU round means were 31.6–48.3 ms before and 31.9–64.1 ms after. Separate first-request observations were 338–339 ms before and 671–686 ms after; peak process RSS was 1,019–1,042 MiB before and 1,214–1,229 MiB after. Those observations include the source-handler fixture and worker startup and are not installed-Gateway memory or latency measurements. The existing worker is reused for the same database and maintenance scope; startup is not paid on each describe or cache miss. This demonstrates moving CPU off the event loop, not reducing total CPU or proving production latency.

The maintainer risk assessment accepts this bounded worker tradeoff and records the remaining deployment-verification gap.

@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review September 16, 2026 07:40
@steipete steipete self-assigned this Sep 16, 2026
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Sep 16, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Sep 16, 2026
@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 16, 2026, 4:32 AM ET / 08:32 UTC (Revision 3).

ClawSweeper review

What this changes

Session detail requests reuse the existing background registry reader, with regression coverage for session replacement and visibility changes during the read.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused fix absent from current main. No actionable correctness finding remains, and the maintainer’s explicit acceptance resolves the previous review’s worker-cost decision blocker.

Priority: P2
Reviewed head: 9e9d820ed629a9643ff41b5d35b6725915fb18c8

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused implementation with meaningful pending-read regressions and bounded benchmark evidence; the prior tradeoff decision is resolved.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The external-contributor proof gate does not apply to this maintainer PR. Its reported source-handler comparison exercises compiled registry workers and preserves complete responses while reducing main-thread CPU; installed-Gateway performance remains outside that evidence and was accepted as follow-up.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The external-contributor proof gate does not apply to this maintainer PR. Its reported source-handler comparison exercises compiled registry workers and preserves complete responses while reducing main-thread CPU; installed-Gateway performance remains outside that evidence and was accepted as follow-up.
Evidence reviewed 8 items Introduced change and merge result: The pinned merge-base-to-head diff adds the shared asynchronous registry read and admission checks. The verified test merge has the pinned base and original head as its parents; its delta contains only the same production and test changes.
Existing cache and lifecycle owner: The asynchronous reader retains one shared fill, overlays current in-memory records and named changes, fences retired database ownership, and shares read-failure fallback among waiting callers. Session lists already consume this owner.
Visibility remains current: Runtime configuration, the session entry, and sharing permissions are resolved after both awaited metadata reads. The added registered-handler cases pause actual worker dispatch and verify replacement metadata, rejection after a foreign session becomes private, child links, and retained collector totals.
Findings None None.
Security None None.

How this fits together

The Gateway combines stored session metadata with subagent activity to answer session detail requests. Moving cold registry reads to the shared worker leaves more Gateway main-thread capacity for other requests.

flowchart TD
 A[Session detail request] --> B[Read model metadata]
 B --> C[Shared registry cache]
 C -->|Cold cache| D[Background database reader]
 D --> E[Check current session and visibility]
 C -->|Warm cache| E
 E --> F[Build session detail response]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +10, Tests +107. Total +117 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 12 2 +10
Tests 1 139 32 +107
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 151 34 +117

Review metrics

Metric Value Why it matters
Reported cold-read CPU Main thread: 22.9–24.9 ms before; 4.8–7.7 ms after The synthetic comparison supports CPU offload; cold wall time increased, so it does not establish lower request latency or total CPU.

Technical review

Best possible solution:

Use the existing registry worker and cache for session descriptions while preserving current visibility checks and unchanged response semantics.

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

Yes, source establishes that a cold session-description request on current main reaches synchronous registry loading; the supplied comparison reports the corresponding main-thread CPU cost. This review did not execute that path.

Is this the best way to solve the issue?

Yes. Reusing the existing asynchronous registry owner avoids a competing cache and preserves post-await session authorization; the disclosed worker-cost tradeoff has been explicitly accepted.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 5e27c4e4302e.

Labels

Label justifications:

  • P2: This addresses bounded Gateway responsiveness costs when session details encounter a cold registry cache.
  • 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: The external-contributor proof gate does not apply to this maintainer PR. Its reported source-handler comparison exercises compiled registry workers and preserves complete responses while reducing main-thread CPU; installed-Gateway performance remains outside that evidence and was accepted as follow-up.

Evidence

What I checked:

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

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-09-16T07:46:28.990Z sha 28159903b6c4b291ede90ee9d223f92082d89b28 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-16T08:23:05.103Z sha 9e9d820 :: blocked before merge. :: none

@steipete
steipete force-pushed the codex/perf-sessions-describe-async branch from 2815990 to 9e9d820 Compare September 16, 2026 08:16
@steipete

Copy link
Copy Markdown
Contributor Author

Maintainer assessment for 9e9d820ed629a9643ff41b5d35b6725915fb18c8: accept the bounded CPU-offload tradeoff raised in Revision 2. The implementation already follows the review's proposed mitigation: reuse the shared registry worker/cache owner used by sessions.list, then resolve the current session and visibility after the read. Worker reuse, cold-fill coalescing, admission fences and existing read-failure behavior remain owned by that same implementation.

The fresh comparison on the row-materialization base shows cold main-thread CPU falling from 22.9–24.9 ms to 4.8–7.7 ms, with the disclosed increase in cold wall time, first-handler startup time and peak process RSS. All 72 focused integration tests pass, all 564 complete benchmark replies match, and independent source review and benchmark audit pass. This is sufficient evidence for this narrow main-thread offload once required exact-head CI passes. Installed-Gateway latency, steady retained memory and direct event-loop delay remain unmeasured; deployment verification is a follow-up, and this PR makes no production latency or total-CPU improvement claim.

@steipete
steipete merged commit 6cffe6e into main Sep 16, 2026
204 of 205 checks passed
@steipete
steipete deleted the codex/perf-sessions-describe-async branch September 16, 2026 08:39
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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