Repository navigation
perf(codex): avoid duplicate catalog reconciliation collections - #184842
Conversation
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.
|
🦞👀 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 SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis PR removes duplicate collections and repeated path normalization from Codex catalog file reconciliation. Example: Periodically reconcile 5,000 unchanged rollout files.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete 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 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe 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]
Technical reviewBest 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
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource 0, Tests +65, Other +10. Total +75 across 4 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 26, 2026, 1:37 PM ET / 17:37 UTC. |
|
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. |
…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.
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.
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
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.
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):
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).
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 outsiderootDirand lacks@openclaw/normalization-coredeclarations. 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.