Repository navigation
fix(ai): record the duration of each agent model request - #4717
Conversation
|
Local run after the change: Not in this change: the backend breakdown of the spend report lists only rows with |
🤖 I have created a release *beep* *boop* --- ## [0.112.3](v0.112.2...v0.112.3) (2026-11-11) ### Bug Fixes * **ai:** record the duration of each agent model request ([#4717](#4717)) ([1930b71](1930b71)) * **devcontainer:** poll the Docker daemon through the clock ([#4721](#4721)) ([be32268](be32268)) * **roadmap:** confine repair fix turns to the plan files ([#4689](#4689)) ([d2e7597](d2e7597)) * **roadmap:** name the nearest test of a module ([#4696](#4696)) ([b746c95](b746c95)) * **roadmap:** scoped intake reads a bounded page count ([#4740](#4740)) ([f89ccc5](f89ccc5)) * **roadmap:** stage context reads runner facts from the package ([#4723](#4723)) ([05e09dc](05e09dc)) * **roadmap:** stage holds an item where openspec is not set up ([#4749](#4749)) ([45bd54a](45bd54a)) * **roadmap:** trace gate reads a tool call citation ([#4694](#4694)) ([5c71ad4](5c71ad4)) ### Performance Improvements * **ci:** cancel superseded CodeQL runs and idle triggers ([#4763](#4763)) ([c951368](c951368)) ### Code Refactoring * **ai:** delete orphan prompts and the prompt fallbacks ([#4710](#4710)) ([38a1b13](38a1b13)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
What
The spend hook of
build_agentrecords the seconds of each model request induration_seconds. A before hook keeps the monotonic start time in aContextVar. The after hook writes the record with the seconds since then. A request that raises runs no after hook, so it writes no record.Why
Since #4237 the stage, refine and alternatives runs write their records through this hook. It passed no duration, so every record held 0.0 and the mean duration of a spend report was too low.
Both hooks are
async def: pydantic-ai runs a plaindefhook in an executor, where theContextVarwould not reach the after hook. The record is written withasyncio.to_thread, so the SQLite write stays off the event loop.Closes #4504
Change:
openspec/changes/archive/2026-11-11-4504-agent-requests-record-no-duration-in/