Skip to content

fix(gateway): keep concurrent session descriptions responsive - #155471

Merged
steipete merged 7 commits into
mainfrom
codex/perf-session-placement-read-batches-20260922
Sep 22, 2026
Merged

steipete merged 7 commits into
mainfrom
codex/perf-session-placement-read-batches-20260922

Conversation

@steipete

@steipete steipete commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes failed or delayed session descriptions when overlapping cold reads flood the shared placement reader, and avoids repeated reads caused by unrelated session updates.

User Impact

Concurrent descriptions and session-event snapshots reuse placement preparation while retaining current placement, move, and reconciliation facts. A keyed description can complete while an unrelated bulk refresh is held. No schema or configuration migration is required.

The projection now bounds retained ID input before worker capture: at most 128 batches and 256 MiB of conservative encoded-ID weight. This does not bound caller promises, result snapshots, resident rows, complete worker envelopes, or total heap. No production-wide CPU saving or elimination of all Gateway stalls is claimed.

Why This Change Was Made

The existing projection owner runs two physical reads, shares already-covered requests, and coalesces only a compatible FIFO tail up to 256 IDs / 64 KiB of weighted input. A larger individual read retains its atomic snapshot. Capacity counts batches rather than consumers, so hundreds of callers can share work. Reservations remain until physical settlement and the final consumer release. Per-session invalidation avoids discarding results for unrelated changes; exact/resident separation, original ID spelling, private consumption frames, and disposal remain intact.

The benchmark canonicalizes its temporary parent on macOS and disables startup update discovery through supported configuration. Reset/archive fixtures now release gates and join owned work after assertion failures and runner timeouts, without increasing deadlines. Acquired admission leases are released before dependent creation is joined. This preserves the ordinary cleanup semantics from #155751 and #155770 while adding fixture-owned timeout cleanup.

Evidence

  • Original production fails the capacity and unrelated-publication regressions. The new oversized-input regression also fails on unchanged e2e45b5 through worker-overload rejection. The bounded candidate passes 13 tests in two files, covering 160 descriptions with large IDs, retained-batch refusal/recovery, FIFO, disposal, identity and freshness. A first baseline filter matched zero tests; it is explicitly excluded from proof.
  • The repaired reset fixture passes 23/23 tests with retries disabled. Controlled acquired-lease fault injection times out with the old cleanup order and settles with the new order, preserving the injected failure and joining all work. This proves a fixture cleanup defect, not the cause of the original CI failure or a production deadlock.
  • Selected local types, typed lint and guards pass through the retained checks plus the corrected lint and remaining guards. Fresh independent P0–P2 review of the bounded owner and cleanup repair is scoped-clean. The one-line CI prerequisite also has scoped-clean review and all three dead-code scans pass with zero unused exports.
  • Current head 60580787c744eb6d8589a207c66d8efe4b9f35fd incorporates main 814a7e75, including the canonical memory-fixture repair fix(tasks): throttle unchanged attempt activity #155745. All six production/test fixture postimages retain their reviewed bytes; the benchmark retains upstream activity-summary diagnostics. Dependencies were reconciled to the new lockfile. Final composition passes 239 cases across 12 files (five script cases skipped), and the complete selected gate passes in 959.98 seconds. Exact-head main CI is successful. The separate Workflow Sanity scanner-install failure passed its qualified single-job retry on attempt 2. No dependency pin or enforcement rule changed. Native recovery merged the exact reviewed head as a0838d92c34b8dbaa60474ca1bd93defd9a901a6; main ancestry and clean checkout are verified. The one-line advisory-export CI prerequisite had independently reached main before this merge and is not part of its net source change.

All four changed test files passed individually on the current head with one worker and retries disabled. Command wall time includes startup/collection; case time sums rounded reported test durations.

Test file Cases Case time Command wall time
src/gateway/session-row-placement-projection.lifecycle.test.ts 3 0.008 s 19.83 s
src/gateway/session-row-projection.prepared-read.test.ts 10 7.525 s 23.86 s
src/gateway/server.sessions.reset-hooks.test.ts 23 15.578 s 40.18 s
src/gateway/server.sessions.archive-worker-placement.test.ts 24 27.060 s 44.56 s

The two fixture files exceed 30 seconds of command wall time, while their reported case time stays below 30 seconds. They cover real registered session lifecycle, placement persistence and cleanup ownership; helper-only tests would miss those boundaries. These existing suites are retained, with no deadline or retry increase. Successful Linux CI reports the following rounded case-time sums and owning job wall times; it does not emit per-file startup/collection wall time. The reset/archive entries share one job, so its wall time is not additive.

Test file CI case-time sum Owning CI job wall
session-row-placement-projection.lifecycle.test.ts 0.009 s 428 s
session-row-projection.prepared-read.test.ts 5.211 s 455 s
server.sessions.reset-hooks.test.ts 6.281 s 687 s
server.sessions.archive-worker-placement.test.ts 20.411 s Same shared job
Historical stress and unfavorable evidence

Before the final bounded-input and lease-order repairs, 20 standalone repetitions of each reset/archive fixture plus three original ordered 40-file Gateway groups passed: 2,710 test executions with retries disabled. Separate e2e45b5 composition passed 112 cases in nine files. Those runs cover their recorded earlier source, not the final candidate.

The historical built replay used 74c39bf, not the current head: 1,000 sessions, 48 measured/16 warmup turns, 100 updates, 256 history reads and 64 probe rounds. Four task-list probes failed, 59/64 readiness observations were degraded, and all four catalog inventories reported refresh warnings. Sampled loop maxima were 366.5 ms during load and 806.9 ms during warmup, with a 3.130-second maximum probe-start gap. There is no completed matched baseline, so no improvement percentage is claimed.

The earlier unbounded-input review finding is now repaired in this PR; its historical deferred disposition is superseded. Earlier compile-cache/model-publication failures remain unexplained after bounded non-reproduction. A previous native merge attempt stopped in a read-only policy fetch before dispatch. Its outcome and capture remain intact; qualified native recovery completed after current-head review and CI gates passed.

@clawsweeper

clawsweeper Bot commented Sep 22, 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.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime scripts Repository scripts size: L maintainer Maintainer-authored PR labels Sep 22, 2026
@steipete steipete self-assigned this Sep 22, 2026
@steipete
steipete marked this pull request as ready for review September 22, 2026 05:55
@steipete
steipete force-pushed the codex/perf-session-placement-read-batches-20260922 branch 2 times, most recently from 74c39bf to 50ee4d1 Compare September 22, 2026 08:01
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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 22, 2026
@clawsweeper

clawsweeper Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 22, 2026, 4:04 PM ET / 20:04 UTC (Revision 12).

ClawSweeper review

What this changes

The PR shares and bounds concurrent session-placement reads, preserves per-session freshness, and improves benchmark isolation and test cleanup.

Merge readiness

✅ Ready for maintainer review

This remains a useful fix absent from current main. No blocking correctness or security findings remain, and the updated evidence addresses the prior test-cost request.

Priority: P2
Reviewed head: 60580787c744eb6d8589a207c66d8efe4b9f35fd

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful regression coverage, documented validation costs, and no remaining actionable findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The trusted-author exemption applies. Current-head evidence exercises sessions.describe with controlled placement readers and verifies fixture cleanup; the older built replay does not prove final-head performance. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The trusted-author exemption applies. Current-head evidence exercises sessions.describe with controlled placement readers and verifies fixture cleanup; the older built replay does not prove final-head performance. No stored-data contract changes.
Evidence reviewed 8 items Pinned production change: The introduced delta adds bounded admission and FIFO dispatch to the existing placement projection. Reservations survive physical settlement until consumers release them; freshness checks cover publications occurring before consumption.
Still necessary on current main: The placement projection on fetched main is unchanged from the pinned merge base: it still submits independent reads and uses a global invalidation revision. The inspected latest release commit lacks this projection file; no shipped implementation of this branch's repair was established.
Regression coverage: Read the complete prepared-read and new lifecycle suites. They cover concurrent descriptions, oversized IDs, admission refusal and recovery, unrelated invalidation, exact reads during held bulk preparation, post-settlement freshness, disposal, FIFO, and private response frames. Controlled readers are supplemental test evidence, not real transport proof.
Findings None None.
Security None None.

How this fits together

The Gateway prepares session metadata for descriptions and session events using placement facts read by a database worker. This projection coordinates those reads before current session information is presented to authorized clients.

flowchart TD
  A[Session descriptions and events] --> B[Placement preparation]
  B --> C[Share or queue bounded reads]
  C --> D[Database worker]
  D --> E[Check session freshness]
  F[Committed session changes] --> E
  E --> G[Authorized session response]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +165, Tests +644, Other +1. Total +810 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 1 201 36 +165
Tests 4 703 59 +644
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 3 4 3 +1
Total 8 908 98 +810

Review metrics

Metric Value Why it matters
Placement admission bounds 2 active reads; 128 retained batches; 256 MiB weighted ID input These limits bound queued input, not result snapshots, caller promises, resident rows, or total heap.
Production and test growth Production +165 net lines; tests +644; tooling +1 Production growth implements scheduling and freshness within the existing owner; tests exercise admission, lifecycle, and cleanup contracts.

Technical review

Best possible solution:

Keep scheduling and freshness in the existing placement projection, with bounded shared reads and synchronous authorized response consumption.

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

Yes, source establishes independent cold reads reaching bounded worker admission and unrelated publications invalidating otherwise usable reads; focused regressions exercise both paths. This read-only review did not execute a current-main reproduction.

Is this the best way to solve the issue?

Yes, the patch extends the existing projection owner, preserves atomic snapshots and private consumption frames, and avoids a competing cache or public configuration surface.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This repairs bounded Gateway responsiveness and read-admission problems without evidence of an urgent production outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool 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 trusted-author exemption applies. Current-head evidence exercises sessions.describe with controlled placement readers and verifies fixture cleanup; the older built replay does not prove final-head performance. No stored-data contract changes.

Evidence

What I checked:

  • Pinned production change: The introduced delta adds bounded admission and FIFO dispatch to the existing placement projection. Reservations survive physical settlement until consumers release them; freshness checks cover publications occurring before consumption. (src/gateway/session-row-placement-projection.ts:48, 60580787c744)
  • Still necessary on current main: The placement projection on fetched main is unchanged from the pinned merge base: it still submits independent reads and uses a global invalidation revision. The inspected latest release commit lacks this projection file; no shipped implementation of this branch's repair was established. (src/gateway/session-row-placement-projection.ts, f0d26603a5c1)
  • Regression coverage: Read the complete prepared-read and new lifecycle suites. They cover concurrent descriptions, oversized IDs, admission refusal and recovery, unrelated invalidation, exact reads during held bulk preparation, post-settlement freshness, disposal, FIFO, and private response frames. Controlled readers are supplemental test evidence, not real transport proof. (src/gateway/session-row-projection.prepared-read.test.ts:129, 60580787c744)
  • Review continuity and measured test cost: The captured body and September 22 follow-up report current-head single-worker command times of 19.83, 23.86, 40.18, and 44.56 seconds, with separate CI case and job timings. The two longer fixture runs are justified by registered lifecycle, persistence, and cleanup boundaries. The latest completed review uses this same head and retains no findings; the historical built replay is explicitly identified as older-source evidence without a matched baseline. (60580787c744)
  • Verified exact-head CI: GitHub reports the linked CI run completed successfully with head_sha equal to the reviewed commit. This review did not execute target code or tests. (60580787c744)
  • Security and storage boundary: The changed owner prepares display facts through the existing read-only database worker. The sessions.describe consumer still authorizes and responds synchronously after preparation; the patch changes no authorization decision, durable format, dependency, credential access, or public plugin API. No Codex dependency contract is involved. (src/gateway/server-methods/sessions-read-by-key.ts:51, 60580787c744)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; 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 (11 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-22T10:13:45.718Z sha cf3dc11 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-22T12:10:51.786Z sha fb1f2a3 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-22T13:04:34.911Z sha fd76f02 :: needs changes before merge. :: none
  • reviewed 2026-09-22T14:35:56.897Z sha 35aa8100f6655f3c58263b329b5d84f1dfc4a9a4 :: needs changes before merge. :: none
  • reviewed 2026-09-22T14:56:39.163Z sha e2e45b5 :: needs changes before merge. :: none
  • reviewed 2026-09-22T15:12:11.361Z sha e2e45b5 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-22T19:30:53.844Z sha 6058078 :: needs changes before merge. :: none
  • reviewed 2026-09-22T19:58:30.905Z sha 6058078 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the codex/perf-session-placement-read-batches-20260922 branch 3 times, most recently from 35aa810 to e2e45b5 Compare September 22, 2026 14:42
@steipete
steipete force-pushed the codex/perf-session-placement-read-batches-20260922 branch from e2e45b5 to 6058078 Compare September 22, 2026 19:23
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Sep 22, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

The remaining test-cost request is addressed in the PR's Evidence section. All four changed test files passed individually on current head 60580787c744eb6d8589a207c66d8efe4b9f35fd with one worker and retries disabled. The body now includes each local command wall time, separate case-time sums, exact successful CI job links/times, and the reason the two real lifecycle fixture commands exceed 30 seconds while their test-case sums remain below it. The complete selected local gate and exact-head main CI also pass. No source changed after this review; the update adds the requested evidence.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@clawsweeper

clawsweeper Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete
steipete merged commit a0838d9 into main Sep 22, 2026
226 of 227 checks passed
@steipete
steipete deleted the codex/perf-session-placement-read-batches-20260922 branch September 22, 2026 20:05
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit to ycmjbot-bot/openclaw that referenced this pull request Sep 22, 2026
* commit 'ba4bc10ee5283f37813593da158cd3146f4cf2bf': (53 commits)
  fix(tests): drain persistence deliveries before fixture cleanup (openclaw#155934)
  fix(tests): drain Gateway abort deliveries before teardown (openclaw#155913)
  fix(test): give the bundled MCP tarball checks time on Windows runners (openclaw#155931)
  improve: explain where session catalog requests spend time (openclaw#155786)
  fix(test): recognize deletion cancellation in SQLite lifecycle proof
  test(gateway): join request lifetimes before fixture teardown
  test(codex): assert late-abort interrupt identity (openclaw#154853)
  fix(cron): avoid blocking Gateway during retention discovery (openclaw#155414)
  fix(tests): drain subagent deliveries before teardown (openclaw#155910)
  fix(ci): recover Security Review when diff data settles slowly (openclaw#155921)
  fix(ci): recover Security Review after checkout failures (openclaw#155919)
  fix(infra): retain SQLite reader modules in PR wrapper inventory
  ci: pack test jobs and add opt-in Spot cron routing (openclaw#155403)
  fix(gateway): retain approval authority across storage waits (openclaw#150237)
  test(media): isolate base64 memory accounting per VM (openclaw#155638)
  fix(gateway): keep concurrent session descriptions responsive (openclaw#155471)
  fix(test): await Talk storage cleanup before removing fixtures
  fix(tests): settle subagent steer work before teardown (openclaw#155888)
  test(ci): respect retained command worker caps (openclaw#155735)
  test(ui): synchronize release fixtures with owned lifetimes
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 23, 2026
…aw#155471)

* fix(gateway): keep concurrent session descriptions responsive

* fix(bench): use canonical gateway fixture paths

* fix(bench): disable startup update checks through config

* test(gateway): settle rollover hook work on assertion failure

* test(gateway): join gated requests before fixture teardown

* fix(gateway): bound retained placement read input

* fix(ci): keep advisory shard limit private
@roboclaw-bot roboclaw-bot mentioned this pull request Sep 24, 2026
2 of 8 tasks
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. scripts Repository scripts size: XL 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