Skip to content

perf(agents): prepare exact tool names once per catalog batch - #139267

Merged
steipete merged 1 commit into
mainfrom
codex/perf-sep05-tool-matcher-latest
Sep 5, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf-sep05-tool-matcher-latest

Conversation

@steipete

@steipete steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Preparing a prompt tool catalog repeatedly normalizes the same execution allowlist for every tool. Larger populated allowlists pay that repeated work in both catalog gating and callable-tool preparation.

Why This Change Was Made

Prepare exact normalized names once per synchronous batch and share that matcher through the existing owner. The matcher does not escape those synchronous operations. Later execution checks keep reading the current allowlist; no persistent cache or authority rule changes.

This also removes the intermediate callable-map tuple allocation while retaining the existing filter-before-prepare ordering. Production: +25/−13 (+12); tests: +89. The growth separates synchronous prepared facts from live execution checks, rather than making a retained cache serve both lifetimes.

User Impact

No intended change to available tools, aliases, literal wildcard/group names, denied-tool metadata, winner order, or mutable-cap behavior. Populated synthetic prompt-policy workloads improve in both measurement orders. This does not establish an end-to-end Gateway or cold-start speedup.

Evidence

  • Historical baseline and candidate: 162 passing cases in eight complete owner/sibling files, including catalog callable output and cap mutation/replacement. Preservation tests pass before the refactor; this is not a failing-before bug fix.
  • Fresh composition on main 426ca0d50f303c7cbec46741be7ff51e99145a18: the same eight complete files pass all 162 current cases, and the full normal changed-file gate passes. Main changed four skill-policy case names/assertions since the historical pair; those inventories are not claimed identical. The newer refusal wording is preserved.
  • Twelve-pass independent managed Codex review: no actionable P0–P2 findings. Root separately inspected owners, callers, siblings, current-main composition and dependency contracts.
  • Fixed B0/C0/C1/B1 complete-operation measurements retain 4,384 operations, 512 batch means and all 195 adverse comparisons. Prompt-apply medians improve 3.55%/5.01% with 8 names, 16.13%/20.78% with 32, and 58.06%/59.64% with 128. Those sizes are synthetic, not observed default frequencies.
  • Opposing costs remain: the empty-cap path is 0.310/0.375 µs slower (4.32%/5.14%); constructor timings are mixed and some maxima worsen substantially. No allocation, retained-memory, cold-start or universal performance gain is claimed.
  • The historical numerical cohort remains bound to base 8797856260efeb94b71d88029850409416d7f74c; the operation is preserved in the current composition, but the old timings were not relabeled as a current-base cohort. Original lint failures and their corrections are retained.

Focused verification:

node scripts/run-vitest.mjs src/agents/agent-tool-availability.test.ts src/agents/tool-policy.test.ts src/agents/openclaw-tools.registration.test.ts src/agents/embedded-agent-runner/run/attempt-prompt-tool-policy.test.ts src/agents/embedded-agent-runner/run/attempt.skills-policy.test.ts src/agents/embedded-agent-runner/run/attempt.tool-search-catalog-abort.test.ts src/agents/code-mode-swarm.lazy.test.ts src/agents/code-mode-swarm.test.ts
pnpm check:changed --timed -- src/agents/agent-tool-availability.test.ts src/agents/agent-tool-availability.ts src/agents/embedded-agent-runner/run/attempt-tool-catalog.ts src/agents/tool-policy-shared.ts

The focused checks exercise the actual policy/catalog owner boundaries. No built CLI, live provider turn, or before/after Gateway timing was run with this patch; campaign live observations from another candidate are not reused as its proof. This bounded behavior-neutral refactor uses focused checks proportional to its unchanged contract.

@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Sep 5, 2026
@steipete
steipete marked this pull request as ready for review September 5, 2026 18:11
@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 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 5, 2026, 2:17 PM ET / 18:17 UTC.

ClawSweeper review

What this changes

Prepare normalized execution allowlists once per tool-catalog batch, reducing repeated name matching while preserving tool availability.

Merge readiness

✅ Ready for maintainer review

No blocking findings. This remains a useful, bounded optimization absent from the inspected main revision; the patch preserves exact-name matching and execution-check lifetimes.

Priority: P3
Reviewed head: 120727163ad0daa43c25c75eb61a3ad60310a168

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with meaningful preservation coverage, appropriately bounded performance claims, and no blocking defect found.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored, behavior-neutral refactor is exempt from contributor live-proof requirements; reported owner tests and synthetic timings cover catalog preparation, without establishing end-to-end performance.
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, behavior-neutral refactor is exempt from contributor live-proof requirements; reported owner tests and synthetic timings cover catalog preparation, without establishing end-to-end performance.
Evidence reviewed 10 items Introduced scope and clean checkout: The pinned introduction contains only the three production modules and availability tests. The verified test-merge comparison lists the same paths. Whitespace validation passed, and the checkout remained clean.
Exact matching preserves the existing contract: The new Set matcher uses the same normalization as the existing single-call predicate. It preserves literal wildcard/group names and empty-list denial; existing glob/group policy matchers have different semantics and cannot replace it.
Preparation lifetime and callback ordering: Both matcher consumers finish synchronously. Availability computes all callable winners before invoking preparation callbacks; execution gating captures denial wrappers rather than retaining the matcher. Catalog restriction and rebuilding invoke finalization again.
Findings None None.
Security None None.

How this fits together

The agent tool catalog determines which tool descriptions and dependent capabilities reach the model. It combines tool definitions with execution restrictions before handing callable tools to the runtime.

flowchart TD
  A[Tool definitions] --> C[Catalog preparation]
  B[Execution allowlist] --> D[Normalize exact names once]
  D --> C
  C --> E[Callable tools and descriptions]
  E --> F[Agent runtime]
  B --> G[Current execution checks]
  F --> G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +12, Tests +89. Total +101 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 3 25 13 +12
Tests 1 89 0 +89
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 114 13 +101

Review metrics

Metric Value Why it matters
Production versus test growth Production +12 net; tests +89 net The production growth separates synchronous prepared matching from live execution checks; tests protect availability behavior without adding test-only production seams.

Technical review

Best possible solution:

Keep exact-name preparation batch-local while preserving live execution checks and shared alias normalization.

Do we have a high-confidence way to reproduce the issue?

Not applicable as a bug reproduction: this is a behavior-preserving optimization, and source confirms repeated normalization in the existing batch paths.

Is this the best way to solve the issue?

Yes. The shared exact-name matcher fits the two synchronous consumers; reusing glob/group matchers would change semantics, while retaining a cache would conflict with mutable execution caps.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 717f824924fe.

Labels

Label changes:

  • add P3: This is a bounded internal performance refactor with no intended user-visible behavior change or urgent regression.
  • 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: This maintainer-authored, behavior-neutral refactor is exempt from contributor live-proof requirements; reported owner tests and synthetic timings cover catalog preparation, without establishing end-to-end performance.

Label justifications:

  • P3: This is a bounded internal performance refactor with no intended user-visible behavior change or urgent 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, behavior-neutral refactor is exempt from contributor live-proof requirements; reported owner tests and synthetic timings cover catalog preparation, without establishing end-to-end performance.

Evidence

What I checked:

  • Introduced scope and clean checkout: The pinned introduction contains only the three production modules and availability tests. The verified test-merge comparison lists the same paths. Whitespace validation passed, and the checkout remained clean. (120727163ad0)
  • Exact matching preserves the existing contract: The new Set matcher uses the same normalization as the existing single-call predicate. It preserves literal wildcard/group names and empty-list denial; existing glob/group policy matchers have different semantics and cannot replace it. (src/agents/tool-policy-shared.ts:61, 120727163ad0)
  • Preparation lifetime and callback ordering: Both matcher consumers finish synchronously. Availability computes all callable winners before invoking preparation callbacks; execution gating captures denial wrappers rather than retaining the matcher. Catalog restriction and rebuilding invoke finalization again. (src/agents/agent-tool-availability.ts:57, 120727163ad0)
  • Execution checks remain live: OpenClaw Code Mode still checks the current execution allowlist in its bridge and joined-spawn guard. The patch does not replace these checks with a retained snapshot. (src/agents/code-mode-swarm.runtime.ts:112, 120727163ad0)
  • Tests protect observable availability: Added coverage checks aliases, literal names, blanks, frozen and sparse lists, and allowlist mutation/replacement across catalog restriction and rebuilding. Existing cases cover denied readers, descriptor reuse, copied definitions, and closed generations. Tests were inspected, not executed during this read-only review. (src/agents/agent-tool-availability.test.ts:52, 120727163ad0)
  • Documented boundary and dependency applicability: The harness documentation defines finalization as updating dependent affordances without rebinding authorization. OpenClaw Code Mode is explicitly separate from Codex Code Mode, and the inspected Codex adapter calls finalization without an execution allowlist. No changed behavior requires a Codex runtime/protocol contract. Public docs: docs/plugins/sdk-agent-harness.md. (docs/plugins/sdk-agent-harness.md:741, 120727163ad0)

Likely related people:

  • Peter Steinberger: Raw commit af9ba2a adds src/agents/agent-tool-availability.ts:57 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: af9ba2adc7ca; files: src/agents/agent-tool-availability.ts)

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 merged commit 5702b80 into main Sep 5, 2026
247 checks passed
@steipete
steipete deleted the codex/perf-sep05-tool-matcher-latest branch September 5, 2026 18:30
@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 5, 2026
* commit '911d7d5b0c107f7274f2415ca9655dcc6105f0e8': (867 commits)
  fix(skills): deliver pending Workshop approval controls (#139248)
  fix(gateway): deliver loopback ask_user prompts to the originating channel (#138831)
  docs: keep root agent instructions focused on repository policy (#139258)
  fix(matrix): exclude archived state roots from scans and selection (#112329)
  perf(agents): prepare exact tool names once per catalog batch (#139267)
  fix: preserve Swarm progress and simplify owner plumbing (#139269)
  fix(tailscale): release claims after gateway process-group exit (#139261)
  refactor(cli): simplify lazy command registration (#139108)
  test(ui): retain synthetic widget failure evidence (#139229)
  fix(buzz): keep implicit replies at thread root (#138879)
  test(diagnostics): await graceful Gateway shutdown before cleanup (#139247)
  fix(ci): unblock releases with different tooling package managers (#139259)
  feat(ui): add social preview links for private sessions (#139250)
  fix(codex): retain failed conversations for guarded continuation (#139246)
  chore(ui): refresh control ui locales (#139200)
  fix(ci): run browser checks for real-gateway inputs (#139256)
  fix(llama-cpp): reconcile managed router state before requests (#136363)
  chore(i18n): refresh native locales (#139237)
  refactor(worker): unify inference payload handling (#139245)
  refactor(terminal): replay wrapped prefixes in one pass (#139240)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling 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: S 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