Skip to content

perf(gateway): refresh only affected session row owners - #185954

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-session-row-consume-main-thread-slices-20261027
Oct 27, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-session-row-consume-main-thread-slices-20261027

Conversation

@steipete

@steipete steipete commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A keyed subagent update advances a global presentation revision, so the next read rebuilds child links and swarm summaries for unrelated resident session rows. A large session list pays for every parent on the page even when only one collector changed.

User Impact

Session lists and session-event consumers reuse unaffected row facts. Session-row stall diagnostics retain their actual session-rows:select / session-rows:consume operation instead of attributing the whole callback to agent-roster. Wire payloads, ordering, sharing checks, and persistence are unchanged.

Why This Change Was Made

The resident registry index already records changed child keys. It now also records old/new swarm requesters. The row context dirties only those requester rows and the old/new parents when a relationship changes, using the existing row revision marker. Broad config/source invalidations retain their broad revision, and replacements retain former child keys while reconciling relationships. No new cache or scheduler is introduced.

Runtime production delta: +27 lines across three owners. The extra code carries exact old/new ownership needed to preserve parent moves, collector transfer, deletion, and replacement; the global per-run invalidation and the misleading roster wrapper are removed. The standalone benchmark and its Knip entry are separate proof tooling.

Evidence

Baseline owner sources: a4a8f632da0a9a2f5ab8ffc2e66fe2b46693ff6a (main at investigation start). The committed scripts/perf/session-row-consume-measure.ts uses 10,000 synthetic resident rows across 100 agents, real registry indexing, relationship reads, materialization, and presentation. List calls consume 100 parent rows; exact-event calls consume the changed child and its parent. Setup, warmup, and byte checks are outside timing. Allocation is sampled separately with collected objects included.

Acceptance, written before measurements: identical row bytes across keyed updates, requester/controller moves, deletion, and replacement; fewer unrelated refreshes and lower CPU/allocation per call. Wall-clock tails are interpreted with host load and counterbalanced arms, not as standalone adverse evidence on this shared host.

Owner workload Main-thread CPU/call Sampled allocation/call Calls per side (timing / allocation)
100-parent page 30.821 → 13.235 ms (−57.1%) 33.649 → 11.847 MB (−64.8%) 9,000 / 6,000
Changed child + parent event 348.976 → 349.792 µs (+0.23%) 376.770 → 368.177 KB (−2.28%) 6,000 / 3,000

All 16 measurement arms match at all 16 intermediate verification states and final row-byte digests. Page refresh work falls from approximately 100 rows to one affected owner per call. Exact events were already scoped to their requested rows: their CPU remains effectively unchanged and allocation improves slightly. Their first visits also include lazy settlement after the broad replacement in verification; no samples were trimmed.

Untraced synchronous slice measurements (3,000 samples per arm, every pair):

Flow / launch order CPU ms/call, base → candidate p99 ms, base → candidate Maximum ms, base → candidate Host load (1 min), base → candidate
Page AB 31.219 → 13.875 77.77 → 118.93 351.77 → 568.34 37.53 → 53.90
Page BA 31.018 → 14.614 360.42 → 136.57 775.67 → 494.37 72.46 → 59.45
Page extra AB 30.227 → 11.215 93.69 → 54.99 433.10 → 370.24 32.56 → 35.33
Event AB 0.322 → 0.341 1.090 → 1.220 9.54 → 9.43 34.16 → 33.00
Event BA 0.376 → 0.358 1.661 → 1.476 46.32 → 15.67 45.04 → 36.46

The page tails had mixed signs, so the extra pair was declared before it ran. Signed paired-mean p99 delta is −73.80 ms (177.29 → 103.49); mean maximum delta is −42.53 ms (520.18 → 477.65). This shared-host wall spread is context, not a production latency claim or an adverse verdict. The CPU reduction holds in every page pair. Event CPU's initial +19 µs reverses in BA, leaving +0.82 µs in the paired mean.

Allocation uses separate 32 KiB sampling passes with minor/major collected objects included; traced timings are not gates. Both page allocation pairs agree at −64.79%. Host loads for page allocation pairs were 45.21/45.43 and 30.09/37.13 (base/candidate), and 28.27/25.91 for event allocation.

The scoped-refresh regression extends the existing resident-projection observer matrix: keyed requester changes rebuild only the two affected parents, and collector completion rebuilds only its swarm owner while parent membership stays unchanged. Both new work-count cases fail against the unmodified base owners: requester movement rebuilds four rows instead of two, and collector completion rebuilds four instead of one. Existing broad publication, registry clearing, persistence, and observer-ordering checks remain. The attribution regression independently fails on main's incorrect agent-roster label. The benchmark separately verifies byte equivalence through controller movement, retirement, and broad replacement.

Focused owner/consumer verification: 65 tests across session-row context, subagent projection/index, exact events, activity-summary publication, placement lifecycle, and subagent memory; 22 roster tests; 32 eager-import/PR-wrapper closure tests. Core targeted typecheck, changed-file format/lint, export collision guard, and git diff --check pass. Test wall time: 150 s for the six owner/consumer files (including worker preparation); 132 s for closure tooling. The final two changed test files pass all 16 cases in 73.51 s including compiler preparation; both keyed regressions fail on the base for the intended work counts. CI supplies broad proof.

Review: independent subagent review (autoreview route unavailable), P0/P1/P2 scope, no accepted findings remaining. The shared Codex autoreview helper refused before inference because its requested provider route did not match operator configuration; no configuration was changed.

Scope of measurement: this is owner-level proof, not a whole-Gateway or live-server result. The fast-path protocol applies to removal of redundant recomputation; no Team access, production load, or long Gateway A/A campaign was performed. Existing synchronous publication and authority checks remain in place. Host-load-related tail variation and exact-event residual cost are reported separately above.

CI follow-up: the first head passed runtime/test/lint checks but failed the test-line ratchet (base already 895 lines over its ceiling; the original custom regression added 137). The regression now extends the existing production-projection matrix, with existing disposable fixtures replacing repeated cleanup. Final test-line delta is −2. No baseline ceiling increase and no existing contract deletion. Independent follow-up review is clean; its swarm-only coverage finding was addressed before this update.

@clawsweeper

clawsweeper Bot commented Oct 27, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-27T14:17:21.164810Z e93ab93 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts agents Agent runtime and tooling size: L labels Oct 27, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR refreshes session-row presentation only for affected parents and swarm requesters and preserves callers’ diagnostic task labels.

Example: One collector completes while a session list displays 100 parent rows.

  • Before: The next read refreshes presentation facts for approximately 100 parents.
  • After: Only the affected swarm requester refreshes, with matching row bytes in the reported owner benchmark.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, narrowly owned optimization with detailed owner-level evidence, held below a clean verdict by the attributable test-line gate failure.
Proof confidence 🦐 gold shrimp (3/6) The review context identifies this as maintainer-authored and outside the ordinary contributor proof gate; the supplied evidence exercises real registry, relationship, materialization, and presentation owners in-process, with explicit limits on whole-Gateway claims.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Large session lists repeat presentation work for unrelated parents after a single subagent update.
Reason: Recorded owner measurements show substantially less CPU and allocation with matching output, and the review context explicitly establishes maintainer direction.

Merge readiness

⛔ Needs changes before merge - 1 item remains

This PR provides a focused performance improvement using existing owners, but its added regression triggers the enforced test-line ratchet; no runtime or security defect was found.

Priority: P2
Reviewed head: e693b15a4ec139d2b68693ace5992b1f74c242b8

Before merge

  • Reconcile the added regression with the test-line budget (P2) - This regression adds 137 net test lines without changing the ceiling, triggering the exact-head checks-fast-baseline-ratchets failure. The checked-out tree contains 6,284,133 test lines against 6,283,101 allowed; the base was already 895 lines over, but scripts/check-test-lines-ratchet.mts permits inherited excess only for changes with a nonpositive test-line delta. Preserve the behavioral assertions while consolidating coverage or make a narrowly justified ceiling adjustment through the checker's documented path.

Findings

  • [P2] Reconcile the added regression with the test-line budget — src/gateway/session-row-projection-context.test.ts:149-150

Tests

  • Missing end-to-end proof: The supplied owner benchmark does not exercise sessions.list or exact events through a running Gateway.
Agent review details

How this fits together

The Gateway session-row projection consumes committed registry publications and stored session metadata, maintains relationships and presentation facts, and supplies session lists and exact-event responses.

flowchart TD
  A[Registry publications] --> B[Resident subagent index]
  B --> C[Changed children and requesters]
  C --> D[Session row context]
  E[Stored session metadata] --> D
  D --> F[Row presentation]
  F --> G[Lists and exact events]
Loading

Technical review

Best possible solution:

Keep the scoped invalidation fix and reconcile its regression coverage with the enforced test-line budget.

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

The base advances the presentation revision for every relevant keyed registry change, causing unrelated presented rows to rebuild child links and swarm summaries; the supplied benchmark and red/green regression corroborate this path without a reviewer-run reproduction.

Is this the best way to solve the issue?

The change follows the existing publication and projection owners, retains broad invalidation and replacement handling, and removes redundant recomputation without adding another cache or scheduler.

Full review comments:

  • [P2] Reconcile the added regression with the test-line budget — src/gateway/session-row-projection-context.test.ts:149-150
    This regression adds 137 net test lines without changing the ceiling, triggering the exact-head checks-fast-baseline-ratchets failure. The checked-out tree contains 6,284,133 test lines against 6,283,101 allowed; the base was already 895 lines over, but scripts/check-test-lines-ratchet.mts permits inherited excess only for changes with a nonpositive test-line delta. Preserve the behavioral assertions while consolidating coverage or make a narrowly justified ceiling adjustment through the checker's documented path.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Keyed registry indexing and presentation invalidation keeps the original intent (44c9551: Preserve current list facts while avoiding complete index rebuilds for internal registry bookkeeping.)
  • Parent membership identity keeps the original intent (d704d3b: Retain equal parent-set identity so consumers avoid repeated structural comparison.)
  • Roster callback diagnostic attribution changes intended behavior with a stated reason (7c1dfd9: Carried the diagnostic wrapper into the roster owner while moving shared config-generation facts; the earlier attribution work intended to identify synchronous operation costs.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm check:test-lines-ratchet --base 200f33b --no-merge-base
  • pnpm test src/gateway/session-row-projection-context.test.ts src/gateway/session-row-placement-projection.lifecycle.test.ts --maxWorkers=1
  • git diff --check

What I checked:

PR surface

Source +27, Tests +137, Docs 0, Other +375. Total +539 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 48 21 +27
Tests 2 141 4 +137
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 375 0 +375
Total 8 565 26 +539

Review metrics

Metric Value Why it matters
Runtime versus regression code Runtime +48/-21 lines; tests +141/-4 lines The 27-line runtime increase carries old/new affected ownership through existing components; the regression growth protects scoped refreshes and relationship retirement.

Labels

Label changes:

  • add P2: A useful session-list performance improvement with a bounded, diff-caused validation blocker and no demonstrated urgent user-facing regression.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: A useful session-list performance improvement with a bounded, diff-caused validation blocker and no demonstrated urgent user-facing regression.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 27, 2026, 9:55 AM ET / 13:55 UTC.

@steipete
steipete force-pushed the steipete/perf-session-row-consume-main-thread-slices-20261027 branch from e693b15 to e93ab93 Compare October 27, 2026 14:17
@steipete
steipete merged commit 38bce0c into main Oct 27, 2026
130 of 132 checks passed
@steipete
steipete deleted the steipete/perf-session-row-consume-main-thread-slices-20261027 branch October 27, 2026 14:39
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
)

* perf(gateway): refresh only affected session row owners

* test(gateway): reuse projection lifecycle proof for scoped refreshes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant