Skip to content

feat(a2ui): add server stream performance logs#2721

Merged
Sherry-hue merged 2 commits into
lynx-family:mainfrom
Sherry-hue:feat/a2ui-server-perf-metrics
May 28, 2026
Merged

feat(a2ui): add server stream performance logs#2721
Sherry-hue merged 2 commits into
lynx-family:mainfrom
Sherry-hue:feat/a2ui-server-perf-metrics

Conversation

@Sherry-hue
Copy link
Copy Markdown
Collaborator

@Sherry-hue Sherry-hue commented May 27, 2026

Summary

Add targeted server-side performance logs around the A2UI streaming APIs so production latency can be broken down by request body handling, validation, agent setup, upstream stream invocation, and first streamed chunk.

Details

  • Report request body metrics from readJsonBodyWithLimit, including declared/raw byte size plus read and JSON parse timings.
  • Log /a2ui/stream and /a2ui/action/stream phases from request receipt through validation, agent connection, first upstream chunk, validation, repair, and completion.
  • Add agent service performance callbacks for cache hit/miss, conversation message construction, model message conversion, and agent.stream() invocation timing.

Validation

  • pnpm -C packages/genui/server exec tsc --noEmit
  • pnpm dprint check packages/genui/server/app/a2ui/_shared.ts packages/genui/server/app/a2ui/stream/route.ts packages/genui/server/app/a2ui/action/stream/route.ts packages/genui/server/service/a2ui-agent.ts
  • pre-commit hooks ran eslint --cache --fix, biome lint --write, and dprint fmt on staged files

Summary by CodeRabbit

Release Notes

  • Chores
    • Enhanced request monitoring with detailed performance metrics collection across the streaming pipeline.
    • Added structured event logging throughout request lifecycle and streaming operations for improved operational visibility.

Review Change Stack

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 27, 2026

⚠️ No Changeset found

Latest commit: e955c3f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 45d90240-f4ea-4ab3-9913-a1d1c112a237

📥 Commits

Reviewing files that changed from the base of the PR and between 6a293cb and 054575f.

📒 Files selected for processing (4)
  • packages/genui/server/app/a2ui/_shared.ts
  • packages/genui/server/app/a2ui/action/stream/route.ts
  • packages/genui/server/app/a2ui/stream/route.ts
  • packages/genui/server/service/a2ui-agent.ts

📝 Walkthrough

Walkthrough

This PR adds comprehensive structured instrumentation and performance event logging across the A2UI server stack. JSON body metrics (size and timing) are collected at the shared parsing layer, exposed through updated return types, and logged by route handlers. The service layer emits performance events at key points (cache hits/misses, message preparation, stream invocation), and both action and standard stream routes wire callback handlers to capture and log these events alongside request lifecycle checkpoints.

Changes

A2UI Server Instrumentation and Performance Event Logging

Layer / File(s) Summary
JSON body metrics contract and collection
packages/genui/server/app/a2ui/_shared.ts
Introduces JsonBodyMetrics interface and extends readJsonBodyWithLimit to measure and return parsing timing, declared byte length, and raw UTF-8 byte length on all success and failure code paths.
Service performance event infrastructure
packages/genui/server/service/a2ui-agent.ts
Adds optional onPerformanceEvent callback to ChatOptions, implements sumContentChars() helper for character counting, and emits structured events during agent cache lookup, model message preparation, stream invocation, and conversation assembly.
Action stream route request lifecycle logging
packages/genui/server/app/a2ui/action/stream/route.ts
Adds stream logger at request start and logs rate-limit decisions, JSON body parsing metrics, validation checkpoints with timing (action name, surfaceId, conversation), wires upstream performance events to logger, and adds connection/first-chunk timing logs during streaming.
Standard stream route request lifecycle logging
packages/genui/server/app/a2ui/stream/route.ts
Adds stream logger at request start and logs rate-limit decisions, JSON body parsing metrics, message/conversation validation with timing, wires upstream performance events to logger, and adds connection/first-chunk timing logs during streaming.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • lynx-family/lynx-stack#2709: Both PRs modify the server A2UI SSE route handlers to add instrumentation and structured logging, including wiring performance/protocol events through the streaming options.

Suggested reviewers

  • HuJean
  • gaoachao
  • PupilTong

Poem

🐰 Metrics flow like carrots through the stream,
Each event logged, a performance dream,
From body bytes to cache timing true,
The agent sings its song for you. 🎵

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(a2ui): add server stream performance logs' directly and concisely describes the main change: adding performance logging to A2UI server streaming endpoints.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

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

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.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 27, 2026

Merging this PR will not alter performance

✅ 81 untouched benchmarks
⏩ 26 skipped benchmarks1


Comparing Sherry-hue:feat/a2ui-server-perf-metrics (e955c3f) with main (f38e285)2

Open in CodSpeed

Footnotes

  1. 26 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (ec73c30) during the generation of this report, so f38e285 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@relativeci
Copy link
Copy Markdown

relativeci Bot commented May 27, 2026

React Example

#8719 Bundle Size — 238KiB (0%).

054575f(current) vs 6a293cb main#8718(baseline)

Bundle metrics  no changes
                 Current
#8719
     Baseline
#8718
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 4 4
No change  Modules 204 204
No change  Duplicate Modules 81 81
No change  Duplicate Code 44.59% 44.59%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#8719
     Baseline
#8718
No change  IMG 145.76KiB 145.76KiB
No change  Other 92.24KiB 92.24KiB

Bundle analysis reportBranch Sherry-hue:feat/a2ui-server-perf...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented May 27, 2026

React Example with Element Template

#987 Bundle Size — 204.36KiB (0%).

054575f(current) vs 6a293cb main#986(baseline)

Bundle metrics  no changes
                 Current
#987
     Baseline
#986
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 4 4
No change  Modules 124 124
No change  Duplicate Modules 50 50
No change  Duplicate Code 45.19% 45.19%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#987
     Baseline
#986
No change  IMG 145.76KiB 145.76KiB
No change  Other 58.61KiB 58.61KiB

Bundle analysis reportBranch Sherry-hue:feat/a2ui-server-perf...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented May 27, 2026

React External

#1834 Bundle Size — 699.5KiB (0%).

054575f(current) vs 6a293cb main#1833(baseline)

Bundle metrics  no changes
                 Current
#1834
     Baseline
#1833
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 3 3
No change  Modules 17 17
No change  Duplicate Modules 5 5
No change  Duplicate Code 7.13% 7.13%
No change  Packages 0 0
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#1834
     Baseline
#1833
No change  Other 699.5KiB 699.5KiB

Bundle analysis reportBranch Sherry-hue:feat/a2ui-server-perf...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented May 27, 2026

Web Explorer

#10295 Bundle Size — 903.53KiB (0%).

054575f(current) vs 6a293cb main#10294(baseline)

Bundle metrics  Change 1 change
                 Current
#10295
     Baseline
#10294
No change  Initial JS 45.06KiB 45.06KiB
No change  Initial CSS 2.22KiB 2.22KiB
No change  Cache Invalidation 0% 0%
No change  Chunks 9 9
No change  Assets 11 11
Change  Modules 232(+0.43%) 231
No change  Duplicate Modules 11 11
No change  Duplicate Code 27.12% 27.12%
No change  Packages 10 10
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#10295
     Baseline
#10294
No change  JS 499.15KiB 499.15KiB
No change  Other 402.16KiB 402.16KiB
No change  CSS 2.22KiB 2.22KiB

Bundle analysis reportBranch Sherry-hue:feat/a2ui-server-perf...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented May 27, 2026

React MTF Example

#1853 Bundle Size — 208.94KiB (0%).

054575f(current) vs 6a293cb main#1852(baseline)

Bundle metrics  no changes
                 Current
#1853
     Baseline
#1852
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 3 3
No change  Modules 199 199
No change  Duplicate Modules 78 78
No change  Duplicate Code 44.08% 44.08%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#1853
     Baseline
#1852
No change  IMG 111.23KiB 111.23KiB
No change  Other 97.71KiB 97.71KiB

Bundle analysis reportBranch Sherry-hue:feat/a2ui-server-perf...Project dashboard


Generated by RelativeCIDocumentationReport issue

@Sherry-hue Sherry-hue marked this pull request as ready for review May 27, 2026 07:42
@Sherry-hue Sherry-hue merged commit fc55da2 into lynx-family:main May 28, 2026
73 of 76 checks passed
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.

2 participants