Skip to content

perf(gateway): keep chat admission metadata off the history queue - #166365

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-chat-send-request-authority-admission-20260919
Oct 7, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-chat-send-request-authority-admission-20260919

Conversation

@steipete

@steipete steipete commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

chat.send could wait behind unrelated transcript-history reads while authorizing a request, admitting its run, or preparing durable input. An ordered metadata read could hold the database writer FIFO while waiting on the single history worker.

User Impact

Hot-session input can be persisted and acknowledged while history dispatch is blocked. Exact session rows, target discovery, transcript identity selection, and bounded cold-archive metadata use the existing projection worker. Writer FIFO ordering, current permissions, source replacement checks, and durable input custody remain intact. There are no schema, configuration, retention, or update changes.

Why This Change Was Made

Metadata discovery and payload reads selected different workers. Use the metadata worker consistently, remove the unused inventory lane parameter, and remove the discovery-only lane fallback. Transcript corpus/archive payloads and maintenance retain their existing owners.

Production LOC delta: +14. The generic reader also serves transcript payloads, so the metadata operations must select the existing projection lane explicitly; transcript target selection also retains its lazy worker/incognito boundary. Most added lines are argument/import formatting. No new pool, cache, wrapper, or configuration option is introduced.

Evidence

Benchmarks and runtime tests ran with provider blacksmith-testbox, profile openclaw-check, on Linux x86_64 / Node 24.19.0. Paired measurements and the first full staged gate used lease tbx_01m499e9p8c3pwdkxrq7kqyt11 on base cc7e664dfe34. The full staged gate also passed after rebase to 8f5c33c30d71 on the Linux rig fallback (node scripts/check-changed.mjs --staged, exit 0, approximately 50 minutes). Fresh-lease integration proof passed on tbx_01m49cshscnkd5rn7tva92rwrp: core production types and 63 tests covering exact reads, worktree-owner projection, managed owner policy, and durable ACK; total command 2m23s.

On tbx_01m49wfjav8vbwxmsdrw22nrad, base 0288eb1f3692, core production types and 218 tests across 16 focused files passed in 6m51s. The three corrected race fixtures passed all 58 tests in 2m24s. Their staged gate and a full 227-case registry lifecycle replay passed in 6m14s. The final branch is rebased onto 98567acd6060; SHA-256 verification confirms all 17 reviewed files are byte-for-byte unchanged. The earlier results are prior-base evidence; hosted CI checks the final integration. All four leases are stopped/expired.

The RPC router/handler and SQLite rig ran 64 sends at concurrency eight, alongside four continuous synthetic history readers and post-ACK preparation. Provider execution was mocked after ACK. Same baseline revision, synthetic data, and lease:

Request latency Before After Reduction
p50 6,451 ms 979 ms 84.8%
p95 17,257 ms 3,339 ms 80.7%
p99 / max 18,234 ms 3,470 ms 81.0%
mean 7,548 ms 1,273 ms 83.1%

Afterward, all 1,500 history-worker requests were background page reads; foreground metadata used the projection worker. Harness RSS after the run was 2.995 GB before and 3.193 GB after; these are whole test-process measurements, including worker heaps and retained synthetic turns.

A second paired run waited for warm startup, then measured 32 requests with one send outstanding and the same four background history readers:

Warm request latency Before After
p50 2,250 ms 188 ms
p95 3,036 ms 323 ms
p99 / max 16,280 ms 2,246 ms
mean 2,710 ms 264 ms

Both workloads still exceed the 150 ms p50 / 500 ms p99 targets. The warm median is below 300 ms. The remaining 2,245 ms warm tail records 2,094 ms in authority, 9 ms in admission, 77 ms in persistence, and 65 ms in run admission. Repeated authority preparation and production latency still need finer attribution; this change removes the proven history-queue dependency without relaxing authority or durability.

  • The full router → durable transcript → ACK regression passes with history dispatch held. The original revision times out waiting for ACK under the same gate (the existing 120-second Vitest deadline), confirming the regression catches the old dependency.
  • Broader owner/sibling coverage: 167 tests passed across 12 files. After the transcript-target and cold-metadata cutover, 71 relevant tests passed, including cold restore authority, physical replacement, first registration, run admission, and ACK-before-skill-preparation behavior.
  • pnpm test src/gateway/server-methods/chat-send-preparation-ack.test.ts --maxWorkers=1: 5 passed; 38.85 s runner wall time including worker compilation; 10.93 s test time. The new case took 3.67 s. Real router authorization and SQLite custody are required to prove a durable ACK; helper-only tests would miss the persistence dependencies. Added Linux test execution cost: approximately 3.7 seconds per run, measured on Testbox; hosted per-case timing was not collected.
  • node scripts/check-changed.mjs --staged: passed on the paired measurement base in 27m53s, including all 27 core test type graphs, lint, dead-export, cycle, and storage guards. Every reviewed file matched its recorded SHA-256.
  • Independent Codex reviews of the production scope and final three test corrections: scoped-clean, no actionable P0/P1 findings.
  • Three additional test fixtures now inject metadata races/errors through the projection worker: native model ownership, diff-baseline generation, and SDK transcript-target locking. All 58 tests in those files passed on the fresh lease in 2m24s; their assertions are unchanged. The scoped staged gate selected and passed the agents-other, other, and plugin-sdk type graphs, lint, and dead-export checks.
24-hour slow-send attribution

The journal query covered 2026-10-05 19:00:50Z through 2026-10-06 19:00:50Z and yielded 77 request and 99 startup records. These are conditional slow-stage distributions: the logger excludes stages below 1,000 ms. Timers include awaited/scheduling time and can overlap; they are not exclusive CPU measurements. Missing fields are absent samples. Nearest-rank p99 equals max for these sample counts.

Stage / phase Samples p50 ms p95 ms p99 / max ms
Request total 77 3,418 5,611 6,951
Authority 77 1,429 2,267 2,748
Admission 77 273 469 685
Attachments 77 0 11 285
Persistence 77 566 1,234 2,815
Preparation 77 0 1 8
Reply context 77 0 83 116
Run admission 77 1,135 2,314 2,402
Effects 77 0 0 0
Response 77 1 1 2
Startup total 99 5,674 102,321 3,288,574
Startup ACK (repeated request duration) 99 3,158 4,851 6,951
Startup authoring 95 1 6 9
Startup preparation 95 3,532 5,951 3,046,035
Startup reply initialization 95 1,612 80,753 356,488
Startup reply context 99 0 0 129
Startup worktree 13 3,575 5,131 5,131
Startup dispatch 99 15 544 8,757

The 54.8-minute startup record had already ACKed in 250 ms and began after that process started. It does not establish pre-ACK blocking or unfinished work from the earlier restart. Source tracing and the blocked-history regression establish the metadata-worker dependency fixed here; they do not attribute every production tail.

Related: #165608.

Hosted CI investigation and remaining upstream failures

Final-head CI run 37556779529, head 3292922b0e82, completed with 79 successful jobs, 24 skipped jobs, two failed test jobs, and the failed aggregate gate. The stale metadata-race fixtures are corrected. No CI rerun was requested.

  • MCP fixture routing: all ten mcp-http.session-controls.test.ts cases fail during tool/auth preparation before the session action. On unchanged base 0288eb1f3692, pnpm exec vitest run --config test/vitest/vitest.gateway-core.config.ts src/gateway/mcp-http.session-controls.test.ts --maxWorkers=1 -t 'MCP dispatch preserves archive final-effect authority: allowed' fails with the identical Shared-state admission requires the host broker; adding --pool=forks passes. Upstream fix: hide web search when no provider is configured #166199 moved the sibling question-authority fixture into the fork-backed database-worker lane but omitted this fixture. This branch does not change its routing.
  • History expectation after the new base: chat.history advances past a replay boundary that cannot fit all projected siblings still expects only sequence 2 on page one. Upstream perf(gateway): bound anchored history pages and message groups #166263 now compresses an oversized source group into a fetchable placeholder before capping, allowing the older sequence-1 message to fit on the same page. The fixture and paging owner are byte-identical between base 98567acd6060 and this branch. The exact filtered case also fails on unchanged base 98567acd6060 on blacksmith-testbox lease tbx_01m49zrpad1bfnzpwb9wp7t3tz: a diagnostic print before the unchanged assertion captured sequences: [1, 2] and hasMore: false. The test exited 1 as expected; the probe command completed in 1m35s, restored the test, removed its temporary worktree, and the lease is stopped. No history behavior is changed here.

The initial CI run also reported one remaining fake timer in subagent-registry-lifecycle.test.ts, case preserves cleanup exhaustion when another run settles (related=true). The complete 227-case file passed separately on unchanged base and candidate, and the corrected head's CI no longer reports it. The original failure remains unexplained; passing replays are not claimed as a fix, and no assertion was weakened.

@clawsweeper

clawsweeper Bot commented Oct 7, 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 enabled auto-merge (squash) October 7, 2026 00:34
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: M labels Oct 7, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 7, 2026
@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 11:41 PM ET / October 7, 2026, 03:41 UTC (Revision 5).

ClawSweeper review

What this changes

Routes session metadata reads through the existing projection worker so chat input can be persisted and acknowledged while transcript history is busy.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main retains the history-queue dependency, and the introduced changes preserve the existing read and write safeguards. No actionable introduced defects or additional review blockers were found.

Priority: P2
Reviewed head: a5137d64c8400a159cfe62c0cffa2a5a8d425e6e

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with strong boundary measurements and preserved race coverage; no actionable patch defect remains.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Captured Linux Testbox evidence exercises the real RPC router and SQLite admission/persistence owners under concurrent or blocked history dispatch, showing durable ACK recovery and paired latency improvements. Provider execution is mocked after ACK, outside the changed boundary. Results remain prior-base evidence; no stored-data contract changes require migration proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Captured Linux Testbox evidence exercises the real RPC router and SQLite admission/persistence owners under concurrent or blocked history dispatch, showing durable ACK recovery and paired latency improvements. Provider execution is mocked after ACK, outside the changed boundary. Results remain prior-base evidence; no stored-data contract changes require migration proof.
Evidence reviewed 9 items Pinned introduced change: Reviewed the merge-base-to-head delta using the host-pinned identities. Production changes select the existing projection lane, remove the unused inventory lane argument, and align discovery with the selected reader lane.
Current main still needs the change: Fetched main still omits the projection lane for the exact read-only entry path and retains the sharing-only discovery fallback. The supplied merged related PRs address different preparation or history-page work, rather than this worker dependency.
Existing worker and lifecycle ownership: The projection lane already uses the same worker implementation and participates in database custody, revocation, cleanup, and runtime shutdown. This PR adds no worker pool or alternate state owner.
Findings None None.
Security None None.

How this fits together

The Gateway reads session metadata to authorize chat requests, select their storage, and admit durable input. These reads share database ownership and ordering safeguards with transcript storage, while history pages run on a separate worker.

flowchart TD
  A[Chat request] --> B[Session metadata worker]
  B --> C[Current authority and source checks]
  C --> D[Ordered input persistence]
  D --> E[Durable acknowledgement]
  F[History requests] --> G[Transcript history worker]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +14, Tests +59, Docs +6. Total +79 across 17 files.

View PR surface stats
Area Files Added Removed Net
Source 5 49 35 +14
Tests 11 120 61 +59
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 17 175 96 +79

Review metrics

Metric Value Why it matters
Production versus test growth production net +14 lines; tests net +59 lines Production growth is justified by explicit selection of the existing metadata worker, with regression coverage at the durable acknowledgement boundary.

Technical review

Best possible solution:

Keep metadata on the existing projection worker while retaining writer ordering, live authority checks, and the history worker for transcript payloads.

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

Yes: current source routes admission metadata through the single history worker, and the supplied blocked-history router regression establishes the failing boundary. This review did not execute a current-main reproduction.

Is this the best way to solve the issue?

Yes: selecting the existing metadata worker removes the demonstrated dependency without adding parallel policy, storage, configuration, or public SDK surface.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded Gateway responsiveness improvement with measured benefits under history contention.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Captured Linux Testbox evidence exercises the real RPC router and SQLite admission/persistence owners under concurrent or blocked history dispatch, showing durable ACK recovery and paired latency improvements. Provider execution is mocked after ACK, outside the changed boundary. Results remain prior-base evidence; no stored-data contract changes require migration proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. Captured Linux Testbox evidence exercises the real RPC router and SQLite admission/persistence owners under concurrent or blocked history dispatch, showing durable ACK recovery and paired latency improvements. Provider execution is mocked after ACK, outside the changed boundary. Results remain prior-base evidence; no stored-data contract changes require migration proof.

Evidence

What I checked:

  • Pinned introduced change: Reviewed the merge-base-to-head delta using the host-pinned identities. Production changes select the existing projection lane, remove the unused inventory lane argument, and align discovery with the selected reader lane. (src/config/sessions/session-entry-read-runtime.ts:153, a5137d64c840)
  • Current main still needs the change: Fetched main still omits the projection lane for the exact read-only entry path and retains the sharing-only discovery fallback. The supplied merged related PRs address different preparation or history-page work, rather than this worker dependency. (src/config/sessions/session-entry-read-runtime.ts:151, 639070bb0972)
  • Existing worker and lifecycle ownership: The projection lane already uses the same worker implementation and participates in database custody, revocation, cleanup, and runtime shutdown. This PR adds no worker pool or alternate state owner. (src/config/sessions/session-transcript-worker-resources.ts:165, a5137d64c840)
  • Ordering and authorization preserved: Ordered exact reads still enter the database writer FIFO, capture native mutation witnesses, reject changed sources, and require synchronous consumers. Worker selection does not change the principals permitted to act or create a new authority-bearing contract. (src/config/sessions/session-entry-read-ordered.ts:58, a5137d64c840)
  • Durable ACK regression: The added case blocks history dispatch, invokes the real Gateway request router through the existing fixture, and verifies both the started acknowledgement and persisted user transcript. The fixture mocks execution only after ACK; authorization and SQLite custody remain real. (src/gateway/server-methods/chat-send-preparation-ack.test.ts:19, a5137d64c840)
  • Captured production-boundary proof: The supplied PR body, captured under sourceRevision 29a27713ad6e7057458d929b758ae618dba582db9b29c411808fbfb74ef85469, records Linux Testbox runs through the RPC router/handler and real SQLite with concurrent history reads. Contended p50 improved from 6451 to 979 ms; warm p50 improved from 2250 to 188 ms. The blocked-history regression reportedly times out before the fix and acknowledges durable input afterward. These measurements prove the scoped queue dependency improvement, not attainment of the broader latency targets.

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • RomneyDa: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (4 earlier review cycles)
  • reviewed 2026-10-07T00:39:46.414Z sha aa202093ccdf0b6af8a9f4cce39610c798c42a83 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-07T01:29:46.128Z sha 3292922 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-07T01:47:32.145Z sha 3292922 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-07T02:07:56.736Z sha 3292922 :: needs maintainer review before merge. :: none

Route exact session reads, store inventory, transcript target selection,
and cold metadata preflight through the existing projection worker.
Preserve writer FIFO, source fences, and durable input custody.

Remove split discovery routing and the unused inventory lane parameter.
Keep native ownership, diff baseline, and SDK transcript target race fixtures on the worker that now owns their metadata reads. Preserve all existing failure and authority assertions.
@steipete
steipete force-pushed the steipete/perf-micro-chat-send-request-authority-admission-20260919 branch from aa20209 to 3292922 Compare October 7, 2026 01:22
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Oct 7, 2026
@steipete
steipete merged commit d6c9fd8 into main Oct 7, 2026
145 of 158 checks passed
@steipete
steipete deleted the steipete/perf-micro-chat-send-request-authority-admission-20260919 branch October 7, 2026 08:23
@steipete

steipete commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Merged as d6c9fd84e3cd39b7abaf5a32bf3c287a001a571b using the pinned-head inherited-failure exception. The landed tree was independently verified against the reviewed head and its actual main parent.

Pinned-head inherited-failure qualification is complete for a5137d64c8400a159cfe62c0cffa2a5a8d425e6e. CI run 37567443775 remains red: all 57 observed cases across 11 failed Node jobs have independent main-baseline evidence. The aggregate gate is downstream of those jobs; failed CI is not being relabeled green.

The inherited failures cover the reconcile pool/lifecycle fixtures' one-idle-executor assumptions; the cron registry-maintenance retained-store byte assertion; closed agent-execution admission during Gateway chat/session/Talk/history fixture writes; the oversized history replay-boundary expectation; board-store publication/cleanup error wording; worker live-event completion assertions; and plugin retirement's direct/explicit cleanup assertions. Matching cases and errors appear in main CI runs 37567947157, 37559068121, and 37563803327, supplemented by isolated Linux reproductions on unchanged main 27ba9720f2c5bad0326fee928ddb562340e0517d. Four sessions-list failures required preserving each successful immediate predecessor before its failing fixture seed; all four reproduced on Node 24.19.0 with the same Agent database execution admission is closed stack.

Every declared failing test/fixture/producer source blob is unchanged between its qualifying main baseline, the actual CI merge's first parent e7546f2e40cc1d75d3a253fae40243be0eea8548, and tested merge 82d70a3a9e28bb15b16fd5477b3aa9a35fb868d9. This PR selects the existing projection worker for metadata reads; it does not change the independently failing executor, fixture, registry-maintenance, board, or plugin-loading owners. Source equality supports the independent reproductions; it is not the sole attribution evidence.

Additional exact-head sibling validation ran on blacksmith-testbox tbx_01m4ag5cy05a35sse2ktcmve0b, with command time 46m15.547s, overall exit 1, and the lease stopped afterward. Combined complete hosted and remote file outcomes are 1,435 passed, 15 failed, and 18 gated/skipped out of 1,468 direct siblings. All 20 additional remote failures are also baseline-qualified: 15 swarm-collector and one terminal test fail host-broker admission during tool preparation; three queued-follow-up cases fail fixture execution admission; and the real HTTP workspace-plugin test reproduces registration count 2 instead of 1 on unchanged main in 70.10s. The latter retains the real isolated source Gateway and synthetic CJS plugin through the supported fixture-owned E2E route.

Passing proof includes all 11 changed test files (187 cases), export-name collision checking, eager-import closure (17 cases), wrapper-source closure (3 cases), 12 additional synthetic E2E files (28 cases), and both isolated synthetic process rigs. Guarded live collection recorded 193 passed and 37 skipped cases; those skips are not claimed as live provider/device proof. No CI rerun, branch update, or workflow dispatch was used for this qualification. The exact-head admin exception remains subject to the native review, security, authority, and final-head gates.

steipete added a commit that referenced this pull request Oct 7, 2026
…e checks

Main moved ordered metadata reads to the projection lane in #166365.
Retire that cache before checking for leaked request registrations, preserving
all existing response, authority, and no-resource assertions.

A diagnostic at the integrated head reproduced the failure and identified
only the idle projection reader's physical path and alias. Both corrected
files pass all 112 cases locally. Fresh P2 review, targeted types, lint, and
formatting pass. Production source is byte-identical to 853cefe.
steipete added a commit that referenced this pull request Oct 7, 2026
* perf(session-readers): reuse captured admission facts

* chore(session-readers): shrink assertion safety baseline

* refactor(session-readers): keep index collector private

* refactor(session-readers): make custody predicates explicit

* test(session-readers): retire the current projection cache in lifetime checks

Main moved ordered metadata reads to the projection lane in #166365.
Retire that cache before checking for leaked request registrations, preserving
all existing response, authority, and no-resource assertions.

A diagnostic at the integrated head reproduced the failure and identified
only the idle projection reader's physical path and alias. Both corrected
files pass all 112 cases locally. Fresh P2 review, targeted types, lint, and
formatting pass. Production source is byte-identical to 853cefe.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 8, 2026
…enclaw#166365)

## What Problem This Solves

`chat.send` could wait behind unrelated transcript-history reads while authorizing a request, admitting its run, or preparing durable input. An ordered metadata read could hold the database writer FIFO while waiting on the single history worker.

## User Impact

Hot-session input can be persisted and acknowledged while history dispatch is blocked. Exact session rows, target discovery, transcript identity selection, and bounded cold-archive metadata use the existing projection worker. Writer FIFO ordering, current permissions, source replacement checks, and durable input custody remain intact. There are no schema, configuration, retention, or update changes.

## Why This Change Was Made

Metadata discovery and payload reads selected different workers. Use the metadata worker consistently, remove the unused inventory lane parameter, and remove the discovery-only lane fallback. Transcript corpus/archive payloads and maintenance retain their existing owners.

Production LOC delta: **+14**. The generic reader also serves transcript payloads, so the metadata operations must select the existing projection lane explicitly; transcript target selection also retains its lazy worker/incognito boundary. Most added lines are argument/import formatting. No new pool, cache, wrapper, or configuration option is introduced.

## Evidence

Benchmarks and runtime tests ran with provider `blacksmith-testbox`, profile `openclaw-check`, on Linux x86_64 / Node 24.19.0. Paired measurements and the first full staged gate used lease **`tbx_01m499e9p8c3pwdkxrq7kqyt11`** on base `4a96fff224ff`. The full staged gate also passed after rebase to `66cf8a4c0732` on the Linux rig fallback (`node scripts/check-changed.mjs --staged`, exit 0, approximately 50 minutes). Fresh-lease integration proof passed on **`tbx_01m49cshscnkd5rn7tva92rwrp`**: core production types and 63 tests covering exact reads, worktree-owner projection, managed owner policy, and durable ACK; total command 2m23s.

On **`tbx_01m49wfjav8vbwxmsdrw22nrad`**, base `fd7d42fa5176`, core production types and 218 tests across 16 focused files passed in 6m51s. The three corrected race fixtures passed all 58 tests in 2m24s. Their staged gate and a full 227-case registry lifecycle replay passed in 6m14s. The final branch is rebased onto `772d281b298f`; SHA-256 verification confirms all 17 reviewed files are byte-for-byte unchanged. The earlier results are prior-base evidence; hosted CI checks the final integration. All four leases are stopped/expired.

The RPC router/handler and SQLite rig ran 64 sends at concurrency eight, alongside four continuous synthetic history readers and post-ACK preparation. Provider execution was mocked after ACK. Same baseline revision, synthetic data, and lease:

| Request latency | Before | After | Reduction |
|---|---:|---:|---:|
| p50 | 6,451 ms | 979 ms | 84.8% |
| p95 | 17,257 ms | 3,339 ms | 80.7% |
| p99 / max | 18,234 ms | 3,470 ms | 81.0% |
| mean | 7,548 ms | 1,273 ms | 83.1% |

Afterward, all 1,500 history-worker requests were background page reads; foreground metadata used the projection worker. Harness RSS after the run was 2.995 GB before and 3.193 GB after; these are whole test-process measurements, including worker heaps and retained synthetic turns.

A second paired run waited for warm startup, then measured 32 requests with one send outstanding and the same four background history readers:

| Warm request latency | Before | After |
|---|---:|---:|
| p50 | 2,250 ms | 188 ms |
| p95 | 3,036 ms | 323 ms |
| p99 / max | 16,280 ms | 2,246 ms |
| mean | 2,710 ms | 264 ms |

**Both workloads still exceed the 150 ms p50 / 500 ms p99 targets.** The warm median is below 300 ms. The remaining 2,245 ms warm tail records 2,094 ms in authority, 9 ms in admission, 77 ms in persistence, and 65 ms in run admission. Repeated authority preparation and production latency still need finer attribution; this change removes the proven history-queue dependency without relaxing authority or durability.

- The full router → durable transcript → ACK regression passes with history dispatch held. The original revision times out waiting for ACK under the same gate (the existing 120-second Vitest deadline), confirming the regression catches the old dependency.
- Broader owner/sibling coverage: 167 tests passed across 12 files. After the transcript-target and cold-metadata cutover, 71 relevant tests passed, including cold restore authority, physical replacement, first registration, run admission, and ACK-before-skill-preparation behavior.
- `pnpm test src/gateway/server-methods/chat-send-preparation-ack.test.ts --maxWorkers=1`: 5 passed; 38.85 s runner wall time including worker compilation; 10.93 s test time. The new case took 3.67 s. Real router authorization and SQLite custody are required to prove a durable ACK; helper-only tests would miss the persistence dependencies. Added Linux test execution cost: approximately 3.7 seconds per run, measured on Testbox; hosted per-case timing was not collected.
- `node scripts/check-changed.mjs --staged`: passed on the paired measurement base in 27m53s, including all 27 core test type graphs, lint, dead-export, cycle, and storage guards. Every reviewed file matched its recorded SHA-256.
- Independent Codex reviews of the production scope and final three test corrections: scoped-clean, no actionable P0/P1 findings.
- Three additional test fixtures now inject metadata races/errors through the projection worker: native model ownership, diff-baseline generation, and SDK transcript-target locking. All 58 tests in those files passed on the fresh lease in 2m24s; their assertions are unchanged. The scoped staged gate selected and passed the `agents-other`, `other`, and `plugin-sdk` type graphs, lint, and dead-export checks.

<details>
<summary>24-hour slow-send attribution</summary>

The journal query covered 2026-10-05 19:00:50Z through 2026-10-06 19:00:50Z and yielded 77 request and 99 startup records. These are **conditional slow-stage distributions**: the logger excludes stages below 1,000 ms. Timers include awaited/scheduling time and can overlap; they are not exclusive CPU measurements. Missing fields are absent samples. Nearest-rank p99 equals max for these sample counts.

| Stage / phase | Samples | p50 ms | p95 ms | p99 / max ms |
|---|---:|---:|---:|---:|
| Request total | 77 | 3,418 | 5,611 | 6,951 |
| Authority | 77 | 1,429 | 2,267 | 2,748 |
| Admission | 77 | 273 | 469 | 685 |
| Attachments | 77 | 0 | 11 | 285 |
| Persistence | 77 | 566 | 1,234 | 2,815 |
| Preparation | 77 | 0 | 1 | 8 |
| Reply context | 77 | 0 | 83 | 116 |
| Run admission | 77 | 1,135 | 2,314 | 2,402 |
| Effects | 77 | 0 | 0 | 0 |
| Response | 77 | 1 | 1 | 2 |
| Startup total | 99 | 5,674 | 102,321 | 3,288,574 |
| Startup ACK (repeated request duration) | 99 | 3,158 | 4,851 | 6,951 |
| Startup authoring | 95 | 1 | 6 | 9 |
| Startup preparation | 95 | 3,532 | 5,951 | 3,046,035 |
| Startup reply initialization | 95 | 1,612 | 80,753 | 356,488 |
| Startup reply context | 99 | 0 | 0 | 129 |
| Startup worktree | 13 | 3,575 | 5,131 | 5,131 |
| Startup dispatch | 99 | 15 | 544 | 8,757 |

The 54.8-minute startup record had already ACKed in 250 ms and began after that process started. It does not establish pre-ACK blocking or unfinished work from the earlier restart. Source tracing and the blocked-history regression establish the metadata-worker dependency fixed here; they do not attribute every production tail.

</details>

Related: openclaw#165608.

<details>
<summary>Hosted CI investigation and remaining upstream failures</summary>

Final-head [CI run 37556779529](https://github.com/openclaw/openclaw/actions/runs/37556779529), head `3292922b0e82`, completed with 79 successful jobs, 24 skipped jobs, two failed test jobs, and the failed aggregate gate. The stale metadata-race fixtures are corrected. No CI rerun was requested.

- **MCP fixture routing:** all ten `mcp-http.session-controls.test.ts` cases fail during tool/auth preparation before the session action. On unchanged base `fd7d42fa5176`, `pnpm exec vitest run --config test/vitest/vitest.gateway-core.config.ts src/gateway/mcp-http.session-controls.test.ts --maxWorkers=1 -t 'MCP dispatch preserves archive final-effect authority: allowed'` fails with the identical `Shared-state admission requires the host broker`; adding `--pool=forks` passes. Upstream openclaw#166199 moved the sibling question-authority fixture into the fork-backed database-worker lane but omitted this fixture. This branch does not change its routing.
- **History expectation after the new base:** `chat.history advances past a replay boundary that cannot fit all projected siblings` still expects only sequence 2 on page one. Upstream openclaw#166263 now compresses an oversized source group into a fetchable placeholder before capping, allowing the older sequence-1 message to fit on the same page. The fixture and paging owner are byte-identical between base `772d281b298f` and this branch. The exact filtered case also fails on unchanged base `772d281b298f` on `blacksmith-testbox` lease `tbx_01m49zrpad1bfnzpwb9wp7t3tz`: a diagnostic print before the unchanged assertion captured `sequences: [1, 2]` and `hasMore: false`. The test exited 1 as expected; the probe command completed in 1m35s, restored the test, removed its temporary worktree, and the lease is stopped. No history behavior is changed here.

The initial CI run also reported one remaining fake timer in `subagent-registry-lifecycle.test.ts`, case `preserves cleanup exhaustion when another run settles (related=true)`. The complete 227-case file passed separately on unchanged base and candidate, and the corrected head's CI no longer reports it. The original failure remains unexplained; passing replays are not claimed as a fix, and no assertion was weakened.

</details>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 8, 2026
* perf(session-readers): reuse captured admission facts

* chore(session-readers): shrink assertion safety baseline

* refactor(session-readers): keep index collector private

* refactor(session-readers): make custody predicates explicit

* test(session-readers): retire the current projection cache in lifetime checks

Main moved ordered metadata reads to the projection lane in openclaw#166365.
Retire that cache before checking for leaked request registrations, preserving
all existing response, authority, and no-resource assertions.

A diagnostic at the integrated head reproduced the failure and identified
only the idle projection reader's physical path and alias. Both corrected
files pass all 112 cases locally. Fresh P2 review, targeted types, lint, and
formatting pass. Production source is byte-identical to 853cefe.
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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant