Repository navigation
perf(models): avoid redundant catalog sanitization - #135091
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed September 1, 2026, 6:34 AM ET / 10:34 UTC. ClawSweeper reviewWhat this changesThe PR removes redundant sanitization while counting stored remote catalog entries and reduces temporary allocations during transport-override stripping. Merge readinessKeep open. No correctness or security finding is supported, and fetched current main has not incorporated this optimization; this maintainer-authored PR remains for normal exact-head CI and maintainer review. Priority: P3 Review scores
Verification
How this fits togetherRemote catalog refresh validates and sanitizes downloaded provider metadata before persisting it, then reports provider/model counts to the CLI and Gateway scheduler. The active overlay separately sanitizes stored data before it affects provider routing or pricing. flowchart LR
A[Catalog HTTP response] --> B[Validate and strip transport overrides]
B --> C[Persisted catalog row]
C --> D[Validate stored row for counts]
C --> E[Sanitize active overlay]
D --> F[CLI and scheduler status]
E --> G[Provider and pricing lookup]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +6. Total +6 across 2 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Land the localized optimization after exact-head CI completes, retaining schema validation for stored rows, sanitization at HTTP persistence, and independent sanitization at overlay activation. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR optimizes an established catalog-refresh path rather than reporting a defect. Is this the best way to solve the issue? Yes. Parsing the stored bundle through the existing schema without re-sanitizing it is the narrowest maintainable change because counts never expose the parsed transport fields, while the producer and overlay retain their sanitization boundaries. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against dc355fabc20a. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Merged via squash.
|
Catalog refreshes were recursively copying already-sanitized stored bundles just to report provider/model counts. The incoming sanitizer also allocated separate filter/map arrays and new entry pairs at every object.
This keeps schema validation on stored reads, removes only their discarded sanitizer copy, and compacts the sanitizer's owned entry array in place. Incoming HTTP 200 data still validates and strips every transport endpoint/header override before persistence; overlay activation still sanitizes independently. Input objects, property order, conditional requests, races, abort/error behavior, persisted shape and schema version stay unchanged.
Production: +12/−6, net +6; tests: 0. The six extra lines replace intermediate arrays with one bounded owned traversal; there is no new cache, dependency, configuration or alternate compatibility path. Arbitrary manually inserted unsanitized cache rows are not a producer contract; the canonical writer already sanitizes before storing them.
Validation: 20 existing catalog/core/store/overlay/CLI tests pass before and after; the three selected six-hour refresh/shutdown/TTL scheduler tests pass (90 unrelated cases not run). Full changed-code checks passed in 233.36s and the clean committed full build in 200.08s. Independent source and raw-results reviews passed; scoped managed review found no actionable issues at its requested priority threshold.
Measured the complete exported refresh operation with native SQLite and guarded supplied Responses, including validation, serialization and transport lifecycle. This measures operation CPU/wall work, not HTTP download, DNS/TLS, Gateway startup or model latency. Fresh proof covers 32 scenarios and 12 exact-byte workload oracles per variant. The fixed before/candidate/candidate/before sequence retained 528 measured blocks,192 warmups,48 row-local first calls and 12,108 complete operations. Ordinary refreshes save 88–112µs; the captured public-catalog fixture saves 9.3–11.0ms on fresh reads.
Percent change versus before (negative is faster):
Both fresh ordinary/public rows passed the predefined 3% improvement requirement in both orders. No protected row regressed by more than 3% in both orders. All four adverse median comparisons and seven adverse first comparisons are retained above. Identical 200 ordinary refreshes cost an additional 22–28µs (+3.03%/+2.45%); that tradeoff is accepted against the larger stored-read savings. First calls are per row after initialization, not cold process startup. Raw CPU/RSS diagnostics are retained without a heap-savings claim. No samples were discarded or timing runs repeated.
Measurement provenance: source HEAD 3e37496 with precisely the two-file candidate diff; after measurements, commit 0887e60 preserved both owner byte hashes. All six proof/timing outer exits were zero; 18 processes, 12 groups, 6 worker generations and 48 exact coordinator paths were independently confirmed closed/absent.
Real built CLI/HTTP proof passed on clean commit 0887e60 in 6.35s (behavior only, not a speed measurement). Three fresh
openclaw models refresh --jsonprocesses exercised an owned numeric-loopback server: HTTP 200 returnedupdatedwith one provider/model and exact sanitized durable bytes; a bodyless conditional 304 returnedunchangedand advanced both persisted check timestamps; malformed UTF-8 returned exit 1 with a visiblecli_errorand preserved the complete prior catalog row byte-for-byte. Independent native Node read-only/query-only SQLite snapshots verified all three outcomes. No injected fetch, clock, build stamp, store, provider credentials or user configuration was used. All 36 observed processes, three CLI groups, listener and eight exact coordinator paths were independently confirmed closed/absent; owned temporary state was removed.Two earlier real-HTTP attempts are retained as failures after their successful first CLI 200. The second captured a system-Python SQLite SELECT failure against the retained WAL-mode main file with absent sidecars. Separate pristine-copy diagnostics reproduced that read-only limitation in the system runtime; Node's native read-only reader succeeded on the same main bytes. The proof now uses that single independently reviewed native reader, with no writable/immutable fallback. This is a fixture/runtime-specific observation, not a claimed upstream SQLite defect. Neither failed attempt is counted as successful proof, and the performance sequence was not rerun.
ClawSweeper's September 1 10:15 UTC review and its rank-up request are addressed by the completed persisted-row/304/invalid-UTF-8 trace above. The serialized-state heuristic does not represent a data-model change: the canonical producer still writes the identical sanitized bundle and row shape, and schema version and overlay validation are unchanged. No migration is needed. Exact-head CI and native landing validation remain required.