Refactor Microsoft Auth endpoints and enhance token handling#32
Open
alfarahn wants to merge 12 commits into
Open
Refactor Microsoft Auth endpoints and enhance token handling#32alfarahn wants to merge 12 commits into
alfarahn wants to merge 12 commits into
Conversation
- Updated MicrosoftAuthEndpoints to use a named HTTP client with a 30s timeout for token requests. - Changed SaveIdentity and UpdateGraphTier methods in PersistentIdentity to be asynchronous. - Enhanced SessionTokenStore to include retry logic for transient network errors when fetching tokens. - Introduced a new Ipv4HttpHandler to enforce IPv4-only connections and a 5s connect timeout for all HTTP clients. - Improved error handling and logging for token refresh operations. - Added ephemeral "cooling down" rows in the ChatView component to visually indicate 429/5xx throttling events. - Implemented timing hooks to capture and log performance metrics for tool calls and server interactions. - Updated dependencies in the project file for GitHub Copilot SDK.
| var done = new TaskCompletionSource(); | ||
| var cancelled = false; | ||
| var toolTracker = new ConcurrentDictionary<string, (string Name, DateTimeOffset StartTime, Activity? Activity)>(); | ||
| var firstEventLogged = 0; |
| id = record.UserId, | ||
| login = $"user-{record.UserId & 0xFFFF:X4}", | ||
| name = record.Name, | ||
| avatar = (string?)null, |
| // Pass null activity — Activity is not safe for concurrent SetTag | ||
| // writers, and these drilldowns run in parallel. Each call still | ||
| // gets its own ActivitySource span inside HttpHelper. | ||
| try { return (c, Breakdown: (object)await GetBreakdownForDay(token, subscriptionId, c.Date, groupBy, activity: null)); } |
| // writers, and these drilldowns run in parallel. Each call still | ||
| // gets its own ActivitySource span inside HttpHelper. | ||
| try { return (c, Breakdown: (object)await GetBreakdownForDay(token, subscriptionId, c.Date, groupBy, activity: null)); } | ||
| catch (Exception ex) { return (c, Breakdown: (object)new { error = ex.Message }); } |
| await ctx.Response.WriteAsync($"data: {donePayload}\n\n"); | ||
| await ctx.Response.Body.FlushAsync(); | ||
| } | ||
| catch { } |
Comment on lines
+422
to
+426
| catch (Exception bgEx) | ||
| { | ||
| logger.LogWarning(bgEx, "Background title generation failed for session {Sid}", bgSessionId); | ||
| return null; | ||
| } |
| logger.LogInformation("timing phase=sdk.first_event ms={Ms:F0} user={User}", firstMs, userLogin); | ||
| await SafeEmit(JsonSerializer.Serialize(new { type = "timing", phase = "sdk.first_event", ms = Math.Round(firstMs, 1), extra = new { evt = evt.GetType().Name } })); | ||
| } | ||
| catch { } |
| logger.LogInformation("timing phase=sdk.first_event ms={Ms:F0} user={User}", firstMs, userLogin); | ||
| await SafeEmit(JsonSerializer.Serialize(new { type = "timing", phase = "sdk.first_event", ms = Math.Round(firstMs, 1), extra = new { evt = evt.GetType().Name } })); | ||
| } | ||
| catch { } |
…loadSessions call
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
… on local IDisposable' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Collaborator
Author
|
@copilot how do you feel about this PR to main does it improve latency? |
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Contributor
Honest read: this PR should help tail latency more than median. Wins:
Neutral / costs:
Net: median p50 ~unchanged, p95/p99 should improve noticeably on cold token refreshes and any IPv6-flaky egress. I'd merge it. The one thing I'd watch post-merge is the App Insights |
| await ctx.Response.WriteAsync($"data: {donePayload}\n\n"); | ||
| await ctx.Response.Body.FlushAsync(); | ||
| } | ||
| catch (OperationCanceledException) { } |
| await ctx.Response.Body.FlushAsync(); | ||
| } | ||
| catch (OperationCanceledException) { } | ||
| catch (ObjectDisposedException) { } |
| // writers, and these drilldowns run in parallel. Each call still | ||
| // gets its own ActivitySource span inside HttpHelper. | ||
| try { return (c, Breakdown: (object)await GetBreakdownForDay(token, subscriptionId, c.Date, groupBy, activity: null)); } | ||
| catch (Exception ex) { return (c, Breakdown: new { error = ex.Message }); } |
| // writers across the 8 parallel queries. HttpHelper still emits | ||
| // its own per-call span. | ||
| try { return (p.Label, Result: await RunResourceGraphQuery(token, p.Kql, subs, activity: null)); } | ||
| catch (Exception ex) { return (p.Label, Result: new { error = "query exception", detail = ex.Message }); } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Type of change
Checklist
dotnet build)npm run buildinsrc/Dashboard/frontend).github/copilot-instructions.mdif behaviour or structure changedCHANGELOG.mdunder[Unreleased]Related issues
Closes #