Repository navigation
fix(app-tools): guard null properties in parameter schemas, fallback user_id, and sanitize tool names (#23297) - #23829
Conversation
Git-on-my-level
left a comment
There was a problem hiding this comment.
The hardening here is solid and well tested — the crash fixes for #23297 are correct — but one change silently alters the request body some existing app tools receive, so I'm requesting a small revision before merge.
What's right (verified):
- app_tools.py
_create_pydantic_model_from_schema: isinstance guards for parameters/properties/required and non-dict param schemas correctly kill the AttributeError/TypeError crashes from #23297. - app_tools.py
_clean_identifier+ tool/model name sanitization is genuinely needed (create_modelmodel names and StructuredTool names do require identifiers), and status-message lookups stay consistent since both writer and reader use the sanitized name. - app_tools.py
_call_tool_endpoint: top-leveluser_idfallback, empty-endpoint guard, and method defaulting to POST all match the issue and are tested. - app_tools.py
load_app_tools:or [], falsy app_id skip, and None-tool skip are correct defensive fixes. - backend/tests/unit/test_app_tools_schema_and_guards.py: I ran all 10 tests in an isolated sandbox — they pass, and they're properly hermetic (httpx/db/circuit-breaker all mocked).
Blocking issue:
- app_tools.py ~line 168 (
clean_field_name = _clean_identifier(param_name, "field")): renamed fields flow straight into the HTTP payload —_call_tool_endpointbuildspayload = {**kwargs, 'uid': uid, ...}(~line 368). Pydantic v2'screate_modelaccepts non-identifier field names (I verifieduser-id,q.query, and123startall construct on the current stack), so before this PR a tool schema declaring"user-id"delivered"user-id"in the JSON body to the app's endpoint. After this PR the endpoint silently receives"user_id". Apps with hyphenated/dotted parameter keys would break with no error on our side. Please keep the raw schema param name on the wire — either keep raw names as field names (they work in pydantic) and sanitize only where identifiers are truly required (model/tool names), or map cleaned names back to the originals when building the payload (aFieldalias would do it). - Same function: two params that sanitize to the same identifier (e.g.
max-tokensandmax_tokens) silently collapse — the later entry overwrites the earlier infield_definitions. A warning log or dedupe check would make this visible. - Test nit:
test_call_tool_endpoint_top_level_user_idsetsagent_config_contextwithout a try/finally reset (thenone_methodtest does this correctly) — the contextvar leaks to later tests in the same process.
Blast radius: only app tools whose schemas use non-identifier parameter names are affected by issue 1; tools with plain identifier params behave identically to before.
USER IMPACT: App tools with parameter names containing characters like "-" or "." would stop receiving those exact keys; for everyone else this just means fewer crashes from malformed app tool schemas.
What I'd still want as a reviewer: a test asserting wire-key fidelity (schema param name == JSON key sent to the endpoint) for a non-identifier param name, a decision/log for sanitization collisions, and the contextvar reset fix. Once param-name handling is settled, this is close to mergeable — the raw-vs-sanitized wire key choice is worth a maintainer familiar with app-tool schemas sanity-checking.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
…user_id, and sanitize tool names (BasedHardware#23297)
…, add wire fidelity test (BasedHardware#23297)
c484959 to
7cb0b22
Compare
|
@Git-on-my-level All three review items addressed: 1. Raw parameter names preserved on wire (blocking issue resolved):
2. Contextvar leak fixed:
3. Wire-key fidelity test added:
Verification:
Payout Address: |
Resolved on head 7cb0b22: raw schema parameter names are now kept as pydantic field names (verified by head-to-head diff — the clean_field_name mapping is removed), so HTTP payloads preserve the exact schema keys; a wire-fidelity test asserts this end-to-end. The test contextvar leak was also fixed. Blocking concerns from this review are addressed.
Git-on-my-level
left a comment
There was a problem hiding this comment.
Since my last review: addressed (wire-key fidelity — raw schema parameter names are now kept as field names and asserted on the wire; the test contextvar leak; collision visibility) · still open (nothing blocking) · newly introduced (nothing problematic — the added transport/description/method guards are safe).
Verdict: all prior blocking concerns are resolved on this head — the #23297 crash fixes now ship without changing what existing app tools receive. From my side this is ready for a maintainer merge decision.
Verified on head 7cb0b22 (both changed files):
- backend/utils/retrieval/tools/app_tools.py —
_create_pydantic_model_from_schemanow keysfield_definitionsby the rawparam_name; the previousclean_field_namemapping (which rewroteuser-idtouser_idin the HTTP payload) is gone — I diffed the two heads to confirm._clean_identifieris still applied where identifiers are genuinely required (create_model model name, StructuredTool name), and the status-message writer/reader (_remember_tool_status/get_tool_status_message) both key on that same sanitized name, so lookups stay consistent. - The duplicate-param warning in that loop is effectively unreachable (schema
propertiesis a dict, so keys are unique) — harmless, and the original collision concern is moot now that raw keys can no longer collapse into one identifier. - The new small guards (
_transportdefaulting to 'sse', description falling back to the tool name,methodwhitespace stripping,configurableisinstance checks) don't alter behavior for well-formed tools. - backend/tests/unit/test_app_tools_schema_and_guards.py — I ran all 11 tests in an isolated sandbox on this head: pass.
test_call_tool_endpoint_preserves_wire_key_fidelityassertsuser-idandq.paramarrive bit-for-bit in the JSON body and the sanitized forms do not, and every test that setsagent_config_contextnow resets it in a finally block.
Security/blast radius: no new external calls or data flows; payloads to existing tool endpoints are unchanged for identifier-safe schemas.
USER IMPACT: none beyond the intended fix — chats with malformed app-tool schemas stop erroring, and every working app tool keeps receiving exactly the parameter keys it gets today.
What I'd still want: nothing blocking. Optional nit if you touch this again: decide whether to keep the unreachable duplicate-name warning or drop it.
Leaving the merge decision to a human maintainer.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
|
One new item since my last review of this head - the code conclusion there is unchanged. Blocking (metadata, not code): Re-verified on the current head
Blast radius: no new external calls, auth changes, or data exposure - the guards only tighten error paths; worst case if wrong is a malformed tool failing to load with a logged warning. USER IMPACT: apps that publish tools with null or incomplete JSON schemas (the #23297 crashes) now work instead of erroring, and tools with unusual names load reliably. Nothing further wanted from my side code-wise. Ready for a human maintainer's merge call once the Failure-Class line is added and preflight passes. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
|
@Git-on-my-level Thank you! The PR description has been updated with the required All metadata preflight checks are now verified and passing. Ready for maintainer merge! |
|
Hey @Dimank92 👋 Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request. After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:
Before your next PR, please skim:
If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing. Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out. Thank you for being part of the Omi community! |
Summary
Closes #23297
Resolves crashes and errors in
backend/utils/retrieval/tools/app_tools.pywhen handling dynamic app tools:_create_pydantic_model_from_schemaagainst"properties": None,"required": None, orNoneparameter schemas._clean_identifierhelper to safely normalize arbitrary tool names and parameter keys into valid Python identifiers.uid = configurable.get('user_id') or config.get('user_id')in_call_tool_endpoint.app_tool.methodto default to'POST', and validatesapp_tool.endpoint.get_enabled_apps(uid) or []and sanitizes items inchat_tools.backend/tests/unit/test_app_tools_schema_and_guards.py(100% passing).Verification
Product invariants affected
none
UI evidence
UI-Evidence: none -- internal logic and test suite only; no UI change.
Failure class (fixes)
Failure-Class: none