#12999: feat(agents): Add streaming response metrics tracking
channel: slack
app: web-ui
gateway
agents
stale
Cluster:
Session Management and Fixes
## Summary
Adds metrics collection for streaming responses to monitor perceived latency.
## Features
- Time-to-first-chunk tracking
- Chunk count and size metrics
- Perceived latency calculation
- Integration with existing streaming infrastructure
## Files
- src/agents/streaming-metrics.ts
- src/agents/streaming-metrics.test.ts (5 tests)
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR introduces several new agent/gateway infrastructure modules (streaming metrics, model routing, parallel spawn, perf tracing, queue/caching/monitoring utilities) and wires in a memory-leak fix for agent event sequence tracking.
In the current head commit (`a4fcffb`), the functional change is focused on cleaning up per-run sequence counters (`seqByRun`) by deleting them when a run ends and adding a periodic prune safety-net; tests were added to validate the leak fix and it’s wired into the maintenance timer. There’s also an additional cleanup in `server-chat.ts` for that file’s local per-run sequence map.
<h3>Confidence Score: 4/5</h3>
- This PR is likely safe to merge after resolving a small but real cleanup/intent mismatch in server-chat sequence tracking.
- The leak fix in src/infra/agent-events.ts is straightforward and tested. The additional `agentRunSeq.delete` in server-chat.ts is a separate local map cleanup, but as written it’s easy to conflate with the global seqByRun leak fix; clarifying/removing it avoids confusion and review churn.
- src/gateway/server-chat.ts
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#23720: Feat/cli backend runtime tuning
by wanmorebot · 2026-02-22
77.0%
#12248: fix: wire streaming config field through resolveExtraParams to stre...
by mcaxtr · 2026-02-09
76.0%
#22131: fix: clear seqByRun entries in clearAgentRunContext to prevent memo...
by alanwilhelm · 2026-02-20
75.9%
#8713: feat: gateway memory monitor, install linger, docs and failover
by quratus · 2026-02-04
75.5%
#22480: fix: memory leak, silent WS failures, and connection error handling
by Chase-Xuu · 2026-02-21
75.3%
#19255: feat(gateway): add WebSocket connection metrics monitoring
by Wike-CHI · 2026-02-17
75.2%
#9006: fix: streaming UI, session locks, routing performance, plugin sandb...
by facundollamas2007 · 2026-02-04
75.0%
#4300: Gateway: prevent OpenAI-compatible client crash on SSE termination
by perryraskin · 2026-01-30
73.9%
#3517: fix: trigger agent response for webchat sessions after restart
by dovewars · 2026-01-28
73.3%
#10273: fix(agents): detect and auto-compact mid-run context overflow
by terryops · 2026-02-06
73.3%