Skip to content

perf(models): avoid redundant catalog sanitization - #135091

Merged
steipete merged 1 commit into
mainfrom
codex/perf-catalog-refresh-20260901
Sep 1, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf-catalog-refresh-20260901

Conversation

@steipete

@steipete steipete commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

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):

Workload Median forward Median reverse First forward First reverse
fresh-one -5.56% -5.97% -27.83% -6.48%
fresh-ordinary-transport -24.15% -29.36% -34.31% -11.58%
fresh-public-catalog -36.92% -39.53% -31.94% -27.57%
304-one -8.54% +14.89% +22.42% +73.99%
304-ordinary-transport -18.90% -11.82% -22.57% -21.02%
304-public-catalog -32.11% -28.75% -16.26% -43.88%
retained-newer-one -2.33% +2.77% +60.96% -23.06%
retained-newer-ordinary-transport -11.77% -14.48% -20.66% -28.64%
retained-newer-public-catalog -15.81% -20.41% -28.75% -16.41%
identical-200-ordinary-transport +3.03% +2.45% +36.47% -7.90%
invalid-json-retains-one -2.48% -1.86% +7.10% +42.31%
disabled-one -3.30% -0.33% +21.07% -9.28%

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 --json processes exercised an owned numeric-loopback server: HTTP 200 returned updated with one provider/model and exact sanitized durable bytes; a bodyless conditional 304 returned unchanged and advanced both persisted check timestamps; malformed UTF-8 returned exit 1 with a visible cli_error and 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.

@clawsweeper

clawsweeper Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Sep 1, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 1, 2026
@clawsweeper

clawsweeper Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 1, 2026, 6:34 AM ET / 10:34 UTC.

ClawSweeper review

What this changes

The PR removes redundant sanitization while counting stored remote catalog entries and reduces temporary allocations during transport-override stripping.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep 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
Reviewed head: 0887e60f32de613c6927acee2f4189d975c7a131

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a focused, source-consistent optimization with no actionable correctness or security issue found.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless reports a current-head real CLI/HTTP trace through the changed refresh owner with 200, 304, and malformed-UTF-8 outcomes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless reports a current-head real CLI/HTTP trace through the changed refresh owner with 200, 304, and malformed-UTF-8 outcomes.
Evidence reviewed 7 items Stored-count boundary: The changed count helper still parses the complete stored bundle with the canonical schema, but no longer creates a discarded sanitized copy; its outputs are only counts and generatedAt.
Persistence producer remains sanitized: HTTP 200 data continues through validation plus sanitization before serialization and storage; the adjacent test asserts persisted provider/model transport overrides are absent.
Independent activation safeguard: The overlay still validates and sanitizes a stored row before exposing provider and pricing metadata, so the optimization does not remove the consuming security boundary.
Findings None None.
Security None None.

How this fits together

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

Before merge

  • Complete next step (P2) - No mechanical repair is identified; retain this maintainer-authored PR for ordinary exact-head CI and maintainer review.
Agent review details

Security

None.

PR surface

Source +6. Total +6 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 2 12 6 +6
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 12 6 +6

Review metrics

Metric Value Why it matters
Production versus tests production +6, tests 0 The added loop-control lines replace intermediate filter/map allocations while preserving the existing validation and sanitization boundaries.

Stored data model

Persistent data-model change detected: serialized state: src/model-catalog/remote-refresh.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

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

Labels

Label justifications:

  • P3: This is a small internal performance optimization with no supported user-facing regression.
  • 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: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless reports a current-head real CLI/HTTP trace through the changed refresh owner with 200, 304, and malformed-UTF-8 outcomes.

Evidence

What I checked:

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-01T10:15:01.123Z sha 0887e60 :: needs maintainer review before merge. :: none

@steipete
steipete marked this pull request as ready for review September 1, 2026 10:27
@steipete
steipete merged commit fc23cb2 into main Sep 1, 2026
343 of 344 checks passed
@steipete
steipete deleted the codex/perf-catalog-refresh-20260901 branch September 1, 2026 10:42
@steipete

steipete commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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