Skip to content

perf(plugins): reuse normalized policy within capability filters - #138003

Merged
steipete merged 1 commit into
mainfrom
codex/perf-sep04-capability-policy
Sep 4, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf-sep04-capability-policy

Conversation

@steipete

@steipete steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

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:

Whole operation Before → candidate, forward Before → candidate, reverse
List 8 active speech providers, 16 policy entries 57.40 → 9.65 µs (83.19% faster) 28.01 → 8.41 µs (69.98% faster)
Prepare 4 media families, 8 owners, 16 policy entries 168.46 → 42.26 µs (74.92% faster) 172.85 → 39.98 µs (76.87% faster)

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.

@clawsweeper

clawsweeper Bot commented Sep 4, 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 4, 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 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 4, 2026, 3:07 AM ET / 07:07 UTC.

ClawSweeper review

What this changes

Reuses 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
Reviewed head: 08f24cd17eea25396131a7be116329fb2ce3da80

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization using the existing policy boundary, with useful freshness coverage and no actionable defect found.
Proof confidence 🌊 off-meta tidepool Not applicable: The contributor-proof gate is exempt for this maintainer-authored internal optimization; supplied benchmarks exercise the changed exported listing and preparation owners, without claiming live Gateway behavior.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The contributor-proof gate is exempt for this maintainer-authored internal optimization; supplied benchmarks exercise the changed exported listing and preparation owners, without claiming live Gateway behavior.
Evidence reviewed 10 items Verified introduced scope: The merge-base-to-head delta contains only the capability runtime and its tests. The recorded test merge has the exact pinned base and head parents, and its result changes only those same files.
Filter lifetime and implementation boundary: Both normalized-policy variables are local to synchronous filters. Manifest normalization remains behind the matching-contract check; active-provider normalization remains behind the config and nonempty-filter paths. Neither value survives another lookup or plugin loading. These are OpenClaw-owned policy functions, with no Codex runtime or protocol dependency.
Existing policy owner and sibling pattern: The policy helper already accepts normalizedConfig, preserves explicit deny/disable precedence, and copies rather than mutates the globally disabled policy. Its sibling manifest-listing function already supplies prepared normalization. External activation still goes through isInstalledPluginEnabled.
Findings None None.
Security None None.

How this fits together

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

Before merge

None.

Agent review details

Security

None.

PR surface

Source +6, Tests +30. Total +36 across 2 files.

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

Review metrics

Metric Value Why it matters
Production versus test growth Production +6 lines; tests +30 lines Production growth carries prepared policy through an existing seam without adding a cache or abstraction; tests protect freshness between calls.

Technical review

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

Labels

Label changes:

  • add P3: This is a bounded internal performance improvement with preserved behavior and no reported user-blocking failure.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The contributor-proof gate is exempt for this maintainer-authored internal optimization; supplied benchmarks exercise the changed exported listing and preparation owners, without claiming live Gateway behavior.

Label justifications:

  • P3: This is a bounded internal performance improvement with preserved behavior and no reported user-blocking failure.
  • 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: The contributor-proof gate is exempt for this maintainer-authored internal optimization; supplied benchmarks exercise the changed exported listing and preparation owners, without claiming live Gateway behavior.

Evidence

What I checked:

  • Verified introduced scope: The merge-base-to-head delta contains only the capability runtime and its tests. The recorded test merge has the exact pinned base and head parents, and its result changes only those same files. (fa55c5f67c98)
  • Filter lifetime and implementation boundary: Both normalized-policy variables are local to synchronous filters. Manifest normalization remains behind the matching-contract check; active-provider normalization remains behind the config and nonempty-filter paths. Neither value survives another lookup or plugin loading. These are OpenClaw-owned policy functions, with no Codex runtime or protocol dependency. (src/plugins/capability-provider-runtime.ts:87, 08f24cd17eea)
  • Existing policy owner and sibling pattern: The policy helper already accepts normalizedConfig, preserves explicit deny/disable precedence, and copies rather than mutates the globally disabled policy. Its sibling manifest-listing function already supplies prepared normalization. External activation still goes through isInstalledPluginEnabled. (src/plugins/manifest-contract-eligibility.ts:38, 08f24cd17eea)
  • Caller and shared capability coverage: Speech listing calls the changed resolver directly. Media-generation and embedding registries share it, while prepared model-runtime facts call media preparation. The optimization stays beneath these callers without changing their APIs or provider identity rules. (src/tts/provider-registry.ts:18, 08f24cd17eea)
  • Behavior-preservation tests: The two added parameterized cases check normalized identifiers, changed enablement, and subsequent denylisting using the same config object across active and manifest lookups. Existing coverage checks forbidden owners, bundled compatibility, external activation, aliases, and media preparation. Tests were inspected, not executed; the read-only diff whitespace check passed. (src/plugins/capability-provider-runtime.test.ts:858, 08f24cd17eea)
  • Current-main necessity: The capability runtime, policy helper, and config-state module have no differences between the pinned merge base and fetched main. Main therefore still performs normalization through the policy helper for each matching entry. (src/plugins/capability-provider-runtime.ts:94, 0ff5f24d7334)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Shubhankar Tripathy: 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.

@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

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 138003

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

@steipete
steipete merged commit 0a6a678 into main Sep 4, 2026
183 checks passed
@steipete
steipete deleted the codex/perf-sep04-capability-policy branch September 4, 2026 07:46
@steipete

steipete commented Sep 4, 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