Skip to content

fix(tools): surface hidden-tool diagnostics via onHiddenDiagnostic callback - #94099

Closed
fsdwen wants to merge 1 commit into
openclaw:mainfrom
fsdwen:fix/92361-tool-availability-hidden-diagnostic
Closed

fsdwen wants to merge 1 commit into
openclaw:mainfrom
fsdwen:fix/92361-tool-availability-hidden-diagnostic

Conversation

@fsdwen

@fsdwen fsdwen commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The tool planner (buildToolPlan) silently hid descriptors with malformed availability expressions (empty allOf/anyOf groups), because it had no mechanism to surface unsupported-signal diagnostics to callers. Tools were hidden with detailed diagnostics but no observable signal reached the developer.

Root Cause

In evaluateExpression (availability.ts), empty allOf/anyOf arrays correctly produce unsupported-signal diagnostics, but buildToolPlan consumes them silently — it pushes descriptors into the hidden[] array with no callback, logger, or event emitter to notify callers.

Additionally, evaluateExpression calls .flatMap() / .map() on allOf/anyOf values without checking they are actually arrays — allowing a crash path if non-array values bypass the TS type system.

Fix

This adds an optional onHiddenDiagnostic callback to BuildToolPlanOptions. The planner invokes it for each diagnostic that hides a tool, giving callers a channel to observe authoring errors without coupling the planner to a specific logging mechanism.

It also adds defensive Array.isArray guards in evaluateExpression before .flatMap() / .map() calls to prevent crashes on malformed non-array allOf/anyOf values.

  • src/tools/types.ts: add onHiddenDiagnostic callback to BuildToolPlanOptions
  • src/tools/planner.ts: invoke onHiddenDiagnostic for each diagnostic that hides a tool
  • src/tools/availability.ts: add Array.isArray guards on allOf/anyOf before .flatMap/.map
  • src/tools/planner.test.ts: verify callback behavior across 3 descriptors (visible, malformed, env-missing)
  • src/tools/availability.test.ts: verify crash prevention for non-array allOf and anyOf

Alternative approaches considered

Approach Verdict
console.warn in evaluateToolAvailability (PR #92368, closed) ❌ Violates purity contract of the evaluator
Full resolvePluginTools integration + recursive validation + SDK exports (PR #92411, open) ❌ Too broad (530 lines / 10 files) — mixes crash prevention, production wiring, and SDK surface into one change
Bounded callback + defensive checks (this PR) ✅ Keeps evaluator pure, adds observable surface at the planner boundary, prevents crash, minimal scope (82 lines / 5 files)

Verification

$ node scripts/run-vitest.mjs run src/tools/planner.test.ts src/tools/availability.test.ts

 ✓  unit  src/tools/availability.test.ts (11 tests) 171ms
 ✓  unit  src/tools/planner.test.ts (7 tests) 29ms
 Test Files  2 passed (2)
      Tests  18 passed (18)

$ node scripts/run-vitest.mjs run src/tools/

 Test Files  3 passed (3)
      Tests  20 passed (20)

Standalone crash-prevention proof:

$ node --import tsx --no-warnings -e "import { evaluateToolAvailability } from './src/tools/availability.js'; ..."
Empty anyOf diagnostic: [{"reason":"unsupported-signal","message":"Empty availability anyOf group"}]
Non-array allOf (no crash): [{"reason":"unsupported-signal","message":"Empty availability allOf group"}]
Non-array anyOf (no crash): [{"reason":"unsupported-signal","message":"Empty availability anyOf group"}]

Real behavior proof

Behavior addressed: Empty allOf/anyOf arrays in tool availability descriptors produce unsupported-signal diagnostics that were silently consumed by buildToolPlan. The planner had no mechanism to surface authoring errors to callers, and evaluateExpression could crash on non-array allOf/anyOf values that bypassed the TS type system.

Real environment tested: Linux, Node.js v22.19.0, OpenClaw upstream/main (0842cb71eb), branch fix/92361-tool-availability-hidden-diagnostic.

Exact steps or command run after this patch:

cd /home/0668000615/10239986/github/openclaw-worktrees/fix-92361-tool-availability-hidden-diagnostic
node scripts/run-vitest.mjs run src/tools/planner.test.ts src/tools/availability.test.ts

Evidence after fix:

 ✓  unit  src/tools/availability.test.ts (11 tests) 171ms
 ✓  unit  src/tools/planner.test.ts (7 tests) 29ms
 Test Files  2 passed (2)
      Tests  18 passed (18)

The onHiddenDiagnostic callback test verifies:

  • Visible tools do NOT trigger any callback
  • Hidden tools with unsupported-signal diagnostics trigger one callback per diagnostic
  • Hidden tools with env-missing diagnostics trigger one callback per diagnostic
  • Multiple hidden tools each produce their own callbacks

Crash-prevention proof:

$ node --import tsx --no-warnings -e "
import { evaluateToolAvailability } from './src/tools/availability.js';
const d = { name:'t',description:'t',inputSchema:{type:'object'},owner:{kind:'core'},executor:{kind:'core',executorId:'t'},availability:{allOf:'not-array'}} as any;
const r = evaluateToolAvailability({ descriptor: d });
console.log(JSON.stringify(r));
"
[{"reason":"unsupported-signal","message":"Empty availability allOf group"}]

No crash — returns a diagnostic instead of throwing .flatMap is not a function.

Observed result after fix: buildToolPlan now calls onHiddenDiagnostic for each diagnostic that hides a tool, giving callers a channel to observe authoring errors. evaluateExpression returns unsupported-signal diagnostics for non-array allOf/anyOf values instead of crashing with .flatMap is not a function. All 18 direct tests and 20 total tools-directory tests pass.

What was not tested: Live gateway startup with a production caller wiring the onHiddenDiagnostic callback, because buildToolPlan has no production callers on current main. The callback contract is verified through unit tests; production wiring is a separate integration task.

What this does NOT change

  • evaluateToolAvailability and evaluateExpression remain pure and side-effect free
  • The ToolPlan.hidden array still contains diagnostics (backward compatible)
  • This PR does NOT wire buildToolPlan into resolvePluginTools — production integration is a separate concern

Closes #92361.

🤖 Generated with Claude Code

…llback

The tool planner silently hid descriptors with malformed availability
expressions (empty allOf/anyOf groups), because buildToolPlan had no
mechanism to surface diagnostics to callers.

This adds an optional onHiddenDiagnostic callback to BuildToolPlanOptions
so callers can observe authoring errors like empty availability groups.
It also adds defensive Array.isArray checks in evaluateExpression to
prevent crashes when non-array values bypass the TS type system.

- types: add onHiddenDiagnostic callback to BuildToolPlanOptions
- planner: invoke onHiddenDiagnostic for each diagnostic that hides a tool
- availability: add Array.isArray guards on allOf/anyOf before .flatMap/.map
- tests: verify callback behavior (3 descriptors) and crash prevention (2 cases)

Fixes openclaw#92361

Co-Authored-By: Claude <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 17, 2026
@clawsweeper

clawsweeper Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed June 24, 2026, 6:47 AM ET / 10:47 UTC.

Summary
This PR adds an optional onHiddenDiagnostic callback to BuildToolPlanOptions, invokes it for hidden availability diagnostics, guards non-array allOf/anyOf, and adds focused tests.

PR surface: Source +12, Tests +67. Total +79 across 5 files.

Reproducibility: yes. Source inspection shows empty availability groups produce unsupported-signal diagnostics, current buildToolPlan only records them in hidden, and current plugin descriptor capture does not preserve availability for registration-time visibility.

Review metrics: 1 noteworthy metric.

  • Public Planner Option: 1 added. BuildToolPlanOptions is exported through the tools barrel and plugin SDK runtime barrel, so callback semantics should be accepted before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #92361
Summary: The canonical issue tracks empty availability-group diagnostics; this PR is one candidate fix, with several overlapping open candidates and no merged canonical implementation yet.

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] Add redacted terminal output proving buildToolPlan invokes onHiddenDiagnostic outside the unit-test assertion, or prove the registration/resolver path after wiring it.
  • Have maintainers choose whether the exported planner callback should exist before or instead of a lifecycle-owned registration warning path.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: The PR body includes terminal/unit evidence for tests and evaluator crash prevention, but it does not show the new callback firing in a direct runtime invocation or the requested registration/resolver path; screenshots, terminal output, copied live output, linked artifacts, recordings, and redacted logs count, with private details redacted, and updating the PR body should trigger a fresh ClawSweeper review or a maintainer can comment @clawsweeper re-review. 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] Merging this branch with its closing reference could close [Bug]: Tool availability evaluator silently ignores empty allOf/anyOf groups during expression normalization #92361 while the plugin registration/startup diagnostic path remains silent.
  • [P1] The PR adds an exported planner option reachable through the tools barrel and plugin SDK runtime barrel, so maintainers should confirm that this callback is intended public API surface.
  • [P1] The supplied real behavior proof covers unit tests and evaluator crash prevention, but it does not show the callback firing from a direct runtime invocation or from the production registration/resolver path.

Maintainer options:

  1. Choose The Supported Boundary (recommended)
    Maintainers should decide whether the supported fix is a planner callback, a registration/resolver warning, or both before adding the exported option.
  2. Wire The Observable Path
    Extend this branch so plugin-authored availability is preserved or evaluated at descriptor registration or plugin resolution, then prove the warning or diagnostic output from that path.
  3. Accept API Helper Only
    Maintainers can intentionally accept the callback as a narrow helper, but should avoid closing the canonical issue until a visible registration/startup diagnostic path lands.

Next step before merge

  • [P1] Maintainers need to choose the canonical implementation and public API boundary among linked PRs before automation expands this partial helper into production wiring.

Security
Cleared: No concrete security or supply-chain regression was found; the diff changes TypeScript source/tests only and does not touch dependencies, workflows, secrets, permissions, or downloaded code execution.

Review findings

  • [P2] Wire hidden diagnostics into the registration path — src/tools/planner.ts:50-55
Review details

Best possible solution:

Land one canonical fix that keeps the evaluator pure and surfaces malformed availability diagnostics once at the plugin descriptor registration or resolver boundary; keep the planner callback only if maintainers want that public API.

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

Yes. Source inspection shows empty availability groups produce unsupported-signal diagnostics, current buildToolPlan only records them in hidden, and current plugin descriptor capture does not preserve availability for registration-time visibility.

Is this the best way to solve the issue?

No. The callback is a plausible helper, but without a production caller or registration sink it is not the complete fix for the linked runtime diagnostic issue.

Full review comments:

  • [P2] Wire hidden diagnostics into the registration path — src/tools/planner.ts:50-55
    Adding the callback here only changes behavior when a caller passes it, but current source search found no production buildToolPlan caller, and plugin descriptor capture still omits tool-authored availability. The linked bug asks for warning-level diagnostics at registration/startup, so this PR should wire the callback into that path or stop closing the canonical issue here.
    Confidence: 0.9

Overall correctness: patch is incorrect
Overall confidence: 0.88

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: The PR targets a bounded developer-facing tool planning diagnostic bug with limited runtime blast radius.
  • merge-risk: 🚨 compatibility: The diff adds an exported planner option reachable through public tool and plugin SDK runtime surfaces.
  • merge-risk: 🚨 other: The branch could close the canonical diagnostic issue without adding the requested observable plugin registration or startup diagnostic path.
  • 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 PR body includes terminal/unit evidence for tests and evaluator crash prevention, but it does not show the new callback firing in a direct runtime invocation or the requested registration/resolver path; screenshots, terminal output, copied live output, linked artifacts, recordings, and redacted logs count, with private details redacted, and updating the PR body should trigger a fresh ClawSweeper review or a maintainer can comment @clawsweeper re-review. 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 +12, Tests +67. Total +79 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 14 2 +12
Tests 2 68 1 +67
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 82 3 +79

What I checked:

  • Repository policy read: Root AGENTS.md was read fully and applied; its PR review policy treats plugin/API surfaces and registration behavior as compatibility-sensitive review context. (AGENTS.md:1, bfffc77bfc86)
  • Scoped plugin policy read: The plugin SDK and plugin boundary guides were read because the tools barrel is re-exported through src/plugin-sdk/agent-runtime.ts and the linked observable behavior crosses plugin descriptor registration. (src/plugin-sdk/AGENTS.md:1, bfffc77bfc86)
  • Current planner only records hidden diagnostics: On current main, buildToolPlan evaluates availability, pushes descriptors with diagnostics into hidden, and continues without logging, emitting, or invoking any diagnostic sink. (src/tools/planner.ts:47, bfffc77bfc86)
  • Current evaluator source-reproduces the malformed diagnostic path: Current main returns unsupported-signal for empty allOf/anyOf, while non-array groups still reach .flatMap()/.map() without guards. (src/tools/availability.ts:132, bfffc77bfc86)
  • No production planner caller found: Repository search found buildToolPlan in the planner module, tests, and the public tools barrel, but no production caller that would pass the new callback after this PR. (bfffc77bfc86)
  • Plugin descriptor capture drops availability on main: Current capturePluginToolDescriptor copies name, title, description, schema, owner, and executor, but not plugin-authored availability, so registration-time empty-group diagnostics cannot be surfaced from cached descriptors. (src/plugins/tool-descriptor-cache.ts:147, bfffc77bfc86)

Likely related people:

  • shakkernerd: Commit c5224a341e79 introduced the generic tool descriptor planner, evaluator, and types touched by this PR. (role: introduced planner surface; confidence: high; commits: c5224a341e79; files: src/tools/availability.ts, src/tools/planner.ts, src/tools/types.ts)
  • hansraj316: Commit 201b5f312f8a changed unsupported-signal propagation in anyOf, directly adjacent to the malformed availability diagnostic behavior. (role: recent availability diagnostic contributor; confidence: medium; commits: 201b5f312f8a; files: src/tools/availability.ts, src/tools/availability.test.ts)
  • steipete: Commit 1466878c36ff added plugin descriptor cache behavior around the registration boundary implicated by the linked bug. (role: plugin descriptor-cache contributor; confidence: high; commits: 1466878c36ff; files: src/plugins/tool-descriptor-cache.ts, src/plugins/tools.ts)
  • medns: Commit 0781dae6204e recently touched request-local plugin tool discovery in src/plugins/tools.ts, adjacent to where a resolver diagnostic sink would likely live. (role: recent plugin resolver contributor; confidence: medium; commits: 0781dae6204e; files: src/plugins/tools.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.

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 17, 2026
@fsdwen

fsdwen commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

All CI checks are green (135 passed). Ready for review.

@vincentkoc would you mind reviewing this? Thanks!

@fsdwen

fsdwen commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 17, 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Jun 17, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Jun 20, 2026
@clawsweeper

clawsweeper Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

@fsdwen thanks for the PR. ClawSweeper is still waiting on real behavior proof before this can move forward.

Useful proof can be a screenshot, short video, terminal output, copied live output, linked artifact, or redacted logs that show the changed behavior after the fix. Please redact private tokens, phone numbers, private endpoints, customer data, and anything else sensitive.

Once proof is added to the PR body or a comment, ClawSweeper or a maintainer can re-check it.

@steipete

Copy link
Copy Markdown
Contributor

Closing as not planned after #92411 landed the concrete evaluator hardening in 0ca6880f3d92d122f10eb80f6b3c46a16cdba6de.

This PR's callback would expand the public planner/SDK contract without a production caller or lifecycle owner. The generic planner already returns diagnostics in ToolPlan.hidden; it should remain pure rather than owning logging policy. Plugin tool availability is manifest-first, so an unused callback does not establish the missing registration path.

#92411 now rejects malformed, sparse, ambiguous, and cyclic plain-JavaScript expressions without throwing or failing open. If a current production registration owner is later shown to discard those returned diagnostics, the supported follow-up is one owner-boundary integration with a live caller repro—not a generic callback added in advance.

Thanks @fsdwen for the careful crash-path analysis and proof.

@steipete steipete closed this Jul 11, 2026
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. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. 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.

[Bug]: Tool availability evaluator silently ignores empty allOf/anyOf groups during expression normalization

2 participants