Skip to content

fix(agent): contextualize cached prefill metrics - #98

Merged
Brooooooklyn merged 1 commit into
mainfrom
fix/agent-prefill-status-context
Jul 18, 2026
Merged

Brooooooklyn merged 1 commit into
mainfrom
fix/agent-prefill-status-context

Conversation

@Brooooooklyn

@Brooooooklyn Brooooooklyn commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • show TTFT and per-turn input/cache context alongside prefill and decode throughput
  • distinguish tiny warm-cache suffixes from comparable bulk-prefill measurements
  • preserve the original rate-only footer when optional context metadata is malformed

Root cause

The agent footer retained only the native prefill and decode rates. On a warm Qwen session, prefill throughput is measured over the fresh suffix while TTFT also includes cache restoration and long-context first-token work. A small suffix such as 42 new tokens over a 114.6K-token cached prefix could therefore display 74.8 tok/s with no indication that it was not a bulk-prefill benchmark.

The completed Pi message already contains the fresh input and cache-read counts, so this change adds that existing context without changing native metrics or public schemas.

Example:

mlx · TTFT 561.7 ms · input 42 new + 114.6k cached · prefill 74.8 tok/s · decode 42.5 tok/s

Validation

  • yarn vp test packages/agent/__test__/performance-status.test.ts packages/agent/__test__/stream-adapter.test.ts packages/agent/__test__/events.test.ts (69 passed)
  • yarn exec tsc -b packages/agent/tsconfig.json --pretty false
  • yarn vp lint packages/agent/src/provider/performance-status.ts packages/agent/__test__/performance-status.test.ts packages/agent/__test__/stream-adapter.test.ts
  • yarn vp fmt --check packages/agent/src/provider/performance-status.ts packages/agent/__test__/performance-status.test.ts packages/agent/__test__/stream-adapter.test.ts

Note

Low Risk
Display-only TUI status formatting with defensive validation; no auth, persistence, or inference behavior changes beyond what is shown in the footer.

Overview
The agent TUI mlx performance footer now adds TTFT and per-turn input context (fresh vs cached tokens) next to the existing prefill/decode throughput, so warm-cache turns do not look like bulk-prefill benchmarks when only a small suffix was prefilled.

PerformanceStatus.record pulls optional TTFT from native metrics and input/cacheRead from the completed assistant message’s usage; formatting distinguishes “N new + M cached” when cacheRead > 0, otherwise a single input count. If TTFT or usage counts are invalid, the footer falls back to the previous rate-only line.

Tests cover tiny vs bulk cached suffixes, malformed metadata fallback, and assert the stream adapter still attaches usage (input / cacheRead) on the Pi assistant message used for recording.

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

@cursor

cursor Bot commented Jul 18, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_c1154316-89ff-4fd9-ac07-b8ef02741d48)

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c3845bef-6a42-493d-ac69-53a17b312c67

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
  • Commit unit tests in branch fix/agent-prefill-status-context

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.

@Brooooooklyn
Brooooooklyn merged commit d53f2c0 into main Jul 18, 2026
12 of 13 checks passed
@Brooooooklyn
Brooooooklyn deleted the fix/agent-prefill-status-context branch July 18, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant