Skip to content

perf(sessions): avoid full display rebuilds during resolution - #169082

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-sessions-resolve-cold-rebuild-20260919
Oct 11, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-sessions-resolve-cold-rebuild-20260919

Conversation

@steipete

@steipete steipete commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Session ID, label, and link resolution waits for every dirty session display row to rebuild. A broad invalidation can therefore turn a small lookup into a long wait, and an unrelated display failure can reject resolution.

User Impact

Session targets resolve from current metadata while unrelated display rows refresh in the background. Existing visibility, canonical readiness, ambiguity, and exact-key behavior remain intact. There are no schema, stored-data, configuration, or upgrade changes.

Why This Change Was Made

Use the session-row projection's existing selection preparation through withReadySessionRows, replacing the separate full-materialization wait. The projection remains the sole owner of indexes and committed invalidation. Production LOC: 15 added, 20 removed (net -5).

Evidence

Final same-host RPC-handler comparison: 2,000 synthetic sessions, approximately 18.4 committed background writes/second, one-second gaps between resolve requests, 30 observations per version. A broad store invalidation precedes each request. Baseline f1fbf170dea3; candidate tree exactly matches 49886f8c40b3474cb09898d6d524f3dff0634669.

Raw session-ID resolution Before After
Average 726.1 ms 338.9 ms
Median 711.4 ms 329.3 ms
p99 944.1 ms 536.0 ms

That is a 2.14× average speedup. The 100 ms cold p99 target is missed: broad invalidation still requires metadata reconciliation. This change removes the additional full-display drain and its unrelated failure dependency.

An earlier higher-frequency comparison on b690de6fbb42 measured cold ID p99 905 → 368 ms, label p99 712 → 402 ms, and reference p99 627 → 310 ms. Under ordinary writes, every selector's p99 stayed below 13 ms on both versions. The hypothesis that every ordinary write rebuilds the ID index was not reproduced; committed publications already maintain that index.

Validation:

  • New real-RPC-handler regression fails on the old code with Unrelated display unavailable and passes with the change.
  • All 78 tests across six focused suites pass on the final candidate tree, covering resolution, visibility, canonicalization, archived/incognito sessions, and preview/resolve behavior.
  • pnpm test src/gateway/sessions-resolve-projection.test.ts --maxWorkers=1: 19 passed, 65.55 seconds wall time. The added case took 3.20 seconds in that run; separate per-case CI seconds were not extracted.
  • Required CI run 38136002901 passed on exact head 49886f8c40b3474cb09898d6d524f3dff0634669, including all production/test type checks, lint, tests, and openclaw/ci-gate. The duplicate serial rig type run was stopped after CI established those results.
  • Independent Codex review is clean at P0–P2; ClawSweeper found no introduced code defect. The author’s temporary validation hold is now resolved.

All runtime measurements and focused tests ran on the authorized Linux rig, with isolated synthetic state and a dedicated temporary directory. Testbox tbx_01m4n5qvqtn33y3zkj86efdzk2 remained queued; AWS cbx_a73fb99b8d51 and Hetzner cbx_6c21ab94c95c sync attempts failed before any workload executed and were released. The old base had unrelated max-lines/dead-export failures; current-main max-lines and exact-head required CI pass. No production Gateway was accessed.

Measurements cover the registered RPC handler and real isolated storage, excluding WebSocket transport and production-load effects. The sample p99 is the maximum of 30 observations per version.

@clawsweeper

clawsweeper Bot commented Oct 11, 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 docs Improvements or additions to documentation gateway Gateway runtime size: S labels Oct 11, 2026
@steipete
steipete marked this pull request as ready for review October 11, 2026 11:33
@clawsweeper clawsweeper Bot added 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. labels Oct 11, 2026
@clawsweeper

clawsweeper Bot commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR resolves session targets using current selection metadata without waiting for unrelated session display rows to rebuild.

Example: Resolve session ID target-id while agent:main:unrelated-display fails to rebuild.

  • Before: The unrelated display failure rejects the lookup.
  • After: The lookup returns agent:main:target through the existing metadata preparation owner.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch and meaningful boundary regression support correctness; the inspected evidence reaches the RPC handler rather than a shipped client flow.
Proof confidence 🦐 gold shrimp (3/6) The task identifies this as maintainer-authored, outside the ordinary contributor proof gate; supplied evidence exercises the real RPC handler with isolated storage, while the author's exact-head validation hold remains explicit.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Resolving a session target can wait for unrelated display refreshes or fail when another session's display cannot rebuild.
Reason: The established feature owner proposes a smaller implementation using an existing readiness contract, with bounded comparative measurements and a relevant failure regression.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep open: this PR makes a useful, focused improvement that current main still lacks, and source review found no introduced correctness defect.

Priority: P2
Reviewed head: 49886f8c40b3474cb09898d6d524f3dff0634669

Before merge

  • Complete next step - Resolve the author's explicit merge hold after the exact-head one-resolve-per-second comparison completes.

Findings

None.

Tests

  • Missing end-to-end proof: Supplied RPC-handler measurements exclude shipped WebSocket transport and production-load effects.
Agent review details

How this fits together

Gateway session resolution accepts keys, IDs, labels, and references, prepares projection metadata, applies current visibility rules, and returns canonical session targets or ambiguity errors.

flowchart TD
A[Client session selector] --> B[Gateway resolve handler]
B --> C[Prepared session resolver]
C --> D[Session row projection]
D --> E[Worker metadata reads]
D --> F[Background display refresh]
C --> G[Current visibility and selection]
G --> H[Canonical target response]
Loading

Technical review

Best possible solution:

Use the existing selection-preparation owner while preserving exact-key readiness, ACP checks, and synchronous current-viewer resolution.

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

Current main visibly awaits the entire display drain for discovery selectors, and the supplied RPC regression targets a sibling display failure; this read-only review ran no target code.

Is this the best way to solve the issue?

The change addresses the dependency at its existing owner rather than adding caching or suppressing failures, while preserving metadata reconciliation and response-boundary visibility checks.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Discovery session preparation changes intended behavior with a stated reason (0bbad56: Prepare durable session facts in workers before synchronous authorization and response publication; the later ACP migration retained this structure and added canonical metadata preparation.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source -5, Tests +47, Docs +1. Total +43 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 15 20 -5
Tests 1 47 0 +47
Docs 1 3 2 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 65 22 +43

Review metrics

Metric Value Why it matters
Production versus regression growth Production +15/-20; tests +47/-0 The production path shrinks, and the added RPC regression protects independence from unrelated display failures.

Labels

Label changes:

  • add P2: Broad invalidation can delay or reject a session lookup because of unrelated display work; the repair has a focused Gateway scope.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: Broad invalidation can delay or reject a session lookup because of unrelated display work; the repair has a focused Gateway scope.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • 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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

Reviewed October 11, 2026, 7:39 AM ET / 11:39 UTC.

@steipete

Copy link
Copy Markdown
Contributor Author

The author’s temporary validation hold is resolved. The final candidate tree exactly matches head 49886f8c40b3474cb09898d6d524f3dff0634669.

The slower-cadence comparison (2,000 sessions, approximately 18.4 writes/second, one-second gaps between requests, 30 samples per version) measured raw-ID average 726.1 → 338.9 ms, median 711.4 → 329.3 ms, and p99 944.1 → 536.0 ms. The 100 ms cold p99 target remains unmet; the improvement is 2.14× on average.

All 78 focused tests passed on that candidate tree, and required CI run 38136002901 passed on the exact PR head. Independent review and ClawSweeper identified no introduced code defect. The PR body now contains final measurements, test cost, and the remaining measurement limits.

@steipete
steipete merged commit f3a442c into main Oct 11, 2026
222 of 225 checks passed
@steipete
steipete deleted the steipete/perf-micro-sessions-resolve-cold-rebuild-20260919 branch October 11, 2026 12:01
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 12, 2026
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Oct 19, 2026
First-parent upstream 75df19c..5ed6a30 (23 commits, including
openclaw#169005 infrastructure SQLite work and runtime-write offload, openclaw#169062,
openclaw#136677, openclaw#169070, openclaw#168857 plugin-sdk SQLite runtime writes into workers,
openclaw#169038, openclaw#168916, openclaw#169053, openclaw#169052 closed-turn transcript work in
workers, openclaw#168974, openclaw#168811, openclaw#169082, openclaw#169084, openclaw#166581 worker heap limits).

Conflicts:
- openclaw-state-worker-runtime.ts: upstream routes more update-run
  mutations to the worker; our continuation custody dispatch stays ahead
  of that branch.
- worker-access inventory: regenerated (632 files, 2429 calls).

server-restart-sentinel.ts auto-merged: upstream's awaited update-run
writes; our continuation restart delivery is unaffected.

Refs #1475

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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: S 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