Skip to content

feat(agent): record how long each todo of a run took - #1812

Merged
edenreich merged 1 commit into
mainfrom
feat/todo-timing
Nov 11, 2026
Merged

edenreich merged 1 commit into
mainfrom
feat/todo-timing

Conversation

@edenreich

Copy link
Copy Markdown
Contributor

Summary

A run now shows where its time went. The session stamps each todo when it starts and when it completes, and adds up the stretches it was in progress for. The model supplies none of it and cannot overwrite it.

  • In the todos state of a headless run, each item carries started_at, completed_at and elapsed_ms
  • In the chat, the todo list shows the time beside a completed item and counts it up beside the one in progress
  • When a run ends, the result of RUN_FINISHED reports todoTimes: the run's wall time split between its todos and the time no todo was in progress

Run on the mock gateway with a scripted session of three TodoWrite calls around two sleeps:

"todoTimes": {"runMs": 3884, "outsideMs": 228, "todos": [{"id": "1", "content": "first", "ms": 2333}, {"id": "2", "content": "second", "ms": 1322}]}

Closes #1807

Changes

  • internal/agent/domain - TodoItem gains the three fields. StampTodos carries a list's times over by id and stamps a status that changed, and TodoItem.ElapsedAt is the time worked on by a given moment
  • internal/agent/loop/agent.go - recordTodos stamps a TodoWrite result against the session's list at the one place the loop records it, under a lock so two calls of one turn stamp in order. The stamped list is what the tool result, the state store and the todo event carry
  • internal/presentation/headless - todoClock attributes the run's wall time to the todo in progress at each moment. The run encoder feeds it the todo updates and adds its summary to the terminal event's result
  • internal/presentation/tui/components/todo_box_view.go - the elapsed time beside an item
  • Tests: the stamping rules as a table (start, continue, complete, reopen, back to pending, never started, forged times), the agent's stamping against the real state store, the clock's split, the TUI's formatting
  • docs/tools-reference.md and docs/ag-ui-output.md

A run that never calls TodoWrite publishes and reports exactly what it did before: the new fields are omitempty and todoTimes is left out.

Differences from the issue

  • A running todo's time is not republished as it grows. The state changes only when TodoWrite is called, so the item in progress carries started_at and what it gathered before, and a client adds the time since started_at. The issue asked that a client need not compute it - for finished stretches it does not
  • The times do not survive a restart of the worker. The stamped list is saved with the TodoWrite result in the conversation, but a resumed session does not restore its todo list today, with or without times. Restoring it is a change of its own
  • The parts add up to runMs within a millisecond, as each is rounded down to whole milliseconds
  • Time waiting on an approval counts for the todo in progress, and so does the time between two runs when a run ends with a todo still in progress. The per-run summary only counts time inside the run
  • A todo without an id gets a new one on every call, as before, so its time starts over

Docs follow-up

A [DOCS] issue for inference-gateway/docs is drafted, not filed: the three fields on a todo and todoTimes on the AG-UI output page.

The session stamps a todo when it starts and when it completes, matched by id from one TodoWrite call to the next, and adds up the stretches it was in progress for. The times ride on the todos state and in the chat's todo list, and a headless run's terminal event reports its wall time split between its todos.
@github-project-automation github-project-automation Bot moved this to Todo in 2026 Nov 11, 2026
@edenreich
edenreich marked this pull request as ready for review November 11, 2026 17:56
@edenreich
edenreich requested a review from a team as a code owner November 11, 2026 17:56
@edenreich
edenreich merged commit c09f02a into main Nov 11, 2026
13 checks passed
@edenreich
edenreich deleted the feat/todo-timing branch November 11, 2026 17:58
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.255.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[FEATURE] Record how long each todo of a run took

1 participant