Adapter function metrics record success for contract-level IOContract mismatches

未关闭
#1,611 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
python
领域
observability

调研方向

Start with mellea/stdlib/components/intrinsic/_util.py at call_intrinsic, then compare the invocation-completion handling in adapter.py and the Embedded/Granite formatter closures added in PR #1609. Trace both the embedded and local_file paths, including how synchronous code dispatches async hooks. Done means contract-level output mismatches are recorded as failures, valid outputs as successes, and each invocation fires exactly once.

由索引模型根据 Issue 内容生成。

描述

area/adapter-functions area/telemetry bug p2

Summary

mellea.adapter_function.invocations/.parse_failures mis-record one class of failure for adapter functions called through call_intrinsic: a contract-level IOContract mismatch on output that is valid JSON.

Background

PR #1609 (issue #1560) wired adapter_function_invocation_complete firing for the Embedded/Granite Switch binding. It fires the outcome once each backend's granite_formatters_processing closure resolves — success if the response parses as JSON, schema_error if it doesn't, error otherwise.

That closure runs before call_intrinsic (mellea/stdlib/components/intrinsic/_util.py:171) calls adapter.io_contract.parse(result_str) — the actual contract check (required fields, types, shape). So when a response is syntactically valid JSON but fails that contract check, AdapterSchemaMismatchError is raised to the caller — but the invocation was already recorded as outcome="success".

Impact

  • The caller is unaffected: AdapterSchemaMismatchError propagates uncaught through every wrapper (rag.py, core.py, guardian.py) straight to application code. No silent failures.
  • The metric is wrong: .parse_failures undercounts this specific failure mode, and .invocations{outcome="success"} overcounts it. A model that drifted into returning valid-but-wrong-shape JSON would look 100% healthy on a dashboard built from these metrics while every call actually fails downstream.
  • Scope is narrow: only applies to output that's valid JSON but violates the adapter's declared schema — not malformed JSON (already schema_error) and not a generation/network failure (already error).
  • Applies to local_file/PEFT too, not just embedded — AdapterMixin.adapter_scope's outcome closes at generation return, before parsing or contract validation ever run, so this binding never records anything for this failure mode either.

Proposed fix

Move (or add) the invocation-complete fire point into call_intrinsic, after io_contract.parse() resolves, so the recorded outcome reflects contract validation too. Complications:

  • call_intrinsic is shared by both bindings — this needs handling that's correct for local_file as well as embedded, not an embedded-only patch.
  • call_intrinsic is synchronous; hook dispatch (invoke_hook) is async. Needs the same sync→async bridging adapter.py's _fire_invocation_complete already does via _run_async_in_thread — the embedded fire helper introduced in #1609 (_fire_embedded_invocation_complete) deliberately avoids that bridging since it's always called from an already-running coroutine, so this can't just reuse it as-is.
  • Need to decide whether the backend-level success fire (in the closures) should be suppressed/deferred entirely in favour of this one, to keep the "fires exactly once per invocation" invariant intact.

cc @ajbozarth

主要语言
Python
星标
1.8k
派生
161
平均合并
4 天 3 小时
30 天内合并 PR
45

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

generative-computing/mellea 的其他 Issue

查看 generative-computing/mellea 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。