openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

Add generated tool provenance and admission checks

Open vaddisrinivas opened this issue 6 months ago • 3 comments

Summary

  • Extend generated tool definitions with provider, capability, digest, risk, and policy-surface metadata.
  • Add an admission helper that can enforce trusted providers, disabled providers/capabilities, source digests, safe names, and duplicate-name checks.
  • Keep legacy generated-tool behavior unchanged when provenance enforcement is disabled.

Problem

  • Generated tools can be wrapped generically, but callers do not yet have a central way to reject untrusted, duplicate, or missing-provenance definitions before registration.
  • Build/admission-time enforcement needs structured metadata that is still provider-agnostic.

Solution

  • Add GeneratedToolAdmissionConfig, GeneratedToolAdmissionReport, and admit_generated_tool_definitions.
  • Normalize generated-tool provenance fields before admission and wrapper construction.
  • Mark generated tools with external side effects when their declared risk requires it.

Submission Checklist

  • [x] Tests added or updated (happy path + at least one failure / edge case) per Testing Strategy: trusted admission, disabled legacy path, untrusted provider, duplicate names, missing risk, unsafe names, and external-effect risk.
  • [x] Diff coverage ≥ 80% — local full coverage not run; focused Rust tests cover the changed module and CI coverage gate will enforce final diff coverage.
  • [x] Coverage matrix updated — N/A: generic generated-tool infrastructure, no existing feature row added/removed/renamed.
  • [x] All affected feature IDs from the matrix are listed in the PR description under ## Related: N/A, no coverage-matrix feature ID applies.
  • [x] No new external network dependencies introduced (mock backend used per Testing Strategy): no network dependency added.
  • [x] Manual smoke checklist updated if this touches release-cut surfaces (docs/RELEASE-MANUAL-SMOKE.md): N/A, no release-cut UI/runtime smoke surface changed.
  • [x] Linked issue closed via Closes #NNN in the ## Related section.

Impact

  • Runtime/platform impact: generated-tool callers can opt into stricter admission without changing default registration behavior.
  • Security impact: enables provenance and risk checks before generated tools become executable Tool objects.
  • Compatibility: existing GeneratedToolDefinition::new callers continue to work with metadata fields defaulted to None.

Related

  • Closes #2542
  • Follow-up PR(s)/TODOs: Companion PRs add provider registry and runtime policy/audit hooks.

AI Authored PR Metadata (required for Codex/Linear PRs)

Linear Issue

  • Key: N/A - GitHub issue #2542
  • URL: https://github.com/tinyhumansai/openhuman/issues/2542

Commit & Branch

  • Branch: codex/oh-2542-generated-tool-admission
  • Commit SHA: 46631365d44929e2eef03935020cdcc5690abca6

Validation Run

  • [x] pnpm --filter openhuman-app format:check: N/A, Rust-only backend tool-infrastructure change.
  • [x] pnpm typecheck: N/A, Rust-only backend tool-infrastructure change.
  • [x] Focused tests: cargo test --manifest-path Cargo.toml generated_tool --lib; cargo test --manifest-path Cargo.toml admission_ --lib
  • [x] Rust fmt/check (if changed): cargo fmt --manifest-path Cargo.toml --all --check; git diff --check
  • [x] Tauri fmt/check (if changed): N/A, no Tauri code changed.
  • [x] PR checklist: node scripts/check-pr-checklist.mjs /tmp/openhuman-pr-body-2542.md

Validation Blocked

  • command: N/A
  • error: N/A
  • impact: N/A

Behavior Changes

  • Intended behavior change: callers can opt into generated-tool admission enforcement.
  • User-visible effect: None by default; provenance enforcement is disabled unless a caller enables it.

Parity Contract

  • Legacy behavior preserved: yes, admission with default config admits existing generated tools.
  • Guard/fallback/dispatch parity checks: adapter mismatch and existing generated-tool validation continue to run before wrapping.

Duplicate / Superseded PR Handling

  • Duplicate PR(s): None found for vaddisrinivas:codex/oh-2542-generated-tool-admission.
  • Canonical PR: this PR.
  • Resolution (closed/superseded/updated): N/A.

Summary by CodeRabbit

  • New Features

    • Metadata for generated tools (provenance, capability, policy, risk) and risk classification that identifies external-effectful tools.
    • Admission pipeline to normalize, validate, and admit/reject tool definitions with configurable enforcement, deduplication, provider/capability allow/deny checks, and explicit rejection reasons.
  • Tests

    • Unit tests covering admission behavior, enforcement toggles, rejection scenarios, and external-effect detection.

Review Change Stack

vaddisrinivas avatar May 23 '26 15:05 vaddisrinivas

📝 Walkthrough

Walkthrough

Adds optional provenance/capability/risk/policy fields to generated tool definitions, a GeneratedToolRisk enum, an admission pipeline that normalizes and validates definitions against configurable policies, Tool::external_effect() mapping from risk, and unit tests covering admission outcomes and risk behavior.

Changes

Generated Tool Provenance and Admission

Layer / File(s) Summary
Data model: provenance & risk metadata
src/openhuman/tools/generated.rs
GeneratedToolDefinition gains optional provider_id, capability_id, source_digest, policy_surface, and risk: Option<GeneratedToolRisk>. GeneratedToolRisk enum and public admission structs (GeneratedToolAdmissionConfig, GeneratedToolAdmissionRejection, GeneratedToolAdmissionReport) are added.
Admission entry: admit_generated_tool_definitions
src/openhuman/tools/generated.rs
Adds admit_generated_tool_definitions(...) which normalizes incoming definitions (trims required and optional fields) and returns a GeneratedToolAdmissionReport with admitted and rejected lists.
Validation and helpers: validate_admission & utilities
src/openhuman/tools/generated.rs
validate_admission(...) enforces schema checks, safe-name rules, deduplication vs existing names, provider allow/deny lists, capability deny list, and requires risk+source_digest when enforcement is enabled; includes provider-id normalization and name-safety helpers.
Tool trait: external_effect implementation
src/openhuman/tools/generated.rs
impl Tool for GeneratedTool now implements external_effect() by treating certain GeneratedToolRisk variants as external-effectful.
Tests and sample data
src/openhuman/tools/generated.rs
sample_definition() updated with new metadata; adds admission_config() helper and unit tests for trusted acceptance, legacy acceptance when enforcement disabled, invalid/untrusted provider rejection, duplicate-name rejection, enforcement-required-field rejections, unsafe-name rejection, and external_effect() checks for ExternalWrite and Execute.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • tinyhumansai/openhuman#2333: Related changes to src/openhuman/tools/generated.rs around generated-tool normalization and adapter-id validation; overlap in generated tool handling.

Suggested reviewers

  • graycyrus

Poem

🐰 I trimmed the names and checked each trait,
I marked the risks that wander out the gate.
Providers stamped and digests neat,
Admissions sort the safe from what’s not sweet.
Hooray — the tool garden hops, a little safer on its feet!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 54.84% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately and concisely describes the main change: adding provenance metadata and admission validation for generated tools.
Linked Issues check ✅ Passed The PR implements all coding requirements from #2542: provenance metadata fields, admission validation logic, diagnostics reporting, and test coverage for allowed/rejected cases.
Out of Scope Changes check ✅ Passed All changes are directly related to #2542 objectives. The external_effect() trait implementation for risk classification is within scope as it supports admission enforcement.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar May 23 '26 15:05 coderabbitai[bot]

Review note on provider/provenance coupling: this PR trims generated-tool provider_id, but admission compares it directly against raw trusted_providers / disabled_providers sets. That is fine as a local helper, but it means provider-id normalization and duplicate-provider semantics can drift from #2541/#2548/#2551.\n\nI would avoid merging this independently of the provider registry decision. Once #2541 has a canonical registry, admission should consume normalized provider records from that registry rather than maintaining a parallel raw BTreeSet<String> trust model. That keeps enforcement behavior stable for case/whitespace/separator edge cases and reduces reviewer surface in #2542/#2543.

YOMXXX avatar May 24 '26 15:05 YOMXXX

Okay getting more eyes on this @graycyrus can you review this?

senamakel avatar May 25 '26 04:05 senamakel

@YOMXXX — agreed that the long-term home for trusted-provider state is the registry in #2541, not a parallel BTreeSet<String> model in this admission helper. Calling that out here so it doesn't get lost:

  • This PR keeps the raw set as a local helper only — normalize_provider_set runs the same normalize_provider_id rules the definitions go through, so case / whitespace / separator edge cases stay consistent for the values that are present.
  • Once #2541 lands a canonical registry, GeneratedToolAdmissionConfig should consume normalized provider records from there instead of carrying its own trust sets. Tracking that follow-up as a hard dependency on this admission path.

Holding the merge on the registry decision SGTM if a maintainer wants to gate it that way; happy to rebase on top of #2541 once it lands.

sanil-23 avatar May 28 '26 15:05 sanil-23

Hey @graycyrus — could you take a look at this one? vaddisrinivas's generated-tool admission PR is CI fully green (29 success / 0 fail) on head bfc4ea8c. CodeRabbit's most recent automated review came back with 0 actionable comments after the rfix push (test mod extracted to sibling, admission logging on dropped invalid provider IDs). YOMXXX's architectural concern about #2541 provider registry is acknowledged as a follow-up. Ready for a maintainer's eye.

sanil-23 avatar May 28 '26 17:05 sanil-23

Posted #2869 with the root-cause fix: #2830's merge inadvertently reverted #2786's SessionExpired classification back to BackendUserError, so the classifies_embedding_api_invalid_token_401_as_session_expired test added by #2786 has been failing on every PR rebased onto post-#2830 main. One-line classifier fix + reconciled the stale companion test.

sanil-23 avatar May 28 '26 20:05 sanil-23