Skip to content

fix(gateway): attribute prepared session-row stalls - #180239

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-stall-attribution-labels-20260919
Oct 22, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-stall-attribution-labels-20260919

Conversation

@steipete

@steipete steipete commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Prepared session-row reads and agent roster batches can produce task=unattributed main-thread stall warnings after their enclosing operation has awaited readiness. Related: #179929 (attribution extracted without its rejected read budget).

User Impact

Operators can identify the RPC method or scheduled task behind a slow synchronous read. Examples: gateway:rpc:sessions.list:session-rows:select and scheduler:maintenance:session-refresh:agent-roster. Session selection, queueing, budgets, and response behavior are unchanged.

Why This Change Was Made

The existing stall owner now carries the code-owned operation name across awaits and times the select, prepare, consume, and roster scopes synchronously. It keeps the phase separate and constructs the combined label only when recording a stall. There is no per-row instrumentation, new queue, configuration, or schema. Runtime code is net +40 lines: carrying task identity across waits and timing the previously unnamed phases requires new diagnostic coverage. Existing timing, queue, and selection owners remain in place.

Evidence

Independent review through P2 found no actionable issues. All 55 focused tests passed (stall monitor, prepared-row lifecycle, event-loop health, and roster configuration); both new prepared-row regressions failed on the original code with an empty stall report. Changed-file formatting/lint and the native core typecheck passed. The export-name collision guard and both source-closure files passed (22 cases). All three paired measurements pass the acceptance rule below; the result is neutral.

The focused test command took 32.73 seconds including worker preparation; the changed test files themselves took milliseconds. No Testbox lease or production Gateway mutation was used.

Measurement acceptance, recorded before running: two concurrent baseline/candidate pairs with identical synthetic 5,000-session/6,000-run fixtures, CPU placements swapped in pair 2, one shared measurement lock, and the shared production guard. Warm real WebSocket sessions.list requests use the same operation count per side. Measure RPC mean/p95/p99, sampled main-isolate allocation per RPC, total GC time per RPC, promotion, and event-loop delay; report sample counts and each side's maximum GC pause.

Decision rules: stop for a mean paired regression of at least 20%, or at least 10% adverse in both pairs. Opposite delta signs or baselines differing by more than 5× are inconclusive; report absolute and relative deltas, run a third pair for a gating metric, and decide on its absolute mean. p95 requires 200 samples per side; p99 requires 1,000; major GC requires 50 collections. Per-collection pause tails are context when collection counts fall at least 20% and total GC does not rise, except a maximum single pause above max(50 ms, twice baseline). Guard-interrupted pairs are discarded. This explicitly requested diagnostic change may land with neutral performance.

Paired measurements: neutral

Three concurrent baseline/candidate pairs used identical synthetic 5,000-session / 6,000-retained-run fixtures and real WebSocket sessions.list calls. Each side completed 240 warmup requests and 2,400 measured requests returning 200 sidebar rows. The first two pairs changed sign for allocation, promotion, total GC, and minor-GC p95, so they were inconclusive for those metrics under v5.2; the third pair resolves them using the absolute mean. No eligible metric reaches a +20% mean regression or is at least +10% adverse in both initial pairs. Pair 3's RPC p99 is +10.98% on its own; the three-pair absolute mean is −0.295 ms (−1.04% of mean baseline). This is neutral evidence, not a speedup claim.

Mean absolute deltas: RPC latency −0.054659 ms; sampled allocation +3,941.99 bytes/RPC (+0.153%); total GC +0.000528612 ms/RPC (+0.359%); promotion −2,060.54 bytes/RPC (−2.477%). Minor-GC p95 is +0.077333 ms (+3.955%). Event-loop p99, minor-GC p99, and major-GC tails are context-only because their per-side sample counts are below the required thresholds. The candidate's maximum single GC pause is below max(50 ms, 2 × baseline max) in every pair.

Method: Linux x64, Node 26.12.1, source Gateways with the three changed owners substituted at their canonical module URLs. Baseline is 34a4e3bf238e1ebcb0c110d6b912f71bbeceed22; candidate owner hashes match this PR head. The intervening rebase changes were UI-only; the measured owners and lockfile are unchanged. Both variants used the same resolver wrapper and verified source-package routing. Slot A held one exclusive lock per pair; baseline used even CPUs 96–126 in pairs 1/3 and odd CPUs 97–127 in pair 2, with candidate on the other interleaved set. Each side verified 16 available CPUs, MemoryMax=16G, CPUWeight=10, and IOWeight=10. Preparation used CPUs 0–63 with nice 19. The shared guard ran unchanged before and during each pair; no accepted pair had a guard violation. Setup-only failed attempts were excluded before measurement.

node --import ./scripts/tsx.mjs scripts/perf/transcript-broadcast-measure.ts \
  --entry <canonical-source-overlay-entry> --state-dir <synthetic-fixture> \
  --scenario sessions.list --row-mode sidebar --limit 200 \
  --clients 8 --rpc-concurrency 4 --warmup-operations 240 --operations 2400 \
  --runs 1 --rounds 1 --allocations --diagnostics --trace-gc \
  --capture-responses --heap-sampling-interval 32768 \
  --start-at <shared-epoch-ms> --port <isolated-port> --mock-port <isolated-mock-port>

There were no diagnostic drops, collection errors, or lost histogram samples. All 20 captured filter/sort/paging responses matched in each pair, after canonical expandSessionRowFacts expansion and normalization of the documented timestamps, process-local rowsRevision UUIDs, and synthetic fixture paths. No row content, ordering, or count was removed.

Each pair cell is baseline → candidate; absolute delta (relative delta). Tail sample counts are baseline/candidate. Means use all three accepted pairs; absolute means retain their sign.

Metric Pair 1 Pair 2 (swapped) Pair 3 Mean absolute delta Mean delta / mean baseline
RPC mean, ms 10.8642 → 10.4660; -0.3981 (-3.66%) 12.5290 → 12.3600; -0.1691 (-1.35%) 10.3369 → 10.7401; +0.4032 (+3.90%) -0.0547 -0.49%
RPC p50, ms 9.9389 → 9.6168; -0.3221 (-3.24%); n=2400/2400 11.4888 → 11.4824; -0.0063 (-0.06%); n=2400/2400 9.5105 → 9.7971; +0.2866 (+3.01%); n=2400/2400 -0.0139 -0.13%
RPC p95, ms 19.5232 → 18.2585; -1.2648 (-6.48%); n=2400/2400 22.7099 → 22.3817; -0.3282 (-1.44%); n=2400/2400 18.0632 → 19.1518; +1.0886 (+6.03%); n=2400/2400 -0.1681 -0.84%
RPC p99, ms 27.4073 → 25.8690; -1.5383 (-5.61%); n=2400/2400 32.8208 → 30.7398; -2.0810 (-6.34%); n=2400/2400 24.8969 → 27.6313; +2.7345 (+10.98%); n=2400/2400 -0.2949 -1.04%
Sampled allocation, KiB/RPC 2485.4691 → 2501.7182; +16.2492 (+0.65%) 2531.3415 → 2523.6391; -7.7024 (-0.30%) 2524.1468 → 2527.1489; +3.0020 (+0.12%) +3.8496 +0.15%
Promotion, KiB/RPC 82.2563 → 83.9819; +1.7256 (+2.10%) 81.0826 → 76.7999; -4.2828 (-5.28%) 80.4119 → 76.9323; -3.4796 (-4.33%) -2.0122 -2.48%
Total GC, ms/RPC 0.1384 → 0.1395; +0.0010 (+0.76%) 0.1690 → 0.1682; -0.0008 (-0.45%) 0.1344 → 0.1357; +0.0013 (+0.96%) +0.0005 +0.36%
Main-thread CPU, ms/RPC 3.3931 → 3.2701; -0.1229 (-3.62%) 3.9116 → 3.8833; -0.0283 (-0.72%) 3.2286 → 3.3574; +0.1289 (+3.99%) -0.0075 -0.21%
Process CPU, ms/RPC 4.4988 → 4.4065; -0.0923 (-2.05%) 5.1887 → 5.0924; -0.0963 (-1.86%) 4.3463 → 4.4150; +0.0687 (+1.58%) -0.0400 -0.85%
Event-loop p99, ms (context) 34.5702 → 36.6019; +2.0316 (+5.88%); n=329/314 39.5182 → 37.0606; -2.4576 (-6.22%); n=364/365 37.0606 → 39.0922; +2.0316 (+5.48%); n=313/320 +0.5352 +1.44%
Minor GC p95, ms 1.6060 → 1.5580; -0.0480 (-2.99%); n=228/230 2.7020 → 2.9420; +0.2400 (+8.88%); n=245/249 1.5580 → 1.5980; +0.0400 (+2.57%); n=240/249 +0.0773 +3.95%
Minor GC p99, ms (context) 2.3500 → 2.3500; +0.0000 (+0.00%); n=228/230 3.1500 → 3.5020; +0.3520 (+11.17%); n=245/249 2.0460 → 1.9660; -0.0800 (-3.91%); n=240/249 +0.0907 +3.60%
Major GC p95, ms (context) 22.7820 → 21.1180; -1.6640 (-7.30%); n=2/2 19.5820 → 23.0380; +3.4560 (+17.65%); n=2/2 19.0700 → 27.1340; +8.0640 (+42.29%); n=2/2 +3.2853 +16.04%
Major GC p99, ms (context) 22.7820 → 21.1180; -1.6640 (-7.30%); n=2/2 19.5820 → 23.0380; +3.4560 (+17.65%); n=2/2 19.0700 → 27.1340; +8.0640 (+42.29%); n=2/2 +3.2853 +16.04%
Pair Minor / major collection counts (B → C) Max single pause, ms (B → C) Minor max, ms (B → C) Major max, ms (B → C) Sampled allocation objects (B → C)
1 228 → 230 / 2 → 2 22.693 → 21.057 2.756 → 2.634 22.693 → 21.057 183,555 → 184,712
2 245 → 249 / 2 → 2 19.567 → 22.964 5.701 → 3.654 19.567 → 22.964 186,894 → 186,353
3 240 → 249 / 2 → 2 19.059 → 27.087 2.464 → 2.571 19.059 → 27.087 186,351 → 186,599

Live log proof

A separate isolated source Gateway served a real WebSocket sessions.list request (200 rows, totalCount 5,000). A task-only overlay injected one 350 ms synchronous pause into selectRows, guarded to fire only for gateway:rpc:sessions.list; this overlay was never used in the paired measurements. The existing event-loop logger emitted:

2026-10-22T03:33:52.321+00:00 [event-loop] main-thread stall: elapsedMs=391 task="gateway:rpc:sessions.list:session-rows:select" taskMs=355

The controller exited 0 and the owned Gateway shut down. The shared guard reported no failure. The committed regression additionally proves background-task attribution after readiness waits (scheduler:maintenance:session-refresh:session-rows:select) and nested roster attribution (...:agent-roster).

CI attribution

Exact-head CI run 39715651391 completed with two inherited non-aggregate failures; the aggregate CI gate remains red. No CI rerun was requested.

  • check-test-types-core-3: chat-details-output-intent.test.tsx:27,53 still supplies artifactsLoading after refactor(ui): observe workspace reads with Solid boundaries #180031 replaced that property with artifactRead. Independent job 119618113966 has the identical TS2353 errors. Both offending file blobs match this head, that job's actual merge checkout b61ce93b0f6b775060b326d222a48c6bff31eb3a, and its main parent 4611232730583082f5c49bd79f1f68dfbfbd1b60.
  • checks-node-changed: the pinned-Bun x-publication-owner-composition.e2e.test.ts:944 anonymous read returned 503 instead of 200. fix(test): X publication e2e returns 503 on the public read under Bun #177556 diagnoses the existing fixture race: a second completion write can invalidate a public representation after the fixture's controller-settlement checkpoint. #179939's baseline proof reproduced the identical failure on both unchanged main 399a360fdfbb15546498a97886cef41fd8cac66b and its candidate on their third focused invocations. The six causal public-cache/response and registry-completion modules are byte-identical here, and the fixture still has the old checkpoint. This fixture never starts the stall monitor, so the added task scopes call through synchronously. Our head and exact-parent focused Bun replays each passed once; those passes are context, not a claim that the race is fixed.

The focused replay used OPENCLAW_E2E_SKIP_BUILD=1 node scripts/run-vitest.mjs src/gateway/x-publication-owner-composition.e2e.test.ts --maxWorkers=1, the supported path for this source-composition fixture. An initial invocation started automatic E2E build preparation and was stopped before running the test to respect the local compute limit. All other non-aggregate CI jobs passed or were intentionally skipped. Independent review remains clean; no review or security requirement is being waived.

Carry code-owned task names across readiness waits and label synchronous selection, preparation, consumption, and roster batches. Keep phase strings separate until a stall is recorded. Operators can identify the enclosing RPC or background task without changing read budgets or scheduling.
@clawsweeper

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

@steipete
steipete marked this pull request as ready for review October 22, 2026 03:13
@chatgpt-codex-connector

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-22T03:13:27.997473Z 15a9a08 Draft marked ready
ℹ️ 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 agents Agent runtime and tooling size: M labels Oct 22, 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 22, 2026
@clawsweeper

clawsweeper Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR preserves operation names across waits and attributes slow synchronous session-row and agent-roster work to those operations.

Example: A sessions.list request awaits readiness, then spends 300 ms selecting session rows.

  • Before: The resumed selection lacks its originating RPC label.
  • After: The stall is labeled gateway:rpc:sessions.list:session-rows:select.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Source review supports the focused implementation, while required performance acceptance and CI failure attribution remain incomplete.
Proof confidence 🌊 off-meta tidepool Not applicable: Ordinary contributor proof gating is not applicable to this maintainer-authored PR; supplied support consists of injected-clock tests through the real monitor and prepared-row owner, with no completed Gateway measurement results.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Operators cannot identify the originating RPC or scheduled task when prepared session-row work stalls after a readiness wait.
Reason: The maintainer-authored direction adds useful diagnostic attribution without new configuration, storage, scheduling policy, or user-facing restrictions.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this PR open: it addresses a source-visible diagnostic gap with maintainer-approved direction, and review found no actionable correctness or security defects.

Priority: P2
Reviewed head: 15a9a08be13c861663bf1389130d125318803610

Before merge

  • Complete next step - Complete the recorded paired performance evaluation and determine whether check-test-types-core-3 and checks-node-changed failures are caused by this patch before landing.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied evidence does not yet demonstrate resumed phase labels through a real Gateway request; focused base-failing regressions are reported.
Agent review details

How this fits together

Gateway RPCs and scheduled jobs enter the prepared-row owner, which combines current session selection and placement facts before synchronous consumption; the shared stall monitor records bounded diagnostic labels and durations.

flowchart TD
  A[RPC or scheduled job] --> B[Operation name context]
  B --> C[Prepared session rows]
  C --> D[Readiness and placement waits]
  D --> E[Synchronous selection and consumption]
  E --> F[Agent roster batch]
  E --> G[Shared stall monitor]
  F --> G
Loading

Technical review

Best possible solution:

Keep task identity and synchronous timing in the existing stall owner, preserving current session-read scheduling and authorization.

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

Current-main source shows task scopes ending when callbacks return promises and resumed prepared-row phases lacking explicit scopes; the PR reports focused regressions failing on the base, but this read-only review executed no target code.

Is this the best way to solve the issue?

The patch is a focused repair using the existing monitor and preparation owners; the added tests cover resumed attribution, exclusion of readiness waits, overlapping callers, and synchronous owner-context reentry.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Asynchronous task identity changes intended behavior with a stated reason (eaa6938: Remove process-wide continuation timing and associated allocation overhead; the current PR explains retaining names across waits while timing only explicit synchronous phases.)
  • Prepared session-row selection and consumption keeps the original intent (f6a3ed7: Reuse selection inside a synchronous frame and select again after asynchronous preparation so current membership, scopes, clock, and identity remain visible.)
  • Private-row preparation and completion keeps the original intent (7855489: Retain captured private-row resources through preparation and cleanup without replaying consumers or changing ordinary synchronous completion.)
  • Agent-roster batching keeps the original intent (e7ec39f: Share roster facts within synchronous batches while preserving freshness across mutable-config batches; subsequent config-publication caching remains unchanged.)
  • Stall threshold and bounded reporting keeps the original intent (8e234e5: Report synchronous stalls at 250 ms inclusive with bounded buffering and task labels, excluding awaited I/O.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 48b4bcb adds src/infra/main-thread-stall.ts:19 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 48b4bcb866fb; files: src/infra/main-thread-stall.ts)
  • weiqinl: Raw commit e7ec39f adds src/agents/agent-scope-config.ts:115 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e7ec39fe54ec; files: src/agents/agent-scope-config.ts)

PR surface

Source +40, Tests +86, Docs +6. Total +132 across 6 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 88 48 +40
Tests 2 87 1 +86
Docs 1 8 2 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 183 51 +132

Labels

Label changes:

  • add P2: Missing operation attribution limits diagnosis of Gateway stalls, with no demonstrated message loss or urgent runtime regression.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool 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: Missing operation attribution limits diagnosis of Gateway stalls, with no demonstrated message loss or urgent runtime regression.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool 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 21, 2026, 11:29 PM ET / October 22, 2026, 03:29 UTC.

@steipete

Copy link
Copy Markdown
Contributor Author

Landing the reviewed head 15a9a08be13c861663bf1389130d125318803610 under the authorized inherited-failure rule. Three swapped-placement measurements are neutral (mean RPC delta −0.055 ms, sampled allocation +0.153%, total GC +0.359%), and the real isolated Gateway log proof passed. Full pair data and sample counts are in the PR body.

The two non-aggregate failures in run 39715651391 are inherited:

Other non-aggregate checks passed or were intentionally skipped. No CI rerun, review waiver, or security waiver was used.

@steipete
steipete merged commit da0de99 into main Oct 22, 2026
231 of 239 checks passed
@steipete
steipete deleted the steipete/perf-micro-stall-attribution-labels-20260919 branch October 22, 2026 03:34
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 22, 2026
Carry code-owned task names across readiness waits and label synchronous selection, preparation, consumption, and roster batches. Keep phase strings separate until a stall is recorded. Operators can identify the enclosing RPC or background task without changing read budgets or scheduling.
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. size: M 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