feat(model): per-attempt ModelEvent retry accounting and timing#4526
Open
sjawhar wants to merge 1 commit into
Open
feat(model): per-attempt ModelEvent retry accounting and timing#4526sjawhar wants to merge 1 commit into
sjawhar wants to merge 1 commit into
Conversation
Contributor
Author
CI status note:
|
1 task
legion-implementer
Bot
force-pushed
the
feat/model-event-retry-accounting
branch
from
July 17, 2026 01:15
7bea5b4 to
bac83a3
Compare
legion-implementer
Bot
force-pushed
the
feat/model-event-retry-accounting
branch
from
July 17, 2026 02:11
bac83a3 to
b5a330d
Compare
Contributor
Author
|
ts-mono types PR moved: meridianlabs-ai/ts-mono#210 → meridianlabs-ai/ts-mono#430 (rebased onto ts-mono main, resubmitted from the trajectory-labs-pbc fork). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contains:
What is the current behavior?
ModelEventis emitted once permodel.generate()call after all retries complete. Several consequences:working_timeon the event is the wall span of the whole call, not per-attempt working time.report_http_retry()) are not separately accounted.What is the new behavior?
model.generate()now emits oneModelEventper attempt, sharing a per-call identifier:ModelGenerateAccounting(ininspect_ai.model._generate_accounting) is set on aContextVarfor the duration of agenerate()call and registers each attempt's event.ModelEventgains:call_id(shared across all attempts of onegenerate())attempt(1-indexed)call_started_at/call_completed_at(per-attempt UTC datetimes)call_working_start/call_working_time(per-attempt monotonic working-time span)call_retries— count of outer scheduled retries (Tenacitybefore_sleep)http_retries— count of provider/HTTP retry signals viareport_http_retry()tests/_helpers/event_assertions.pyandtests/_helpers/retry_provider.pyexpose reusable helpers for asserting the per-attempt invariants.inspect_ai.analysis._dataframe.events.columnsexports the new fields so dataframe-based consumers see them.ModelUsageData/emit_model_usage) carry the new accounting forward.inspect-openapi.jsonis regenerated. Legacy logs (without these fields) round-trip via acall_id is Nonesentinel handled intests/log/test_legacy_log_compat.py.count_tokensandcompactremain eventless; provider-returnedExceptionresults keep the existingRuntimeErrorwrap with no retry.The split between
call_retriesandhttp_retriesis intentional:call_retriesis the count of outer scheduled retries (each one starts a newModelEventattempt)http_retriesis the count of provider-internal HTTP retries reported viareport_http_retry()(these do not start a new attempt)Does this PR introduce a breaking change?
Additive schema changes to
ModelEvent. Consumers reading the OpenAPI schema or log files will see new optional fields. Existing logs continue to deserialize (no required new fields). Downstream code that introspectsModelEventand the dataframe export should benefit but may need to opt into the new fields.Other information:
hypothesis,mutmut(with a scoped[tool.mutmut]for_generate_accounting.py).make check(ruff + mypy) is clean; targeted retry-accounting tests pass under asyncio and trio.GenerateConfig()shared mutable default, xdist teardown + hook-entrypoint ordering,_model_infoimport-cycle break).