Repository navigation
improve(codex): reduce startup CPU for large rollouts - #138784
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 4, 2026, 10:43 PM ET / September 5, 2026, 02:43 UTC. ClawSweeper reviewWhat this changesThe PR reduces CPU spent scanning Codex conversation files during resume by using native reverse newline search and expanding chunk-boundary coverage. Merge readiness✅ Ready for maintainer review Keep open: the CPU optimization remains absent from the reviewed main revision, and the focused patch has no blocking correctness findings. The supplied measurements support its deliberately limited performance claim. Priority: P2 Review scores
Verification
How this fits togetherThe Codex plugin inspects saved native conversation files before reusing a thread. Its startup guard combines token usage and context-window information, then preserves or rotates the saved thread binding. flowchart TD
A[Conversation resume] --> B[Saved thread binding]
B --> C[Codex conversation file]
C --> D[Reverse chunk reader]
D --> E[Token usage and context window]
E --> F{Existing budget checks}
F --> G[Reuse saved thread]
F --> H[Generation-checked rotation]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +2, Tests +1. Total +3 across 2 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep one startup inspection path with native byte search, complete-record parsing, and unchanged token-budget, filesystem, and generation safeguards. Do we have a high-confidence way to reproduce the issue? Yes: placing a large record between the file tail and required token/window information exercises the per-byte scan still present on reviewed main. The supplied filesystem comparison measures that scenario; this reviewer did not rerun OpenClaw. Is this the best way to solve the issue? Yes, for the stated CPU-only improvement: replacing byte iteration inside the existing reader avoids a competing parser, new dependency, or early search cutoff. Large-record decoding and parsing remain separate work. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 116c6c3be399. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
* refs/remotes/origin/main: (602 commits) fix(plugins): trace trust refusals and repair legacy provenance (openclaw#138746) perf(sqlite): reuse compiled plugin state point reads (openclaw#138758) refactor: type chat prefetch dependencies and clean loading tests (openclaw#138793) ci: reduce Doctor test startup and core lint jobs (openclaw#138796) feat(update): retain run history and share outcome reports (openclaw#138690) chore(deps): update @openclaw/fs-safe to 0.8.1 (openclaw#138500) fix: preserve global board ownership from pinning to notifications (openclaw#138675) fix(gateway): deliver session catalog updates from slow hosts (openclaw#138674) perf(sessions): index pending conversation replies (openclaw#127182) perf(auth): reuse ordered provider alias entries (openclaw#138805) docs(diagnostics): clarify whole-process CPU metrics (openclaw#138804) perf(memory): narrow source reads and stream embedding cache rows (openclaw#138766) fix: allow older source on newer Testbox checkouts (openclaw#138782) fix(agents): preserve recovered task progress and lifecycle ownership (openclaw#138785) perf(codex): reduce rollout tail scan CPU (openclaw#138784) perf(gateway): stop projecting history deltas at the byte budget (openclaw#138655) fix(build): bound native declaration inputs to checkout (openclaw#138742) fix(cli): preserve foreground Gateway argument handling (openclaw#138765) fix(ui): align task toolbar with side-panel tabs (openclaw#138769) fix(logbook): drain accepted work before closing SQLite (openclaw#138754) ... # Conflicts: # src/agents/embedded-agent-runner/compact.queued.ts
What Problem This Solves
Resolves unnecessary startup CPU when a Codex conversation's token snapshot sits behind a large rollout record, or its latest usage needs a context window from an older record.
Why This Change Was Made
Use native Buffer reverse newline search inside the existing 64 KiB reader. It reconstructs and parses the same complete records, preserving latest usage, older windows, short reads, descriptor cleanup, and the current generation checks before binding clears. The loop stops when its prefix is empty because negative Buffer offsets wrap around.
Production is +5/-3 (net +2) for the native-search loop and its termination comment. The existing older-window test becomes three boundary cases, +25/-24 (net +1).
User Impact
Large or sparse-token rollouts require less scan CPU when resuming a Codex conversation. Large-record JSON decoding and parsing remain synchronous, so this is a bounded startup improvement.
Evidence
f325f4f58d44f9ef1326743c664c603432894b71, retaining fix(codex): preserve native threads after interrupted compaction #138473's generation fences. All 140 tests across three files passed: startup binding, connection preparation, and binding-store ownership. Coverage includes byte 0/1/65,535, split UTF-8, CRLF, malformed/unterminated records, short reads, path/symlink rejection, revoked authority, predecessor-generation lease races, and cancellation cleanup.05a236c7versus this exact scan change: four variants, three samples each, Node 26.8.1 on a contended macOS host. With a 32 MiB unrelated record, median process CPU was 405→270 ms for an older window, 354→290 ms for a large trailing record, and 403→293 ms with discovery. All twelve results, read counts/bytes, and JSON parse counts/characters matched; the complete-tail control retained one 64 KiB read. The reader/parser prefix is byte-identical on the integration base.c57e3632now pins 0.153.4; direct inspection of that exact upstream release confirms the six token/rollout producer files remain byte-identical. This qualifies these contracts, not the entire runtime.Earlier fixture-padding, lint/type, and local command-selection failures are retained in the proof record and corrected; no test deadline or assertion outcome was relaxed. Separate follow-ups cover large-record parsing, the preexisting legacy session-file reader, and opt-in compressed rollouts.
Exact-head CI run 33938705423 completed successfully on
f8b33a290f24d2e950455f61ae7e10c4a0d2ec4b(36 successful jobs, 17 skipped).