Skip to content

perf(codex): avoid duplicate catalog reconciliation collections - #184842

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-codex-catalog-reconcile-files-20261026
Oct 26, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-codex-catalog-reconcile-files-20261026

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Periodic Codex catalog file reconciliation rebuilds two full collections and repeats logical-path work even when every rollout is unchanged.

Related: #163706. The directory watcher cache already exists in the measured baseline; this removes residual work after that change.

User Impact

Catalog results and refresh timing stay the same, with less allocation and CPU during file reconciliation. No config, migration, permissions, file-format, or public API changes.

Why This Change Was Made

Transfer the scanner's fresh result map to the reconciliation owner instead of copying it, and use the existing row map for tracked-path membership instead of allocating a Set. Consult observed physical fingerprints before deriving a logical-path fallback, and reuse the logical key during removal checks. Failed reads replace an existing value or delete the current key in place so they remain retryable without revisiting entries or changing the scanner's directory cache.

The existing bounded watcher cache, directory identity checks, safe rollout reads, publication lifetime checks, and native selected-rollout rules remain the owners of their respective contracts. No additional cache or invalidation path.

Evidence

Five counterbalanced baseline/candidate pairs plus one predeclared timing-only pair over 5,000 real synthetic rollout files; 2,000 reconciliations per side after 100 warmups. Separate untraced CPU/GC/latency and allocation-sampling passes. Baseline: c00af62. Same scanner runtime and prepared files on both sides.

Acceptance declared before measurement: fewer collection/normalization operations, lower allocation/CPU, and identical publications/fingerprints. Apply absolute GC and tail thresholds; run matched A/A controls before an adverse verdict.

Mean over paired runs Base Candidate Absolute delta Mean paired delta
Allocated MiB / reconciliation (5 pairs) 6.969 5.255 -1.714 -24.6%
CPU ms / reconciliation (6 pairs) 6.712 5.737 -0.975 -14.3%
GC ms / reconciliation 0.085 0.066 -0.019 -22.8%
Reconciliation median ms 8.440 7.337 -1.104 -12.7%
Reconciliation p95 ms 11.668 13.075 +1.407 +11.0%
Reconciliation p99 ms 21.352 24.826 +3.474 +33.6%
Event-loop p99 ms 2.638 2.498 -0.140 -5.3%
End RSS MiB 256.088 251.761 -4.327 -1.6%
End used heap MiB 92.651 78.380 -14.271 -7.3%

Timing distributions have 2,000 reconciliation samples per arm per pair (12,000 per side total); allocation has 10,000 iterations per side. RSS/heap are end snapshots, not a retention claim. CPU improves in five pairs and rises 5.6% in pair 3; allocation falls 23.8–25.0% in all five pairs. Whole-Gateway effect is unmeasured.

Tail limitation: owner reconciliation p95/p99 are inconclusive on this shared host. Four matched, counterbalanced, untraced A/A controls over identical baseline code produced p99 changes from −59.4% to +56.9% and p95 up to +67.4%. One predeclared extra A/B pair was then collected. Under the signed-absolute-mean rule for mixed signs, p95 +1.407 ms is below 20% of the 11.668 ms baseline (2.334 ms), and p99 +3.474 ms is below 20% of the 21.352 ms baseline (4.270 ms). The relative p99 mean is dominated by smaller baselines and is not used as a rejection signal. This is an allocation/CPU win with unresolved owner latency tails, not a latency improvement claim. Event-loop p99 improves.

Per-pair timing, controls, host load, GC counts and pause context
Pair CPU ms/op B → C GC ms/op B → C Minor / major GC count B → C Max GC pause ms B → C Loop p99 ms B → C (samples B / C) 1-min host load start/end B → C
1 8.050 → 6.074 0.0903 → 0.0682 443/13 → 333/12 4.14 → 4.97 2.787 → 2.456 (19729 / 15862) 22.8/21.7 → 21.1/23.2
2 7.538 → 5.737 0.0886 → 0.0685 444/12 → 332/12 3.39 → 4.13 2.638 → 2.472 (18415 / 14564) 20.1/22.7 → 22.4/20.1
3 7.189 → 7.591 0.0895 → 0.0725 448/13 → 335/12 4.60 → 5.62 2.669 → 2.679 (17376 / 20272) 22.0/21.8 → 21.8/21.9
4 6.853 → 6.071 0.0874 → 0.0694 448/13 → 334/12 4.66 → 5.10 2.671 → 2.556 (16191 / 16663) 15.4/18.3 → 16.4/15.6
5 4.931 → 4.301 0.0751 → 0.0595 446/13 → 332/12 4.09 → 3.99 2.480 → 2.378 (12459 / 11620) 20.6/18.6 → 18.0/16.4
6 5.709 → 4.647 0.0818 → 0.0577 445/13 → 333/12 4.18 → 2.48 2.585 → 2.447 (14054 / 13004) 11.9/12.4 → 13.2/11.9

Major-GC tails are context only (fewer than 50 major collections per arm); each maximum stays below 50 ms. Allocation sampling is separate from timing/GC.

GC kind Mean count B → C Mean total ms B → C
minor 445.7 → 333.2 135.03 → 101.39
major 12.8 → 12.0 33.31 → 28.32
incremental 12.8 → 12.0 2.59 → 2.23
weak 0.0 → 0.0 0.00 → 0.00
Identical-source control pair Reconciliation p95 ms A → A Reconciliation p99 ms A → A
1 11.579 → 8.496 15.324 → 14.616
2 7.619 → 8.029 8.379 → 13.146
3 11.297 → 10.081 34.989 → 14.188
4 9.597 → 16.065 16.013 → 21.560

A/A arms also contain 2,000 samples each; launch order alternates. These local macOS runs use serial arms, not CPU affinity. Host load is recorded; no maintenance windows are trimmed.

One timing pair was replaced because source identity was uncertain during a temporary edit/revert in its window, not because of its results. Original pair 4: CPU 6.292 → 6.566 ms/op, GC 0.0832 → 0.0749 ms/op, loop p99 2.671 → 2.574 ms, max GC pause 4.58 → 7.11 ms. The complete replacement pair is included above.

The owner benchmark asserts that unchanged passes neither publish nor request native refresh. It measures real scanner/reconciliation work, not whole-Gateway or native App Server latency. Whole-Gateway stress was omitted under this deletion lane's fast-path instruction; no production load was started.

Commands (usage is also in the script header):

node --import ./scripts/tsx.mjs scripts/perf/codex-catalog-reconcile-measure.ts --state-dir "$PWD/.local/catalog-fixture" --prepare
node --import ./scripts/tsx.mjs scripts/perf/codex-catalog-reconcile-measure.ts --state-dir "$PWD/.local/catalog-fixture" --operations 2000 --warmup 100 --output result.json
# Add --owner <captured-baseline-owner.ts> for baseline; --allocations for the separate allocation pass.

The captured baseline owner differs only in import specifiers pointing at the same dependencies. The scanner's only code change is its compile-time membership parameter type.

The identity regression fails on baseline because it receives an unnecessary copied map. With the change, all 37 focused tests pass: rollout currency, catalog capacity/native authority, and persisted restart state. Additional cases exercise failed reads with and without an existing fingerprint and verify scanner cache isolation. New regression cases took 38 ms combined; the three-file command took 58.82 s including compilation (existing test bodies approximately 17 s).

node scripts/run-vitest.mjs extensions/codex/src/session-catalog-rollouts.test.ts extensions/codex/src/session-catalog-index-capacity.test.ts extensions/codex/src/session-catalog-resident-state.test.ts --maxWorkers=1

Changed-file oxfmt and extension/script lint pass. The package-only typecheck (node scripts/run-tsgo.mjs -p extensions/codex/tsconfig.json --noEmit) could not complete: package-boundary resolution pulls source files outside rootDir and lacks @openclaw/normalization-core declarations. No diagnostic names either changed production file. This is an unpassed local setup check; the normal extensions typecheck remains a PR CI gate. Broader validation belongs to exact-head PR CI.

Independent subagent review (autoreview route unavailable): clean P0–P2 review of the diff and owning contracts. The configured autoreview route was refused for an operator-provider mismatch; no configuration was changed. Author simplification pass removed the duplicate collections without introducing replacement state.

Production source LOC: 0 net (+18/−18): removal of runtime collections is offset by narrow membership parameter signatures and ownership/retry comments. Tests: +65 lines. Existing benchmark: +10 lines for usage, host load, and memory reporting.

Transfer the fresh scanner result map to reconciliation, reuse tracked path membership, and avoid repeated logical-path lookups on unchanged files. Preserve failed-read retries and cached directory fingerprints.
@clawsweeper

clawsweeper Bot commented Oct 26, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T17:25:16.139572Z fe9c798 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 26, 2026
@clawsweeper

clawsweeper Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR removes duplicate collections and repeated path normalization from Codex catalog file reconciliation.

Example: Periodically reconcile 5,000 unchanged rollout files.

  • Before: Reconciliation copies the scanner map, creates a tracked-path Set, and eagerly derives logical paths.
  • After: Reconciliation owns the fresh scanner map, reuses existing membership, and skips unnecessary path derivation.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A correct, focused optimization supported by owner-level measurements; proof remains scoped to an in-process workload, and one added test pins implementation identity.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor proof gate does not apply to this maintainer-authored PR; its reported macOS benchmark exercises the real reconciliation owner and filesystem scanner over 5,000 files, with lower allocation and CPU and explicitly inconclusive owner latency tails.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Periodic reconciliation spends avoidable CPU and allocation on unchanged Codex histories.
Reason: The maintainer-authored direction removes measurable waste without changing configuration, public APIs, persisted formats, or catalog results.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it is a focused, maintainer-authored optimization with measurable allocation and CPU savings, and no introduced production defect was found.

Priority: P2
Reviewed head: fe9c798a7cc6096c3eb954da5f73f60c67dcc24a

Before merge

None.

Findings

None.

Tests

  • Low-value test extensions/codex/src/session-catalog-rollouts.test.ts: Remove the added map-identity test: its distinguishing assertion pins an internal object-transfer choice, while the benchmark already measures allocation and checks unchanged publications; retain the failed-read and cache-isolation cases.
  • Missing end-to-end proof: The supplied benchmark exercises production owners in process; it does not establish whole-Gateway performance, which the PR explicitly leaves unclaimed.
Agent review details

How this fits together

The resident Codex catalog scans local rollout files, compares fingerprints, and publishes changed display rows through the existing index owner.

flowchart LR
  A[Local rollout files] --> B[Filesystem scanner]
  C[Directory watcher cache] --> B
  B --> D[File reconciliation]
  E[Resident catalog rows] --> D
  D --> F[Catalog index publication]
Loading

Technical review

Best possible solution:

Use the existing scanner and index owners to remove redundant work while preserving retry, publication, and native-selection behavior.

Do we have a high-confidence way to reproduce the issue?

Current main visibly allocates both redundant collections on every reconciliation; the supplied benchmark reports their cost, and no target code was executed during this review.

Is this the best way to solve the issue?

The production diff is the smallest complete optimization: it reuses existing state, transfers a fresh map, and preserves failed-read retries without adding another cache or owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 99f7a303e3ff.

Provenance checked

  • Reconciliation collections, fingerprint lookup, and removal membership keeps the original intent (456178d: The extraction preserved the existing catalog implementation to satisfy the file-size lint limit; it did not establish copying as a required contract.)
  • Failed-read retries and publication lifetime keeps the original intent (1746b63: Lifecycle simplification retained failed-read retryability, native selection, and ordinary shutdown settlement.)
  • Scanner membership and serialized scans keeps the original intent (e4ac046: The catalog index already serializes scans; accepting a membership interface changes only the parameter contract, leaving scheduling and cache behavior intact.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit e4ac046 adds extensions/codex/src/session-catalog-rollout-scanner.ts:132 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e4ac046c6446; files: extensions/codex/src/session-catalog-rollout-scanner.ts)
  • Jason (Json): Raw commit 456178d adds extensions/codex/src/session-catalog-index-reconcile.ts:42 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 456178d8da64; files: extensions/codex/src/session-catalog-index-reconcile.ts)

PR surface

Source 0, Tests +65, Other +10. Total +75 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 18 18 0
Tests 1 65 0 +65
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 10 0 +10
Total 4 93 18 +75

Labels

Label changes:

  • add P2: Measured recurring catalog CPU and allocation savings have limited scope and no demonstrated urgent user-facing failure.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Measured recurring catalog CPU and allocation savings have limited scope and no demonstrated urgent user-facing failure.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 26, 2026, 1:37 PM ET / 17:37 UTC.

@steipete

Copy link
Copy Markdown
Contributor Author

Keeping the ownership-transfer identity regression as the requested performance work/identity guard: it fails on main's full-map copy, while ordinary catalog-value assertions would allow that allocation to return. The test also verifies unchanged fingerprints, no file reads, and no publications. The failed-read and scanner-cache-isolation cases remain. This is an internal performance invariant, not a new public object-identity contract.

Whole-Gateway performance remains explicitly unclaimed; this scoped deletion uses the real owner/scanner workload and the documented fast-path proof. No production finding requires a change.

@steipete
steipete merged commit 7001a36 into main Oct 26, 2026
133 of 135 checks passed
@steipete
steipete deleted the steipete/perf-codex-catalog-reconcile-files-20261026 branch October 26, 2026 17:52
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 27, 2026
…claw#184842)

Transfer the fresh scanner result map to reconciliation, reuse tracked path membership, and avoid repeated logical-path lookups on unchanged files. Preserve failed-read retries and cached directory fingerprints.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: codex P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: S 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