Repository navigation
perf(gateway): serve transcript pages as transferred bytes instead of cloning entry objects onto the main thread - #163771
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 2, 2026, 6:39 PM ET / 22:39 UTC (Revision 2). ClawSweeper reviewWhat this changesThe PR prepares and transfers chat-history JSON bytes in the history worker, preserves presentation metadata, and delays local TUI model preparation until startup maintenance finishes. Merge readiness✅ Ready for maintainer review The optimization remains useful: current main and the latest release retain the size/content exclusions and buffer-copying behavior. No actionable correctness or security defect was found in the introduced patch. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway history subsystem reads stored conversations, prepares bounded display pages, and returns them to chat clients. This change moves presentation and serialization into its worker while preserving the Gateway’s final access and model-visibility checks. flowchart LR
A[Chat history request] --> B[Session selection]
B --> C[History worker]
D[Stored transcript] --> C
E[Profile and automation metadata] --> C
C --> F[Transferred JSON bytes]
F --> G[Current access and model checks]
G --> H[Chat history response]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +17, Tests +195, Docs +9. Total +221 across 20 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep one worker-owned presentation and serialization path, with explicit object adapters and current permission checks at response publication. Do we have a high-confidence way to reproduce the issue? Yes, source establishes the copying path and current encoding exclusions; the supplied production-handler benchmark measures their cost. This review did not execute a runtime reproduction. Is this the best way to solve the issue? Yes, extending the existing worker and serializer owners removes copying while retaining object adapters, pagination, legacy metrics, and final visibility policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 9feb364cc960. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
9895b44 to
336edc5
Compare
… cloning entry objects onto the main thread (openclaw#163771) * perf(gateway): transfer transcript page bytes from workers * fix(tui): prepare model runtime after session maintenance
What Problem This Solves
Concurrent chat history requests still copy worker reply buffers, and smaller pages or pages with profile, automation, or compaction metadata return complete message objects to the Gateway thread.
User Impact
Durable history pages keep their existing JSON, pagination, redaction, sharing, and model-visibility behavior while moving page presentation and serialization into the history worker. No schema, stored transcript, retention, configuration, or update changes are required.
Why This Change Was Made
The existing large-page byte path did not transfer its buffer and the coalesced-read owner cloned that buffer for followers. The worker now transfers its owned UTF-8 array, and coalesced readers share the immutable bytes with separate mutable metadata. Profile avatars and automation labels resolve through their existing shared-state owners before serialization. Legacy compaction token metrics travel as prepared facts. This removes size/content eligibility scans, duplicate host decoration, and duplicate entry capture.
Explicit object adapters, operator model restrictions, cursor deltas, and HTTP/SSE readers retain their existing contracts. Current sessions.messages.subscribe replays pending approvals, not transcript pages; cursor replay is measured separately.
Production delta after the CI repair: 123 additions / 106 deletions, net +17 lines. The 20-line legacy metric adapter preserves the documented pre-removal compaction-checkpoint upgrade contract without transferring stored archive paths or unrelated entry metadata; the rest of production is net -3 lines, including one comment explaining startup ordering.
CI exposed an existing embedded-startup race: model preparation acquired an auth read owner while session maintenance could retire its database. The follow-up moves initial model publication behind maintenance and joins config-listener registration during shutdown. The original CI shard reproduces the failure on the old code; the repaired owner passes it.
Evidence
Small tail pages use 64–66% less sampled main-thread heap allocation and 43–50% less main-thread CPU. Already-encoded large tail pages use 16–24% less CPU, with essentially unchanged sampled heap.
The synthetic Node 26.8.1 Linux rig exercises the actual
chat.historyhandler and production frame serializer with 2,000 entries, 500 append/read rounds, and 3 or 10 readers. Complete content, identity, and order are checked outside the measured region. It does not measure network/socket latency.The coalesced byte-buffer regression fails on the original owner for both first-reader and last-reader cancellation; retained object-isolation and capacity cases pass. Earlier proof ran on
blacksmith-testboxleasetbx_01m3yzvnjat2z8005zms2dfwjs. Final continuation validation is recorded below.Node 26.8.1 synthetic benchmark measurements
Before → after. Tail and replay phases each contain 100 rounds; append phases contain 500 appends and read rounds, starting from 2,000 entries. Append-phase heap includes append/projection work; CPU/page measures the read group only. Heap is sampled V8 allocation including collected objects and excludes external ArrayBuffer backing storage. Tail pages contain 200 messages; cursor replay contains 100. Each fixture uses deterministic synthetic text, verifies complete message content/identity/order, and checks the final appended head. Session presentation timestamps are excluded only from replay hash comparisons.
The unchanged replay path still allocates roughly 8 MB/page with 4 KiB source messages and remains follow-up work. Timing varies across cells; the 10-reader large-page tail p95 and replay timings did not improve. These are production-handler/frame-serialization measurements, not socket latency or a production deployment.
Validation and Follow-up
All heavy checks ran on provider blacksmith-testbox, profile openclaw-check. All task leases were stopped after use. Source/head checks preceded validation, and all rebases preserved the stable patch identity. The final head is
336edc5af7d0, based on maina97e007542ef; final CI validates that rebased tree.tbx_01m3z2eeg1mtd27gbq84hamcjdnode scripts/check-changed.mjs --stagednode scripts/run-vitest.mjs <nine focused files> --maxWorkers=1pnpm buildtbx_01m3z6jqmg51eprvx91c9jst0fsrc/tui/embedded-backend.test.ts, vianode scripts/run-vitest.mjs ... --maxWorkers=1tbx_01m3z9njqf770skz6ddqprd684node scripts/check-changed.mjs --stagedfor the startup repairThe nine history files cover transfer/schema behavior, automation labels, worker replies, cursor history, coalesced reads, legacy metrics, CLI-imported anchors, model visibility, and read-only worker boundaries. Changed-file test execution was 0.66s for transfer/schema, 4.18s for automation labels, 7.06s for history-worker behavior, 6.49s for cursor history, and 0.56s for coalesced handoff. The three wrapper shards took 107.14s, 19.19s, and 9.36s. History proof ran on base
2ea5f1b5907aplus the history patch; startup proof ran on published head9895b4411827plus the repair.Initial CI 37062649719 exposed the startup race in
checks-node-changed-compact-small-14. Its test step took 173.56s; the failing child shard took 42.73s. The original trio (session-list-viewers.perf,session-message-events, andsessions-list-persisted-worker) reproduced the same auth-owner failure on the old startup method in 42.26s, then passed with the repair. Shutdown coverage also verifies that a listener installed after shutdown begins is unregistered. Final CI 37073163314 passed for336edc5af7d0: all 76 workflow jobs completed successfully or were intentionally skipped, with no failing jobs. Workflow wall time was 469s (7m49s); aggregate Node-job time, including setup, was 4,026s. The PR-level rollup reported 78 passing checks and no failed or pending checks.Independent Codex reviews of the history change and final startup repair completed scoped-clean, exit 0, with no findings at the configured P0 threshold. Each received the full 3,600-second engine allowance and returned normally. Fixture lint issues were corrected without suppressions. Native checksum-sync timeouts required a clean replacement lease; no check was bypassed. An initial baseline worktree had incomplete workspace dependency links and failed before collection; it is excluded from regression evidence.
Known limits: the earlier import-closure failure followed the unchanged provider-failover → plugin-loader → auth-store chain and reproduced on the original page kernel. The prior Linux rig measured the actual source handler and production serializer, not a dist-Gateway WebSocket connection or production traffic. Its worktree was removed. Cursor replay still allocates about 8 MB/page with 4 KiB source messages and needs a separate worker-byte cutover; this PR does not claim to improve it.