Skip to content

fix(gateway): stop session refresh loops and reuse run indexes - #156268

Merged
steipete merged 2 commits into
mainfrom
codex/team-r4-run-index-20260923
Sep 23, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/team-r4-run-index-20260923

Conversation

@steipete

@steipete steipete commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Persisting an already-absent subagent run can leave session refreshes spinning over an empty batch. Unrelated row updates also rebuild the complete active-run index and active-ancestor membership when the registries have not changed.

User Impact

Session refreshes finish after an already-absent subagent publication and avoid repeated projection work while keeping run status, model, ownership, and time-sensitive facts current.

Why This Change Was Made

The prepared-context fast path now checks the published subagent revision as well as the row epoch and snapshot, allowing a no-op persistence publication to settle. The existing run-registry version controls index reuse inside each session-row projection. Ancestor membership is reused only while both the run index and subagent topology are unchanged. Each projection and the public index builder still own independent maps, and subagent clock views continue to refresh.

Evidence

The owner and session-projection suites passed 108 tests on Linux with Node 24.19.0. A new regression starts with real persisted-registry publication and waits for ensureMaterialized; it fails against the original guard. The final 16-case persistence/projection file passed, including the new regression in 2.14 s; its isolated command took 55.69 s. This real persistence and drain boundary is needed to reproduce the starvation loop. The additional test-only changed gate and independent P2 review also passed. The four new cases cover unrelated row epochs, model and identity changes, queue/owner/lifecycle/clear transitions, stale queue callbacks, map isolation, and subagent expiry. Fresh independent review through P2 found no actionable issues.

check:changed passed, including production types, all 25 core test-type partitions, lint, and guards. The new test file passed in 22 ms of test time; the isolated pnpm test src/gateway/session-row-projection-context.test.ts --maxWorkers=1 command took 26.75 s including 12.95 s of shared worker preparation.

A matched Linux ABBA replay exercised the registered sessions.list handler over 513 stored rows, 512 active runs, and 511 subagent links. Each CPU batch included 16 unrelated stored-row updates and list requests; each variant has six measured batches. V8 allocation sampling includes collected objects.

Workload Baseline CPU / 16 calls Candidate CPU / 16 calls Sampled allocation / call
Stable active runs 115.52 ms 91.12 ms (-21.1%) 6.10 → 5.62 MB (-7.8%)
Model changes on every update 118.62 ms 120.87 ms (+1.9%) 6.15 → 6.18 MB (+0.5%)

Stable-run index builds fell from 48 to zero per 48 measured calls; the genuine-change control retained all 48 builds. Normalized response digests match within both workloads; only the independently identified temporary store path in the response envelope was normalized. Superseded captured indexes were collected after run changes, while steady reuse retained the current index. RSS was higher in candidate samples, so no retained-heap or RSS saving is claimed.

These are synthetic session-list workload results, not aggregate production CPU measurements. Proof used Node 24.19.0 on one Linux x64 Testbox, with independent frozen dependency installs and verified source/log hashes. Testbox run.

The initial hosted merge ref hit the unrelated UI route-ownership type error fixed upstream in 813a10e7. This branch includes that repair.

@clawsweeper

clawsweeper Bot commented Sep 23, 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 size: M labels Sep 23, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Sep 23, 2026
@clawsweeper

clawsweeper Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 23, 2026, 2:49 AM ET / 06:49 UTC.

ClawSweeper review

What this changes

Reuse unchanged active-run indexes and subagent ancestor membership during Gateway session refreshes, with regression coverage for invalidation and time-sensitive reads.

Merge readiness

✅ Ready for maintainer review

Keep open: the optimization remains useful on current main, and the introduced changes have no actionable correctness findings. The supplied production-handler replay supports the performance improvement while preserving response content.

Priority: P2
Reviewed head: 05983f10c2b4aa0be24943937bbec9cb867bdf8a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with meaningful invalidation coverage and relevant before/after production-path measurements.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied Linux Testbox replay exercises the registered sessions.list handler and changed projection owner, reporting lower stable-workload CPU, matching responses, and rebuilds under genuine model changes. Raw linked logs were inaccessible to this reviewer; no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied Linux Testbox replay exercises the registered sessions.list handler and changed projection owner, reporting lower stable-workload CPU, matching responses, and rebuilds under genuine model changes. Raw linked logs were inaccessible to this reviewer; no stored-data contract changes.
Evidence reviewed 8 items Introduced change: Reviewed the pinned merge-base-to-head patch. Its production changes reuse projection-local indexes, check both registry revisions during preparation, and expose the existing run-index version reader.
Invalidation and clock boundary: The registry canonicalizes projection inputs and increments its version for relevant registration, model, capacity-wait, lifecycle, release, and cleanup changes. Ancestor reuse requires unchanged run-index and topology identities; subagent atTime views still recreate clock-sensitive query caches.
Current-main necessity: The three touched production files are unchanged between the pinned merge base and fetched main. Main therefore still rebuilds the active-run index during refresh preparation; it does not contain this reuse optimization.
Findings None None.
Security None None.

How this fits together

The Gateway combines stored session rows with live run and subagent facts to produce session lists and updates. This change avoids rebuilding unchanged display indexes while retaining registry-owned invalidation.

flowchart TD
  A[Session refresh] --> B[Session row projection]
  C[Run registry version] --> D{Facts changed?}
  E[Subagent topology] --> D
  B --> D
  D -->|No| F[Reuse display indexes]
  D -->|Yes| G[Rebuild display indexes]
  F --> H[Current session rows]
  G --> H
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +23, Tests +192. Total +215 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 3 37 14 +23
Tests 1 192 0 +192
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 229 14 +215

Review metrics

Metric Value Why it matters
Reported session-list CPU Stable runs −21.1%; changing-model control +1.9% The paired workloads show that the benefit comes from unchanged-fact reuse, without claiming an improvement when rebuilding is necessary.

Technical review

Best possible solution:

Keep display-index reuse local to each projection, driven by registry-owned versions while refreshing clock-sensitive subagent views.

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

Not applicable as a functional bug reproduction: this is a performance optimization. Current source confirms the repeated work, and the supplied registered-handler replay measures its cost.

Is this the best way to solve the issue?

Yes. Reusing facts under the existing registry version is a narrow solution that preserves independent indexes and avoids a competing cache owner.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded Gateway performance improvement with measured session-refresh savings and no demonstrated urgent user-facing failure.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The supplied Linux Testbox replay exercises the registered sessions.list handler and changed projection owner, reporting lower stable-workload CPU, matching responses, and rebuilds under genuine model changes. Raw linked logs were inaccessible to this reviewer; no stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The supplied Linux Testbox replay exercises the registered sessions.list handler and changed projection owner, reporting lower stable-workload CPU, matching responses, and rebuilds under genuine model changes. Raw linked logs were inaccessible to this reviewer; no stored-data contract changes.

Label justifications:

  • P2: This is a bounded Gateway performance improvement with measured session-refresh savings and no demonstrated urgent user-facing failure.
  • 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. Sufficient (live_output): The supplied Linux Testbox replay exercises the registered sessions.list handler and changed projection owner, reporting lower stable-workload CPU, matching responses, and rebuilds under genuine model changes. Raw linked logs were inaccessible to this reviewer; no stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied Linux Testbox replay exercises the registered sessions.list handler and changed projection owner, reporting lower stable-workload CPU, matching responses, and rebuilds under genuine model changes. Raw linked logs were inaccessible to this reviewer; no stored-data contract changes.

Evidence

What I checked:

  • Introduced change: Reviewed the pinned merge-base-to-head patch. Its production changes reuse projection-local indexes, check both registry revisions during preparation, and expose the existing run-index version reader. (src/gateway/session-row-projection-context.ts:36, 05983f10c2b4)
  • Invalidation and clock boundary: The registry canonicalizes projection inputs and increments its version for relevant registration, model, capacity-wait, lifecycle, release, and cleanup changes. Ancestor reuse requires unchanged run-index and topology identities; subagent atTime views still recreate clock-sensitive query caches. (src/gateway/session-row-projection-context.ts:56, 05983f10c2b4)
  • Current-main necessity: The three touched production files are unchanged between the pinned merge base and fetched main. Main therefore still rebuilds the active-run index during refresh preparation; it does not contain this reuse optimization. (src/gateway/session-row-projection-context.ts:50, 2e9a2eceb11b)
  • Latest-release comparison: The v2026.9.5 source also calls buildProjectedAgentRunIndex during each new preparation epoch, so the latest supplied release does not already implement the proposed reuse. (src/gateway/session-row-projection-context.ts:47, ec9c1a13db89)
  • Production-path performance evidence: The captured PR body, context sourceRevision eea8d3876585ff348cd960b51070a46baa6426894d0f25e0631378ae1f56a882, reports a Linux Node 24.19.0 ABBA replay through the registered sessions.list handler with 513 stored rows, 512 active runs, and 511 subagent links. Stable-run CPU fell 21.1%, sampled allocation fell 7.8%, response digests matched, and the changing-model control retained index rebuilds. The body explicitly disclaims production-wide CPU and RSS savings. (05983f10c2b4)
  • Proof inspection limits: The linked Testbox run exists and its shell job ended as cancelled. No artifacts were listed. Fetching job logs was blocked by the review host's storage-domain allowlist, so raw benchmark logs were not independently inspected; this does not contradict the supplied replay results.

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.

@steipete steipete changed the title perf(gateway): reuse active-run facts during session refreshes fix(gateway): stop session refresh loops and reuse run indexes Sep 23, 2026
@steipete
steipete marked this pull request as ready for review September 23, 2026 06:56
Reuse the registry-owned version within each session-row projection, keeping independent index builders and current subagent clock views. Avoid rebuilding run and ancestor facts for unrelated row updates.
@steipete
steipete force-pushed the codex/team-r4-run-index-20260923 branch from fbbb4e9 to 4a92ee5 Compare September 23, 2026 07:26
@steipete
steipete merged commit 383730e into main Sep 23, 2026
202 of 203 checks passed
@steipete
steipete deleted the codex/team-r4-run-index-20260923 branch September 23, 2026 08:47
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 24, 2026
…law#156268)

* perf(gateway): reuse active-run facts during session refreshes

Reuse the registry-owned version within each session-row projection, keeping independent index builders and current subagent clock views. Avoid rebuilding run and ancestor facts for unrelated row updates.

* test(gateway): cover subagent registry refresh settling
@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 P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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