Skip to content

fix(tools): reject malformed availability expressions - #92411

Merged
steipete merged 1 commit into
openclaw:mainfrom
Pick-cat:fix/92361-tool-availability-empty-group-warning
Jul 11, 2026
Merged

steipete merged 1 commit into
openclaw:mainfrom
Pick-cat:fix/92361-tool-availability-empty-group-warning

Conversation

@Pick-cat

@Pick-cat Pick-cat commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

ToolDescriptor availability is typed in TypeScript, but external JavaScript can still provide malformed runtime values. The existing shallow key check can throw on nested primitives, overflow on cycles, or let sparse groups evaluate as available.

Why This Change Was Made

  • Validate availability expressions recursively before evaluation, including required signal fields and group arrays.
  • Treat the WeakSet as the active recursion stack so true cycles are rejected while shared sibling expressions remain valid.
  • Materialize array indices during validation so sparse groups and config paths cannot skip checks.
  • Preserve existing behavior for absent availability and the precise empty-allOf / empty-anyOf diagnostics.

The submitted ten-file callback/cache/plugin design was replaced with this evaluator-owned path. Current plugin availability is manifest-first; adding a second runtime-tool availability contract and repeated hot-path logging would recreate an ownership model removed from main.

User Impact

Malformed or cyclic descriptors now fail closed with the existing unsupported-signal diagnostic instead of throwing, overflowing, or exposing a tool. Valid descriptors and public types are unchanged; there is no new config, callback, cache, or plugin API.

Evidence

No changelog entry: CHANGELOG.md is release-owned in this repository.

@openclaw-barnacle openclaw-barnacle Bot added size: XS proof: supplied External PR includes structured after-fix real behavior proof. labels Jun 12, 2026
@clawsweeper

clawsweeper Bot commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 11, 2026, 8:24 AM ET / 12:24 UTC.

Summary
The PR recursively validates tool availability expressions and adds regression coverage for malformed, sparse, cyclic, and shared expressions.

PR surface: Source +66, Tests +74. Total +140 across 2 files.

Reproducibility: yes. A typed context signal containing equals: undefined has a deterministic source path: current evaluation treats it like omission, while the PR returns unsupported-signal.

Review metrics: 1 noteworthy metric.

  • Optional-field acceptance: 1 behavior changed. The optional context equals property now rejects an explicitly undefined value accepted by the current TypeScript contract.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #92361
Summary: This PR is the active candidate fix for the canonical malformed-availability report; one open sibling overlaps but adds a separate planner callback contract.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🦐 gold shrimp
Result: blocked until stronger real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Accept explicit undefined for the optional context comparator and add regression coverage.
  • [P1] Post completed exact-head terminal or packed-consumer output with private details redacted, then update the PR body to trigger review; if needed, ask a maintainer to comment @clawsweeper re-review.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: The exact-head PR body says runtime, build, changed-gate, and packed-consumer proof is still running; the successful proof check only validated that context/evidence text exists, not an observed after-fix result. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] A typed context availability descriptor with equals: undefined becomes unsupported and hidden after merge.
  • [P1] The rewritten exact head lacks completed after-fix runtime or packed-consumer output; the successful proof workflow only validated PR-body structure.

Maintainer options:

  1. Preserve optional-property behavior (recommended)
    Allow equals: undefined, add a focused regression test, and attach completed exact-head runtime evidence before merge.
  2. Intentionally tighten the contract
    If explicit undefined must be invalid, encode that restriction in the exported type and provide compatibility rationale and proof before merge.

Next step before merge

  • [P1] The code defect is narrow, but insufficient exact-head real-behavior proof makes this a human-only follow-up rather than a ClawSweeper repair candidate.

Security
Cleared: The two-file evaluator and test patch adds no dependency, secret, permission, network, workflow, downloaded-code, or supply-chain surface.

Review findings

  • [P1] Preserve explicit undefined for optional equals — src/tools/availability.ts:104
Review details

Best possible solution:

Treat an explicitly undefined optional context comparator as omitted, add regression coverage, and retain evaluator-owned recursive rejection for genuinely malformed values.

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

Yes. A typed context signal containing equals: undefined has a deterministic source path: current evaluation treats it like omission, while the PR returns unsupported-signal.

Is this the best way to solve the issue?

No, not yet. Recursive validation at the pure evaluator boundary is the best architecture, but it must preserve the existing optional-property semantics.

Full review comments:

  • [P1] Preserve explicit undefined for optional equals — src/tools/availability.ts:104
    Treat equals: undefined like an omitted optional property. This is valid under the current ToolAvailabilitySignal type, and the existing evaluator handles both forms identically; the new "equals" in value check instead rejects the descriptor and hides the tool. Accept undefined here and add a regression case.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against a4ee15a851df.

Label changes

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The exact-head PR body says runtime, build, changed-gate, and packed-consumer proof is still running; the successful proof check only validated that context/evidence text exists, not an observed after-fix result. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • remove proof: sufficient: Current real behavior proof status is insufficient, not sufficient.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: 📣 needs proof.

Label justifications:

  • P2: The malformed-input hardening is bounded, but one typed-descriptor compatibility regression blocks an otherwise focused fix.
  • merge-risk: 🚨 compatibility: Merging can hide a descriptor that is valid under the current ToolAvailabilitySignal contract.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The exact-head PR body says runtime, build, changed-gate, and packed-consumer proof is still running; the successful proof check only validated that context/evidence text exists, not an observed after-fix result. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +66, Tests +74. Total +140 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 70 4 +66
Tests 1 74 0 +74
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 144 4 +140

What I checked:

  • Optional comparator contract: The public context signal declares equals as optional, and the repository does not enable exactOptionalPropertyTypes, so typed callers may explicitly provide equals: undefined. (src/tools/types.ts:44, a4ee15a851df)
  • Changed runtime behavior: The new in-property validation rejects a present equals value unless it is a JSON primitive, making explicit undefined malformed rather than equivalent to omission. (src/tools/availability.ts:104, 53ceb54b6a71)
  • Existing evaluator semantics: Current main treats an undefined context comparator as the no-comparator branch, so the PR changes an accepted typed descriptor into unsupported-signal. (src/tools/availability.ts:117, b36139035653)
  • Exact-head proof gap: The proof workflow only reported that the PR contains problem context and evidence; the PR body still says the exact-head runtime, build, and packed-consumer proof is running and provides no completed observed output. (53ceb54b6a71)
  • Feature provenance: Current blame connects the availability type and evaluator to steipete, who also authored the rewritten exact head and is the live assignee. (src/tools/types.ts:34, b36139035653)

Likely related people:

  • steipete: Current history attributes the generic availability contract and evaluator to this person; they also authored the rewritten PR head and are assigned to the PR. (role: feature introducer and recent area contributor; confidence: high; commits: b36139035653, 53ceb54b6a71; files: src/tools/types.ts, src/tools/availability.ts, src/tools/availability.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.
Review history (4 earlier review cycles)
  • reviewed 2026-07-03T02:17:47.948Z sha fbe2d09fc2902d11e434835ad7dd720c9812be38 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-09T07:37:31.683Z sha aa2e3486dcc42ac8b0e22ef4b8a7b112b5120793 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-09T08:33:05.166Z sha aa2e3486dcc42ac8b0e22ef4b8a7b112b5120793 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-10T09:42:20.247Z sha afd9dbd482ccc6e892a6696624595622f36b2365 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Jun 12, 2026
@Pick-cat

Copy link
Copy Markdown
Contributor Author

Addressed ClawSweeper feedback by wiring the first production buildToolPlan consumer:

  • auditPluginToolDescriptors() runs during plugin tool registration in resolvePluginTools
  • Logs unsupported-signal authoring errors (empty allOf/anyOf, malformed availability) at warn level with plugin + tool name
  • Extended onHiddenDiagnostic callback to include the hidden descriptor for actionable logs

Pushed in aa0fb8c21d. @clawsweeper re-review

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jun 14, 2026
@Pick-cat

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Addressed the P1 registration-audit blocker on head 5d4ea58:

  • capturePluginToolDescriptor now preserves availability expressions attached to plugin tools
  • resolvePluginTools audit path covered by integration test (empty availability group at registration)
  • PR body updated with production auditPluginToolDescriptors terminal proof

Focused tests pass locally (planner, audit helper, descriptor cache, resolvePluginTools warning).

@clawsweeper

clawsweeper Bot commented Jun 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@Pick-cat

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Addressed P1 typing/compatibility feedback on head af05d19d3c6:

  • Declared AnyAgentTool.availability?: ToolAvailabilityExpression and exported the type from plugin-sdk
  • Added isToolAvailabilityExpression so descriptor capture ignores non-expression metadata objects
  • Updated PR body with resolvePluginTools registration-path proof

@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Jun 14, 2026
@clawsweeper

clawsweeper Bot commented Jun 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@Pick-cat

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Re-requesting re-review on head af05d19d3c6. Previous re-review run (27503874959) stayed in progress; CI is green and P1 typing/proof feedback was addressed in the latest commit.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 🔁 re-review loop A fresh ClawSweeper review was explicitly requested after the latest review. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jun 14, 2026
@Pick-cat

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Follow-up on head a750d39b2c5 for remaining label blockers:

  • Fixed P1 cross-plugin normalized tool-name reservation after availability filtering (src/plugins/tools.ts)
  • Added cached + uncached regression coverage in tools.optional.test.ts
  • Prior CI fix (3e0aa772ba4) restored replaySafe metadata and SDK baseline hash

CI was green on 3e0aa772ba4; this push only adds the name-reservation fix + tests.

@clawsweeper

clawsweeper Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Jun 15, 2026
@Pick-cat

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main and resolved merge conflicts.

Head: 52b174ad85a — single commit on current main, scoped to warn-only descriptor authoring diagnostics (no public plugin-sdk availability exports, no fail-closed resolver filtering).

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@Pick-cat

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@Pick-cat

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The P1 crash finding (collectAuthProviderIds at src/plugins/tools.ts, reviewed against 0321c04663af) is fixed on current head b49789bc3f9:

  • af494862460 guards the recursive collector — if (!availability || typeof availability !== "object") return; before any in check — so { allOf: ["bad"] } / { anyOf: [null] } no longer throw before diagnostics are emitted.
  • Regression test resolves tools without throwing when availability holds malformed nested entries drives { allOf: ["bad", null] } through resolvePluginTools with hasAuthForProvider: () => true (the exact crash path).
  • b49789bc3f9 adds an extra self-referential-cycle guard.

Verification on head:

node scripts/run-vitest.mjs src/tools/planner.test.ts src/plugins/tool-descriptor-cache.test.ts src/plugins/tools.optional.test.ts src/tools/availability.test.ts
  -> 100 passed
node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental false
  -> exit 0

The PR body has been rewritten to match the current warn-only diff — the earlier SDK-export and fail-closed framing (and the stale head SHA) were removed, and the compatibility note now states the warn-only semantics explicitly for maintainer acceptance.

@Pick-cat

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Addressed the P2 cycle-detection finding on 16a919be3c. hasAvailabilityExpressionShape now tracks the active recursion stack (add on enter, remove in finally) instead of a cumulative seen set, so a valid expression that reuses the same signal object across siblings ({ allOf: [auth, auth] }) is no longer mis-flagged as a cycle and hidden by buildToolPlan, while genuine self-cycles still short-circuit. New regression with a negative control (passes on the recursion-stack version, fails on the old cumulative-set version) is in the body Evidence under Cycle detection fix. Touched lanes 101 passed; tsgo clean. (The earlier security-fast red was a transient PyPI pip install pre-commit failure, unrelated to the diff — re-triggered.)

@clawsweeper

clawsweeper Bot commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@Pick-cat

Pick-cat commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

Pushed fix for the P1 recursion guard:

  • Added WeakSet-backed cycle detection to collectAuthProviderIds — self-referential allOf/anyOf records no longer cause stack overflow.
  • Added regression test: cyclic availability resolves without error.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@steipete

Copy link
Copy Markdown
Contributor

Land-ready maintainer rewrite complete at exact head 53ceb54b6a712bb1e3fffe818ef4c24ca7f5f3ab.

What changed:

  • Replaced the submitted ten-file callback/cache/plugin path with one private evaluator-owned validator and focused tests.
  • Explicit null, malformed signal/group fields, ambiguous shapes, sparse arrays, and true cycles now return the existing unsupported-signal diagnostic.
  • Absent availability, valid signals, shared sibling objects, and precise empty-group diagnostics keep their existing behavior.
  • No new planner callback, runtime-tool availability contract, plugin cache, config surface, or repeated logging.
  • Contributor credit is preserved in the signed replacement commit. Thanks @Pick-cat for the original work.

Proof:

  • Exact-head hosted CI: run 29152354527, 45 passed / 11 scope-skipped / 0 failed.
  • Sanitized AWS focused tests: run_ea4dddbbf9f9, pnpm test src/tools/availability.test.ts src/tools/planner.test.ts, 2 files / 33 tests passed.
  • Sanitized AWS changed gate: run_58148ec9f23c, pnpm check:changed; core/core-test type checks, lint, and routed guards passed.
  • Sanitized AWS packed consumer: run_7a0137008e98; Node 24.15.0, pnpm 11.2.2, build and canonical pack passed, tarball SHA-256 df31c27d0123ec5562a3006d3e94fda6374e4b9eff07dddc16dab7e347d9b993.
  • Fresh external npm consumer imported openclaw/plugin-sdk/agent-runtime; marker PACKED_CONSUMER_OK valid=4 invalid=6 covered absent/undefined/always/shared-child controls plus explicit null, sparse groups/path, ambiguous shape, and cycle rejection.
  • Guest safety proof: public network, Tailscale off, empty instance profile, IMDSv2 IAM endpoint 404, only CI forwarded, no hydration. Lease released and disappeared from AWS inventory.
  • Autoreview ran until clean. Earlier passes found and drove fixes for explicit-null and sparse-array fail-open paths; final result clean at 0.94 confidence.
  • Native OPENCLAW_TESTBOX=1 scripts/pr prepare-run 92411 reused recent exact-head evidence. main advanced only in unrelated gateway history files; no rebase or PR-head movement was required.

Before: malformed plain-JavaScript descriptors could throw, overflow, or fail open. After: the installed public package returns one stable diagnostic and keeps the tool hidden. No relevant proof gap remains; the packed SDK import is the supported evaluator entry point. CHANGELOG.md remains untouched per release-owned policy.

@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

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

Labels

merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants