Skip to content

perf(sessions): skip unused prompt-start history traversal - #185395

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-session-start-runtime-history-20261026
Oct 27, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-session-start-runtime-history-20261026

Conversation

@steipete

@steipete steipete commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Session runtime preparation walks the entire resident transcript branch even when in-history system-prompt updates are enabled and the prompt-state owner immediately discards that history.

User Impact

A small CPU and allocation reduction when starting or resuming sessions on routes that support in-history prompt updates. This does not change prompt contents, checkpoint retirement, transcript window policy, or authority checks, and does not explain seconds-long session-start stalls.

Why This Change Was Made

Pass a history supplier to the existing prompt-state owner, which invokes it only when an incapable route needs to inspect and retire an earlier prompt series. The enabled path still clears unsent attempt state. There is no cache or second policy owner. Runtime LOC delta: 0; the production change replaces three lines, with formatter-only wrapping. The benchmark adds 143 script lines and documents its own usage; tests add 22 net lines. The requested non-test diff is therefore +143 lines, entirely measurement tooling, with no runtime growth.

Evidence

The regression uses the real runtime-preparation caller and prompt-state owner. On baseline a7fe06b17a966a1a1a518f805f85c7cbfaf9fee5 it fails because getBranch() is called once; with the change it must be called zero times while pending prompt state is cleared. Existing tests cover disabled-route retirement, retries, checkpoint rejection, and prompt-prefix stability.

Owner measurement: a real resident SessionManager with 4,096 synthetic transcript entries, 3,000 operations per sample; five alternating timing samples per revision and two separate sampled-allocation passes per revision. Preparation and warmup are excluded. The benchmark includes the caller's per-operation callback creation. These are owner costs, not full-turn latency.

Owner metric Baseline Candidate Change
Main-thread CPU / 3,000 starts (5 samples/side) 1,288.70 ms 1.06 ms -99.92%
Sampled allocation / 3,000 starts (2 samples/side) 766.48 MiB 1.30 MiB -99.83%
Branch traversals / 3,000 starts 3,000 0 -3,000

Mean absolute saving: 0.429 ms CPU and 261.2 KiB allocated per start at 4,096 entries. Host one-minute load ranged from 67.7 to 86.7 on a 32-core Mac; main-thread CPU is reported separately from wall time. Baseline wall time ranged 1,409–3,723 ms per 3,000 starts under that contention. Timing and allocation passes are separate; no GC or full-Gateway improvement is inferred from the owner benchmark.

Focused validation passed: 31 prompt-state tests, 18 runtime-preparation tests (including the regression), and 13 prompt-prefix-stability tests. File-scoped core/scripts lint, formatting, and git diff --check passed. Focused command: node scripts/run-vitest.mjs src/agents/embedded-agent-runner/session-prompt-state.test.ts src/agents/embedded-agent-runner/run/attempt-session-runtime-prepare.test.ts src/agents/agent-tools.prefix-stability.test.ts --maxWorkers=1. Both built Gateway smokes passed: each completed four turns, four tool calls/results, and ten committed churn writes; delivered session events were 11,180 / 11,830. Exact-head CI and build artifacts passed on f5634d28a751dd9eaa33274c80450bd5b9031bdf, including the aggregate openclaw/ci-gate. No CI failures were rerun. The rebase left the measured owners and SessionManager unchanged.

Review: independent subagent review (autoreview route unavailable), no actionable findings through P2. The GitHub Codex review also completed on f5634d28a751dd9eaa33274c80450bd5b9031bdf with no findings. The Codex autoreview preflight rejected the requested provider route because it did not match the operator configuration; the configuration was left unchanged. ClawSweeper’s separate advisory review was still running at handoff.

Runtime proof uses isolated built Gateways with 10,800 synthetic sessions, 128 MiB of transcripts, 40 plugins, 65 WebSocket clients, concurrent mock turns with tools/native subagents, and list/search churn. The canonical stress harness's 60-second smoke is setup/behavior proof only, not a 10-minute performance comparison. The loopback mock route does not enable the optimized native-endpoint prompt-update policy. A prior phase probe failed during warmup because unrelated metadata publications prevented its generic quiet condition; its partial timings are excluded. Full multi-pair stress was omitted under the task's explicit fast-path rule for unambiguous redundant-work deletion.

Gateway smoke telemetry — context only, not performance acceptance

Each arm ran for 60 seconds after preparation. Host load differed substantially and this mock route does not exercise the optimized policy; neither favorable nor unfavorable differences below are attributed to the patch. No A/A controls or allocation pass were run, and no adverse verdict is drawn.

Metric Baseline smoke Candidate smoke
Main-thread CPU 15.11% 14.38%
Allocation rate Not collected Not collected
GC 0.782 s/min 0.366 s/min
Minor / major collections 67 / 4 65 / 7
Maximum minor / major pause 44.96 / 190.27 ms 10.36 / 36.19 ms
Event-loop p99 (samples) 72.16 ms (2,459) 42.66 ms (2,744)
Client sessions.list p99 (samples) 217.43 ms (121) 101.79 ms (121)
Server sessions.list handler p99 (samples) 212.99 ms (121) 99.33 ms (121)
RSS / main heap at timing stop 2,863 / 695 MiB 3,043 / 701 MiB
Host load average (1 / 5 / 15 min) 91.7 / 94.0 / 90.6 46.9 / 59.0 / 72.9

The list tails have fewer than 1,000 samples. These are smoke artifacts, not evidence of a full-Gateway speedup or regression. The requested phase p50/p90 comparison remains a gap: the earlier phase driver's warmup failed, while the canonical smoke validates workload completion without reproducing the native-route optimization.

Let the prompt-state owner request resident history only when a route needs to retire prior prompt updates. Preserve pending-state cleanup and disabled-route checkpoint behavior. Avoid one discarded branch traversal on enabled session starts.
@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

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 ✅ Completed 2026-10-27T03:44:19.878499Z f5634d2 PR opened
ℹ️ 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 scripts Repository scripts agents Agent runtime and tooling size: S labels Oct 27, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 27, 2026
@steipete
steipete merged commit 80e9b4a into main Oct 27, 2026
133 of 135 checks passed
@steipete
steipete deleted the steipete/perf-session-start-runtime-history-20261026 branch October 27, 2026 03:55
@steipete

Copy link
Copy Markdown
Contributor Author

The subscriber-visible session-start harness is merged in #185389. Use one tooling checkout containing that change against each already-built Gateway revision, with fresh output directories and the same sandbox mode:

node --import ./scripts/tsx.mjs scripts/perf/turn-start-phases.ts --entry /path/to/base/dist/entry.js --output .local/session-start-base --port 52000
node --import ./scripts/tsx.mjs scripts/perf/turn-start-phases.ts --entry /path/to/candidate/dist/entry.js --output .local/session-start-candidate --port 52010

For sandbox proof, add --sandbox-image openclaw-sandbox:bookworm-slim to both commands. Defaults: 10,800 sessions, 40 plugins, 65 clients, four concurrent turns, long retained histories, sidebar/list/search/history churn, and 40 fresh plus 40 warm samples. --cold-rounds 2 --warm-rounds 2 gives a shorter descriptive smoke run (eight samples per cohort).

summary.json now has run-correlated ACK/provider-request/subscriber-text/tool-start waterfalls and p50/p90 distributions. Existing diagnostics.scope names remain overlapping round/cohort aggregates, not invented per-run spans. Counterbalance revision order and use A/A controls before attributing adverse results. Details: docs/reference/session-start-measurement.md.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 27, 2026
…185395)

Let the prompt-state owner request resident history only when a route needs to retire prior prompt updates. Preserve pending-state cleanup and disabled-route checkpoint behavior. Avoid one discarded branch traversal on enabled session starts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. scripts Repository scripts size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant