Repository navigation
perf(sessions): skip unused prompt-start history traversal - #185395
Conversation
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.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
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 52010For sandbox proof, add
|
…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.
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
a7fe06b17a966a1a1a518f805f85c7cbfaf9fee5it fails becausegetBranch()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.
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 --checkpassed. 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 onf5634d28a751dd9eaa33274c80450bd5b9031bdf, including the aggregateopenclaw/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
f5634d28a751dd9eaa33274c80450bd5b9031bdfwith 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.
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.