Repository navigation
perf(codex): reconcile session catalogs incrementally - #152257
Conversation
Coalesce observed activity into bounded native prefix checks and run full native and file safety reconciliation every 15 minutes. Keep file deadlines independent of native retries, and preserve snapshot overflow and source backoff settlement when a prefix walk ends early. Preserve immediate lifecycle updates and first-page readiness. Document the silent-change bound and the remaining native JSON parsing cost.
|
🦞👀 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 18, 2026, 7:50 PM ET / 23:50 UTC. ClawSweeper reviewWhat this changesThe Codex session catalog replaces repeated full scans with activity-driven prefix checks and 15-minute safety scans, with matching recovery tests and documentation. Merge readiness✅ Ready for maintainer review This remains a useful optimization: current main still performs full reconciliation every 30 seconds. The introduced changes preserve recovery and catalog bounds, and no blocking correctness defect was found. Priority: P2 Review scores
Verification
How this fits togetherThe Codex plugin builds OpenClaw’s session catalog from native app-server metadata, lifecycle notifications, and local rollout files. Its resident index supplies session lists and searches while preserving a restartable SQLite snapshot. flowchart TD
A[Native lifecycle notifications] --> B[Resident catalog index]
C[30-second scheduler] --> D{Activity or safety scan due?}
D -->|Activity| E[Native prefix check]
D -->|Safety deadline| F[Full native and local file scans]
E --> B
F --> B
B --> G[Session lists and searches]
B --> H[SQLite snapshot]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +87, Tests +244, Docs +20. Total +351 across 15 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep reconciliation with the existing catalog owner, preserving immediate notifications, full recovery walks, and the explicitly documented silent-change interval. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main unconditionally schedules full reconciliation every 30 seconds, matching the reported large-home overhead. No runtime benchmark was executed during this review. Is this the best way to solve the issue? Yes. The patch extends the existing reconciliation owner, retains full safety recovery, and documents the freshness tradeoff without adding competing caches or configuration. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against c0233f0e0fc6. 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.
|
* commit 'ca69b4d25dfcd488acc6ba1d878e4b4252f40cd2': (325 commits) perf(gateway): streamline config reload comparison (#152279) fix(xai): reject invalid UTF-8 OAuth responses (#111737) fix(release): accept waived advisory performance evidence for stable publication (#152290) fix: deliver watcher results while other sessions are busy (#152287) perf(media): reuse attachment filename classification (#152274) refactor(build): reuse forwarded option scanning (#152293) chore(diagnostics-otel): revert unapproved duration-bucket merge (#152292) fix: stop chat media reads after access changes (#152219) fix(test): use Gateway WebSocket transport in network fixtures (#152143) improve: retain quota refresh evidence from successful CI runs (#152173) improve(gateway): reduce memory used by session selection (#152260) perf(agents): use keyed subagent capability lookups (#152263) refactor(matrix): centralize media metadata assembly (#149128) chore(ui): refresh control ui locales (#152276) feat: open Crabbox apps beside the conversation (#152094) refactor: simplify worker and model fallback handling (#152268) perf(codex): reconcile session catalogs incrementally (#152257) fix(ui): keep submitted prompts visible across session startup (#152241) perf(sessions): move automatic maintenance database work to workers (#148630) fix: preserve reply metadata through outbound preparation (#152231) ...
Parse and project native catalog pages in one client-owned worker while preserving transport order, bounded display previews, cancellation routing, and joined worker shutdown. Keep complete native control metadata for canonical forks and direct-input checks. Publish affirmative ephemeral metadata before settling native requests, so helper shutdown cannot lose catalog exclusion while a passive worker refresh is pending. The existing catalog index owns deletion, stale-read fencing, and persistence. Synchronize worker-backed fixtures without changing deadlines or weakening assertions, and register the standalone synthetic benchmark. Main-baseline comparisons reproduced the PR regressions before repair. Focused worker, catalog, guarded-request, canonical-fork, and SQLite-restart proof plus changed checks passed; independent Codex review is scoped-clean through P2. Exact-head CI is required before landing. Related: #152035, #151998, #152257.
Coalesce observed activity into bounded native prefix checks and run full native and file safety reconciliation every 15 minutes. Keep file deadlines independent of native retries, and preserve snapshot overflow and source backoff settlement when a prefix walk ends early. Preserve immediate lifecycle updates and first-page readiness. Document the silent-change bound and the remaining native JSON parsing cost.
Parse and project native catalog pages in one client-owned worker while preserving transport order, bounded display previews, cancellation routing, and joined worker shutdown. Keep complete native control metadata for canonical forks and direct-input checks. Publish affirmative ephemeral metadata before settling native requests, so helper shutdown cannot lose catalog exclusion while a passive worker refresh is pending. The existing catalog index owns deletion, stale-read fencing, and persistence. Synchronize worker-backed fixtures without changing deadlines or weakening assertions, and register the standalone synthetic benchmark. Main-baseline comparisons reproduced the PR regressions before repair. Focused worker, catalog, guarded-request, canonical-fork, and SQLite-restart proof plus changed checks passed; independent Codex review is scoped-clean through P2. Exact-head CI is required before landing. Related: #152035, #151998, #152257.
Parse and project native catalog pages in one client-owned worker while preserving transport order, bounded display previews, cancellation routing, and joined worker shutdown. Keep complete native control metadata for canonical forks and direct-input checks. Publish affirmative ephemeral metadata before settling native requests, so helper shutdown cannot lose catalog exclusion while a passive worker refresh is pending. The existing catalog index owns deletion, stale-read fencing, and persistence. Synchronize worker-backed fixtures without changing deadlines or weakening assertions, and register the standalone synthetic benchmark. Main-baseline comparisons reproduced the PR regressions before repair. Focused worker, catalog, guarded-request, canonical-fork, and SQLite-restart proof plus changed checks passed; independent Codex review is scoped-clean through P2. Exact-head CI is required before landing. Related: openclaw#152035, openclaw#151998, openclaw#152257.
Related: #150659
What Problem This Solves
Large Codex homes repeatedly serialize and parse their entire native session inventory every 30 seconds, even when nothing has changed.
User Impact
Idle homes issue no native catalog requests or filesystem scans between 15-minute safety cycles. Notifications and acknowledged catalog actions still update rows immediately; activity coalesces a native prefix check at the next 30-second tick.
Silent external changes outside that prefix—including metadata edits without timestamp changes, remote deletions/archives, and local file disappearance—converge at the next successful safety cycle. Safety cycles start 15 minutes apart; convergence also includes scheduling, in-flight work, and scan/walk duration. Startup and reconnect recovery still perform full reconciliation. No configuration, schema, native rollout, or update/rollback changes.
Why This Change Was Made
The resident index already owns incremental event updates. Its currency owner now schedules activity-driven prefix reconciliation and the less frequent full safety cycle. File-scan deadlines advance independently, so native failures do not replay successful scans or shift their next deadline. Native pages remain ordered by descending recency; reconciliation stops after a whole page leaves the canonical resident metadata unchanged, or at the retained-row cap. It never interprets an unvisited tail as deletion. Full walks retain membership repair, cursor-loop guards, and overflow discovery; local native omissions still require filesystem or lifecycle evidence before removal.
Native attempt settlement now follows the whole walk, including successful early termination, so partial recovery probes release source backoff correctly. Preview caching, field-observation fencing, first-page readiness, and stable tie positions retain their existing owners.
Evidence
Operator-supplied baseline on 2026-09-18 (build
19a209e3fdee, about 11,000 rollouts): a 15-secondstrace -e writecapture saw 76 MB in 41 stdout-socket writes, approximately 10thread/listresponses of 2–8 MB. Full first-user-message previews dominated the payload. A separate five-second main-thread profile attributed 16% of busy CPU to app-server JSON parsing and 15% to GC. No thread identifiers or private message text are included here.A local synthetic measurement exercised the production scanner over 11,000 plain rollouts in 110 date directories on Apple M3 Ultra / Node 26.8.2. Seven scans took 1.376–8.171 seconds wall time (median 4.705 seconds) and 0.775–1.579 seconds CPU. Every scan performed 11,001
lstat, 117realpath, and 116opendircalls, with zero content opens/reads. This justified moving file scans to the safety cadence too; these are local measurements, not a production after-profile.Validation:
node scripts/run-vitest.mjswith the Codex extension config, allsession-catalogfiles, and the client preview/decoder tests.session-catalog-resident-state,snapshot-recovery,native-performance,cold-native, andephemeral). This includes real isolated Codex app-server walks over 3,000 synthetic threads and cold readiness plus SQLite restart over 490 rollouts.node scripts/check-changed.mjspassed, including extension/test type checks, lint, boundary and import-cycle guards. Fresh checks after the last edits also passed: both extension tsgo lanes, scoped oxlint/oxfmt, andgit diff --check.No live service was changed or re-profiled. The patch does not depend on an upstream Codex change.
Codex protocol evidence and upstream follow-up
Personally inspected sibling Codex source at
dcfcb570b2cd0a2500b1d47a7b04a7cb1b0a0bd2:codex-rs/app-server/src/request_processors/thread_processor.rs:2563–2593maps the requested recency sort/direction.codex-rs/state/src/runtime/threads.rs:1453–1482,1507–1530uses descendingrecency_at_mswith a strict timestamp keyset cursor;:527–540derives continuation from the last admitted row. Cursors are opaque continuations, not frozen snapshots. Each reconciliation starts at the head, and safety walks repair silent or concurrent changes outside its prefix.codex-rs/app-server-protocol/src/protocol/v2/thread_data.rs:243–251exposes whole-second timestamps;thread_processor.rs:5939–5941performs that rounding. The index preserves its existing native tie positions.codex-rs/app-server-protocol/src/protocol/v2/thread.rs:1368–1435providesuseStateDbOnlybut no bounded preview projection.thread_data.rs:216exposespreview: String;thread_processor.rs:6075–6086extracts the full first user message, and:5915forwards the stored preview.Upstream opportunity: Codex
thread/listcould truncate previews server-side or offer a bounded metadata projection. OpenClaw's current preview cache runs afterJSON.parse, saving subsequent sanitization and retention rather than wire decoding. Avoiding that parse locally would require a separate transport-parser change; reducing the number of requested pages addresses this owner directly.