Repository navigation
[Fix] Lazy compile protocol validators - #82064
Conversation
00e354a to
1723501
Compare
|
Maintainer verification before merge. Behavior addressed: Gateway protocol validators now lazy-compile on first use instead of compiling every AJV schema during cold import.
Evidence after fix:
Observed result after fix: focused protocol validator tests passed, gateway direct-start E2E passed, two-gateway WS + HTTP + node-pairing E2E passed, and changed gate passed. Thanks @samzong. |
|
ClawSweeper status: review started. I am starting a fresh review of this pull request: [Fix] Lazy compile protocol validators This is item 1/1 in the current shard. Shard 0/1. This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking. Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted. |
|
Landed via rebase merge onto Gate/proof:
Landed commits: Performance proof: median protocol import Thanks @samzong. |
Summary
src/gateway/protocol/index.tseagerly compiled every AJV protocol validator..errorscompatibility.Change Type
Scope
Linked Issue/PR
Real behavior proof
tbx_01krndx4fdwmd5yw2j64cdj5nt,tbx_01krne47hfznt4qtwn2t36c416,tbx_01krne7bsbzhwrr4dzt16zp08t).node --import tsx --input-type=module <inline AJV compile counter script>node scripts/run-vitest.mjs src/gateway/protocol/index.test.ts src/gateway/server.ios-client-id.test.tsnode scripts/crabbox-wrapper.mjs run --provider blacksmith-testbox --blacksmith-org openclaw --blacksmith-workflow .github/workflows/ci-check-testbox.yml --blacksmith-job check --blacksmith-ref main --timing-json --shell -- <baseline-vs-PR benchmark + targeted protocol tests>node scripts/crabbox-wrapper.mjs run --provider blacksmith-testbox --blacksmith-org openclaw --blacksmith-workflow .github/workflows/ci-check-testbox.yml --blacksmith-job check --blacksmith-ref main --timing-json --shell -- "node scripts/run-vitest.mjs run --config test/vitest/vitest.e2e.config.ts src/gateway/server-network-runtime.e2e.test.ts test/gateway.multi.e2e.test.ts"node scripts/crabbox-wrapper.mjs run --provider blacksmith-testbox --blacksmith-org openclaw --blacksmith-workflow .github/workflows/ci-check-testbox.yml --blacksmith-job check --blacksmith-ref main --timing-json --shell -- "pnpm check:changed"tbx_01krndx4fdwmd5yw2j64cdj5ntandtbx_01krne47hfznt4qtwn2t36c416:pnpm test, fullpnpm check, and Docker gateway-network lane were not run. Targeted Testbox E2E, changed gate, and protocol benchmark were run.origin/mainshowed 159 compile calls during import, median 213.5ms import time, and median 51.7MB RSS delta.Root Cause
src/gateway/protocol/index.tscreated an AJV instance and exported validators by runningajv.compile(...)at module top level.Regression Test Plan
src/gateway/protocol/index.test.ts..errors, and can all be proactively compiled in a smoke path.User-visible / Behavior Changes
None. Protocol validation semantics stay the same; cold import CPU and RSS costs are deferred until validators are used.
Security Impact
Human Verification
.errorscompatibility, Gateway iOS client id validation consumer, Blacksmith Testbox gateway startup E2E, two-gateway WS/HTTP/node-pairing E2E, changed gate, TypeScript checks, lint, format, and build..errors; valid input resets.errorstonull; all exported validators can still be forced to compile during tests.pnpm check, fullpnpm test, and Docker gateway-network lane.AI-assisted: Yes - Codex implemented and verified the change.
Risks and Mitigations
src/gateway/protocol/index.test.tsincludes a compile-all smoke test that forces every exported protocol validator to compile during test runs.ValidateFunctionerror behavior..errorsis readable after invalid input and resets tonullafter valid input.