Files
dify/api/services/external_agents/execution_usage.py
Yansong Zhang 3dcec58817 fix(a2a): retain standalone inputs and reported usage on dev [skip ci]
Apply only independent DIFY-3055 fix 74897faa05 on top of current dev 679d65bf9f. Preserve all existing frontend, Native, Hosted and Billing integration history. No latest-main merge is imported into dev.

The current Hosted API and dedicated external worker use separately validated preserving source layers, with a non-Hosted default API fallback. This dev-only ref update avoids opaque automatic full-stack deployment. The same backend PR runs normal required CI; no workflow settings change.
2026-11-19 21:31:33 +08:00

31 lines
1.4 KiB
Python

"""Consumer-owned reads of proven usage for one frozen external execution.
Usage is observational: missing evidence never means zero and cannot change a
business result, submit work, or authorize another execution.
"""
from datetime import datetime
from typing import Protocol
from .runtime_contracts import RuntimeScope
class ExternalExecutionUsageQuery(Protocol):
def total_tokens(self, scope: RuntimeScope, invocation_id: str, *, now: datetime) -> int | None:
"""Read the admitted owner's retry prefix through this exact Invocation.
Preconditions: scope is the admitted execution owner and now is the
observation time. Reconstruct its complete persisted identity, validate
every attempt and retry link, and count only actual business dispatches.
Different connection revisions may belong to the same legal retry chain.
Postconditions: return a nonnegative sum only when every dispatched
attempt has a proven call-total summary; a reported zero remains zero.
None means no dispatch or unavailable/incomplete ownership, retention,
retry-chain or usage evidence. Never sum Trace steps or infer zero from
a missing record. Reads have no business or provider side effects.
Infrastructure failures may raise; callers must preserve the business
result and treat a failed read as unknown usage.
"""
...