Skip to content

feat: Calculate actual average response time from comment data#237

Draft
EdiWeeks wants to merge 4 commits into
mainfrom
fix/issue-179-actual-response-time
Draft

feat: Calculate actual average response time from comment data#237
EdiWeeks wants to merge 4 commits into
mainfrom
fix/issue-179-actual-response-time

Conversation

@EdiWeeks
Copy link
Copy Markdown
Collaborator

@EdiWeeks EdiWeeks commented Feb 20, 2026

Summary

  • Replaced workload-based estimate with actual first-response time calculated from work item comments
  • Fetches comments for tickets from the last 30 days, finds first internal (non-requester) response
  • Parallelized comment fetching in batches of 10 using Promise.allSettled
  • Added 5-minute TTL cache to avoid re-fetching on repeated page loads
  • Falls back to workload-based estimate when no comment data is available
image

Test plan

  • Navigate to the team page and verify avgResponseTime shows actual values (e.g., "2h", "1d", "< 1h")
  • Verify members with no recent tickets show fallback estimates
  • Reload page within 5 minutes and confirm faster load (cached)

Closes #179

🤖 Generated with Claude Code

Replaces workload-based estimate with actual first-response time
calculated from work item comments. Fetches comments for tickets
from the last 30 days in parallel batches of 10, with a 5-minute
TTL cache. Falls back to workload estimate when no data available.

Closes #179

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements actual average response time calculation based on work item comments, replacing the previous workload-based estimation. The implementation fetches comments for tickets from the last 30 days, identifies the first internal (non-requester) response, and calculates actual response times. To mitigate performance impact, it uses batched parallel fetching (10 concurrent requests) and a 5-minute TTL cache.

Changes:

  • Added comment-based response time calculation with 30-day lookback window
  • Implemented module-level caching with 5-minute TTL to reduce API load
  • Added parallel comment fetching in batches of 10 using Promise.allSettled
  • Retained workload-based estimation as fallback when no comment data available

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/app/api/devops/team/route.ts Outdated
Comment thread src/app/api/devops/team/route.ts
Comment thread src/app/api/devops/team/route.ts Outdated
Comment thread src/app/api/devops/team/route.ts
Comment thread src/app/api/devops/team/route.ts Outdated
Comment thread src/app/api/devops/team/route.ts Outdated
Comment thread src/app/api/devops/team/route.ts
Comment thread src/app/api/devops/team/route.ts
Comment thread src/app/api/devops/team/route.ts Outdated
if (authorEmail === requesterEmail) continue;

const responseTimeMs = comment.createdAt.getTime() - ticket.createdAt.getTime();
if (responseTimeMs <= 0) continue;
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

The check for responseTimeMs <= 0 at line 290 might filter out valid same-millisecond responses. While unlikely, if a comment is created in the same millisecond as the ticket (especially in automated systems), it would be incorrectly excluded. The condition should be responseTimeMs < 0 to only exclude invalid negative values while allowing zero (immediate response).

Suggested change
if (responseTimeMs <= 0) continue;
if (responseTimeMs < 0) continue;

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

A 0ms response is almost certainly an automated system comment, not a genuine human response. Keeping <= 0 to filter those out.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think we need an IF here ... even a system automated response won't be 0ms. Suggest we keep it symple for now and not worry about agentic responses (that used to ignore automated initial "thank you for you message" responses, but will would look to implement an actual useful agentic response).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agreed — removed the check entirely in d6822d7. Keeping it simple.

- Extract shared formatDuration() helper to reduce duplication
- Add error logging to catch block in getFirstResponseTimeMs()
- Guard requester email check to handle empty string edge case
- Cap ticket processing at 100 most recent to prevent excessive API calls

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@BenGWeeks BenGWeeks marked this pull request as draft February 20, 2026 19:09
@BenGWeeks BenGWeeks marked this pull request as draft February 20, 2026 19:09
@EdiWeeks EdiWeeks removed the request for review from akash2017sky March 11, 2026 17:22
EdiWeeks and others added 2 commits March 11, 2026 17:23
Keep response time cache from PR branch and request parameter from main.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Per review feedback — even automated responses won't be 0ms, so the
guard is unnecessary. Keep it simple.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@EdiWeeks EdiWeeks marked this pull request as ready for review March 11, 2026 17:27
@EdiWeeks
Copy link
Copy Markdown
Collaborator Author

@BenGWeeks please approve

@EdiWeeks EdiWeeks marked this pull request as draft March 18, 2026 09:44
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.

Implement actual average response time calculation

3 participants