Skip to content

[feat] agent: add per-turn duration and a DSH-inspired Trace timing overview #468

Open

Description

@yefuyou

Context / why

Follow-up to @FayeSpica's request in #421 to take inspiration from DSH's Trace layout and show each turn's duration on the Trace page and beside "Completed" in the chat status row.

Existing foundations:

I did not find an open issue/PR specifically implementing this follow-up at the time of filing. I (@yefuyou) intend to take ownership of the implementation, starting with Slice A (persisted per-turn timing), then Slice B (timing overview). Please flag any parallel work or conflicting ownership so I can coordinate before coding.

Current gap (source checked)

  • src/canvas/traceTurns.ts's ConversationTurn has ID, number, text, runtime, model and status, but no duration.
  • apps/api/src/opendirector_api/agent.py's Conversations.update(begin/finish) persists the streaming placeholder and final reply, but no authoritative turn timing. GET /assistant/conversations/{id}/trace returns metadata from the persisted conversation without reading logs.
  • src/canvas/AssistantTracePage.tsx shows per-turn folding and runtime-specific trace details; AssistantPanel.tsx exposes the per-reply Trace link.

A UI-only duration calculated from parsed harness log timestamps would be unreliable across runtimes, missing logs and interrupted runs.

Goal

Add accurate, persisted per-turn timing and a lightweight DSH-inspired timing overview on the existing Trace page, without a new trace store, provider calls or changes to execution semantics. Make slow turns and their already-linked jobs easier to inspect. Preserve the distinction between turn completion and asynchronous generation Job completion.

Reference: DSH official Trajectory README. Borrow the turn-aware ledger + timing overview concept, not a pixel-perfect clone.

Proposed design

Slice A (first PR): authoritative turn timing, end to end

  1. Record an optional UTC startedAt when a turn is durably accepted and an optional UTC finishedAt when the assistant reply reaches a terminal state. Define the duration boundary as accepted turn → terminal assistant reply, not image/video Job settlement.
  2. Measure durationMs using server-side monotonic elapsed time during an uninterrupted execution. Persist it with the final reply. These field names are proposed, to be finalized against existing serialization contracts before implementation; do not infer missing historical values from arbitrary log events.
  3. Extend the existing conversation/read-only trace projections with nullable timing. Reuse the persisted assistant reply for the Chat status row, so reload/archiving do not change the displayed value. A legacy or uncleanly interrupted turn with no trustworthy terminal timestamp shows Unavailable, not a fabricated duration. Running turns show Running; any live elapsed indicator must be clearly labeled provisional.
  4. In Chat, render e.g. Completed · 12.4 s adjacent to the existing status/Trace affordance, with appropriate stopped/interrupted labels. In the Trace turn header, show duration, status and runtime; optionally show recorded absolute start/end in a tooltip.
  5. Keep read-only inspect paths side-effect free: no edit lease, job submission, project mutation or new model request on view.

Slice B (follow-up PR on the same issue, after Slice A is accepted): timing overview

  • Add a compact timing overview above the existing conversation turn list, with one selectable, accessible bar/row per executed turn. Link selection to the existing turn ID, expand/scroll into its lazy-loaded details and retain legacy links.
  • Prefer a clear per-turn duration comparison for the first slice; avoid representing gaps between historical user prompts as Agent execution time. A shared-clock horizontal timeline or step-level waterfall is optional only when start/end evidence is reliable across runtimes. Do not generate fake event spans by subtracting adjacent timestamps.
  • Use existing per-runtime normalizers and TurnTrace details for drilling down. Keep Turn → Job linked status visible, explicitly separate a turn's duration from accepted-but-still-running Jobs.
  • Missing/partial logs, stale interrupted turns, missing timing and running turns must remain visibly distinct. Keep labels in en-US and zh-CN.
  • Fetch only metadata for collapsed turns; details remain on-demand. No eager N×log loading, new giant aggregation response or global Trace framework. Define a reasonable long-conversation/browser performance fixture before shipping the overview.

Important timing semantics

Case Display
Finished reply with measured duration Terminal status + measured turn duration
Streaming / active reply Running; terminal duration not yet available
Crash/restart or historical reply missing timing Unavailable, no guessed measurement
Tool call completed but generation Job queued/running Turn may be completed; Job remains independently queued/running
Cross-runtime log timestamps absent or ambiguous No tool-level duration bar; keep available event details

Do not conflate turn wall time with #449's TTFA (first editable-node frame) or TTC (decoded adopted asset frame).

Acceptance

  • Fixed, documented timestamp/duration semantics, with correct persistence on accepted start and complete/stopped/interrupted finish.
  • Legacy conversations, old Trace URLs, archived sessions and mixed runtimes remain readable; null/unknown times are truthful.
  • Chat terminal status and Trace turn header show the same persisted duration after reload, with en-US/zh-CN labels.
  • Overview selects the intended turn, works with collapsed/lazy detail, supports keyboard/focus and narrow layouts, and does not fetch all raw log bodies.
  • Correct Turn/Job separation, including accepted work still running after the assistant finishes.
  • Targeted Python and TypeScript regressions for timing, failure, missing fields and persistence; fixture-backed browser test for status and overview interactions; no paid provider required.
  • All views are read-only; no prompt/credential data newly exposed in overview, no execution-path behavior change.
  • Coordinate with [RFC] Benchmark TTFA and TTC and Reduce Agent Tool Overhead #449's assignees on terminology before broadening scope to performance instrumentation.

Non-goals

No Trace Markdown export (#421/#422), TTFA/TTC benchmark or polling optimization (#449), generic OpenTelemetry backend, forced per-tool timing across all harnesses, cross-session profiler, replay/fork controls, or wholesale recreation of DSH.

Implementation ownership: I (@yefuyou) plan to implement this follow-up in two reviewable PRs. Slice A will be independently mergeable; Slice B will follow once timing semantics are reviewed. Feedback on the scope is welcome, especially from @FayeSpica and the #449 owners. I will keep #422 (report export) separate.

Refs #261, #372, #374, #407, #409, #421, #422, #449.

Activity

  1. yefuyou commented on Nov 23, 2026

    @yefuyou
    ContributorAuthor

    I'd like to take this follow-up, @FayeSpica. This is based on your original suggestion in #421.

    I'll implement it in two small, reviewable slices: (1) persist authoritative per-turn timing and show it in Chat + the existing Trace headers, then (2) add a DSH-inspired timing overview on the conversation Trace page. I'll keep the report export in #422 separate and coordinate metric terminology with #449. If there's overlapping work already underway or you'd prefer a different scope, please let me know.

  2. yefuyou commented on Nov 23, 2026

    @yefuyou
    ContributorAuthor

    Slice A is now available for review as #476 (draft): #476

    This PR persists authoritative per-turn timing and shows the same saved duration in Chat and conversation Trace. It covers legacy/unknown timing and terminal statuses. The DSH-inspired timing overview remains Slice B and will be a separate follow-up PR.

    I have explicitly documented how the timing boundary differs from #469's tool/CLI performance ledger. Focused tests and independent review passed; the new PR's GitHub CI is pending. I'll keep this draft until its checks are verified.

  3. yefuyou commented on Nov 23, 2026

    @yefuyou
    ContributorAuthor

    Update on #468 Slice A: PR #476 is now Ready for Review at b59a61a7be3fe994111827989a44fd7a60fc3f08.

    All 13/13 GitHub checks are passing, including the browser gate with en-US/zh-CN stopped/interrupted status assertions. CODEOWNERS reviewers @princepride and @hsliuustc0106 have been automatically requested. The DSH-inspired timing overview is still reserved for Slice B.

    Integration note: GitHub currently reports this PR as having a merge conflict (mergeable_state=dirty) against latest main, despite earlier local trial merges. I'll reconcile this on the feature branch; CI passing is not the same as being mergeable. No merge has been attempted.

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

Metadata

Metadata

Assignees

Labels

area:agentAgent runtime, assistant chat and tools

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions