Repository navigation
perf(gateway): reuse prepared task parents and attribute row selections - #181732
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7c46564fcd
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
7c46564 to
f9ed0a6
Compare
|
@clawsweeper re-review The OTel restart finding is fixed and covered with a real-SDK regression. The branch, PR body, and all three paired measurements are current at f9ed0a6. |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. What this changesThis PR reuses prepared task-parent identities and exports session-row selection counts through Prometheus and OpenTelemetry. Example: An OTel service samples 4 parent selections, restarts with the same SDK, then samples a cumulative total of 6.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR provides a measured allocation improvement and useful bounded telemetry; no actionable defect remains in the reviewed diff, including the OTel restart repair. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe Gateway session-row projection selects resident descendants for task PR subscriptions, while its existing memory sampler carries cumulative selection totals to diagnostic exporters. flowchart LR
A[Task PR subscriptions] --> B[Prepared parent row]
B --> C[Resident parent index]
C --> D[Live audience checks]
C --> E[Selection counters]
E --> F[Memory sampler]
F --> G[Prometheus and OpenTelemetry]
Technical reviewBest possible solution: Retain the existing projection and sampler owners, carry prepared parent identities directly, and preserve exporter baselines for the lifetime of their instruments. Do we have a high-confidence way to reproduce the issue? Current main passes parent keys back through lineage resolution despite already holding prepared rows; the supplied Gateway measurements exercise that path, and the restart regression directly encodes the earlier recounting failure. Is this the best way to solve the issue? The change removes repeated work at the existing owner and adds bounded counters through existing exporters without introducing a competing selection cache. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 3ac1e62c3603. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +189, Tests +124, Docs +24, Other +48. Total +385 across 25 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 23, 2026, 12:06 PM ET / 16:06 UTC. |
…ns (openclaw#181732) * perf(gateway): reuse prepared task parents and attribute row selections * fix(diagnostics-otel): retain row selection totals across restarts
What Problem This Solves
Task pull-request subscriptions repeatedly resolve parent identities that the session-row owner has already prepared. Production allocation profiles also group several selection paths under the same roster wrapper, obscuring which caller is doing the work.
User Impact
Task descendant selection returns the same results with less allocation. Operators gain bounded selection-kind/caller counters to distinguish broad scans, exact reads, child traversal, and running-candidate lookups. No configuration or schema changes are required.
Why This Change Was Made
Pass the prepared parent row through the existing selector and remove the ordinary-parent physical lookup, which only sentinel parents need. Preserve raw aliases, sentinel behavior, federation, live audience checks, and the existing sharing-revision cache. Ordered broad selections are already retained; unordered catalogs keep their observable resident ordering.
The existing memory sampler carries process-lifetime counters to Prometheus and OpenTelemetry; selections update scalar totals without emitting individual diagnostic events. OTel baselines follow the retained Meter and metric-name prefix, so restarting a service with a preloaded SDK does not double-count prior totals.
Runtime code adds 216 lines and removes 27 (net +189). The selection optimization is net +1 for the typed prepared-row input; the remaining growth implements the requested attribution, exporters, and their lifecycle. No new selection cache or duplicate owner was added.
Evidence
The task traversal regression observed 4 redundant parent resolutions before, 0 after, including after reparenting. All 24 owner tests and 45 focused telemetry tests passed, along with changed-file lint/formatting, the targeted core typecheck, the export collision guard, and 22 import-closure tests. Independent review found no actionable P0–P2 findings. The OTel restart finding from GitHub review was reproduced, fixed, covered with a real-SDK regression (restart, repeated sample, prefix isolation, new provider), and independently reviewed.
Real Gateway measurement
Synthetic fixture: 5,000 sessions, 6,000 retained runs, four tabs watching 50 task keys each. Each side performs 1,000 stored-row updates at a 100 ms interval, 125 sidebar list requests, and 256 subscription refreshes. The driver joins the subscription owner's asynchronous work and validates every watched snapshot. All six runs produced identical initial/final snapshot hashes.
Baseline is
36f471b55b8aplus identical telemetry and harness. The measured candidate owner hashes match final headf9ed0a64ddd9. Pairs 1 and 2 ran concurrently within one exclusive, guarded slot with interleaved CPUs and swapped placement. Pair 3 used another exclusive slot with the same interleaving and guard to resolve the opposite-sign update p99. No pair was interrupted by the guard. A preliminary setup-only failure was discarded: the driver now waits for/readyzbefore connecting.Values below are baseline → candidate. Allocation includes sampled collected objects; each update includes its notification work and the stated sidebar mix.
The original swapped-pair mean is −6.00% allocation and −2.80% main CPU. Across all three pairs these are −5.98% (−1.252 MB/update) and −3.55% (−1.033 ms/update). Update p99 changed by +7.272, −3.225, and −3.297 ms: the opposite-sign result is decided on its +0.250 ms absolute mean, not a relative mean dominated by the smallest baseline. Other mixed-sign absolute means: process CPU +0.177 ms/update, total GC −0.128 ms/update, promotion +0.0086 MB/update, and event-loop p99 −0.601 ms. None crosses the adverse gate.
Acceptance: reject ≥20% adverse paired mean or ≥10% adverse in both swapped pairs. Opposite signs or >5× baseline spread require absolute deltas and a third pair for a gating metric. p99 requires 1,000 samples/side and p95 requires 200. Minor p95's absolute mean is −0.043 ms, within the sub-millisecond context rule; minor p99 and major pause tails are context-only at these collection counts. Candidate maximum pauses are below
max(50 ms, 2 × baseline maximum)in each pair. Sidebar tails have only 125 samples/side and are context: mean latency deltas are −0.588, −0.338, and +0.697 ms.Attribution: each full run made 430,000 detached parent selections, about 500 additional parent selections attributed to task-PR work, and only one broad sidebar selection, with no broad resets. This reproduces the parent path that a warm sidebar-only workload missed. A separate 100-update qualification profile reduced the selector allocation subtree from 242.4 to 106.5 MB and its parent-resolution subtree from 80.8 to 3.1 MB; those overlapping subtrees must not be added.
Reproduce with the committed
scripts/perf/session-pr-subscriptions-measure.tsand fixture/paired-run instructions inscripts/perf/README.md:Limits: this is a synthetic caller ratio, not a claim of an exact production speedup. Both sides include identical telemetry, so its overhead is not isolated. No production deployment was performed; PR CI supplies the broad validation.
Production follow-up: compare
rate(openclaw_session_row_selections_total[5m])andrate(openclaw_session_row_selection_rows_total[5m])grouped bykind,task, alongsiderate(openclaw_session_row_selection_resets_total[5m]). Includeparent/other: detached work does not necessarily inherit the originating RPC task. A follow-up allocation profile should show the reducedselectSessionRowParentsubtree at a comparable selection rate.