feat: expose bare generation time and hedge flags in CallStats
CallStats gains hedges/generation_ms/hedge_won (all defaulted, appended after total_latency_ms); _CallContext counts them via record_generation (overwrite for chat/OCR, accumulate for embedding batches) and register_hedge, and snapshot carries them out. All three _attempt implementations time only the transport call itself on the same injected clock as total_latency_ms; the chat sink is recorded by the orchestrator so hedge winner attribution stays with T3. Hedge counters stay 0/False until the T3 orchestration lands. Red-green evidence: tests/outputs/137/t2/ (10 new tests AttributeError red, then green; full unit+contracts 1621 passed).
This commit is contained in:
@@ -370,7 +370,11 @@ class EmbeddingClient:
|
||||
# 登记在 transport 调用**之前**(同 RetryMW): 失败与取消的尝试也真的发出去了
|
||||
context.register_attempt()
|
||||
try:
|
||||
# 裸生成时间(1.3.7 H8): 计时只包 transport 调用本身(同 RetryMW 口径),
|
||||
# 与本链路 total_latency_ms 同一只注入钟;分批累加在成功分支登记
|
||||
gen_started = self._now()
|
||||
result = await self._transport.embed(texts=batch, source=source, call_id=call_id)
|
||||
gen_ms = int((self._now() - gen_started) * 1000)
|
||||
if self._expected_dim is not None and result.dim != self._expected_dim:
|
||||
raise ResultInvalidError(
|
||||
f"{source.name} 维度 {result.dim} 不符期望 {self._expected_dim}",
|
||||
@@ -384,6 +388,7 @@ class EmbeddingClient:
|
||||
actual = result.prompt_tokens
|
||||
# 真实 usage 恰为 0 也是已知事实, 后续取消不得改写成 est
|
||||
settlement_known = True
|
||||
context.record_generation(gen_ms, accumulate=True)
|
||||
await self._record_quietly(self._breaker.record_success(entry))
|
||||
await self._record_quietly(self._quota.mark_progress())
|
||||
latency_ms = int((self._now() - started) * 1000)
|
||||
|
||||
Reference in New Issue
Block a user