Repository navigation
perf: speed up chat history preparation - #133635
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 8:04 PM ET / August 31, 2026, 00:04 UTC. ClawSweeper reviewWhat this changesThis PR speeds chat-history preparation by avoiding markup cleanup and metadata parsing when a message lacks the relevant heartbeat token or inbound-context sentinels. Merge readinessKeep open. The introduced owner-local fast paths preserve the existing marker, delivery-hint, and whole-line Priority: P3 Review scores
Verification
How this fits togetherGateway history projection sanitizes stored chat text before it reaches the Control UI, TUI, and model replay. The changed functions detect internal metadata and heartbeat acknowledgements so ordinary messages can bypass unnecessary parsing. flowchart LR
A[Stored chat messages] --> B[Gateway history projection]
B --> C[Inbound metadata detection]
B --> D[Heartbeat acknowledgement cleanup]
C --> E[Sanitized history]
D --> E
E --> F[Control UI, TUI, and model replay]
Before merge
Agent review detailsSecurityNone. PR surfaceSource -9. Total -9 across 2 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the shared-owner fast paths and land after exact-head CI confirms the existing sanitization and heartbeat contracts. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR optimizes existing history preparation rather than reporting a failure. Its supplied body includes before/after real-transcript and ephemeral-Gateway measurements. Is this the best way to solve the issue? Yes. The change keeps the parsing and stripping owners intact while making their no-sentinel paths cheaper; it does not add a competing cache or behavior path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 0b392310b92d. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
The shared-owner fast paths are reviewed and ready for native landing. Exact-head CI run 33343149590 is green for The Node profile showed ordinary messages repeatedly entering inbound-metadata regex matching and heartbeat markup cleanup. The canonical detector and token-absence check remove that work while retaining marked metadata, wrapped heartbeat tokens, timestamp handling, and the uncapped TTS/deduplication boundary. Rich initial 400-message preparation improved 22.056 → 16.770 ms; older 1,000-message preparation improved 14.479 → 11.248 ms. These are Gateway preparation timings, not browser-paint timings. 467 focused/integration tests passed. All 600,000 differential helper comparisons matched, as did 15 real SQLite page snapshots (8,100 messages) after normalizing only each fresh database's source identifier. The clean Linux ephemeral-Gateway REST/SSE and replay-boundary proof is run 33342433086, wrapper exit 0, lease stopped. Fresh Codex autoreview and ClawSweeper found no actionable source defect. Executed focused commandsnode scripts/run-vitest.mjs src/auto-reply/heartbeat.test.ts src/auto-reply/heartbeat-filter.test.ts src/auto-reply/reply/strip-inbound-meta.test.ts src/auto-reply/reply/agent-runner-presentation.test.ts src/gateway/chat-display-projection.test.ts src/gateway/chat-display-projection.media.test.ts src/gateway/chat-display-projection.tool-result.test.ts src/gateway/chat-display-projection.forwarded.test.ts src/agents/cli-runner.helpers.test.ts src/tui/tui-formatters.test.ts
node scripts/crabbox-wrapper.mjs run --timing-json -- node scripts/run-vitest.mjs src/gateway/sessions-history-http.test.ts src/agents/embedded-agent-runner/run/attempt.llm-boundary.cache-stability.test.ts
node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/auto-reply/heartbeat.ts src/auto-reply/reply/strip-inbound-meta.ts
node scripts/run-tsgo.mjs -p .artifacts/control-ui-e2e/history-window-perf/tsconfig.third.json
git diff --checkThe scoped typecheck inherits the repository's core compiler options and aliases. The broad local check stopped at pre-existing shared-install |
|
Merged via squash.
|
What Problem This Solves
Opening or scrolling back through long Control UI chats still spends avoidable Gateway time scanning ordinary messages for inbound metadata and heartbeat acknowledgement markup.
Follow-up to #133565, which increased history windows and optimized the initial projection path.
Why This Change Was Made
The metadata owner now checks literal provenance markers and delivery hints directly, using its whole-line regex only when
Context:is present. Both metadata-stripping entry points share that detector. The heartbeat owner skips markup cleanup when the literal acknowledgement token is absent; the cleanup only inserts spaces or removes edge wrappers, so it cannot create that token.This removes repeated scans at their shared owners, benefiting Gateway history, TUI formatting, and model replay. Production LOC: +12/-21 (net -9); tests: +0/-0. No new cache, configuration, storage, protocol, page-size, or rendering changes. The full-text and capped sanitization passes remain because TTS matching and deduplication need uncapped text.
User Impact
Chats open and older history loads with less Gateway processing. Existing metadata stripping, heartbeat suppression, displayed messages, initial 400-message windows, and older 1,000-message windows retain their behavior.
Release-note context: Chat history skips metadata-pattern and heartbeat-markup scans for ordinary messages, reducing Gateway work when opening chats and loading older history.
Evidence
Paired Node inspector measurements against baseline
6af76da58f4c469398eea9f03101c8d8fd349996on the same macOS arm64 machine, Node 26.8.1, real isolated SQLite transcripts with 3,000 messages and 2,048 Markdown characters per message. Five warmup rounds and 30 measured rounds per scenario, with scenario order rotated. These medians measure history read/projection; they exclude setup, serialization, network, and browser painting.An independent earlier pair measured 15–17% less time for rich initial pages. Metadata-heavy pages improved about 9–10%; short-message differences were small and noisy on the busy host. The expanded rich CPU profile fell from 4,420.8 to 3,395.7 ms; metadata stripping and heartbeat markup cleanup accounted for 502.8 and 179.4 ms of sampled self time before this patch and disappear from the top frames afterward. No browser-paint improvement is claimed.
467 existing focused/integration tests passed: 358 local heartbeat, metadata, presentation, Gateway projection, TUI, and CLI replay tests, plus 109 clean Linux tests for provider-boundary cache stability and a real ephemeral Gateway's REST/SSE history flow. Blacksmith Testbox run 33342433086 completed with wrapper exit 0 and its lease was stopped; the backing Actions lifecycle may show cancellation after successful external cleanup.
600,000 deterministic old/new helper comparisons over 50,000 adversarial strings matched. All 15 page snapshots (8,100 messages) were deeply equal after normalizing only the source identifier derived from each fresh database's path and rewrite generation. Existing behavior tests plus paired profiling and differential checks were used instead of adding timing assertions or implementation-coupled tests. Temporary measurement harnesses are not part of the product diff.
Targeted formatting, lint, and strict typechecking of both edited modules passed. The broad local changed gate stopped at six pre-existing
tslogdeclaration errors insrc/logging/logger.ts; local integration setup also lackedshiki/wasm, so integration proof ran in the clean Linux Testbox. Named local follow-up: repair the shared dependency installation. Required Codex autoreview passed with no findings; exact-head CI run 33343149590 passed for5a0f80701bf8bf8cb71f669392200106c0da982c. This satisfies ClawSweeper’s remaining CI request.