Skip to content

perf(codex): reconcile session catalogs incrementally - #152257

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-codex-catalog-incremental-reconcile-20260918
Sep 19, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-codex-catalog-incremental-reconcile-20260918

Conversation

@steipete

Copy link
Copy Markdown
Contributor

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-second strace -e write capture saw 76 MB in 41 stdout-socket writes, approximately 10 thread/list responses 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, 117 realpath, and 116 opendir calls, 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:

  • Catalog/client lane: 452 tests in 42 files passed, using node scripts/run-vitest.mjs with the Codex extension config, all session-catalog files, and the client preview/decoder tests.
  • Database-worker lane: 14 tests in 5 files passed (session-catalog-resident-state, snapshot-recovery, native-performance, cold-native, and ephemeral). 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.mjs passed, 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, and git diff --check.
  • Regressions cover zero idle requests/stats, stopping at a known prefix, timestamp-preserving metadata updates, bounded silent-removal repair, retained tails, recovery-probe settlement, overflow persistence, and independent file deadlines through native outages. The primary page-count, overflow, and outage regressions were demonstrated failing before their fixes.
  • Independent Codex review: scoped-clean through P2, with no accepted/actionable findings.

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–2593 maps the requested recency sort/direction. codex-rs/state/src/runtime/threads.rs:1453–1482,1507–1530 uses descending recency_at_ms with a strict timestamp keyset cursor; :527–540 derives 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–251 exposes whole-second timestamps; thread_processor.rs:5939–5941 performs that rounding. The index preserves its existing native tie positions.
  • codex-rs/app-server-protocol/src/protocol/v2/thread.rs:1368–1435 provides useStateDbOnly but no bounded preview projection. thread_data.rs:216 exposes preview: String; thread_processor.rs:6075–6086 extracts the full first user message, and :5915 forwards the stored preview.

Upstream opportunity: Codex thread/list could truncate previews server-side or offer a bounded metadata projection. OpenClaw's current preview cache runs after JSON.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.

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.
@clawsweeper

clawsweeper Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: codex size: L maintainer Maintainer-authored PR labels Sep 18, 2026
@steipete
steipete marked this pull request as ready for review September 18, 2026 23:43
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 18, 2026
@clawsweeper

clawsweeper Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 18, 2026, 7:50 PM ET / 23:50 UTC.

ClawSweeper review

What this changes

The 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
Reviewed head: 8331ba09a2781057ce1e6991031d3de5a878eb6c

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with meaningful recovery coverage, an explicit freshness tradeoff, and no blocking finding.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied Repository State identifies this as maintainer-authored, so the external-contributor proof gate does not apply. Reported real app-server tests cover hydration and restart; scheduler regressions use controlled fixtures, and no production after-profile is claimed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied Repository State identifies this as maintainer-authored, so the external-contributor proof gate does not apply. Reported real app-server tests cover hydration and restart; scheduler regressions use controlled fixtures, and no production after-profile is claimed.
Evidence reviewed 7 items Current main still needs the optimization: At the fetched main revision, the currency scheduler unconditionally runs file and native reconciliation every 30 seconds. The related merged work at #150659 established the resident catalog but did not implement this activity-driven cadence.
Prefix termination preserves unseen rows: Incremental walks omit the full-walk removal inventory, compare canonical resident rows, and stop at an unchanged page or retained-row limit. Full walks retain membership reconciliation, and both paths persist the existing overflow marker.
Recovery and cadence coverage: Inspected regressions cover idle request suppression, retained tails, silent-change repair, successful prefix recovery settlement, overflow persistence, and independent file deadlines during native outages. The PR reports 452 catalog/client tests and 14 database-worker tests passing; these were not rerun during this read-only review. The introduced diff passed git diff --check.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +87, Tests +244, Docs +20. Total +351 across 15 files.

View PR surface stats
Area Files Added Removed Net
Source 5 158 71 +87
Tests 9 281 37 +244
Docs 1 25 5 +20
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 15 464 113 +351

Review metrics

Metric Value Why it matters
Safety cadence 30 seconds → 15 minutes Idle full scans become 30 times less frequent, while silent external changes may wait until the next successful safety cycle.
Production versus test growth Production net +87 lines; tests net +244 lines Production growth implements activity tracking and walk-level settlement; the added tests target recovery and bounded reconciliation.

Technical review

Best 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.

Labels

Label changes:

  • add P2: This addresses measured catalog overhead in large Codex homes without evidence of an urgent outage.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied Repository State identifies this as maintainer-authored, so the external-contributor proof gate does not apply. Reported real app-server tests cover hydration and restart; scheduler regressions use controlled fixtures, and no production after-profile is claimed.

Label justifications:

  • P2: This addresses measured catalog overhead in large Codex homes without evidence of an urgent outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied Repository State identifies this as maintainer-authored, so the external-contributor proof gate does not apply. Reported real app-server tests cover hydration and restart; scheduler regressions use controlled fixtures, and no production after-profile is claimed.

Evidence

What I checked:

  • Current main still needs the optimization: At the fetched main revision, the currency scheduler unconditionally runs file and native reconciliation every 30 seconds. The related merged work at fix(codex): keep session catalog queries in memory #150659 established the resident catalog but did not implement this activity-driven cadence. (extensions/codex/src/session-catalog-currency.ts:25, c0233f0e0fc6)
  • Prefix termination preserves unseen rows: Incremental walks omit the full-walk removal inventory, compare canonical resident rows, and stop at an unchanged page or retained-row limit. Full walks retain membership reconciliation, and both paths persist the existing overflow marker. (extensions/codex/src/session-catalog-index.ts:392, 8331ba09a278)
  • Recovery and cadence coverage: Inspected regressions cover idle request suppression, retained tails, silent-change repair, successful prefix recovery settlement, overflow persistence, and independent file deadlines during native outages. The PR reports 452 catalog/client tests and 14 database-worker tests passing; these were not rerun during this read-only review. The introduced diff passed git diff --check. (extensions/codex/src/session-catalog-backoff.test.ts:19, 8331ba09a278)
  • Dependency contract applies: The hydration iterator directly requests Codex thread/list with descending recency, opaque pagination cursors, and useStateDbOnly. These protocol assumptions make personal inspection of the Codex implementation relevant. (extensions/codex/src/session-catalog-native-page.ts:35, 8331ba09a278)
  • Native pagination contract inspected: Personally inspected the available sibling revision: thread listing uses recency_at_ms ordering and timestamp keyset continuation; ThreadListParams supports database-only reads. Ownership was verified through the backing repository’s remote URL. This checkout is revision 6b9826e3aa83b1a5947db50f4332cb9c65f1b340, not the historical revision cited in the PR body. (codex-rs/state/src/runtime/threads.rs:1481, 6b9826e3aa83)
  • Prior merged ownership: Current-main history repeatedly identifies Peter Steinberger on catalog work. GitHub commit metadata verifies steipete authored the merged resident-catalog change and shows the currency module among its additions. Deeper local blame and patch traversal encountered unavailable objects, so no source-line introduction attribution is asserted. (extensions/codex/src/session-catalog-currency.ts, 96275066b944)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 1ea8eeb into main Sep 19, 2026
171 checks passed
@steipete
steipete deleted the steipete/perf-codex-catalog-incremental-reconcile-20260918 branch September 19, 2026 00:09
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 19, 2026
* 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)
  ...
steipete added a commit that referenced this pull request Sep 19, 2026
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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 19, 2026
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.
steipete added a commit that referenced this pull request Sep 19, 2026
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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 20, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: codex maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant