Skip to content

perf(reply): attribute startup and avoid redundant workspace scans - #169307

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-reply-initialization-breakdown-20260919
Oct 11, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-reply-initialization-breakdown-20260919

Conversation

@steipete

@steipete steipete commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

First-message startup reported several seconds as replyInitialization without identifying which owner was waiting or working. Add subphase attribution to the existing slow chat-send diagnostics and remove repeated workspace preparation scans.

User Impact

Operators can distinguish workspace setup, session hydration, fresh snapshots, commit work, admission, prompt/skills assembly, tool catalogs, and model/auth preparation. Recently attested workspaces no longer synchronously inventory every skill to prepare expiry evidence.

Why This Change Was Made

Keep the existing replyInitialization boundary (dispatch through session preparation); prompt/tool/model assembly remains in preparation. Request-scoped observers reuse existing timeline spans, capture open spans at startup completion, and work with timeline file logging disabled. Nested measurements overlap and must not be added together.

Workspace expiry cannot proceed while an attestation is recent. That path needs directory identity checks, not full content inventories. Expired or unattested workspaces retain their content evidence and disappearance checks. There are no schema, configuration, or persisted format changes. The session-context resolver and title-listener lifecycle move to their existing preparation/background owners to keep oversized dispatch modules from growing.

Evidence

Isolated Linux Gateway, synthetic state only: 2,000 workspace source files, 128 skills, 513 configured models, 128 existing sessions with 32 KiB transcripts, Code Mode enabled. Existing activity-summary work settled through its owner before each measured wave. Real sessions.create → chat.send → agent.wait, synthetic HTTP model endpoint. Both runs completed all 21 turns.

Subphase Single before / final (ms) 20-way before avg / p95 (ms) 20-way final avg / p95 (ms)
replyInitialization 1,054 / 916 3,165 / 3,989 3,030 / 3,953
Workspace preparation 99 / 88 626 / 990 435 / 745
Session initialization 167 / 90 1,437 / 1,880 1,392 / 1,919
Session hydration 100 / 23 280 / 503 246 / 420
Session snapshot 6 / 5 333 / 493 302 / 443
Session commit 47 / 46 820 / 1,040 840 / 1,074
Git baseline 603 / 488 564 / 664 564 / 692
Skill snapshot 63 / 75 1,035 / 1,592 1,212 / 1,694
History loading unavailable / 96 unavailable 408 / 607
Actor creation unavailable / 51 unavailable 774 / 1,002
History boundary unavailable / 2 unavailable 370 / 511
Later preparation 2,166 / 2,454 8,369 / 10,022 9,498 / 11,434

The <1 s initialization p95 target was missed. The consistent measured win is workspace preparation: average 30.5% lower and p95 24.7% lower. Final initialization average improved 4.3%, while p95 was essentially flat. Final send-to-first-model timing was 15,667 ms average / 16,876 ms p95 versus 13,990 / 15,217 before; whole-startup improvement is not established. A prior candidate run measured a larger startup improvement, which was not reproduced on the final shared-host run. P95 follows the repository convention and is the maximum for this 20-sample wave.

History, actor, history-boundary, commit-fresh-read, and commit-mutation splits were added after the baseline; their before values are unavailable. Session persistence and later runtime preparation remain substantial. Parent and child spans overlap.

Final Gateway RSS was 788 MiB at readiness and 2,120 MiB after the burst. Baseline RSS was not captured, so no allocation improvement is claimed. Timings measure pre-provider work, not external provider latency.

Independent review is clean through P2 on the implementation and final lint corrections. The rig passed 273 focused tests across 17 files (six existing skips), the export-collision guard, and all 20 closure tests. The broader changed-code gate completed: production types, all 28 test-type groups, lint, dead exports, import cycles, and guards passed. Exact-head CI has one independently reproduced pre-existing failure, detailed below.

The workspace regression failed before the fix (eight synchronous skill-stat calls for one skill), then passed afterward. Per-file single-worker commands on the rig were pnpm test src/gateway/server-methods/chat-send-diagnostics.test.ts --maxWorkers=1 (18.28 s wall) and pnpm test src/agents/workspace-attestation.worker.test.ts --maxWorkers=1 (94.16 s wall, including cold worker setup). The new test bodies measured 4 ms each for the two diagnostics cases and 2.015 s for the workspace case; no test files or CI shards were added.

Initial prestart-steering runs timed out. Later baseline runs exposed SQLite FULL during teardown; after recovering disk space, the accepted case passed on current main and all three cases passed on the candidate. These are environment-affected failures, not a claimed product repair. The closure suite also first hit ENOSPC, then passed all 20 tests after cleanup. The first CI run exposed lint issues in this diff; the final corrections pass the targeted lint checks.

Blacksmith tbx_01m4p1m9hav2wvmqdwb0qe0p3w passed the initial diagnostics/timeline tests; later sync timed out. A fresh Blacksmith lease remained queued, and AWS cbx_9eaf42790ab4 and Hetzner cbx_32a4d24fb27c stalled in sync, so validation uses the authorized Linux rig fallback. All cloud leases are stopped. No test result is claimed for failed synchronization.

Production source is +102 lines net; tests are +88 and docs +18. The explicitly requested attribution contract accounts for the growth. No cache or alternate workspace-preparation implementation was added; full-content scanning is removed from the recent-attestation path.

CI disposition

Exact-head CI run 38172968600 failed only checks-node-changed-compact-small-4-1: Gateway ACP completion ownership > completes persistence failure after explicit abort once received lifecycle end without start. Its failure triggered the existing fail-fast cancellation monitor; cancelled siblings are not claimed as green.

The ACP lifecycle files are unchanged by this PR. On unchanged current-main production 072f977edd46c7134dbdb05ec00fac03f6cf8069, a controlled replay of that same test reproduced the identical assertion in both cold and warm iterations. The test wrapper held the real start-recovery read result until the original public abort emitted its real terminal event; it did not replace rows, authority, event values, or assertions. An ordinary baseline run passed, so this is explicitly a timing-sensitive reproduction. The existing delayed-start admission is rejected once abort reserves terminal publication.

Landing uses the operator-authorized inherited-failure exception. No CI rerun, update-branch, or workflow dispatch was used to chase green.

Report nested reply and runtime preparation spans in slow chat-send diagnostics. Preserve the existing initialization boundary and identify fresh reads, mutations, history, and actor preparation. Avoid full expiry inventories for recently attested workspaces while preserving disappearance guards.
@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 agents Agent runtime and tooling size: L labels Oct 11, 2026
@steipete
steipete marked this pull request as ready for review October 11, 2026 19:30
@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: ⏳ 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 maintainer review before merge.

What this changes

This PR adds detailed chat startup timings and avoids redundant skill inventories for recently attested workspaces.

Example: Twenty concurrent first turns on an isolated Linux Gateway with 128 workspace skills.

  • Before: Workspace preparation averaged 626 ms with a 990 ms p95.
  • After: Workspace preparation averaged 435 ms with a 745 ms p95; whole-startup improvement was not established.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful, supported by shipped-path measurements, and free of identified introduced defects; source inspection verifies unchanged stored formats and mutation contracts.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Supplied final measurements exercise workspace, session, and agent preparation through real Gateway RPCs on isolated Linux synthetic state, completing single-turn and concurrent workloads and reporting the new subphases.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Operators cannot locate first-message startup delays, and recently attested workspaces perform unnecessary synchronous skill inventories.
Reason: Maintainer-authored direction is established, and the measured workspace improvement plus useful attribution justify the change despite the explicitly unmet whole-startup target.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it provides useful startup attribution and a measured workspace improvement absent from main, with no actionable introduced defect found; the updated inherited-failure evidence addresses the previous CI attribution request.

Priority: P2
Reviewed head: 7396ee78cd1a5f95c9e3e54051227271a284546d

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway chat dispatch prepares workspace and session state before agent execution, while existing preparation spans feed request-owned startup diagnostics.

flowchart TD
  A[Chat send] --> B[Detached dispatch]
  B --> C[Workspace preparation]
  C --> D[Session initialization]
  D --> E[Agent preparation]
  E --> F[Model execution]
  C --> G[Startup diagnostics]
  D --> G
  E --> G
Loading

Technical review

Best possible solution:

Retain the scoped attribution and scan removal, preserving workspace safety and using the recorded inherited-failure disposition during native landing.

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

Current main captures full skill inventories twice even when recent attestation prevents expiry, and the supplied regression reports eight synchronous skill-stat calls for one skill before the fix.

Is this the best way to solve the issue?

Reusing existing span helpers and the filesystem guard’s directory-only mode removes unnecessary work without adding another cache or weakening expiry decisions.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Verified introduction: The pinned introduction diff adds span observation and timing wrappers, changes two workspace guard calls, and moves existing session-selection and title-listener logic without changing their decisions. (7396ee78cd1a)
  • Workspace protection retained: Recent attestations select the existing directory-identity guard; vanished workspaces still fail, while expired or unattested workspaces retain full content evidence. (src/agents/workspace.ts:675, 7396ee78cd1a)
  • Expiry remains storage-owned: The worker independently refuses expiry when attestation or setup evidence is recent, preserving its transaction admission and recovery-hold checks. (src/agents/workspace-state-store.worker.ts:154, 7396ee78cd1a)
  • Observer lifecycle: Async-local observation isolates requests, catches observer failures, and retires open measurements at startup completion without changing timeline activation. (src/infra/diagnostics-timeline.ts:83, 7396ee78cd1a)
  • Supplied shipped-path measurements: The complete body reports real sessions.create → chat.send → agent.wait runs on isolated Linux synthetic state, completing 21 turns per variant and exposing the changed subphases; it explicitly disclaims whole-startup and allocation improvements. (7396ee78cd1a)
  • Current main still needs the change: Fetched main retains both full workspace-inventory captures and lacks the request span observer. (src/agents/workspace.ts:673, 670ad6a9b0fc)

Likely related people:

  • Peter Steinberger: Raw commit e532b82 adds src/gateway/server-methods/chat-send-diagnostics.ts:42 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e532b8282767; files: src/gateway/server-methods/chat-send-diagnostics.ts)
  • Vincent Koc: Raw commit 196ea61 adds src/infra/diagnostics-timeline.ts:288 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 196ea61ec4d2; files: src/infra/diagnostics-timeline.ts)
  • Shakker: Raw commit 097eed8 adds src/infra/diagnostics-timeline.ts:180 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 097eed8cd8b4; files: src/infra/diagnostics-timeline.ts)

PR surface

Source +102, Tests +88, Docs +18. Total +208 across 12 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 9 410 308 +102
Tests 2 88 0 +88
Docs 1 18 0 +18
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 516 308 +208

Review metrics

Metric Value Why it matters
Production versus test LOC Production +410/-308, net +102; tests +88/-0. Growth supplies requested startup attribution through existing owners without adding a cache or competing workspace-preparation path.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Useful diagnostics and a bounded workspace performance improvement warrant normal priority; no urgent user-facing regression is established.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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.

History

Review history (3 earlier review cycles)
  • reviewed 2026-10-11T19:39:59.968Z sha b56bb53 :: needs changes before merge. :: none
  • reviewed 2026-10-11T19:55:16.244Z sha 7a5d699 :: needs changes before merge. :: none
  • reviewed 2026-10-11T20:51:48.114Z sha 7396ee7 :: needs changes before merge. :: none

Reviewed October 11, 2026, 5:45 PM ET / 21:45 UTC (Revision 4).

@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 11, 2026
@steipete
steipete merged commit 4d5e037 into main Oct 11, 2026
152 of 181 checks passed
@steipete
steipete deleted the steipete/perf-micro-reply-initialization-breakdown-20260919 branch October 11, 2026 21:47
@steipete

Copy link
Copy Markdown
Contributor Author

Merged with the operator-authorized inherited-failure exception, pinning reviewed head 7396ee78cd1a5f95c9e3e54051227271a284546d.

The only root failure in CI run 38172968600 was checks-node-changed-compact-small-4-1: Gateway ACP completion ownership > completes persistence failure after explicit abort once observed end without start. Its failure caused the existing fail-fast cancellation of siblings; cancelled jobs are not represented as passing.

The relevant ACP event/admission files are unchanged by this PR. A controlled replay on unchanged current-main production 072f977edd46c7134dbdb05ec00fac03f6cf8069 reproduced the same assertion in both cold and warm iterations. It delayed only the return of the real start-recovery read until the original public abort emitted its real terminal event, preserving the RPCs, rows, authority, and assertions. An ordinary baseline run passed; the failure is timing-sensitive. This remains a separate ACP lifecycle follow-up.

The lane passed 273 focused tests, 20 closure tests, export-collision checking, all 28 test-type groups, production types, lint, dead exports, import-cycle checking, and the remaining changed-code guards. Synthetic Gateway proof completed all 21 turns. Fresh independent review was clean through P2. The native merge helper stopped before mutation because its shared tsx dependency did not match the trust anchor; the explicitly authorized exact-head REST fallback performed the merge.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 12, 2026
…penclaw#169307)

* perf(reply): attribute startup and avoid redundant workspace scans

Report nested reply and runtime preparation spans in slow chat-send diagnostics. Preserve the existing initialization boundary and identify fresh reads, mutations, history, and actor preparation. Avoid full expiry inventories for recently attested workspaces while preserving disappearance guards.

* fix(diagnostics): avoid shadowing the phase iterator

* fix(diagnostics): preserve binding and satisfy lint contracts
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: L 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