Repository navigation
perf(plugins): reuse normalized policy within capability filters - #138003
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed September 4, 2026, 3:07 AM ET / 07:07 UTC. ClawSweeper reviewWhat this changesReuses normalized plugin policy within provider filters, reducing repeated work while preserving provider selection and config changes between calls. Merge readiness✅ Ready for maintainer review Keep open: the inspected main and latest release still lack this useful optimization. No blocking correctness findings emerged. Priority: P3 Review scores
Verification
How this fits togetherOpenClaw resolves speech, embedding, and media providers from active registries and plugin manifests. These filters apply operator policy before returning providers for listing, preparation, or execution. flowchart TD
A[Operator plugin policy] --> B[Normalize once per filter]
C[Plugin manifests] --> D[Check capability ownership]
D --> E[Apply existing owner policy]
F[Active provider registry] --> E
B --> E
E --> G[Eligible providers]
G --> H[Speech and media consumers]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +6, Tests +30. Total +36 across 2 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep normalization local and lazy in each filter, with the existing policy owner retaining all eligibility decisions. Do we have a high-confidence way to reproduce the issue? Not applicable to a correctness bug: source confirms repeated normalization, and the PR reports paired performance measurements that were not rerun during this read-only review. Is this the best way to solve the issue? Yes. Reusing the existing prepared-policy seam removes repeated work without duplicating policy; caching across calls would introduce unnecessary invalidation and freshness concerns. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 0ff5f24d7334. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Ready to land unchanged head 08f24cd. The existing policy owner remains authoritative; each synchronous filter now reuses one lazily normalized value. Production +6 lines carries those prepared facts through the existing seam, without a cache, config change, or cross-call stale state. The same 164 cases passed before and after, and the full changed check and independent managed Codex review passed. Exact local commands: node scripts/run-vitest.mjs src/plugins/capability-provider-runtime.test.ts src/plugins/capability-provider-runtime.generation.test.ts src/plugins/manifest-contract-eligibility.test.ts src/plugins/config-state.test.ts src/plugins/provider-registry-shared.test.ts --reporter=verbose
node scripts/check-changed.mjs --base 59bfe7734917b9ab8dec32581f4d49620e518093 -- src/plugins/capability-provider-runtime.ts src/plugins/capability-provider-runtime.test.ts
OPENCLAW_TESTBOX=1 scripts/pr prepare-run 138003Native prepare passed without a rebase, source change, push, or local gate replay. It verified exact-head CI 33846712479 and Workflow Sanity 33846712573. The full latest ClawSweeper review has no findings or pre-merge actions. The fixed 4,668-call cohort passed both orders: listing medians improved 83.19%/69.98%, and four-family preparation 74.92%/76.87%. All protected median and sampled tree-RSS gates passed. This is listing/preparation evidence, not a live provider, whole Gateway startup, or model-turn claim. Mixed tails and all 15 adverse summaries remain documented in the PR body; no performance rerun was used for landing. The later requested-provider scan experiment is separate and is not included here. |
|
Merged via squash.
|
What Problem This Solves
Capability-provider resolution was normalizing the complete plugin policy for every matching manifest and every active provider. The shared policy helper already accepts a prepared
normalizedConfig; these two filters were not using that seam.Why This Change Was Made
Normalize lazily once per synchronous filter and pass the result to the existing policy owner. Empty/no-contract filters still avoid normalization. Nothing is retained between calls or across plugin loading, so later mutations of the same config object take effect. Allow/deny rules, bundled speech compatibility, external owner activation, aliases and provider identity keep their existing owners and behavior. Production is +6 lines, carrying prepared facts through the existing seam without a cache or new abstraction; tests are +30 lines.
User Impact
Capability-provider listing and media-family preparation do less repeated work when policy covers multiple providers, without changing provider selection or policy behavior.
Evidence
The fixed local benchmark measured the real exported functions with synthetic in-memory registries and prepared metadata, in B0/C0/C1/B1 order. Medians below are per-call batch means:
Both primaries passed the predeclared 3% improvement requirement in both orders. All six protected rows passed the rule rejecting median regressions exceeding both 3% and 1 µs. The single-provider row was 4.34%/7.27% slower, but only 42/68 ns; empty preparation was 437 ns slower in reverse. Large, external-policy and globally disabled speech fixtures also remained covered. Sampled process-tree peak RSS changed −2.23%/+0.50%, within the fixed 10% bound; kernel child RSS changed −1.84%/−3.19%.
This is a listing/preparation improvement, not a measured Gateway startup or model-turn improvement. Tails were mixed: reverse media-preparation p95 rose 12.68% (31.33 µs), reverse empty-preparation p95 rose 307.08% (79.85 µs), and forward single-provider/disabled-speech p95 rose 1.10/8.17 µs. All 15 adverse first/warm/median/tail/RSS observations are retained; first/warm and p95 were diagnostics, not acceptance gates. No failed timing sample was discarded or repeated.
Validation: the same 164 cases across five whole suites passed on before and candidate, including the new active/manifest policy-mutation cases. The complete explicit-base changed check passed all 29 stages, and fresh managed Codex review found no actionable P0–P2 issue. Paired native proof retained full input/output identity and compiled-source correspondence; the fixed cohort contains 4,668 selected calls and 512 measured means, with all six product hosts positively closed and candidate source restored unchanged.
Two setup issues are retained separately: a metadata preflight encountered reported libraries without readable physical files, now recorded explicitly; a root preflight assumed absent source-map
sourcesContent, followed by one unadmitted B0 dispatch that exited before product imports. Both compiled owner bodies were then reviewed and the admitted fixed cohort ran once. Neither setup issue supplied or replaced a timing sample. No configuration, dependency, schema, persistence or public API changes.