Skip to content

Add assistant turn stats footer#2601

Open
coygeek wants to merge 3 commits intopingdotgg:mainfrom
coygeek:fix/session-stats-footer-metrics
Open

Add assistant turn stats footer#2601
coygeek wants to merge 3 commits intopingdotgg:mainfrom
coygeek:fix/session-stats-footer-metrics

Conversation

@coygeek
Copy link
Copy Markdown

@coygeek coygeek commented May 8, 2026

Summary

Closes #2518.

  • add a compact assistant turn stats footer with model/effort, elapsed time, output tokens, throughput, TTFT, and tool-call count when available
  • project token usage onto the latest completed turn so the footer survives reloads and avoids stale/unassigned context-window snapshots
  • derive Codex TTFT from first assistant output and completed throughput duration from active assistant response boundaries, excluding approval/user-input waits and preserving provider-supplied durations
  • keep unavailable metrics hidden instead of fabricating zero values

Verification

  • cd apps/server && bun run test -- src/orchestration/Layers/ProviderRuntimeIngestion.test.ts
  • cd apps/server && bun run test -- src/orchestration/Layers/ProviderRuntimeIngestion.test.ts src/orchestration/Layers/ProjectionPipeline.test.ts
  • cd apps/web && bun run test -- src/lib/turnStats.test.ts src/lib/contextWindow.test.ts
  • bun fmt
  • bun lint (passes with existing warnings only)
  • bun typecheck
  • bun run test
  • git diff --check

Live smoke

  • Reused the local app on http://localhost:5733/
  • Sent a short Codex turn via agent-browser
  • Confirmed one [data-assistant-turn-stats="true"] footer rendered with 16 tokens, 66.7 tok/sec, and Time-to-first: 7.2 sec
  • Confirmed SQLite persisted the same latest turn with durationMs: 240, timeToFirstTokenMs: 7216, and lastOutputTokens: 16, so completed TPS is not using the old sub-10ms final-delta denominator

Note

Medium Risk
Touches provider ingestion/projection and token-usage normalization, which can affect persisted thread metadata and any downstream metrics/UX. Changes are well-covered by new targeted tests but involve timing/edge-case logic across providers.

Overview
Adds a compact per-assistant-message stats footer in the chat timeline (model/effort, elapsed, token count, throughput, TTFT, tool-call count), derived for the latest completed assistant turn and omitted when metrics are missing.

To make these stats stable across reloads, provider ingestion now derives Codex generation durationMs and timeToFirstTokenMs from assistant stream boundaries (excluding approval/user-input gaps) and merges them into context-window.updated activities only when the provider doesn’t supply valid timings; the contracts schema is extended to include timeToFirstTokenMs, and Codex token-usage events now carry/propagate turnId.

Also fixes a projection edge case where thread.session-set with activeTurnId: null would clear latestTurnId, and adjusts proposed plan export filenames to be plan-*.md (without double-prefixing).

Reviewed by Cursor Bugbot for commit 69658e2. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Add assistant turn stats footer to chat timeline

  • Adds a TurnStatsFooter component to assistant messages displaying model, token count, throughput, time-to-first-token, and tool call count when available.
  • Introduces deriveLatestAssistantTurnStats and buildLatestAssistantTurnStatsMap in turnStats.ts to compute human-readable stats from turn timing, context window snapshots, and activities.
  • Derives assistant stream duration and TTFT in ProviderRuntimeIngestion.ts from Codex delta timestamps when provider usage lacks these values; excludes tool/request gaps.
  • Adds turnId and providerRefs.providerTurnId to emitted thread.token-usage.updated runtime events in the Codex adapter; events without payload are now dropped.
  • Fixes ProjectionPipeline.ts to preserve latestTurnId when a session update sets activeTurnId to null.
  • Prefixes buildProposedPlanMarkdownFilename output with plan- unless the name already starts with plan.

Macroscope summarized 69658e2.

Show compact assistant turn stats with model, elapsed time, token count, throughput, TTFT, and tool-call count when those fields are available. Derive Codex timing from response boundaries so completed throughput does not use tiny final delta gaps as the denominator.

Closes pingdotgg#2518
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 8, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 47437705-b4c2-4741-8dde-8701f872992f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added size:XL 500-999 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels May 8, 2026
Comment thread apps/web/src/lib/turnStats.ts Outdated
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp Bot commented May 8, 2026

Approvability

Verdict: Needs human review

This PR introduces a new user-facing feature (assistant turn stats footer) with new UI components, business logic, backend timing infrastructure, and schema changes spanning multiple layers. The scope and new capability warrant human review.

You can customize Macroscope's approvability policy. Learn more.

Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e433872. Configure here.

Comment thread apps/web/src/lib/turnStats.ts
@juliusmarminge
Copy link
Copy Markdown
Member

juliusmarminge commented May 8, 2026

CleanShot 2026-05-08 at 09 51 45@2x

@coygeek
Copy link
Copy Markdown
Author

coygeek commented May 8, 2026

image

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

Labels

size:XL 500-999 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Add compact per-turn session stats footer

2 participants