Skip to content

[feat] agent: persist and display per-turn duration (#468) - #476

Open
yefuyou wants to merge 9 commits into
ThinkFlowLab:mainfrom
yefuyou:feat/468-turn-timing
Open

yefuyou wants to merge 9 commits into
ThinkFlowLab:mainfrom
yefuyou:feat/468-turn-timing

Conversation

@yefuyou

@yefuyou yefuyou commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Refs #468 (Slice A: per-turn timing only).

Persist authoritative timing metadata for each accepted Agent turn and show the same recorded duration in Chat and the existing conversation-wide Trace page. This is a small, reviewable first slice of the DSH-inspired timing work requested by @FayeSpica; the visual timing overview (Slice B) remains follow-up work.

  • Persist optional startedAt and finishedAt (ISO 8601 UTC) and durationMs (non-negative integer) on the assistant reply.
  • Capture the start after successful admission inside the conversation begin transaction; measure elapsed time with the server's monotonic clock and persist at finish. Finish updates preserve the recorded start.
  • Expose nullable fields in the existing read-only conversation Trace projection; display the persisted result in Chat and per-turn Trace headers with shared formatting and en-US/zh-CN translations.
  • Support complete, stopped, interrupted, legacy missing timestamps and post-restart unknown durations without inventing elapsed time.
  • No new timing database, provider requests, replay controls or changes to asynchronous generation Job semantics.

Timing semantics and limitations

  • Duration is turn admission → terminal reply, not completion of linked generation Jobs, and excludes the begin/finish disk writes.
  • durationMs uses an in-process monotonic measurement. A restart/multi-process handoff may leave only startedAt with an unknown duration; historical turns are not backfilled.
  • For comparison with [perf] agent: record where a turn spends its time (#449) #469: that PR measures tool/CLI breakdown and reports turnSeconds under agent-runs/timing/, with a different boundary. This PR records user-visible turn duration in conversation history. Both can coexist, but their values should not be presented as identical.
  • On a failed finish persistence write, a durable duration is not guaranteed.

Validation

  • Python targeted regression suite: 57 passed; 10 new tests reported. Clean-main versus feature-branch comparison in the same sandbox found the same 340 failing test IDs in full pytest, with no additional test failures on this branch. Most involve unavailable FFmpeg/ffprobe; 17 runtime failures remain uninvestigated.
  • TypeScript: 966 passed, 0 failed; build and i18n validation passed.
  • Fixture-backed browser: turn timing and assistant sessions checks passed after earlier changes, including English/Chinese, persisted Chat/Trace agreement, reload, missing historical timing, deep links and turn expansion.
  • After the final 40c344e4 change to stop/interruption display, the browser suite was not rerun. Those statuses are covered in unit tests, not by a dedicated browser scenario.
  • Independent v2 review of final head: APPROVED after fixing duplicate terminal-status rendering. PR head: 40c344e442ce3e2e8f24afc5f338556f2189ac7d.
  • No paid model/provider calls. GitHub PR CI pending.

Parallel development / merge notes

Out of scope

Slice B DSH-inspired visual overview, trace export, TTFA/TTC benchmarking, new tool-level instrumentation, Job durations, performance optimization, and execution semantics changes.

Review focus

Please review the admission/terminal timing boundaries, cancellation and restart cases, compatibility with #469 and in-flight conversation lifecycle PRs, and the presentation of stopped/interrupted replies.

Please keep this PR as a draft until its own GitHub CI runs on the submitted head.

…hinkFlowLab#468)

## summary
- Conversations.update stamps startedAt on the assistant placeholder at acceptance and finishedAt/durationMs (monotonic) at finish entry, without touching produce()/turn().
- Conversations.trace() returns startedAt/finishedAt/durationMs per turn, null when unknown.
- Tests cover complete, stop, runtime failure, rejected turns, archive, legacy data, and restart.
@yefuyou
yefuyou marked this pull request as ready for review November 23, 2026 13:26
@github-actions github-actions Bot added area:agent Agent runtime, assistant chat and tools type:feat New capability or behaviour labels Nov 23, 2026
@github-actions
github-actions Bot requested review from FayeSpica and wuzhf9 November 23, 2026 13:26
# Conflicts:
#	tests/test_assistant_conversation_trace.py

This branch has not been deployed

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

Labels

area:agent Agent runtime, assistant chat and tools type:feat New capability or behaviour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants